From 48e2d6e8f969c2359a90d52d7a76d6076014abf7 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Wed, 6 Mar 2019 18:03:09 +0100 Subject: [PATCH] cpu/atmega_common: implement irq_is_enabled() --- cpu/avr8_common/include/irq_arch.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cpu/avr8_common/include/irq_arch.h b/cpu/avr8_common/include/irq_arch.h index 5287a9c251..1c8261a46e 100644 --- a/cpu/avr8_common/include/irq_arch.h +++ b/cpu/avr8_common/include/irq_arch.h @@ -103,6 +103,21 @@ __attribute__((always_inline)) static inline int irq_is_in(void) return (state & AVR8_STATE_FLAG_ISR); } +/** + * @brief Test if interrupts are currently enabled + */ +__attribute__((always_inline)) static inline int irq_is_enabled(void) +{ + uint8_t mask; + __asm__ volatile( + "in %[dest], __SREG__" "\n\t" + : [dest] "=r"(mask) + : /* no inputs */ + : "memory" + ); + return mask & (1 << 7); +} + #ifdef __cplusplus } #endif