Open mbenkmann opened 2 years ago
Why not return a bool?
@FrankBoesing I don't know what C standard is supposed to be supported.
gnu++14 (C++ 14)
The "atomic" macros can help here, from <util/atomic.h>
. They disable/enable interrupts, optionally with saving state. The syntax looks like:
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
// Do stuff
}
This form guarantees the interrupts get reenabled appropriately.
It is better for a function to not simply disable and enable interrupts, so the following pattern is generally better:
To be able to use this pattern, a function __irq_enabled() is necessary. The following can be inserted right into the relevant headers (kinetis.h for Teensy 3, imxrt.h for Teensy 4) next to __enable_irq() and disable_irq():