From 60cf6dca486eb1a06f34667f82ae2c96c1b48ae1 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 29 Nov 2010 23:07:32 +0100 Subject: digital/avr/common: add interrupts save and restore inlines --- digital/avr/common/io.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'digital/avr') diff --git a/digital/avr/common/io.h b/digital/avr/common/io.h index 4a6c1665..7f94f4e6 100644 --- a/digital/avr/common/io.h +++ b/digital/avr/common/io.h @@ -37,6 +37,28 @@ # define ISR SIGNAL #endif +/** Saved interrupts state. */ +typedef uint8_t intr_flags_t; + +/** Lock interrupts, and return saved state. Warning: this is not a memory + * barrier you still need to use volatile access where needed. + * + * Please try to find ways not to lock interrupts, this is dangerous! */ +extern inline intr_flags_t +intr_lock (void) +{ + intr_flags_t flags = SREG; + cli (); + return flags; +} + +/** Restore interrupts saved state. */ +extern inline void +intr_restore (intr_flags_t flags) +{ + SREG = flags; +} + #else /* HOST */ /* Same as on AVR. */ @@ -47,6 +69,14 @@ #define sei() #define cli() +typedef int intr_flags_t; + +extern inline intr_flags_t +intr_lock (void) { return 0; } + +extern inline void +intr_restore (intr_flags_t flags) { } + #endif /* HOST */ /** Use these macros to define port and bit number combination. -- cgit v1.2.3