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.h
- Revision:
- 18:8665cc17b30d
- Parent:
- 17:93011ddbd0a2
- Child:
- 19:d974f46f6882
diff -r 93011ddbd0a2 -r 8665cc17b30d rtos_serial.h --- a/rtos_serial.h Wed Oct 30 05:01:45 2013 +0000 +++ b/rtos_serial.h Wed Oct 30 05:53:06 2013 +0000 @@ -84,6 +84,34 @@ */ /** An RTOS-friendly serial port + * + * Example: + * @code + * // Bridge the USB serial interface to a uart + * #include "mbed.h" + * #include "rtos.h" + * #include "rtos_serial.h" + * + * DigitalOut myled(LED1); + * + * void p_to_p(const void* arg) { + * RTOS_Serial** ports = (RTOS_Serial**) arg; + * while (true) ports[1]->putc(ports[0]->getc()); + * } + * + * int main() { + * RTOS_Serial host(USBTX, USBRX); + * RTOS_Serial uart(p13, p14); + * RTOS_Serial *host_uart_ports[] = {&host, &uart}; + * Thread host_to_port_thread(p_to_p, (void*) host_uart_ports); + * RTOS_Serial *uart_host_ports[] = {&uart, &host}; + * Thread port_to_host_thread(p_to_p, (void*) uart_host_ports); + * + * while (true) { + * myled = !myled; + * Thread::wait(400); + * } + * } */ class RTOS_Serial : public RawSerial { public: