diff --git a/libs/bluetooth/bluetooth_utils.c b/libs/bluetooth/bluetooth_utils.c index f15c1a6291..375cd46233 100644 --- a/libs/bluetooth/bluetooth_utils.c +++ b/libs/bluetooth/bluetooth_utils.c @@ -394,14 +394,12 @@ void jsble_queue_pending_buf(BLEPending blep, uint16_t data, char *ptr, size_t l // Push the actual event JsSysTime d = (JsSysTime)((data<<8)|blep); jshPushIOEvent(EV_BLUETOOTH_PENDING, d); - jshHadEvent(); } /// Add a new bluetooth event to the queue with 16 bits of data void jsble_queue_pending(BLEPending blep, uint16_t data) { JsSysTime d = (JsSysTime)((data<<8)|blep); jshPushIOEvent(EV_BLUETOOTH_PENDING, d); - jshHadEvent(); } /* Handler for common event types (between nRF52/ESP32). Called first diff --git a/src/jsdevices.c b/src/jsdevices.c index d8db0d1c24..f0c1ca82dc 100644 --- a/src/jsdevices.c +++ b/src/jsdevices.c @@ -477,7 +477,7 @@ void jshPushIOCharEvents(IOEventFlags channel, char *data, unsigned int count) { for (i=0;icdcRX, rxLength); + jshHadEvent(); // Set CDC_READ_WAIT_EMPTY flag - we'll re-enable USB RX using // USBD_LL_PrepareReceive ONLY when we have enough space diff --git a/targets/nrf5x/jshardware.c b/targets/nrf5x/jshardware.c index 6f9137e84d..d605e6ed31 100644 --- a/targets/nrf5x/jshardware.c +++ b/targets/nrf5x/jshardware.c @@ -235,7 +235,7 @@ static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst, /*Get amount of data transfered*/ size_t size = app_usbd_cdc_acm_rx_size(p_cdc_acm); jshPushIOCharEvents(EV_USBSERIAL, m_rx_buffer, size); - + jshHadEvent(); /*Setup next transfer*/ ret = app_usbd_cdc_acm_read(&m_app_cdc_acm, @@ -1671,7 +1671,6 @@ static void jsvPinWatchHandler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t a lastHandledPinState = !lastHandledPinState; IOEventFlags evt = jshGetEventFlagsForWatchedPin(pin); jshPushIOWatchEvent(evt); - jshHadEvent(); } @@ -2205,7 +2204,6 @@ static void twis_event_handler(nrf_drv_twis_evt_t const * const p_event) break; case TWIS_EVT_READ_DONE: jshPushIOEvent(EV_I2C1, twisAddr|0x80|(p_event->data.tx_amount<<8)); // send event to indicate a read - jshHadEvent(); twisAddr += p_event->data.tx_amount; break; case TWIS_EVT_WRITE_REQ: @@ -2217,7 +2215,6 @@ static void twis_event_handler(nrf_drv_twis_evt_t const * const p_event) twisAddr = twisRxBuf[0]; if (p_event->data.rx_amount>1) { jshPushIOEvent(EV_I2C1, twisAddr|((p_event->data.rx_amount-1)<<8)); // send event to indicate a write - jshHadEvent(); JsVar *i2c = jsvObjectGetChildIfExists(execInfo.root,"I2C1"); if (i2c) { JsVar *buf = jsvObjectGetChildIfExists(i2c,"buffer"); @@ -2921,12 +2918,10 @@ void COMP_LPCOMP_IRQHandler() { if (nrf_lpcomp_event_check(NRF_LPCOMP_EVENT_UP) && nrf_lpcomp_int_enable_check(LPCOMP_INTENSET_UP_Msk)) { nrf_lpcomp_event_clear(NRF_LPCOMP_EVENT_UP); jshPushIOEvent(EV_CUSTOM, EVC_LPCOMP | EVC_DATA_LPCOMP_UP); - jshHadEvent(); } if (nrf_lpcomp_event_check(NRF_LPCOMP_EVENT_DOWN) && nrf_lpcomp_int_enable_check(LPCOMP_INTENSET_DOWN_Msk)) { nrf_lpcomp_event_clear(NRF_LPCOMP_EVENT_DOWN); jshPushIOEvent(EV_CUSTOM, EVC_LPCOMP); - jshHadEvent(); } } diff --git a/targets/stm32/jshardware.c b/targets/stm32/jshardware.c index 0aa4291372..33c3fd2e19 100644 --- a/targets/stm32/jshardware.c +++ b/targets/stm32/jshardware.c @@ -2740,10 +2740,12 @@ bool jshSleep(JsSysTime timeUntilWake) { do { // we loop here so we can half-wake to kick the WDT without incurring wait for USB JsSysTime timeToSleep = timeUntilWake; + // Don't sleep so long the WDT goes off! if (isAutoWDT && timeToSleep>watchdogSleepMax) timeToSleep = watchdogSleepMax; - if (timeUntilWake==JSSYSTIME_MAX) timeUntilWake = 0; // if we're just waiting for as long as possible - else timeUntilWake -= timeToSleep; + // if JSSYSTIME_MAX we just sleep as long as possible unless woken by something else + if (timeUntilWake!=JSSYSTIME_MAX) + timeUntilWake -= timeToSleep; if (isAutoWDT) jshKickWatchDog(); /* Add EXTI for Serial port */ //jshPinWatch(JSH_PORTA_OFFSET+10, true); @@ -2877,6 +2879,7 @@ bool jshSleep(JsSysTime timeUntilWake) { #endif __WFI(); // Wait for Interrupt jsiSetSleep(JSI_SLEEP_AWAKE); + jshHadEventDuringSleep = false; /* We may have woken up before the wakeup event. If so then make sure we clear the event */ diff --git a/targets/stm32/stm32_it.c b/targets/stm32/stm32_it.c index a8fcf6baa6..3143ccbaca 100644 --- a/targets/stm32/stm32_it.c +++ b/targets/stm32/stm32_it.c @@ -304,6 +304,7 @@ NO_INLINE static void USART_IRQHandler(USART_TypeDef *USART, IOEventFlags device if (jshIsSerial7Bit(device)) ch &= 0x7F; /* Put it in our queue */ jshPushIOCharEvent(device, ch); + jshHadEvent(); } /* If overrun condition occurs, clear the ORE flag and recover communication */ if (USART_GetFlagStatus(USART, USART_FLAG_ORE) != RESET) { diff --git a/targets/stm32_ll/stm32_it.c b/targets/stm32_ll/stm32_it.c index eb4916aa2f..3967e8b94c 100644 --- a/targets/stm32_ll/stm32_it.c +++ b/targets/stm32_ll/stm32_it.c @@ -272,6 +272,7 @@ static void USART_IRQHandler(USART_TypeDef *USART, IOEventFlags device) { if (jshIsSerial7Bit(device)) ch &= 0x7F; /* Put it in our queue */ jshPushIOCharEvent(device, ch); + jshHadEvent(); } /* If overrun condition occurs, clear the ORE flag and recover communication */ if (LL_USART_IsActiveFlag_ORE(USART) != RESET)