Radio Control Layer (RCL)
LRF.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2025, 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 ti_drivers_rcl_LRF__include
34 #define ti_drivers_rcl_LRF__include
35 
36 #include <stdint.h>
37 #include <stddef.h>
38 #include <stdbool.h>
41 
46 #define LRF_TxPower_Use_Min ((LRF_TxPowerTable_Index){.rawValue = -128})
47 
51 #define LRF_TxPower_Use_Max ((LRF_TxPowerTable_Index){.rawValue = 125})
52 
56 #define LRF_TxPower_Use_Raw ((LRF_TxPowerTable_Index){.rawValue = 126})
57 
62 #define LRF_TxPower_None ((LRF_TxPowerTable_Index){.rawValue = 127})
63 
68 #define LRF_SETTINGS_BUFFER_UNLIMITED 0x3FFF
69 
74 #define LRF_RSSI_INVALID (127)
75 
76 
77 typedef enum LRF_RadioState_e {
79  RadioState_ImagesLoaded, /* TOPsm images loaded, persists */
80  RadioState_Configured, /* REGBANK values loaded, no persist */
82 
86 typedef enum LRF_SetupResult_e {
97 
99  uint32_t imageLen;
100  uint32_t image[];
101 };
102 
103 typedef union {
104  struct {
105  uint32_t lengthMinus1 : 12;
106  uint32_t type : 4;
107  uint32_t startAddress : 16;
108  } region;
109  uint32_t value32;
110  uint16_t value16[2];
111  struct {
112  uint16_t value16;
113  uint16_t address;
114  } sparse;
115  struct {
116  uint16_t value16;
117  uint16_t mask16;
118  } masked;
119  struct {
120  uint32_t length : 14;
121  uint32_t invertedFeatureMask : 1;
122  uint32_t compoundSegment : 1;
123  uint32_t featureMask : 16;
124  } segment;
126 
128  uint32_t numEntries;
129  LRF_ConfigWord *entries[];
130 };
131 
132 typedef enum {
148 
149 typedef enum {
153 
154 typedef struct {
155  /* Settings */
156  uint16_t phyFeatures;
158 
159 #ifdef BUFFER_SPLIT_SUPPORT
160  /* State variables */
161  bool started;
162  int32_t totalLength;
163  uint32_t segmentLength;
164 
165  /* State variables for region */
166  uintptr_t address;
167  LRF_RegionOperation operation;
168  uint32_t regionLength;
169  uint32_t regionStart;
170 #endif
172 
173 #define LRF_PhyFeatures_Default 0
174 
175 /* The definition below ensures an invalid value runtime and a warning compiletime */
176 #define __ERROR_Address_is_in_an_invalid_range_for_LRF_setup 0x00040000
177 
178 #define _ADDRESS_REGION_BIT(_address) \
179  ((((((uintptr_t)(_address)) >= (LRF_BASE_ADDR)) && \
180  ((uintptr_t)(_address)) < ((LRF_BASE_ADDR) + 0x10000)) ? 0 : \
181  ((((uintptr_t)(_address)) >= (PBE_RAM_BASE_ADDR)) && \
182  (((uintptr_t)(_address)) < ((PBE_RAM_BASE_ADDR) + 0x10000)) ? \
183  1 : \
184  (((((uintptr_t)(_address)) >= 0) && \
185  (((uintptr_t)(_address)) < 0x10000)) ? \
186  2 : \
187  (__ERROR_Address_is_in_an_invalid_range_for_LRF_setup)))) << 14)
188 
189 #define LRF_SETTINGS_CLEAR(_startAddress, _numWords) \
190  ((((_numWords) - 1) & 0x0FFF) | \
191  _ADDRESS_REGION_BIT(_startAddress) | \
192  ((((uintptr_t)(_startAddress)) & 0xFFFF) << 16))
193 
194 #define LRF_SETTINGS_16BIT_BLOCK(_startAddress, _numWords) \
195  ((((_numWords) - 1) & 0x0FFF) | \
196  _ADDRESS_REGION_BIT(_startAddress) | (1 << 12) | \
197  ((((uintptr_t)(_startAddress)) & 0xFFFF) << 16))
198 
199 #define LRF_SETTINGS_16BIT_DUAL_ENTRY(_value0, _value1) \
200  (((_value0) & 0xFFFF) | (((_value1) & 0xFFFF) << 16))
201 
202 #define LRF_SETTINGS_32BIT_BLOCK(_startAddress, _numWords) \
203  ((((_numWords) - 1) & 0x0FFF) | \
204  _ADDRESS_REGION_BIT(_startAddress) | (2 << 12) | \
205  ((((uintptr_t)(_startAddress)) & 0xFFFF) << 16))
206 
207 #define LRF_SETTINGS_16BIT_SPARSE_BLOCK(_startAddress, _numWords) \
208  ((((_numWords) - 1) & 0x0FFF) | \
209  _ADDRESS_REGION_BIT(_startAddress) | (3 << 12)) \
210 
211 #define LRF_SETTINGS_16BIT_SPARSE_ENTRY(_address, _value) \
212  (((((uintptr_t)(_address)) & 0xFFFF) << 16) | ((_value) & 0xFFFF))
213 
214 #define LRF_SETTINGS_16BIT_MASKED_BLOCK(_startAddress, _numWords) \
215  ((((_numWords) - 1) & 0x0FFF) | (11 << 12) | \
216  ((((uintptr_t)(_startAddress)) & 0xFFFF) << 16))
217 
218 #define LRF_SETTINGS_16BIT_MASKED_ENTRY(_mask, _value) \
219  ((((_mask) & 0xFFFF) << 16) | ((_value) & 0xFFFF))
220 
221 LRF_SetupResult LRF_setupRadio(const LRF_Config *lrfConfig, uint16_t phyFeatures, LRF_RadioState lrfState);
222 
223 LRF_SetupResult LRF_loadImage(const LRF_TOPsmImage *image, uint32_t destinationAddress);
224 
226 {
227 #ifdef BUFFER_SPLIT_SUPPORT
228  state->totalLength = 0;
229 #else
230  (void)state;
231 #endif
232 }
233 
235  LRF_ApplySettingsBase includeBase,
236  uint16_t phyFeatures);
238  LRF_ApplySettingsState *state,
239  int32_t bufferAvailWords);
240 
241 void LRF_enable(void);
242 void LRF_disable(void);
243 void LRF_powerDown(void);
244 void LRF_sendHardStop(void);
245 void LRF_sendGracefulStop(void);
246 void LRF_hardStop(void);
247 void LRF_waitForTopsmReady(void);
248 uint32_t LRF_prepareTxFifo(void);
249 uint32_t LRF_getTxFifoWritable(void);
250 uint32_t LRF_peekTxFifo(int32_t offset);
251 uint8_t *LRF_getTxFifoWrAddr(int32_t offset);
252 void LRF_retryTxFifo(void);
253 void LRF_skipTxFifoWords(uint32_t wordLength);
254 void LRF_writeTxFifoWords(const uint32_t *data32, uint32_t wordLength);
255 void LRF_resetTxFifo(void);
256 void LRF_deallocateTxFifo(void);
257 uint32_t LRF_prepareRxFifo(void);
258 bool LRF_hasRxWordToRead(void);
259 void LRF_readRxFifoWords(uint32_t *data32, uint32_t wordLength);
260 uint32_t LRF_peekRxFifo(int32_t offset);
261 void LRF_discardRxFifoWords(uint32_t wordLength);
262 void LRF_setRxFifoEffSz(uint32_t maxSz);
263 void LRF_peekRxFifoWords(uint32_t *data32, uint32_t wordLength, uint32_t startRp);
264 uint32_t LRF_getUncommittedFifoStatus(uint32_t *currentRp);
265 void LRF_resetRxFifo(void);
266 void LRF_programFrequency(uint32_t frequency, bool tx);
267 uint32_t LRF_enableSynthRefsys(void);
268 void LRF_disableSynthRefsys(void);
269 void LRF_setClockEnable(uint16_t mask, uint8_t entryNumber);
270 void LRF_clearClockEnable(uint16_t mask, uint8_t entryNumber);
271 int8_t LRF_readRssi(void);
272 void LRF_setRawTxPower(uint32_t value, uint32_t temperatureCoefficient);
274 bool LRF_imagesNeedUpdate(const LRF_Config *lrfConfig);
275 
287 LRF_TxPowerTable_Entry LRF_TxPowerTable_findValueExtended(const LRF_TxPowerTable *table, LRF_TxPowerTable_Index powerLevel, bool roundUp, bool returnBoundaryOnOutOfRange);
288 
289 void LRF_rclEnableRadioClocks(void);
290 void LRF_rclDisableRadioClocks(void);
291 
304 {
305  return LRF_TxPowerTable_findValueExtended(table, powerLevel, false, false);
306 }
307 
308 static inline void LRF_enableHwInterrupt(uint32_t mask)
309 {
311 }
312 
313 static inline void LRF_disableHwInterrupt(uint32_t mask)
314 {
316 }
317 
318 static inline void LRF_clearHwInterrupt(uint32_t mask)
319 {
321 }
322 
323 extern uint32_t swParamList[];
324 extern const size_t swParamListSz;
325 
326 #endif /* ti_drivers_rcl_LRF__include */
int8_t LRF_readRssi(void)
Definition: LRFLPF3.c:1382
Definition: LRF.h:133
void LRF_rclEnableRadioClocks(void)
Definition: LRFLPF3.c:1358
Definition: LRF.h:146
Definition: LRF.h:143
Definition: LRF.h:78
void LRF_setClockEnable(uint16_t mask, uint8_t entryNumber)
Definition: LRF.h:98
static void LRF_resetSettingsState(LRF_ApplySettingsState *state)
Definition: LRF.h:225
Definition: LRF.h:141
LRF_SetupResult LRF_loadImage(const LRF_TOPsmImage *image, uint32_t destinationAddress)
Definition: LRF.c:46
bool LRF_hasRxWordToRead(void)
Definition: LRFLPF3_FIFO.c:384
Index of the tx power table.
Definition: LRFLPF3.h:170
Definition: LRF.h:134
LRF_RadioState
Definition: LRF.h:77
Definition: LRF.h:150
LRF_SetupResult
Setup operation result.
Definition: LRF.h:86
void LRF_sendHardStop(void)
LRF_SetupResult LRF_setupRadio(const LRF_Config *lrfConfig, uint16_t phyFeatures, LRF_RadioState lrfState)
void LRF_deallocateTxFifo(void)
uint32_t LRF_getTxFifoWritable(void)
Definition: LRFLPF3_FIFO.c:70
void LRF_sendGracefulStop(void)
static 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.h:303
LRF_TxPowerTable_Entry LRF_TxPowerTable_findValueExtended(const LRF_TxPowerTable *table, LRF_TxPowerTable_Index powerLevel, bool roundUp, bool returnBoundaryOnOutOfRange)
Search for settings corresponding to tx power in the tx power table with extended options...
Definition: LRF.c:761
void LRF_discardRxFifoWords(uint32_t wordLength)
Definition: LRFLPF3_FIFO.c:192
void LRF_peekRxFifoWords(uint32_t *data32, uint32_t wordLength, uint32_t startRp)
Definition: LRFLPF3_FIFO.c:313
Definition: LRF.h:94
Definition: LRF.h:135
Definition: LRF.h:151
uint32_t value32
Definition: LRF.h:109
Definition: LRF.h:127
uint32_t image[]
Definition: LRF.h:100
void RCL_Hal_clearCommandRadioInterrupt(uint32_t mask)
Definition: RCLLPF3_Hal.c:367
void LRF_writeTxFifoWords(const uint32_t *data32, uint32_t wordLength)
Definition: LRFLPF3_FIFO.c:240
Definition: LRF.h:87
LRF_SetupResult LRF_applySettings(LRF_ConfigWord *config, LRF_ApplySettingsState *state, int32_t bufferAvailWords)
Definition: LRF.c:158
void LRF_clearClockEnable(uint16_t mask, uint8_t entryNumber)
Definition: LRF.h:139
Definition: LRF.h:140
Definition: LRF.h:154
uint32_t LRF_enableSynthRefsys(void)
Definition: LRFLPF3.c:1328
uint32_t LRF_prepareRxFifo(void)
Definition: LRFLPF3_FIFO.c:353
Radio configuration structure.
Definition: LRFLPF3.h:581
uint8_t * LRF_getTxFifoWrAddr(int32_t offset)
Definition: LRFLPF3_FIFO.c:122
static void LRF_clearHwInterrupt(uint32_t mask)
Definition: LRF.h:318
LRF_ApplySettingsBase
Definition: LRF.h:149
Definition: LRF.h:95
uint32_t imageLen
Definition: LRF.h:99
Definition: LRF.h:88
Definition: LRF.h:145
bool LRF_imagesNeedUpdate(const LRF_Config *lrfConfig)
Definition: LRFLPF3.c:304
Single entry of the tx power table. Maps power in dBm to specific register settings.
Definition: LRFLPF3.h:183
void LRF_hardStop(void)
uint32_t swParamList[]
Definition: LRFLPF3.c:151
static void LRF_disableHwInterrupt(uint32_t mask)
Definition: LRF.h:313
Definition: LRF.h:80
void LRF_setRxFifoEffSz(uint32_t maxSz)
Definition: LRFLPF3_FIFO.c:269
Definition: LRF.h:92
void LRF_powerDown(void)
Definition: LRF.h:137
void LRF_resetRxFifo(void)
Definition: LRF.h:103
void LRF_disable(void)
Definition: LRFLPF3.c:858
void LRF_rclDisableRadioClocks(void)
Definition: LRFLPF3.c:1370
Definition: LRF.h:142
void LRF_programFrequency(uint32_t frequency, bool tx)
Definition: LRFLPF3.c:1239
static void LRF_enableHwInterrupt(uint32_t mask)
Definition: LRF.h:308
Definition: LRF.h:136
uint32_t LRF_getUncommittedFifoStatus(uint32_t *currentRp)
Definition: LRFLPF3_FIFO.c:329
void LRF_disableSynthRefsys(void)
Definition: LRFLPF3.c:1353
Tx power table, containing all characterized dBm to register settings mappings.
Definition: LRFLPF3.h:202
const size_t swParamListSz
Definition: LRFLPF3.c:152
Definition: LRF.h:89
void LRF_resetTxFifo(void)
void RCL_Hal_disableCommandRadioInterrupt(uint32_t mask)
Definition: RCLLPF3_Hal.c:372
uint16_t phyFeatures
Definition: LRF.h:156
void LRF_retryTxFifo(void)
Definition: LRFLPF3_FIFO.c:375
void LRF_initSettingsState(LRF_ApplySettingsState *state, LRF_ApplySettingsBase includeBase, uint16_t phyFeatures)
Definition: LRF.c:149
uint32_t LRF_prepareTxFifo(void)
Definition: LRFLPF3_FIFO.c:78
Definition: LRF.h:90
void LRF_waitForTopsmReady(void)
Definition: LRFLPF3.c:886
void LRF_enable(void)
Definition: LRFLPF3.c:833
uint32_t numEntries
Definition: LRF.h:128
Definition: LRF.h:79
Definition: LRF.h:93
void LRF_setRawTxPower(uint32_t value, uint32_t temperatureCoefficient)
Definition: LRFLPF3.c:1397
uint32_t LRF_peekTxFifo(int32_t offset)
Definition: LRFLPF3_FIFO.c:108
LRF_ApplySettingsBase includeBase
Definition: LRF.h:157
void LRF_readRxFifoWords(uint32_t *data32, uint32_t wordLength)
Definition: LRFLPF3_FIFO.c:209
Definition: LRF.h:144
Definition: LRF.h:91
LRF_RegionOperation
Definition: LRF.h:132
void RCL_Hal_enableCommandRadioInterrupt(uint32_t mask)
Definition: RCLLPF3_Hal.c:361
LRF_TxPowerTable_Entry LRF_getRawTxPower(void)
Definition: LRFLPF3.c:1404
Definition: LRF.h:138
void LRF_skipTxFifoWords(uint32_t wordLength)
Definition: LRFLPF3_FIFO.c:178
uint32_t LRF_peekRxFifo(int32_t offset)
Definition: LRFLPF3_FIFO.c:94