interrupt_avr8.h
Go to the documentation of this file.00001
00038 #ifndef UTILS_INTERRUPT_INTERRUPT_H
00039 #define UTILS_INTERRUPT_INTERRUPT_H
00040
00041 #include <compiler.h>
00042 #include <parts.h>
00043
00064 #if defined(__DOXYGEN__)
00065 # define ISR(vect)
00066 #elif defined(__GNUC__)
00067 # include <avr/interrupt.h>
00068 #elif defined(__ICCAVR__)
00069 # define __ISR(x) _Pragma(#x)
00070 # define ISR(vect) __ISR(vector=vect) __interrupt void handler_##vect(void)
00071 #endif
00072
00078 #define irq_initialize_vectors() \
00079 PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
00080
00081 #ifdef __GNUC__
00082 # define cpu_irq_enable() sei()
00083 # define cpu_irq_disable() cli()
00084 #else
00085 # define cpu_irq_enable() __enable_interrupt()
00086 # define cpu_irq_disable() __disable_interrupt()
00087 #endif
00088
00089 typedef uint8_t irqflags_t;
00090
00091 static inline irqflags_t cpu_irq_save(void)
00092 {
00093 irqflags_t val = SREG;
00094 cpu_irq_disable();
00095 return val;
00096 }
00097
00098 static inline void cpu_irq_restore(irqflags_t flags)
00099 {
00100 barrier();
00101 SREG = flags;
00102 }
00103
00104 static inline bool cpu_irq_is_enabled_flags(irqflags_t flags)
00105 {
00106 #if XMEGA
00107 # ifdef __GNUC__
00108 return flags & CPU_I_bm;
00109 # else
00110 return flags & I_bm;
00111 # endif
00112 #endif
00113 }
00114
00115 #define cpu_irq_is_enabled() cpu_irq_is_enabled_flags(SREG)
00116
00118
00123
00124 #define Enable_global_interrupt() cpu_irq_enable()
00125 #define Disable_global_interrupt() cpu_irq_disable()
00126 #define Is_global_interrupt_enabled() cpu_irq_is_enabled()
00127
00128
00129 #endif