Skip to content

Commit 5bb0017

Browse files
committed
[nrf fromtree] samples: boards: nrf: system_off: use sys_poweroff
Make use of the new sys_poweroff API to actually power off the system. This lets us remove many hacks present in the sample. Signed-off-by: Gerard Marull-Paretas <[email protected]> (cherry picked from commit 37b26f4)
1 parent f195f48 commit 5bb0017

File tree

2 files changed

+3
-34
lines changed

2 files changed

+3
-34
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
CONFIG_PM=y
21
# Required to disable default behavior of deep sleep on timeout
32
CONFIG_PM_DEVICE=y
43
CONFIG_GPIO=y
54
# Optional select RAM retention (nRF52 only)
65
#CONFIG_APP_RETENTION=y
76
CONFIG_CRC=y
7+
CONFIG_POWEROFF=y

samples/boards/nrf/system_off/src/main.c

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,15 @@
77
#include <stdio.h>
88
#include <zephyr/kernel.h>
99
#include <zephyr/device.h>
10-
#include <zephyr/init.h>
11-
#include <zephyr/pm/pm.h>
1210
#include <zephyr/pm/device.h>
13-
#include <zephyr/pm/policy.h>
11+
#include <zephyr/sys/poweroff.h>
1412
#include <soc.h>
1513
#include "retained.h"
1614
#include <hal/nrf_gpio.h>
1715

1816
#define BUSY_WAIT_S 2U
1917
#define SLEEP_S 2U
2018

21-
/* Prevent deep sleep (system off) from being entered on long timeouts
22-
* or `K_FOREVER` due to the default residency policy.
23-
*
24-
* This has to be done before anything tries to sleep, which means
25-
* before the threading system starts up.
26-
*/
27-
static int disable_ds_1(void)
28-
{
29-
30-
pm_policy_state_lock_get(PM_STATE_SOFT_OFF, PM_ALL_SUBSTATES);
31-
return 0;
32-
}
33-
34-
SYS_INIT(disable_ds_1, PRE_KERNEL_1, 99);
35-
3619
int main(void)
3720
{
3821
int rc;
@@ -90,21 +73,7 @@ int main(void)
9073
retained_update();
9174
}
9275

93-
/* Above we disabled entry to deep sleep based on duration of
94-
* controlled delay. Here we need to override that, then
95-
* force entry to deep sleep on any delay.
96-
*/
97-
pm_state_force(0u, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0});
76+
sys_poweroff();
9877

99-
/* Now we need to go sleep. This will let the idle thread runs and
100-
* the pm subsystem will use the forced state. To confirm that the
101-
* forced state is used, lets set the same timeout used previously.
102-
*/
103-
k_sleep(K_SECONDS(SLEEP_S));
104-
105-
printk("ERROR: System off failed\n");
106-
while (true) {
107-
/* spin to avoid fall-off behavior */
108-
}
10978
return 0;
11079
}

0 commit comments

Comments
 (0)