Inherit from Serial and use software buffers for TX and RX. This allows the UART peripherals to operate in a IRQ driven mode. Overrides most (but not all) stdio functions as Serial did

Dependencies:   Buffer

Dependents:   buffered_serial_test BLE_Police_HRM evena_BLE_Police_HRM df-2014-workshop-rfid-case-generator-k64f ... more


 #include "mbed.h"
 #include "BufferedSerial.h"

 BufferedSerial pc(USBTX, USBRX);

 int main()
         Timer s;
         pc.printf("Hello World - buff\n");
         int buffered_time = s.read_us();
         wait(0.1f); // give time for the buffer to empty
         printf("Hello World - poll\n");
         int polled_time = s.read_us();
         wait(0.1f); // give time for the buffer to empty
         pc.printf("printf buffered took %d us\n", buffered_time);
         pc.printf("printf polled took %d us\n", polled_time);

Revisions of BufferedSerial.cpp

Revision Date Message Actions
7:6fa214b41d73 2015-01-02 made updates to enable the ability to expand the internal buffer. Additionally, used the definition to set the size of the ring buffers in the constructor initializer list. Increased the default buffer size to 512. Additional clean ups (param cks) File  Diff  Annotate
6:8287e83943f0 2014-09-09 added #define to change the base Serial class to RawSerial if desired File  Diff  Annotate
4:2ba4d2e1f05d 2013-12-30 Disable TX IRQ when nothing is left in the buffer (FRDM support). Tested example program with KL46Z, KL25Z and LPC11U24. LPC1768 doesn't work. Need to investigate. File  Diff  Annotate
3:6b76fcf27545 2013-06-12 Updates to block only tx irq when fifo needs a kick. Updated comments and documentation File  Diff  Annotate
2:7e8a450a9101 2013-05-24 Override virtual member write. Better management of prime to avoid contentious writes under heavy traffic. updated puts to add \n per stdlib puts definition File  Diff  Annotate
1:57a11fb5d529 2013-05-23 Added prime (private member).Only want to pull from the buffer and write in one spot. prime stops irq's and call the member txIrq to put the oldest buffered byte in the transmitter. IRQ will pull the rest out once enabled again. File  Diff  Annotate
0:a977d0a3d81e 2013-05-23 TX and RX peripheral functions are IRQ driven. Most stdlib functions are overridden for transmit. Not so much for reading. getc is implemented but not the more formatted scanf. File  Diff  Annotate