[PATCH] serial: smh: Fake tstc

Tom Rini trini at konsulko.com
Tue Jun 7 18:47:13 CEST 2022


On Tue, May 17, 2022 at 01:55:07PM -0400, Sean Anderson wrote:

> ARM semihosting provides no provisions for determining if there is
> pending input. The only way to determine if there is console input is to
> do a read (and block until the user types something). For this reason,
> we always return true for tstc (since you will always get input if you
> try). However, this behavior can cause problems for code which expects
> tstc to eventually be empty. In query_console_serial, there is the
> following construct:
> 
> 	/* empty input buffer */
> 	while (tstc())
> 		getchar();
> 
> with the current implementation, this effectively turns into an infinite
> loop. To avoid this, fake tstc by returning false half of the time. This
> is generally OK because the other common construct looks like
> 
> 	do {
> 		if (tstc())
> 			process(getchar());
> 	} while (!timeout());
> 
> so it's fine if we only read a new character every other loop. This will
> break things like CYGACC_COMM_IF_GETC_TIMEOUT, but that could be
> reworked to test on the timeout instead of calling tstc again (and
> ymodem over semihosted serial is not that useful in the first place).
> 
> Signed-off-by: Sean Anderson <sean.anderson at seco.com>

Applied to u-boot/next, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20220607/5ef946dc/attachment.sig>


More information about the U-Boot mailing list