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.
Fork of MTS-Serial by
MTSSerial.cpp
- Committer:
- Mike Fiore
- Date:
- 2014-05-19
- Revision:
- 1:d34b566d6f47
- Child:
- 4:d348d001283b
File content as of revision 1:d34b566d6f47:
#include "MTSSerial.h" #include "MTSLog.h" using namespace mts; MTSSerial::MTSSerial(PinName TXD, PinName RXD, int txBufferSize, int rxBufferSize) : MTSBufferedIO(txBufferSize, rxBufferSize) , serial(TXD,RXD) { serial.attach(this, &MTSSerial::handleRead, Serial::RxIrq); } MTSSerial::~MTSSerial() { } void MTSSerial::baud(int baudrate) { serial.baud(baudrate); } void MTSSerial::format(int bits, SerialBase::Parity parity, int stop_bits) { serial.format(bits, parity, stop_bits); } void MTSSerial::handleRead() { char byte = serial.getc(); if(rxBuffer.write(byte) != 1) { logError("Serial Rx Byte Dropped [%c][0x%02X]", byte, byte); } } void MTSSerial::handleWrite() { while(txBuffer.size() != 0) { if (serial.writeable()) { char byte; if(txBuffer.read(byte) == 1) { serial.attach(NULL, Serial::RxIrq); serial.putc(byte); serial.attach(this, &MTSSerial::handleRead, Serial::RxIrq); } } else { return; } } }