Xmega Application Note


sleepmgr.h

Go to the documentation of this file.
00001 
00038 #ifndef SLEEPMGR_H
00039 #define SLEEPMGR_H
00040 
00041 #include <compiler.h>
00042 #include <sleep.h>
00043 #include <parts.h>
00044 
00045 #if defined(XMEGA)
00046 # include "xmega/sleepmgr.h"
00047 #elif (defined(__GNUC__) && defined(__AVR32__)) || (defined(__ICCAVR32__) || defined(__AAVR32__))
00048 # include "uc3/sleepmgr.h"
00049 #else
00050 # error Unsupported device.
00051 #endif
00052 
00086 #if defined(__DOXYGEN__) && !defined(CONFIG_SLEEPMGR_ENABLE)
00087 #  define CONFIG_SLEEPMGR_ENABLE
00088 #endif
00089 
00104 static inline void sleepmgr_init(void)
00105 {
00106 #ifdef CONFIG_SLEEPMGR_ENABLE
00107         uint8_t i;
00108 
00109         for (i = 0; i < SLEEPMGR_NR_OF_MODES - 1; i++) {
00110                 sleepmgr_locks[i] = 0;
00111         }
00112         sleepmgr_locks[SLEEPMGR_NR_OF_MODES - 1] = 1;
00113 #endif /* CONFIG_SLEEPMGR_ENABLE */
00114 }
00115 
00124 static inline void sleepmgr_lock_mode(enum sleepmgr_mode mode)
00125 {
00126 #ifdef CONFIG_SLEEPMGR_ENABLE
00127         irqflags_t flags;
00128 
00129         Assert(sleepmgr_locks[mode] < 0xff);
00130 
00131         // Enter a critical section
00132         flags = cpu_irq_save();
00133 
00134         ++sleepmgr_locks[mode];
00135 
00136         // Leave the critical section
00137         cpu_irq_restore(flags);
00138 #endif /* CONFIG_SLEEPMGR_ENABLE */
00139 }
00140 
00149 static inline void sleepmgr_unlock_mode(enum sleepmgr_mode mode)
00150 {
00151 #ifdef CONFIG_SLEEPMGR_ENABLE
00152         irqflags_t flags;
00153 
00154         Assert(sleepmgr_locks[mode]);
00155 
00156         // Enter a critical section
00157         flags = cpu_irq_save();
00158 
00159         --sleepmgr_locks[mode];
00160 
00161         // Leave the critical section
00162         cpu_irq_restore(flags);
00163 #endif /* CONFIG_SLEEPMGR_ENABLE */
00164 }
00165 
00179 
00180 
00181 #endif /* SLEEPMGR_H */
@DOC_TITLE@
Generated on Fri Oct 22 12:15:25 2010 for AVR1300 Using the Xmega ADC by doxygen 1.6.3