Skip to content

Commit 98bee29

Browse files
committed
Sends characters if TX is empty. Buffers the rest. TX interrupts working.
1 parent f12b6ef commit 98bee29

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

cores/arduino/ard_sup/uart/ap3_uart.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,40 +122,38 @@ size_t Uart::write(const uint8_t *buffer, size_t size)
122122
//FIFO on Apollo3 is 32 bytes
123123

124124
//If TX UART is sitting idle, load it. This will start the ISR TX handler as well.
125-
uint32_t uartFlags = 0;
125+
uint32_t uartFlags;
126126
am_hal_uart_flags_get(_handle, &uartFlags);
127-
128-
// am_hal_uart_tx_flush(_handle);
129127
if (uartFlags & AM_HAL_UART_FR_TX_EMPTY)
130-
//if (1)
131128
{
132129
uint32_t amtToSend = size;
133130
if (amtToSend > AM_HAL_UART_FIFO_MAX)
134131
amtToSend = AM_HAL_UART_FIFO_MAX;
135132

133+
size -= amtToSend;
134+
136135
//Transfer to local buffer
137136
uint8_t tempTX[AM_HAL_UART_FIFO_MAX];
138137
for (int x = 0; x < amtToSend; x++)
139-
tempTX[x] = _tx_buffer.read_char();
138+
tempTX[x] = buffer[x];
140139

141140
const am_hal_uart_transfer_t sUartWrite =
142141
{
143142
.ui32Direction = AM_HAL_UART_WRITE,
144-
.pui8Data = (uint8_t *)buffer,
145-
.ui32NumBytes = size,
146-
.ui32TimeoutMs = 0, //Use non-blocking xfer
143+
.pui8Data = (uint8_t *)tempTX,
144+
.ui32NumBytes = amtToSend,
145+
// .ui32TimeoutMs = 0, //Use non-blocking xfer
146+
.ui32TimeoutMs = AM_HAL_UART_WAIT_FOREVER,
147147
.pui32BytesTransferred = (uint32_t *)&ui32BytesWritten,
148148
};
149149
am_hal_uart_transfer(_handle, &sUartWrite);
150150
}
151-
else
152-
{
153-
//UART is already sending bytes so load the ring buffer instead
154-
for (int x = 0; x < size; x++)
155-
_tx_buffer.store_char(buffer[x]);
156-
ui32BytesWritten = size;
157-
}
158-
return ui32BytesWritten;
151+
152+
//Transfer any remaining bytes into ring buffer
153+
for (int x = 0; x < size; x++)
154+
_tx_buffer.store_char(buffer[x]);
155+
156+
return ui32BytesWritten; //Return number of bytes pushed to UART hardware
159157
}
160158

161159
// Stop Bits

0 commit comments

Comments
 (0)