From 70dbf7e695d24067ded1e041f39bac9f577abbf0 Mon Sep 17 00:00:00 2001 From: Mahesh Mahadevan Date: Fri, 20 May 2022 16:41:46 -0500 Subject: [PATCH] drivers: uart_imx: Fix the poll_in function Current poll_in function implementation blocks when there is no data available. The Zephyr documentation for poll_in expects the function to return -1 when no data is available. Signed-off-by: Mahesh Mahadevan --- drivers/serial/uart_imx.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/serial/uart_imx.c b/drivers/serial/uart_imx.c index 7c1b336c73..e07588381c 100644 --- a/drivers/serial/uart_imx.c +++ b/drivers/serial/uart_imx.c @@ -113,16 +113,18 @@ static void uart_imx_poll_out(const struct device *dev, unsigned char c) static int uart_imx_poll_in(const struct device *dev, unsigned char *c) { UART_Type *uart = UART_STRUCT(dev); + int ret = -1; - while (!UART_GetStatusFlag(uart, uartStatusRxDataReady)) { - } - *c = UART_Getchar(uart); + if (UART_GetStatusFlag(uart, uartStatusRxDataReady)) { + *c = UART_Getchar(uart); - if (UART_GetStatusFlag(uart, uartStatusRxOverrun)) { - UART_ClearStatusFlag(uart, uartStatusRxOverrun); + if (UART_GetStatusFlag(uart, uartStatusRxOverrun)) { + UART_ClearStatusFlag(uart, uartStatusRxOverrun); + } + ret = 0; } - return 0; + return ret; } #ifdef CONFIG_UART_INTERRUPT_DRIVEN