Skip to content

Commit f8a9e11

Browse files
committed
WIP supervisor: check for interrupt during rx_chr
1 parent dc36a2c commit f8a9e11

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

supervisor/shared/micropython.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,32 @@
2929
#include "supervisor/serial.h"
3030
#include "lib/oofatfs/ff.h"
3131
#include "py/mpconfig.h"
32+
#include "py/mpstate.h"
3233

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

36+
#if CIRCUITPY_WATCHDOG
37+
#include "shared-bindings/watchdog/__init__.h"
38+
#define WATCHDOG_EXCEPTION_CHECK() (MP_STATE_VM(mp_pending_exception) == &mp_watchdog_timeout_exception)
39+
#else
40+
#define WATCHDOG_EXCEPTION_CHECK() 0
41+
#endif
42+
3543
int mp_hal_stdin_rx_chr(void) {
3644
for (;;) {
3745
#ifdef MICROPY_VM_HOOK_LOOP
3846
MICROPY_VM_HOOK_LOOP
3947
#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+
}
4058
if (serial_bytes_available()) {
4159
toggle_rx_led();
4260
return serial_read();

0 commit comments

Comments
 (0)