Skip to content

Commit 56ebbb4

Browse files
Marius Scholtznashif
authored andcommitted
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 <[email protected]>
1 parent 5a1129f commit 56ebbb4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

drivers/serial/uart_sam.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ static int uart_sam_irq_tx_ready(const struct device *dev)
229229

230230
volatile Uart * const uart = cfg->regs;
231231

232-
return (uart->UART_SR & UART_SR_TXRDY);
232+
/* Check that the transmitter is ready but only
233+
* return true if the interrupt is also enabled
234+
*/
235+
return (uart->UART_SR & UART_SR_TXRDY &&
236+
uart->UART_IMR & UART_IMR_TXRDY);
233237
}
234238

235239
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)
256260

257261
volatile Uart * const uart = cfg->regs;
258262

259-
return !(uart->UART_SR & UART_SR_TXRDY);
263+
return (uart->UART_SR & UART_SR_TXRDY &&
264+
uart->UART_IMR & UART_IMR_TXEMPTY);
260265
}
261266

262267
static int uart_sam_irq_rx_ready(const struct device *dev)

drivers/serial/usart_sam.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ static int usart_sam_irq_tx_ready(const struct device *dev)
230230

231231
volatile Usart * const usart = config->regs;
232232

233-
return (usart->US_CSR & US_CSR_TXRDY);
233+
/* Check that the transmitter is ready but only
234+
* return true if the interrupt is also enabled
235+
*/
236+
return (usart->US_CSR & US_CSR_TXRDY &&
237+
usart->US_IMR & US_IMR_TXRDY);
234238
}
235239

236240
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)
257261

258262
volatile Usart * const usart = config->regs;
259263

260-
return !(usart->US_CSR & US_CSR_TXRDY);
264+
return (usart->US_CSR & US_CSR_TXRDY &&
265+
usart->US_CSR & US_CSR_TXEMPTY);
261266
}
262267

263268
static int usart_sam_irq_rx_ready(const struct device *dev)

0 commit comments

Comments
 (0)