Skip to content

Commit fea8ee4

Browse files
Jerzy Kasenbergdkalowsk
authored andcommitted
tests: drivers: uart: async_api: Fix chain write
This fixes the case where uart_tx() called from tx callback fill UART output fifo and immediately execute callback again. This can happen when hardware does not have interrupt for output FIFO empty and there is no non-blocking way to tell that transfer finished. For such case as soon as output FIFO is filled there is interrupt that informs that more data can be transmitted. For hardware with 32 byte fifo callback was seen to be executed recursively 3 times. That would not be a problem if chained_write_next_buf was set BEFORE next call uart_tx(). Additionally semaphore max value is increased to 2 to accommodate such case. Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg.xr@bp.renesas.com>
1 parent 8186e6c commit fea8ee4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tests/drivers/uart/uart_async_api/src/test_uart_async.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define NOCACHE_MEM 0
1818
#endif /* CONFIG_NOCACHE_MEMORY */
1919

20-
K_SEM_DEFINE(tx_done, 0, 1);
20+
K_SEM_DEFINE(tx_done, 0, 2);
2121
K_SEM_DEFINE(tx_aborted, 0, 1);
2222
K_SEM_DEFINE(rx_rdy, 0, 1);
2323
K_SEM_DEFINE(rx_buf_coherency, 0, 255);
@@ -833,8 +833,8 @@ static void test_chained_write_callback(const struct device *dev,
833833
switch (evt->type) {
834834
case UART_TX_DONE:
835835
if (chained_write_next_buf) {
836-
uart_tx(dev, chained_write_tx_bufs[1], 10, 100 * USEC_PER_MSEC);
837836
chained_write_next_buf = false;
837+
uart_tx(dev, chained_write_tx_bufs[1], 10, 100 * USEC_PER_MSEC);
838838
}
839839
tx_sent = 1;
840840
k_sem_give(&tx_done);

0 commit comments

Comments
 (0)