Simple driver for DWM1000 modules.
Diff: DW1000.cpp
- Revision:
- 2:12a2907957b8
- Parent:
- 0:2c8820705cdd
- Child:
- 4:faf802b4af85
--- a/DW1000.cpp Fri Jan 29 10:48:21 2016 +0000 +++ b/DW1000.cpp Fri Feb 05 13:48:42 2016 +0000 @@ -1,3 +1,5 @@ +// Adapted from Matthias Grob & Manuel Stalder - ETH Zürich - 2015 + #include "DW1000.h" // Change this depending on whether damaged or heatlhy DWM1000 modules are used. @@ -6,7 +8,8 @@ //#include "PC.h" //static PC pc(USBTX, USBRX, 115200); // USB UART Terminal -DW1000::DW1000(SPI& spi, InterruptIn& irq, PinName CS, PinName RESET) : spi(spi), cs(CS), irq(irq), reset(RESET) { +DW1000::DW1000(SPI& spi, InterruptIn& irq, PinName CS, PinName RESET) +: irq(irq), spi(spi), cs(CS), reset(RESET) { irq.rise(this, &DW1000::ISR); setCallbacks(NULL, NULL); @@ -65,6 +68,8 @@ writeRegister8(DW1000_SYS_CFG, 3, 0x20); // enable auto reenabling receiver after error irq.enable_irq(); + + startRX(); } void DW1000::setCallbacks(void (*callbackRX)(void), void (*callbackTX)(void)) { @@ -131,6 +136,10 @@ writeRegister8(DW1000_SYS_STATUS, 0, 0xF8); // clearing of sending status bits } +uint64_t DW1000::getSYSTimestamp() { + return readRegister40(DW1000_SYS_TIME, 0); +} + uint64_t DW1000::getRXTimestamp() { return readRegister40(DW1000_RX_TIME, 0); } @@ -139,6 +148,18 @@ return readRegister40(DW1000_TX_TIME, 0); } +float DW1000::getSYSTimestampUS() { + return getSYSTimestamp() * TIMEUNITS_TO_US; +} + +float DW1000::getRXTimestampUS() { + return getRXTimestamp() * TIMEUNITS_TO_US; +} + +float DW1000::getTXTimestampUS() { + return getTXTimestamp() * TIMEUNITS_TO_US; +} + uint16_t DW1000::getStdNoise() { return readRegister16(DW1000_RX_FQUAL, 0x00); } @@ -169,12 +190,12 @@ return readRegister16(DW1000_RX_FQUAL, 0x06); } -uint8_t DW1000::getPRF() { - uint16_t prf_mask = (0x1 << 19) | (0x1 << 18); - uint16_t prf = readRegister16(DW1000_CHAN_CTRL, 0x00); - prf >> 18; - prf &= 0x03; - return static_cast<uint8_t>(prf); +uint8_t DW1000::getPRF() +{ + uint32_t prf_mask = static_cast<uint32_t>(0x1 << 19 | 0x1 << 18); + uint32_t prf = readRegister32(DW1000_CHAN_CTRL, 0x00); + prf >>= 18; + return static_cast<uint8_t>(prf & prf_mask); } void DW1000::sendString(char* message) { @@ -201,6 +222,11 @@ } void DW1000::sendDelayedFrame(uint8_t* message, uint16_t length, uint64_t TxTimestamp) { + if (TxTimestamp > CONST_2POWER40) + { + TxTimestamp -= CONST_2POWER40; + } + //if (length >= 1021) length = 1021; // check for maximim length a frame can have with 1024 Byte frames [not used, see constructor] if (length >= 125) length = 125; // check for maximim length a frame can have with 127 Byte frames writeRegister(DW1000_TX_BUFFER, 0, message, length); // fill buffer