Skip to content

Commit fb9e4cf

Browse files
author
Daniel Campora
committed
cc3200: Make sure to handle all pending pin interrupts.
When entering the interrupt handler of a given GPIO port, more than one pin could have pending interrupts, therefore care must be taken to service each interrupt one by one before leaving.
1 parent 8e611e8 commit fb9e4cf

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

cc3200/mods/pybpin.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,6 @@ STATIC const mp_map_elem_t pin_locals_dict_table[] = {
712712
{ MP_OBJ_NEW_QSTR(MP_QSTR_INT_RISING_FALLING), MP_OBJ_NEW_SMALL_INT(GPIO_BOTH_EDGES) },
713713
{ MP_OBJ_NEW_QSTR(MP_QSTR_INT_LOW_LEVEL), MP_OBJ_NEW_SMALL_INT(GPIO_LOW_LEVEL) },
714714
{ MP_OBJ_NEW_QSTR(MP_QSTR_INT_HIGH_LEVEL), MP_OBJ_NEW_SMALL_INT(GPIO_HIGH_LEVEL) },
715-
716715
{ MP_OBJ_NEW_QSTR(MP_QSTR_S2MA), MP_OBJ_NEW_SMALL_INT(PIN_STRENGTH_2MA) },
717716
{ MP_OBJ_NEW_QSTR(MP_QSTR_S4MA), MP_OBJ_NEW_SMALL_INT(PIN_STRENGTH_4MA) },
718717
{ MP_OBJ_NEW_QSTR(MP_QSTR_S6MA), MP_OBJ_NEW_SMALL_INT(PIN_STRENGTH_6MA) },
@@ -752,12 +751,18 @@ STATIC void GPIOA3IntHandler (void) {
752751

753752
// common interrupt handler
754753
STATIC void EXTI_Handler(uint port) {
755-
uint32_t bit = MAP_GPIOIntStatus(port, true);
756-
MAP_GPIOIntClear(port, bit);
757-
758-
// TODO: loop through all the active bits before exiting
759-
pin_obj_t *self = (pin_obj_t *)pin_find_pin_by_port_bit(&pin_cpu_pins_locals_dict, port, bit);
760-
mp_obj_t _callback = mpcallback_find(self);
761-
mpcallback_handler(_callback);
754+
uint32_t bits = MAP_GPIOIntStatus(port, true);
755+
MAP_GPIOIntClear(port, bits);
756+
757+
// might be that we have more than one Pin interrupt triggered at the same time
758+
// therefore we must loop through all the 8 possible bits
759+
for (int i = 0; i < 8; i++) {
760+
uint32_t bit = (1 << i);
761+
if (bit & bits) {
762+
pin_obj_t *self = (pin_obj_t *)pin_find_pin_by_port_bit(&pin_cpu_pins_locals_dict, port, bit);
763+
mp_obj_t _callback = mpcallback_find(self);
764+
mpcallback_handler(_callback);
765+
}
766+
}
762767
}
763768

0 commit comments

Comments
 (0)