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: 02_DPPU_JUANDA_120 02_DPPU_JUANDA_120_Latest_copy 02_DPPU_JUANDA_120_Latest
Diff: SerialPipe.cpp
- Revision:
- 13:e2446fcdc246
- Parent:
- 12:684b31d5482b
- Child:
- 14:69c3e57ef0f5
--- a/SerialPipe.cpp Fri Nov 15 13:33:39 2013 +0000
+++ b/SerialPipe.cpp Tue Nov 19 08:34:51 2013 +0000
@@ -16,31 +16,53 @@
}
// tx channel
-int SerialPipe::put(const char* b, int n, bool t)
+int SerialPipe::writeable(void)
+{
+ return _pipeTx.free();
+}
+
+int SerialPipe::putc(int c)
+{
+ return _putc(c);
+}
+
+int SerialPipe::put(const void* buffer, int length, bool blocking)
{
- int c = n;
- while (c && t)
+ int count = length;
+ const char* ptr = (const char*)buffer;
+ while (count && blocking)
{
- int i = _pipeTx.put(b, c, false);
- b += i;
- c -= i;
- // give a chance to start tx
- __disable_irq();
- txIrqBuf();
- __enable_irq();
+ int written = _pipeTx.put(ptr, count, false);
+ ptr += written;
+ count -= written;
+ txStart();
}
- return (n - c);
+ return (length - count);
+}
+
+int SerialPipe::_putc(int c)
+{
+ c = _pipeTx.putc(c);
+ txStart();
+ return c;
}
void SerialPipe::txIrqBuf(void)
{
- while (serial_writable(&_serial) && _pipeTx.readable())
+ while (Serial::writeable() && _pipeTx.readable())
{
- char ch = _pipeTx.getc();
- serial_putc(&_serial, ch);
+ char c = _pipeTx.getc();
+ Serial::_putc(c);
}
}
+void SerialPipe::txStart(void)
+{
+ __disable_irq();
+ txIrqBuf();
+ __enable_irq();
+}
+
// rx channel
int SerialPipe::readable(void)
{
@@ -49,21 +71,26 @@
int SerialPipe::getc(void)
{
+ return _getc();
+}
+
+int SerialPipe::get(void* buffer, int length, bool blocking)
+{
+ return _pipeRx.get((char*)buffer,length,blocking);
+}
+
+int SerialPipe::_getc(void)
+{
return _pipeRx.getc();
}
-int SerialPipe::get(char* b, int s, bool t)
-{
- return _pipeRx.get(b,s,t);
-}
-
void SerialPipe::rxIrqBuf(void)
{
- while (serial_readable(&_serial))
+ while (Serial::readable())
{
- char ch = serial_getc(&_serial);
+ char c = Serial::_getc();
if (_pipeRx.writeable())
- _pipeRx.putc(ch);
+ _pipeRx.putc(c);
else
/* overflow */;
}
@@ -75,31 +102,31 @@
: SerialPipe(tx,rx,rxSize,txSize,name)
{}
-int SerialPipeEx::getLine(char* b, int s)
+int SerialPipeEx::getLine(char* buffer, int length)
{
int o = 0;
int i = 0;
int l = _pipeRx.start();
- while ((i < l) && (o < s))
+ while ((i < l) && (o < length))
{
int t = _pipeRx.next();
i ++;
if (t == '\r') // terminate commands with carriage return
{
_pipeRx.done();
- if (s > o)
- b[o] = '\0';
+ if (length > o)
+ buffer[o] = '\0';
return o; // if enter send the zero char
}
else if (t == '\n') // skip/filter new line
/* skip */;
else if (t != '\b') // normal char (no backspace)
- b[o++] = t;
+ buffer[o++] = t;
else if (o > 0) // backspace
o --; // remove it
}
o = 0;
- if (s > 0)
- b[0] = '\0';
+ if (length > 0)
+ buffer[0] = '\0';
return WAIT;
}