Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions samples/boards/nordic/system_off/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ tests:
ordered: true
regex:
- "system off demo"
- "Retained data: INVALID"
- "Retained data: valid"
- "Boot count: 1"
- "Off count: 0"
- "Active Ticks:"
Expand Down Expand Up @@ -87,7 +87,7 @@ tests:
ordered: true
regex:
- "system off demo"
- "Retained data: INVALID"
- "Retained data: valid"
- "Boot count: 1"
- "Off count: 0"
- "Active Ticks:"
Expand Down Expand Up @@ -140,7 +140,7 @@ tests:
ordered: true
regex:
- "system off demo"
- "Retained data: INVALID"
- "Retained data: valid"
- "Boot count: 1"
- "Off count: 0"
- "Active Ticks:"
Expand Down
20 changes: 15 additions & 5 deletions samples/boards/nordic/system_off/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <zephyr/sys/poweroff.h>
#include <zephyr/sys/util.h>

#define NON_WAKEUP_RESET_REASON (RESET_PIN | RESET_SOFTWARE | RESET_POR | RESET_DEBUG)

#if defined(CONFIG_GRTC_WAKEUP_ENABLE)
#include <zephyr/drivers/timer/nrf_grtc_timer.h>
#define DEEP_SLEEP_TIME_S 2
Expand All @@ -29,15 +31,14 @@ static const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
static const struct device *comp_dev = DEVICE_DT_GET(DT_NODELABEL(comp));
#endif

void print_reset_cause(void)
void print_reset_cause(uint32_t reset_cause)
{
uint32_t reset_cause;

hwinfo_get_reset_cause(&reset_cause);
if (reset_cause & RESET_DEBUG) {
printf("Reset by debugger.\n");
} else if (reset_cause & RESET_CLOCK) {
printf("Wakeup from System OFF by GRTC.\n");
} else if (reset_cause & RESET_LOW_POWER_WAKE) {
printf("Wakeup from System OFF by GPIO.\n");
} else {
printf("Other wake up cause 0x%08X.\n", reset_cause);
}
Expand All @@ -46,6 +47,7 @@ void print_reset_cause(void)
int main(void)
{
int rc;
uint32_t reset_cause;
const struct device *const cons = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));

if (!device_is_ready(cons)) {
Expand All @@ -54,11 +56,19 @@ int main(void)
}

printf("\n%s system off demo\n", CONFIG_BOARD);
print_reset_cause();
hwinfo_get_reset_cause(&reset_cause);
print_reset_cause(reset_cause);

if (IS_ENABLED(CONFIG_APP_USE_RETAINED_MEM)) {
bool retained_ok = retained_validate();

if (reset_cause & NON_WAKEUP_RESET_REASON) {
retained.boots = 0;
retained.off_count = 0;
retained.uptime_sum = 0;
retained.uptime_latest = 0;
retained_ok = true;
}
/* Increment for this boot attempt and update. */
retained.boots += 1;
retained_update();
Expand Down
Loading