Skip to content

Commit 1033e89

Browse files
committed
supervisor: use mp_handle_pending to check for exceptions
1 parent f8a9e11 commit 1033e89

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

supervisor/shared/micropython.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "lib/oofatfs/ff.h"
3131
#include "py/mpconfig.h"
3232
#include "py/mpstate.h"
33+
#include "py/runtime.h"
3334

3435
#include "supervisor/shared/status_leds.h"
3536

@@ -45,16 +46,7 @@ int mp_hal_stdin_rx_chr(void) {
4546
#ifdef MICROPY_VM_HOOK_LOOP
4647
MICROPY_VM_HOOK_LOOP
4748
#endif
48-
// Check to see if we've been CTRL-Ced by autoreload or the user.
49-
if (MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))) {
50-
// clear exception and generate stacktrace
51-
MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL;
52-
nlr_raise(&MP_STATE_VM(mp_kbd_exception));
53-
}
54-
if (MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception)) || WATCHDOG_EXCEPTION_CHECK()) {
55-
// stop reading immediately
56-
return EOF;
57-
}
49+
mp_handle_pending();
5850
if (serial_bytes_available()) {
5951
toggle_rx_led();
6052
return serial_read();

supervisor/shared/tick.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "supervisor/shared/tick.h"
2828

2929
#include "py/mpstate.h"
30+
#include "py/runtime.h"
3031
#include "supervisor/linker.h"
3132
#include "supervisor/filesystem.h"
3233
#include "supervisor/background_callback.h"
@@ -149,17 +150,7 @@ void mp_hal_delay_ms(mp_uint_t delay) {
149150
while (remaining > 0) {
150151
RUN_BACKGROUND_TASKS;
151152
// Check to see if we've been CTRL-Ced by autoreload or the user.
152-
if(MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)))
153-
{
154-
// clear exception and generate stacktrace
155-
MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL;
156-
nlr_raise(&MP_STATE_VM(mp_kbd_exception));
157-
}
158-
if( MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception)) ||
159-
WATCHDOG_EXCEPTION_CHECK()) {
160-
// stop sleeping immediately
161-
break;
162-
}
153+
mp_handle_pending();
163154
remaining = end_tick - port_get_raw_ticks(NULL);
164155
// We break a bit early so we don't risk setting the alarm before the time when we call
165156
// sleep.

0 commit comments

Comments
 (0)