Xmega Application Note


sleepmgr.h

Go to the documentation of this file.
00001 
00038 #ifndef XMEGA_SLEEPMGR_H
00039 #define XMEGA_SLEEPMGR_H
00040 
00041 #ifdef __cplusplus
00042 extern "C" {
00043 #endif
00044 
00045 #include <compiler.h>
00046 #include <conf_sleepmgr.h>
00047 
00053 enum sleepmgr_mode {
00055         SLEEPMGR_ACTIVE,
00057         SLEEPMGR_IDLE,
00059         SLEEPMGR_ESTDBY,
00061         SLEEPMGR_PSAVE,
00063         SLEEPMGR_STDBY,
00065         SLEEPMGR_PDOWN,
00066         SLEEPMGR_NR_OF_MODES,
00067 };
00068 
00074 #if defined(CONFIG_SLEEPMGR_ENABLE) || defined(__DOXYGEN__)
00075 
00076 extern uint8_t sleepmgr_locks[];
00077 #  ifndef __DOXYGEN__
00078 PROGMEM_DECLARE(extern enum SLEEP_SMODE_enum, sleepmgr_configs[]);
00079 #  else
00080 
00084 extern enum SLEEP_SMODE_enum sleepmgr_configs[];
00085 #  endif /* __DOXYGEN__ */
00086 #endif /* CONFIG_SLEEPMGR_ENABLE */
00087 
00088 
00089 static inline void sleepmgr_enter_sleep(void)
00090 {
00091 #ifdef CONFIG_SLEEPMGR_ENABLE
00092         enum SLEEP_SMODE_enum PROGMEM_PTR_T config_ptr = sleepmgr_configs;
00093         enum SLEEP_SMODE_enum               config;
00094         uint8_t                             *lock_ptr = sleepmgr_locks;
00095 
00096         cpu_irq_disable();
00097 
00098         // Return right away if first mode (ACTIVE) is locked.
00099         if (*lock_ptr) {
00100                 cpu_irq_enable();
00101                 return;
00102         }
00103         lock_ptr++;
00104 
00105         // Find first non-zero lock count, starting with the shallowest modes.
00106         while (!(*lock_ptr)) {
00107                 lock_ptr++;
00108                 config_ptr++;
00109         }
00110 
00111         Assert((uintptr_t)(lock_ptr - sleepmgr_locks) < SLEEPMGR_NR_OF_MODES);
00112         config = PROGMEM_READ_BYTE(config_ptr);
00113         sleep_set_mode(config);
00114         sleep_enable();
00115 
00116         cpu_irq_enable();
00117         sleep_enter();
00118 
00119         sleep_disable();
00120 #else
00121         cpu_irq_enable();
00122 #endif /* CONFIG_SLEEPMGR_ENABLE */
00123 }
00124 
00126 
00127 #ifdef __cplusplus
00128 }
00129 #endif
00130 
00131 #endif /* XMEGA_SLEEPMGR_H */
@DOC_TITLE@
Generated on Fri Oct 22 12:15:25 2010 for AVR1300 Using the Xmega ADC by doxygen 1.6.3