Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DecaWave by
Diff: DW1000/DW1000.cpp
- Revision:
- 21:23bf4399020d
- Parent:
- 20:257d56530ae1
- Child:
- 22:576ee999b004
--- a/DW1000/DW1000.cpp Tue Nov 25 15:22:53 2014 +0000 +++ b/DW1000/DW1000.cpp Wed Nov 26 12:10:09 2014 +0000 @@ -3,6 +3,8 @@ DW1000::DW1000(PinName MOSI, PinName MISO, PinName SCLK, PinName CS, PinName IRQ) : irq(IRQ), spi(MOSI, MISO, SCLK), cs(CS) { receiving = false; // state in the beginning is not listening for frames sending = false; // state in the beginning is not sending anything + callbackRX = NULL; // TODO: setter + callbackTX = NULL; deselect(); // Chip must be deselected first spi.format(8,0); // Setup the spi for standard 8 bit data and SPI-Mode 0 (GPIO5, GPIO6 open circuit or ground on DW1000) @@ -65,25 +67,27 @@ if (length >= 1021) length = 1021; // check for maximim length a frame can have TODO: 127 Byte mode? writeRegister(DW1000_TX_BUFFER, 0, message, length); // fill buffer - uint8_t backup = readRegister8(DW1000_TX_FCTRL, 1); // put length of frame including 2 CRC Bytes - length += 2; + uint8_t backup = readRegister8(DW1000_TX_FCTRL, 1); // put length of frame + length += 2; // including 2 CRC Bytes length = ((backup & 0xFC) << 8) | (length & 0x03FF); - writeRegister(DW1000_TX_FCTRL, 0, (uint8_t*)&length, 2); + writeRegister16(DW1000_TX_FCTRL, 0, length); - if (receiving) stopTRX(); // stop receiving if we are in this state - sending = true; + /*if (receiving)*/ stopTRX(); // stop receiving if we are in this state + //sending = true; + wait(0.01); writeRegister8(DW1000_SYS_CTRL, 0, 0x02); // trigger sending process by setting the TXSTRT bit + wait(0.01); } void DW1000::startRX() { - while(sending); // block until sending finished TODO: the right way?? - receiving = true; + //while(sending); // block until sending finished TODO: the right way?? + //receiving = true; writeRegister8(DW1000_SYS_CTRL, 0x01, 0x01); // start listening for preamble by setting the RXENAB bit } void DW1000::stopRX() { - receiving = false; stopTRX(); + //receiving = false; } // PRIVATE Methods ------------------------------------------------------------------------------------ @@ -113,13 +117,17 @@ void DW1000::ISR() { uint64_t status = getStatus(); if (status & 0x4000) { - callbackRX(getFramelength()); + if (callbackRX != NULL) + callbackRX(getFramelength()); } if (status & 0x80) { sending = false; - if (receiving) startRX(); // enable receiver again if we need to preserve state TODO: have to do it here?? - callbackTX(); + wait(0.1); + /*if (receiving)*/ startRX(); // enable receiver again if we need to preserve state TODO: have to do it here?? + if (callbackTX != NULL) + callbackTX(); } + //writeRegister16(DW1000_SYS_STATUS, 0, 0x1111); // TODO: clearing status bits not necessary? } uint16_t DW1000::getFramelength() {