mirror of
https://github.com/apache/nuttx.git
synced 2026-08-08 14:07:17 +00:00
SIM: Fix simulated console... it needs to return immediately when even one byte is read
This commit is contained in:
parent
a574a3cc8a
commit
cf1caa48ce
3 changed files with 41 additions and 6 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
|||
|
|
@ -42,9 +42,14 @@
|
|||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
#include <sys/types.h>
|
||||
#include <nuttx/irq.h>
|
||||
#include <arch/irq.h>
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
# include <sys/types.h>
|
||||
# include <stdbool.h>
|
||||
|
||||
# include <nuttx/irq.h>
|
||||
# include <arch/irq.h>
|
||||
#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
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <pthread.h>
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue