diff options
Diffstat (limited to 'wirish')
-rw-r--r-- | wirish/ext_interrupts.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/wirish/ext_interrupts.h b/wirish/ext_interrupts.h index 80e2e9e..e68d973 100644 --- a/wirish/ext_interrupts.h +++ b/wirish/ext_interrupts.h @@ -23,6 +23,7 @@ *****************************************************************************/ #include "libmaple_types.h" +#include "nvic.h" /** * @file ext_interrupts.h @@ -73,6 +74,32 @@ void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode); */ void detachInterrupt(uint8 pin); +/** + * Re-enable interrupts. + * + * Call this after noInterrupts() to re-enable interrupt handling, + * after you have finished with a timing-critical section of code. + * + * @see noInterrupts() + */ +static inline __attribute__((always_inline)) void interrupts() { + nvic_globalirq_enable(); +} + +/** + * Disable interrupts. + * + * After calling this function, all user-programmable interrupts will + * be disabled. You can call this function before a timing-critical + * section of code, then call interrupts() to re-enable interrupt + * handling. + * + * @see interrupts() + */ +static inline __attribute__((always_inline)) void noInterrupts() { + nvic_globalirq_disable(); +} + #ifdef __cplusplus } #endif |