@@ -58,12 +58,14 @@ void UART::WrapperCallback(uart_callback_args_t *p_args) {
58
58
{
59
59
break ;
60
60
}
61
- case UART_EVENT_TX_COMPLETE:
62
- case UART_EVENT_TX_DATA_EMPTY:
61
+ case UART_EVENT_TX_COMPLETE: // This is call when the transmission is complete
63
62
{
64
- // uint8_t to_enqueue = uart_ptr->txBuffer.available() < uart_ptr->uart_ctrl.fifo_depth ? uart_ptr->txBuffer.available() : uart_ptr->uart_ctrl.fifo_depth;
65
- // while (to_enqueue) {
66
- uart_ptr->tx_done = true ;
63
+ uart_ptr->tx_complete = true ;
64
+ break ;
65
+ }
66
+ case UART_EVENT_TX_DATA_EMPTY: // This is called when the buffer is empty
67
+ { // Last byte is transmitting, but ready for more data
68
+ uart_ptr->tx_empty = true ;
67
69
break ;
68
70
}
69
71
case UART_EVENT_RX_CHAR:
@@ -87,6 +89,8 @@ UART::UART(int _pin_tx, int _pin_rx, int _pin_rts, int _pin_cts):
87
89
rx_pin(_pin_rx),
88
90
rts_pin(_pin_rts),
89
91
cts_pin(_pin_cts),
92
+ tx_empty(true ),
93
+ tx_complete(true ),
90
94
init_ok(false ) {
91
95
/* -------------------------------------------------------------------------- */
92
96
uart_cfg.txi_irq = FSP_INVALID_VECTOR;
@@ -109,9 +113,10 @@ bool UART::setUpUartIrqs(uart_cfg_t &cfg) {
109
113
size_t UART::write (uint8_t c) {
110
114
/* -------------------------------------------------------------------------- */
111
115
if (init_ok) {
112
- tx_done = false ;
116
+ tx_empty = false ;
117
+ tx_complete = false ;
113
118
R_SCI_UART_Write (&uart_ctrl, &c, 1 );
114
- while (!tx_done ) {}
119
+ while (!tx_empty ) {}
115
120
return 1 ;
116
121
}
117
122
else {
@@ -121,9 +126,10 @@ size_t UART::write(uint8_t c) {
121
126
122
127
size_t UART::write (uint8_t * c, size_t len) {
123
128
if (init_ok) {
124
- tx_done = false ;
129
+ tx_empty = false ;
130
+ tx_complete = false ;
125
131
R_SCI_UART_Write (&uart_ctrl, c, len);
126
- while (!tx_done ) {}
132
+ while (!tx_empty ) {}
127
133
return len;
128
134
}
129
135
else {
@@ -322,7 +328,7 @@ int UART::read() {
322
328
/* -------------------------------------------------------------------------- */
323
329
void UART::flush () {
324
330
/* -------------------------------------------------------------------------- */
325
- while (txBuffer. available () );
331
+ while (!tx_complete );
326
332
}
327
333
328
334
/* -------------------------------------------------------------------------- */
@@ -335,4 +341,4 @@ size_t UART::write_raw(uint8_t* c, size_t len) {
335
341
i++;
336
342
}
337
343
return len;
338
- }
344
+ }
0 commit comments