kfsw-platform/src/reset.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <errno.h> | ||
| 2 | #include <stdbool.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | |||
| 5 | #include <zephyr/drivers/hwinfo.h> | ||
| 6 | |||
| 7 | #include <kfsw/platform/reset.h> | ||
| 8 | |||
| 9 | 4 | int kfsw_platform_get_reset_cause(uint32_t *cause) | |
| 10 | { | ||
| 11 | int rc; | ||
| 12 | |||
| 13 | 4 | if (cause == NULL) { | |
| 14 | ✗ | return -EINVAL; | |
| 15 | } | ||
| 16 | |||
| 17 | 4 | *cause = 0U; | |
| 18 | |||
| 19 | 4 | rc = hwinfo_get_reset_cause(cause); | |
| 20 | |||
| 21 | 4 | if (rc == 0) { | |
| 22 | /* Clear latched flags so the next boot reports a new reset event. */ | ||
| 23 | 4 | (void)hwinfo_clear_reset_cause(); | |
| 24 | } | ||
| 25 | |||
| 26 | 4 | return rc; | |
| 27 | } | ||
| 28 | |||
| 29 | 24 | bool kfsw_platform_reset_cause_is_watchdog(uint32_t cause) | |
| 30 | { | ||
| 31 | 24 | return (cause & RESET_WATCHDOG) != 0U; | |
| 32 | } | ||
| 33 | |||
| 34 | 22 | const char *kfsw_platform_reset_cause_name(uint32_t cause) | |
| 35 | { | ||
| 36 | /* Priority order for the reported name, watchdog first. */ | ||
| 37 | 22 | if ((cause & RESET_WATCHDOG) != 0U) { | |
| 38 | 6 | return "watchdog"; | |
| 39 | } | ||
| 40 | 16 | if ((cause & RESET_BROWNOUT) != 0U) { | |
| 41 | ✗ | return "brownout"; | |
| 42 | } | ||
| 43 | 16 | if ((cause & RESET_POR) != 0U) { | |
| 44 | 10 | return "power-on"; | |
| 45 | } | ||
| 46 | 6 | if ((cause & RESET_SOFTWARE) != 0U) { | |
| 47 | 2 | return "software"; | |
| 48 | } | ||
| 49 | 4 | if ((cause & RESET_PIN) != 0U) { | |
| 50 | 2 | return "pin"; | |
| 51 | } | ||
| 52 | 2 | if ((cause & RESET_DEBUG) != 0U) { | |
| 53 | ✗ | return "debug"; | |
| 54 | } | ||
| 55 | 2 | if ((cause & RESET_LOW_POWER_WAKE) != 0U) { | |
| 56 | ✗ | return "low-power-wake"; | |
| 57 | } | ||
| 58 | |||
| 59 | 2 | return "unknown"; | |
| 60 | } | ||
| 61 |