aboutsummaryrefslogtreecommitdiffstats
path: root/src/avr/irq.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/avr/irq.h')
-rw-r--r--src/avr/irq.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/avr/irq.h b/src/avr/irq.h
new file mode 100644
index 00000000..bfc6cb51
--- /dev/null
+++ b/src/avr/irq.h
@@ -0,0 +1,29 @@
+#ifndef __AVR_IRQ_H
+#define __AVR_IRQ_H
+// Definitions for irq enable/disable on AVR
+
+#include <avr/interrupt.h> // cli
+#include "compiler.h" // barrier
+
+static inline void irq_disable(void) {
+ cli();
+ barrier();
+}
+
+static inline void irq_enable(void) {
+ barrier();
+ sei();
+}
+
+static inline uint8_t irq_save(void) {
+ uint8_t flag = SREG;
+ irq_disable();
+ return flag;
+}
+
+static inline void irq_restore(uint8_t flag) {
+ barrier();
+ SREG = flag;
+}
+
+#endif // irq.h