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) || defined(DeviceFamily_CC27XX)
41 # include <ti/devices/DeviceFamily.h>
42 # include DeviceFamily_constructPath(inc/hw_types.h)
43 # include DeviceFamily_constructPath(inc/hw_lrfdpbe.h)
45 #endif
46 
47 #ifdef DeviceFamily_CC1308
48 # define BUFFER_SPLIT_SUPPORT
49 # include "LRFCC1308.h"
50 #endif
51 
56 #define LRF_TxPower_Use_Min ((LRF_TxPowerTable_Index){.rawValue = -128})
57 
61 #define LRF_TxPower_Use_Max ((LRF_TxPowerTable_Index){.rawValue = 125})
62 
66 #define LRF_TxPower_Use_Raw ((LRF_TxPowerTable_Index){.rawValue = 126})
67 
72 #define LRF_TxPower_None ((LRF_TxPowerTable_Index){.rawValue = 127})
73 
78 #define LRF_SETTINGS_BUFFER_UNLIMITED 0x3FFF
79 
84 #define LRF_RSSI_INVALID (127)
85 
86 
87 typedef enum LRF_RadioState_e {
89  RadioState_ImagesLoaded, /* TOPsm images loaded, persists */
90  RadioState_Configured, /* REGBANK values loaded, no persist */
92 
96 typedef enum LRF_SetupResult_e {
107 
109  uint32_t imageLen;
110  uint32_t image[];
111 };
112 
113 typedef union {
114  struct {
115  uint32_t lengthMinus1 : 12;
116  uint32_t type : 4;
117  uint32_t startAddress : 16;
118  } region;
119  uint32_t value32;
120  uint16_t value16[2];
121  struct {
122  uint16_t value16;
123  uint16_t address;
124  } sparse;
125  struct {
126  uint16_t value16;
127  uint16_t mask16;
128  } masked;
129  struct {
130  uint32_t length : 14;
131  uint32_t invertedFeatureMask : 1;
132  uint32_t compoundSegment : 1;
133  uint32_t featureMask : 16;
134  } segment;
136 
138  uint32_t numEntries;
139  LRF_ConfigWord *entries[];
140 };
141 
142 typedef enum {
158 
159 typedef enum {
163 
164 typedef struct {
165  /* Settings */
166  uint16_t phyFeatures;
168 
169 #ifdef BUFFER_SPLIT_SUPPORT
170  /* State variables */
171  bool started;
172  int32_t totalLength;
173  uint32_t segmentLength;
174 
175  /* State variables for region */
176  uintptr_t address;
177  LRF_RegionOperation operation;
178  uint32_t regionLength;
179  uint32_t regionStart;
180 #endif
182 
183 #define LRF_PhyFeatures_Default 0
184 
185 #define LRF_NUM_CLK_ENA 2 /* Number of clock enable sets */
186 #define LRF_CLK_ENA_APP 0 /* Clock enable set to use for the application */
187 #define LRF_CLK_ENA_RCL 1 /* Clock enable set to use by the RCL */
188 
189 /* The definition below ensures an invalid value runtime and a warning compiletime */
190 #define __ERROR_Address_is_in_an_invalid_range_for_LRF_setup 0x00040000
191 
192 #define _ADDRESS_REGION_BIT(_address) \
193  ((((((uintptr_t)(_address)) >= (LRF_BASE_ADDR)) && \
194  ((uintptr_t)(_address)) < ((LRF_BASE_ADDR) + 0x10000)) ? 0 : \
195  ((((uintptr_t)(_address)) >= (PBE_RAM_BASE_ADDR)) && \
196  (((uintptr_t)(_address)) < ((PBE_RAM_BASE_ADDR) + 0x10000)) ? \
197  1 : \
198  (((((uintptr_t)(_address)) >= 0) && \
199  (((uintptr_t)(_address)) < 0x10000)) ? \
200  2 : \
201  (__ERROR_Address_is_in_an_invalid_range_for_LRF_setup)))) << 14)
202 
203 #define LRF_SETTINGS_CLEAR(_startAddress, _numWords) \
204  ((((_numWords) - 1) & 0x0FFF) | \
205  _ADDRESS_REGION_BIT(_startAddress) | \
206  ((((uintptr_t)(_startAddress)) & 0xFFFF) << 16))
207 
208 #define LRF_SETTINGS_16BIT_BLOCK(_startAddress, _numWords) \
209  ((((_numWords) - 1) & 0x0FFF) | \
210  _ADDRESS_REGION_BIT(_startAddress) | (1 << 12) | \
211  ((((uintptr_t)(_startAddress)) & 0xFFFF) << 16))
212 
213 #define LRF_SETTINGS_16BIT_DUAL_ENTRY(_value0, _value1) \
214  (((_value0) & 0xFFFF) | (((_value1) & 0xFFFF) << 16))
215 
216 #define LRF_SETTINGS_32BIT_BLOCK(_startAddress, _numWords) \
217  ((((_numWords) - 1) & 0x0FFF) | \
218  _ADDRESS_REGION_BIT(_startAddress) | (2 << 12) | \
219  ((((uintptr_t)(_startAddress)) & 0xFFFF) << 16))
220 
221 #define LRF_SETTINGS_16BIT_SPARSE_BLOCK(_startAddress, _numWords) \
222  ((((_numWords) - 1) & 0x0FFF) | \
223  _ADDRESS_REGION_BIT(_startAddress) | (3 << 12)) \
224 
225 #define LRF_SETTINGS_16BIT_SPARSE_ENTRY(_address, _value) \
226  (((((uintptr_t)(_address)) & 0xFFFF) << 16) | ((_value) & 0xFFFF))
227 
228 #define LRF_SETTINGS_16BIT_MASKED_BLOCK(_startAddress, _numWords) \
229  ((((_numWords) - 1) & 0x0FFF) | (11 << 12) | \
230  ((((uintptr_t)(_startAddress)) & 0xFFFF) << 16))
231 
232 #define LRF_SETTINGS_16BIT_MASKED_ENTRY(_mask, _value) \
233  ((((_mask) & 0xFFFF) << 16) | ((_value) & 0xFFFF))
234 
235 LRF_SetupResult LRF_setupRadio(const LRF_Config *lrfConfig, uint16_t phyFeatures, LRF_RadioState lrfState);
236 
237 LRF_SetupResult LRF_loadImage(const LRF_TOPsmImage *image, uint32_t destinationAddress);
238 
240 {
241 #ifdef BUFFER_SPLIT_SUPPORT
242  state->totalLength = 0;
243 #else
244  (void)state;
245 #endif
246 }
247 
249  LRF_ApplySettingsBase includeBase,
250  uint16_t phyFeatures);
252  LRF_ApplySettingsState *state,
253  int32_t bufferAvailWords);
254 
255 void LRF_enable(void);
256 void LRF_disable(void);
257 void LRF_powerDown(void);
258 void LRF_sendHardStop(void);
259 void LRF_sendGracefulStop(void);
260 void LRF_hardStop(void);
261 
262 void LRF_waitForTopsmReady(void);
263 uint32_t LRF_prepareRxFifo(void);
264 uint32_t LRF_prepareTxFifo(void);
265 uint32_t LRF_peekRxFifo(int32_t offset);
266 uint32_t LRF_peekTxFifo(int32_t offset);
267 uint8_t *LRF_getTxFifoWrAddr(int32_t offset);
268 void LRF_skipTxFifoWords(uint32_t wordLength);
269 void LRF_discardRxFifoWords(uint32_t wordLength);
270 void LRF_readRxFifoWords(uint32_t *data32, uint32_t wordLength);
271 void LRF_writeTxFifoWords(const uint32_t *data32, uint32_t wordLength);
272 void LRF_setRxFifoEffSz(uint32_t maxSz);
273 void LRF_programFrequency(uint32_t frequency, bool tx);
274 uint32_t LRF_enableSynthRefsys(void);
275 void LRF_disableSynthRefsys(void);
276 void LRF_setClockEnable(uint16_t mask, uint8_t entryNumber);
277 void LRF_clearClockEnable(uint16_t mask, uint8_t entryNumber);
278 int8_t LRF_readRssi(void);
279 void LRF_setRawTxPower(uint32_t value, uint32_t temperatureCoefficient);
281 bool LRF_imagesNeedUpdate(const LRF_Config *lrfConfig);
282 
295 
296 void LRF_rclEnableRadioClocks(void);
297 void LRF_rclDisableRadioClocks(void);
298 
299 static inline void LRF_setAppClockEnable(uint16_t mask)
300 {
302 }
303 
304 static inline void LRF_clearAppClockEnable(uint16_t mask)
305 {
307 }
308 
309 extern uint32_t swParamList[];
310 extern const size_t swParamListSz;
311 
312 #endif
int8_t LRF_readRssi(void)
Definition: LRFCC23X0.c:1361
#define LRF_CLK_ENA_APP
Definition: LRF.h:186
Definition: LRF.h:143
void LRF_rclEnableRadioClocks(void)
Definition: LRFCC23X0.c:1335
Definition: LRF.h:156
Definition: LRF.h:153
Definition: LRF.h:88
void LRF_setClockEnable(uint16_t mask, uint8_t entryNumber)
Definition: LRFCC23X0.c:1304
Definition: LRF.h:108
static void LRF_resetSettingsState(LRF_ApplySettingsState *state)
Definition: LRF.h:239
Definition: LRF.h:151
LRF_SetupResult LRF_loadImage(const LRF_TOPsmImage *image, uint32_t destinationAddress)
Definition: LRF.c:46
Definition: LRF.h:144
LRF_RadioState
Definition: LRF.h:87
Definition: LRF.h:160
LRF_SetupResult
Setup operation result.
Definition: LRF.h:96
void LRF_sendHardStop(void)
LRF_SetupResult LRF_setupRadio(const LRF_Config *lrfConfig, uint16_t phyFeatures, LRF_RadioState lrfState)
Definition: LRFCC23X0.c:95
Single entry of the tx power table. Maps power in dBm to specific register settings.
Definition: LRFCC23X0.h:185
void LRF_sendGracefulStop(void)
void LRF_discardRxFifoWords(uint32_t wordLength)
Definition: LRFCC23X0.c:758
Definition: LRF.h:104
Definition: LRF.h:145
Definition: LRF.h:161
uint32_t value32
Definition: LRF.h:119
Definition: LRF.h:137
uint32_t image[]
Definition: LRF.h:110
Tx power table, containing all characterized dBm to register settings mappings.
Definition: LRFCC23X0.h:204
void LRF_writeTxFifoWords(const uint32_t *data32, uint32_t wordLength)
Definition: LRFCC23X0.c:794
Definition: LRF.h:97
LRF_SetupResult LRF_applySettings(LRF_ConfigWord *config, LRF_ApplySettingsState *state, int32_t bufferAvailWords)
Definition: LRF.c:118
void LRF_clearClockEnable(uint16_t mask, uint8_t entryNumber)
Definition: LRFCC23X0.c:1313
Index of the tx power table.
Definition: LRFCC23X0.h:172
Definition: LRF.h:149
Radio configuration structure.
Definition: LRFCC23X0.h:476
Definition: LRF.h:150
Definition: LRF.h:164
static void LRF_clearAppClockEnable(uint16_t mask)
Definition: LRF.h:304
uint32_t LRF_enableSynthRefsys(void)
Definition: LRFCC23X0.c:1273
uint32_t LRF_prepareRxFifo(void)
Definition: LRFCC23X0.c:643
static void LRF_setAppClockEnable(uint16_t mask)
Definition: LRF.h:299
uint8_t * LRF_getTxFifoWrAddr(int32_t offset)
Definition: LRFCC23X0.c:697
LRF_ApplySettingsBase
Definition: LRF.h:159
Definition: LRF.h:105
uint32_t imageLen
Definition: LRF.h:109
Definition: LRF.h:98
Definition: LRF.h:155
bool LRF_imagesNeedUpdate(const LRF_Config *lrfConfig)
Definition: LRFCC23X0.c:192
void LRF_hardStop(void)
uint32_t swParamList[]
Definition: LRFCC23X0.c:76
Definition: LRF.h:90
void LRF_setRxFifoEffSz(uint32_t maxSz)
Definition: LRFCC23X0.c:814
Definition: LRF.h:102
void LRF_powerDown(void)
Definition: LRF.h:147
Definition: LRF.h:113
void LRF_disable(void)
Definition: LRFCC23X0.c:610
void LRF_rclDisableRadioClocks(void)
Definition: LRFCC23X0.c:1348
Definition: LRF.h:152
void LRF_programFrequency(uint32_t frequency, bool tx)
Definition: LRFCC23X0.c:1184
Definition: LRF.h:146
void LRF_disableSynthRefsys(void)
Definition: LRFCC23X0.c:1298
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
const size_t swParamListSz
Definition: LRFCC23X0.c:77
Definition: LRF.h:99
uint16_t phyFeatures
Definition: LRF.h:166
void LRF_initSettingsState(LRF_ApplySettingsState *state, LRF_ApplySettingsBase includeBase, uint16_t phyFeatures)
Definition: LRF.c:109
uint32_t LRF_prepareTxFifo(void)
Definition: LRFCC23X0.c:662
Definition: LRF.h:100
void LRF_waitForTopsmReady(void)
Definition: LRFCC23X0.c:634
void LRF_enable(void)
Definition: LRFCC23X0.c:588
uint32_t numEntries
Definition: LRF.h:138
Definition: LRF.h:89
Definition: LRF.h:103
void LRF_setRawTxPower(uint32_t value, uint32_t temperatureCoefficient)
Definition: LRFCC23X0.c:1366
uint32_t LRF_peekTxFifo(int32_t offset)
Definition: LRFCC23X0.c:686
LRF_ApplySettingsBase includeBase
Definition: LRF.h:167
void LRF_readRxFifoWords(uint32_t *data32, uint32_t wordLength)
Definition: LRFCC23X0.c:772
Definition: LRF.h:154
Definition: LRF.h:101
LRF_RegionOperation
Definition: LRF.h:142
LRF_TxPowerTable_Entry LRF_getRawTxPower(void)
Definition: LRFCC23X0.c:1373
Definition: LRF.h:148
void LRF_skipTxFifoWords(uint32_t wordLength)
Definition: LRFCC23X0.c:747
uint32_t LRF_peekRxFifo(int32_t offset)
Definition: LRFCC23X0.c:675