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 C027_Support by
SerialPipe.cpp
- Committer:
- mazgch
- Date:
- 2014-03-14
- Revision:
- 18:e5697801df29
- Parent:
- 17:296d94a006b4
- Child:
- 19:2b5d097ca15d
File content as of revision 18:e5697801df29:
#pragma once
#include "SerialPipe.h"
SerialPipe::SerialPipe(PinName tx, PinName rx, int rxSize, int txSize)
: _SerialPipeBase(tx,rx), _pipeRx(rxSize), _pipeTx(txSize)
{
attach(this, &SerialPipe::rxIrqBuf, RxIrq);
attach(this, &SerialPipe::txIrqBuf, TxIrq);
}
SerialPipe::SerialPipe(PinName tx, PinName rx, PinName rts, PinName cts,
int rxSize, int txSize)
: _SerialPipeBase(tx,rx), _pipeRx(rxSize), _pipeTx(txSize)
{
attach(this, &SerialPipe::rxIrqBuf, RxIrq);
attach(this, &SerialPipe::txIrqBuf, TxIrq);
set_flow_control(RTSCTS, rts, cts);
}
SerialPipe::~SerialPipe(void)
{
attach(NULL, RxIrq);
attach(NULL, TxIrq);
}
// tx channel
int SerialPipe::writeable(void)
{
return _pipeTx.free();
}
int SerialPipe::putc(int c)
{
c = _pipeTx.putc(c);
txStart();
return c;
}
int SerialPipe::put(const void* buffer, int length, bool blocking)
{
int count = length;
const char* ptr = (const char*)buffer;
if (count)
{
do
{
int written = _pipeTx.put(ptr, count, false);
ptr += written;
count -= written;
txStart();
}
while (count && blocking);
}
return (length - count);
}
void SerialPipe::txIrqBuf(void)
{
while (_SerialPipeBase::writeable() && _pipeTx.readable())
{
char c = _pipeTx.getc();
_SerialPipeBase::_base_putc(c);
}
}
void SerialPipe::txStart(void)
{
__disable_irq();
txIrqBuf();
__enable_irq();
}
// rx channel
int SerialPipe::readable(void)
{
return _pipeRx.readable();
}
int SerialPipe::getc(void)
{
if (!_pipeRx.readable())
return EOF;
return _pipeRx.getc();
}
int SerialPipe::get(void* buffer, int length, bool blocking)
{
return _pipeRx.get((char*)buffer,length,blocking);
}
void SerialPipe::rxIrqBuf(void)
{
while (_SerialPipeBase::readable())
{
char c = _SerialPipeBase::_base_getc();
if (_pipeRx.writeable())
_pipeRx.putc(c);
else
/* overflow */;
}
}
