Commit bfbc4215 authored by schneider's avatar schneider
Browse files

Merge branch 'schneider/mpy-portstate' into 'master'

fix(interrupts): Add the callbacks to the list of root pointers

See merge request card10/firmware!374
parents 0fd6d958 2afaf931
...@@ -11,7 +11,6 @@ shift 5 ...@@ -11,7 +11,6 @@ shift 5
OUTPUT_DIR="$(dirname "$OUTPUT")" OUTPUT_DIR="$(dirname "$OUTPUT")"
# call gcc -E to generate qstr.i.last # 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" gcc -E -DNO_QSTR -I"$SOURCE_DIR/micropython" -I"$PROJECT_SRC" -I"$OUTPUT_DIR" "$@" >"$OUTPUT_DIR/qstr.i.last"
......
...@@ -2,10 +2,12 @@ ...@@ -2,10 +2,12 @@
#include "api/caller.h" #include "api/caller.h"
#include "mphalport.h" #include "mphalport.h"
#include "card10-version.h" #include "card10-version.h"
#include "modules/interrupt.h"
#include "max32665.h" #include "max32665.h"
#include "lib/utils/pyexec.h" #include "lib/utils/pyexec.h"
#include "lib/mp-readline/readline.h"
#include "py/gc.h" #include "py/gc.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/stackctrl.h" #include "py/stackctrl.h"
...@@ -45,6 +47,9 @@ int main(void) ...@@ -45,6 +47,9 @@ int main(void)
mp_init(); mp_init();
readline_init0();
interrupt_init0();
/* request by badge.team */ /* request by badge.team */
mp_obj_list_init(mp_sys_path, 0); mp_obj_list_init(mp_sys_path, 0);
mp_obj_list_append(mp_sys_path, MP_ROM_QSTR(MP_QSTR_)); mp_obj_list_append(mp_sys_path, MP_ROM_QSTR(MP_QSTR_));
......
...@@ -79,7 +79,7 @@ upy = static_library( ...@@ -79,7 +79,7 @@ upy = static_library(
micropython_additional_sources, micropython_additional_sources,
micropython_extmod_sources, micropython_extmod_sources,
mp_headers, mp_headers,
include_directories: micropython_includes, include_directories: [micropython_includes, include_directories('../epicardium')],
c_args: '-w', c_args: '-w',
) )
......
...@@ -7,20 +7,22 @@ ...@@ -7,20 +7,22 @@
#include "py/obj.h" #include "py/obj.h"
#include "py/runtime.h" #include "py/runtime.h"
// TODO: these should be intialized as mp_const_none void interrupt_init0(void)
mp_obj_t callbacks[EPIC_INT_NUM] = { {
0, 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) void epic_isr_default_handler(api_int_id_t id)
{ {
// TODO: check if id is out of rante // TODO: check if id is out of rante
// TOOD: check against mp_const_none // TOOD: check against mp_const_none
mp_obj_t callback = MP_STATE_PORT(interrupt_callbacks)[id];
if (id < EPIC_INT_NUM) { if (id < EPIC_INT_NUM) {
if (callbacks[id]) { if (callback) {
mp_sched_schedule( mp_sched_schedule(callback, MP_OBJ_NEW_SMALL_INT(id));
callbacks[id], 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) ...@@ -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 // TODO: throw error if id is out of range
if (id < EPIC_INT_NUM) { if (id < EPIC_INT_NUM) {
callbacks[id] = callback_obj; MP_STATE_PORT(interrupt_callbacks)[id] = callback_obj;
} }
return mp_const_none; return mp_const_none;
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#include "py/obj.h" #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_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_enable_callback(mp_obj_t id_in);
mp_obj_t mp_interrupt_disable_callback(mp_obj_t id_in); mp_obj_t mp_interrupt_disable_callback(mp_obj_t id_in);
...@@ -93,7 +93,14 @@ typedef long mp_off_t; ...@@ -93,7 +93,14 @@ typedef long mp_off_t;
/* TODO: Document this */ /* TODO: Document this */
#define MP_STATE_PORT MP_STATE_VM #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 */ /* For some reason, we need to define readline history manually */
#define MICROPY_PORT_ROOT_POINTERS \ #define MICROPY_PORT_ROOT_POINTERS \
const char *readline_hist[16]; const char *readline_hist[16]; \
mp_obj_t interrupt_callbacks[EPIC_INT_NUM]; \
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment