From f6ae835137cbdcf87579e6ee8b4fe910a3f03c36 Mon Sep 17 00:00:00 2001 From: Yin Fengwei Date: Thu, 20 Dec 2018 17:41:59 +0800 Subject: [PATCH] dm: flush the input/output during tty open. Discard the input/output data when open tty file. To avoid the mevent callback is triggered immediately when the fd is added to epoll. Also update the uart_drain only read the data from tty file when fifo has available space. Tracked-On: #2159 Signed-off-by: Yin Fengwei Acked-by: Anthony Xu --- devicemodel/hw/uart_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/devicemodel/hw/uart_core.c b/devicemodel/hw/uart_core.c index 7f96f44ff..4ae02b151 100644 --- a/devicemodel/hw/uart_core.c +++ b/devicemodel/hw/uart_core.c @@ -134,6 +134,7 @@ ttyopen(struct ttyfd *tf) tf->tio_new = tf->tio_orig; cfmakeraw(&tf->tio_new); tf->tio_new.c_cflag |= CLOCAL; + tcflush(tf->fd_in, TCIOFLUSH); tcsetattr(tf->fd_in, TCSANOW, &tf->tio_new); if (tf->fd_in == STDIN_FILENO) { @@ -396,9 +397,10 @@ uart_drain(int fd, enum ev_type ev, void *arg) if ((uart->mcr & MCR_LOOPBACK) != 0) { (void) ttyread(&uart->tty); } else { - while ((ch = ttyread(&uart->tty)) != -1) + /* only read tty when rxfifo available to make sure no data lost */ + while (rxfifo_available(uart) && (ch = ttyread(&uart->tty)) != -1) { rxfifo_putchar(uart, ch); - + } uart_toggle_intr(uart); }