Commit 314a22e5 authored by schneider's avatar schneider
Browse files

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

parent 0fd6d958
...@@ -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_));
......
...@@ -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);
// TODO: we need this define, but the header is not found...
//#include "epicardium/epicardium.h"
#define EPIC_INT_NUM 9
/* Hardware Name */ /* Hardware Name */
#define MICROPY_HW_BOARD_NAME "card10" #define MICROPY_HW_BOARD_NAME "card10"
#define MICROPY_HW_MCU_NAME "max32666" #define MICROPY_HW_MCU_NAME "max32666"
...@@ -95,5 +99,6 @@ typedef long mp_off_t; ...@@ -95,5 +99,6 @@ typedef long mp_off_t;
/* 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