@@ -122,40 +122,38 @@ size_t Uart::write(const uint8_t *buffer, size_t size)
122
122
// FIFO on Apollo3 is 32 bytes
123
123
124
124
// 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;
126
126
am_hal_uart_flags_get (_handle, &uartFlags);
127
-
128
- // am_hal_uart_tx_flush(_handle);
129
127
if (uartFlags & AM_HAL_UART_FR_TX_EMPTY)
130
- // if (1)
131
128
{
132
129
uint32_t amtToSend = size;
133
130
if (amtToSend > AM_HAL_UART_FIFO_MAX)
134
131
amtToSend = AM_HAL_UART_FIFO_MAX;
135
132
133
+ size -= amtToSend;
134
+
136
135
// Transfer to local buffer
137
136
uint8_t tempTX[AM_HAL_UART_FIFO_MAX];
138
137
for (int x = 0 ; x < amtToSend; x++)
139
- tempTX[x] = _tx_buffer. read_char () ;
138
+ tempTX[x] = buffer[x] ;
140
139
141
140
const am_hal_uart_transfer_t sUartWrite =
142
141
{
143
142
.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,
147
147
.pui32BytesTransferred = (uint32_t *)&ui32BytesWritten,
148
148
};
149
149
am_hal_uart_transfer (_handle, &sUartWrite );
150
150
}
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
159
157
}
160
158
161
159
// Stop Bits
0 commit comments