Skip to content

Commit f6ae835

Browse files
fyin1wenlingz
authored andcommitted
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 <fengwei.yin@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
1 parent 88a7d8b commit f6ae835

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

devicemodel/hw/uart_core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ ttyopen(struct ttyfd *tf)
134134
tf->tio_new = tf->tio_orig;
135135
cfmakeraw(&tf->tio_new);
136136
tf->tio_new.c_cflag |= CLOCAL;
137+
tcflush(tf->fd_in, TCIOFLUSH);
137138
tcsetattr(tf->fd_in, TCSANOW, &tf->tio_new);
138139

139140
if (tf->fd_in == STDIN_FILENO) {
@@ -396,9 +397,10 @@ uart_drain(int fd, enum ev_type ev, void *arg)
396397
if ((uart->mcr & MCR_LOOPBACK) != 0) {
397398
(void) ttyread(&uart->tty);
398399
} else {
399-
while ((ch = ttyread(&uart->tty)) != -1)
400+
/* only read tty when rxfifo available to make sure no data lost */
401+
while (rxfifo_available(uart) && (ch = ttyread(&uart->tty)) != -1) {
400402
rxfifo_putchar(uart, ch);
401-
403+
}
402404
uart_toggle_intr(uart);
403405
}
404406

0 commit comments

Comments
 (0)