Skip to content

Commit 91a53a4

Browse files
committed
Use UART TX FIFO
When possible, fill the tx FIFO in interrupt handler, in order to reduce number of interrupts called and overhead.
1 parent 28d2a75 commit 91a53a4

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

cores/arduino/UARTClass.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,12 @@ void UARTClass::IrqHandler( void )
217217
// if irq is Transmitter Holding Register
218218
else if(uart_irq_tx_ready(CONFIG_UART_CONSOLE_INDEX))
219219
{
220-
if (_tx_buffer->_iTail != _tx_buffer->_iHead) {
221-
uart_poll_out(CONFIG_UART_CONSOLE_INDEX, _tx_buffer->_aucBuffer[_tx_buffer->_iTail]);
222-
_tx_buffer->_iTail = (unsigned int)(_tx_buffer->_iTail + 1) % UART_BUFFER_SIZE;
220+
if(_tx_buffer->_iTail != _tx_buffer->_iHead)
221+
{
222+
int end = (_tx_buffer->_iTail < _tx_buffer->_iHead) ? _tx_buffer->_iHead:SERIAL_BUFFER_SIZE;
223+
int l = min(end - _tx_buffer->_iTail, UART_FIFO_SIZE);
224+
uart_fifo_fill(CONFIG_UART_CONSOLE_INDEX, _tx_buffer->_aucBuffer+_tx_buffer->_iTail, l);
225+
_tx_buffer->_iTail = (_tx_buffer->_iTail+l)%UART_BUFFER_SIZE;
223226
}
224227
else
225228
{

system/libarc32_arduino101/drivers/ns16550.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ unsigned char uart_poll_out(
352352
*
353353
* uart_fifo_fill - fill FIFO with data
354354
*
355+
* It is up to the caller to make sure that FIFO capcity is not exceeded
356+
*
355357
* RETURNS: number of bytes sent
356358
*/
357359

@@ -362,8 +364,8 @@ int uart_fifo_fill(int which, /* UART on which to send */
362364
{
363365
int i;
364366

365-
for (i = 0; i < size && (INBYTE(LSR(which)) &
366-
LSR_BOTH_EMPTY) != 0; i++) {
367+
for (i = 0; i < size ; i++)
368+
{
367369
OUTBYTE(THR(which), txData[i]);
368370
}
369371
return i;

system/libarc32_arduino101/drivers/uart.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ extern "C" {
5454
/* options for uart init */
5555
#define UART_OPTION_AFCE 0x01
5656

57+
/* Size of the FIFO in bytes */
58+
#define UART_FIFO_SIZE 16
59+
5760
/* generic UART info structure */
5861
struct uart_init_info {
5962
int baud_rate;

0 commit comments

Comments
 (0)