RTOS safe buffered serial driver
Fork of SerialDriver by
Revision 4:3c0d0c37ad75, committed 2015-02-23
- Comitter:
- rosterloh84
- Date:
- Mon Feb 23 13:06:32 2015 +0000
- Parent:
- 3:ea9719695b6a
- Commit message:
- Added tx and rx overflow callback and message complete callback
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 |
diff -r ea9719695b6a -r 3c0d0c37ad75 SerialDriver.cpp --- a/SerialDriver.cpp Mon Jan 26 19:21:56 2015 +0000 +++ b/SerialDriver.cpp Mon Feb 23 13:06:32 2015 +0000 @@ -156,9 +156,14 @@ rxBuffer[rxIn]= (unsigned char)c; rxIn= (rxIn+1) % rxBufferLength; rxCount++; + if ('\n' == c) { + _callback_auto_detect.call(); + } } - else // drop byte :( + else { // drop byte :( numRxDrops++; + _callback_rx_overflow.call(); + } } if(wasEmpty && !isRxBufferEmpty()) // more bytes can go
diff -r ea9719695b6a -r 3c0d0c37ad75 SerialDriver.h --- a/SerialDriver.h Mon Jan 26 19:21:56 2015 +0000 +++ b/SerialDriver.h Mon Feb 23 13:06:32 2015 +0000 @@ -49,7 +49,13 @@ // drop counters volatile int numTxDrops, numRxDrops; + FunctionPointer _callback_rx_overflow; + FunctionPointer _callback_tx_overflow; + FunctionPointer _callback_auto_detect; + public: + enum IrqType { RxOvIrq = 0, TxOvIrq, RxAutoDetect}; + /// @brief Prepares ring buffer and irq /// /// If no buffer was set, the buffer gets allocated. @@ -62,6 +68,16 @@ SerialDriver(PinName txPin, PinName rxPin, int txBufferLength_= 256, int rxBufferLength_= 256, unsigned char * txBuffer_= NULL, unsigned char * rxBuffer_= NULL); + void attach(IrqType irq, void (*function)(void)) { + if (irq == RxOvIrq) { + _callback_tx_overflow.attach( function ); + } else if (irq == TxOvIrq) { + _callback_tx_overflow.attach( function ); + } else if (irq == RxAutoDetect) { + _callback_auto_detect.attach( function ); + } //else { } + } + //////////////////////////////////////////////////////////////// // Basic IO Operation