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 <gerard@teslabs.com>
This commit is contained in:
parent
526a7bb20d
commit
37b26f40a6
2 changed files with 3 additions and 34 deletions
|
@ -1,7 +1,7 @@
|
|||
CONFIG_PM=y
|
||||
# Required to disable default behavior of deep sleep on timeout
|
||||
CONFIG_PM_DEVICE=y
|
||||
CONFIG_GPIO=y
|
||||
# Optional select RAM retention (nRF52 only)
|
||||
#CONFIG_APP_RETENTION=y
|
||||
CONFIG_CRC=y
|
||||
CONFIG_POWEROFF=y
|
||||
|
|
|
@ -7,10 +7,8 @@
|
|||
#include <stdio.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/init.h>
|
||||
#include <zephyr/pm/pm.h>
|
||||
#include <zephyr/pm/device.h>
|
||||
#include <zephyr/pm/policy.h>
|
||||
#include <zephyr/sys/poweroff.h>
|
||||
#include <soc.h>
|
||||
#include "retained.h"
|
||||
#include <hal/nrf_gpio.h>
|
||||
|
@ -18,21 +16,6 @@
|
|||
#define BUSY_WAIT_S 2U
|
||||
#define SLEEP_S 2U
|
||||
|
||||
/* Prevent deep sleep (system off) from being entered on long timeouts
|
||||
* or `K_FOREVER` due to the default residency policy.
|
||||
*
|
||||
* This has to be done before anything tries to sleep, which means
|
||||
* before the threading system starts up.
|
||||
*/
|
||||
static int disable_ds_1(void)
|
||||
{
|
||||
|
||||
pm_policy_state_lock_get(PM_STATE_SOFT_OFF, PM_ALL_SUBSTATES);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SYS_INIT(disable_ds_1, PRE_KERNEL_1, 99);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int rc;
|
||||
|
@ -90,21 +73,7 @@ int main(void)
|
|||
retained_update();
|
||||
}
|
||||
|
||||
/* Above we disabled entry to deep sleep based on duration of
|
||||
* controlled delay. Here we need to override that, then
|
||||
* force entry to deep sleep on any delay.
|
||||
*/
|
||||
pm_state_force(0u, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0});
|
||||
sys_poweroff();
|
||||
|
||||
/* Now we need to go sleep. This will let the idle thread runs and
|
||||
* the pm subsystem will use the forced state. To confirm that the
|
||||
* forced state is used, lets set the same timeout used previously.
|
||||
*/
|
||||
k_sleep(K_SECONDS(SLEEP_S));
|
||||
|
||||
printk("ERROR: System off failed\n");
|
||||
while (true) {
|
||||
/* spin to avoid fall-off behavior */
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue