gustavonihei commented on a change in pull request #3642:
URL: https://github.com/apache/incubator-nuttx/pull/3642#discussion_r625873350
##########
File path: arch/xtensa/src/esp32/esp32_serial.c
##########
@@ -358,24 +362,112 @@ static uart_dev_t g_uart2port =
/****************************************************************************
* Private Functions
****************************************************************************/
+#ifndef CONFIG_SUPPRESS_UART_CONFIG
+/****************************************************************************
+ * Name: esp32_reset_rx_fifo
+ *
+ * Description:
+ * Resets the RX FIFO.
+ * NOTE: We can not use rxfifo_rst to reset the hardware RX FIFO.
+ *
+ * Parameters:
+ * priv - Pointer to the serial driver struct.
+ *
+ ****************************************************************************/
+
+static void esp32_reset_rx_fifo(struct esp32_dev_s *priv)
+{
+ uint32_t rx_status_reg;
+ uint32_t fifo_cnt;
+ uint32_t mem_rx_status_reg;
+ uint32_t rd_address;
+ uint32_t wr_address;
+ do
+ {
+ rx_status_reg = getreg32(UART_STATUS_REG(priv->config->id));
+ fifo_cnt = REG_MASK(rx_status_reg, UART_RXFIFO_CNT);
+ mem_rx_status_reg = getreg32(UART_MEM_RX_STATUS_REG(priv->config->id));
+ rd_address = REG_MASK(mem_rx_status_reg, UART_RD_ADDRESS);
+ wr_address = REG_MASK(mem_rx_status_reg, UART_WR_ADDRESS);
+
+ if ((fifo_cnt != 0) || (rd_address != wr_address))
+ {
+ getreg32(DR_UART_FIFO_REG(priv->config->id));
+ }
+ else
+ {
+ break;
+ }
+ }
+ while (true);
Review comment:
```suggestion
uint32_t rx_status_reg = getreg32(UART_STATUS_REG(priv->config->id));
uint32_t fifo_cnt = REG_MASK(rx_status_reg, UART_RXFIFO_CNT);
uint32_t mem_rx_status_reg =
getreg32(UART_MEM_RX_STATUS_REG(priv->config->id));
uint32_t rd_address = REG_MASK(mem_rx_status_reg, UART_RD_ADDRESS);
uint32_t wr_address = REG_MASK(mem_rx_status_reg, UART_WR_ADDRESS);
while ((fifo_cnt != 0) || (rd_address != wr_address))
{
getreg32(DR_UART_FIFO_REG(priv->config->id));
rx_status_reg = getreg32(UART_STATUS_REG(priv->config->id));
fifo_cnt = REG_MASK(rx_status_reg, UART_RXFIFO_CNT);
mem_rx_status_reg = getreg32(UART_MEM_RX_STATUS_REG(priv->config->id));
rd_address = REG_MASK(mem_rx_status_reg, UART_RD_ADDRESS);
wr_address = REG_MASK(mem_rx_status_reg, UART_WR_ADDRESS);
}
```
This suggestion is functionally equivalent, but I believe it makes the while
condition for termination more explicit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]