Buffered Serial Port Driver for RTOS
Dependents: nucleo_cannonball PiballNeoController
Buffered Serial Port Driver for RTOS
- ISR driven, ring buffered IO operation
- IO operations are idle waiting, don't waste time in RTOS :D
- Can use external buffers
- Based on mbed RawSerial
Example
SerialDriver Example
#include "SerialDriver.h" SerialDriver pc(USBTX, USBRX); int main() { // setup serial port pc.baud(9600); // print some text pc.puts("This is just a string.\r\n"); pc.printf("But this is a %s with integer %i and float %f.\r\n", "formatted text", 123, 0.456f); // now lets behave like a null modem while(1) pc.putc(pc.getc()); }
Look at the API Documentation for more Examples.
Dependencies
Import librarymbed
The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Import librarymbed-rtos
Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.
If you find a bug, please help me to fix it. Send me a message. You can help me a lot: Write a demo program that causes the bug reproducible.
Diff: SerialDriver.cpp
- Revision:
- 5:cb9007ef1a30
- Parent:
- 4:a41e47716932
- Child:
- 6:bf5fb8677212
--- a/SerialDriver.cpp Fri Oct 23 13:49:19 2015 +0000 +++ b/SerialDriver.cpp Fri Oct 23 13:55:39 2015 +0000 @@ -91,8 +91,7 @@ // write as long as you can bool wasFull= isTxBufferFull(); - bool wasEmpty= isTxBufferEmtpy(); - while(SerialBase::writeable() && !wasEmpty) + while(SerialBase::writeable() && !isTxBufferEmtpy()) { // take byte from tx buffer and put it out SerialBase::_base_putc(txBuffer[txOut]); @@ -103,10 +102,10 @@ if(wasFull && !isTxBufferFull()) // more bytes can come semTxBufferFull.release(); - // ok, let's wait for next writability - // if the is something to send, + // ok, let's wait for next writability, + // if there is something to send, // else we need tx interrupt not yet - if(wasEmpty); + if(!isTxBufferEmtpy()); enableTxInterrupt(); }