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/30 06:59:18 UTC

[incubator-nuttx] branch master updated: boards/boardctl:common boardctl to read reset cause.

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.git


The following commit(s) were added to refs/heads/master by this push:
     new 4071f46  boards/boardctl:common boardctl to read reset cause.
4071f46 is described below

commit 4071f460b2487636e801782e687f4793620e5b3d
Author: 田昕 <ti...@xiaomi.com>
AuthorDate: Wed Mar 30 11:50:19 2022 +0800

    boards/boardctl:common boardctl to read reset cause.
    
    Signed-off-by: 田昕 <ti...@xiaomi.com>
---
 boards/Kconfig         |  9 +++++++++
 boards/boardctl.c      | 21 +++++++++++++++++++++
 include/nuttx/board.h  | 18 ++++++++++++++++++
 include/sys/boardctl.h | 42 +++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 89 insertions(+), 1 deletion(-)

diff --git a/boards/Kconfig b/boards/Kconfig
index a571070..ce5ef17 100644
--- a/boards/Kconfig
+++ b/boards/Kconfig
@@ -3499,6 +3499,15 @@ config BOARD_ASSERT_RESET_VALUE
 		implementations to handle the reset differently for the
 		case of a crash.
 
+config BOARDCTL_RESET_CAUSE
+	bool "Return reset cause"
+	default n
+	depends on ARCH_HAVE_RESET
+	---help---
+		Enables support for the BOARDIOC_RESET_CAUSE boardctl() command.
+		Architecture specific logic must provide the board_reset_cause()
+		interface.
+
 config BOARDCTL_UNIQUEID
 	bool "Return board unique ID"
 	default n
diff --git a/boards/boardctl.c b/boards/boardctl.c
index 0a44c31..d28c7b7 100644
--- a/boards/boardctl.c
+++ b/boards/boardctl.c
@@ -777,6 +777,27 @@ int boardctl(unsigned int cmd, uintptr_t arg)
         break;
 #endif
 
