8000 zephyr: Allow pins to support both hard and soft interrupts. by danicampora · Pull Request #16916 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

zephyr: Allow pins to support both hard and soft interrupts. #16916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions ports/zephyr/machine_pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,26 @@ void machine_pin_deinit(void) {
static void gpio_callback_handler(const struct device *port, struct gpio_callback *cb, gpio_port_pins_t pins) {
machine_pin_irq_obj_t *irq = CONTAINER_OF(cb, machine_pin_irq_obj_t, callback);

#if MICROPY_STACK_CHECK
// This callback executes in an ISR context so the stack-limit check must be changed to
// use the ISR stack for the duration of this function (so that hard IRQ callbacks work).
char *orig_stack_top = MP_STATE_THREAD(stack_top);
size_t orig_stack_limit = MP_STATE_THREAD(stack_limit);
MP_STATE_THREAD(stack_top) = (void *)&irq;
MP_STATE_THREAD(stack_limit) = CONFIG_ISR_STACK_SIZE - 512;
#endif

mp_irq_handler(&irq->base);

#if MICROPY_STACK_CHECK
// Restore original stack-limit checking values.
MP_STATE_THREAD(stack_top) = orig_stack_top;
MP_STATE_THREAD(stack_limit) = orig_stack_limit;
#endif
if (irq->base.ishard) {
#if MICROPY_STACK_CHECK
// This callback executes in an ISR context so the stack-limit check must be changed to
// use the ISR stack for the duration of this function (so that hard IRQ callbacks work).
char *orig_stack_top = MP_STATE_THREAD(stack_top);
size_t orig_stack_limit = MP_STATE_THREAD(stack_limit);
MP_STATE_THREAD(stack_top) = (void *)&irq;
MP_STATE_THREAD(stack_limit) = CONFIG_ISR_STACK_SIZE - 512;
#endif

mp_irq_handler(&irq->base);

#if MICROPY_STACK_CHECK
// Restore original stack-limit checking values.
MP_STATE_THREAD(stack_top) = orig_stack_top;
MP_STATE_THREAD(stack_limit) = orig_stack_limit;
#endif
} else {
mp_sched_schedule(irq->base.handler, irq->base.parent);
}
}

static void machine_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
Expand Down
Loading
0