From 79e481d093987d170565bcc26bcefbd2adeaa1c6 Mon Sep 17 00:00:00 2001 From: anjiahao Date: Tue, 11 Apr 2023 21:31:25 +0800 Subject: [PATCH] resetcause:show reset string not number Signed-off-by: anjiahao --- nshlib/nsh_syscmds.c | 71 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/nshlib/nsh_syscmds.c b/nshlib/nsh_syscmds.c index 406d2eac2..9943924ab 100644 --- a/nshlib/nsh_syscmds.c +++ b/nshlib/nsh_syscmds.c @@ -85,6 +85,43 @@ static const char g_unknown[] = "unknown"; #endif +#if defined(CONFIG_BOARDCTL_RESET_CAUSE) && !defined(CONFIG_NSH_DISABLE_RESET_CAUSE) + +/* Keep update with nuttx kernel definition */ + +static FAR const char *const g_resetcause[] = +{ + "none", + "power_on", + "rtc_watchdog", + "brown_out", + "core_soft_reset", + "core_deep_sleep", + "core_main_watchdog", + "core_rtc_watchdog", + "cpu_main_watchdog", + "cpu_soft_reset", + "cpu_rtc_watchdog", + "pin", + "lowpower", + "unkown" +}; +#endif + +#if (defined(CONFIG_BOARDCTL_RESET) && !defined(CONFIG_NSH_DISABLE_REBOOT)) || \ + (defined(CONFIG_BOARDCTL_RESET_CAUSE) && !defined(CONFIG_NSH_DISABLE_RESET_CAUSE)) +static FAR const char * const g_resetflag[] = +{ + "reboot", + "assert", + "painc", + "bootloader", + "recovery", + "factory", + NULL +}; +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -396,7 +433,26 @@ int cmd_reboot(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) if (argc > 1) { - boardctl(BOARDIOC_RESET, atoi(argv[1])); + int i = 0; + + while (g_resetflag[i] != NULL) + { + if (strcmp(g_resetflag[i], argv[1]) == 0) + { + break; + } + + i++; + } + + if (g_resetflag[i]) + { + boardctl(BOARDIOC_RESET, i); + } + else + { + boardctl(BOARDIOC_RESET, atoi(argv[1])); + } } else { @@ -428,8 +484,17 @@ int cmd_reset_cause(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) return ERROR; } - nsh_output(vtbl, "cause:0x%x,flag:0x%" PRIx32 "\n", - cause.cause, cause.flag); + if (cause.cause != BOARDIOC_RESETCAUSE_CPU_SOFT) + { + nsh_output(vtbl, "%s(%lu)\n", + g_resetcause[cause.cause], cause.flag); + } + else + { + nsh_output(vtbl, "%s(%s)\n", + g_resetcause[cause.cause], g_resetflag[cause.flag]); + } + return OK; } #endif