You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/03/31 09:09:29 UTC
[incubator-nuttx-apps] branch master updated: apps/nsh:add resetcause command
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new cbc9163 apps/nsh:add resetcause command
cbc9163 is described below
commit cbc9163266808e1fae0e71d2e1e41c8e3d648645
Author: 田昕 <ti...@xiaomi.com>
AuthorDate: Wed Mar 30 15:38:21 2022 +0800
apps/nsh:add resetcause command
Signed-off-by: 田昕 <ti...@xiaomi.com>
---
nshlib/Kconfig | 6 ++++++
nshlib/nsh.h | 4 ++++
nshlib/nsh_command.c | 4 ++++
nshlib/nsh_syscmds.c | 20 ++++++++++++++++++++
4 files changed, 34 insertions(+)
diff --git a/nshlib/Kconfig b/nshlib/Kconfig
index 64861f8..b9aba12 100644
--- a/nshlib/Kconfig
+++ b/nshlib/Kconfig
@@ -547,6 +547,12 @@ config NSH_DISABLE_XD
bool "Disable xd"
default DEFAULT_SMALL
+config NSH_DISABLE_RESET_CAUSE
+ bool "Disable reset cause"
+ default n if !DEFAULT_SMALL
+ default y if DEFAULT_SMALL
+ depends on BOARDCTL_RESET_CAUSE
+
endmenu
if MMCSD
diff --git a/nshlib/nsh.h b/nshlib/nsh.h
index e2f7ed9..d7d2c55 100644
--- a/nshlib/nsh.h
+++ b/nshlib/nsh.h
@@ -1157,6 +1157,10 @@ int cmd_pmconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
int cmd_reboot(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif
+#if defined(CONFIG_BOARDCTL_RESET_CAUSE) && !defined(CONFIG_NSH_DISABLE_RESET_CAUSE)
+ int cmd_reset_cause(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+#endif
+
#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif
diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index a78190d..213e707 100644
--- a/nshlib/nsh_command.c
+++ b/nshlib/nsh_command.c
@@ -439,6 +439,10 @@ static const struct cmdmap_s g_cmdmap[] =
{ "reboot", cmd_reboot, 1, 2, NULL },
#endif
+#if defined(CONFIG_BOARDCTL_RESET_CAUSE) && !defined(CONFIG_NSH_DISABLE_RESET_CAUSE)
+ { "resetcause", cmd_reset_cause, 1, 1, NULL },
+#endif
+
#ifdef NSH_HAVE_DIROPTS
# ifndef CONFIG_NSH_DISABLE_RM
{ "rm", cmd_rm, 2, 3, "[-r] <file-path>" },
diff --git a/nshlib/nsh_syscmds.c b/nshlib/nsh_syscmds.c
index c68c1c1..471131c 100644
--- a/nshlib/nsh_syscmds.c
+++ b/nshlib/nsh_syscmds.c
@@ -319,6 +319,26 @@ int cmd_reboot(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
}
#endif
+#if defined(CONFIG_BOARDCTL_RESET_CAUSE) && !defined(CONFIG_NSH_DISABLE_RESET_CAUSE)
+int cmd_reset_cause(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
+{
+ int ret;
+ struct boardioc_reset_cause_s cause;
+
+ memset(&cause, 0, sizeof(cause));
+ ret = boardctl(BOARDIOC_RESET_CAUSE, &cause);
+ if (ret < 0)
+ {
+ nsh_error(vtbl, g_fmtcmdfailed, argv[0], "boardctl", NSH_ERRNO);
+ return ERROR;
+ }
+
+ nsh_output(vtbl, "cause:0x%x, flag:0x" PRIx32 "\n",
+ cause.cause, cause.flag);
+ return OK;
+}
+#endif
+
/****************************************************************************
* Name: cmd_rptun
****************************************************************************/