Skip to content
Snippets Groups Projects
Commit b6a2a86a authored by schneider's avatar schneider
Browse files

fix(interrupt): add disable function, add error code to api

parent b457c4b6
No related branches found
No related tags found
1 merge request!18Python interrupts
Pipeline #1358 passed
......@@ -4,16 +4,19 @@
static bool enabled[API_INT_MAX + 1];
void api_interrupt_trigger(api_int_id_t id)
int api_interrupt_trigger(api_int_id_t id)
{
if (id <= API_INT_MAX) {
if (enabled[id]) {
while (API_CALL_MEM->int_id)
;
API_CALL_MEM->int_id = id;
TMR_TO_Start(MXC_TMR5, 1, 0);
}
if (id > API_INT_MAX) {
return EINVAL;
}
if (enabled[id]) {
while (API_CALL_MEM->int_id)
;
API_CALL_MEM->int_id = id;
TMR_TO_Start(MXC_TMR5, 1, 0);
}
return 0;
}
void api_interrupt_init(void)
......@@ -26,16 +29,22 @@ void api_interrupt_init(void)
}
}
void epic_interrupt_enable(api_int_id_t int_id)
int epic_interrupt_enable(api_int_id_t int_id)
{
if (int_id <= API_INT_MAX) {
enabled[int_id] = true;
if (int_id > API_INT_MAX) {
return EINVAL;
}
enabled[int_id] = true;
return 0;
}
void epic_interrupt_disable(api_int_id_t int_id)
int epic_interrupt_disable(api_int_id_t int_id)
{
if (int_id <= API_INT_MAX) {
enabled[int_id] = false;
if (int_id > API_INT_MAX) {
return EINVAL;
}
enabled[int_id] = false;
return 0;
}
#pragma once
#include "api/common.h"
void api_interrupt_init(void);
void api_interrupt_trigger(api_int_id_t id);
int api_interrupt_trigger(api_int_id_t id);
......@@ -156,13 +156,13 @@ typedef uint32_t api_int_id_t;
*
* :param int_id: The interrupt to be enabled
*/
API(API_INTERRUPT_ENABLE, void epic_interrupt_enable(api_int_id_t int_id));
API(API_INTERRUPT_ENABLE, int epic_interrupt_enable(api_int_id_t int_id));
/**
* Disable/mask an API interrupt
*
* :param int_id: The interrupt to be disabled
*/
API(API_INTERRUPT_DISABLE, void epic_interrupt_disable(api_int_id_t int_id));
API(API_INTERRUPT_DISABLE, int epic_interrupt_disable(api_int_id_t int_id));
#endif /* _EPICARDIUM_H */
......@@ -44,17 +44,33 @@ STATIC mp_obj_t mp_interrupt_enable_callback(mp_obj_t id_in)
api_int_id_t id = mp_obj_get_int(id_in);
// TODO: throw error if id is out of range or epic_interrupt_enable failed
epic_interrupt_enable(id);
if (epic_interrupt_enable(id) < 0) {
}
return mp_const_none;
}
STATIC mp_obj_t mp_interrupt_disable_callback(mp_obj_t id_in)
{
api_int_id_t id = mp_obj_get_int(id_in);
// TODO: throw error if id is out of range or epic_interrupt_enable failed
if (epic_interrupt_disable(id) < 0) {
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(
interrupt_set_callback_obj, mp_interrupt_set_callback
);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(
interrupt_enable_callback_obj, mp_interrupt_enable_callback
);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(
interrupt_disable_callback_obj, mp_interrupt_disable_callback
);
STATIC const mp_rom_map_elem_t interrupt_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_interrupt) },
......@@ -62,6 +78,8 @@ STATIC const mp_rom_map_elem_t interrupt_module_globals_table[] = {
MP_ROM_PTR(&interrupt_set_callback_obj) },
{ MP_ROM_QSTR(MP_QSTR_enable_callback),
MP_ROM_PTR(&interrupt_enable_callback_obj) },
{ MP_ROM_QSTR(MP_QSTR_disable_callback),
MP_ROM_PTR(&interrupt_disable_callback_obj) },
{ MP_ROM_QSTR(MP_QSTR_BHI160), MP_OBJ_NEW_SMALL_INT(2) },
};
STATIC MP_DEFINE_CONST_DICT(
......
......@@ -28,4 +28,5 @@ Q(vibrate)
Q(set_callback)
Q(enable_callback)
Q(disable_callback)
Q(BHI160)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment