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 24:6f25ba679490, committed 2014-11-27
- Comitter:
- manumaet
- Date:
- Thu Nov 27 16:26:42 2014 +0000
- Parent:
- 23:661a79e56208
- Child:
- 25:d58b0595b300
- Commit message:
- no more printfs and heap in interrupt, ack of every frame works
Changed in this revision
--- a/DW1000/DW1000.cpp Thu Nov 27 13:34:35 2014 +0000
+++ b/DW1000/DW1000.cpp Thu Nov 27 16:26:42 2014 +0000
@@ -56,11 +56,9 @@
sendFrame((uint8_t*)message, strlen(message)+1);
}
-char* DW1000::receiveString() {
+void DW1000::receiveString(char* message) {
uint16_t framelength = getFramelength();
- char* receive = new char[framelength]; // prepare memory for the string on the heap
- readRegister(DW1000_RX_BUFFER, 0, (uint8_t*)receive, framelength); // get data from buffer
- return receive;
+ readRegister(DW1000_RX_BUFFER, 0, (uint8_t*)message, framelength); // get data from buffer
}
void DW1000::sendFrame(uint8_t* message, uint16_t length) {
@@ -75,7 +73,7 @@
if (receiving) stopTRX(); // stop receiving if we are in this state
sending = true;
writeRegister8(DW1000_SYS_CTRL, 0, 0x02); // trigger sending process by setting the TXSTRT bit
- //if (receiving) startRX();
+ if (receiving) startRX();
}
void DW1000::startRX() {
--- a/DW1000/DW1000.h Thu Nov 27 13:34:35 2014 +0000
+++ b/DW1000/DW1000.h Thu Nov 27 16:26:42 2014 +0000
@@ -1,4 +1,4 @@
-// by Manuel Stalder & Matthias Grob 2015
+// by Matthias Grob & Manuel Stalder - ETH Zürich - 2015
#ifndef DW1000_H
#define DW1000_H
@@ -63,7 +63,7 @@
uint64_t getStatus(); // get the 40 bit device status
void sendString(char* message); // to send String with arbitrary length
- char* receiveString(); // to receive char string with arbitrary length (ATTENTION! you have to delete the returned memory location like "client delete[] receivedMessage;")
+ void receiveString(char* message); // to receive char string (length of the buffer must be 1021 to be safe)
void sendFrame(uint8_t* message, uint16_t length); // send a raw frame (length in bytes)
void startRX(); // start listening for frames
void stopRX(); // stop listening for frames
--- a/main.cpp Thu Nov 27 13:34:35 2014 +0000
+++ b/main.cpp Thu Nov 27 16:26:42 2014 +0000
@@ -1,3 +1,4 @@
+// by Matthias Grob & Manuel Stalder - ETH Zürich - 2015
#include "mbed.h"
#include "PC.h" // Serial Port via USB for debugging with Terminal
#include "DW1000.h"
@@ -5,42 +6,55 @@
PC pc(USBTX, USBRX, 921600); // USB UART Terminal
DW1000 dw(PA_7, PA_6, PA_5, PB_6, PB_9); // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ)
-const float timeunit = 1/(128*499.2e6);
+const float timeunit = 1/(128*499.2);
int i=0;
-char message[1200] = "";
-uint64_t TX_timestamp = 0;
-uint64_t RX_timestamp = 0;
+char message[1021] = "";
+char messageRX[1021] = "";
+
+uint64_t TX_timestamp;
+uint64_t RX_timestamp;
+
+int event_i = 0;
+char event[10][20];
+uint64_t eventtimes[10];
void callbackRX(int framelength) {
+ TX_timestamp = dw.readRegister40(DW1000_TX_TIME, 0);
RX_timestamp = dw.readRegister40(DW1000_RX_TIME, 0);
- if (framelength < 200) {
- char* receive = dw.receiveString(); // receive a string
- pc.printf("Received: \"%s\" %d ", receive, framelength);
- pc.printf("Status: %010llX ", dw.getStatus());
+ dw.receiveString(messageRX); // receive a string
#if 0
- sprintf(message, "ACK \"%s\"", receive);
- dw.sendString(message);
- wait(0.1);
+ message[0] = 'A';
+ for(int i = 0; i < 10; i++)
+ message[i+1] = messageRX[i];
+ dw.sendString(message);
#endif
- delete[] receive;
- } else
- pc.printf("Received! %d ", framelength);
-
- uint64_t difference = RX_timestamp - TX_timestamp;
- //pc.printf("Timestamp: %lld\r\n", difference);
- pc.printf("Time since TX: %fs\r\n", difference*timeunit); // TODO: gives some wrong values because of timer overflow
+ eventtimes[event_i] = RX_timestamp - TX_timestamp; // TODO: gives some wrong values because of timer overflow
+ event[event_i][0] = '!';
+ event[event_i][1] = 'R';
+ event[event_i][2] = ' ';
+ for(int i = 0; i < 10; i++)
+ event[event_i][i+3] = messageRX[i];
+ if (event_i == 8)
+ event_i = 0;
+ else
+ event_i++;
dw.startRX();
}
void callbackTX() {
//TX_timestamp = dw.readRegister40(DW1000_TX_TIME, 0);
- /*char messagecheck[1021];
- dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, 1021);
- if (i < 200)
- pc.printf("%d Sent: \"%s\" %d ", i, messagecheck, strlen(messagecheck)+1);
+ //dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, 1021);
+ //pc.printf("! %d Sent: \"%s\" %d\r\n", i, message, strlen(message)+1);
+ eventtimes[event_i] = 0;
+ event[event_i][0] = '!';
+ event[event_i][1] = 'S';
+ event[event_i][2] = ' ';
+ for(int i = 0; i < 10; i++)
+ event[event_i][i+3] = message[i];
+ if (event_i == 8)
+ event_i = 0;
else
- pc.printf("%d Sent! %d ", i, strlen(messagecheck)+1);*/
- pc.printf("SENT!! Status: %010llX\r\n", dw.getStatus());
+ event_i++;
}
int main() {
@@ -54,23 +68,29 @@
dw.callbackTX = &callbackTX;
// Receiver initialisation
- dw.writeRegister16(DW1000_SYS_MASK, 0, 0x4080); //| 0x0080); // TODO: RX only good frame 0x4000, RX all frames 0x2000, TX done 0x0080
+ dw.writeRegister16(DW1000_SYS_MASK, 0, 0x4000); //| 0x0080); // TODO: RX only good frame 0x4000, RX all frames 0x2000, TX done 0x0080
dw.startRX();
while(1) {
+ for(int i = 0; i < 10; i++)
+ if(event[i][0] == '!') {
+ pc.printf("%s Time: %fus\r\n", event[i], eventtimes[i]*timeunit);
+ event[i][0] = 'X';
+ }
#if 1
- sprintf(message, "Hi %d", i);
- if ((i % 10) > 5) {
+ sprintf(message, "%d", i);
+ //if ((i % 10) > 5) {
dw.sendString(message);
//pc.printf("%d Sent: \"%s\" %d \r\n", i, message, strlen(message)+1);
- }
+ //}
#endif
#if 0
pc.printf("%d Waiting... %d %d ", i, dw.receiving, dw.sending);
wait(5);
#endif
- wait(0.2);
+ wait(1);
//pc.printf("Status: %010llX\r\n", dw.getStatus());
+ //pc.printf("State: %010llX\r\n", dw.readRegister40(DW1000_SYS_STATE, 0));
i++;
}
}
\ No newline at end of file