From 041721cd22dc2614037a944078974aa49083795b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 13 Dec 2014 13:04:02 -0600 Subject: [PATCH] SIM: Fix simulated console... it needs to return immediately when even one byte is read --- arch/sim/src/up_devconsole.c | 22 ++++++++++++++++++++-- arch/sim/src/up_internal.h | 13 ++++++++++--- arch/sim/src/up_simuart.c | 12 +++++++++++- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/arch/sim/src/up_devconsole.c b/arch/sim/src/up_devconsole.c index a817493071..5549db4832 100644 --- a/arch/sim/src/up_devconsole.c +++ b/arch/sim/src/up_devconsole.c @@ -86,23 +86,41 @@ static const struct file_operations devconsole_fops = static ssize_t devconsole_read(struct file *filep, char *buffer, size_t len) { size_t remaining = len; + ssize_t nread; int ch; /* Loop until all requested bytes have been read. No error checking */ - for (remaining = len; remaining > 0; remaining--) + sched_lock(); + for (remaining = len, nread = 0; remaining > 0; remaining--) { + /* Read the next character from the console, we should only wait + * on the first read. + */ + ch = simuart_getc(); if (ch < 0) { set_errno(EIO); + sched_unlock(); return ERROR; } *buffer++ = ch; + nread++; + + /* We have at least one character. Return now if no further + * characters are available without waiting. + */ + + if (!simuart_checkc()) + { + break; + } } - return len; + sched_unlock(); + return nread; } /**************************************************************************** diff --git a/arch/sim/src/up_internal.h b/arch/sim/src/up_internal.h index ea20934fcc..c2fac55d25 100644 --- a/arch/sim/src/up_internal.h +++ b/arch/sim/src/up_internal.h @@ -42,9 +42,14 @@ #include #include -#include -#include -#include + +#ifndef __ASSEMBLY__ +# include +# include + +# include +# include +#endif /************************************************************************** * Pre-processor Definitions @@ -213,6 +218,7 @@ void up_registerblockdevice(void); void simuart_start(void); int simuart_putc(int ch); int simuart_getc(void); +bool simuart_checkc(void); /* up_uartwait.c **********************************************************/ @@ -288,6 +294,7 @@ void netdriver_loop(void); #endif #ifdef CONFIG_SIM_SPIFLASH +struct spi_dev_s; struct spi_dev_s *up_spiflashinitialize(void); #endif diff --git a/arch/sim/src/up_simuart.c b/arch/sim/src/up_simuart.c index ba237fb7e7..7f940a9a94 100644 --- a/arch/sim/src/up_simuart.c +++ b/arch/sim/src/up_simuart.c @@ -37,6 +37,7 @@ * Included Files ****************************************************************************/ +#include #include #include #include @@ -274,7 +275,6 @@ int simuart_getc(void) simuart_wait(); } - /* The UART buffer is non-empty... Take the next byte from the tail * of the buffer. */ @@ -294,3 +294,13 @@ int simuart_getc(void) return ch; } } + +/**************************************************************************** + * Name: simuart_getc + ****************************************************************************/ + +bool simuart_checkc(void) +{ + return g_uarthead != g_uarttail; +} +