amiro-lld / include / DW1000 / v1 / deca_instance_v1.h @ b6364b51
History | View | Annotate | Download (28.814 KB)
1 |
/*! ----------------------------------------------------------------------------
|
---|---|
2 |
* @file instance.h
|
3 |
* @brief DecaWave header for application level instance
|
4 |
*
|
5 |
* @attention
|
6 |
*
|
7 |
* Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland.
|
8 |
*
|
9 |
* All rights reserved.
|
10 |
*
|
11 |
* @author DecaWave
|
12 |
*/
|
13 |
#ifndef __DECAINSTANCE_V1_H_
|
14 |
#define DECAINSTANCE_V1_H
|
15 |
|
16 |
#ifdef __cplusplus
|
17 |
extern "C" { |
18 |
#endif
|
19 |
|
20 |
#include <amiro-lld.h> |
21 |
#if (defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1)) || defined(__DOXYGEN__) |
22 |
|
23 |
#include <alld_DW1000.h> |
24 |
|
25 |
/******************************************************************************************************************
|
26 |
********************* NOTES on DW (MP) features/options ***********************************************************
|
27 |
*******************************************************************************************************************/
|
28 |
#define DEEP_SLEEP (0) //To enable deep-sleep set this to 1 |
29 |
//DEEP_SLEEP mode can be used, for example, by a Tag instance to put the DW1000 into low-power deep-sleep mode:
|
30 |
// when the Anchor is sending the range report back to the Tag, the Tag will enter sleep after a ranging exchange is finished
|
31 |
// once it receives a report or times out, before the next poll message is sent (before next ranging exchange is started).
|
32 |
|
33 |
#define CORRECT_RANGE_BIAS (1) // Compensate for small bias due to uneven accumulator growth at close up high power |
34 |
|
35 |
|
36 |
#define ANCTOANCTWR (1) //if set to 1 then anchor to anchor TWR will be done in the last slot |
37 |
|
38 |
#define DISCOVERY (0) //set to 1 to enable tag discovery - tags starts by sending blinks (with own ID) and then |
39 |
//anchor assigns a slot to it and gives it short address
|
40 |
/******************************************************************************************************************
|
41 |
*******************************************************************************************************************
|
42 |
*******************************************************************************************************************/
|
43 |
|
44 |
#define NUM_INST 1 |
45 |
#define SPEED_OF_LIGHT (299702547.0) // in m/s in air |
46 |
#define MASK_40BIT (0x00FFFFFFFFFF) // DW1000 counter is 40 bits |
47 |
#define MASK_TXDTS (0x00FFFFFFFE00) //The TX timestamp will snap to 8 ns resolution - mask lower 9 bits. |
48 |
|
49 |
//! callback events
|
50 |
#define DWT_SIG_RX_NOERR 0 |
51 |
#define DWT_SIG_TX_DONE 1 // Frame has been sent |
52 |
#define DWT_SIG_RX_OKAY 2 // Frame Received with Good CRC |
53 |
#define DWT_SIG_RX_ERROR 3 // Frame Received but CRC is wrong |
54 |
#define DWT_SIG_RX_TIMEOUT 4 // Timeout on receive has elapsed |
55 |
#define DWT_SIG_TX_AA_DONE 6 // ACK frame has been sent (as a result of auto-ACK) |
56 |
#define DWT_SIG_RX_BLINK 7 // Received ISO EUI 64 blink message |
57 |
#define DWT_SIG_RX_PHR_ERROR 8 // Error found in PHY Header |
58 |
#define DWT_SIG_RX_SYNCLOSS 9 // Un-recoverable error in Reed Solomon Decoder |
59 |
#define DWT_SIG_RX_SFDTIMEOUT 10 // Saw preamble but got no SFD within configured time |
60 |
#define DWT_SIG_RX_PTOTIMEOUT 11 // Got preamble detection timeout (no preamble detected) |
61 |
|
62 |
#define DWT_SIG_TX_PENDING 12 // TX is pending |
63 |
#define DWT_SIG_TX_ERROR 13 // TX failed |
64 |
#define DWT_SIG_RX_PENDING 14 // RX has been re-enabled |
65 |
#define DWT_SIG_DW_IDLE 15 // DW radio is in IDLE (no TX or RX pending) |
66 |
|
67 |
#define SIG_RX_UNKNOWN 99 // Received an unknown frame |
68 |
|
69 |
//DecaRTLS frame function codes
|
70 |
#define RTLS_DEMO_MSG_TAG_POLL (0x81) // Tag poll message |
71 |
#define RTLS_DEMO_MSG_ANCH_RESP (0x70) // Anchor response to poll |
72 |
#define RTLS_DEMO_MSG_ANCH_POLL (0x71) // Anchor to anchor poll message |
73 |
#define RTLS_DEMO_MSG_ANCH_RESP2 (0x72) // Anchor response to poll from anchor |
74 |
#define RTLS_DEMO_MSG_ANCH_FINAL (0x73) // Anchor final massage back to Anchor |
75 |
#define RTLS_DEMO_MSG_TAG_FINAL (0x82) // Tag final massage back to Anchor |
76 |
|
77 |
|
78 |
//lengths including the Decaranging Message Function Code byte
|
79 |
#define TAG_POLL_MSG_LEN 2 // FunctionCode(1), Range Num (1) |
80 |
#define ANCH_RESPONSE_MSG_LEN 8 // FunctionCode(1), Sleep Correction Time (2), Measured_TOF_Time(4), Range Num (1) (previous) |
81 |
#define TAG_FINAL_MSG_LEN 33 // FunctionCode(1), Range Num (1), Poll_TxTime(5), |
82 |
// Resp0_RxTime(5), Resp1_RxTime(5), Resp2_RxTime(5), Resp3_RxTime(5), Final_TxTime(5), Valid Response Mask (1)
|
83 |
|
84 |
#define MAX_MAC_MSG_DATA_LEN (TAG_FINAL_MSG_LEN) //max message len of the above |
85 |
|
86 |
#define STANDARD_FRAME_SIZE 127 |
87 |
//#define STANDARD_FRAME_SIZE 80
|
88 |
|
89 |
#define ADDR_BYTE_SIZE_L (8) |
90 |
#define ADDR_BYTE_SIZE_S (2) |
91 |
|
92 |
#define FRAME_CONTROL_BYTES 2 |
93 |
#define FRAME_SEQ_NUM_BYTES 1 |
94 |
#define FRAME_PANID 2 |
95 |
#define FRAME_CRC 2 |
96 |
#define FRAME_SOURCE_ADDRESS_S (ADDR_BYTE_SIZE_S)
|
97 |
#define FRAME_DEST_ADDRESS_S (ADDR_BYTE_SIZE_S)
|
98 |
#define FRAME_SOURCE_ADDRESS_L (ADDR_BYTE_SIZE_L)
|
99 |
#define FRAME_DEST_ADDRESS_L (ADDR_BYTE_SIZE_L)
|
100 |
#define FRAME_CTRLP (FRAME_CONTROL_BYTES + FRAME_SEQ_NUM_BYTES + FRAME_PANID) //5 |
101 |
#define FRAME_CRTL_AND_ADDRESS_L (FRAME_DEST_ADDRESS_L + FRAME_SOURCE_ADDRESS_L + FRAME_CTRLP) //21 bytes for 64-bit addresses) |
102 |
#define FRAME_CRTL_AND_ADDRESS_S (FRAME_DEST_ADDRESS_S + FRAME_SOURCE_ADDRESS_S + FRAME_CTRLP) //9 bytes for 16-bit addresses) |
103 |
#define FRAME_CRTL_AND_ADDRESS_LS (FRAME_DEST_ADDRESS_L + FRAME_SOURCE_ADDRESS_S + FRAME_CTRLP) //15 bytes for 1 16-bit address and 1 64-bit address) |
104 |
#define MAX_USER_PAYLOAD_STRING_LL (STANDARD_FRAME_SIZE-FRAME_CRTL_AND_ADDRESS_L-TAG_FINAL_MSG_LEN-FRAME_CRC) //127 - 21 - 16 - 2 = 88 |
105 |
#define MAX_USER_PAYLOAD_STRING_SS (STANDARD_FRAME_SIZE-FRAME_CRTL_AND_ADDRESS_S-TAG_FINAL_MSG_LEN-FRAME_CRC) //127 - 9 - 16 - 2 = 100 |
106 |
#define MAX_USER_PAYLOAD_STRING_LS (STANDARD_FRAME_SIZE-FRAME_CRTL_AND_ADDRESS_LS-TAG_FINAL_MSG_LEN-FRAME_CRC) //127 - 15 - 16 - 2 = 94 |
107 |
|
108 |
//NOTE: the user payload assumes that there are only 88 "free" bytes to be used for the user message (it does not scale according to the addressing modes)
|
109 |
#define MAX_USER_PAYLOAD_STRING MAX_USER_PAYLOAD_STRING_LL
|
110 |
|
111 |
#define MAX_TAG_LIST_SIZE (8) |
112 |
#define MAX_ANCHOR_LIST_SIZE (4) //this is limited to 4 in this application |
113 |
#define NUM_EXPECTED_RESPONSES (3) //e.g. MAX_ANCHOR_LIST_SIZE - 1 |
114 |
#define NUM_EXPECTED_RESPONSES_ANC (1) //anchors A0, A1 and A2 are involved in anchor to anchor ranging |
115 |
#define NUM_EXPECTED_RESPONSES_ANC0 (2) //anchor A0 expects response from A1 and A2 |
116 |
|
117 |
#define GATEWAY_ANCHOR_ADDR (0x8000) |
118 |
#define A1_ANCHOR_ADDR (0x8001) |
119 |
#define A2_ANCHOR_ADDR (0x8002) |
120 |
#define A3_ANCHOR_ADDR (0x8003) |
121 |
|
122 |
|
123 |
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
124 |
// NOTE: the maximum RX timeout is ~ 65ms
|
125 |
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
126 |
|
127 |
#define INST_DONE_WAIT_FOR_NEXT_EVENT 1 //this signifies that the current event has been processed and instance is ready for next one |
128 |
#define INST_DONE_WAIT_FOR_NEXT_EVENT_TO 2 //this signifies that the current event has been processed and that instance is waiting for next one with a timeout |
129 |
//which will trigger if no event coming in specified time
|
130 |
#define INST_NOT_DONE_YET 0 //this signifies that the instance is still processing the current event |
131 |
|
132 |
//application data message byte offsets
|
133 |
#define FCODE 0 // Function code is 1st byte of messageData |
134 |
#define PTXT 2 // Poll TX time |
135 |
#define RRXT0 7 // A0 Response RX time |
136 |
#define RRXT1 12 // A1 Response RX time |
137 |
#define RRXT2 17 // A2 Response RX time |
138 |
#define RRXT3 22 // A3 Response RX time |
139 |
#define FTXT 27 // Final TX time |
140 |
#define VRESP 32 // Mask of valid response times (e.g. if bit 1 = A0's response time is valid) |
141 |
#define RES_TAG_SLP0 1 // Response tag sleep correction LSB |
142 |
#define RES_TAG_SLP1 2 // Response tag sleep correction MSB |
143 |
#define TOFR 3 // ToF (n-1) 4 bytes |
144 |
#define TOFRN 7 // range number 1 byte |
145 |
#define POLL_RNUM 1 // Poll message range number |
146 |
|
147 |
//this it the delay used for configuring the receiver on delay (wait for response delay)
|
148 |
//NOTE: this RX_RESPONSE_TURNAROUND is dependent on the microprocessor and code optimisations
|
149 |
#define RX_RESPONSEX_TURNAROUND (50) //takes about 100 us for response to come back |
150 |
#define RX_RESPONSE1_TURNAROUND (200) //takes about 200 us for the 1st response to come back (from A0) |
151 |
#define RX_RESPONSE1_TURNAROUND_6M81 (300) //takes about 100 us for response to come back |
152 |
#define RX_RESPONSE1_TURNAROUND_110K (300) //takes about 100 us for response to come back |
153 |
|
154 |
/* For TAG HAL F1 */
|
155 |
//#define RX_RESPONSE1_TURNAROUND (200) //takes about 200 us for the 1st response to come back (from A0)
|
156 |
//#define RX_RESPONSE1_TURNAROUND_6M81 (300) //takes about 100 us for response to come back
|
157 |
//#define RX_RESPONSE1_TURNAROUND_110K (18700) //takes about 100 us for response to come back
|
158 |
|
159 |
/* For ANCHOR HAL F1 */
|
160 |
//#define RX_RESPONSE1_TURNAROUND (300) //takes about 200 us for the 1st response to come back (from A0)
|
161 |
//#define RX_RESPONSE1_TURNAROUND_6M81 (300) //takes about 100 us for response to come back
|
162 |
//#define RX_RESPONSE1_TURNAROUND_110K (4700) //takes about 100 us for response to come back
|
163 |
|
164 |
//Tag will range to 3 or 4 anchors
|
165 |
//Each ranging exchange will consist of minimum of 3 messages (Poll, Response, Final)
|
166 |
//and a maximum of 6 messages (Poll, Response x 4, Final)
|
167 |
//Thus the ranging exchange will take either 28 ms for 110 kbps and 5 ms for 6.81 Mbps.
|
168 |
//NOTE: the above times are for 110k rate with 64 symb non-standard SFD and 1024 preamble length
|
169 |
|
170 |
typedef enum instanceModes{LISTENER, TAG, ANCHOR, ANCHOR_RNG, NUM_MODES} INST_MODE; |
171 |
|
172 |
//Listener = in this mode, the instance only receives frames, does not respond
|
173 |
//Tag = Exchanges DecaRanging messages (Poll-Response-Final) with Anchor and enabling Anchor to calculate the range between the two instances
|
174 |
//Anchor = see above
|
175 |
//Anchor_Rng = the anchor (assumes a tag function) and ranges to another anchor - used in Anchor to Anchor TWR for auto positioning function
|
176 |
|
177 |
#define TOF_REPORT_NUL 0 |
178 |
#define TOF_REPORT_T2A 1 |
179 |
#define TOF_REPORT_A2A 2 |
180 |
|
181 |
#define INVALID_TOF (0xABCDFFFF) |
182 |
|
183 |
typedef enum inst_states |
184 |
{ |
185 |
TA_INIT, //0
|
186 |
|
187 |
TA_TXE_WAIT, //1 - state in which the instance will enter sleep (if ranging finished) or proceed to transmit a message
|
188 |
TA_TXPOLL_WAIT_SEND, //2 - configuration and sending of Poll message
|
189 |
TA_TXFINAL_WAIT_SEND, //3 - configuration and sending of Final message
|
190 |
TA_TXRESPONSE_WAIT_SEND, //4 - a place holder - response is sent from call back
|
191 |
TA_TX_WAIT_CONF, //6 - confirmation of TX done message
|
192 |
|
193 |
TA_RXE_WAIT, //7
|
194 |
TA_RX_WAIT_DATA, //8
|
195 |
|
196 |
TA_SLEEP_DONE, //9
|
197 |
TA_TXRESPONSE_SENT_POLLRX, //10
|
198 |
TA_TXRESPONSE_SENT_RESPRX, //11
|
199 |
TA_TXRESPONSE_SENT_TORX //12
|
200 |
|
201 |
} INST_STATES; |
202 |
|
203 |
|
204 |
// This file defines data and functions for access to Parameters in the Device
|
205 |
//message structure for Poll, Response and Final message
|
206 |
|
207 |
typedef struct |
208 |
{ |
209 |
uint8_t frameCtrl[2]; // frame control bytes 00-01 |
210 |
uint8_t seqNum; // sequence_number 02
|
211 |
uint8_t panID[2]; // PAN ID 03-04 |
212 |
uint8_t destAddr[ADDR_BYTE_SIZE_L]; // 05-12 using 64 bit addresses
|
213 |
uint8_t sourceAddr[ADDR_BYTE_SIZE_L]; // 13-20 using 64 bit addresses
|
214 |
uint8_t messageData[MAX_USER_PAYLOAD_STRING_LL] ; // 22-124 (application data and any user payload)
|
215 |
uint8_t fcs[2] ; // 125-126 we allow space for the CRC as it is logically part of the message. However ScenSor TX calculates and adds these bytes. |
216 |
} srd_msg_dlsl ; |
217 |
|
218 |
typedef struct |
219 |
{ |
220 |
uint8_t frameCtrl[2]; // frame control bytes 00-01 |
221 |
uint8_t seqNum; // sequence_number 02
|
222 |
uint8_t panID[2]; // PAN ID 03-04 |
223 |
uint8_t destAddr[ADDR_BYTE_SIZE_S]; // 05-06
|
224 |
uint8_t sourceAddr[ADDR_BYTE_SIZE_S]; // 07-08
|
225 |
uint8_t messageData[MAX_USER_PAYLOAD_STRING_SS] ; // 09-124 (application data and any user payload)
|
226 |
uint8_t fcs[2] ; // 125-126 we allow space for the CRC as it is logically part of the message. However ScenSor TX calculates and adds these bytes. |
227 |
} srd_msg_dsss ; |
228 |
|
229 |
typedef struct |
230 |
{ |
231 |
uint8_t frameCtrl[2]; // frame control bytes 00-01 |
232 |
uint8_t seqNum; // sequence_number 02
|
233 |
uint8_t panID[2]; // PAN ID 03-04 |
234 |
uint8_t destAddr[ADDR_BYTE_SIZE_L]; // 05-12 using 64 bit addresses
|
235 |
uint8_t sourceAddr[ADDR_BYTE_SIZE_S]; // 13-14
|
236 |
uint8_t messageData[MAX_USER_PAYLOAD_STRING_LS] ; // 15-124 (application data and any user payload)
|
237 |
uint8_t fcs[2] ; // 125-126 we allow space for the CRC as it is logically part of the message. However ScenSor TX calculates and adds these bytes. |
238 |
} srd_msg_dlss ; |
239 |
|
240 |
typedef struct |
241 |
{ |
242 |
uint8_t frameCtrl[2]; // frame control bytes 00-01 |
243 |
uint8_t seqNum; // sequence_number 02
|
244 |
uint8_t panID[2]; // PAN ID 03-04 |
245 |
uint8_t destAddr[ADDR_BYTE_SIZE_S]; // 05-06
|
246 |
uint8_t sourceAddr[ADDR_BYTE_SIZE_L]; // 07-14 using 64 bit addresses
|
247 |
uint8_t messageData[MAX_USER_PAYLOAD_STRING_LS] ; // 15-124 (application data and any user payload)
|
248 |
uint8_t fcs[2] ; // 125-126 we allow space for the CRC as it is logically part of the message. However ScenSor TX calculates and adds these bytes. |
249 |
} srd_msg_dssl ; |
250 |
|
251 |
typedef struct |
252 |
{ |
253 |
uint8_t channelNumber ; // valid range is 1 to 11
|
254 |
uint8_t preambleCode ; // 00 = use NS code, 1 to 24 selects code
|
255 |
uint8_t pulseRepFreq ; // NOMINAL_4M, NOMINAL_16M, or NOMINAL_64M
|
256 |
uint8_t dataRate ; // DATA_RATE_1 (110K), DATA_RATE_2 (850K), DATA_RATE_3 (6M81)
|
257 |
uint8_t preambleLen ; // values expected are 64, (128), (256), (512), 1024, (2048), and 4096
|
258 |
uint8_t pacSize ; |
259 |
uint8_t nsSFD ; |
260 |
uint16_t sfdTO; //!< SFD timeout value (in symbols) e.g. preamble length (128) + SFD(8) - PAC + some margin ~ 135us... DWT_SFDTOC_DEF; //default value
|
261 |
} instanceConfig_t ; |
262 |
|
263 |
typedef struct |
264 |
{ |
265 |
uint16_t slotPeriod ; //slot period (time for 1 tag to range to 4 anchors)
|
266 |
uint16_t numSlots ; // number of slots in one superframe (number of tags supported)
|
267 |
uint16_t sfPeriod ; // superframe period in ms
|
268 |
|
269 |
uint16_t pollSleepDly ; // the minimum SLEEP time should be FRAME PERIOD so that tags don't interfere
|
270 |
uint16_t replyDly ; //response delay time (Tag or Anchor when sending Final/Response messages respectively)
|
271 |
} sfConfig_t ; |
272 |
|
273 |
/******************************************************************************************************************
|
274 |
*******************************************************************************************************************
|
275 |
*******************************************************************************************************************/
|
276 |
|
277 |
//size of the event queue, in this application there should be at most 2 unprocessed events,
|
278 |
//i.e. if there is a transmission with wait for response then the TX callback followed by RX callback could be executed
|
279 |
//in turn and the event queued up before the instance processed the TX event.
|
280 |
#define MAX_EVENT_NUMBER (6) |
281 |
|
282 |
typedef struct |
283 |
{ |
284 |
uint8_t type; // event type - if 0 there is no event in the queue
|
285 |
uint8_t type_save; // holds the event type - does not clear (used to show what event has been processed)
|
286 |
uint8_t type_pend; // set if there is a pending event
|
287 |
uint16_t rxLength ; // length of RX data (does not apply to TX events)
|
288 |
|
289 |
uint64_t timeStamp ; // last timestamp (Tx or Rx) - 40 bit DW1000 time
|
290 |
|
291 |
uint32_t timeStamp32l ; // last tx/rx timestamp - low 32 bits of the 40 bit DW1000 time
|
292 |
uint32_t timeStamp32h ; // last tx/rx timestamp - high 32 bits of the 40 bit DW1000 time
|
293 |
|
294 |
uint32_t uTimeStamp ; //32 bit system counter (ms) - STM32 tick time (at time of IRQ)
|
295 |
|
296 |
union {
|
297 |
//holds received frame (after a good RX frame event)
|
298 |
uint8_t frame[STANDARD_FRAME_SIZE]; |
299 |
srd_msg_dlsl rxmsg_ll ; //64 bit addresses
|
300 |
srd_msg_dssl rxmsg_sl ; |
301 |
srd_msg_dlss rxmsg_ls ; |
302 |
srd_msg_dsss rxmsg_ss ; //16 bit addresses
|
303 |
}msgu; |
304 |
|
305 |
//uint32_t eventtime ;
|
306 |
//uint32_t eventtimeclr ;
|
307 |
uint8_t gotit; //stores the instance function which processed the event (used for debug)
|
308 |
}event_data_t ; |
309 |
|
310 |
extern event_data_t dw_event_g; // TODO |
311 |
|
312 |
// TX power and PG delay configuration structure
|
313 |
typedef struct { |
314 |
uint8_t PGdelay; |
315 |
|
316 |
//TX POWER
|
317 |
//31:24 BOOST_0.125ms_PWR
|
318 |
//23:16 BOOST_0.25ms_PWR-TX_SHR_PWR
|
319 |
//15:8 BOOST_0.5ms_PWR-TX_PHR_PWR
|
320 |
//7:0 DEFAULT_PWR-TX_DATA_PWR
|
321 |
uint32_t txPwr[2]; // |
322 |
}tx_struct; |
323 |
|
324 |
typedef struct |
325 |
{ |
326 |
INST_MODE mode; //instance mode (tag or anchor)
|
327 |
|
328 |
INST_STATES testAppState ; //state machine - current state
|
329 |
INST_STATES nextState ; //state machine - next state
|
330 |
INST_STATES previousState ; //state machine - previous state
|
331 |
int done ; //done with the current event/wait for next event to arrive |
332 |
|
333 |
//configuration structures
|
334 |
dwt_config_t configData ; //DW1000 channel configuration
|
335 |
dwt_txconfig_t configTX ; //DW1000 TX power configuration
|
336 |
uint16_t txAntennaDelay ; //DW1000 TX antenna delay
|
337 |
uint16_t rxAntennaDelay ; //DW1000 RX antenna delay
|
338 |
uint32_t txPower ; //DW1000 TX power
|
339 |
uint8_t txPowerChanged ; //power has been changed - update the register on next TWR exchange
|
340 |
uint8_t antennaDelayChanged; //antenna delay has been changed - update the register on next TWR exchange
|
341 |
|
342 |
uint16_t instanceAddress16; //contains tag/anchor address
|
343 |
|
344 |
//timeouts and delays
|
345 |
int32_t tagSleepTime_ms; //in milliseconds - defines the nominal Tag sleep time period
|
346 |
int32_t tagSleepRnd; //add an extra slot duration to sleep time to avoid collision before getting synced by anchor 0
|
347 |
|
348 |
//this is the delay used for the delayed transmit
|
349 |
uint64_t pollTx2FinalTxDelay ; //this is delay from Poll Tx time to Final Tx time in DW1000 units (40-bit)
|
350 |
uint64_t pollTx2FinalTxDelayAnc ; //this is delay from Poll Tx time to Final Tx time in DW1000 units (40-bit) for Anchor to Anchor ranging
|
351 |
uint64_t fixedReplyDelayAnc ; |
352 |
uint32_t fixedReplyDelayAncP ; |
353 |
int ancRespRxDelay ;
|
354 |
|
355 |
int fwtoTime_sy ; //this is final message duration (longest out of ranging messages) |
356 |
int fwtoTimeAnc_sy ;
|
357 |
uint32_t delayedReplyTime; // delayed reply time of ranging-init/response/final message
|
358 |
|
359 |
uint32_t rxTimeouts ; |
360 |
|
361 |
//message structure used for holding the data of the frame to transmit before it is written to the DW1000
|
362 |
srd_msg_dsss msg_f ; // ranging message frame with 16-bit addresses
|
363 |
|
364 |
//Tag function address/message configuration
|
365 |
uint8_t shortAdd_idx ; // device's 16-bit address low byte (used as index into arrays [0 - 3])
|
366 |
uint8_t eui64[8]; // device's EUI 64-bit address |
367 |
uint16_t psduLength ; // used for storing the TX frame length
|
368 |
uint8_t frameSN; // modulo 256 frame sequence number - it is incremented for each new frame transmission
|
369 |
uint16_t panID ; // panid used in the frames
|
370 |
|
371 |
//64 bit timestamps
|
372 |
//union of TX timestamps
|
373 |
union {
|
374 |
uint64_t txTimeStamp ; // last tx timestamp
|
375 |
uint64_t tagPollTxTime ; // tag's poll tx timestamp
|
376 |
uint64_t anchorRespTxTime ; // anchor's reponse tx timestamp
|
377 |
}txu; |
378 |
uint64_t tagPollRxTime ; // receive time of poll message
|
379 |
|
380 |
|
381 |
//application control parameters
|
382 |
uint8_t wait4ack ; // if this is set to DWT_RESPONSE_EXPECTED, then the receiver will turn on automatically after TX completion
|
383 |
|
384 |
int8_t responseTO ; |
385 |
uint8_t instToSleep; // if set the instance will go to sleep before sending the blink/poll message
|
386 |
uint8_t stopTimer; // stop/disable an active timer
|
387 |
uint8_t instanceTimerEn; // enable/start a timer
|
388 |
uint32_t instanceWakeTime; //
|
389 |
uint32_t nextSleepPeriod; |
390 |
|
391 |
uint8_t gotTO; // got timeout event
|
392 |
|
393 |
uint8_t rxResponseMaskAnc; |
394 |
uint8_t rxResponseMask; // bit mask - bit 0 = received response from anchor ID = 0, bit 1 from anchor ID = 1 etc...
|
395 |
uint8_t rxResponseMaskReport; |
396 |
uint8_t rangeNum; // incremented for each sequence of ranges (each slot)
|
397 |
uint8_t rangeNumA[MAX_TAG_LIST_SIZE]; // array which holds last range number from each tag
|
398 |
uint8_t rangeNumAnc; // incremented for each sequence of ranges (each slot) - anchor to anchor ranging
|
399 |
uint8_t rangeNumAAnc[MAX_ANCHOR_LIST_SIZE]; //array which holds last range number for each anchor
|
400 |
uint16_t sframePeriod; |
401 |
uint16_t slotPeriod; |
402 |
uint16_t numSlots; |
403 |
uint32_t a0SlotTime; |
404 |
uint32_t a1SlotTime; |
405 |
int32_t tagSleepCorrection; |
406 |
int32_t tagSleepCorrection2; |
407 |
|
408 |
//diagnostic counters/data, results and logging
|
409 |
uint32_t tof[MAX_TAG_LIST_SIZE]; //this is an array which holds last ToF from particular tag (ID 0-7)
|
410 |
|
411 |
//this is an array which holds last ToF to each anchor it should
|
412 |
uint32_t tofArray[MAX_ANCHOR_LIST_SIZE]; //contain 4 ToF to 4 anchors all relating to same range number sequence
|
413 |
|
414 |
uint32_t tofAnc[MAX_ANCHOR_LIST_SIZE]; //this is an array which holds last ToFs from particular anchors (0, 0-1, 0-2, 1-2)
|
415 |
|
416 |
//this is an array which holds last ToFs of the Anchor to Anchor ranging
|
417 |
uint32_t tofArrayAnc[MAX_ANCHOR_LIST_SIZE]; //it contains 3 ToFs relating to same range number sequence (0, 0-1, 0-2, 1-2)
|
418 |
|
419 |
int txMsgCount; //number of transmitted messages |
420 |
int rxMsgCount; //number of received messages |
421 |
int lateTX; //number of "LATE" TX events |
422 |
int lateRX; //number of "LATE" RX events |
423 |
|
424 |
int longTermRangeCount ; //total number of ranges |
425 |
|
426 |
int newRange; //flag set when there is a new range to report TOF_REPORT_A2A or TOF_REPORT_T2A |
427 |
int newRangeAncAddress; //last 4 bytes of anchor address - used for printing/range output display |
428 |
int newRangeTagAddress; //last 4 bytes of tag address - used for printing/range output display |
429 |
int newRangeTime;
|
430 |
|
431 |
uint8_t gatewayAnchor ; //set to TRUE = 1 if anchor address == GATEWAY_ANCHOR_ADDR
|
432 |
|
433 |
//event queue - used to store DW1000 events as they are processed by the dw_isr/callback functions
|
434 |
event_data_t dwevent[MAX_EVENT_NUMBER]; //this holds any TX/RX events and associated message data
|
435 |
event_data_t saved_dwevent; //holds an RX event while the ACK is being sent
|
436 |
uint8_t dweventIdxOut; |
437 |
uint8_t dweventIdxIn; |
438 |
uint8_t dweventPeek; |
439 |
uint8_t monitor; |
440 |
uint32_t timeofTx ; |
441 |
|
442 |
uint8_t rxRespsIdx; //index into the array below (current tag (4bits)/seq number(4bits))
|
443 |
int8_t rxResps[256];
|
444 |
|
445 |
int dwIDLE; //set to 1 when the RST goes high after wake up (it is set in process_dwRSTn_irq) |
446 |
|
447 |
} instance_data_t ; |
448 |
|
449 |
//-------------------------------------------------------------------------------------------------------------
|
450 |
//
|
451 |
// Functions used in logging/displaying range and status data
|
452 |
//
|
453 |
//-------------------------------------------------------------------------------------------------------------
|
454 |
|
455 |
// function to calculate and report the Time of Flight to the GUI/display
|
456 |
int reportTOF(int idx, uint32_t tofx); |
457 |
void clearDistTable(int idx); |
458 |
void setTagDist(int tidx, int aidx); |
459 |
double getTagDist(int idx); |
460 |
|
461 |
// clear the status/ranging data
|
462 |
void instanceclearcounts(void) ; |
463 |
|
464 |
//-------------------------------------------------------------------------------------------------------------
|
465 |
//
|
466 |
// Functions used in driving/controlling the ranging application
|
467 |
//
|
468 |
//-------------------------------------------------------------------------------------------------------------
|
469 |
|
470 |
void instance_close(void); |
471 |
// Call init, then call config, then call run. call close when finished
|
472 |
// initialise the instance (application) structures and DW1000 device
|
473 |
int instance_init(void); |
474 |
// configure the instance and DW1000 device
|
475 |
void instance_config(instanceConfig_t *config, sfConfig_t *sfconfig) ;
|
476 |
|
477 |
// configure the MAC address
|
478 |
void instancesetaddresses(uint16_t address) ;
|
479 |
|
480 |
void inst_processrxtimeout(instance_data_t *inst);
|
481 |
|
482 |
// called (periodically or from and interrupt) to process any outstanding TX/RX events and to drive the ranging application
|
483 |
int instance_run(void) ; // returns indication of status report change |
484 |
int testapprun(instance_data_t *inst, int message); |
485 |
|
486 |
// calls the DW1000 interrupt handler
|
487 |
#define instance_process_irq(x) dwt_isr() //call device interrupt handler |
488 |
// configure TX/RX callback functions that are called from DW1000 ISR
|
489 |
void instance_rxcallback(const dwt_cb_data_t *rxd); |
490 |
void instance_txcallback(const dwt_cb_data_t *txd); |
491 |
/*TODO: add callbacks */
|
492 |
void instance_rxtimeoutcallback(const dwt_cb_data_t *rxd); |
493 |
void instance_rxerrorcallback(const dwt_cb_data_t *rxd); |
494 |
|
495 |
|
496 |
|
497 |
// sets the Tag sleep delay time (the time Tag "sleeps" between each ranging attempt)
|
498 |
void instancesettagsleepdelay(int rangingsleep); |
499 |
void instancesetreplydelay(int delayms); |
500 |
|
501 |
// set/get the instance roles e.g. Tag/Anchor/Listener
|
502 |
void instancesetrole(int mode) ; // |
503 |
int instancegetrole(void) ; |
504 |
// get the DW1000 device ID (e.g. 0xDECA0130 for DW1000)
|
505 |
uint32_t instancereaddeviceid(void) ; // Return Device ID reg, enables validation of physical device presence |
506 |
|
507 |
double instancegetidist(int idx); |
508 |
double instancegetidistraw(int idx); |
509 |
int instancegetidist_mm(int idx); |
510 |
int instancegetidistraw_mm(int idx); |
511 |
uint8_t instancevalidranges(void);
|
512 |
void instancecleardisttableall(void); |
513 |
|
514 |
void instance_backtoanchor(instance_data_t *inst);
|
515 |
int instancesenddlypacket(instance_data_t *inst, int delayedTx); |
516 |
|
517 |
int instancegetrnum(void); |
518 |
int instancegetrnuma(int idx); |
519 |
int instancegetrnumanc(int idx); |
520 |
int instancegetlcount(void); |
521 |
|
522 |
int instancenewrangeancadd(void); |
523 |
int instancenewrangetagadd(void); |
524 |
int instancenewrangepolltim(void); |
525 |
int instancenewrange(void); |
526 |
int instancenewrangetim(void); |
527 |
|
528 |
uint64_t convertmicrosectodevicetimeu (double microsecu);
|
529 |
double convertdevicetimetosec(int32_t dt);
|
530 |
|
531 |
#define DWT_PRF_64M_RFDLY (514.462f) |
532 |
#define DWT_PRF_16M_RFDLY (513.9067f) |
533 |
|
534 |
/* Extern declaration while defining the data in .c file */
|
535 |
extern const uint16_t rfDelays[2]; |
536 |
extern const uint16_t rfDelaysTREK[2]; |
537 |
extern const tx_struct txSpectrumConfig[8]; |
538 |
extern instance_data_t instance_data[NUM_INST] ;
|
539 |
|
540 |
|
541 |
int instance_peekevent(void); |
542 |
|
543 |
void instance_saveevent(event_data_t newevent, uint8_t etype);
|
544 |
|
545 |
event_data_t instance_getsavedevent(void);
|
546 |
|
547 |
void instance_putevent(event_data_t newevent, uint8_t etype);
|
548 |
|
549 |
event_data_t* instance_getevent(int x);
|
550 |
|
551 |
void instance_clearevents(void); |
552 |
|
553 |
void instance_notify_DW1000_inIDLE(int idle); |
554 |
|
555 |
|
556 |
// TODO: The following Functions are added in user applciation (previously on the API )
|
557 |
|
558 |
double dwt_getrangebias(uint8_t chan, float range, uint8_t prf); |
559 |
|
560 |
uint32_t dwt_getotptxpower(uint8_t prf, uint8_t chan); |
561 |
|
562 |
uint16_t dwt_getTREKOTPantennadelay(uint8_t anchor, uint8_t chan, uint8_t datarate); |
563 |
|
564 |
uint16_t dwt_readantennadelay(uint8_t prf); |
565 |
|
566 |
|
567 |
/* End of user application functions (Previously on API) */
|
568 |
|
569 |
|
570 |
// configure TX power
|
571 |
void instanceconfigtxpower(uint32_t txpower);
|
572 |
void instancesettxpower(void); |
573 |
|
574 |
// configure the antenna delays
|
575 |
void instanceconfigantennadelays(uint16_t tx, uint16_t rx);
|
576 |
void instancesetantennadelays(void); |
577 |
uint16_t instancetxantdly(void);
|
578 |
uint16_t instancerxantdly(void);
|
579 |
|
580 |
int instance_starttxtest(int framePeriod); |
581 |
|
582 |
#endif /* defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1) */ |
583 |
|
584 |
#ifdef __cplusplus
|
585 |
} |
586 |
#endif
|
587 |
|
588 |
#endif /* DECAINSTANCE_V1_H */ |