Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Sleep manager

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.

Macros

#define CONFIG_SLEEPMGR_ENABLE
 Configuration symbol for enabling the sleep manager. More...
 

Enumerations

enum  sleepmgr_mode {
  SLEEPMGR_ACTIVE = 0,
  SLEEPMGR_IDLE_0,
  SLEEPMGR_IDLE_1,
  SLEEPMGR_IDLE_2,
  SLEEPMGR_STANDBY,
  SLEEPMGR_NR_OF_MODES
}
 Sleep mode locks. More...
 

Functions

static void sleepmgr_enter_sleep (void)
 Go to sleep in the deepest allowed mode. More...
 
static enum sleepmgr_mode sleepmgr_get_sleep_mode (void)
 Retrieves the deepest allowable sleep mode. More...
 
static void sleepmgr_init (void)
 Initialize the lock counts. More...
 
static void sleepmgr_lock_mode (enum sleepmgr_mode mode)
 Increase lock count for a sleep mode. More...
 
static void sleepmgr_sleep (const enum sleepmgr_mode sleep_mode)
 
static void sleepmgr_unlock_mode (enum sleepmgr_mode mode)
 Decrease lock count for a sleep mode. More...
 

Internal arrays

uint8_t sleepmgr_locks []
 Sleep mode lock counters. More...
 

#define CONFIG_SLEEPMGR_ENABLE

Configuration symbol for enabling the sleep manager.

If this symbol is not defined, the functions of this service are replaced with dummy functions. This is useful for reducing code size and execution time if the sleep manager is not needed in the application.

This symbol may be defined in conf_sleepmgr.h.

Sleep mode locks.

Identifiers for the different sleep mode locks.

Enumerator
SLEEPMGR_ACTIVE 

Active mode.

SLEEPMGR_IDLE_0 

Idle 0 mode.

Potential Wake Up sources: Synchronous(APB, AHB), asynchronous.

SLEEPMGR_IDLE_1 

Idle 1 mode.

Potential Wake Up sources: Synchronous (APB), asynchronous

SLEEPMGR_IDLE_2 

Idle 2 mode.

Potential Wake Up sources: Asynchronous

SLEEPMGR_STANDBY 

Standby mode.

Potential Wake Up sources: Asynchronous

SLEEPMGR_NR_OF_MODES 

sleepmgr_enter_sleep ( void  )
inlinestatic

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.

References cpu_irq_disable, cpu_irq_enable, sleep_mode, SLEEPMGR_ACTIVE, sleepmgr_get_sleep_mode(), and sleepmgr_sleep().

Referenced by main(), run_usb_cdc_test(), run_usb_keyboard_test(), run_usb_mouse_test(), and run_usb_msc_test().

static enum sleepmgr_mode sleepmgr_get_sleep_mode ( void  )
inlinestatic

Retrieves the deepest allowable sleep mode.

Searches through the sleep mode lock counts, starting at the shallowest sleep mode, until the first non-zero lock count is found. The deepest allowable sleep mode is then returned.

References Assert, sleep_mode, SLEEPMGR_ACTIVE, sleepmgr_locks, and SLEEPMGR_NR_OF_MODES.

Referenced by sleepmgr_enter_sleep().

static void sleepmgr_init ( void  )
inlinestatic

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.

References i, sleepmgr_locks, and SLEEPMGR_NR_OF_MODES.

Referenced by bootloader_system_init(), firmware_gen_system_init(), and main().

static void sleepmgr_lock_mode ( enum sleepmgr_mode  mode)
inlinestatic

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
modeSleep mode to lock.

References cpu_irq_restore(), cpu_irq_save(), mode, sleepmgr_locks, and UNUSED.

Referenced by main(), udd_sleep_mode(), and uhd_sleep_mode().

static void sleepmgr_sleep ( const enum sleepmgr_mode  sleep_mode)
inlinestatic
static void sleepmgr_unlock_mode ( enum sleepmgr_mode  mode)
inlinestatic

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
modeSleep mode to unlock.

References cpu_irq_restore(), cpu_irq_save(), mode, sleepmgr_locks, and UNUSED.

Referenced by udd_sleep_mode(), and uhd_sleep_mode().

uint8_t sleepmgr_locks[]