Skip to content

Commit

Permalink
tlsr82/serial: clear uart tx index when uart_reset called.
Browse files Browse the repository at this point in the history
Otherwise, after the rx error occur, the tx output will be
out of sequence, for example:
normal log:
[   30.163000] 12345678abcdefgh
[   30.666000] 12345678abcdefgh
[   31.169000] 12345678abcdefgh
[   31.672000] 12345678abcdefgh
[   32.175000] 12345678abcdefgh
[   32.678000] 12345678abcdefgh
[   33.181000] 12345678abcdefgh

error log:
he 7 .20]0003 127456c8abgdefch
gde [6.707002] 16345b78afcde
fcde
fghe10010] 5234a678ebcd
 77 713 00]41238567dabchefgd
che 7 .21]0003 127456c8abgdefch
gde [8.709002] 16345b78afcde
fcde

Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
  • Loading branch information
CV-Bowen authored and xiaoxiang781216 committed Sep 19, 2022
1 parent f286012 commit 282c410
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions arch/arm/src/tlsr82/tlsr82_serial.c
Expand Up @@ -331,32 +331,51 @@ static uart_dev_t g_uart0_dev =
****************************************************************************/

/****************************************************************************
* Name: uart_reset
* Name: uart_clr_rx_index
*
* Description:
* Reset the uart hardware, the software pointer must be set to zero
* (function uart_clr_rx_index() must be called).
* Clear the uart receive software pointer, this function must be called
* after wakeup from power-saving mode or reset uart.
*
* Parameters:
* uart_num - the uart hardware index
*
* Returned Values:
* void
*
****************************************************************************/

static inline void uart_clr_rx_index(int uart_num)
{
uart_rxindex = 0;
}

/****************************************************************************
* Name: uart_clr_tx_index
*
* Description:
* Clear the uart transimit software pointer, this function must be called
* after wakeup from power-saving mode or reset uart.
*
* Parameters:
* uart_num - the uart hardware index
*
* Returned Values:
* void
*
****************************************************************************/

static inline void uart_reset(void)
static inline void uart_clr_tx_index(int uart_num)
{
RESET_RST0_REG |= RESET_RST0_UART;
RESET_RST0_REG &= ~RESET_RST0_UART;
uart_txindex = 0;
}

/****************************************************************************
* Name: uart_reset
*
* Description:
* Clear the uart receive software pointer, this function must be called
* after wakeup from power-saving mode or reset uart.
* Reset the uart hardware, the software pointer must be set to zero
* (function uart_clr_rx_index() must be called).
*
* Parameters:
* uart_num - the uart hardware index
Expand All @@ -366,9 +385,12 @@ static inline void uart_reset(void)
*
****************************************************************************/

static inline void uart_clr_rx_index(int uart_num)
static inline void uart_reset(int uart_num)
{
uart_rxindex = 0;
RESET_RST0_REG |= RESET_RST0_UART;
RESET_RST0_REG &= ~RESET_RST0_UART;
uart_clr_rx_index(uart_num);
uart_clr_tx_index(uart_num);
}

/****************************************************************************
Expand Down Expand Up @@ -999,7 +1021,7 @@ static int tlsr82_uart_setup(struct uart_dev_s *dev)

/* Reset the uart */

uart_reset();
uart_reset(priv->port);

/* Uart communication parameters config
* TODO: unity below functions to uart_format_config()
Expand Down Expand Up @@ -1071,10 +1093,9 @@ static int UART_RAMCODE tlsr82_interrupt(int irq, void *context, void *arg)

uart_irq_clr(priv->port, UART_IRQ_CLR_RX);

/* uart_reset() clear hardware pointer, and clear software pointer */
/* uart_reset() clear hardware and software fifo index */

uart_reset();
uart_clr_rx_index(priv->port);
uart_reset(priv->port);
}

#ifdef CONFIG_SERIAL_TXDMA
Expand Down

0 comments on commit 282c410

Please sign in to comment.