Skip to content
Snippets Groups Projects
Commit 9da89eec authored by Jake Read's avatar Jake Read
Browse files

unfuxed by flummoxing earle pio code

parent bd497223
Branches
No related tags found
No related merge requests found
...@@ -61,9 +61,17 @@ Not totally sure, but I'm going to move on to try out Earle's software serial PI ...@@ -61,9 +61,17 @@ Not totally sure, but I'm going to move on to try out Earle's software serial PI
So - let's try this out. So - let's try this out.
OK, my big dawg `earle` looks to have this locked down, it is werken. It's also wrapped in the arduino Serial API meaning I could use 'em in an abstracted class for P2P comms. Bless his heart, now I need to check i.e. continuity and make some measurements... OK, I have this up and running: I am streaming at a fixed BAUD, then counting the ratio of bytes we miss in a stream. The uc's are counting missed and proper bytes (reading monotonic sequence numbers) and then checking also intervals between transmissions...
Ah, jesus, nevermind, it is catching garbage bytes... all 255's, and it's reporting new-byteness when in fact none are visible on the line. | Mbit/s | Misses (errs / total-bytes) | Expected Byte Time (us) | Avg Byte Time |
| --- | --- | --- | --- |
| 0.1 | nil | 100 | 110.2 |
| 0.5 | nil | 20 | 22.2 |
| 1.0 | 0.025 (1/40) (!) | 10 | 13.4 |
| 2.5 | 0.497 | 4 | 11.0 |
| 5.0 | 0.755 | 2 | 11.0 |
So, I'm not convinced that I haven't fuxd anything here... it seems wild that we would have such a bottleneck to performance, and there are a few red flags here; namely that we have a lower bound of 11us between transmits, which would also explain our increasing error rate when we surpass 1 Mbit/sec (as the byte-wise period there is 10us or so).
--- ---
......
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
// "D10" - GPIO 3 // "D10" - GPIO 3
#define PIN_DEBUG 3 #define PIN_DEBUG 3
// on XIAO "RX" - GPIO 1
#define PIN_RX 1 #define PIN_RX 1
#define PIO_BAUD 1000000 #define PIN_TX 0
#define PIO_BAUD 2500000
SerialPIO serial(SerialPIO::NOPIN, PIN_RX); SerialPIO serial(PIN_TX, PIN_RX);
void setup(void){ void setup(void){
pinMode(PIN_LED_B, OUTPUT); pinMode(PIN_LED_B, OUTPUT);
...@@ -27,39 +27,70 @@ void setup(void){ ...@@ -27,39 +27,70 @@ void setup(void){
} }
uint32_t lastUpdate = 0; uint32_t lastUpdate = 0;
uint32_t updateInterval = 200; uint32_t updateInterval = 1000;
uint8_t expectedRx = 0; uint8_t expectedRx = 0;
uint32_t missCount = 0; uint32_t missCount = 0;
uint32_t catchCount = 0; uint32_t catchCount = 0;
uint8_t expected_miss = 0;
uint8_t actual_miss = 0;
uint8_t chars[256]; uint8_t chars[256];
uint8_t seqNum = 0;
// and let's calculate actual bandwidth (success bytes / sec * 8) and bitrate ( * 10)
// and record avg per-cycle pickup ?
uint32_t lastTx = 0;
float intervalEstimate = 0.0F;
void loop(void){ void loop(void){
// catch 'em AFAP
if(serial.available()){ if(serial.available()){
// earle core throws -1 if we have an error, while(serial.available()){
int data = serial.read(); int data = serial.read();
// earle core throws -1 if we have an error,
if(data < 0) { if(data < 0) {
return; return;
} }
// count total hits // count total hits
catchCount ++; catchCount ++;
// catch data and count sequence errors // stuff it
digitalWrite(PIN_DEBUG, !digitalRead(PIN_DEBUG));
chars[catchCount & 255] = data; chars[catchCount & 255] = data;
// check for missus
if(data != expectedRx){ if(data != expectedRx){
actual_miss = data;
expected_miss = expectedRx;
missCount ++; missCount ++;
} }
expectedRx = data + 1; expectedRx = data + 1;
} }
// uint8_t data = uart_rx_program_getc(pio, sm); }
// digitalWrite(PIN_DEBUG, LOW);
// and write AFAP, recording outgoing times
if(serial.availableForWrite()){
digitalWrite(PIN_DEBUG, !digitalRead(PIN_DEBUG));
serial.write(seqNum ++);
uint32_t txTime = micros();
uint32_t txInterval = txTime - lastTx;
lastTx = txTime;
intervalEstimate = (float)txInterval * 0.01F + intervalEstimate * 0.99F;
// while(serial.availableForWrite()){
// }
}
// ... // ...
if(lastUpdate + updateInterval < millis()){ if(lastUpdate + updateInterval < millis()){
lastUpdate = millis(); lastUpdate = millis();
digitalWrite(PIN_LED_B, !digitalRead(PIN_LED_B)); digitalWrite(PIN_LED_B, !digitalRead(PIN_LED_B));
displayPrint(String(missCount) + " / " + String(catchCount) + " \n" + displayPrint(String(missCount) + " / " + String(catchCount) + " \n" +
String(chars[0]) + ", " + String(chars[1]) + ", " + String(chars[2]) + ", " + String(chars[3]) + ", " + String(chars[4]) + ", " + String(chars[5]) + ", " "miss: " + String((float)missCount / (float)catchCount, 9) + "\n" +
String(expected_miss) + ": " + String(actual_miss) + "\n" +
"avg interval: " + String(intervalEstimate, 4)
// String(chars[0]) + ", " + String(chars[1]) + ", " + String(chars[2]) + ", " + String(chars[3]) + ", " + String(chars[4]) + ", " + String(chars[5]) + ", "
); );
// displayPrint(spipi_print()); // displayPrint(spipi_print());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment