Xmega Application Note


Sleep manager

Enumerations

enum  sleepmgr_mode {
  SLEEPMGR_ACTIVE, SLEEPMGR_IDLE, SLEEPMGR_ESTDBY, SLEEPMGR_PSAVE,
  SLEEPMGR_STDBY, SLEEPMGR_PDOWN, SLEEPMGR_NR_OF_MODES
}
 

Sleep mode locks.

More...

Functions

static void sleepmgr_enter_sleep (void)
 Go to sleep in the deepest allowed mode.
static void sleepmgr_init (void)
 Initialize the lock counts.
static void sleepmgr_lock_mode (enum sleepmgr_mode mode)
 Increase lock count for a sleep mode.
static void sleepmgr_unlock_mode (enum sleepmgr_mode mode)
 Decrease lock count for a sleep mode.

Detailed Description

The sleep manager is a service for ensuring that the device is not put to sleep in deeper sleep modes than the system (e.g., peripheral drivers, services or the application) allows at any given time.

It is based on the use of lock counting for the individual sleep modes, and will put the device to sleep in the shallowest sleep mode that has a non-zero lock count. The drivers/services/application can change these counts by use of sleepmgr_lock_mode and sleepmgr_unlock_mode. Refer to sleepmgr_mode for a list of the sleep modes available for locking, and the device datasheet for information on their effect.

The application must supply the file conf_sleepmgr.h.

For the sleep manager to be enabled, the symbol CONFIG_SLEEPMGR_ENABLE must be defined, e.g., in conf_sleepmgr.h. If this symbol is not defined, the functions are replaced with dummy functions and no RAM is used.


Enumeration Type Documentation

Sleep mode locks.

Identifiers for the different sleep mode locks.

Enumerator:
SLEEPMGR_ACTIVE 

Active mode.

SLEEPMGR_IDLE 

Idle mode.

SLEEPMGR_ESTDBY 

Extended Standby mode.

SLEEPMGR_PSAVE 

Power Save mode.

SLEEPMGR_STDBY 

Standby mode.

SLEEPMGR_PDOWN 

Power Down mode.

SLEEPMGR_NR_OF_MODES 

Definition at line 53 of file sleepmgr.h.

00053                    {
00055         SLEEPMGR_ACTIVE,
00057         SLEEPMGR_IDLE,
00059         SLEEPMGR_ESTDBY,
00061         SLEEPMGR_PSAVE,
00063         SLEEPMGR_STDBY,
00065         SLEEPMGR_PDOWN,
00066         SLEEPMGR_NR_OF_MODES,
00067 };


Function Documentation

sleepmgr_enter_sleep ( void   )  [inline, static]

Go to sleep in the deepest allowed mode.

Searches through the sleep mode lock counts, starting at the shallowest sleep mode, until the first non-zero lock count is found. The device is then put to sleep in the sleep mode that corresponds to the lock.

Note:
This function enables interrupts before going to sleep, and will leave them enabled upon return. This also applies if sleep is skipped due to ACTIVE mode being locked.

Definition at line 89 of file sleepmgr.h.

References Assert, cpu_irq_disable, cpu_irq_enable, sleep_set_mode(), and SLEEPMGR_NR_OF_MODES.

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 }

Here is the call graph for this function:

static void sleepmgr_init ( void   )  [inline, static]

Initialize the lock counts.

Sets all lock counts to 0, except the very last one, which is set to 1. This is done to simplify the algorithm for finding the deepest allowable sleep mode in sleepmgr_enter_sleep.

Definition at line 104 of file sleepmgr.h.

References SLEEPMGR_NR_OF_MODES.

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 }

static void sleepmgr_lock_mode ( enum sleepmgr_mode  mode  )  [inline, static]

Increase lock count for a sleep mode.

Increases the lock count for mode to ensure that the sleep manager does not put the device to sleep in the deeper sleep modes.

Parameters:
mode Sleep mode to lock.

Definition at line 124 of file sleepmgr.h.

References Assert, cpu_irq_restore(), and cpu_irq_save().

Referenced by adc_enable(), and rtc_init().

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 }

Here is the call graph for this function:

static void sleepmgr_unlock_mode ( enum sleepmgr_mode  mode  )  [inline, static]

Decrease lock count for a sleep mode.

Decreases the lock count for mode. If the lock count reaches 0, the sleep manager can put the device to sleep in the deeper sleep modes.

Parameters:
mode Sleep mode to unlock.

Definition at line 149 of file sleepmgr.h.

References Assert, cpu_irq_restore(), and cpu_irq_save().

Referenced by adc_disable().

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 }

Here is the call graph for this function:

@DOC_TITLE@
Generated on Fri Oct 22 12:15:26 2010 for AVR1300 Using the Xmega ADC by doxygen 1.6.3