From: Grant Edwards <grante@visi.com>
To: ecos-discuss@sources.redhat.com
Subject: [ECOS] semi-blocking serial read
Date: Wed, 15 Aug 2001 15:08:00 -0000 [thread overview]
Message-ID: <20010815171000.A6737@visi.com> (raw)
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
next reply other threads:[~2001-08-15 15:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-15 15:08 Grant Edwards [this message]
2001-08-16 3:30 ` David Airlie
2001-08-16 6:30 ` Jonathan Larmour
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20010815171000.A6737@visi.com \
--to=grante@visi.com \
--cc=ecos-discuss@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).