From 15530a69c79ded8b38cdb1d87a4e2515a4e12510 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Fri, 22 May 2020 18:43:23 +0800 Subject: [PATCH] supervisor: tick: check for watchdog exception if enabled Check to see if the current exception is a Watchdog exception, if it's enabled. This ensures we break out of the current sleep() if a watchdog timeout hits. Signed-off-by: Sean Cross --- supervisor/shared/tick.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/supervisor/shared/tick.c b/supervisor/shared/tick.c index 0e2adf2160..ba12e1e8c7 100644 --- a/supervisor/shared/tick.c +++ b/supervisor/shared/tick.c @@ -86,6 +86,13 @@ void PLACE_IN_ITCM(supervisor_run_background_tasks_if_tick)() { run_background_tasks(); } +#ifdef CIRCUITPY_WATCHDOG +extern mp_obj_exception_t mp_watchdog_timeout_exception; +#define WATCHDOG_EXCEPTION_CHECK() (MP_STATE_VM(mp_pending_exception) == &mp_watchdog_timeout_exception) +#else +#define WATCHDOG_EXCEPTION_CHECK() 0 +#endif + void mp_hal_delay_ms(mp_uint_t delay) { uint64_t start_tick = port_get_raw_ticks(NULL); // Adjust the delay to ticks vs ms. @@ -97,7 +104,7 @@ void mp_hal_delay_ms(mp_uint_t delay) { // Check to see if we've been CTRL-Ced by autoreload or the user. if(MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) || MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception)) || - MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_watchdog_exception))) { + WATCHDOG_EXCEPTION_CHECK()) { break; } remaining = end_tick - port_get_raw_ticks(NULL);