Skip to content

Commit 04cb93a

Browse files
pizi-nordicnashif
authored andcommitted
power: Add sys_pm_force_power_state() API
At the moment application which chosen policy based power management does not have an option to override decision taken by the policy (it could only disable some power states). This commit adds the sys_pm_force_power_state() method, which allow the application to choose power state used when OS decide to suspend the SoC. Signed-off-by: Piotr Zięcik <[email protected]>
1 parent fa46d80 commit 04cb93a

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

include/power.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern unsigned char sys_pm_idle_exit_notify;
2828
* @brief Power Management states.
2929
*/
3030
enum power_states {
31+
SYS_POWER_STATE_AUTO = (-2),
3132
SYS_POWER_STATE_ACTIVE = (-1),
3233
#ifdef CONFIG_SYS_POWER_LOW_POWER_STATE
3334
# ifdef CONFIG_SYS_POWER_STATE_CPU_LPS_SUPPORTED
@@ -200,6 +201,22 @@ void sys_resume(void);
200201
*/
201202
extern enum power_states sys_suspend(s32_t ticks);
202203

204+
/**
205+
* @brief Force usage of given power state.
206+
*
207+
* This function overrides decision made by PM policy
208+
* forcing usage of given power state in all subseqent
209+
* suspend operations.
210+
*
211+
* Forcing the SYS_POWER_STATE_AUTO power state restores
212+
* normal operation.
213+
*
214+
* @param state Power state which should be used in all
215+
* subsequent suspend operations or
216+
* SYS_POWER_STATE_AUTO.
217+
*/
218+
extern void sys_pm_force_power_state(enum power_states state);
219+
203220
#ifdef CONFIG_PM_CONTROL_OS_DEBUG
204221
/**
205222
* @brief Dump Low Power states related debug info

subsys/power/power.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
LOG_MODULE_REGISTER(power);
1717

1818
static int post_ops_done = 1;
19+
static enum power_states forced_pm_state = SYS_POWER_STATE_AUTO;
1920
static enum power_states pm_state;
2021

2122
#ifdef CONFIG_PM_CONTROL_OS_DEBUG
@@ -73,11 +74,22 @@ __weak void sys_pm_notify_lps_exit(enum power_states state)
7374
/* This function can be overridden by the application. */
7475
}
7576

77+
void sys_pm_force_power_state(enum power_states state)
78+
{
79+
__ASSERT(state >= SYS_POWER_STATE_AUTO &&
80+
state < SYS_POWER_STATE_MAX,
81+
"Invalid power state %d!", state);
82+
83+
forced_pm_state = state;
84+
}
85+
7686
enum power_states sys_suspend(s32_t ticks)
7787
{
7888
bool deep_sleep;
7989

80-
pm_state = sys_pm_policy_next_state(ticks);
90+
pm_state = (forced_pm_state == SYS_POWER_STATE_AUTO) ?
91+
sys_pm_policy_next_state(ticks) : forced_pm_state;
92+
8193
if (pm_state == SYS_POWER_STATE_ACTIVE) {
8294
LOG_DBG("No PM operations done.");
8395
return pm_state;

0 commit comments

Comments
 (0)