+#ifdef CONFIG_BOARDCTL_RESET_CAUSE
+      /* CMD:           BOARDIOC_RESET_CAUSE
+       * DESCRIPTION:   Get the cause of last-time board reset
+       * ARG:           A pointer to an instance of struct
+       *                boardioc_reset_cause_s
+       * CONFIGURATION: CONFIG_BOARDCTL_RESET_CAUSE
+       * DEPENDENCIES:  Board logic must provide the
+       *                board_reset_cause() interface.
+       */
+
+      case BOARDIOC_RESET_CAUSE:
+        {
+          FAR struct boardioc_reset_cause_s *cause =
+            (FAR struct boardioc_reset_cause_s *)arg;
+
+          DEBUGASSERT(cause != NULL);
+          ret = board_reset_cause(cause);
+        }
+        break;
+#endif
+
        default:
          {
 #ifdef CONFIG_BOARDCTL_IOCTL
diff --git a/include/nuttx/board.h b/include/nuttx/board.h
index 0f9d7eb..0288756 100644
--- a/include/nuttx/board.h
+++ b/include/nuttx/board.h
@@ -96,6 +96,10 @@
 #  include <nuttx/irq.h>
 #endif
 
+#ifdef CONFIG_BOARDCTL_RESET_CAUSE
+#  include <sys/boardctl.h>
+#endif
+
 /****************************************************************************
  * Public Function Prototypes
  *
@@ -819,6 +823,20 @@ void board_crashdump(uintptr_t currentsp, FAR void *tcb,
 void board_init_rngseed(void);
 #endif
 
+/****************************************************************************
+ * Name: board_reset_cause
+ *
+ * Description:
+ *   This interface may be used by application specific logic to get the
+ *   cause of last reset. Support for this function is required by
+ *   board-level logic if CONFIG_BOARDCTL_RESET is selected.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_BOARDCTL_RESET_CAUSE
+int board_reset_cause(FAR struct boardioc_reset_cause_s *cause);
+#endif
+
 #undef EXTERN
 #ifdef __cplusplus
 }
diff --git a/include/sys/boardctl.h b/include/sys/boardctl.h
index 7f9e07a..14e1526 100644
--- a/include/sys/boardctl.h
+++ b/include/sys/boardctl.h
@@ -180,6 +180,12 @@
  *                1=locked.
  * CONFIGURATION: CONFIG_BOARDCTL_TESTSET
  * DEPENDENCIES:  Architecture-specific logic provides up_testset()
+ *
+ * CMD:           BOARDIOC_RESET_CAUSE
+ * DESCRIPTION:   Get the cause of last-time board reset
+ * ARG:           A pointer to an instance of struct boardioc_reset_cause_s
+ * CONFIGURATION: CONFIG_BOARDCTL_RESET_CAUSE
+ * DEPENDENCIES:  Board logic must provide the board_reset_cause() interface.
  */
 
 #define BOARDIOC_INIT              _BOARDIOC(0x0001)
@@ -202,6 +208,7 @@
 #define BOARDIOC_UNIQUEKEY         _BOARDIOC(0x0012)
 #define BOARDIOC_SWITCH_BOOT       _BOARDIOC(0x0013)
 #define BOARDIOC_BOOT_IMAGE        _BOARDIOC(0x0014)
+#define BOARDIOC_RESET_CAUSE       _BOARDIOC(0x0015)
 
 /* If CONFIG_BOARDCTL_IOCTL=y, then board-specific commands will be support.
  * In this case, all commands not recognized by boardctl() will be forwarded
@@ -210,7 +217,7 @@
  * User defined board commands may begin with this value:
  */
 
-#define BOARDIOC_USER              _BOARDIOC(0x0015)
+#define BOARDIOC_USER              _BOARDIOC(0x0016)
 
 /****************************************************************************
  * Public Type Definitions
@@ -403,6 +410,39 @@ struct boardioc_boot_info_s
 };
 #endif
 
+#ifdef CONFIG_BOARDCTL_RESET_CAUSE
+/* Describes the reason of last reset */
+
+enum boardioc_reset_cause_e
+{
+  BOARDIOC_RESETCAUSE_NONE = 0,
+  BOARDIOC_RESETCAUSE_SYS_CHIPPOR,      /* chip power on */
+  BOARDIOC_RESETCAUSE_SYS_RWDT,         /* RTC watchdog system reset */
+  BOARDIOC_RESETCAUSE_SYS_BOR,          /* brown-out system reset */
+  BOARDIOC_RESETCAUSE_CORE_SOFT,        /* software core reset */
+  BOARDIOC_RESETCAUSE_CORE_DPSP,        /* deep-sleep core reset */
+  BOARDIOC_RESETCAUSE_CORE_MWDT,        /* main watchdog core reset */
+  BOARDIOC_RESETCAUSE_CORE_RWDT,        /* RTC watchdog core reset */
+  BOARDIOC_RESETCAUSE_CPU_MWDT,         /* main watchdog cpu reset */
+  BOARDIOC_RESETCAUSE_CPU_SOFT,         /* software cpu reset */
+  BOARDIOC_RESETCAUSE_CPU_RWDT          /* RTC watchdog cpu reset */
+};
+
+enum boardioc_softreset_subreason_e
+{
+  BOARDIOC_SOFTRESETCAUSE_USER_REBOOT = 0,
+  BOARDIOC_SOFTRESETCAUSE_PANIC,
+  BOARDIOC_SOFTRESETCAUSE_ASSERT
+};
+
+struct boardioc_reset_cause_s
+{
+  enum boardioc_reset_cause_e cause;  /* The reason of last reset */
+  uint32_t flag;                      /* watchdog number when watchdog reset,
+                                       * or soft-reset subreason */
+};
+#endif
+
 /****************************************************************************
  * Public Data
  ****************************************************************************/