amiro-lld / include / DW1000 / v1 / deca_instance_v1.h @ 78cc79d4
History | View | Annotate | Download (28.468 KB)
1 | 69a601a5 | Cung Sang | /*! ----------------------------------------------------------------------------
|
---|---|---|---|
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 | //Tag will range to 3 or 4 anchors
|
||
155 | //Each ranging exchange will consist of minimum of 3 messages (Poll, Response, Final)
|
||
156 | //and a maximum of 6 messages (Poll, Response x 4, Final)
|
||
157 | //Thus the ranging exchange will take either 28 ms for 110 kbps and 5 ms for 6.81 Mbps.
|
||
158 | //NOTE: the above times are for 110k rate with 64 symb non-standard SFD and 1024 preamble length
|
||
159 | |||
160 | typedef enum instanceModes{LISTENER, TAG, ANCHOR, ANCHOR_RNG, NUM_MODES} INST_MODE; |
||
161 | |||
162 | //Listener = in this mode, the instance only receives frames, does not respond
|
||
163 | //Tag = Exchanges DecaRanging messages (Poll-Response-Final) with Anchor and enabling Anchor to calculate the range between the two instances
|
||
164 | //Anchor = see above
|
||
165 | //Anchor_Rng = the anchor (assumes a tag function) and ranges to another anchor - used in Anchor to Anchor TWR for auto positioning function
|
||
166 | |||
167 | #define TOF_REPORT_NUL 0 |
||
168 | #define TOF_REPORT_T2A 1 |
||
169 | #define TOF_REPORT_A2A 2 |
||
170 | |||
171 | #define INVALID_TOF (0xABCDFFFF) |
||
172 | |||
173 | typedef enum inst_states |
||
174 | { |
||
175 | TA_INIT, //0
|
||
176 | |||
177 | TA_TXE_WAIT, //1 - state in which the instance will enter sleep (if ranging finished) or proceed to transmit a message
|
||
178 | TA_TXPOLL_WAIT_SEND, //2 - configuration and sending of Poll message
|
||
179 | TA_TXFINAL_WAIT_SEND, //3 - configuration and sending of Final message
|
||
180 | TA_TXRESPONSE_WAIT_SEND, //4 - a place holder - response is sent from call back
|
||
181 | TA_TX_WAIT_CONF, //6 - confirmation of TX done message
|
||
182 | |||
183 | TA_RXE_WAIT, //7
|
||
184 | TA_RX_WAIT_DATA, //8
|
||
185 | |||
186 | TA_SLEEP_DONE, //9
|
||
187 | TA_TXRESPONSE_SENT_POLLRX, //10
|
||
188 | TA_TXRESPONSE_SENT_RESPRX, //11
|
||
189 | TA_TXRESPONSE_SENT_TORX //12
|
||
190 | |||
191 | } INST_STATES; |
||
192 | |||
193 | |||
194 | // This file defines data and functions for access to Parameters in the Device
|
||
195 | //message structure for Poll, Response and Final message
|
||
196 | |||
197 | typedef struct |
||
198 | { |
||
199 | uint8_t frameCtrl[2]; // frame control bytes 00-01 |
||
200 | uint8_t seqNum; // sequence_number 02
|
||
201 | uint8_t panID[2]; // PAN ID 03-04 |
||
202 | uint8_t destAddr[ADDR_BYTE_SIZE_L]; // 05-12 using 64 bit addresses
|
||
203 | uint8_t sourceAddr[ADDR_BYTE_SIZE_L]; // 13-20 using 64 bit addresses
|
||
204 | uint8_t messageData[MAX_USER_PAYLOAD_STRING_LL] ; // 22-124 (application data and any user payload)
|
||
205 | 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. |
||
206 | } srd_msg_dlsl ; |
||
207 | |||
208 | typedef struct |
||
209 | { |
||
210 | uint8_t frameCtrl[2]; // frame control bytes 00-01 |
||
211 | uint8_t seqNum; // sequence_number 02
|
||
212 | uint8_t panID[2]; // PAN ID 03-04 |
||
213 | uint8_t destAddr[ADDR_BYTE_SIZE_S]; // 05-06
|
||
214 | uint8_t sourceAddr[ADDR_BYTE_SIZE_S]; // 07-08
|
||
215 | uint8_t messageData[MAX_USER_PAYLOAD_STRING_SS] ; // 09-124 (application data and any user payload)
|
||
216 | 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. |
||
217 | } srd_msg_dsss ; |
||
218 | |||
219 | typedef struct |
||
220 | { |
||
221 | uint8_t frameCtrl[2]; // frame control bytes 00-01 |
||
222 | uint8_t seqNum; // sequence_number 02
|
||
223 | uint8_t panID[2]; // PAN ID 03-04 |
||
224 | uint8_t destAddr[ADDR_BYTE_SIZE_L]; // 05-12 using 64 bit addresses
|
||
225 | uint8_t sourceAddr[ADDR_BYTE_SIZE_S]; // 13-14
|
||
226 | uint8_t messageData[MAX_USER_PAYLOAD_STRING_LS] ; // 15-124 (application data and any user payload)
|
||
227 | 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. |
||
228 | } srd_msg_dlss ; |
||
229 | |||
230 | typedef struct |
||
231 | { |
||
232 | uint8_t frameCtrl[2]; // frame control bytes 00-01 |
||
233 | uint8_t seqNum; // sequence_number 02
|
||
234 | uint8_t panID[2]; // PAN ID 03-04 |
||
235 | uint8_t destAddr[ADDR_BYTE_SIZE_S]; // 05-06
|
||
236 | uint8_t sourceAddr[ADDR_BYTE_SIZE_L]; // 07-14 using 64 bit addresses
|
||
237 | uint8_t messageData[MAX_USER_PAYLOAD_STRING_LS] ; // 15-124 (application data and any user payload)
|
||
238 | 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. |
||
239 | } srd_msg_dssl ; |
||
240 | |||
241 | 26dead12 | Cung Sang | typedef struct __attribute__((packed)) |
242 | 69a601a5 | Cung Sang | { |
243 | uint8_t channelNumber ; // valid range is 1 to 11
|
||
244 | uint8_t preambleCode ; // 00 = use NS code, 1 to 24 selects code
|
||
245 | uint8_t pulseRepFreq ; // NOMINAL_4M, NOMINAL_16M, or NOMINAL_64M
|
||
246 | uint8_t dataRate ; // DATA_RATE_1 (110K), DATA_RATE_2 (850K), DATA_RATE_3 (6M81)
|
||
247 | uint8_t preambleLen ; // values expected are 64, (128), (256), (512), 1024, (2048), and 4096
|
||
248 | uint8_t pacSize ; |
||
249 | uint8_t nsSFD ; |
||
250 | uint16_t sfdTO; //!< SFD timeout value (in symbols) e.g. preamble length (128) + SFD(8) - PAC + some margin ~ 135us... DWT_SFDTOC_DEF; //default value
|
||
251 | } instanceConfig_t ; |
||
252 | |||
253 | typedef struct |
||
254 | { |
||
255 | uint16_t slotPeriod ; //slot period (time for 1 tag to range to 4 anchors)
|
||
256 | uint16_t numSlots ; // number of slots in one superframe (number of tags supported)
|
||
257 | uint16_t sfPeriod ; // superframe period in ms
|
||
258 | |||
259 | uint16_t pollSleepDly ; // the minimum SLEEP time should be FRAME PERIOD so that tags don't interfere
|
||
260 | uint16_t replyDly ; //response delay time (Tag or Anchor when sending Final/Response messages respectively)
|
||
261 | } sfConfig_t ; |
||
262 | |||
263 | /******************************************************************************************************************
|
||
264 | *******************************************************************************************************************
|
||
265 | *******************************************************************************************************************/
|
||
266 | |||
267 | //size of the event queue, in this application there should be at most 2 unprocessed events,
|
||
268 | //i.e. if there is a transmission with wait for response then the TX callback followed by RX callback could be executed
|
||
269 | //in turn and the event queued up before the instance processed the TX event.
|
||
270 | #define MAX_EVENT_NUMBER (6) |
||
271 | |||
272 | 26dead12 | Cung Sang | typedef struct __attribute__((packed)) |
273 | 69a601a5 | Cung Sang | { |
274 | uint8_t type; // event type - if 0 there is no event in the queue
|
||
275 | uint8_t type_save; // holds the event type - does not clear (used to show what event has been processed)
|
||
276 | uint8_t type_pend; // set if there is a pending event
|
||
277 | uint16_t rxLength ; // length of RX data (does not apply to TX events)
|
||
278 | |||
279 | uint64_t timeStamp ; // last timestamp (Tx or Rx) - 40 bit DW1000 time
|
||
280 | |||
281 | uint32_t timeStamp32l ; // last tx/rx timestamp - low 32 bits of the 40 bit DW1000 time
|
||
282 | uint32_t timeStamp32h ; // last tx/rx timestamp - high 32 bits of the 40 bit DW1000 time
|
||
283 | |||
284 | uint32_t uTimeStamp ; //32 bit system counter (ms) - STM32 tick time (at time of IRQ)
|
||
285 | |||
286 | union {
|
||
287 | //holds received frame (after a good RX frame event)
|
||
288 | uint8_t frame[STANDARD_FRAME_SIZE]; |
||
289 | srd_msg_dlsl rxmsg_ll ; //64 bit addresses
|
||
290 | srd_msg_dssl rxmsg_sl ; |
||
291 | srd_msg_dlss rxmsg_ls ; |
||
292 | srd_msg_dsss rxmsg_ss ; //16 bit addresses
|
||
293 | }msgu; |
||
294 | |||
295 | //uint32_t eventtime ;
|
||
296 | //uint32_t eventtimeclr ;
|
||
297 | uint8_t gotit; //stores the instance function which processed the event (used for debug)
|
||
298 | }event_data_t ; |
||
299 | |||
300 | 26dead12 | Cung Sang | extern event_data_t dw_event_g;
|
301 | 69a601a5 | Cung Sang | |
302 | // TX power and PG delay configuration structure
|
||
303 | 26dead12 | Cung Sang | typedef struct __attribute__((packed)) { |
304 | 69a601a5 | Cung Sang | uint8_t PGdelay; |
305 | |||
306 | //TX POWER
|
||
307 | //31:24 BOOST_0.125ms_PWR
|
||
308 | //23:16 BOOST_0.25ms_PWR-TX_SHR_PWR
|
||
309 | //15:8 BOOST_0.5ms_PWR-TX_PHR_PWR
|
||
310 | //7:0 DEFAULT_PWR-TX_DATA_PWR
|
||
311 | uint32_t txPwr[2]; // |
||
312 | }tx_struct; |
||
313 | |||
314 | 26dead12 | Cung Sang | typedef struct __attribute__((packed)) |
315 | 69a601a5 | Cung Sang | { |
316 | INST_MODE mode; //instance mode (tag or anchor)
|
||
317 | |||
318 | INST_STATES testAppState ; //state machine - current state
|
||
319 | INST_STATES nextState ; //state machine - next state
|
||
320 | INST_STATES previousState ; //state machine - previous state
|
||
321 | int done ; //done with the current event/wait for next event to arrive |
||
322 | |||
323 | //configuration structures
|
||
324 | dwt_config_t configData ; //DW1000 channel configuration
|
||
325 | dwt_txconfig_t configTX ; //DW1000 TX power configuration
|
||
326 | uint16_t txAntennaDelay ; //DW1000 TX antenna delay
|
||
327 | uint16_t rxAntennaDelay ; //DW1000 RX antenna delay
|
||
328 | uint32_t txPower ; //DW1000 TX power
|
||
329 | uint8_t txPowerChanged ; //power has been changed - update the register on next TWR exchange
|
||
330 | uint8_t antennaDelayChanged; //antenna delay has been changed - update the register on next TWR exchange
|
||
331 | |||
332 | uint16_t instanceAddress16; //contains tag/anchor address
|
||
333 | |||
334 | //timeouts and delays
|
||
335 | int32_t tagSleepTime_ms; //in milliseconds - defines the nominal Tag sleep time period
|
||
336 | int32_t tagSleepRnd; //add an extra slot duration to sleep time to avoid collision before getting synced by anchor 0
|
||
337 | |||
338 | //this is the delay used for the delayed transmit
|
||
339 | uint64_t pollTx2FinalTxDelay ; //this is delay from Poll Tx time to Final Tx time in DW1000 units (40-bit)
|
||
340 | uint64_t pollTx2FinalTxDelayAnc ; //this is delay from Poll Tx time to Final Tx time in DW1000 units (40-bit) for Anchor to Anchor ranging
|
||
341 | uint64_t fixedReplyDelayAnc ; |
||
342 | uint32_t fixedReplyDelayAncP ; |
||
343 | int ancRespRxDelay ;
|
||
344 | |||
345 | int fwtoTime_sy ; //this is final message duration (longest out of ranging messages) |
||
346 | int fwtoTimeAnc_sy ;
|
||
347 | uint32_t delayedReplyTime; // delayed reply time of ranging-init/response/final message
|
||
348 | |||
349 | uint32_t rxTimeouts ; |
||
350 | |||
351 | //message structure used for holding the data of the frame to transmit before it is written to the DW1000
|
||
352 | srd_msg_dsss msg_f ; // ranging message frame with 16-bit addresses
|
||
353 | |||
354 | //Tag function address/message configuration
|
||
355 | uint8_t shortAdd_idx ; // device's 16-bit address low byte (used as index into arrays [0 - 3])
|
||
356 | uint8_t eui64[8]; // device's EUI 64-bit address |
||
357 | uint16_t psduLength ; // used for storing the TX frame length
|
||
358 | uint8_t frameSN; // modulo 256 frame sequence number - it is incremented for each new frame transmission
|
||
359 | uint16_t panID ; // panid used in the frames
|
||
360 | |||
361 | //64 bit timestamps
|
||
362 | //union of TX timestamps
|
||
363 | union {
|
||
364 | uint64_t txTimeStamp ; // last tx timestamp
|
||
365 | uint64_t tagPollTxTime ; // tag's poll tx timestamp
|
||
366 | uint64_t anchorRespTxTime ; // anchor's reponse tx timestamp
|
||
367 | }txu; |
||
368 | uint64_t tagPollRxTime ; // receive time of poll message
|
||
369 | |||
370 | |||
371 | //application control parameters
|
||
372 | uint8_t wait4ack ; // if this is set to DWT_RESPONSE_EXPECTED, then the receiver will turn on automatically after TX completion
|
||
373 | |||
374 | int8_t responseTO ; |
||
375 | uint8_t instToSleep; // if set the instance will go to sleep before sending the blink/poll message
|
||
376 | uint8_t stopTimer; // stop/disable an active timer
|
||
377 | uint8_t instanceTimerEn; // enable/start a timer
|
||
378 | uint32_t instanceWakeTime; //
|
||
379 | uint32_t nextSleepPeriod; |
||
380 | |||
381 | uint8_t gotTO; // got timeout event
|
||
382 | |||
383 | uint8_t rxResponseMaskAnc; |
||
384 | uint8_t rxResponseMask; // bit mask - bit 0 = received response from anchor ID = 0, bit 1 from anchor ID = 1 etc...
|
||
385 | uint8_t rxResponseMaskReport; |
||
386 | uint8_t rangeNum; // incremented for each sequence of ranges (each slot)
|
||
387 | uint8_t rangeNumA[MAX_TAG_LIST_SIZE]; // array which holds last range number from each tag
|
||
388 | uint8_t rangeNumAnc; // incremented for each sequence of ranges (each slot) - anchor to anchor ranging
|
||
389 | uint8_t rangeNumAAnc[MAX_ANCHOR_LIST_SIZE]; //array which holds last range number for each anchor
|
||
390 | uint16_t sframePeriod; |
||
391 | uint16_t slotPeriod; |
||
392 | uint16_t numSlots; |
||
393 | uint32_t a0SlotTime; |
||
394 | uint32_t a1SlotTime; |
||
395 | int32_t tagSleepCorrection; |
||
396 | int32_t tagSleepCorrection2; |
||
397 | |||
398 | //diagnostic counters/data, results and logging
|
||
399 | uint32_t tof[MAX_TAG_LIST_SIZE]; //this is an array which holds last ToF from particular tag (ID 0-7)
|
||
400 | |||
401 | //this is an array which holds last ToF to each anchor it should
|
||
402 | uint32_t tofArray[MAX_ANCHOR_LIST_SIZE]; //contain 4 ToF to 4 anchors all relating to same range number sequence
|
||
403 | |||
404 | 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)
|
||
405 | |||
406 | //this is an array which holds last ToFs of the Anchor to Anchor ranging
|
||
407 | uint32_t tofArrayAnc[MAX_ANCHOR_LIST_SIZE]; //it contains 3 ToFs relating to same range number sequence (0, 0-1, 0-2, 1-2)
|
||
408 | |||
409 | int txMsgCount; //number of transmitted messages |
||
410 | int rxMsgCount; //number of received messages |
||
411 | int lateTX; //number of "LATE" TX events |
||
412 | int lateRX; //number of "LATE" RX events |
||
413 | |||
414 | int longTermRangeCount ; //total number of ranges |
||
415 | |||
416 | int newRange; //flag set when there is a new range to report TOF_REPORT_A2A or TOF_REPORT_T2A |
||
417 | int newRangeAncAddress; //last 4 bytes of anchor address - used for printing/range output display |
||
418 | int newRangeTagAddress; //last 4 bytes of tag address - used for printing/range output display |
||
419 | 26dead12 | Cung Sang | uint32_t newRangeTime; |
420 | 69a601a5 | Cung Sang | |
421 | uint8_t gatewayAnchor ; //set to TRUE = 1 if anchor address == GATEWAY_ANCHOR_ADDR
|
||
422 | |||
423 | //event queue - used to store DW1000 events as they are processed by the dw_isr/callback functions
|
||
424 | event_data_t dwevent[MAX_EVENT_NUMBER]; //this holds any TX/RX events and associated message data
|
||
425 | event_data_t saved_dwevent; //holds an RX event while the ACK is being sent
|
||
426 | uint8_t dweventIdxOut; |
||
427 | uint8_t dweventIdxIn; |
||
428 | uint8_t dweventPeek; |
||
429 | uint8_t monitor; |
||
430 | uint32_t timeofTx ; |
||
431 | |||
432 | uint8_t rxRespsIdx; //index into the array below (current tag (4bits)/seq number(4bits))
|
||
433 | int8_t rxResps[256];
|
||
434 | |||
435 | int dwIDLE; //set to 1 when the RST goes high after wake up (it is set in process_dwRSTn_irq) |
||
436 | |||
437 | } instance_data_t ; |
||
438 | |||
439 | //-------------------------------------------------------------------------------------------------------------
|
||
440 | //
|
||
441 | // Functions used in logging/displaying range and status data
|
||
442 | //
|
||
443 | //-------------------------------------------------------------------------------------------------------------
|
||
444 | |||
445 | // function to calculate and report the Time of Flight to the GUI/display
|
||
446 | int reportTOF(int idx, uint32_t tofx); |
||
447 | void clearDistTable(int idx); |
||
448 | void setTagDist(int tidx, int aidx); |
||
449 | double getTagDist(int idx); |
||
450 | |||
451 | // clear the status/ranging data
|
||
452 | void instanceclearcounts(void) ; |
||
453 | |||
454 | //-------------------------------------------------------------------------------------------------------------
|
||
455 | //
|
||
456 | // Functions used in driving/controlling the ranging application
|
||
457 | //
|
||
458 | //-------------------------------------------------------------------------------------------------------------
|
||
459 | |||
460 | void instance_close(void); |
||
461 | // Call init, then call config, then call run. call close when finished
|
||
462 | // initialise the instance (application) structures and DW1000 device
|
||
463 | 26dead12 | Cung Sang | int instance_init(DW1000Driver* drv);
|
464 | 33f54213 | Cung Sang | |
465 | 69a601a5 | Cung Sang | // configure the instance and DW1000 device
|
466 | 4172c48d | Cung Sang | void instance_config(instanceConfig_t *config, sfConfig_t *sfconfig, DW1000Driver* drv) ;
|
467 | 69a601a5 | Cung Sang | |
468 | // configure the MAC address
|
||
469 | void instancesetaddresses(uint16_t address) ;
|
||
470 | |||
471 | void inst_processrxtimeout(instance_data_t *inst);
|
||
472 | |||
473 | // called (periodically or from and interrupt) to process any outstanding TX/RX events and to drive the ranging application
|
||
474 | int instance_run(void) ; // returns indication of status report change |
||
475 | int testapprun(instance_data_t *inst, int message); |
||
476 | |||
477 | // calls the DW1000 interrupt handler
|
||
478 | #define instance_process_irq(x) dwt_isr() //call device interrupt handler |
||
479 | // configure TX/RX callback functions that are called from DW1000 ISR
|
||
480 | void instance_rxcallback(const dwt_cb_data_t *rxd); |
||
481 | void instance_txcallback(const dwt_cb_data_t *txd); |
||
482 | void instance_rxtimeoutcallback(const dwt_cb_data_t *rxd); |
||
483 | void instance_rxerrorcallback(const dwt_cb_data_t *rxd); |
||
484 | |||
485 | |||
486 | |||
487 | // sets the Tag sleep delay time (the time Tag "sleeps" between each ranging attempt)
|
||
488 | void instancesettagsleepdelay(int rangingsleep); |
||
489 | void instancesetreplydelay(int delayms); |
||
490 | |||
491 | // set/get the instance roles e.g. Tag/Anchor/Listener
|
||
492 | void instancesetrole(int mode) ; // |
||
493 | int instancegetrole(void) ; |
||
494 | // get the DW1000 device ID (e.g. 0xDECA0130 for DW1000)
|
||
495 | uint32_t instancereaddeviceid(void) ; // Return Device ID reg, enables validation of physical device presence |
||
496 | |||
497 | double instancegetidist(int idx); |
||
498 | double instancegetidistraw(int idx); |
||
499 | int instancegetidist_mm(int idx); |
||
500 | int instancegetidistraw_mm(int idx); |
||
501 | uint8_t instancevalidranges(void);
|
||
502 | void instancecleardisttableall(void); |
||
503 | |||
504 | void instance_backtoanchor(instance_data_t *inst);
|
||
505 | int instancesenddlypacket(instance_data_t *inst, int delayedTx); |
||
506 | |||
507 | int instancegetrnum(void); |
||
508 | int instancegetrnuma(int idx); |
||
509 | int instancegetrnumanc(int idx); |
||
510 | int instancegetlcount(void); |
||
511 | |||
512 | int instancenewrangeancadd(void); |
||
513 | int instancenewrangetagadd(void); |
||
514 | int instancenewrangepolltim(void); |
||
515 | int instancenewrange(void); |
||
516 | 26dead12 | Cung Sang | uint32_t instancenewrangetim(void);
|
517 | 69a601a5 | Cung Sang | |
518 | uint64_t convertmicrosectodevicetimeu (double microsecu);
|
||
519 | double convertdevicetimetosec(int32_t dt);
|
||
520 | |||
521 | |||
522 | 33f54213 | Cung Sang | // -------------------------------------------------------------------------------------------------------------------
|
523 | // Deca Calibration Values
|
||
524 | // -------------------------------------------------------------------------------------------------------------------
|
||
525 | |||
526 | #define DWT_PRF_64M_RFDLY (514.462f) |
||
527 | #define DWT_PRF_16M_RFDLY (513.9067f) |
||
528 | |||
529 | /* Extern declaration while defining them in .c file */
|
||
530 | 69a601a5 | Cung Sang | extern const uint16_t rfDelays[2]; |
531 | extern const uint16_t rfDelaysTREK[2]; |
||
532 | extern const tx_struct txSpectrumConfig[8]; |
||
533 | extern instance_data_t instance_data[NUM_INST] ;
|
||
534 | |||
535 | 33f54213 | Cung Sang | extern sfConfig_t sfConfig[4]; |
536 | extern instanceConfig_t chConfig[4]; |
||
537 | |||
538 | 69a601a5 | Cung Sang | |
539 | int instance_peekevent(void); |
||
540 | |||
541 | void instance_saveevent(event_data_t newevent, uint8_t etype);
|
||
542 | |||
543 | event_data_t instance_getsavedevent(void);
|
||
544 | |||
545 | void instance_putevent(event_data_t newevent, uint8_t etype);
|
||
546 | |||
547 | event_data_t* instance_getevent(int x);
|
||
548 | |||
549 | void instance_clearevents(void); |
||
550 | |||
551 | void instance_notify_DW1000_inIDLE(int idle); |
||
552 | |||
553 | double dwt_getrangebias(uint8_t chan, float range, uint8_t prf); |
||
554 | |||
555 | uint32_t dwt_getotptxpower(uint8_t prf, uint8_t chan); |
||
556 | |||
557 | uint16_t dwt_getTREKOTPantennadelay(uint8_t anchor, uint8_t chan, uint8_t datarate); |
||
558 | |||
559 | uint16_t dwt_readantennadelay(uint8_t prf); |
||
560 | |||
561 | // configure TX power
|
||
562 | void instanceconfigtxpower(uint32_t txpower);
|
||
563 | void instancesettxpower(void); |
||
564 | |||
565 | // configure the antenna delays
|
||
566 | void instanceconfigantennadelays(uint16_t tx, uint16_t rx);
|
||
567 | void instancesetantennadelays(void); |
||
568 | uint16_t instancetxantdly(void);
|
||
569 | uint16_t instancerxantdly(void);
|
||
570 | |||
571 | int instance_starttxtest(int framePeriod); |
||
572 | |||
573 | 33f54213 | Cung Sang | |
574 | |||
575 | 69a601a5 | Cung Sang | #endif /* defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1) */ |
576 | |||
577 | #ifdef __cplusplus
|
||
578 | } |
||
579 | #endif
|
||
580 | |||
581 | #endif /* DECAINSTANCE_V1_H */ |