Radio Control Layer (RCL)
LRF.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2023, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef __lrf_h__
34 #define __lrf_h__
35 
36 #include <stdint.h>
37 #include <stddef.h>
38 #include <stdbool.h>
39 
40 #if defined(DeviceFamily_CC23X0R5) || defined(DeviceFamily_CC23X0R2)
41 # include <ti/devices/DeviceFamily.h>
42 # include DeviceFamily_constructPath(driverlib/pbe_regs.h)
43 # include "LRFCC23X0.h"
44 #endif
45 
46 #ifdef DeviceFamily_CC1308
47 # define BUFFER_SPLIT_SUPPORT
48 # include "LRFCC1308.h"
49 #endif
50 
55 #define LRF_TxPower_Use_Min ((LRF_TxPowerTable_Index){.rawValue = -128})
56 
60 #define LRF_TxPower_Use_Max ((LRF_TxPowerTable_Index){.rawValue = 125})
61 
65 #define LRF_TxPower_Use_Raw ((LRF_TxPowerTable_Index){.rawValue = 126})
66 
71 #define LRF_TxPower_None ((LRF_TxPowerTable_Index){.rawValue = 127})
72 
77 #define LRF_SETTINGS_BUFFER_UNLIMITED 0x3FFF
78 
83 #define LRF_RSSI_INVALID (127)
84 
85 
86 typedef enum LRF_RadioState_e {
88  RadioState_ImagesLoaded, /* TOPsm images loaded, persists */
89  RadioState_Configured, /* REGBANK values loaded, no persist */
91 
95 typedef enum LRF_SetupResult_e {
106 
108  uint32_t imageLen;
109  uint32_t image[];
110 };
111 
112 typedef union {
113  struct {
114  uint32_t lengthMinus1 : 12;
115  uint32_t type : 4;
116  uint32_t startAddress : 16;
117  } region;
118  uint32_t value32;
119  uint16_t value16[2];
120  struct {
121  uint16_t value16;
122  uint16_t address;
123  } sparse;
124  struct {
125  uint16_t value16;
126  uint16_t mask16;
127  } masked;
128  struct {
129  uint32_t length : 14;
130  uint32_t invertedFeatureMask : 1;
131  uint32_t compoundSegment : 1;
132  uint32_t featureMask : 16;
133  } segment;
135 
137  uint32_t numEntries;
139 };
140 
141 typedef enum {
157 
158 typedef enum {
162 
163 typedef struct {
164  /* Settings */
165  uint16_t phyFeatures;
167 
168 #ifdef BUFFER_SPLIT_SUPPORT
169  /* State variables */
170  bool started;
171  int32_t totalLength;
172  uint32_t segmentLength;
173 
174  /* State variables for region */
175  uintptr_t address;
176  LRF_RegionOperation operation;
177  uint32_t regionLength;
178  uint32_t regionStart;
179 #endif
181 
182 #define LRF_PhyFeatures_Default 0
183 
184 #define LRF_NUM_CLK_ENA 2 /* Number of clock enable sets */
185 #define LRF_CLK_ENA_APP 0 /* Clock enable set to use for the application */
186 #define LRF_CLK_ENA_RCL 1 /* Clock enable set to use by the RCL */
187 
188 /* The definition below ensures an invalid value runtime and a warning compiletime */
189 #define __ERROR_Address_is_in_an_invalid_range_for_LRF_setup 0x00040000
190 
191 #define _ADDRESS_REGION_BIT(_address) \
192  ((((((uintptr_t)(_address)) >= (LRF_BASE_ADDR)) && \
193  ((uintptr_t)(_address)) < ((LRF_BASE_ADDR) + 0x10000)) ? 0 : \
194  ((((uintptr_t)(_address)) >= (PBE_RAM_BASE_ADDR)) && \
195  (((uintptr_t)(_address)) < ((PBE_RAM_BASE_ADDR) + 0x10000)) ? \
196  1 : \
197  (((((uintptr_t)(_address)) >= 0) && \
198  (((uintptr_t)(_address)) < 0x10000)) ? \
199  2 : \
200  (__ERROR_Address_is_in_an_invalid_range_for_LRF_setup)))) << 14)
201 
202 #define LRF_SETTINGS_CLEAR(_startAddress, _numWords) \
203  ((((_numWords) - 1) & 0x0FFF) | \
204  _ADDRESS_REGION_BIT(_startAddress) | \
205  ((((uintptr_t)(_startAddress)) & 0xFFFF) << 16))
206 
207 #define LRF_SETTINGS_16BIT_BLOCK(_startAddress, _numWords) \
208  ((((_numWords) - 1) & 0x0FFF) | \
209  _ADDRESS_REGION_BIT(_startAddress) | (1 << 12) | \
210  ((((uintptr_t)(_startAddress)) & 0xFFFF) << 16))
211 
212 #define LRF_SETTINGS_16BIT_DUAL_ENTRY(_value0, _value1) \
213  (((_value0) & 0xFFFF) | (((_value1) & 0xFFFF) << 16))
214 
215 #define LRF_SETTINGS_32BIT_BLOCK(_startAddress, _numWords) \
216  ((((_numWords) - 1) & 0x0FFF) | \
217  _ADDRESS_REGION_BIT(_startAddress) | (2 << 12) | \
218  ((((uintptr_t)(_startAddress)) & 0xFFFF) << 16))
219 
220 #define LRF_SETTINGS_16BIT_SPARSE_BLOCK(_startAddress, _numWords) \
221  ((((_numWords) - 1) & 0x0FFF) | \
222  _ADDRESS_REGION_BIT(_startAddress) | (3 << 12)) \
223 
224 #define LRF_SETTINGS_16BIT_SPARSE_ENTRY(_address, _value) \
225  (((((uintptr_t)(_address)) & 0xFFFF) << 16) | ((_value) & 0xFFFF))
226 
227 #define LRF_SETTINGS_16BIT_MASKED_BLOCK(_startAddress, _numWords) \
228  ((((_numWords) - 1) & 0x0FFF) | (11 << 12) | \
229  ((((uintptr_t)(_startAddress)) & 0xFFFF) << 16))
230 
231 #define LRF_SETTINGS_16BIT_MASKED_ENTRY(_mask, _value) \
232  ((((_mask) & 0xFFFF) << 16) | ((_value) & 0xFFFF))
233 
234 LRF_SetupResult LRF_setupRadio(const LRF_Config *lrfConfig, uint16_t phyFeatures, LRF_RadioState lrfState);
235 
236 LRF_SetupResult LRF_loadImage(const LRF_TOPsmImage *image, uint32_t destinationAddress);
237 
239 {
240 #ifdef BUFFER_SPLIT_SUPPORT
241  state->totalLength = 0;
242 #else
243  (void)state;
244 #endif
245 }
246 
248  LRF_ApplySettingsBase includeBase,
249  uint16_t phyFeatures);
251  LRF_ApplySettingsState *state,
252  int32_t bufferAvailWords);
253 
254 void LRF_enable(void);
255 void LRF_disable(void);
256 void LRF_powerDown(void);
257 void LRF_sendHardStop(void);
259 void LRF_hardStop(void);
260 
261 void LRF_waitForTopsmReady(void);
262 uint32_t LRF_prepareRxFifo(void);
263 uint32_t LRF_prepareTxFifo(void);
264 uint32_t LRF_peekRxFifo(int32_t offset);
265 uint32_t LRF_peekTxFifo(int32_t offset);
266 uint8_t *LRF_getTxFifoWrAddr(int32_t offset);
267 void LRF_skipTxFifoWords(uint32_t wordLength);
268 void LRF_discardRxFifoWords(uint32_t wordLength);
269 void LRF_readRxFifoWords(uint32_t *data32, uint32_t wordLength);
270 void LRF_writeTxFifoWords(const uint32_t *data32, uint32_t wordLength);
271 void LRF_setRxFifoEffSz(uint32_t maxSz);
272 void LRF_programFrequency(uint32_t frequency, bool tx);
273 uint32_t LRF_enableSynthRefsys(void);
274 void LRF_disableSynthRefsys(void);
275 void LRF_setClockEnable(uint16_t mask, uint8_t entryNumber);
276 void LRF_clearClockEnable(uint16_t mask, uint8_t entryNumber);
277 int8_t LRF_readRssi(void);
278 void LRF_setRawTxPower(uint32_t value, uint32_t temperatureCoefficient);
280 bool LRF_imagesNeedUpdate(const LRF_Config *lrfConfig);
281 
294 
295 void LRF_rclEnableRadioClocks(void);
296 void LRF_rclDisableRadioClocks(void);
297 
298 static inline void LRF_setAppClockEnable(uint16_t mask)
299 {
301 }
302 
303 static inline void LRF_clearAppClockEnable(uint16_t mask)
304 {
306 }
307 
308 extern uint32_t swParamList[];
309 extern const size_t swParamListSz;
310 
311 #endif
PBE_RAM_BASE_ADDR
#define PBE_RAM_BASE_ADDR
Definition: LRFCC23X0.h:464
LRF_readRxFifoWords
void LRF_readRxFifoWords(uint32_t *data32, uint32_t wordLength)
Definition: LRFCC23X0.c:716
LRF_disableSynthRefsys
void LRF_disableSynthRefsys(void)
Definition: LRFCC23X0.c:1198
LRF_clearClockEnable
void LRF_clearClockEnable(uint16_t mask, uint8_t entryNumber)
Definition: LRFCC23X0.c:1213
swParamListSz
const size_t swParamListSz
Definition: LRFCC23X0.c:73
RadioState_Down
@ RadioState_Down
Definition: LRF.h:87
Par_Reference_32bit
@ Par_Reference_32bit
Definition: LRF.h:151
LRF_RegionOperation_Invalid
@ LRF_RegionOperation_Invalid
Definition: LRF.h:155
TOPSM_RAM_SZ
#define TOPSM_RAM_SZ
Definition: LRFCC23X0.h:469
LRF_clearAppClockEnable
static void LRF_clearAppClockEnable(uint16_t mask)
Definition: LRF.h:303
LRF_peekRxFifo
uint32_t LRF_peekRxFifo(int32_t offset)
Definition: LRFCC23X0.c:657
LRF_TxPower_Use_Min
#define LRF_TxPower_Use_Min
Definition: LRF.h:55
Par_Write_32bit
@ Par_Write_32bit
Definition: LRF.h:152
LRF_setAppClockEnable
static void LRF_setAppClockEnable(uint16_t mask)
Definition: LRF.h:298
LRF_TxPowerTable_findValue
LRF_TxPowerTable_Entry LRF_TxPowerTable_findValue(const LRF_TxPowerTable *table, LRF_TxPowerTable_Index powerLevel)
Search for settings corresponding to the highest tx power lower than specified value in the tx power ...
Definition: LRF.c:668
LRF_BASE_ADDR
#define LRF_BASE_ADDR
Definition: LRFCC23X0.h:463
LRF_TxPowerTable_Index
Index of the tx power table.
Definition: LRFCC23X0.h:153
SW_Write_32bit
@ SW_Write_32bit
Definition: LRF.h:148
LRF_TxPowerTable::numEntries
uint32_t numEntries
Definition: LRFCC23X0.h:185
LRF_TOPsmImage_s::imageLen
uint32_t imageLen
Definition: LRF.h:108
LRF_enable
void LRF_enable(void)
Definition: LRFCC23X0.c:572
LRF_imagesNeedUpdate
bool LRF_imagesNeedUpdate(const LRF_Config *lrfConfig)
Definition: LRFCC23X0.c:184
LRF_prepareRxFifo
uint32_t LRF_prepareRxFifo(void)
Definition: LRFCC23X0.c:627
LRF_loadImage
LRF_SetupResult LRF_loadImage(const LRF_TOPsmImage *image, uint32_t destinationAddress)
Definition: LRF.c:46
LRF_resetSettingsState
static void LRF_resetSettingsState(LRF_ApplySettingsState *state)
Definition: LRF.h:238
LRF_getTxFifoWrAddr
uint8_t * LRF_getTxFifoWrAddr(int32_t offset)
Definition: LRFCC23X0.c:681
SetupResult_ErrorImageLen
@ SetupResult_ErrorImageLen
Definition: LRF.h:98
LRF.h
HW_Write_16bit_sparse
@ HW_Write_16bit_sparse
Definition: LRF.h:145
LRF_TxPowerTable_Entry::power
LRF_TxPowerTable_Index power
Definition: LRFCC23X0.h:166
LRF_SetupResult
LRF_SetupResult
Setup operation result.
Definition: LRF.h:95
HW_Region_Clear
@ HW_Region_Clear
Definition: LRF.h:142
RCL_Command.h
LRF_sendGracefulStop
void LRF_sendGracefulStop(void)
LRF_disable
void LRF_disable(void)
Definition: LRFCC23X0.c:594
LRF_discardRxFifoWords
void LRF_discardRxFifoWords(uint32_t wordLength)
Definition: LRFCC23X0.c:703
LRFCC23X0.h
LRF_ApplySettingsState
Definition: LRF.h:163
LRF_CLK_ENA_APP
#define LRF_CLK_ENA_APP
Definition: LRF.h:185
SetupResult_Ok
@ SetupResult_Ok
Definition: LRF.h:96
LRF_enableSynthRefsys
uint32_t LRF_enableSynthRefsys(void)
Definition: LRFCC23X0.c:1173
LRF_TxPowerTable::powerTable
LRF_TxPowerTable_Entry powerTable[]
Definition: LRFCC23X0.h:186
RCL_Debug_assert
#define RCL_Debug_assert(expr)
Definition: RCL_Debug.h:39
LRF_ConfigWord::sparse
struct LRF_ConfigWord::@58 sparse
LRF_applySettings
LRF_SetupResult LRF_applySettings(LRF_ConfigWord *config, LRF_ApplySettingsState *state, int32_t bufferAvailWords)
Definition: LRF.c:118
LRF_ConfigWord::segment
struct LRF_ConfigWord::@60 segment
LRF_ConfigWord::value16
uint16_t value16[2]
Definition: LRF.h:119
LRF_writeTxFifoWords
void LRF_writeTxFifoWords(const uint32_t *data32, uint32_t wordLength)
Definition: LRFCC23X0.c:723
SetupResult_ErrorElemAddrAlign
@ SetupResult_ErrorElemAddrAlign
Definition: LRF.h:102
LRF_TxPowerEntry_INVALID_VALUE
#define LRF_TxPowerEntry_INVALID_VALUE
Definition: LRFCC23X0.h:172
LRF_ConfigWord
Definition: LRF.h:112
Par_Region_Clear
@ Par_Region_Clear
Definition: LRF.h:150
LRF_TxPower_Use_Raw
#define LRF_TxPower_Use_Raw
Definition: LRF.h:65
HW_Write_16bit
@ HW_Write_16bit
Definition: LRF.h:143
swParamList
uint32_t swParamList[]
Definition: LRFCC23X0.c:72
RadioState_ImagesLoaded
@ RadioState_ImagesLoaded
Definition: LRF.h:88
LRF_RadioState
LRF_RadioState
Definition: LRF.h:86
LRF_ConfigWord::value32
uint32_t value32
Definition: LRF.h:118
LRF_hardStop
void LRF_hardStop(void)
LRF_setRxFifoEffSz
void LRF_setRxFifoEffSz(uint32_t maxSz)
Definition: LRFCC23X0.c:731
LRF_TOPsmImage_s::image
uint32_t image[]
Definition: LRF.h:109
MAX_REG_CONFIG_LEN
#define MAX_REG_CONFIG_LEN
Definition: LRFCC23X0.h:470
LRF_TxPowerTable
Tx power table, containing all characterized dBm to register settings mappings.
Definition: LRFCC23X0.h:184
SW_Write_16bit
@ SW_Write_16bit
Definition: LRF.h:147
LRF_setupRadio
LRF_SetupResult LRF_setupRadio(const LRF_Config *lrfConfig, uint16_t phyFeatures, LRF_RadioState lrfState)
Definition: LRFCC23X0.c:88
RCL_Debug.h
LRF_setRawTxPower
void LRF_setRawTxPower(uint32_t value, uint32_t temperatureCoefficient)
Definition: LRFCC23X0.c:1266
LRF_ApplySettingsBase
LRF_ApplySettingsBase
Definition: LRF.h:158
SetupResult_ErrorParRange
@ SetupResult_ErrorParRange
Definition: LRF.h:103
LRF_readRssi
int8_t LRF_readRssi(void)
Definition: LRFCC23X0.c:1261
LRF_powerDown
void LRF_powerDown(void)
LRF_ApplySettings_IncludeBase
@ LRF_ApplySettings_IncludeBase
Definition: LRF.h:160
SetupResult_ErrorElemType
@ SetupResult_ErrorElemType
Definition: LRF.h:101
LRF_getRawTxPower
LRF_TxPowerTable_Entry LRF_getRawTxPower(void)
Definition: LRFCC23X0.c:1273
LRF_RegConfigList_s::entries
LRF_ConfigWord * entries[]
Definition: LRF.h:138
LRF_initSettingsState
void LRF_initSettingsState(LRF_ApplySettingsState *state, LRF_ApplySettingsBase includeBase, uint16_t phyFeatures)
Definition: LRF.c:109
HW_Write_16bit_masked
@ HW_Write_16bit_masked
Definition: LRF.h:153
SetupResult_ErrorElemLen
@ SetupResult_ErrorElemLen
Definition: LRF.h:100
LRF_rclDisableRadioClocks
void LRF_rclDisableRadioClocks(void)
Definition: LRFCC23X0.c:1248
LRF_skipTxFifoWords
void LRF_skipTxFifoWords(uint32_t wordLength)
Definition: LRFCC23X0.c:692
LRF_rclEnableRadioClocks
void LRF_rclEnableRadioClocks(void)
Definition: LRFCC23X0.c:1235
LRF_TxPowerTable_findValue
LRF_TxPowerTable_Entry LRF_TxPowerTable_findValue(const LRF_TxPowerTable *table, LRF_TxPowerTable_Index powerLevel)
Search for settings corresponding to the highest tx power lower than specified value in the tx power ...
Definition: LRF.c:668
HW_Write_32bit
@ HW_Write_32bit
Definition: LRF.h:144
LRF_setClockEnable
void LRF_setClockEnable(uint16_t mask, uint8_t entryNumber)
Definition: LRFCC23X0.c:1204
SetupResult_Ok_Partial
@ SetupResult_Ok_Partial
Definition: LRF.h:97
LRF_ApplySettingsState::phyFeatures
uint16_t phyFeatures
Definition: LRF.h:165
LRF_ConfigWord::masked
struct LRF_ConfigWord::@59 masked
LRF_prepareTxFifo
uint32_t LRF_prepareTxFifo(void)
Definition: LRFCC23X0.c:643
LRF_ConfigWord::region
struct LRF_ConfigWord::@57 region
LRF_RegConfigList_s
Definition: LRF.h:136
LRF_RegionOperation_Skip
@ LRF_RegionOperation_Skip
Definition: LRF.h:154
LRF_waitForTopsmReady
void LRF_waitForTopsmReady(void)
Definition: LRFCC23X0.c:618
LRF_programFrequency
void LRF_programFrequency(uint32_t frequency, bool tx)
Definition: LRFCC23X0.c:1084
LRF_ApplySettings_NoBase
@ LRF_ApplySettings_NoBase
Definition: LRF.h:159
LRF_RegConfigList_s::numEntries
uint32_t numEntries
Definition: LRF.h:137
RadioState_Configured
@ RadioState_Configured
Definition: LRF.h:89
LRF_RegionOperation
LRF_RegionOperation
Definition: LRF.h:141
LRF_TOPsmImage_s
Definition: LRF.h:107
LRF_TxPowerTable_Index::rawValue
int8_t rawValue
Definition: LRFCC23X0.h:158
LRF_ApplySettingsState::includeBase
LRF_ApplySettingsBase includeBase
Definition: LRF.h:166
LRF_sendHardStop
void LRF_sendHardStop(void)
LRF_peekTxFifo
uint32_t LRF_peekTxFifo(int32_t offset)
Definition: LRFCC23X0.c:670
SetupResult_ErrorSwConfig
@ SetupResult_ErrorSwConfig
Definition: LRF.h:104
LRF_initSettingsState
void LRF_initSettingsState(LRF_ApplySettingsState *state, LRF_ApplySettingsBase includeBase, uint16_t phyFeatures)
Definition: LRF.c:109
SetupResult_ErrorConfigLen
@ SetupResult_ErrorConfigLen
Definition: LRF.h:99
LRF_TxPower_Use_Max
#define LRF_TxPower_Use_Max
Definition: LRF.h:60
LRF_Config
Radio configuration structure.
Definition: LRFCC23X0.h:456
LRF_TxPowerTable_Entry
Single entry of the tx power table. Maps power in dBm to specific register settings.
Definition: LRFCC23X0.h:165
LRF_applySettings
LRF_SetupResult LRF_applySettings(LRF_ConfigWord *config, LRF_ApplySettingsState *state, int32_t bufferAvailWords)
Definition: LRF.c:118
SW_Region_Clear
@ SW_Region_Clear
Definition: LRF.h:146
SW_Write_16bit_sparse
@ SW_Write_16bit_sparse
Definition: LRF.h:149
LRF_loadImage
LRF_SetupResult LRF_loadImage(const LRF_TOPsmImage *image, uint32_t destinationAddress)
Definition: LRF.c:46