2014-03-15 02:41:28 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <stm32f4xx_hal.h>
|
|
|
|
|
2014-04-08 10:21:26 -04:00
|
|
|
#include "nlr.h"
|
2014-03-15 02:41:28 -04:00
|
|
|
#include "misc.h"
|
|
|
|
#include "mpconfig.h"
|
|
|
|
#include "qstr.h"
|
2014-04-08 10:21:26 -04:00
|
|
|
#include "gc.h"
|
2014-03-15 02:41:28 -04:00
|
|
|
#include "obj.h"
|
|
|
|
#include "runtime.h"
|
|
|
|
|
|
|
|
#include "pin.h"
|
2014-04-18 17:38:09 -04:00
|
|
|
#include "extint.h"
|
2014-03-15 02:41:28 -04:00
|
|
|
|
|
|
|
// Usage Model:
|
|
|
|
//
|
|
|
|
// There are a total of 22 interrupt lines. 16 of these can come from GPIO pins
|
|
|
|
// and the remaining 6 are from internal sources.
|
|
|
|
//
|
|
|
|
// For lines 0 thru 15, a given line can map to the corresponding line from an
|
|
|
|
// arbitrary port. So line 0 can map to Px0 where x is A, B, C, ... and
|
|
|
|
// line 1 can map to Px1 where x is A, B, C, ...
|
|
|
|
//
|
|
|
|
// def callback(line):
|
|
|
|
// print("line =", line)
|
|
|
|
//
|
2014-04-18 17:38:09 -04:00
|
|
|
// # Note: ExtInt will automatically configure the gpio line as an input.
|
|
|
|
// extint = pyb.ExtInt(pin, pyb.ExtInt.MODE_IRQ_FALLING, pyb.GPIO.PULL_UP, callback)
|
2014-03-15 02:41:28 -04:00
|
|
|
//
|
|
|
|
// Now every time a falling edge is seen on the X1 pin, the callback will be
|
|
|
|
// called. Caution: mechanical pushbuttons have "bounce" and pushing or
|
|
|
|
// releasing a switch will often generate multiple edges.
|
|
|
|
// See: http://www.eng.utah.edu/~cs5780/debouncing.pdf for a detailed
|
|
|
|
// explanation, along with various techniques for debouncing.
|
|
|
|
//
|
|
|
|
// Trying to register 2 callbacks onto the same pin will throw an exception.
|
|
|
|
//
|
|
|
|
// If pin is passed as an integer, then it is assumed to map to one of the
|
|
|
|
// internal interrupt sources, and must be in the range 16 thru 22.
|
|
|
|
//
|
|
|
|
// All other pin objects go through the pin mapper to come up with one of the
|
|
|
|
// gpio pins.
|
|
|
|
//
|
2014-04-18 17:38:09 -04:00
|
|
|
// extint = pyb.ExtInt(pin, mode, pull, callback)
|
2014-03-15 02:41:28 -04:00
|
|
|
//
|
2014-04-18 17:38:09 -04:00
|
|
|
// Valid modes are pyb.ExtInt.MODE_IRQ_RISING, pyb.ExtInt.MODE_IRQ_FALLING,
|
|
|
|
// pyb.ExtInt.MODE_IRQ_RISING_FALLING, pyb.ExtInt.MODE_EVT_RISING,
|
|
|
|
// pyb.ExtInt.MODE_EVT_FALLING, and pyb.ExtInt.MODE_EVT_RISING_FALLING.
|
2014-03-15 02:41:28 -04:00
|
|
|
//
|
2014-04-18 17:38:09 -04:00
|
|
|
// Only the MODE_IRQ_xxx modes have been tested. The MODE_EVT_xxx modes have
|
|
|
|
// something to do with sleep mode and the WFE instruction.
|
2014-03-15 02:41:28 -04:00
|
|
|
//
|
2014-04-18 17:38:09 -04:00
|
|
|
// Valid pull values are pyb.GPIO.PULL_UP, pyb.GPIO.PULL_DOWN, pyb.GPIO.PULL_NONE.
|
2014-03-15 02:41:28 -04:00
|
|
|
//
|
2014-04-18 17:38:09 -04:00
|
|
|
// extint.line() will return the line number that pin was mapped to.
|
|
|
|
// extint.disable() can be use to disable the interrupt associated with a given
|
|
|
|
// exti object. This could be useful for debouncing.
|
|
|
|
// extint.enable() enables a disabled interrupt
|
|
|
|
// extint.swint() will allow the callback to be triggered from software.
|
2014-03-15 02:41:28 -04:00
|
|
|
//
|
2014-04-18 17:38:09 -04:00
|
|
|
// pyb.ExtInt.regs() will dump the values of the EXTI registers.
|
2014-03-15 02:41:28 -04:00
|
|
|
//
|
|
|
|
// There is also a C API, so that drivers which require EXTI interrupt lines
|
2014-04-18 17:38:09 -04:00
|
|
|
// can also use this code. See extint.h for the available functions and
|
2014-03-15 02:41:28 -04:00
|
|
|
// usrsw.h for an example of using this.
|
2014-03-28 21:24:44 -04:00
|
|
|
//
|
|
|
|
// TODO Add python method to change callback object.
|
2014-03-15 02:41:28 -04:00
|
|
|
|
|
|
|
#define EXTI_OFFSET (EXTI_BASE - PERIPH_BASE)
|
|
|
|
|
|
|
|
// Macro used to set/clear the bit corresponding to the line in the IMR/EMR
|
|
|
|
// register in an atomic fashion by using bitband addressing.
|
|
|
|
#define EXTI_MODE_BB(mode, line) (*(__IO uint32_t *)(PERIPH_BB_BASE + ((EXTI_OFFSET + (mode)) * 32) + ((line) * 4)))
|
|
|
|
|
|
|
|
#define EXTI_Mode_Interrupt offsetof(EXTI_TypeDef, IMR)
|
|
|
|
#define EXTI_Mode_Event offsetof(EXTI_TypeDef, EMR)
|
|
|
|
|
|
|
|
#define EXTI_SWIER_BB(line) (*(__IO uint32_t *)(PERIPH_BB_BASE + ((EXTI_OFFSET + offsetof(EXTI_TypeDef, SWIER)) * 32) + ((line) * 4)))
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
mp_obj_base_t base;
|
|
|
|
mp_small_int_t line;
|
2014-04-18 17:38:09 -04:00
|
|
|
} extint_obj_t;
|
2014-03-15 02:41:28 -04:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
mp_obj_t callback_obj;
|
|
|
|
void *param;
|
|
|
|
uint32_t mode;
|
2014-04-18 17:38:09 -04:00
|
|
|
} extint_vector_t;
|
2014-03-15 02:41:28 -04:00
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
STATIC extint_vector_t extint_vector[EXTI_NUM_VECTORS];
|
2014-03-15 02:41:28 -04:00
|
|
|
|
|
|
|
#if !defined(ETH)
|
|
|
|
#define ETH_WKUP_IRQn 62 // The 405 doesn't have ETH, but we want a value to put in our table
|
|
|
|
#endif
|
|
|
|
|
2014-03-26 18:35:55 -04:00
|
|
|
STATIC const uint8_t nvic_irq_channel[EXTI_NUM_VECTORS] = {
|
2014-03-15 02:41:28 -04:00
|
|
|
EXTI0_IRQn, EXTI1_IRQn, EXTI2_IRQn, EXTI3_IRQn, EXTI4_IRQn,
|
|
|
|
EXTI9_5_IRQn, EXTI9_5_IRQn, EXTI9_5_IRQn, EXTI9_5_IRQn, EXTI9_5_IRQn,
|
|
|
|
EXTI15_10_IRQn, EXTI15_10_IRQn, EXTI15_10_IRQn, EXTI15_10_IRQn, EXTI15_10_IRQn,
|
|
|
|
EXTI15_10_IRQn, PVD_IRQn, RTC_Alarm_IRQn, OTG_FS_WKUP_IRQn, ETH_WKUP_IRQn,
|
|
|
|
OTG_HS_WKUP_IRQn, TAMP_STAMP_IRQn, RTC_WKUP_IRQn
|
|
|
|
};
|
|
|
|
|
2014-04-08 17:35:42 -04:00
|
|
|
// Set override_callback_obj to true if you want to unconditionally set the
|
|
|
|
// callback function.
|
|
|
|
//
|
2014-03-15 02:41:28 -04:00
|
|
|
// NOTE: param is for C callers. Python can use closure to get an object bound
|
|
|
|
// with the function.
|
2014-04-18 17:38:09 -04:00
|
|
|
uint extint_register(mp_obj_t pin_obj, mp_obj_t mode_obj, mp_obj_t pull_obj, mp_obj_t callback_obj, bool override_callback_obj, void *param) {
|
2014-03-15 02:41:28 -04:00
|
|
|
const pin_obj_t *pin = NULL;
|
|
|
|
uint v_line;
|
|
|
|
|
|
|
|
if (MP_OBJ_IS_INT(pin_obj)) {
|
|
|
|
// If an integer is passed in, then use it to identify lines 16 thru 22
|
|
|
|
// We expect lines 0 thru 15 to be passed in as a pin, so that we can
|
|
|
|
// get both the port number and line number.
|
|
|
|
v_line = mp_obj_get_int(pin_obj);
|
|
|
|
if (v_line < 16) {
|
2014-04-18 17:38:09 -04:00
|
|
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "ExtInt vector %d < 16, use a Pin object", v_line));
|
2014-03-15 02:41:28 -04:00
|
|
|
}
|
|
|
|
if (v_line >= EXTI_NUM_VECTORS) {
|
2014-04-18 17:38:09 -04:00
|
|
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "ExtInt vector %d >= max of %d", v_line, EXTI_NUM_VECTORS));
|
2014-03-15 02:41:28 -04:00
|
|
|
}
|
|
|
|
} else {
|
2014-04-18 17:38:09 -04:00
|
|
|
pin = pin_find(pin_obj);
|
2014-03-15 02:41:28 -04:00
|
|
|
v_line = pin->pin;
|
|
|
|
}
|
|
|
|
int mode = mp_obj_get_int(mode_obj);
|
|
|
|
if (mode != GPIO_MODE_IT_RISING &&
|
|
|
|
mode != GPIO_MODE_IT_FALLING &&
|
|
|
|
mode != GPIO_MODE_IT_RISING_FALLING &&
|
|
|
|
mode != GPIO_MODE_EVT_RISING &&
|
|
|
|
mode != GPIO_MODE_EVT_FALLING &&
|
|
|
|
mode != GPIO_MODE_EVT_RISING_FALLING) {
|
2014-04-18 17:38:09 -04:00
|
|
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid ExtInt Mode: %d", mode));
|
2014-03-15 02:41:28 -04:00
|
|
|
}
|
|
|
|
int pull = mp_obj_get_int(pull_obj);
|
|
|
|
if (pull != GPIO_NOPULL &&
|
|
|
|
pull != GPIO_PULLUP &&
|
|
|
|
pull != GPIO_PULLDOWN) {
|
2014-04-18 17:38:09 -04:00
|
|
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Invalid ExtInt Pull: %d", pull));
|
2014-03-15 02:41:28 -04:00
|
|
|
}
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
extint_vector_t *v = &extint_vector[v_line];
|
2014-04-08 17:35:42 -04:00
|
|
|
if (!override_callback_obj && v->callback_obj != mp_const_none && callback_obj != mp_const_none) {
|
2014-04-18 17:38:09 -04:00
|
|
|
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "ExtInt vector %d is already in use", v_line));
|
2014-03-15 02:41:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// We need to update callback and param atomically, so we disable the line
|
|
|
|
// before we update anything.
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
extint_disable(v_line);
|
2014-03-15 02:41:28 -04:00
|
|
|
|
|
|
|
v->callback_obj = callback_obj;
|
|
|
|
v->param = param;
|
|
|
|
v->mode = (mode & 0x00010000) ? // GPIO_MODE_IT == 0x00010000
|
|
|
|
EXTI_Mode_Interrupt : EXTI_Mode_Event;
|
|
|
|
|
|
|
|
if (v->callback_obj != mp_const_none) {
|
|
|
|
|
|
|
|
GPIO_InitTypeDef exti;
|
|
|
|
exti.Pin = pin->pin_mask;
|
|
|
|
exti.Mode = mode;
|
|
|
|
exti.Pull = pull;
|
|
|
|
exti.Speed = GPIO_SPEED_FAST;
|
|
|
|
HAL_GPIO_Init(pin->gpio, &exti);
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
// Calling HAL_GPIO_Init does an implicit extint_enable
|
2014-03-15 02:41:28 -04:00
|
|
|
|
|
|
|
/* Enable and set NVIC Interrupt to the lowest priority */
|
|
|
|
HAL_NVIC_SetPriority(nvic_irq_channel[v_line], 0x0F, 0x0F);
|
|
|
|
HAL_NVIC_EnableIRQ(nvic_irq_channel[v_line]);
|
|
|
|
}
|
|
|
|
return v_line;
|
|
|
|
}
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
void extint_enable(uint line) {
|
2014-03-15 02:41:28 -04:00
|
|
|
if (line >= EXTI_NUM_VECTORS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Since manipulating IMR/EMR is a read-modify-write, and we want this to
|
|
|
|
// be atomic, we use the bit-band area to just affect the bit we're
|
|
|
|
// interested in.
|
2014-04-18 17:38:09 -04:00
|
|
|
EXTI_MODE_BB(extint_vector[line].mode, line) = 1;
|
2014-03-15 02:41:28 -04:00
|
|
|
}
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
void extint_disable(uint line) {
|
2014-03-15 02:41:28 -04:00
|
|
|
if (line >= EXTI_NUM_VECTORS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Since manipulating IMR/EMR is a read-modify-write, and we want this to
|
|
|
|
// be atomic, we use the bit-band area to just affect the bit we're
|
|
|
|
// interested in.
|
|
|
|
EXTI_MODE_BB(EXTI_Mode_Interrupt, line) = 0;
|
|
|
|
EXTI_MODE_BB(EXTI_Mode_Event, line) = 0;
|
|
|
|
}
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
void extint_swint(uint line) {
|
2014-03-15 02:41:28 -04:00
|
|
|
if (line >= EXTI_NUM_VECTORS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EXTI->SWIER = (1 << line);
|
|
|
|
}
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
STATIC mp_obj_t extint_obj_line(mp_obj_t self_in) {
|
|
|
|
extint_obj_t *self = self_in;
|
2014-03-15 02:41:28 -04:00
|
|
|
return MP_OBJ_NEW_SMALL_INT(self->line);
|
|
|
|
}
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
STATIC mp_obj_t extint_obj_enable(mp_obj_t self_in) {
|
|
|
|
extint_obj_t *self = self_in;
|
|
|
|
extint_enable(self->line);
|
2014-03-15 02:41:28 -04:00
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
STATIC mp_obj_t extint_obj_disable(mp_obj_t self_in) {
|
|
|
|
extint_obj_t *self = self_in;
|
|
|
|
extint_disable(self->line);
|
2014-03-15 02:41:28 -04:00
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
STATIC mp_obj_t extint_obj_swint(mp_obj_t self_in) {
|
|
|
|
extint_obj_t *self = self_in;
|
|
|
|
extint_swint(self->line);
|
2014-03-15 02:41:28 -04:00
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
STATIC mp_obj_t extint_regs(void) {
|
2014-03-15 02:41:28 -04:00
|
|
|
printf("EXTI_IMR %08lx\n", EXTI->IMR);
|
|
|
|
printf("EXTI_EMR %08lx\n", EXTI->EMR);
|
|
|
|
printf("EXTI_RTSR %08lx\n", EXTI->RTSR);
|
|
|
|
printf("EXTI_FTSR %08lx\n", EXTI->FTSR);
|
|
|
|
printf("EXTI_SWIER %08lx\n", EXTI->SWIER);
|
|
|
|
printf("EXTI_PR %08lx\n", EXTI->PR);
|
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
// line_obj = pyb.ExtInt(pin, mode, trigger, callback)
|
2014-03-15 02:41:28 -04:00
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
STATIC mp_obj_t extint_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
|
|
|
|
// type_in == extint_obj_type
|
2014-03-15 02:41:28 -04:00
|
|
|
|
2014-04-19 19:16:30 -04:00
|
|
|
mp_arg_check_num(n_args, n_kw, 4, 4, false);
|
2014-03-15 02:41:28 -04:00
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
extint_obj_t *self = m_new_obj(extint_obj_t);
|
2014-03-15 02:41:28 -04:00
|
|
|
self->base.type = type_in;
|
|
|
|
mp_obj_t line_obj = args[0];
|
|
|
|
mp_obj_t mode_obj = args[1];
|
|
|
|
mp_obj_t trigger_obj = args[2];
|
|
|
|
mp_obj_t callback_obj = args[3];
|
2014-04-18 17:38:09 -04:00
|
|
|
self->line = extint_register(line_obj, mode_obj, trigger_obj, callback_obj, false, NULL);
|
2014-03-15 02:41:28 -04:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
STATIC void extint_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
|
|
|
|
extint_obj_t *self = self_in;
|
|
|
|
print(env, "<ExtInt line=%u>", self->line);
|
2014-03-15 02:41:28 -04:00
|
|
|
}
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_line_obj, extint_obj_line);
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_enable_obj, extint_obj_enable);
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_disable_obj, extint_obj_disable);
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(extint_obj_swint_obj, extint_obj_swint);
|
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_0(extint_regs_fun_obj, extint_regs);
|
|
|
|
STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(extint_regs_obj, (mp_obj_t)&extint_regs_fun_obj);
|
|
|
|
|
|
|
|
STATIC const mp_map_elem_t extint_locals_dict_table[] = {
|
|
|
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_line), (mp_obj_t)&extint_obj_line_obj },
|
|
|
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable), (mp_obj_t)&extint_obj_enable_obj },
|
|
|
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable), (mp_obj_t)&extint_obj_disable_obj },
|
|
|
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_swint), (mp_obj_t)&extint_obj_swint_obj },
|
|
|
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_regs), (mp_obj_t)&extint_regs_obj },
|
|
|
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_IRQ_RISING), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_IT_RISING) },
|
|
|
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_IRQ_FALLING), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_IT_FALLING) },
|
|
|
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_IRQ_RISING_FALLING), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_IT_RISING_FALLING) },
|
|
|
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_EVT_RISING), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_EVT_RISING) },
|
|
|
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_EVT_FALLING), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_EVT_FALLING) },
|
|
|
|
{ MP_OBJ_NEW_QSTR(MP_QSTR_EVT_RISING_FALLING), MP_OBJ_NEW_SMALL_INT(GPIO_MODE_EVT_RISING_FALLING) },
|
|
|
|
};
|
|
|
|
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(extint_locals_dict, extint_locals_dict_table);
|
|
|
|
|
|
|
|
const mp_obj_type_t extint_type = {
|
2014-03-26 18:35:55 -04:00
|
|
|
{ &mp_type_type },
|
2014-04-18 17:38:09 -04:00
|
|
|
.name = MP_QSTR_ExtInt,
|
|
|
|
.print = extint_obj_print,
|
|
|
|
.make_new = extint_make_new,
|
|
|
|
.locals_dict = (mp_obj_t)&extint_locals_dict,
|
2014-03-15 02:41:28 -04:00
|
|
|
};
|
|
|
|
|
2014-04-18 17:38:09 -04:00
|
|
|
void extint_init(void) {
|
|
|
|
for (extint_vector_t *v = extint_vector; v < &extint_vector[EXTI_NUM_VECTORS]; v++) {
|
2014-03-15 02:41:28 -04:00
|
|
|
v->callback_obj = mp_const_none;
|
|
|
|
v->param = NULL;
|
|
|
|
v->mode = EXTI_Mode_Interrupt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-08 10:21:26 -04:00
|
|
|
// Interrupt handler
|
2014-03-15 02:41:28 -04:00
|
|
|
void Handle_EXTI_Irq(uint32_t line) {
|
|
|
|
if (__HAL_GPIO_EXTI_GET_FLAG(1 << line)) {
|
|
|
|
__HAL_GPIO_EXTI_CLEAR_FLAG(1 << line);
|
|
|
|
if (line < EXTI_NUM_VECTORS) {
|
2014-04-18 17:38:09 -04:00
|
|
|
extint_vector_t *v = &extint_vector[line];
|
2014-03-15 02:41:28 -04:00
|
|
|
if (v->callback_obj != mp_const_none) {
|
2014-04-08 10:21:26 -04:00
|
|
|
// When executing code within a handler we must lock the GC to prevent
|
|
|
|
// any memory allocations. We must also catch any exceptions.
|
|
|
|
gc_lock();
|
|
|
|
nlr_buf_t nlr;
|
|
|
|
if (nlr_push(&nlr) == 0) {
|
|
|
|
mp_call_function_1(v->callback_obj, MP_OBJ_NEW_SMALL_INT(line));
|
|
|
|
nlr_pop();
|
|
|
|
} else {
|
|
|
|
// Uncaught exception; disable the callback so it doesn't run again.
|
|
|
|
v->callback_obj = mp_const_none;
|
2014-04-18 17:38:09 -04:00
|
|
|
extint_disable(line);
|
|
|
|
printf("Uncaught exception in ExtInt interrupt handler line %lu\n", line);
|
2014-04-08 10:21:26 -04:00
|
|
|
mp_obj_print_exception((mp_obj_t)nlr.ret_val);
|
|
|
|
}
|
|
|
|
gc_unlock();
|
2014-03-15 02:41:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|