summaryrefslogtreecommitdiff
path: root/digital/avr/common
diff options
context:
space:
mode:
authorNicolas Schodet2010-11-29 23:07:32 +0100
committerNicolas Schodet2010-11-29 23:07:32 +0100
commit60cf6dca486eb1a06f34667f82ae2c96c1b48ae1 (patch)
tree905cecb8feca8f43583d744e9bd09ac901d6d1d4 /digital/avr/common
parent20ea07aeeee6135a29c1462b88956c5af379c1e2 (diff)
digital/avr/common: add interrupts save and restore inlines
Diffstat (limited to 'digital/avr/common')
-rw-r--r--digital/avr/common/io.h30
1 files changed, 30 insertions, 0 deletions
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.