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:
- jengbrecht
- Date:
- 2013-12-19
- Revision:
- 46:b30547bf07d5
- Parent:
- 45:40745c2036cf
- Parent:
- 39:6e94520a3217
- Child:
- 67:1003b410f781
File content as of revision 46:b30547bf07d5:
#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);
clearToSend = true;
rts = new InterruptIn(RTS);
rts->rise(this, &MTSSerialFlowControl::stopSending); // active low -> stop sending
rts->fall(this, &MTSSerialFlowControl::startSending); // active low -> start sending
cts = new DigitalOut(CTS);
notifyStartSending();
highThreshold = rxBufSize * 0.85;
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::startSending()
{
clearToSend = true;
}
void MTSSerialFlowControl::stopSending()
{
clearToSend = false;
}
void MTSSerialFlowControl::notifyStartSending()
{
cts->write(0);
}
void MTSSerialFlowControl::notifyStopSending()
{
cts->write(1);
}
void MTSSerialFlowControl::handleRead()
{
if (rxBuffer->available() > highThreshold) {
notifyStopSending();
}
while (serial->readable()) {
rxBuffer->write(serial->getc());
}
}
void MTSSerialFlowControl::handleWrite()
{
if (clearToSend) {
while(txBuffer->available() != 0) {
if (serial->writeable()) {
char byte;
if(txBuffer->read(byte) == 1) {
serial->putc(byte);
}
} else {
wait(.05);
}
}
}
}
#endif /* MTSSERIALFLOWCONTROL */
uIP Socket Modem Shield (Outdated - see below)