@@ -140,7 +140,7 @@ _txBufferSize(0),
140
140
_onReceiveCB(NULL ),
141
141
_onReceiveErrorCB(NULL ),
142
142
_onReceiveTimeout(true ),
143
- _rxTimeout(10 ),
143
+ _rxTimeout(2 ),
144
144
_eventTask(NULL )
145
145
#if !CONFIG_DISABLE_HAL_LOCKS
146
146
,_lock(NULL )
@@ -212,6 +212,18 @@ void HardwareSerial::onReceive(OnReceiveCb function, bool onlyOnTimeout)
212
212
HSERIAL_MUTEX_UNLOCK ();
213
213
}
214
214
215
+ // This function allow the user to define how many bytes will trigger an Interrupt that will copy RX FIFO to the internal RX Ringbuffer
216
+ // ISR will also move data from FIFO to RX Ringbuffer after a RX Timeout defined in HardwareSerial::setRxTimeout(uint8_t symbols_timeout)
217
+ // A low value of FIFO Full bytes will consume more CPU time within the ISR
218
+ // A high value of FIFO Full bytes will make the application wait longer to have byte available for the Stkech in a streaming scenario
219
+ // Both RX FIFO Full and RX Timeout may affect when onReceive() will be called
220
+ void HardwareSerial::setRxFIFOFull (uint8_t fifoBytes)
221
+ {
222
+ HSERIAL_MUTEX_LOCK ();
223
+ uartSetRxFIFOFull (_uart, fifoBytes); // Set new timeout
224
+ HSERIAL_MUTEX_UNLOCK ();
225
+ }
226
+
215
227
// timout is calculates in time to receive UART symbols at the UART baudrate.
216
228
// the estimation is about 11 bits per symbol (SERIAL_8N1)
217
229
void HardwareSerial::setRxTimeout (uint8_t symbols_timeout)
@@ -223,7 +235,7 @@ void HardwareSerial::setRxTimeout(uint8_t symbols_timeout)
223
235
_rxTimeout = symbols_timeout;
224
236
if (!symbols_timeout) _onReceiveTimeout = false ; // only when RX timeout is disabled, we also must disable this flag
225
237
226
- if (_uart != NULL ) uart_set_rx_timeout (_uart_nr , _rxTimeout); // Set new timeout
238
+ uartSetRxTimeout (_uart, _rxTimeout); // Set new timeout
227
239
228
240
HSERIAL_MUTEX_UNLOCK ();
229
241
}
@@ -250,6 +262,7 @@ void HardwareSerial::_uartEventTask(void *args)
250
262
for (;;) {
251
263
// Waiting for UART event.
252
264
if (xQueueReceive (uartEventQueue, (void * )&event, (portTickType)portMAX_DELAY)) {
265
+ hardwareSerial_error_t currentErr = UART_NO_ERROR;
253
266
switch (event.type ) {
254
267
case UART_DATA:
255
268
if (uart->_onReceiveCB && uart->available () > 0 &&
@@ -258,28 +271,32 @@ void HardwareSerial::_uartEventTask(void *args)
258
271
break ;
259
272
case UART_FIFO_OVF:
260
273
log_w (" UART%d FIFO Overflow. Consider adding Hardware Flow Control to your Application." , uart->_uart_nr );
261
- if (uart-> _onReceiveErrorCB ) uart-> _onReceiveErrorCB ( UART_FIFO_OVF_ERROR) ;
274
+ currentErr = UART_FIFO_OVF_ERROR;
262
275
break ;
263
276
case UART_BUFFER_FULL:
264
277
log_w (" UART%d Buffer Full. Consider increasing your buffer size of your Application." , uart->_uart_nr );
265
- if (uart-> _onReceiveErrorCB ) uart-> _onReceiveErrorCB ( UART_BUFFER_FULL_ERROR) ;
278
+ currentErr = UART_BUFFER_FULL_ERROR;
266
279
break ;
267
280
case UART_BREAK:
268
281
log_w (" UART%d RX break." , uart->_uart_nr );
269
- if (uart-> _onReceiveErrorCB ) uart-> _onReceiveErrorCB ( UART_BREAK_ERROR) ;
282
+ currentErr = UART_BREAK_ERROR;
270
283
break ;
271
284
case UART_PARITY_ERR:
272
285
log_w (" UART%d parity error." , uart->_uart_nr );
273
- if (uart-> _onReceiveErrorCB ) uart-> _onReceiveErrorCB ( UART_PARITY_ERROR) ;
286
+ currentErr = UART_PARITY_ERROR;
274
287
break ;
275
288
case UART_FRAME_ERR:
276
289
log_w (" UART%d frame error." , uart->_uart_nr );
277
- if (uart-> _onReceiveErrorCB ) uart-> _onReceiveErrorCB ( UART_FRAME_ERROR) ;
290
+ currentErr = UART_FRAME_ERROR;
278
291
break ;
279
292
default :
280
293
log_w (" UART%d unknown event type %d." , uart->_uart_nr , event.type );
281
294
break ;
282
295
}
296
+ if (currentErr != UART_NO_ERROR) {
297
+ if (uart->_onReceiveErrorCB ) uart->_onReceiveErrorCB (currentErr);
298
+ if (uart->_onReceiveCB && uart->available () > 0 ) uart->_onReceiveCB (); // forces User Callback too
299
+ }
283
300
}
284
301
}
285
302
}
@@ -366,9 +383,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
366
383
}
367
384
368
385
// Set UART RX timeout
369
- if (_uart != NULL ) {
370
- uart_set_rx_timeout (_uart_nr, _rxTimeout);
371
- }
386
+ uartSetRxTimeout (_uart, _rxTimeout);
372
387
373
388
HSERIAL_MUTEX_UNLOCK ();
374
389
}
0 commit comments