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.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
io/MTSSerial.cpp
- Committer:
- jengbrecht
- Date:
- 2014-01-04
- Revision:
- 140:bf0c8288eb78
- Parent:
- 129:3aa470877c59
- Child:
- 141:571e0ef6c8dc
File content as of revision 140:bf0c8288eb78:
#include "MTSSerial.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);
//serial.attach(this, &MTSSerial::handleWrite, Serial::TxIrq);
}
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()
{
while (serial.readable()) {
char byte = serial.getc();
if(rxBuffer.write(byte) != 1) {
printf("[ERROR] Serial Rx Byte Dropped [%c][0x%02X]\r\n", byte, byte);
if(byte == 0xFF) {
serial.attach(NULL, Serial::RxIrq);
serial.attach(this, &MTSSerial::handleRead, Serial::RxIrq);
printf("[INFO] Reset the RxIrq.\n\r");
}
return;
}
}
}
// Currently uses Non-Irq based blocking write calls
void MTSSerial::handleWrite()
{
while(txBuffer.size() != 0) {
if (serial.writeable()) {
char byte;
if(txBuffer.read(byte) == 1) {
serial.putc(byte);
}
} else {
return;
}
}
}
uIP Socket Modem Shield (Outdated - see below)