From e93cf224b6e8f6559f6b40a18c09f884b01f4855 Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Sun, 7 Apr 2024 17:24:07 +0900 Subject: [PATCH] drivers: serial: pl011: Add err_check function Implementing err_check function by porting from rpi_pico implementation. Signed-off-by: TOKITA Hiroshi --- drivers/serial/uart_pl011.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/serial/uart_pl011.c b/drivers/serial/uart_pl011.c index 6b496923536..53e6e96b123 100644 --- a/drivers/serial/uart_pl011.c +++ b/drivers/serial/uart_pl011.c @@ -153,6 +153,29 @@ static void pl011_poll_out(const struct device *dev, get_uart(dev)->dr = (uint32_t)c; } +static int pl011_err_check(const struct device *dev) +{ + int errors = 0; + + if (get_uart(dev)->rsr & PL011_RSR_ECR_OE) { + errors |= UART_ERROR_OVERRUN; + } + + if (get_uart(dev)->rsr & PL011_RSR_ECR_BE) { + errors |= UART_BREAK; + } + + if (get_uart(dev)->rsr & PL011_RSR_ECR_PE) { + errors |= UART_ERROR_PARITY; + } + + if (get_uart(dev)->rsr & PL011_RSR_ECR_FE) { + errors |= UART_ERROR_FRAMING; + } + + return errors; +} + static int pl011_runtime_configure_internal(const struct device *dev, const struct uart_config *cfg, bool disable) @@ -390,6 +413,7 @@ static void pl011_irq_callback_set(const struct device *dev, static const struct uart_driver_api pl011_driver_api = { .poll_in = pl011_poll_in, .poll_out = pl011_poll_out, + .err_check = pl011_err_check, #ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE .configure = pl011_runtime_configure, .config_get = pl011_runtime_config_get,