Implement Tx only Flush (#3433)

* add option to Flush() to only clear txQueue

Add the option to cause Flush() to just wait for tx data to clear the tx fifo and uart, leave the rx queue and rx fifo as is.

* support tx only flush()

* support tx only Flush()

* support txOnly for Flush()

* compatibility to Stream()

* compatibility for Stream()

* default value error

* default value error

* Update esp32-hal-uart.h

* Update esp32-hal-uart.c

* Update HardwareSerial.cpp

* sp

* correctly implement flushTxOnly()
This commit is contained in:
chuck todd 2019-11-11 07:37:35 -07:00 committed by Me No Dev
parent e59355df71
commit 7d2632c024
4 changed files with 23 additions and 9 deletions

View File

@ -131,11 +131,16 @@ int HardwareSerial::read(void)
return -1;
}
void HardwareSerial::flush()
void HardwareSerial::flush(void)
{
uartFlush(_uart);
}
void HardwareSerial::flush(bool txOnly)
{
uartFlushTxOnly(_uart, txOnly);
}
size_t HardwareSerial::write(uint8_t c)
{
uartWrite(_uart, c);

View File

@ -63,6 +63,7 @@ public:
int peek(void);
int read(void);
void flush(void);
void flush( bool txOnly);
size_t write(uint8_t);
size_t write(const uint8_t *buffer, size_t size);

View File

@ -327,6 +327,11 @@ void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len)
}
void uartFlush(uart_t* uart)
{
uartFlushTxOnly(uart,false);
}
void uartFlushTxOnly(uart_t* uart, bool txOnly)
{
if(uart == NULL) {
return;
@ -335,6 +340,7 @@ void uartFlush(uart_t* uart)
UART_MUTEX_LOCK();
while(uart->dev->status.txfifo_cnt || uart->dev->status.st_utx_out);
if( !txOnly ){
//Due to hardware issue, we can not use fifo_rst to reset uart fifo.
//See description about UART_TXFIFO_RST and UART_RXFIFO_RST in <<esp32_technical_reference_manual>> v2.6 or later.
@ -344,6 +350,7 @@ void uartFlush(uart_t* uart)
}
xQueueReset(uart->queue);
}
UART_MUTEX_UNLOCK();
}

View File

@ -63,6 +63,7 @@ void uartWrite(uart_t* uart, uint8_t c);
void uartWriteBuf(uart_t* uart, const uint8_t * data, size_t len);
void uartFlush(uart_t* uart);
void uartFlushTxOnly(uart_t* uart, bool txOnly );
void uartSetBaudRate(uart_t* uart, uint32_t baud_rate);
uint32_t uartGetBaudRate(uart_t* uart);