init

Dependencies:   aconno_I2C Lis2dh12 WatchdogTimer

Committer:
pathfindr
Date:
Mon Feb 17 23:24:52 2020 +0000
Revision:
58:8d4a354816b1
usb

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pathfindr 58:8d4a354816b1 1 #ifndef MM2WAYRANGING_H
pathfindr 58:8d4a354816b1 2 #define MM2WAYRANGING_H
pathfindr 58:8d4a354816b1 3
pathfindr 58:8d4a354816b1 4 #include "mbed.h"
pathfindr 58:8d4a354816b1 5 #include "DW1000.h"
pathfindr 58:8d4a354816b1 6
pathfindr 58:8d4a354816b1 7
pathfindr 58:8d4a354816b1 8 #define TIMEUNITS_TO_US (1/(128*499.2)) // conversion between the decawave timeunits (ca 15.65ps) to microseconds.
pathfindr 58:8d4a354816b1 9 #define US_TO_TIMEUNITS (128*499.2) // conversion between microseconds to the decawave timeunits (ca 15.65ps).
pathfindr 58:8d4a354816b1 10 #define MMRANGING_2POWER40 1099511627776 // decimal value of 2^40 to correct timeroverflow between timestamps
pathfindr 58:8d4a354816b1 11
pathfindr 58:8d4a354816b1 12 //Predefined delay for the critical answers in the ranging algorithm
pathfindr 58:8d4a354816b1 13 //HAS TO BE BIGGER THAN THE PROCESSING TIME OF THE FRAME ON THE NODE
pathfindr 58:8d4a354816b1 14 #define ANSWER_DELAY_US 2500 //2500 works for 110kbps, 900 for 6.8Mbps
pathfindr 58:8d4a354816b1 15 #define ANSWER_DELAY_TIMEUNITS ANSWER_DELAY_US * (128*499.2)
pathfindr 58:8d4a354816b1 16
pathfindr 58:8d4a354816b1 17 class MM2WayRanging {
pathfindr 58:8d4a354816b1 18
pathfindr 58:8d4a354816b1 19 public:
pathfindr 58:8d4a354816b1 20 MM2WayRanging(DW1000& DW);
pathfindr 58:8d4a354816b1 21
pathfindr 58:8d4a354816b1 22 bool beacon_requestRanging();
pathfindr 58:8d4a354816b1 23 void anchor_standbyToRange();
pathfindr 58:8d4a354816b1 24
pathfindr 58:8d4a354816b1 25 bool isBeacon;
pathfindr 58:8d4a354816b1 26 uint8_t address; // Identifies the nodes as source and destination in rangingframes
pathfindr 58:8d4a354816b1 27 bool overflow; // TRUE if counter overflows while ranging
pathfindr 58:8d4a354816b1 28
pathfindr 58:8d4a354816b1 29 private:
pathfindr 58:8d4a354816b1 30 DW1000& dw;
pathfindr 58:8d4a354816b1 31 Timer LocalTimer;
pathfindr 58:8d4a354816b1 32
pathfindr 58:8d4a354816b1 33 bool waitForFrameTX(float time_before);
pathfindr 58:8d4a354816b1 34 bool waitForFrameRX(float time_before);
pathfindr 58:8d4a354816b1 35 void callbackRX();
pathfindr 58:8d4a354816b1 36 void callbackTX();
pathfindr 58:8d4a354816b1 37
pathfindr 58:8d4a354816b1 38 void beacon_ready_Send();
pathfindr 58:8d4a354816b1 39 void anchor_to_beacon_Send(uint8_t destination);
pathfindr 58:8d4a354816b1 40 void beacon_to_anchor_response_Send(uint8_t destination, uint64_t rxTimestamp);
pathfindr 58:8d4a354816b1 41
pathfindr 58:8d4a354816b1 42 //void correctReceiverTimestamps(uint8_t source);
pathfindr 58:8d4a354816b1 43 //void correctSenderTimestamps(uint8_t source);
pathfindr 58:8d4a354816b1 44
pathfindr 58:8d4a354816b1 45 enum FrameType{
pathfindr 58:8d4a354816b1 46 BEACON_READY=1,
pathfindr 58:8d4a354816b1 47 ANCHOR_TO_BEACON_PING,
pathfindr 58:8d4a354816b1 48 BEACON_TO_ANCHOR_RESPONSE
pathfindr 58:8d4a354816b1 49 };
pathfindr 58:8d4a354816b1 50
pathfindr 58:8d4a354816b1 51 //the packed attribute makes sure the types only use their respective size in memory (8 bit for uint8_t), otherwise they would always use 32 bit
pathfindr 58:8d4a354816b1 52 //IT IS A GCC SPECIFIC DIRECTIVE
pathfindr 58:8d4a354816b1 53 struct __attribute__((packed, aligned(1))) RangingFrame {
pathfindr 58:8d4a354816b1 54 uint8_t source;
pathfindr 58:8d4a354816b1 55 uint8_t destination;
pathfindr 58:8d4a354816b1 56 uint8_t type;
pathfindr 58:8d4a354816b1 57 };
pathfindr 58:8d4a354816b1 58
pathfindr 58:8d4a354816b1 59 RangingFrame rangingFrame; // buffer in class for sending a frame (not made locally because then we can recall in the interrupt what was sent)
pathfindr 58:8d4a354816b1 60 RangingFrame receivedFrame;
pathfindr 58:8d4a354816b1 61
pathfindr 58:8d4a354816b1 62 uint64_t RxTimestamp;
pathfindr 58:8d4a354816b1 63 uint64_t rangingTxTimestamp[5];
pathfindr 58:8d4a354816b1 64 uint64_t rangingRxTimestamp[5];
pathfindr 58:8d4a354816b1 65 uint64_t rangingTOF[5];
pathfindr 58:8d4a354816b1 66 float rangingDistance[5];
pathfindr 58:8d4a354816b1 67 };
pathfindr 58:8d4a354816b1 68 #endif