Merge pull request #3318 from jepler/interrupt-serial-rx

supervisor: check for interrupt during rx_chr
This commit is contained in:
Jeff Epler 2020-08-25 21:01:33 -05:00 committed by GitHub
commit 2e0a109331
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 11 deletions

View File

@ -113,6 +113,8 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
start = mp_hal_ticks_ms(); start = mp_hal_ticks_ms();
mp_call_function_0(module_fun); mp_call_function_0(module_fun);
mp_hal_set_interrupt_char(-1); // disable interrupt mp_hal_set_interrupt_char(-1); // disable interrupt
// Handle any ctrl-c interrupt that arrived just in time
mp_handle_pending();
nlr_pop(); nlr_pop();
ret = 0; ret = 0;
if (exec_flags & EXEC_FLAG_PRINT_EOF) { if (exec_flags & EXEC_FLAG_PRINT_EOF) {

View File

@ -67,6 +67,8 @@ void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
#ifdef RUN_BACKGROUND_TASKS #ifdef RUN_BACKGROUND_TASKS
RUN_BACKGROUND_TASKS; RUN_BACKGROUND_TASKS;
#endif #endif
mp_handle_pending();
#ifndef NDEBUG #ifndef NDEBUG
if (o_in == MP_OBJ_NULL) { if (o_in == MP_OBJ_NULL) {
mp_print_str(print, "(nil)"); mp_print_str(print, "(nil)");

View File

@ -29,14 +29,24 @@
#include "supervisor/serial.h" #include "supervisor/serial.h"
#include "lib/oofatfs/ff.h" #include "lib/oofatfs/ff.h"
#include "py/mpconfig.h" #include "py/mpconfig.h"
#include "py/mpstate.h"
#include "py/runtime.h"
#include "supervisor/shared/status_leds.h" #include "supervisor/shared/status_leds.h"
#if CIRCUITPY_WATCHDOG
#include "shared-bindings/watchdog/__init__.h"
#define WATCHDOG_EXCEPTION_CHECK() (MP_STATE_VM(mp_pending_exception) == &mp_watchdog_timeout_exception)
#else
#define WATCHDOG_EXCEPTION_CHECK() 0
#endif
int mp_hal_stdin_rx_chr(void) { int mp_hal_stdin_rx_chr(void) {
for (;;) { for (;;) {
#ifdef MICROPY_VM_HOOK_LOOP #ifdef MICROPY_VM_HOOK_LOOP
MICROPY_VM_HOOK_LOOP MICROPY_VM_HOOK_LOOP
#endif #endif
mp_handle_pending();
if (serial_bytes_available()) { if (serial_bytes_available()) {
toggle_rx_led(); toggle_rx_led();
return serial_read(); return serial_read();

View File

@ -27,6 +27,7 @@
#include "supervisor/shared/tick.h" #include "supervisor/shared/tick.h"
#include "py/mpstate.h" #include "py/mpstate.h"
#include "py/runtime.h"
#include "supervisor/linker.h" #include "supervisor/linker.h"
#include "supervisor/filesystem.h" #include "supervisor/filesystem.h"
#include "supervisor/background_callback.h" #include "supervisor/background_callback.h"
@ -149,17 +150,7 @@ void mp_hal_delay_ms(mp_uint_t delay) {
while (remaining > 0) { while (remaining > 0) {
RUN_BACKGROUND_TASKS; RUN_BACKGROUND_TASKS;
// Check to see if we've been CTRL-Ced by autoreload or the user. // 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_handle_pending();
{
// clear exception and generate stacktrace
MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL;
nlr_raise(&MP_STATE_VM(mp_kbd_exception));
}
if( MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception)) ||
WATCHDOG_EXCEPTION_CHECK()) {
// stop sleeping immediately
break;
}
remaining = end_tick - port_get_raw_ticks(NULL); remaining = end_tick - port_get_raw_ticks(NULL);
// We break a bit early so we don't risk setting the alarm before the time when we call // We break a bit early so we don't risk setting the alarm before the time when we call
// sleep. // sleep.