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.
Revision 29:019ff388ed76, committed 2014-11-28
- Comitter:
- manumaet
- Date:
- Fri Nov 28 16:45:10 2014 +0000
- Parent:
- 28:a830131560e8
- Child:
- 30:4ecc69d3cf8d
- Commit message:
- problem with member function pointers solved!
Changed in this revision
--- a/DW1000/DW1000.cpp Fri Nov 28 14:40:03 2014 +0000
+++ b/DW1000/DW1000.cpp Fri Nov 28 16:45:10 2014 +0000
@@ -17,9 +17,18 @@
irq.rise(this, &DW1000::ISR); // attach Interrupt handler to rising edge
}
-void DW1000::setCallbacks(void (*callbackRX)(), void (*callbackTX)()) {
- DW1000::callbackRX = callbackRX;
- DW1000::callbackTX = callbackTX;
+void DW1000::setCallbacks(void (*callbackRX)(void), void (*callbackTX)(void)) {
+ bool RX = false;
+ bool TX = false;
+ if (callbackRX) {
+ DW1000::callbackRX.attach(callbackRX);
+ RX = true;
+ }
+ if (callbackTX) {
+ DW1000::callbackTX.attach(callbackTX);
+ TX = true;
+ }
+ setInterrupt(RX,TX);
}
uint32_t DW1000::getDeviceID() {
@@ -54,10 +63,6 @@
return readRegister40(DW1000_SYS_STATUS, 0);
}
-void DW1000::setInterrupt(bool RX, bool TX) {
- writeRegister16(DW1000_SYS_MASK, 0, RX*0x4000 | TX*0x0080); // RX good frame 0x4000, TX done 0x0080
-}
-
uint64_t DW1000::getRXTimestamp() {
return readRegister40(DW1000_RX_TIME, 0);
}
@@ -117,17 +122,19 @@
writeRegister8(DW1000_PMSC, 3, 0xF0); // clear All reset
}
+
+void DW1000::setInterrupt(bool RX, bool TX) {
+ writeRegister16(DW1000_SYS_MASK, 0, RX*0x4000 | TX*0x0080); // RX good frame 0x4000, TX done 0x0080
+}
+
void DW1000::ISR() {
uint64_t status = getStatus();
if (status & 0x4000) { // a frame was received
- if (callbackRX != NULL)
- callbackRX();
+ callbackRX.call();
writeRegister16(DW1000_SYS_STATUS, 0, 0x6F00); // clearing of receiving status bits
}
if (status & 0x80) { // sending complete
- //startRX(); // enable receiver again if we need to preserve state TODO: have to do it here??
- if (callbackTX != NULL)
- callbackTX();
+ callbackTX.call();
writeRegister8(DW1000_SYS_STATUS, 0, 0xF8); // clearing of sending status bits
}
}
--- a/DW1000/DW1000.h Fri Nov 28 14:40:03 2014 +0000
+++ b/DW1000/DW1000.h Fri Nov 28 16:45:10 2014 +0000
@@ -54,7 +54,13 @@
class DW1000 {
public:
DW1000(PinName MOSI, PinName MISO, PinName SCLK, PinName CS, PinName IRQ); // constructor, uses SPI class
- void setCallbacks(void (*callbackRX)(), void (*callbackTX)()); // setter for callback function pointer fields
+ 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
+ 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);
+ }
// Device API
uint32_t getDeviceID(); // gets the Device ID which should be 0xDECA0130 (good for testing SPI!)
@@ -62,7 +68,6 @@
void setEUI(uint64_t EUI); // sets 64 bit Extended Unique Identifier according to IEEE standard
float getVoltage(); // gets the current chip voltage measurement form the A/D converter
uint64_t getStatus(); // get the 40 bit device status
- void setInterrupt(bool RX, bool TX); // set Interrupt for received a good frame (CRC ok) or transmission done
uint64_t getRXTimestamp();
uint64_t getTXTimestamp();
@@ -72,15 +77,16 @@
void startRX(); // start listening for frames
void stopTRX(); // disable tranceiver go back to idle mode
- private:
+ //private:
void loadLDE(); // load the leading edge detection algorithm to RAM, [IMPORTANT because receiving malfunction may occur] see User Manual LDELOAD on p22 & p158
void resetRX(); // soft reset only the tranciever part of DW1000
void resetAll(); // soft reset the entire DW1000 (some registers stay as they were see User Manual)
// Interrupt
InterruptIn irq; // Pin used to handle Events from DW1000 by an Interrupthandler
- void (*callbackRX)(); // function pointer to callback which is called when successfull RX took place
- void (*callbackTX)(); // function pointer to callback which is called when successfull TX took place
+ FunctionPointer callbackRX; // function pointer to callback which is called when successfull RX took place
+ FunctionPointer callbackTX; // function pointer to callback which is called when successfull TX took place
+ void setInterrupt(bool RX, bool TX); // set Interrupt for received a good frame (CRC ok) or transmission done
void ISR(); // interrupt handling method (also calls according callback methods)
uint16_t getFramelength(); // to get the framelength of the received frame from the PHY header
--- a/MMRanging/MMRanging.cpp Fri Nov 28 14:40:03 2014 +0000
+++ b/MMRanging/MMRanging.cpp Fri Nov 28 16:45:10 2014 +0000
@@ -8,7 +8,7 @@
event_i = 0;
counter = 0;
- dw.setInterrupt(true, true);
+ dw.setCallbacks(this, &MMRanging::callbackRX, &MMRanging::callbackTX);
dw.startRX();
}
--- a/main.cpp Fri Nov 28 14:40:03 2014 +0000
+++ b/main.cpp Fri Nov 28 16:45:10 2014 +0000
@@ -10,9 +10,6 @@
char message[100] = "";
-void callbackRX() {r.callbackRX();} // TODO: solve cast from memebr function pointer to function pointer
-void callbackTX() {r.callbackTX();}
-
int main() {
pc.printf("DecaWave 0.2\r\nup and running!\r\n");
dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a working SPI connection
@@ -21,7 +18,6 @@
pc.printf("Voltage: %f\r\n", dw.getVoltage());
r.receiver = true;
- dw.setCallbacks(&callbackRX, &callbackTX);
while(1) {
for(int j = 0; j < 10; j++)