From 314a22e50db69245015dde5e99e769042e5a7642 Mon Sep 17 00:00:00 2001 From: schneider Date: Fri, 31 Jan 2020 13:48:15 +0100 Subject: [PATCH 1/2] fix(interrupts): Add the callbacks to the list of root pointers --- pycardium/main.c | 5 +++++ pycardium/modules/interrupt.c | 20 +++++++++++--------- pycardium/modules/interrupt.h | 2 ++ pycardium/mpconfigport.h | 7 ++++++- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pycardium/main.c b/pycardium/main.c index b87b4a1e..3aec0491 100644 --- a/pycardium/main.c +++ b/pycardium/main.c @@ -2,10 +2,12 @@ #include "api/caller.h" #include "mphalport.h" #include "card10-version.h" +#include "modules/interrupt.h" #include "max32665.h" #include "lib/utils/pyexec.h" +#include "lib/mp-readline/readline.h" #include "py/gc.h" #include "py/runtime.h" #include "py/stackctrl.h" @@ -45,6 +47,9 @@ int main(void) mp_init(); + readline_init0(); + interrupt_init0(); + /* request by badge.team */ mp_obj_list_init(mp_sys_path, 0); mp_obj_list_append(mp_sys_path, MP_ROM_QSTR(MP_QSTR_)); diff --git a/pycardium/modules/interrupt.c b/pycardium/modules/interrupt.c index 9e2058e5..65e3ce63 100644 --- a/pycardium/modules/interrupt.c +++ b/pycardium/modules/interrupt.c @@ -7,20 +7,22 @@ #include "py/obj.h" #include "py/runtime.h" -// TODO: these should be intialized as mp_const_none -mp_obj_t callbacks[EPIC_INT_NUM] = { - 0, -}; +void interrupt_init0(void) +{ + int id; + for (id = 0; id < EPIC_INT_NUM; id++) { + MP_STATE_PORT(interrupt_callbacks)[id] = NULL; + } +} void epic_isr_default_handler(api_int_id_t id) { // TODO: check if id is out of rante // TOOD: check against mp_const_none + mp_obj_t callback = MP_STATE_PORT(interrupt_callbacks)[id]; if (id < EPIC_INT_NUM) { - if (callbacks[id]) { - mp_sched_schedule( - callbacks[id], MP_OBJ_NEW_SMALL_INT(id) - ); + if (callback) { + mp_sched_schedule(callback, MP_OBJ_NEW_SMALL_INT(id)); } } } @@ -35,7 +37,7 @@ mp_obj_t mp_interrupt_set_callback(mp_obj_t id_in, mp_obj_t callback_obj) // TODO: throw error if id is out of range if (id < EPIC_INT_NUM) { - callbacks[id] = callback_obj; + MP_STATE_PORT(interrupt_callbacks)[id] = callback_obj; } return mp_const_none; diff --git a/pycardium/modules/interrupt.h b/pycardium/modules/interrupt.h index 3588d1e0..ef931034 100644 --- a/pycardium/modules/interrupt.h +++ b/pycardium/modules/interrupt.h @@ -2,6 +2,8 @@ #include "py/obj.h" +void interrupt_init0(void); + mp_obj_t mp_interrupt_set_callback(mp_obj_t id_in, mp_obj_t callback_obj); mp_obj_t mp_interrupt_enable_callback(mp_obj_t id_in); mp_obj_t mp_interrupt_disable_callback(mp_obj_t id_in); diff --git a/pycardium/mpconfigport.h b/pycardium/mpconfigport.h index 242c6a52..359bf799 100644 --- a/pycardium/mpconfigport.h +++ b/pycardium/mpconfigport.h @@ -1,3 +1,7 @@ +// TODO: we need this define, but the header is not found... +//#include "epicardium/epicardium.h" +#define EPIC_INT_NUM 9 + /* Hardware Name */ #define MICROPY_HW_BOARD_NAME "card10" #define MICROPY_HW_MCU_NAME "max32666" @@ -95,5 +99,6 @@ typedef long mp_off_t; /* For some reason, we need to define readline history manually */ #define MICROPY_PORT_ROOT_POINTERS \ - const char *readline_hist[16]; + const char *readline_hist[16]; \ + mp_obj_t interrupt_callbacks[EPIC_INT_NUM]; \ -- GitLab From 2afaf931240ba8f24f064af08065448b851b74fb Mon Sep 17 00:00:00 2001 From: schneider Date: Fri, 31 Jan 2020 17:41:49 +0100 Subject: [PATCH 2/2] fix(mpconfig): Remove hard coded value for interrupt numbers --- lib/micropython/gen-qstr.sh | 1 - pycardium/meson.build | 2 +- pycardium/mpconfigport.h | 10 ++++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/micropython/gen-qstr.sh b/lib/micropython/gen-qstr.sh index 78ecf851..747ae3f6 100755 --- a/lib/micropython/gen-qstr.sh +++ b/lib/micropython/gen-qstr.sh @@ -11,7 +11,6 @@ shift 5 OUTPUT_DIR="$(dirname "$OUTPUT")" - # call gcc -E to generate qstr.i.last gcc -E -DNO_QSTR -I"$SOURCE_DIR/micropython" -I"$PROJECT_SRC" -I"$OUTPUT_DIR" "$@" >"$OUTPUT_DIR/qstr.i.last" diff --git a/pycardium/meson.build b/pycardium/meson.build index aa637280..3007f7b0 100644 --- a/pycardium/meson.build +++ b/pycardium/meson.build @@ -79,7 +79,7 @@ upy = static_library( micropython_additional_sources, micropython_extmod_sources, mp_headers, - include_directories: micropython_includes, + include_directories: [micropython_includes, include_directories('../epicardium')], c_args: '-w', ) diff --git a/pycardium/mpconfigport.h b/pycardium/mpconfigport.h index 359bf799..03fd3d3f 100644 --- a/pycardium/mpconfigport.h +++ b/pycardium/mpconfigport.h @@ -1,7 +1,3 @@ -// TODO: we need this define, but the header is not found... -//#include "epicardium/epicardium.h" -#define EPIC_INT_NUM 9 - /* Hardware Name */ #define MICROPY_HW_BOARD_NAME "card10" #define MICROPY_HW_MCU_NAME "max32666" @@ -97,6 +93,12 @@ typedef long mp_off_t; /* TODO: Document this */ #define MP_STATE_PORT MP_STATE_VM +#ifndef NO_QSTR +#include "epicardium.h" +#else +#define EPIC_INT_NUM 1 +#endif + /* For some reason, we need to define readline history manually */ #define MICROPY_PORT_ROOT_POINTERS \ const char *readline_hist[16]; \ -- GitLab