drivers: serial: atmel_sam: Fix api to work with modbus

This patch adds fixes to the api so that it behaves as expected.
1 - The irq_tx_ready now only returns true if the tx interrupt is
enabled.
2 - The irq_tx_complete now functions as expected and returns true
only once all characters have been transmitted

Signed-off-by: Marius Scholtz <mariuss@ricelectronics.com>
This commit is contained in:
Marius Scholtz 2022-01-21 09:17:54 -08:00 committed by Anas Nashif
commit 56ebbb4603
2 changed files with 14 additions and 4 deletions

View file

@ -229,7 +229,11 @@ static int uart_sam_irq_tx_ready(const struct device *dev)
volatile Uart * const uart = cfg->regs; volatile Uart * const uart = cfg->regs;
return (uart->UART_SR & UART_SR_TXRDY); /* Check that the transmitter is ready but only
* return true if the interrupt is also enabled
*/
return (uart->UART_SR & UART_SR_TXRDY &&
uart->UART_IMR & UART_IMR_TXRDY);
} }
static void uart_sam_irq_rx_enable(const struct device *dev) static void uart_sam_irq_rx_enable(const struct device *dev)
@ -256,7 +260,8 @@ static int uart_sam_irq_tx_complete(const struct device *dev)
volatile Uart * const uart = cfg->regs; volatile Uart * const uart = cfg->regs;
return !(uart->UART_SR & UART_SR_TXRDY); return (uart->UART_SR & UART_SR_TXRDY &&
uart->UART_IMR & UART_IMR_TXEMPTY);
} }
static int uart_sam_irq_rx_ready(const struct device *dev) static int uart_sam_irq_rx_ready(const struct device *dev)

View file

@ -230,7 +230,11 @@ static int usart_sam_irq_tx_ready(const struct device *dev)
volatile Usart * const usart = config->regs; volatile Usart * const usart = config->regs;
return (usart->US_CSR & US_CSR_TXRDY); /* Check that the transmitter is ready but only
* return true if the interrupt is also enabled
*/
return (usart->US_CSR & US_CSR_TXRDY &&
usart->US_IMR & US_IMR_TXRDY);
} }
static void usart_sam_irq_rx_enable(const struct device *dev) static void usart_sam_irq_rx_enable(const struct device *dev)
@ -257,7 +261,8 @@ static int usart_sam_irq_tx_complete(const struct device *dev)
volatile Usart * const usart = config->regs; volatile Usart * const usart = config->regs;
return !(usart->US_CSR & US_CSR_TXRDY); return (usart->US_CSR & US_CSR_TXRDY &&
usart->US_CSR & US_CSR_TXEMPTY);
} }
static int usart_sam_irq_rx_ready(const struct device *dev) static int usart_sam_irq_rx_ready(const struct device *dev)