Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
serialBuffer.cpp@6:ca024bcee813, 2017-03-08 (annotated)
- Committer:
- UHSLMarcus
- Date:
- Wed Mar 08 11:11:20 2017 +0000
- Revision:
- 6:ca024bcee813
- Parent:
- 1:985b6f1c7347
- Child:
- 8:93d1469f3f6d
updated to use simpler linear array lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
UHSLMarcus | 0:dd6d74f39384 | 1 | #include "serialBuffer.h" |
UHSLMarcus | 0:dd6d74f39384 | 2 | |
UHSLMarcus | 1:985b6f1c7347 | 3 | utils::SerialBuffer::SerialBuffer(PinName tx, PinName rx) : RawSerial(tx, rx), rx_buffer(255) { |
UHSLMarcus | 6:ca024bcee813 | 4 | RawSerial::attach(callback(this, &utils::SerialBuffer::rx_interrupt), Serial::RxIrq); |
UHSLMarcus | 0:dd6d74f39384 | 5 | return; |
UHSLMarcus | 0:dd6d74f39384 | 6 | } |
UHSLMarcus | 0:dd6d74f39384 | 7 | |
UHSLMarcus | 1:985b6f1c7347 | 8 | utils::SerialBuffer::~SerialBuffer() { |
UHSLMarcus | 0:dd6d74f39384 | 9 | RawSerial::attach(NULL, RawSerial::RxIrq); |
UHSLMarcus | 0:dd6d74f39384 | 10 | return; |
UHSLMarcus | 0:dd6d74f39384 | 11 | } |
UHSLMarcus | 0:dd6d74f39384 | 12 | |
UHSLMarcus | 1:985b6f1c7347 | 13 | int utils::SerialBuffer::readable() { |
UHSLMarcus | 6:ca024bcee813 | 14 | return rx_buffer.count() > 0; |
UHSLMarcus | 0:dd6d74f39384 | 15 | } |
UHSLMarcus | 1:985b6f1c7347 | 16 | |
UHSLMarcus | 1:985b6f1c7347 | 17 | char utils::SerialBuffer::getc() { |
UHSLMarcus | 0:dd6d74f39384 | 18 | RawSerial::attach(NULL, RawSerial::RxIrq); |
UHSLMarcus | 0:dd6d74f39384 | 19 | |
UHSLMarcus | 6:ca024bcee813 | 20 | char nextChar = rx_buffer.pop(); |
UHSLMarcus | 0:dd6d74f39384 | 21 | |
UHSLMarcus | 6:ca024bcee813 | 22 | RawSerial::attach(callback(this, &utils::SerialBuffer::rx_interrupt), Serial::RxIrq); |
UHSLMarcus | 0:dd6d74f39384 | 23 | |
UHSLMarcus | 6:ca024bcee813 | 24 | return nextChar; |
UHSLMarcus | 0:dd6d74f39384 | 25 | } |
UHSLMarcus | 0:dd6d74f39384 | 26 | |
UHSLMarcus | 1:985b6f1c7347 | 27 | void utils::SerialBuffer::rx_interrupt(void) { |
UHSLMarcus | 6:ca024bcee813 | 28 | if(serial_readable(&_serial) && !rx_buffer.full()) { |
UHSLMarcus | 6:ca024bcee813 | 29 | rx_buffer.push(serial_getc(&_serial)); |
UHSLMarcus | 0:dd6d74f39384 | 30 | } |
UHSLMarcus | 0:dd6d74f39384 | 31 | |
UHSLMarcus | 0:dd6d74f39384 | 32 | return; |
UHSLMarcus | 6:ca024bcee813 | 33 | } |