TI BLE5-Stack API Documentation  2.01.03.00
TOF.h
Go to the documentation of this file.
1 /******************************************************************************
2 
3  @file TOF.h
4 
5  @brief This file contains methods to enable/disable and control TOF
6  Group: WCS, BTS
7  $Target Device: DEVICES $
8 
9  ******************************************************************************
10  $License: BSD3 2018 $
11  ******************************************************************************
12  $Release Name: PACKAGE NAME $
13  $Release Date: PACKAGE RELEASE DATE $
14  *****************************************************************************/
15 
26 #ifndef TOF_H_
27 #define TOF_H_
28 
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33 
34 /*********************************************************************
35  * INCLUDES
36  */
37 
38 /* RF includes */
39 #include <ti/drivers/rf/RF.h>
40 
41 #include <ti/devices/DeviceFamily.h>
42 #include "rfc_cmd_tof.h"
43 #include "tof_security.h"
44 
45 /*********************************************************************
46  * CONSTANTS
47  */
48 
49 #define TOF_TIMEOUTVAL 0xFFFFFFFF
50 
51 #define TOF_MAX_NUM_FREQ 20
52 
53 #define TOF_SEEDLEN 32
54 
55 #define TOF_COMPENSATION_NO_COMP 0
56 #define TOF_COMPENSATION_STIM_COMP 1
57 #define TOF_COMPENSATION_CORRELATOR_COMP 2
58 
59 // If using partial result readout or double sync word buffer, these are the event ID's
60 #define IRQN_PARTIAL_READ_READY 15
61 #define IRQN_DOUBLE_SYNCWORD_BUFFER_SWITCH 11
62 #define RF_EventPartialReadReady (1 << IRQN_PARTIAL_READ_READY)
63 #define RF_EventDoubleSyncWordBufferSwitch (1 << IRQN_DOUBLE_SYNCWORD_BUFFER_SWITCH)
64 
65 #define TOF_FILL_BOTH_BUFF TOF_SEC_FILL_BOTH_BUFFS
66 #define TOF_FILL_1ST_BUFF TOF_SEC_FILL_1ST_BUFF
67 #define TOF_FILL_2ND_BUFF TOF_SEC_FILL_2ND_BUFF
68 
69 // The ready-flags for the double buffers
70 #define syncWordBufferOneReady 0x01
71 #define syncWordBufferTwoReady 0x02
72 
73 #define TICK_TO_METER (6.25 * 3)
74 
75 #define TOF_PATCH_LOCATION 0x21000914
76 #define SUCCESS 0x00
77 #define FAILURE 0x01
78 
79 #ifdef USE_TRACER
81 /* tracer configuration */
82 #define CMD_ENABLE_DBG_CMDID 0x602
83 #define CMD_ENABLE_DBG_CONFIG ((0<<14) | (1<<12) | (1<<11) | (2<<9) | (1<<8) | (1<<6))
84 #endif // USE_TRACER
85 
87 /*********************************************************************
88  * MACROS
89  */
90 
91 /*********************************************************************
92  * TYPEDEFS
93  */
94 
99 typedef enum
101 {
102  ToF_ROLE_SLAVE = 0,
103  ToF_ROLE_MASTER,
104  ToF_ROLE_PASSIVE
105 } ToF_Role;
106 
108 typedef enum
109 {
110  TOF_SUCCESS = 0,
111  TOF_FAILED,
112 } TofStatus_e;
113 
115 typedef enum
116 {
117  TOF_SYNC_WAIT_FOR_SYNC = 0,
118  TOF_SYNC_SYNCHRONIZED,
119  TOF_SYNC_OUT_OF_SYNC,
121 
123 typedef enum
124 {
125  TOF_HANDSHAKE_STARTED = 0,
126  TOF_HANDSHAKE_IN_PROGRESS,
127  TOF_HANDSHAKE_RECOVERING,
128  TOF_HANDSHAKE_COMPLETE,
129  TOF_HANDSHAKE_FAILED
131 
133 typedef rfc_CMD_TOF_sample_extended_t ToF_Sample;
134 
136 typedef rfc_CMD_TOF_synthCal_t ToF_SynthCal;
137 
138 typedef uint8_t* ToF_TX_Buf;
139 typedef uint8_t* ToF_RX_Buf;
140 
142 typedef void (*TOF_ApplicationCB)(void);
144 
146 typedef struct
147 {
148  RF_Object rfObject;
149  RF_Handle rfHandle;
150  ToF_Role tofRole;
151  uint8_t numFreqs;
152  uint16_t *pFrequencies;
153  uint8_t freqChangePeriod;
154  ToF_SynthCal synthCal[TOF_MAX_NUM_FREQ];
155  ToF_TX_Buf pTxBuf;
156  ToF_RX_Buf pRxBuf;
157  ToF_Sample *pT1RSSIBuf;
158  uint16_t numSyncwordsPerBurst;
159  uint8_t slaveLqiFilter;
160  uint8_t postProcessLqiThresh;
161  uint16_t postProcessMagnRatio;
162 } ToF_Object, ToF_Struct, *ToF_Handle;
164 
166 typedef struct
167 {
168  ToF_Role tofRole;
169  ToF_Sample *pT1RSSIBuf;
171  uint8_t *pTxBuf;
172  uint8_t *pRxBuf;
173  uint16_t *pFrequencies;
174  uint8_t numFreq;
176  uint8_t mask;
178  uint16_t syncTimeout;
180  uint8_t slaveLqiFilter;
183 } ToF_Params;
184 
186 typedef struct
187 {
188  uint16_t freq;
189  double tick;
190  double tickVariance;
191  uint32_t numOk;
192 } ToF_BurstStat;
193 
195 typedef struct
196 {
197  uint32_t freq;
198  RF_EventMask rfEvent;
199  uint32_t ratSyncTime;
200 } ToF_Status;
201 
203 typedef struct
204 {
205  uint16_t internalCtr;
206  uint16_t lastSharedCtr;
208  uint8_t lastBuffFilled;
209  TofHandshakeState_e handshakeState;
210  TofSyncState_e currentSyncState;
211  broadCast_t tofBroadcast;
212 } ToF_Sync;
213 
214 #ifdef RTLS_TOF_DEBUG
215 typedef struct
217 {
218  uint32_t numRecoveries;
219  uint32_t numSkippedRuns;
220  uint32_t numGoodTofRuns;
221  uint32_t numBadTofRuns;
222  uint32_t totalNumOk;
223  uint32_t totalNumNOk;
224  uint32_t failedHandshakes;
225 } ToF_InternalStatistics;
226 #endif
227 
230 /*-------------------------------------------------------------------
231  * FUNCTIONS
232  */
233 
242 ToF_Handle TOF_open(ToF_Struct *tofStruct, ToF_Params *params);
243 
252 ToF_Status TOF_run(ToF_Handle handle, uint32_t nextTaskTime);
253 
261 void TOF_clearBuffers(ToF_Handle handle);
262 
271 void TOF_getBurstStat(ToF_Handle handle, ToF_BurstStat **resultBuffer);
272 
280 void TOF_close(ToF_Handle handle);
281 
293 int TOF_setSeed(uint8_t* newSeed);
294 
302 uint8_t TOF_getSeed(uint8_t *dst);
303 
311 void TOF_roleSwitch(ToF_Role newRole);
312 
313 
314 /*********************************************************************
315 *********************************************************************/
316 
317 #ifdef __cplusplus
318 }
319 #endif
320 
321 #endif /* TOF_H_ */
322 
TofSyncState_e currentSyncState
Current state of ToF Sync.
Definition: TOF.h:210
TOF Burst Stats Structure.
Definition: TOF.h:195
uint8_t TOF_getSeed(uint8_t *dst)
copy 32 byte seed into dst
RF_EventMask rfEvent
RF Event.
Definition: TOF.h:198
uint8_t * pTxBuf
Pointer to Tx buffer.
Definition: TOF.h:171
ToF_Status TOF_run(ToF_Handle handle, uint32_t nextTaskTime)
Start a ToF run.
int TOF_setSeed(uint8_t *newSeed)
call ToF Security module to restart the ctr drbg new 128-bit random seed
TofHandshakeState_e handshakeState
Holds the state of the Master<->Slave handshake (i.e if Master->Slave Slave->Master Master->Slave exc...
Definition: TOF.h:209
ToF_Handle TOF_open(ToF_Struct *tofStruct, ToF_Params *params)
Initiate RF ToF params and open RF driver.
uint16_t freq
Frequency.
Definition: TOF.h:188
uint8_t mask
Mask for the LFSR.
Definition: TOF.h:176
TOF Parameters Structure.
Definition: TOF.h:166
uint16_t syncTimeout
How long to wait for first sync word.
Definition: TOF.h:178
void TOF_getBurstStat(ToF_Handle handle, ToF_BurstStat **resultBuffer)
Get the result for the last ToF burst (run)
ToF_Role tofRole
Slave or master.
Definition: TOF.h:168
#define TOF_MAX_NUM_FREQ
Maximun number of frequencies.
Definition: TOF.h:51
void TOF_clearBuffers(ToF_Handle handle)
Clean buffers for the specified ToF Handle.
TOF Burst Stats Structure.
Definition: TOF.h:186
uint8_t * ToF_RX_Buf
Pointer to RX buffer.
Definition: TOF.h:139
uint32_t numOk
Number of good samples.
Definition: TOF.h:191
void TOF_roleSwitch(ToF_Role newRole)
Switch ToF role.
ToF_Sample * pT1RSSIBuf
Pointer to T1|RSSI result buffer.
Definition: TOF.h:169
uint16_t numSyncwordsPerBurst
Number of bursts to be made (same as sync word length if using single buffer)
Definition: TOF.h:170
void TOF_close(ToF_Handle handle)
Close the ToF and RF drivers.
uint8_t freqChangePeriod
How often should we change freq?
Definition: TOF.h:177
uint8_t slaveLqiFilter
Automatic filtering for ToF Slave role.
Definition: TOF.h:180
ToF_Role
Enumeration for TOF roles of operation.
Definition: TOF.h:100
double tick
Clock&#39;s time between ticks.
Definition: TOF.h:189
broadCast_t tofBroadcast
RF data.
Definition: TOF.h:211
tofSecCfgPrms_t tofSecurityParams
TOF Security Configuration Paramaters.
Definition: TOF.h:175
TofHandshakeState_e
TOF Handshake State.
Definition: TOF.h:123
uint8_t postProcessLqiThresh
LQI threshold used for onchip post processing.
Definition: TOF.h:181
uint8_t * ToF_TX_Buf
Pointer to TX buffer.
Definition: TOF.h:138
uint16_t internalCtr
Internal counter that counts how many ToF bursts (runs) we processed so far.
Definition: TOF.h:205
TOF Sync Structure.
Definition: TOF.h:203
ToF security module interface.
ToF Security Configuration Parameters.
Definition: tof_security.h:84
uint8_t lastBuffFilled
Holds the last buffer that was filled (in case ToF Security is using double buffer mode) ...
Definition: TOF.h:208
double tickVariance
Variance of tick value.
Definition: TOF.h:190
TOF_ApplicationCB pfnTofApplicationCB
Callback to application.
Definition: TOF.h:179
rfc_CMD_TOF_sample_extended_t ToF_Sample
TOF Sample.
Definition: TOF.h:133
uint16_t numBuffSwitchRemaining
Counts for the current ToF run, how many buffer switches are remaining until the run ends...
Definition: TOF.h:207
uint8_t numFreq
Number of frequencies in above list.
Definition: TOF.h:174
uint16_t * pFrequencies
Pointer to Frequencies.
Definition: TOF.h:173
uint32_t freq
Frequency.
Definition: TOF.h:197
uint16_t postProcessMagnRatio
Magnitude radio threshold used for onchip post processing.
Definition: TOF.h:182
uint8_t * pRxBuf
Pointer to Rx buffer.
Definition: TOF.h:172
uint16_t lastSharedCtr
Last instance of shared counter as captured by the RTLS Passive.
Definition: TOF.h:206
rfc_CMD_TOF_synthCal_t ToF_SynthCal
Pointer to frequency calibration struct, used for the pre-calibration of the synth.
Definition: TOF.h:136
uint32_t ratSyncTime
RAT Sync Time.
Definition: TOF.h:199
void(* TOF_ApplicationCB)(void)
Callback to a handler supplied by the application.
Definition: TOF.h:142
TofSyncState_e
TOF Sync State.
Definition: TOF.h:115
TofStatus_e
TOF Errors.
Definition: TOF.h:108
© Copyright 1995-2020, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale