Skip to content

Commit acb65be

Browse files
Daniel Camporadanicampora
authored andcommitted
zephyr: Allow pins to support both hard and soft interrupts.
Signed-off-by: Daniel Campora <[email protected]>
1 parent 3823aeb commit acb65be

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

ports/zephyr/machine_pin.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,26 @@ void machine_pin_deinit(void) {
6363
static void gpio_callback_handler(const struct device *port, struct gpio_callback *cb, gpio_port_pins_t pins) {
6464
machine_pin_irq_obj_t *irq = CONTAINER_OF(cb, machine_pin_irq_obj_t, callback);
6565

66-
#if MICROPY_STACK_CHECK
67-
// This callback executes in an ISR context so the stack-limit check must be changed to
68-
// use the ISR stack for the duration of this function (so that hard IRQ callbacks work).
69-
char *orig_stack_top = MP_STATE_THREAD(stack_top);
70-
size_t orig_stack_limit = MP_STATE_THREAD(stack_limit);
71-
MP_STATE_THREAD(stack_top) = (void *)&irq;
72-
MP_STATE_THREAD(stack_limit) = CONFIG_ISR_STACK_SIZE - 512;
73-
#endif
74-
75-
mp_irq_handler(&irq->base);
76-
77-
#if MICROPY_STACK_CHECK
78-
// Restore original stack-limit checking values.
79-
MP_STATE_THREAD(stack_top) = orig_stack_top;
80-
MP_STATE_THREAD(stack_limit) = orig_stack_limit;
81-
#endif
66+
if (irq->base.ishard) {
67+
#if MICROPY_STACK_CHECK
68+
// This callback executes in an ISR context so the stack-limit check must be changed to
69+
// use the ISR stack for the duration of this function (so that hard IRQ callbacks work).
70+
char *orig_stack_top = MP_STATE_THREAD(stack_top);
71+
size_t orig_stack_limit = MP_STATE_THREAD(stack_limit);
72+
MP_STATE_THREAD(stack_top) = (void *)&irq;
73+
MP_STATE_THREAD(stack_limit) = CONFIG_ISR_STACK_SIZE - 512;
74+
#endif
75+
76+
mp_irq_handler(&irq->base);
77+
78+
#if MICROPY_STACK_CHECK
79+
// Restore original stack-limit checking values.
80+
MP_STATE_THREAD(stack_top) = orig_stack_top;
81+
MP_STATE_THREAD(stack_limit) = orig_stack_limit;
82+
#endif
83+
} else {
84+
mp_sched_schedule(irq->base.handler, irq->base.parent);
85+
}
8286
}
8387

8488
static void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {

0 commit comments

Comments
 (0)