Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Revision:
50:50b8aea54a51
Parent:
48:5999e510f154
Child:
53:79a72d752ec4
--- a/DW1000/DW1000.cpp	Tue Nov 24 16:43:13 2015 +0000
+++ b/DW1000/DW1000.cpp	Thu Nov 26 21:42:51 2015 +0000
@@ -1,9 +1,14 @@
 #include "DW1000.h"
 
+// Change this depending on whether damaged or heatlhy DWM1000 modules are used.
+const bool DWM1000_DAMAGED = true;
+
 //#include "PC.h"
 //static PC pc(USBTX, USBRX, 115200);           // USB UART Terminal
 
 DW1000::DW1000(SPI& spi, InterruptMultiplexer& irq_mp, PinName CS, PinName RESET) : spi(spi), cs(CS), irq_mp(irq_mp), reset(RESET) {
+    irq_index = irq_mp.addCallback(this, &DW1000::ISR, false);
+
     setCallbacks(NULL, NULL);
 
     deselect();                         // Chip must be deselected first
@@ -57,22 +62,20 @@
     writeRegister16(DW1000_LDE_CTRL, 0x1804, 16384); // = 2^14 a quarter of the range of the 16-Bit register which corresponds to zero calibration in a round trip (TX1+RX2+TX2+RX1)
 
     writeRegister8(DW1000_SYS_CFG, 3, 0x20);    // enable auto reenabling receiver after error
-    
-    irq_index = irq_mp.addISR(this, &DW1000::ISR);
 }
 
 void DW1000::setCallbacks(void (*callbackRX)(void), void (*callbackTX)(void)) {
     bool RX = false;
     bool TX = false;
     if (callbackRX) {
-        DW1000::callbackRX.attach(callbackRX);
+        this->callbackRX.attach(callbackRX);
         RX = true;
     }
     if (callbackTX) {
-        DW1000::callbackTX.attach(callbackTX);
+        this->callbackTX.attach(callbackTX);
         TX = true;
     }
-    setInterrupt(RX,TX);
+    setInterrupt(RX, TX);
 }
 
 uint32_t DW1000::getDeviceID() {
@@ -215,13 +218,26 @@
 }
 
 void DW1000::hardwareReset(PinName reset_pin) {
-    DigitalOut reset(reset_pin);
-    reset = 1;
-    wait_ms(100);
-    reset = 0;
-    wait_ms(100);
-    reset = 1;
-    wait_ms(100);
+    // DWM1000 RESET logic.
+    if (DWM1000_DAMAGED) {
+        // The following code works for damaged DWM1000 modules.
+        // IMPORTANT: This will damage healthy DWM1000 modules!
+        DigitalInOut reset(reset_pin);
+        reset.output();
+        reset = 1;
+        wait_ms(100);
+        reset = 0;
+        wait_ms(100);
+        reset = 1;
+        wait_ms(100);
+    } else {
+        // The following code works for healthy DWM1000 modules
+        DigitalInOut reset(reset_pin);
+        reset.output();
+        reset = 0;
+        wait_ms(100);
+        reset.input();
+    }
 }
 
 void DW1000::resetAll() {
@@ -246,7 +262,6 @@
 }
 
 void DW1000::ISR() {
-//    pc.printf("ISR\r\n");
     uint64_t status = getStatus();
     if (status & 0x4000) {                                          // a frame was received
         callbackRX.call();
@@ -337,18 +352,22 @@
 }
 
 void DW1000::select() {     // always called to start an SPI transmission
-    irq_mp.disable(irq_index);
+    irq_mp.getIRQ().disable_irq();
     cs = 0;                 // set Cable Select pin low to start transmission
 }
+
 void DW1000::deselect() {   // always called to end an SPI transmission
     cs = 1;                 // set Cable Select pin high to stop transmission
-    irq_mp.enable(irq_index);
+    irq_mp.getIRQ().enable_irq();
 }
 
 void DW1000::enable_irq() {     // always called to start an SPI transmission
     //pc.printf("Enabling irq %d\r\n", irq_index);
-    irq_mp.enable(irq_index);
+    irq_mp.enableCallback(irq_index);
+    //irq_mp.enable_irq();
 }
+
 void DW1000::disable_irq() {   // always called to end an SPI transmission
-    irq_mp.disable(irq_index);
+    irq_mp.disableCallback(irq_index);
+    //irq_mp.disable_irq();
 }