sim_uart: fix printf error when use irq mode

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2022-12-16 23:36:00 +08:00 committed by Xiang Xiao
parent eb102a668f
commit 2dbfd8e798

View File

@ -41,10 +41,16 @@
#endif
#define TTY_RECVSEND(port) \
if (g_tty##port##_priv.fd > 0) \
if (g_##port##_priv.fd >= 0) \
{ \
uart_recvchars(&g_tty##port##_dev); \
uart_xmitchars(&g_tty##port##_dev); \
if (g_##port##_priv.rxint) \
{ \
uart_recvchars(&g_##port##_dev); \
} \
if (g_##port##_priv.txint) \
{ \
uart_xmitchars(&g_##port##_dev); \
} \
} \
/****************************************************************************
@ -59,7 +65,15 @@ struct tty_priv_s
/* The file descriptor. It is returned by open */
int fd;
int fd;
/* TX interrupt enable or not */
bool txint;
/* RX interrupt enable or not */
bool rxint;
};
/****************************************************************************
@ -130,10 +144,17 @@ static char g_tty3_txbuf[CONFIG_SIM_UART_BUFFER_SIZE];
#endif
#ifdef USE_DEVCONSOLE
static struct tty_priv_s g_console_priv =
{
.path = "console",
.fd = 0,
};
static struct uart_dev_s g_console_dev =
{
.isconsole = true,
.ops = &g_tty_ops,
.priv = &g_console_priv,
.xmit =
{
.size = CONFIG_SIM_UART_BUFFER_SIZE,
@ -344,12 +365,10 @@ static int tty_ioctl(struct file *filep, int cmd, unsigned long arg)
switch (cmd)
{
case TCGETS:
return host_uart_getcflag(dev->isconsole ? 0 : priv->fd,
&termiosp->c_cflag);
return host_uart_getcflag(priv->fd, &termiosp->c_cflag);
case TCSETS:
return host_uart_setcflag(dev->isconsole ? 0 : priv->fd,
termiosp->c_cflag);
return host_uart_setcflag(priv->fd, termiosp->c_cflag);
}
#endif
@ -371,7 +390,7 @@ static int tty_receive(struct uart_dev_s *dev, uint32_t *status)
struct tty_priv_s *priv = dev->priv;
*status = 0;
return host_uart_getc(dev->isconsole ? 0 : priv->fd);
return host_uart_getc(priv->fd);
}
/****************************************************************************
@ -384,6 +403,9 @@ static int tty_receive(struct uart_dev_s *dev, uint32_t *status)
static void tty_rxint(struct uart_dev_s *dev, bool enable)
{
struct tty_priv_s *priv = dev->priv;
priv->rxint = enable;
}
/****************************************************************************
@ -398,7 +420,7 @@ static bool tty_rxavailable(struct uart_dev_s *dev)
{
struct tty_priv_s *priv = dev->priv;
return host_uart_checkin(dev->isconsole ? 0 : priv->fd);
return host_uart_checkin(priv->fd);
}
/****************************************************************************
@ -448,10 +470,9 @@ static void tty_send(struct uart_dev_s *dev, int ch)
static void tty_txint(struct uart_dev_s *dev, bool enable)
{
if (enable)
{
uart_xmitchars(dev);
}
struct tty_priv_s *priv = dev->priv;
priv->txint = enable;
}
/****************************************************************************
@ -466,7 +487,7 @@ static bool tty_txready(struct uart_dev_s *dev)
{
struct tty_priv_s *priv = dev->priv;
return host_uart_checkout(dev->isconsole ? 0 : priv->fd);
return host_uart_checkout(dev->isconsole ? 1 : priv->fd);
}
/****************************************************************************
@ -527,24 +548,23 @@ void sim_uartinit(void)
void sim_uartloop(void)
{
#ifdef USE_DEVCONSOLE
uart_recvchars(&g_console_dev);
uart_xmitchars(&g_console_dev);
TTY_RECVSEND(console)
#endif
#ifdef CONFIG_SIM_UART0_NAME
TTY_RECVSEND(0)
TTY_RECVSEND(tty0)
#endif
#ifdef CONFIG_SIM_UART1_NAME
TTY_RECVSEND(1)
TTY_RECVSEND(tty1)
#endif
#ifdef CONFIG_SIM_UART2_NAME
TTY_RECVSEND(2)
TTY_RECVSEND(tty2)
#endif
#ifdef CONFIG_SIM_UART3_NAME
TTY_RECVSEND(3)
TTY_RECVSEND(tty3)
#endif
}