summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/esp32/mpconfigport.h1
-rw-r--r--ports/esp8266/mpconfigport.h1
-rw-r--r--py/mpconfig.h4
-rw-r--r--py/runtime.h1
-rw-r--r--py/scheduler.c14
5 files changed, 16 insertions, 5 deletions
diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h
index 8788963cb..0c7d42210 100644
--- a/ports/esp32/mpconfigport.h
+++ b/ports/esp32/mpconfigport.h
@@ -264,6 +264,7 @@ void *esp_native_code_commit(void *, size_t, void *);
#endif
// Functions that should go in IRAM
+#define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) IRAM_ATTR f
#define MICROPY_WRAP_MP_KEYBOARD_INTERRUPT(f) IRAM_ATTR f
#define UINT_FMT "%u"
diff --git a/ports/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h
index 2c56b4188..52028e833 100644
--- a/ports/esp8266/mpconfigport.h
+++ b/ports/esp8266/mpconfigport.h
@@ -195,6 +195,7 @@ extern const struct _mp_obj_module_t mp_module_onewire;
#define MICROPY_PY_SYS_PLATFORM "esp8266"
#define MP_FASTCODE(n) __attribute__((section(".iram0.text." #n))) n
+#define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) MP_FASTCODE(f)
#define MICROPY_WRAP_MP_KEYBOARD_INTERRUPT(f) MP_FASTCODE(f)
#define MICROPY_WRAP_MP_SCHED_SCHEDULE(f) MP_FASTCODE(f)
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 5c7212fd1..2934f8ec8 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -1504,6 +1504,10 @@ typedef double mp_float_t;
/*****************************************************************************/
/* Hooks for a port to wrap functions with attributes */
+#ifndef MICROPY_WRAP_MP_SCHED_EXCEPTION
+#define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) f
+#endif
+
#ifndef MICROPY_WRAP_MP_KEYBOARD_INTERRUPT
#define MICROPY_WRAP_MP_KEYBOARD_INTERRUPT(f) f
#endif
diff --git a/py/runtime.h b/py/runtime.h
index 0cbbb287a..9ad4bc024 100644
--- a/py/runtime.h
+++ b/py/runtime.h
@@ -64,6 +64,7 @@ extern const byte mp_binary_op_method_name[];
void mp_init(void);
void mp_deinit(void);
+void mp_sched_exception(mp_obj_t exc);
void mp_keyboard_interrupt(void);
void mp_handle_pending(bool raise_exc);
void mp_handle_pending_tail(mp_uint_t atomic_state);
diff --git a/py/scheduler.c b/py/scheduler.c
index 6b138a631..f37f8c3f8 100644
--- a/py/scheduler.c
+++ b/py/scheduler.c
@@ -28,17 +28,21 @@
#include "py/runtime.h"
-#if MICROPY_KBD_EXCEPTION
-// This function may be called asynchronously at any time so only do the bare minimum.
-void MICROPY_WRAP_MP_KEYBOARD_INTERRUPT(mp_keyboard_interrupt)(void) {
- MP_STATE_VM(mp_kbd_exception).traceback_data = NULL;
- MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception));
+void mp_sched_exception(mp_obj_t exc) {
+ MP_STATE_VM(mp_pending_exception) = exc;
#if MICROPY_ENABLE_SCHEDULER
if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) {
MP_STATE_VM(sched_state) = MP_SCHED_PENDING;
}
#endif
}
+
+#if MICROPY_KBD_EXCEPTION
+// This function may be called asynchronously at any time so only do the bare minimum.
+void MICROPY_WRAP_MP_KEYBOARD_INTERRUPT(mp_keyboard_interrupt)(void) {
+ MP_STATE_VM(mp_kbd_exception).traceback_data = NULL;
+ mp_sched_exception(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)));
+}
#endif
#if MICROPY_ENABLE_SCHEDULER