diff --git a/epicardium/api/interrupt-receiver.c b/epicardium/api/interrupt-receiver.c index 87fa8c3522c6ee281ec4b83a65b7ed771aa9932d..95c5038d12ee10bdc53a087ea121a568bb44d86a 100644 --- a/epicardium/api/interrupt-receiver.c +++ b/epicardium/api/interrupt-receiver.c @@ -3,33 +3,33 @@ #include "api/common.h" #include "epicardium.h" -void api_interrupt_handler_ctrl_c (api_int_id_t id) __attribute__ ((weak, alias("api_interrupt_handler_default"))); -void api_interrupt_handler_bhi160 (api_int_id_t id) __attribute__ ((weak, alias("api_interrupt_handler_default"))); +void api_interrupt_handler_ctrl_c(api_int_id_t id) + __attribute__((weak, alias("api_interrupt_handler_default"))); +void api_interrupt_handler_bhi160(api_int_id_t id) + __attribute__((weak, alias("api_interrupt_handler_default"))); /* Timer Interrupt used for control char notification */ void TMR5_IRQHandler(void) { TMR_IntClear(MXC_TMR5); - switch(API_CALL_MEM->int_id) { - case API_INT_CTRL_C: - api_interrupt_handler_ctrl_c(API_CALL_MEM->int_id); - break; - case API_INT_BHI160: - api_interrupt_handler_bhi160(API_CALL_MEM->int_id); - break; - } + switch (API_CALL_MEM->int_id) { + case API_INT_CTRL_C: + api_interrupt_handler_ctrl_c(API_CALL_MEM->int_id); + break; + case API_INT_BHI160: + api_interrupt_handler_bhi160(API_CALL_MEM->int_id); + break; + } - API_CALL_MEM->int_id = 0; + API_CALL_MEM->int_id = 0; } -__attribute__((weak)) -void api_interrupt_handler_catch_all(api_int_id_t id) +__attribute__((weak)) void api_interrupt_handler_catch_all(api_int_id_t id) { } void api_interrupt_handler_default(api_int_id_t id) { - api_interrupt_handler_catch_all(id); + api_interrupt_handler_catch_all(id); } - diff --git a/epicardium/api/interrupt-sender.c b/epicardium/api/interrupt-sender.c index fb4cb1458b39b528c73dba550f19cfc74e0c6734..3714c2797f4e460485bb678b0a2b339d3d41f9ad 100644 --- a/epicardium/api/interrupt-sender.c +++ b/epicardium/api/interrupt-sender.c @@ -6,35 +6,36 @@ static bool enabled[API_INT_MAX + 1]; void 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) { + if (enabled[id]) { + while (API_CALL_MEM->int_id) + ; + API_CALL_MEM->int_id = id; + TMR_TO_Start(MXC_TMR5, 1, 0); + } + } } void api_interrupt_init(void) { - int i; - API_CALL_MEM->int_id = 0; + int i; + API_CALL_MEM->int_id = 0; - for(i=0; i <= API_INT_MAX; i++) { - enabled[i] = false; - } + for (i = 0; i <= API_INT_MAX; i++) { + enabled[i] = false; + } } void api_interrupt_enable(api_int_id_t int_id) { - if(int_id <= API_INT_MAX) { - enabled[int_id] = true; - } + if (int_id <= API_INT_MAX) { + enabled[int_id] = true; + } } void api_interrupt_disable(api_int_id_t int_id) { - if(int_id <= API_INT_MAX) { - enabled[int_id] = false; - } + if (int_id <= API_INT_MAX) { + enabled[int_id] = false; + } } diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 5d9af78e4801f116a97887a97431c8f8e89d7867..4a7cc404c3a0620a081c7b7aeec8076dd18fd7fd 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -2,6 +2,7 @@ #define _EPICARDIUM_H #include <stdint.h> +/* clang-format off */ #define API_INT_CTRL_C 1 #define API_INT_BHI160 2 #define API_INT_MAX API_INT_BHI160 @@ -10,7 +11,6 @@ #define API(id, def) def #endif -/* clang-format off */ #define API_UART_WRITE 0x1 #define API_UART_READ 0x2 #define API_LEDS_SET 0x3 diff --git a/epicardium/main.c b/epicardium/main.c index 94bcdd01d69890c705c9b02f47454a342b9265ea..6f91854ebbf1fa23bfcfbfb257f7744cafaa4deb 100644 --- a/epicardium/main.c +++ b/epicardium/main.c @@ -47,7 +47,7 @@ int main(void) cdcacm_init(); fatfs_init(); - api_interrupt_init(); + api_interrupt_init(); printf("=> Initializing tasks ...\n"); diff --git a/epicardium/modules/serial.c b/epicardium/modules/serial.c index aa46f233ce69a43f7831b34b907e72ced60ce47c..2ac1381274a68089ed4d7aad847768bbbe43d550 100644 --- a/epicardium/modules/serial.c +++ b/epicardium/modules/serial.c @@ -13,7 +13,6 @@ #include "epicardium.h" #include "api/interrupt-sender.h" - /* Task ID for the serial handler */ TaskHandle_t serial_task_id = NULL; @@ -58,13 +57,13 @@ static void enqueue_char(char chr) { if (chr == 0x3) { /* Control-C */ - api_interrupt_trigger(API_INT_CTRL_C); + api_interrupt_trigger(API_INT_CTRL_C); } - if (chr == 0x0e) { + if (chr == 0x0e) { /* Control-N */ - api_interrupt_trigger(API_INT_BHI160); - } + api_interrupt_trigger(API_INT_BHI160); + } if (xQueueSend(read_queue, &chr, 100) == errQUEUE_FULL) { /* Queue overran, wait a bit */ diff --git a/pycardium/modules/interrupt.c b/pycardium/modules/interrupt.c index 92bc3dcbb59de20c81ed60d534aa5e619a5a8e40..45ee55c383c63dabacbc911d303b8133fad9aa12 100644 --- a/pycardium/modules/interrupt.c +++ b/pycardium/modules/interrupt.c @@ -9,40 +9,46 @@ mp_obj_t bhi160_callback = NULL; static void interrupt_set(api_int_id_t id, mp_obj_t func) { - // TODO: maintain list of interrupts callbacks - if(id == API_INT_BHI160) { - bhi160_callback = func; - } + // TODO: maintain list of interrupts callbacks + if (id == API_INT_BHI160) { + bhi160_callback = func; + } } void api_interrupt_handler_catch_all(api_int_id_t id) { - // TODO: iterate over registered callbacks - if(id == API_INT_BHI160) { - if(bhi160_callback) { - mp_sched_schedule(bhi160_callback, MP_OBJ_NEW_SMALL_INT(0)); - } - } + // TODO: iterate over registered callbacks + if (id == API_INT_BHI160) { + if (bhi160_callback) { + mp_sched_schedule( + bhi160_callback, MP_OBJ_NEW_SMALL_INT(0) + ); + } + } } STATIC mp_obj_t mp_interrupt_set_callback(mp_obj_t id_in, mp_obj_t callback_obj) { - // TODO: check argument types + // TODO: check argument types api_int_id_t id = mp_obj_get_int(id_in); - interrupt_set(id, callback_obj); + interrupt_set(id, callback_obj); return mp_const_none; } STATIC mp_obj_t mp_interrupt_enable_callback(mp_obj_t id_in) { - // TODO: check argument types + // TODO: check argument types api_int_id_t id = mp_obj_get_int(id_in); - api_interrupt_enable(id); + api_interrupt_enable(id); 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_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 const mp_rom_map_elem_t interrupt_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_interrupt) }, @@ -50,7 +56,9 @@ STATIC const mp_rom_map_elem_t interrupt_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_enable_callback), MP_ROM_PTR(&interrupt_enable_callback_obj) }, { MP_ROM_QSTR(MP_QSTR_BHI160), MP_OBJ_NEW_SMALL_INT(2) }, }; -STATIC MP_DEFINE_CONST_DICT(interrupt_module_globals, interrupt_module_globals_table); +STATIC MP_DEFINE_CONST_DICT( + interrupt_module_globals, interrupt_module_globals_table +); // Define module object. const mp_obj_module_t interrupt_module = { @@ -58,5 +66,6 @@ const mp_obj_module_t interrupt_module = { .globals = (mp_obj_dict_t *)&interrupt_module_globals, }; +/* clang-format off */ // Register the module to make it available in Python MP_REGISTER_MODULE(MP_QSTR_interrupt, interrupt_module, MODULE_INTERRUPT_ENABLED); diff --git a/pycardium/mphalport.c b/pycardium/mphalport.c index 0dedf72c5fef883f93d82e28c366c72688c33379..b950f85fbeadd925ade6a0fe46576a4104d81b0c 100644 --- a/pycardium/mphalport.c +++ b/pycardium/mphalport.c @@ -64,13 +64,13 @@ long _write(int fd, const char *buf, size_t cnt) void api_interrupt_handler_ctrl_c(void) { - /* Taken from lib/micropython/micropython/lib/utils/interrupt_char.c */ - MP_STATE_VM(mp_pending_exception) = - MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)); + /* Taken from lib/micropython/micropython/lib/utils/interrupt_char.c */ + MP_STATE_VM(mp_pending_exception) = + MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)); #if MICROPY_ENABLE_SCHEDULER - if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) { - MP_STATE_VM(sched_state) = MP_SCHED_PENDING; - } + if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) { + MP_STATE_VM(sched_state) = MP_SCHED_PENDING; + } #endif } @@ -82,11 +82,11 @@ void mp_hal_set_interrupt_char(char c) ); } - if(c == 0x03) { - api_interrupt_enable(API_INT_CTRL_C); - } else { - api_interrupt_disable(API_INT_CTRL_C); - } + if (c == 0x03) { + api_interrupt_enable(API_INT_CTRL_C); + } else { + api_interrupt_disable(API_INT_CTRL_C); + } } /****************************************************************************** @@ -135,7 +135,7 @@ mp_import_stat_t mp_import_stat(const char *path) mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { /* TODO: Once fs is implemented, get this working as well */ - mp_raise_NotImplementedError ("FS is not yet implemented"); + mp_raise_NotImplementedError("FS is not yet implemented"); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);