py/scheduler: Add mp_sched_exception() to schedule a pending exception.
This helper is added to properly set a pending exception, to mirror mp_sched_schedule(), which schedules a function. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
7e549b6718
commit
7cbf826a95
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue