Skip to content

Commit 2e0a109

Browse files
authored
Merge pull request #3318 from jepler/interrupt-serial-rx
supervisor: check for interrupt during rx_chr
2 parents 78c512e + c0753c1 commit 2e0a109

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

lib/utils/pyexec.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
113113
start = mp_hal_ticks_ms();
114114
mp_call_function_0(module_fun);
115115
mp_hal_set_interrupt_char(-1); // disable interrupt
116+
// Handle any ctrl-c interrupt that arrived just in time
117+
mp_handle_pending();
116118
nlr_pop();
117119
ret = 0;
118120
if (exec_flags & EXEC_FLAG_PRINT_EOF) {

py/obj.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
6767
#ifdef RUN_BACKGROUND_TASKS
6868
RUN_BACKGROUND_TASKS;
6969
#endif
70+
mp_handle_pending();
71+
7072
#ifndef NDEBUG
7173
if (o_in == MP_OBJ_NULL) {
7274
mp_print_str(print, "(nil)");

supervisor/shared/micropython.c

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

3335
#include "supervisor/shared/status_leds.h"
3436

37+
#if CIRCUITPY_WATCHDOG
38+
#include "shared-bindings/watchdog/__init__.h"
39+
#define WATCHDOG_EXCEPTION_CHECK() (MP_STATE_VM(mp_pending_exception) == &mp_watchdog_timeout_exception)
40+
#else
41+
#define WATCHDOG_EXCEPTION_CHECK() 0
42+
#endif
43+
3544
int mp_hal_stdin_rx_chr(void) {
3645
for (;;) {
3746
#ifdef MICROPY_VM_HOOK_LOOP
3847
MICROPY_VM_HOOK_LOOP
3948
#endif
49+
mp_handle_pending();
4050
if (serial_bytes_available()) {
4151
toggle_rx_led();
4252
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)