This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new b0d76da sys/reboot: add function to set reboot reason string
b0d76da is described below
commit b0d76daf9b21e1d9a471ff643df0251e0d439d80
Author: JustineKH <[email protected]>
AuthorDate: Wed Sep 2 10:15:32 2020 -0700
sys/reboot: add function to set reboot reason string
---
hw/hal/include/hal/hal_system.h | 2 ++
hw/mcu/dialog/da1469x/src/hal_system.c | 17 ++++++++++---
sys/reboot/include/reboot/log_reboot.h | 5 ++--
sys/reboot/src/log_reboot.c | 44 +++++++++++++++++++++++++++++++++-
sys/reboot/syscfg.yml | 6 +++++
5 files changed, 68 insertions(+), 6 deletions(-)
diff --git a/hw/hal/include/hal/hal_system.h b/hw/hal/include/hal/hal_system.h
index fa0255a..1089d40 100644
--- a/hw/hal/include/hal/hal_system.h
+++ b/hw/hal/include/hal/hal_system.h
@@ -72,6 +72,8 @@ enum hal_reset_reason {
HAL_RESET_SYS_OFF_INT = 7,
/** Restart due to DFU */
HAL_RESET_DFU = 8,
+ /** Restart reason other */
+ HAL_RESET_OTHER = 256,
};
/**
diff --git a/hw/mcu/dialog/da1469x/src/hal_system.c
b/hw/mcu/dialog/da1469x/src/hal_system.c
index 2841979..3c35141 100644
--- a/hw/mcu/dialog/da1469x/src/hal_system.c
+++ b/hw/mcu/dialog/da1469x/src/hal_system.c
@@ -52,13 +52,24 @@ hal_system_init(void)
CRG_TOP->RESET_STAT_REG = 0;
if (reg & CRG_TOP_RESET_STAT_REG_PORESET_STAT_Msk) {
- g_hal_reset_reason = HAL_RESET_POR;
+ if (reg & CRG_TOP_RESET_STAT_REG_SWD_HWRESET_STAT_Msk) {
+ g_hal_reset_reason = HAL_RESET_PIN;
+ }
+ if (reg & CRG_TOP_RESET_STAT_REG_HWRESET_STAT_Msk) {
+ g_hal_reset_reason = HAL_RESET_POR;
+ } else if (reg & CRG_TOP_RESET_STAT_REG_SWRESET_STAT_Msk) {
+ g_hal_reset_reason = HAL_RESET_SYS_OFF_INT;
+ }
} else if (reg & CRG_TOP_RESET_STAT_REG_WDOGRESET_STAT_Msk) {
g_hal_reset_reason = HAL_RESET_WATCHDOG;
- } else if (reg & CRG_TOP_RESET_STAT_REG_SWRESET_STAT_Msk) {
- g_hal_reset_reason = HAL_RESET_SOFT;
+ } else if (reg & CRG_TOP_RESET_STAT_REG_CMAC_WDOGRESET_STAT_Msk) {
+ g_hal_reset_reason = HAL_RESET_OTHER + 1;
+ } else if (reg & CRG_TOP_RESET_STAT_REG_SWD_HWRESET_STAT_Msk) {
+ g_hal_reset_reason = HAL_RESET_OTHER;
} else if (reg & CRG_TOP_RESET_STAT_REG_HWRESET_STAT_Msk) {
g_hal_reset_reason = HAL_RESET_PIN;
+ } else if (reg & CRG_TOP_RESET_STAT_REG_SWRESET_STAT_Msk) {
+ g_hal_reset_reason = HAL_RESET_SOFT;
} else {
g_hal_reset_reason = 0;
}
diff --git a/sys/reboot/include/reboot/log_reboot.h
b/sys/reboot/include/reboot/log_reboot.h
index 1a2e1ca..8b41a01 100644
--- a/sys/reboot/include/reboot/log_reboot.h
+++ b/sys/reboot/include/reboot/log_reboot.h
@@ -34,7 +34,8 @@ extern "C" {
(reason == HAL_RESET_REQUESTED ? "REQUESTED" : \
(reason == HAL_RESET_SYS_OFF_INT ? "SYSTEM_OFF_INT" : \
(reason == HAL_RESET_DFU ? "DFU" : \
- "UNKNOWN"))))))))
+ (reason == HAL_RESET_OTHER ? "OTHER" : \
+ "UNKNOWN")))))))))
struct log_reboot_info {
enum hal_reset_reason reason;
@@ -45,7 +46,7 @@ struct log_reboot_info {
int log_reboot(const struct log_reboot_info *info);
void reboot_start(enum hal_reset_reason reason);
-
+const char * log_reboot_reason_str(enum hal_reset_reason reason);
extern uint16_t reboot_cnt;
#ifdef __cplusplus
diff --git a/sys/reboot/src/log_reboot.c b/sys/reboot/src/log_reboot.c
index 0f4e42d..1d52ce6 100644
--- a/sys/reboot/src/log_reboot.c
+++ b/sys/reboot/src/log_reboot.c
@@ -207,7 +207,7 @@ log_reboot_write(const struct log_reboot_info *info)
}
cbor_encode_text_stringz(&map, "rsn");
- cbor_encode_text_stringz(&map, REBOOT_REASON_STR(info->reason));
+ cbor_encode_text_stringz(&map,log_reboot_reason_str(info->reason));
cbor_encode_text_stringz(&map, "cnt");
cbor_encode_int(&map, reboot_cnt);
@@ -383,6 +383,48 @@ reboot_conf_export(void (*func)(char *name, char *val),
return 0;
}
+const char *
+log_reboot_reason_str(enum hal_reset_reason reason)
+{
+ static char str_reason[MYNEWT_VAL(REBOOT_LOG_REBOOT_REASON_SIZE)];
+
+ if (reason >= HAL_RESET_OTHER) {
+ snprintf(str_reason,MYNEWT_VAL(REBOOT_LOG_REBOOT_REASON_SIZE),"OTHER:
0x%X",reason - HAL_RESET_OTHER);
+ return str_reason;
+ }
+
+ switch (reason) {
+ case HAL_RESET_POR:
+ return "HARD";
+ break;
+ case HAL_RESET_PIN:
+ return "RESET_PIN";
+ break;
+ case HAL_RESET_WATCHDOG:
+ return "WDOG";
+ break;
+ case HAL_RESET_SOFT:
+ return "SOFT";
+ break;
+ case HAL_RESET_BROWNOUT:
+ return "BROWNOUT";
+ break;
+ case HAL_RESET_REQUESTED:
+ return "REQUESTED";
+ break;
+ case HAL_RESET_SYS_OFF_INT:
+ return "SYSTEM_OFF_INT";
+ break;
+ case HAL_RESET_DFU:
+ return "DFU";
+ break;
+ default:
+ snprintf(str_reason,MYNEWT_VAL(REBOOT_LOG_REBOOT_REASON_SIZE),"UNKNOWN
%d",reason);
+ return str_reason;
+ break;
+ }
+}
+
void
log_reboot_pkg_init(void)
{
diff --git a/sys/reboot/syscfg.yml b/sys/reboot/syscfg.yml
index 62ed99b..bde712d 100644
--- a/sys/reboot/syscfg.yml
+++ b/sys/reboot/syscfg.yml
@@ -45,6 +45,12 @@ syscfg.defs:
this size is allocated on the stack each time an entry is written.
value: 256
+ REBOOT_LOG_REBOOT_REASON_SIZE:
+ description: >
+ The maximum size, in bytes, of a reboot reason string entry. A
buffer of
+ this size is allocated on the stack each time an entry is written.
+ value: 32
+
REBOOT_SYSINIT_STAGE:
description: >
Sysinit stage for reboot functionality.