From 0fd7b2b7a8d5da995bc22b8e766227378eb1fc18 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Tue, 20 Apr 2021 00:32:44 +0200 Subject: [PATCH] Fix serial driver --- drivers/serial.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/serial.c b/drivers/serial.c index 1d175b2..fa54a0b 100644 --- a/drivers/serial.c +++ b/drivers/serial.c @@ -117,12 +117,12 @@ static void uart_check_rx(struct uart_device* uart, uint32_t intr) static void uart_check_tx(struct uart_device* uart, uint32_t intr) { /* We are currently sending, send next char */ - if (intr & LPC_UART_ST_TX_READY) { + if (intr & LPC_UART_ST_TX_IDLE) { if (uart->sending && (uart->out_length > uart->sending)) { uart->regs->tx_data = uart->out_buff[uart->sending++]; } else { uart->sending = 0; - uart->regs->inten_clear = LPC_UART_ST_TX_READY; + uart->regs->inten_clear = LPC_UART_ST_TX_IDLE; } } } @@ -132,10 +132,11 @@ static void UART_Handler(struct uart_device* uart) { uint32_t intr = uart->regs->status; - uart_check_rx(uart, intr); - uart_check_tx(uart, intr); /* Clear all flags */ uart->regs->status = LPC_UART_ST_CLEAR; + /* And check what got received / sent */ + uart_check_rx(uart, intr); + uart_check_tx(uart, intr); } @@ -162,9 +163,9 @@ static void uart_start_sending(uint32_t uart_num) if (!uart->sending && (uart->out_length != 0)) { uart->sending++; uart->regs->tx_data = uart->out_buff[0]; - /* Activate only LPC_UART_ST_TX_READY in order to prevent multiple calls to + /* Activate only LPC_UART_ST_TX_IDLE in order to prevent multiple calls to * the interrupt handler, which will cause data loss */ - uart->regs->inten_set = (LPC_UART_ST_TX_READY); + uart->regs->inten_set = (LPC_UART_ST_TX_IDLE); } } @@ -258,7 +259,7 @@ int serial_flush(uint32_t uart_num) /* Active wait for message to be sent. If interrupts are * disabled, call the UART handler while waiting. */ while (uart->sending) { - if (get_priority_mask() == 0) { + if (get_priority_mask() != 0) { uart_check_tx(uart, uart->regs->status); } } -- 2.43.0