Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#include "libmaple/ring_buffer.h"
#include "streaming.h"
uint8_t buffer[32];
ring_buffer message_buffer = { buffer, 0, 0, 32 - 1 };
void queue_message(const char *str) {
while (*str) {
GPIOC_BASE->BRR = (1 << 13); // time function using gpio toggle
rb_safe_insert(&message_buffer, *str++);
GPIOC_BASE->BSRR = (1 << 13);
// put a scope on PC13 to see how much time rb_safe_insert() actually takes
// I measured ~500 nano seconds
}
}
void setup() {
Serial.begin(115200);
pinMode(PC13, OUTPUT);
queue_message("Hello World\r\n");
}
void loop() {
if ( !rb_is_empty(&message_buffer)) {
Serial << "message size=" << rb_full_count(&message_buffer)
<< " head=" << message_buffer.head
<< " tail=" << message_buffer.tail
<< "\r\n";
Serial << "[";
do {
int c = rb_remove(&message_buffer);
Serial.write(c);
} while (!rb_is_empty(&message_buffer));
Serial << "]\r\n";
}
delay(1000);
queue_message("Hello Again\r\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment