RTOS safe buffered serial driver
Fork of SerialDriver by
Diff: SerialDriver.h
- Revision:
- 4:3c0d0c37ad75
- Parent:
- 3:ea9719695b6a
--- 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