From 6881fa3712de15d4b938dcb330bae7744a6db4bf Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Fri, 30 Aug 2019 18:01:58 -0700 Subject: g: fix UART TX done logic TX is done when both TX_IDLE and TX_EMPTY conditions are true. Fixing the check makes unnecessary the code which waited for another character time before proceeding when flushing the UART TX FIFO. BRANCH=cr50, cr50-mp BUG=b:140305442 TEST=added code to print a really long string before reset in the 'reboot' command, observed that the entire string is reliably printed before the reset. Change-Id: I0882d96ba9ca5412deb704ccdbc43e8cebeeeab5 Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1779587 Reviewed-by: Marius Schilder Reviewed-by: Andrey Pronin --- chip/g/uartn.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/chip/g/uartn.c b/chip/g/uartn.c index ce90b7b290..3f4b75b7e0 100644 --- a/chip/g/uartn.c +++ b/chip/g/uartn.c @@ -62,28 +62,16 @@ void uartn_tx_stop(int uart) int uartn_tx_in_progress(int uart) { /* Transmit is in progress unless the TX FIFO is empty and idle. */ - return !(GR_UART_STATE(uart) & (GC_UART_STATE_TXIDLE_MASK | - GC_UART_STATE_TXEMPTY_MASK)); + return (GR_UART_STATE(uart) & (GC_UART_STATE_TXIDLE_MASK | + GC_UART_STATE_TXEMPTY_MASK)) != + (GC_UART_STATE_TXIDLE_MASK | GC_UART_STATE_TXEMPTY_MASK); } void uartn_tx_flush(int uart) { - timestamp_t ts; - int i; - /* Wait until TX FIFO is idle. */ while (uartn_tx_in_progress(uart)) ; - /* - * Even when uartn_tx_in_progress() returns false, the chip seems to - * be still trasmitting, resetting at this point results in an eaten - * last symbol. Let's just wait some time (required to transmit 10 - * bits at 115200 baud). - */ - ts = get_time(); /* Start time. */ - for (i = 0; i < 1000; i++) /* Limit it in case timer is not running. */ - if ((get_time().val - ts.val) > ((1000000 * 10) / 115200)) - return; } int uartn_tx_ready(int uart) -- cgit v1.2.1