sim/uart: check if txbuffer is not full before uart write
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
parent
4fa163ade7
commit
eb102a668f
@ -199,10 +199,10 @@ int host_uart_setcflag(int fd, unsigned int cflag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: host_uart_checkc
|
* Name: host_uart_checkin
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
bool host_uart_checkc(int fd)
|
bool host_uart_checkin(int fd)
|
||||||
{
|
{
|
||||||
struct pollfd pfd;
|
struct pollfd pfd;
|
||||||
|
|
||||||
@ -210,3 +210,16 @@ bool host_uart_checkc(int fd)
|
|||||||
pfd.events = POLLIN;
|
pfd.events = POLLIN;
|
||||||
return poll(&pfd, 1, 0) == 1;
|
return poll(&pfd, 1, 0) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: host_uart_checkout
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
bool host_uart_checkout(int fd)
|
||||||
|
{
|
||||||
|
struct pollfd pfd;
|
||||||
|
|
||||||
|
pfd.fd = fd;
|
||||||
|
pfd.events = POLLOUT;
|
||||||
|
return poll(&pfd, 1, 0) == 1;
|
||||||
|
}
|
||||||
|
@ -195,7 +195,8 @@ int host_uart_open(const char *pathname);
|
|||||||
void host_uart_close(int fd);
|
void host_uart_close(int fd);
|
||||||
int host_uart_putc(int fd, int ch);
|
int host_uart_putc(int fd, int ch);
|
||||||
int host_uart_getc(int fd);
|
int host_uart_getc(int fd);
|
||||||
bool host_uart_checkc(int fd);
|
bool host_uart_checkin(int fd);
|
||||||
|
bool host_uart_checkout(int fd);
|
||||||
int host_uart_setcflag(int fd, unsigned int cflag);
|
int host_uart_setcflag(int fd, unsigned int cflag);
|
||||||
int host_uart_getcflag(int fd, unsigned int *cflag);
|
int host_uart_getcflag(int fd, unsigned int *cflag);
|
||||||
|
|
||||||
|
@ -40,6 +40,13 @@
|
|||||||
#define CONFIG_SIM_UART_BUFFER_SIZE 256
|
#define CONFIG_SIM_UART_BUFFER_SIZE 256
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define TTY_RECVSEND(port) \
|
||||||
|
if (g_tty##port##_priv.fd > 0) \
|
||||||
|
{ \
|
||||||
|
uart_recvchars(&g_tty##port##_dev); \
|
||||||
|
uart_xmitchars(&g_tty##port##_dev); \
|
||||||
|
} \
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Types
|
* Private Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -391,7 +398,7 @@ static bool tty_rxavailable(struct uart_dev_s *dev)
|
|||||||
{
|
{
|
||||||
struct tty_priv_s *priv = dev->priv;
|
struct tty_priv_s *priv = dev->priv;
|
||||||
|
|
||||||
return host_uart_checkc(dev->isconsole ? 0 : priv->fd);
|
return host_uart_checkin(dev->isconsole ? 0 : priv->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -457,7 +464,9 @@ static void tty_txint(struct uart_dev_s *dev, bool enable)
|
|||||||
|
|
||||||
static bool tty_txready(struct uart_dev_s *dev)
|
static bool tty_txready(struct uart_dev_s *dev)
|
||||||
{
|
{
|
||||||
return true;
|
struct tty_priv_s *priv = dev->priv;
|
||||||
|
|
||||||
|
return host_uart_checkout(dev->isconsole ? 0 : priv->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -518,38 +527,24 @@ void sim_uartinit(void)
|
|||||||
void sim_uartloop(void)
|
void sim_uartloop(void)
|
||||||
{
|
{
|
||||||
#ifdef USE_DEVCONSOLE
|
#ifdef USE_DEVCONSOLE
|
||||||
if (host_uart_checkc(0))
|
uart_recvchars(&g_console_dev);
|
||||||
{
|
uart_xmitchars(&g_console_dev);
|
||||||
uart_recvchars(&g_console_dev);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_SIM_UART0_NAME
|
#ifdef CONFIG_SIM_UART0_NAME
|
||||||
if (g_tty0_priv.fd > 0 && host_uart_checkc(g_tty0_priv.fd))
|
TTY_RECVSEND(0)
|
||||||
{
|
|
||||||
uart_recvchars(&g_tty0_dev);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_SIM_UART1_NAME
|
#ifdef CONFIG_SIM_UART1_NAME
|
||||||
if (g_tty1_priv.fd > 0 && host_uart_checkc(g_tty1_priv.fd))
|
TTY_RECVSEND(1)
|
||||||
{
|
|
||||||
uart_recvchars(&g_tty1_dev);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_SIM_UART2_NAME
|
#ifdef CONFIG_SIM_UART2_NAME
|
||||||
if (g_tty2_priv.fd > 0 && host_uart_checkc(g_tty2_priv.fd))
|
TTY_RECVSEND(2)
|
||||||
{
|
|
||||||
uart_recvchars(&g_tty2_dev);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_SIM_UART3_NAME
|
#ifdef CONFIG_SIM_UART3_NAME
|
||||||
if (g_tty3_priv.fd > 0 && host_uart_checkc(g_tty3_priv.fd))
|
TTY_RECVSEND(3)
|
||||||
{
|
|
||||||
uart_recvchars(&g_tty3_dev);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,10 +126,10 @@ int host_uart_setcflag(int fd, unsigned int cflag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: host_uart_checkc
|
* Name: host_uart_checkin
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
bool host_uart_checkc(int fd)
|
bool host_uart_checkin(int fd)
|
||||||
{
|
{
|
||||||
DWORD size;
|
DWORD size;
|
||||||
|
|
||||||
@ -140,3 +140,12 @@ bool host_uart_checkc(int fd)
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: host_uart_checkout
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
bool host_uart_checkout(int fd)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user