[U-Boot] [PATCH v2] NS16550: buffer reads

Wolfgang Denk wd at denx.de
Mon Oct 24 22:00:12 CEST 2011


Dear Graeme Russ,

In message <4EA5BBEF.1050706 at gmail.com> you wrote:
> 
> > Why would any of the transfer commands actually turn off flow control?
> 
> getc() sends an XOFF

Oops?  You got something wrong, I think.

Receiving a '\n' would cause sending XOFF, and getc() would, if state
is XOFF, send an XON.

> consider the follow (admittedly canned) example:
> 
> loadb ; sleep 20
> 
> An XOFF will be sent when the user hits 'enter' but loadb will send an XON
> when it calls getc(). Now after the transfer is complete, there will have
> been no XOFF before the sleep command is run so if the user enters anything
> during the sleep command, those characters can be lost

Agreed.  You can relax situation if functions that use the serial line
for their own purposes (like running some serial transfer protocol)
would have some initialization part where they remember the line state
(and, if it was XOFF, send XON), plus a termination part where they
restore the old line state (i. e. if it was XOFF initially, send XOFF
again).


But note that such software flow control is again just a little
improvement, it is definitely not a guaranteed way to prevent any
character losses.  Assume the situation where the user copy & pastes
some multi-line command sequence. We will receive a character sequence
like this:

	a b c d e '\n' f g h i j k ...

We will send XOFF after receiving the '\n' - guess when XOFF will be
loaded into our transmitter? When the last bit and stop bits have been
sent? When the receiver on the other size will actually read this from
his FIFO? And How long it then will take until his Tx fifo empties,
and he stops sending more characters?

Assume we have a simple device with a small Rx FIFO - say, 8 bytes
only. Guess what the chances are that we will overrun this FIFO (and
then lose characters) before the other side stops sending?

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
As far as the laws of mathematics refer  to  reality,  they  are  not
certain;  and  as  far  as  they  are  certain,  they do not refer to
reality.                                           -- Albert Einstein


More information about the U-Boot mailing list