Skip to content

Commit 7366ed0

Browse files
descampsasys_maker
authored and
sys_maker
committed
Flush wait for transmission to be complete
In previous version, flush wait for the transmission to be complete by checking if the transmission holding register (or fifo) is empty. When this happen, the last byte is still in the shift register, and has still to be transmitted. This mean we can't know when the transmission is actually complete, which is crucial to implement RS485 communication, for example. This commit change this behaviour and wait for the shift register to be empty, which means the transmission is really complete.
1 parent 48b0e58 commit 7366ed0

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

cores/arduino/UARTClass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void UARTClass::flush( void )
169169
{
170170
while (_tx_buffer->_iHead != _tx_buffer->_iTail); //wait for transmit data to be sent
171171
// Wait for transmission to complete
172-
while (uart_irq_tx_ready(CONFIG_UART_CONSOLE_INDEX));
172+
while(!uart_tx_complete(CONFIG_UART_CONSOLE_INDEX));
173173
}
174174

175175
size_t UARTClass::write( const uint8_t uc_data )

system/libarc32_arduino101/drivers/ns16550.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,16 @@ void uart_int_connect(int which, /* UART to which to connect */
626626
/* set the Host Processor Interrupt Routing Mask */
627627
SOC_UNMASK_INTERRUPTS(INT_UART_0_MASK + (which * UART_REG_ADDR_INTERVAL));
628628
}
629+
630+
/*******************************************************************************
631+
*
632+
* uart_tx_complete - check if tx holding and shift register are empty
633+
*
634+
* RETURNS: zero if registers are non-empty (transmission not complete),
635+
* non-zero if registers are empty (transmission complete)
636+
*/
637+
638+
uint8_t uart_tx_complete(int which)
639+
{
640+
return INBYTE(LSR(which)) & LSR_TEMT;
641+
}

system/libarc32_arduino101/drivers/uart.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ int uart_line_status(int port);
9191
int uart_break_check(int port);
9292
void uart_break_send(int port, int delay);
9393
void uart_disable(int port);
94+
uint8_t uart_tx_complete(int which);
9495

9596
#ifdef __cplusplus
9697
}

0 commit comments

Comments
 (0)