Simple driver for DWM1000 modules.

Revision:
2:12a2907957b8
Parent:
1:19b5bef7ecf4
Child:
4:faf802b4af85
--- a/DW1000.h	Fri Jan 29 10:48:21 2016 +0000
+++ b/DW1000.h	Fri Feb 05 13:48:42 2016 +0000
@@ -1,10 +1,10 @@
 // Adapted from Matthias Grob & Manuel Stalder - ETH Zürich - 2015
+
 #ifndef DW1000_H
 #define DW1000_H
 
 #include "mbed.h"
 
-
 // register addresses
 //      Mnemonic                    Address Bytes Description
 #define DW1000_DEV_ID               0x00 //     4 Device Identifier – includes device type and revision information
@@ -51,13 +51,19 @@
 #define DW1000_SUBADDRESS_FLAG      0x40 // if we have a sub address second Bit has to be 1
 #define DW1000_2_SUBADDRESS_FLAG    0x80 // if we have a long sub adress (more than 7 Bit) we set this Bit in the first part
 
-class DW1000 {
-    public:            
+class DW1000
+{
+    public:
+        const static float TIMEUNITS_TO_US = (1/(128*499.2f));  // conversion between the decawave timeunits (ca 15.65ps) to microseconds.
+        const static float US_TO_TIMEUNITS = (128*499.2f);      // conversion between microseconds to the decawave timeunits (ca 15.65ps).
+        const static uint64_t CONST_2POWER40 = 1099511627776;  // Time register in DW1000 is 40 bit so this is needed to detect overflows.
+
         DW1000(SPI& spi, InterruptIn& irq, PinName CS, PinName RESET = NC);              // constructor, uses SPI class
 
         void setCallbacks(void (*callbackRX)(void), void (*callbackTX)(void));                  // setter for callback functions, automatically enables interrupt, if NULL is passed the coresponding interrupt gets disabled
         template<typename T>
-            void setCallbacks(T* tptr, void (T::*mptrRX)(void), void (T::*mptrTX)(void)) {      // overloaded setter to treat member function pointers of objects
+        void setCallbacks(T* tptr, void (T::*mptrRX)(void), void (T::*mptrTX)(void))
+        {      // overloaded setter to treat member function pointers of objects
             callbackRX.attach(tptr, mptrRX);                                                    // possible client code: dw.setCallbacks(this, &A::callbackRX, &A::callbackTX);
             callbackTX.attach(tptr, mptrTX);                                                    // concept seen in line 100 of http://developer.mbed.org/users/mbed_official/code/mbed/docs/4fc01daae5a5/InterruptIn_8h_source.html
             setInterrupt(true,true);
@@ -73,17 +79,21 @@
         bool hasReceivedFrame();
         void clearReceivedFlag();
         void clearSentFlag();
+        uint64_t getSYSTimestamp();
         uint64_t getRXTimestamp();
         uint64_t getTXTimestamp();
+        float getSYSTimestampUS();
+        float getRXTimestampUS();
+        float getTXTimestampUS();
 
-        uint16_t DW1000::getStdNoise();
-        uint16_t DW1000::getPACC();
-        uint16_t DW1000::getFPINDEX();
-        uint16_t DW1000::getFPAMPL1();
-        uint16_t DW1000::getFPAMPL2();
-        uint16_t DW1000::getFPAMPL3();
-        uint16_t DW1000::getCIRPWR();
-        uint8_t DW1000::getPRF();
+        uint16_t getStdNoise();
+        uint16_t getPACC();
+        uint16_t getFPINDEX();
+        uint16_t getFPAMPL1();
+        uint16_t getFPAMPL2();
+        uint16_t getFPAMPL3();
+        uint16_t getCIRPWR();
+        uint8_t getPRF();
         
         void sendString(char* message);                                                         // to send String with arbitrary length
         void receiveString(char* message);                                                      // to receive char string (length of the buffer must be 1021 to be safe)