summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/pic16bit/board.c2
-rw-r--r--ports/stm32/pendsv.c4
-rw-r--r--ports/unix/unix_mphal.c2
-rw-r--r--ports/windows/windows_mphal.c2
-rw-r--r--py/mpstate.h3
-rw-r--r--py/scheduler.c4
6 files changed, 10 insertions, 7 deletions
diff --git a/ports/pic16bit/board.c b/ports/pic16bit/board.c
index b0e9d1727..8cc2e88f3 100644
--- a/ports/pic16bit/board.c
+++ b/ports/pic16bit/board.c
@@ -140,7 +140,7 @@ int switch_get(int sw) {
// TODO need an irq
void uart_rx_irq(void) {
if (c == interrupt_char) {
- MP_STATE_THREAD(mp_pending_exception) = MP_STATE_PORT(keyboard_interrupt_obj);
+ MP_STATE_MAIN_THREAD(mp_pending_exception) = MP_STATE_PORT(keyboard_interrupt_obj);
}
}
*/
diff --git a/ports/stm32/pendsv.c b/ports/stm32/pendsv.c
index 2887ac572..c5b2fcf92 100644
--- a/ports/stm32/pendsv.c
+++ b/ports/stm32/pendsv.c
@@ -60,10 +60,10 @@ void pendsv_init(void) {
// the given exception object using nlr_jump in the context of the top-level
// thread.
void pendsv_kbd_intr(void) {
- if (MP_STATE_THREAD(mp_pending_exception) == MP_OBJ_NULL) {
+ if (MP_STATE_MAIN_THREAD(mp_pending_exception) == MP_OBJ_NULL) {
mp_sched_keyboard_interrupt();
} else {
- MP_STATE_THREAD(mp_pending_exception) = MP_OBJ_NULL;
+ MP_STATE_MAIN_THREAD(mp_pending_exception) = MP_OBJ_NULL;
pendsv_object = &MP_STATE_VM(mp_kbd_exception);
SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
}
diff --git a/ports/unix/unix_mphal.c b/ports/unix/unix_mphal.c
index 111844abc..1d3c52bf1 100644
--- a/ports/unix/unix_mphal.c
+++ b/ports/unix/unix_mphal.c
@@ -54,7 +54,7 @@ STATIC void sighandler(int signum) {
sigprocmask(SIG_SETMASK, &mask, NULL);
nlr_raise(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)));
#else
- if (MP_STATE_THREAD(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))) {
+ if (MP_STATE_MAIN_THREAD(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))) {
// this is the second time we are called, so die straight away
exit(1);
}
diff --git a/ports/windows/windows_mphal.c b/ports/windows/windows_mphal.c
index ba1d982ad..7a3d881a3 100644
--- a/ports/windows/windows_mphal.c
+++ b/ports/windows/windows_mphal.c
@@ -80,7 +80,7 @@ void mp_hal_stdio_mode_orig(void) {
// the thread created for handling it might not be running yet so we'd miss the notification.
BOOL WINAPI console_sighandler(DWORD evt) {
if (evt == CTRL_C_EVENT) {
- if (MP_STATE_THREAD(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))) {
+ if (MP_STATE_MAIN_THREAD(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))) {
// this is the second time we are called, so die straight away
exit(1);
}
diff --git a/py/mpstate.h b/py/mpstate.h
index f5fb5b707..e42d13fb2 100644
--- a/py/mpstate.h
+++ b/py/mpstate.h
@@ -285,12 +285,13 @@ extern mp_state_ctx_t mp_state_ctx;
#define MP_STATE_VM(x) (mp_state_ctx.vm.x)
#define MP_STATE_MEM(x) (mp_state_ctx.mem.x)
+#define MP_STATE_MAIN_THREAD(x) (mp_state_ctx.thread.x)
#if MICROPY_PY_THREAD
extern mp_state_thread_t *mp_thread_get_state(void);
#define MP_STATE_THREAD(x) (mp_thread_get_state()->x)
#else
-#define MP_STATE_THREAD(x) (mp_state_ctx.thread.x)
+#define MP_STATE_THREAD(x) MP_STATE_MAIN_THREAD(x)
#endif
#endif // MICROPY_INCLUDED_PY_MPSTATE_H
diff --git a/py/scheduler.c b/py/scheduler.c
index 0114a7a58..bd0bbf207 100644
--- a/py/scheduler.c
+++ b/py/scheduler.c
@@ -28,8 +28,10 @@
#include "py/runtime.h"
+// Schedules an exception on the main thread (for exceptions "thrown" by async
+// sources such as interrupts and UNIX signal handlers).
void MICROPY_WRAP_MP_SCHED_EXCEPTION(mp_sched_exception)(mp_obj_t exc) {
- MP_STATE_THREAD(mp_pending_exception) = exc;
+ MP_STATE_MAIN_THREAD(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;