sim arch: Add non blocking read to devconsole driver
This commit is contained in:
parent
643f5782aa
commit
63c9f1a86e
@ -43,6 +43,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
@ -97,12 +98,13 @@ static ssize_t devconsole_read(struct file *filep, char *buffer, size_t len)
|
||||
* on the first read.
|
||||
*/
|
||||
|
||||
ch = simuart_getc();
|
||||
ch = simuart_getc(!(filep->f_oflags & O_NONBLOCK));
|
||||
if (ch < 0)
|
||||
{
|
||||
set_errno(EIO);
|
||||
/* errno is set in upper layer according to returned value */
|
||||
|
||||
sched_unlock();
|
||||
return ERROR;
|
||||
return ch;
|
||||
}
|
||||
|
||||
*buffer++ = ch;
|
||||
|
@ -262,7 +262,7 @@ void up_registerblockdevice(void);
|
||||
|
||||
void simuart_start(void);
|
||||
int simuart_putc(int ch);
|
||||
int simuart_getc(void);
|
||||
int simuart_getc(bool block);
|
||||
bool simuart_checkc(void);
|
||||
void simuart_terminate(void);
|
||||
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@ -268,7 +269,7 @@ int simuart_putc(int ch)
|
||||
* Name: simuart_getc
|
||||
****************************************************************************/
|
||||
|
||||
int simuart_getc(void)
|
||||
int simuart_getc(bool block)
|
||||
{
|
||||
int index;
|
||||
int ch;
|
||||
@ -282,6 +283,12 @@ int simuart_getc(void)
|
||||
{
|
||||
/* Wait for a byte to become available */
|
||||
|
||||
if (!block && (g_uarthead == g_uarttail))
|
||||
{
|
||||
sched_unlock();
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
while (g_uarthead == g_uarttail)
|
||||
{
|
||||
simuart_wait();
|
||||
|
Loading…
Reference in New Issue
Block a user