Skip to content

Commit 49957e5

Browse files
mstasiaknordicrlubos
authored andcommitted
[nrf fromlist] samples: nordic: system_off: check for supported reset causes
Check whether used reset causes are supported by hwinfo driver. Upstream PR #: 93910 Signed-off-by: Michał Stasiak <[email protected]>
1 parent d6ac46b commit 49957e5

File tree

1 file changed

+18
-2
lines changed
  • samples/boards/nordic/system_off/src

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,17 @@ static const struct gpio_dt_spec sw0 = GPIO_DT_SPEC_GET(DT_ALIAS(sw0), gpios);
3131
static const struct device *comp_dev = DEVICE_DT_GET(DT_NODELABEL(comp));
3232
#endif
3333

34-
void print_reset_cause(uint32_t reset_cause)
34+
int print_reset_cause(uint32_t reset_cause)
3535
{
36+
int32_t ret;
37+
uint32_t supported;
38+
39+
ret = hwinfo_get_supported_reset_cause((uint32_t *) &supported);
40+
41+
if (ret || !(reset_cause & supported)) {
42+
return -ENOTSUP;
43+
}
44+
3645
if (reset_cause & RESET_DEBUG) {
3746
printf("Reset by debugger.\n");
3847
} else if (reset_cause & RESET_CLOCK) {
@@ -42,6 +51,8 @@ void print_reset_cause(uint32_t reset_cause)
4251
} else {
4352
printf("Other wake up cause 0x%08X.\n", reset_cause);
4453
}
54+
55+
return 0;
4556
}
4657

4758
int main(void)
@@ -57,7 +68,12 @@ int main(void)
5768

5869
printf("\n%s system off demo\n", CONFIG_BOARD);
5970
hwinfo_get_reset_cause(&reset_cause);
60-
print_reset_cause(reset_cause);
71+
rc = print_reset_cause(reset_cause);
72+
73+
if (rc < 0) {
74+
printf("Reset cause not supported.\n");
75+
return 0;
76+
}
6177

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

0 commit comments

Comments
 (0)