Created
July 14, 2016 18:02
-
-
Save RickKimball/f30392aab4eb7a7ac65b54fc62915acd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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