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.

Files at this revision

API Documentation at this revision

Comitter:
BlazeX
Date:
Thu Oct 29 19:38:11 2015 +0000
Parent:
7:ce54b429086f
Commit message:
Beta Update: Could SerialDriver inherit RawSerial rather than SerialBase? Maybe, let's try!

Changed in this revision

SerialDriver.cpp Show annotated file Show diff for this revision Revisions of this file
SerialDriver.h Show annotated file Show diff for this revision Revisions of this file
--- a/SerialDriver.cpp	Tue Oct 27 17:51:30 2015 +0000
+++ b/SerialDriver.cpp	Thu Oct 29 19:38:11 2015 +0000
@@ -1,7 +1,7 @@
 #include "SerialDriver.h"
 
 SerialDriver::SerialDriver(PinName txPin, PinName rxPin, int txBufferLength_, int rxBufferLength_, unsigned char * txBuffer_, unsigned char * rxBuffer_)
-    : SerialBase(txPin, rxPin), semTxBufferFull(0), semRxBufferEmpty(0)
+    : RawSerial(txPin, rxPin), semTxBufferFull(0), semRxBufferEmpty(0)
 {    
     // check buffer length
     txBufferLength= txBufferLength_;
@@ -228,3 +228,4 @@
 } 
 
 // still thinking of XTN
+
--- a/SerialDriver.h	Tue Oct 27 17:51:30 2015 +0000
+++ b/SerialDriver.h	Thu Oct 29 19:38:11 2015 +0000
@@ -23,13 +23,13 @@
 /// @class SerialDriver
 /// @brief RTOS compatible buffered Serial port driver
 /// 
-/// - Based on SerialBase.
+/// - Based on RawSerial.
 /// - Can use external buffers.
 /// - ISR driven, ring buffered IO operation
 /// - Can Replace mbed RawSerial
 /// - IO operations are idle waiting, don't waste time in RTOS :D
 /// - Do not use attach methods for TxIrq or RxIrq! They are already in use.
-class SerialDriver : public SerialBase
+class SerialDriver : public RawSerial
 {
 protected:
     // ring buffered rx/tx