An RTOS-friendly Serial interface Its primary benefit is that it never hogs the CPU. An amusing alternative to the traditional ring-bufferd interrupt-serviced systems, it uses short mbed-rtos queues to buffer characters to and from the UART, and a thread to service the transmitter. Short interrupt service routines enqueue received characters and signal the transmit thread when the transmitter is available. WARNING: Do not create RTOS-Serial objects before the RTOS is running! Put them inside your main() block or another function, not in the global initialization.
Dependents: Test_RDM880_rfid_reader
Diff: rtos_serial.cpp
- Revision:
- 7:dd892347b524
- Parent:
- 6:438a6c0acbd4
- Child:
- 8:3644d12758da
--- a/rtos_serial.cpp Sun Oct 20 05:36:16 2013 +0000 +++ b/rtos_serial.cpp Mon Oct 21 22:58:04 2013 +0000 @@ -52,7 +52,11 @@ int RTOS_Serial::get_index() { return _serial.index; } +#ifdef RTOS_Serial_underscore_putc +int RTOS_Serial::_putc(int c) { +#else int RTOS_Serial::putc(int c) { +#endif //return Serial::putc(c); //DEBUG //if (tx_q.put((int *)c, osWaitForever) == osOK) return c; else return EOF; int status; @@ -76,10 +80,18 @@ } int RTOS_Serial::parent_putc(int c) { +#ifdef RTOS_Serial_underscore_putc + return Serial::_putc(c); +#else return Serial::putc(c); +#endif } +#ifdef RTOS_Serial_underscore_getc +int RTOS_Serial::_getc() { +#else int RTOS_Serial::getc() { +#endif int rv; //return Serial::getc(); //FIXME: stand-in, which fails if we use our RX ISR osEvent evt = rx_q.get(); @@ -114,7 +126,7 @@ } // class method void RTOS_Serial::UART3_TX_ISR(){ - //uint32_t IRR = LPC_UART3->IIR; + //uint32_t IRR = LPC_UART3->IIR; //DEBUG: maybe this? //tx_emitter_threadp->signal_set(0x1); tx_tp[3]->signal_set(0x01); }