Skip to content

Commit ff50704

Browse files
pizi-nordicnashif
authored andcommitted
samples: nrf52: power_mgr: Demonstrate power state forcing
This commit extends the power_mgr sample in order to demonstrate power state forcing using the sys_pm_force_power_state() API. Signed-off-by: Piotr Zięcik <[email protected]>
1 parent 04cb93a commit ff50704

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

samples/boards/nrf52/power_mgr/README.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,9 @@ nRF52 core output
104104
--> Entering to SYS_POWER_STATE_CPU_LPS_2 state.
105105
--> Exited from SYS_POWER_STATE_CPU_LPS_2 state.
106106
107-
Press BUTTON1 to enter into Deep Sleep state. Press BUTTON2 to exit Deep Sleep state
108-
--> Entering to SYS_POWER_STATE_DEEP_SLEEP state.
107+
<-- Enabling SYS_POWER_STATE_CPU_LPS_1 state --->
108+
<-- Forcing SYS_POWER_STATE_CPU_LPS_2 state --->
109+
110+
<-- App doing busy wait for 10 Sec -->
111+
112+
<-- App going to sleep for 10 Sec -->

samples/boards/nrf52/power_mgr/src/main.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void main(void)
5151
/*
5252
* Start the demo.
5353
*/
54-
for (int i = 1; i <= 6; i++) {
54+
for (int i = 1; i <= 8; i++) {
5555
unsigned int sleep_seconds;
5656

5757
switch (i) {
@@ -71,6 +71,16 @@ void main(void)
7171
sys_pm_ctrl_disable_state(SYS_POWER_STATE_CPU_LPS_1);
7272
break;
7373

74+
case 7:
75+
printk("\n<-- Enabling %s state --->\n",
76+
STRINGIFY(SYS_POWER_STATE_CPU_LPS_1));
77+
sys_pm_ctrl_enable_state(SYS_POWER_STATE_CPU_LPS_1);
78+
79+
printk("<-- Forcing %s state --->\n",
80+
STRINGIFY(SYS_POWER_STATE_CPU_LPS_2));
81+
sys_pm_force_power_state(SYS_POWER_STATE_CPU_LPS_2);
82+
break;
83+
7484
default:
7585
/* Do nothing. */
7686
break;
@@ -87,6 +97,11 @@ void main(void)
8797
k_sleep(K_SECONDS(sleep_seconds));
8898
}
8999

100+
/* Restore automatic power management. */
101+
printk("\n<-- Forcing %s state --->\n",
102+
STRINGIFY(SYS_POWER_STATE_AUTO));
103+
sys_pm_force_power_state(SYS_POWER_STATE_AUTO);
104+
90105
printk("\nPress BUTTON1 to enter into Deep Sleep state. "
91106
"Press BUTTON2 to exit Deep Sleep state\n");
92107
while (1) {

0 commit comments

Comments
 (0)