Skip to content

Commit 3a94c28

Browse files
committed
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. The rp2 Timer constructor now has a hard= argument to explicitly choose between these. Add support for this for ports using the generic software timer, setting the default to False to match the existing behaviour. Signed-off-by: Chris Webb <chris@arachsys.com>
1 parent 03d20f2 commit 3a94c28

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

extmod/machine_timer.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ static void machine_timer_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
4242
}
4343

4444
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) {
45-
enum { ARG_mode, ARG_callback, ARG_period, ARG_tick_hz, ARG_freq, };
45+
enum { ARG_mode, ARG_callback, ARG_period, ARG_tick_hz, ARG_freq, ARG_hard, };
4646
static const mp_arg_t allowed_args[] = {
4747
{ MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = SOFT_TIMER_MODE_PERIODIC} },
4848
{ MP_QSTR_callback, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
4949
{ MP_QSTR_period, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0xffffffff} },
5050
{ MP_QSTR_tick_hz, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1000} },
5151
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
52+
{ MP_QSTR_hard, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
5253
};
5354

5455
// Parse args
@@ -81,6 +82,12 @@ static mp_obj_t machine_timer_init_helper(machine_timer_obj_t *self, size_t n_ar
8182
self->py_callback = args[ARG_callback].u_obj;
8283
}
8384

85+
if (args[ARG_hard].u_bool) {
86+
self->flags |= SOFT_TIMER_FLAG_HARD_CALLBACK;
87+
} else {
88+
self->flags &= ~SOFT_TIMER_FLAG_HARD_CALLBACK;
89+
}
90+
8491
if (self->py_callback != mp_const_none) {
8592
soft_timer_insert(self, self->delta_ms);
8693
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy