mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
extmod/machine_timer: Support hard IRQ soft timer callbacks.
machine.Timer() has inconsistent behaviour between ports: some run callbacks in hard IRQ context whereas others schedule them like soft IRQs. As on the rp2 port, add support to the generic software timer for a hard= argument to explicitly choose between these, setting the default to False to match the existing behaviour. This enables hard timer callbacks for the alif, mimxrt and samd ports. Signed-off-by: Chris Webb <chris@arachsys.com>
This commit is contained in:
committed by
Damien George
parent
ad11df7f7a
commit
955b6a907c
@@ -42,13 +42,14 @@ static void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
|
||||
}
|
||||
|
||||
static mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_mode, ARG_callback, ARG_period, ARG_tick_hz, ARG_freq, };
|
||||
enum { ARG_mode, ARG_callback, ARG_period, ARG_tick_hz, ARG_freq, ARG_hard, };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = SOFT_TIMER_MODE_PERIODIC} },
|
||||
{ MP_QSTR_callback, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||
{ MP_QSTR_period, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0xffffffff} },
|
||||
{ MP_QSTR_tick_hz, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1000} },
|
||||
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
|
||||
{ MP_QSTR_hard, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
|
||||
};
|
||||
|
||||
// Parse args
|
||||
@@ -81,6 +82,12 @@ static mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_ar
|
||||
self->py_callback = args[ARG_callback].u_obj;
|
||||
}
|
||||
|
||||
if (args[ARG_hard].u_bool) {
|
||||
self->flags |= SOFT_TIMER_FLAG_HARD_CALLBACK;
|
||||
} else {
|
||||
self->flags &= ~SOFT_TIMER_FLAG_HARD_CALLBACK;
|
||||
}
|
||||
|
||||
if (self->py_callback != mp_const_none) {
|
||||
soft_timer_insert(self, self->delta_ms);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user