Energy Modes management driver. More...
![]() |
Defines | |
#define | SLEEP_EM4_WAKEUP_CALLBACK_ENABLED true |
Enable/disable the HW block for protecting accidental setting of low energy modes (recommended to be set to true). | |
#define | SLEEP_LOWEST_ENERGY_MODE_DEFAULT sleepEM3 |
Configure default lowest energy mode that the system can be set to. | |
Typedefs | |
typedef void(* | SLEEP_CbFuncPtr_t )(SLEEP_EnergyMode_t) |
Callback function pointer type. | |
Enumerations | |
enum | SLEEP_EnergyMode_t { sleepEM0 = 0, sleepEM1 = 1, sleepEM2 = 2, sleepEM3 = 3, sleepEM4 = 4 } |
Status value used for showing the Energy Mode the device is currently in. More... | |
Functions | |
void | SLEEP_Init (SLEEP_CbFuncPtr_t pSleepCb, SLEEP_CbFuncPtr_t pWakeUpCb) |
Initialize the Sleep module. | |
SLEEP_EnergyMode_t | SLEEP_Sleep (void) |
Sets the system to sleep into the lowest possible energy mode. | |
void | SLEEP_ForceSleepInEM4 (void) |
Force the device to go to EM4 without doing any checks. | |
void | SLEEP_SleepBlockBegin (SLEEP_EnergyMode_t eMode) |
Begin sleep block in the requested energy mode. | |
void | SLEEP_SleepBlockEnd (SLEEP_EnergyMode_t eMode) |
End sleep block in the requested energy mode. |
Energy Modes management driver.
This is a energy modes management module consisting of sleep.c and sleep.h source files. The main purpose of the module is to ease energy optimization with a simple API. The module allows the system to always sleep in the lowest possible energy mode. Users could set up callbacks that are being called before and after each and every sleep. A counting semaphore is available for each low energy mode (EM1/EM2/EM3) to protect certain system states from being corrupted. This semaphore has limit set to maximum 255 locks.
#define SLEEP_EM4_WAKEUP_CALLBACK_ENABLED true |
#define SLEEP_LOWEST_ENERGY_MODE_DEFAULT sleepEM3 |
Configure default lowest energy mode that the system can be set to.
Possible values:
typedef void(* SLEEP_CbFuncPtr_t)(SLEEP_EnergyMode_t) |
enum SLEEP_EnergyMode_t |
void SLEEP_ForceSleepInEM4 | ( | void | ) |
Force the device to go to EM4 without doing any checks.
This function unblocks the low energy sleep block then goes to EM4.
Definition at line 238 of file sleep.c.
References sleepEM4.
void SLEEP_Init | ( | SLEEP_CbFuncPtr_t | pSleepCb, | |
SLEEP_CbFuncPtr_t | pWakeUpCb | |||
) |
Initialize the Sleep module.
Use this function to initialize the Sleep module, should be called only once! Pointers to sleep and wake-up callback functions shall be provided when calling this function. If SLEEP_EM4_WAKEUP_CALLBACK_ENABLED is set to true, this function checks for the cause of the reset that implicitly called it and calls the wakeup callback if the reset was a wakeup from EM4 (does not work on Gecko MCU).
[in] | pSleepCb | Pointer to the callback function that is being called before the device is going to sleep. |
[in] | pWakeUpCb | Pointer to the callback function that is being called after wake up. |
Definition at line 156 of file sleep.c.
References sleepEM4.
SLEEP_EnergyMode_t SLEEP_Sleep | ( | void | ) |
Sets the system to sleep into the lowest possible energy mode.
This function takes care of the system states protected by the sleep block provided by SLEEP_SleepBlockBegin() / SLEEP_SleepBlockEnd(). It allows the system to go into the lowest possible energy mode that the device can be set into at the time of the call of this function. This function will not go lower than EM3 because leaving EM4 requires resetting MCU. To enter into EM4 call SLEEP_ForceSleepInEM4().
void SLEEP_SleepBlockBegin | ( | SLEEP_EnergyMode_t | eMode | ) |
Begin sleep block in the requested energy mode.
Blocking a critical system state from a certain energy mode makes sure that the system is not set to that energy mode while the block is not being released. Every SLEEP_SleepBlockBegin() increases the corresponding counter and every SLEEP_SleepBlockEnd() decreases it.
Example:
SLEEP_SleepBlockBegin(sleepEM2); // do not allow EM2 or higher // do some stuff that requires EM1 at least, like ADC sampling SLEEP_SleepBlockEnd(sleepEM2); // remove restriction for EM2
[in] | eMode | Energy mode to begin to block. Possible values:
|
void SLEEP_SleepBlockEnd | ( | SLEEP_EnergyMode_t | eMode | ) |
End sleep block in the requested energy mode.
Release restriction for entering certain energy mode. Every call of this function reduce blocking counter by 1. Once the counter for specific energy mode is 0 and all counters for lower energy modes are 0 as well, using particular energy mode is allowed. Every SLEEP_SleepBlockBegin() increases the corresponding counter and every SLEEP_SleepBlockEnd() decreases it.
Example:
// at start all energy modes are allowed SLEEP_SleepBlockBegin(sleepEM2); // EM2, EM3, EM4 are blocked SLEEP_SleepBlockBegin(sleepEM1); // EM1, EM2, EM3, EM4 are blocked SLEEP_SleepBlockBegin(sleepEM1); // EM1, EM2, EM3, EM4 are blocked SLEEP_SleepBlockEnd(sleepEM2); // still EM1, EM2, EM3, EM4 are blocked SLEEP_SleepBlockEnd(sleepEM1); // still EM1, EM2, EM3, EM4 are blocked SLEEP_SleepBlockEnd(sleepEM1); // all energy modes are allowed now
[in] | eMode | Energy mode to end to block. Possible values:
|