Page 1 of 1

How to work with atomic esp32 operations (disabling interrupts)

Posted: Sat Feb 25, 2023 12:06 pm
by Uint64_t
I have a section of code where it is impossible for an interrupt to work. How can this be implemented? For example, the
instruction 1
instruction 2
disable interrupt
main instruction
enable interrupt
...

Re: How to work with atomic esp32 operations (disabling interrupts)

Posted: Sun Feb 26, 2023 5:30 am
by ESP_Sprite
You would use a critical section (docs).

Re: How to work with atomic esp32 operations (disabling interrupts)

Posted: Sun Feb 26, 2023 10:39 am
by Uint64_t
Great! But if I need to block the interrupt only on the GPIO13 and do not touch the rest and it should be in the task

Re: How to work with atomic esp32 operations (disabling interrupts)

Posted: Mon Feb 27, 2023 12:06 am
by ESP_Sprite
?

Re: How to work with atomic esp32 operations (disabling interrupts)

Posted: Mon Feb 27, 2023 9:12 am
by vanBassum
instruction 1
instruction 2
gpio_set_intr_type(irqPin, GPIO_INTR_DISABLE);
main instruction
gpio_set_intr_type(irqPin, GPIO_INTR_HIGH_LEVEL);

Re: How to work with atomic esp32 operations (disabling interrupts)

Posted: Mon Feb 27, 2023 6:06 pm
by Uint64_t
Thanks for the explanation!

Re: How to work with atomic esp32 operations (disabling interrupts)

Posted: Tue Feb 28, 2023 12:44 am
by ESP_Sprite
Note that on an ESP32, a critical section tends to be better for this, as disabling the IRQ has the race condition that the IRQ may already be in the process of being serviced on the other core. (Additionally, gpio_set_intr_type goes over a shared bus; I'm not sure if without a write fence that write is guaranteed to arrive before the next instruction.)