From 92b1cb574320578abe022c021c4b1891cfafbae6 Mon Sep 17 00:00:00 2001 From: Roy Hooper Date: Mon, 14 May 2018 17:41:17 -0400 Subject: [PATCH] move reload exception to reload.c --- py/py.mk | 1 + py/reload.c | 16 ++++++++++++++++ py/reload.h | 10 ++++++++++ shared-bindings/supervisor/__init__.c | 9 ++------- 4 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 py/reload.c create mode 100644 py/reload.h diff --git a/py/py.mk b/py/py.mk index 21f81c35d5..e934c3a83f 100644 --- a/py/py.mk +++ b/py/py.mk @@ -188,6 +188,7 @@ PY_O_BASENAME = \ objtype.o \ objzip.o \ opmethods.o \ + reload.o \ sequence.o \ stream.o \ binary.o \ diff --git a/py/reload.c b/py/reload.c new file mode 100644 index 0000000000..95305f2c9c --- /dev/null +++ b/py/reload.c @@ -0,0 +1,16 @@ +// +// Created by Roy Hooper on 2018-05-14. +// + +#include "reload.h" +#include "py/mpstate.h" + +void mp_raise_reload_exception(void) { + MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception)); +#if MICROPY_ENABLE_SCHEDULER + if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) { + MP_STATE_VM(sched_state) = MP_SCHED_PENDING; + } +#endif + +} diff --git a/py/reload.h b/py/reload.h new file mode 100644 index 0000000000..72e84e5ca6 --- /dev/null +++ b/py/reload.h @@ -0,0 +1,10 @@ +// +// Created by Roy Hooper on 2018-05-14. +// + +#ifndef CIRCUITPYTHON_RELOAD_H +#define CIRCUITPYTHON_RELOAD_H + +void mp_raise_reload_exception(void); + +#endif //CIRCUITPYTHON_RELOAD_H diff --git a/shared-bindings/supervisor/__init__.c b/shared-bindings/supervisor/__init__.c index 4eae404060..b2b0c80d96 100644 --- a/shared-bindings/supervisor/__init__.c +++ b/shared-bindings/supervisor/__init__.c @@ -25,6 +25,7 @@ */ #include "py/obj.h" #include "py/runtime.h" + #include "py/reload.h" #include "lib/utils/interrupt_char.h" #include "supervisor/shared/autoreload.h" @@ -101,13 +102,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(supervisor_set_rgb_status_brightness_obj, supervisor_s //| STATIC mp_obj_t supervisor_reload(void) { reload_requested = true; - - MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception)); - #if MICROPY_ENABLE_SCHEDULER - if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) { - MP_STATE_VM(sched_state) = MP_SCHED_PENDING; - } - #endif + mp_raise_reload_exception(); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(supervisor_reload_obj, supervisor_reload);