* [ECOS] semi-blocking serial read
@ 2001-08-15 15:08 Grant Edwards
2001-08-16 3:30 ` David Airlie
0 siblings, 1 reply; 3+ messages in thread
From: Grant Edwards @ 2001-08-15 15:08 UTC (permalink / raw)
To: ecos-discuss
My serial.c driver code has diverged somewhat from the standard
serial.c. Most of the things I've done have either evolved in
parallel in the official one (like a non-blocking mode) or are
things that other people don't want.
One unique thing that mine does have that is both general and
(IMO) pretty useful is semi-blocking reads.
A semi-blocking read will block until _some_ amount of data is
available and return after transferring whatever is available.
This is primarily useful for UARTs with FIFOs such that receive
data comes in "chunks". A semi-blocking read waits for the
next "chunk". This allows you to process incoming data with
the lowest possible latency without doing a non-blocking read
in a busy-wait loop.
The change is pretty trivial. In serial_read() you do
something like this:
1 while (size < *len) {
2 if (cbuf->nb > 0) {
3 #ifdef CYGPKG_IO_SERIAL_FLOW_CONTROL
4 if ( (cbuf->nb <= cbuf->low_water) &&
5 (chan->flow_desc.flags & CYG_SERIAL_FLOW_IN_THROTTLED) )
6 restart_rx( chan, false );
7 #endif
8 *buf++ = cbuf->data[cbuf->get];
9 if (++cbuf->get == cbuf->len) cbuf->get = 0;
10 cbuf->nb--;
11 size++;
12 } else {
13 #ifdef CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING
--- 14 if (!cbuf->blocking) {
+++ 14 if (cbuf->nonblocking || (cbuf->semiblocking && size))) {
15 *len = size; // characters actually read
16 res = -EAGAIN;
17 break;
18 }
19 #endif // CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING
The cbuf struct needs to change a little to accomodate the two
flags "nonblocking" and "semiblocking", but I think you see
what I mean.
I don't use serial.c and probably won't get around to
submitting a patch for some time, but I thought I'd toss the
idea out in case anybody else could use something like it.
--
Grant Edwards
grante@visi.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [ECOS] semi-blocking serial read
2001-08-15 15:08 [ECOS] semi-blocking serial read Grant Edwards
@ 2001-08-16 3:30 ` David Airlie
2001-08-16 6:30 ` Jonathan Larmour
0 siblings, 1 reply; 3+ messages in thread
From: David Airlie @ 2001-08-16 3:30 UTC (permalink / raw)
To: Grant Edwards; +Cc: ecos-discuss
I thought about doing this before.. and never got around to it .. god this
would save me a lot of extra crap I've added to my code .. loads of tslp
and stuff waiting for data...
I might go code up a patch for this in the next couple of weeks, when I
get the chance to sit down with my eCos devel system.. that is unless
someone beats me to it ...
Dave.
On Wed, 15 Aug 2001, Grant Edwards wrote:
>
> My serial.c driver code has diverged somewhat from the standard
> serial.c. Most of the things I've done have either evolved in
> parallel in the official one (like a non-blocking mode) or are
> things that other people don't want.
>
> One unique thing that mine does have that is both general and
> (IMO) pretty useful is semi-blocking reads.
>
> A semi-blocking read will block until _some_ amount of data is
> available and return after transferring whatever is available.
>
> This is primarily useful for UARTs with FIFOs such that receive
> data comes in "chunks". A semi-blocking read waits for the
> next "chunk". This allows you to process incoming data with
> the lowest possible latency without doing a non-blocking read
> in a busy-wait loop.
>
> The change is pretty trivial. In serial_read() you do
> something like this:
>
> 1 while (size < *len) {
> 2 if (cbuf->nb > 0) {
> 3 #ifdef CYGPKG_IO_SERIAL_FLOW_CONTROL
> 4 if ( (cbuf->nb <= cbuf->low_water) &&
> 5 (chan->flow_desc.flags & CYG_SERIAL_FLOW_IN_THROTTLED) )
> 6 restart_rx( chan, false );
> 7 #endif
> 8 *buf++ = cbuf->data[cbuf->get];
> 9 if (++cbuf->get == cbuf->len) cbuf->get = 0;
> 10 cbuf->nb--;
> 11 size++;
> 12 } else {
> 13 #ifdef CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING
> --- 14 if (!cbuf->blocking) {
> +++ 14 if (cbuf->nonblocking || (cbuf->semiblocking && size))) {
> 15 *len = size; // characters actually read
> 16 res = -EAGAIN;
> 17 break;
> 18 }
> 19 #endif // CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING
>
>
> The cbuf struct needs to change a little to accomodate the two
> flags "nonblocking" and "semiblocking", but I think you see
> what I mean.
>
> I don't use serial.c and probably won't get around to
> submitting a patch for some time, but I thought I'd toss the
> idea out in case anybody else could use something like it.
>
>
--
David Airlie, Software Engineer, Parthus Technologies plc.,
Mary Rosse Centre, National Tech Park, Limerick, Ireland.
t: +353-61-508116 / f: +353-61-508101 / David.Airlie@parthus.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [ECOS] semi-blocking serial read
2001-08-16 3:30 ` David Airlie
@ 2001-08-16 6:30 ` Jonathan Larmour
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Larmour @ 2001-08-16 6:30 UTC (permalink / raw)
To: David Airlie; +Cc: Grant Edwards, ecos-discuss
David Airlie wrote:
>
> I thought about doing this before.. and never got around to it .. god this
> would save me a lot of extra crap I've added to my code .. loads of tslp
> and stuff waiting for data...
>
> I might go code up a patch for this in the next couple of weeks, when I
> get the chance to sit down with my eCos devel system.. that is unless
> someone beats me to it ...
If you do, it would be nice if it was overall controlled by a separate CDL
option, like the non-blocking stuff. After all, it's only useful on systems
that do receive stuff in chunks.
Jifl
--
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-08-16 6:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-15 15:08 [ECOS] semi-blocking serial read Grant Edwards
2001-08-16 3:30 ` David Airlie
2001-08-16 6:30 ` Jonathan Larmour
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).