diff options
| author | robert-hh <robert@hammelrath.com> | 2022-08-26 16:42:10 +0200 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-08-31 00:18:27 +1000 |
| commit | 8804993d0f5326fd71f137433a1b52199d65f119 (patch) | |
| tree | 0c2c8e6dfabea073dd09cac51b7c3f00be8c52b0 /ports/esp8266/uart.c | |
| parent | 49e17c8bb0c55d8efb3f768ba1dfd5b27c466b26 (diff) | |
esp8266/machine_uart: Implement uart.flush() and uart.txdone().
uart.flush()
flush() will wait until all characters but the last one have been sent.
It returns while the last character is sent. If needed, the calling
code has to add one character wait time. To avoid a permanent lock,
a timeout applies depending on the size of the FIFO and the baud rate.
ret = uart.txdone()
ret is True if no transfer is in progress. It returns already True when
the last byte of a transfer is sent.
ret is False otherwise.
Diffstat (limited to 'ports/esp8266/uart.c')
| -rw-r--r-- | ports/esp8266/uart.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/ports/esp8266/uart.c b/ports/esp8266/uart.c index 978a7efc3..117cd1bf6 100644 --- a/ports/esp8266/uart.c +++ b/ports/esp8266/uart.c @@ -111,6 +111,15 @@ void uart_tx_one_char(uint8 uart, uint8 TxChar) { WRITE_PERI_REG(UART_FIFO(uart), TxChar); } +int uart_txdone(uint8 uart) { + uint32 fifo_cnt = READ_PERI_REG(UART_STATUS(uart)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S); + if ((fifo_cnt >> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) == 0) { + return true; + } else { + return false; + } +} + void uart_flush(uint8 uart) { while (true) { uint32 fifo_cnt = READ_PERI_REG(UART_STATUS(uart)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S); |
