Skip to content

Commit b4adb76

Browse files
committed
Added Error flag to show if a UART overflow has occurred
1 parent d9ff37d commit b4adb76

File tree

5 files changed

+10
-3
lines changed

5 files changed

+10
-3
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
ESP8266: Wifi library doesn't handle {password: null} (fix #753)
2323
ESP8266: make topstrings and topreadonly work on Mac OS X (fix #1210)
2424
Change order of execution for init - E.on('init',...) now executed before onInit
25+
Added Error flag to show if a UART overflow has occurred
2526

2627
1v93 : Ensure that specifying too many advertising UUIDs causes an exception, not a reboot
2728
nRF5x: Fix for time jump caused by reentrancy in jshGetSystemTime

src/jsutils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ typedef enum {
404404
JSERR_LOW_MEMORY = 8, ///< Memory is running low - Espruino had to run a garbage collection pass or remove some of the command history
405405
JSERR_MEMORY = 16, ///< Espruino ran out of memory and was unable to allocate some data that it needed.
406406
JSERR_MEMORY_BUSY = 32, ///< Espruino was busy doing something with memory (eg. garbage collection) so an IRQ couldn't allocate memory
407+
JSERR_UART_OVERFLOW = 64 ///< A UART received data but it was not read in time and was lost
407408
} PACKED_FLAGS JsErrorFlags;
408409

409410
/** Error flags for things that we don't really want to report on the console,

src/jswrap_espruino.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ Get and reset the error flags. Returns an array that can contain:
644644
`'LOW_MEMORY'`: Memory is running low - Espruino had to run a garbage collection pass or remove some of the command history
645645
646646
`'MEMORY'`: Espruino ran out of memory and was unable to allocate some data that it needed.
647+
648+
`'JSERR_UART_OVERFLOW'` : A UART received data but it was not read in time and was lost
647649
*/
648650
JsVar *jswrap_espruino_getErrorFlags() {
649651
JsVar *arr = jsvNewEmptyArray();
@@ -653,7 +655,8 @@ JsVar *jswrap_espruino_getErrorFlags() {
653655
if (jsErrorFlags&JSERR_CALLBACK) jsvArrayPushAndUnLock(arr, jsvNewFromString("CALLBACK"));
654656
if (jsErrorFlags&JSERR_LOW_MEMORY) jsvArrayPushAndUnLock(arr, jsvNewFromString("LOW_MEMORY"));
655657
if (jsErrorFlags&JSERR_MEMORY) jsvArrayPushAndUnLock(arr, jsvNewFromString("MEMORY"));
656-
if (jsErrorFlags&JSERR_MEMORY_BUSY) jsvArrayPushAndUnLock(arr, jsvNewFromString("JSERR_MEMORY_BUSY"));
658+
if (jsErrorFlags&JSERR_MEMORY_BUSY) jsvArrayPushAndUnLock(arr, jsvNewFromString("MEMORY_BUSY"));
659+
if (jsErrorFlags&JSERR_UART_OVERFLOW) jsvArrayPushAndUnLock(arr, jsvNewFromString("UART_OVERFLOW"));
657660
jsErrorFlags = JSERR_NONE;
658661
return arr;
659662
}

targets/nrf5x/jshardware.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,8 @@ void uart0_event_handle(app_uart_evt_t * p_event) {
838838
jshPushIOEvent(IOEVENTFLAGS_SERIAL_TO_SERIAL_STATUS(EV_SERIAL1) | EV_SERIAL_STATUS_FRAMING_ERR, 0);
839839
if (p_event->data.error_communication & (UART_ERRORSRC_PARITY_Msk) && jshGetErrorHandlingEnabled(EV_SERIAL1))
840840
jshPushIOEvent(IOEVENTFLAGS_SERIAL_TO_SERIAL_STATUS(EV_SERIAL1) | EV_SERIAL_STATUS_PARITY_ERR, 0);
841+
if (p_event->data.error_communication & (UART_ERRORSRC_OVERRUN_Msk))
842+
jsErrorFlags |= JSERR_UART_OVERFLOW;
841843
} else if (p_event->evt_type == APP_UART_TX_EMPTY) {
842844
int ch = jshGetCharToTransmit(EV_SERIAL1);
843845
if (ch >= 0) {

targets/stm32/stm32_it.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ NO_INLINE static void USART_IRQHandler(USART_TypeDef *USART, IOEventFlags device
300300
jshPushIOCharEvent(device, (char)USART_ReceiveData(USART));
301301
}
302302
/* If overrun condition occurs, clear the ORE flag and recover communication */
303-
if (USART_GetFlagStatus(USART, USART_FLAG_ORE) != RESET)
304-
{
303+
if (USART_GetFlagStatus(USART, USART_FLAG_ORE) != RESET) {
304+
jsErrorFlags |= JSERR_UART_OVERFLOW;
305305
(void)USART_ReceiveData(USART);
306306
}
307307
if(USART_GetITStatus(USART, USART_IT_TXE) != RESET) {

0 commit comments

Comments
 (0)