Buffered Serial Port Driver for RTOS tested with a K64F
Dependents: JRO_CR2 frdm_test JRO_DDSv2 JRO_DDSv2_rev2019
Fork of SerialDriver by
Examples/Example_Bridge.cpp@5:ee58295c58e1, 2015-02-10 (annotated)
- Committer:
- miguelcordero191
- Date:
- Tue Feb 10 14:29:32 2015 +0000
- Revision:
- 5:ee58295c58e1
- Parent:
- 4:3956012cd0c4
This library just was modified when a K64F is used
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
BlazeX | 0:cd0d79be0c1a | 1 | /// @file Example_Bridge.cpp |
BlazeX | 0:cd0d79be0c1a | 2 | /// @brief Forwarding every byte from USB to uart and vice versa |
BlazeX | 0:cd0d79be0c1a | 3 | /// |
BlazeX | 0:cd0d79be0c1a | 4 | /// - Uses SerialDriver with USBTX and USBRX. |
BlazeX | 0:cd0d79be0c1a | 5 | /// - Uses SerialDriver with p13 and p14. |
BlazeX | 0:cd0d79be0c1a | 6 | /// |
BlazeX | 0:cd0d79be0c1a | 7 | /// - LED1 indicates forwarding pc to uart works |
BlazeX | 0:cd0d79be0c1a | 8 | /// - LED2 indicates forwarding uart to pc works |
BlazeX | 0:cd0d79be0c1a | 9 | /// - LED4 indicates a parallel thread running |
BlazeX | 0:cd0d79be0c1a | 10 | /// |
BlazeX | 0:cd0d79be0c1a | 11 | /// - connect p13 with p14 to get a hardware null modem ;) |
BlazeX | 0:cd0d79be0c1a | 12 | |
BlazeX | 0:cd0d79be0c1a | 13 | #if 0 |
BlazeX | 0:cd0d79be0c1a | 14 | |
BlazeX | 0:cd0d79be0c1a | 15 | #include "SerialDriver.h" |
BlazeX | 0:cd0d79be0c1a | 16 | |
BlazeX | 0:cd0d79be0c1a | 17 | SerialDriver pc(USBTX, USBRX); |
miguelcordero191 | 4:3956012cd0c4 | 18 | SerialDriver uart(D0, D1); |
miguelcordero191 | 4:3956012cd0c4 | 19 | DigitalOut led1(LED1), led2(LED2), led4(LED3); |
BlazeX | 0:cd0d79be0c1a | 20 | |
BlazeX | 0:cd0d79be0c1a | 21 | // This thread forwards from pc to uart |
BlazeX | 0:cd0d79be0c1a | 22 | void forwardPc(void const * argument) |
BlazeX | 0:cd0d79be0c1a | 23 | { |
BlazeX | 0:cd0d79be0c1a | 24 | // Sometimes You're the Hammer, |
BlazeX | 0:cd0d79be0c1a | 25 | while(1) |
BlazeX | 0:cd0d79be0c1a | 26 | { |
BlazeX | 0:cd0d79be0c1a | 27 | uart.putc(pc.getc()); |
BlazeX | 0:cd0d79be0c1a | 28 | led1= !led1; |
BlazeX | 0:cd0d79be0c1a | 29 | } |
BlazeX | 0:cd0d79be0c1a | 30 | } |
BlazeX | 0:cd0d79be0c1a | 31 | |
BlazeX | 0:cd0d79be0c1a | 32 | // This thread forwards from uart to pc |
BlazeX | 0:cd0d79be0c1a | 33 | void forwardUart(void const * argument) |
BlazeX | 0:cd0d79be0c1a | 34 | { |
BlazeX | 0:cd0d79be0c1a | 35 | // Sometimes You're the Nail |
BlazeX | 0:cd0d79be0c1a | 36 | while(1) |
BlazeX | 0:cd0d79be0c1a | 37 | { |
BlazeX | 0:cd0d79be0c1a | 38 | pc.putc(uart.getc()); |
BlazeX | 0:cd0d79be0c1a | 39 | led2= !led2; |
BlazeX | 0:cd0d79be0c1a | 40 | } |
BlazeX | 0:cd0d79be0c1a | 41 | } |
BlazeX | 0:cd0d79be0c1a | 42 | |
BlazeX | 0:cd0d79be0c1a | 43 | int main() |
BlazeX | 0:cd0d79be0c1a | 44 | { |
BlazeX | 0:cd0d79be0c1a | 45 | // setup serial ports |
BlazeX | 0:cd0d79be0c1a | 46 | pc.baud(9600); |
miguelcordero191 | 4:3956012cd0c4 | 47 | uart.baud(9600); |
BlazeX | 0:cd0d79be0c1a | 48 | |
BlazeX | 0:cd0d79be0c1a | 49 | // Start the forwarding threads |
BlazeX | 0:cd0d79be0c1a | 50 | Thread forwardPcThread(&forwardPc); |
BlazeX | 0:cd0d79be0c1a | 51 | Thread forwardUartThread(&forwardUart); |
BlazeX | 0:cd0d79be0c1a | 52 | |
BlazeX | 0:cd0d79be0c1a | 53 | // Do something else now |
BlazeX | 0:cd0d79be0c1a | 54 | while(1) |
BlazeX | 0:cd0d79be0c1a | 55 | { |
BlazeX | 0:cd0d79be0c1a | 56 | Thread::wait(20); |
BlazeX | 0:cd0d79be0c1a | 57 | led4= !led4; |
BlazeX | 0:cd0d79be0c1a | 58 | } |
BlazeX | 0:cd0d79be0c1a | 59 | } |
BlazeX | 0:cd0d79be0c1a | 60 | |
BlazeX | 0:cd0d79be0c1a | 61 | #endif |
BlazeX | 1:1464146bd7fb | 62 |