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/MTSSerialFlowControl.cpp
- Committer:
- sgodinez
- Date:
- 2013-12-26
- Revision:
- 78:ef3ee53cf5df
- Parent:
- 77:d7b14688a704
- Child:
- 81:45e1359a5c69
- Child:
- 84:77c5ab16534d
File content as of revision 78:ef3ee53cf5df:
#ifndef MTSSERIALFLOWCONTROL_CPP
#define MTSSERIALFLOWCONTROL_CPP
#include "MTSSerialFlowControl.h"
using namespace mts;
MTSSerialFlowControl::MTSSerialFlowControl(PinName TXD, PinName RXD, PinName RTS, PinName CTS, int txBufSize, int rxBufSize, char* name) : MTSBufferedIO(txBufSize, rxBufSize), if_name(name)
{
serial = new Serial(TXD, RXD);
serial->attach(this, &MTSSerialFlowControl::handleRead, Serial::RxIrq);
//serial->attach(this, &MTSSerialFlowControl::handleWrite, Serial::TxIrq);
rts = new DigitalOut(RTS);
cts = new DigitalIn(CTS);
notifyStartSending();
//highThreshold = MAX(rxBufSize - 10, rxBufSize * 0.85);
highThreshold = 10;
lowThreshold = rxBufSize * 0.3;
rxBuffer->attach(this, &MTSSerialFlowControl::notifyStartSending, lowThreshold, Vars::LESS);
}
MTSSerialFlowControl::~MTSSerialFlowControl()
{
delete rts;
delete cts;
delete serial;
}
void MTSSerialFlowControl::baud(int baudrate)
{
serial->baud(baudrate);
}
void MTSSerialFlowControl::format(int bits, SerialBase::Parity parity, int stop_bits)
{
serial->format(bits, parity, stop_bits);
}
void MTSSerialFlowControl::notifyStartSending()
{
rts->write(0);
//printf("RTS: START SENDING US BYTES - RX[%d]\r\n", rxBuffer->size());
}
void MTSSerialFlowControl::notifyStopSending()
{
rts->write(1);
//printf("RTS: STOP SENDING US BYTES - RX[%d]\r\n", rxBuffer->size());
}
void MTSSerialFlowControl::handleRead()
{
while (serial->readable()) {
rxBuffer->write(serial->getc());
if (rxBuffer->size() > highThreshold) {
notifyStopSending();
}
}
}
void MTSSerialFlowControl::handleWrite()
{
while(txBuffer->size() != 0) {
if (serial->writeable() && cts->read() == 0) {
char byte;
if(txBuffer->read(byte) == 1) {
serial->putc(byte);
}
} else {
return;
}
}
}
#endif /* MTSSERIALFLOWCONTROL */
uIP Socket Modem Shield (Outdated - see below)