mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-05-22 01:27:11 +08:00
Merge branch 'feature/add_reset_reason' into 'master'
Add reset reason function See merge request sdk/ESP8266_RTOS_SDK!651
This commit is contained in:
@ -175,6 +175,12 @@ config TASK_WDT_TIMEOUT_S
|
||||
default 14 if TASK_WDT_TIMEOUT_14N
|
||||
default 15 if TASK_WDT_TIMEOUT_15N
|
||||
|
||||
config RESET_REASON
|
||||
bool "Enable reset reason"
|
||||
default y
|
||||
help
|
||||
Enable this option, the reset reason function can be used, or compiler will show function linking error.
|
||||
|
||||
config WIFI_PPT_TASKSTACK_SIZE
|
||||
int "ppT task stack size"
|
||||
default 2048
|
||||
|
29
components/esp8266/include/esp8266/rtc_register.h
Normal file
29
components/esp8266/include/esp8266/rtc_register.h
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
NO_MEAN = 0,
|
||||
POWERON_RESET = 1, /**<1, Vbat power on reset*/
|
||||
EXT_RESET = 2, /**<2, external system reset*/
|
||||
SW_RESET = 3, /**<3, Software reset digital core*/
|
||||
OWDT_RESET = 4, /**<4, Legacy watch dog reset digital core*/
|
||||
DEEPSLEEP_RESET = 5, /**<5, Deep Sleep reset digital core*/
|
||||
SDIO_RESET = 6, /**<6, Reset by SLC module, reset digital core*/
|
||||
} RESET_REASON;
|
||||
|
||||
#define RTC_STORE0 (REG_RTC_BASE + 0x30)
|
||||
#define RTC_STATE1 (REG_RTC_BASE + 0x14)
|
||||
#define RTC_STATE2 (REG_RTC_BASE + 0x18)
|
@ -28,6 +28,24 @@ typedef enum {
|
||||
ESP_MAC_WIFI_SOFTAP,
|
||||
} esp_mac_type_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reset reasons
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_RST_UNKNOWN = 0, //!< Reset reason can not be determined
|
||||
ESP_RST_POWERON, //!< Reset due to power-on event
|
||||
ESP_RST_EXT, //!< Reset by external pin (not applicable for ESP8266)
|
||||
ESP_RST_SW, //!< Software reset via esp_restart
|
||||
ESP_RST_PANIC, //!< Software reset due to exception/panic
|
||||
ESP_RST_INT_WDT, //!< Reset (software or hardware) due to interrupt watchdog
|
||||
ESP_RST_TASK_WDT, //!< Reset due to task watchdog
|
||||
ESP_RST_WDT, //!< Reset due to other watchdogs
|
||||
ESP_RST_DEEPSLEEP, //!< Reset after exiting deep sleep mode
|
||||
ESP_RST_BROWNOUT, //!< Brownout reset (software or hardware)
|
||||
ESP_RST_SDIO, //!< Reset over SDIO
|
||||
} esp_reset_reason_t;
|
||||
|
||||
/**
|
||||
* @brief Set base MAC address with the MAC address which is stored in EFUSE or
|
||||
* external storage e.g. flash and EEPROM.
|
||||
@ -123,6 +141,12 @@ void system_restore(void) __attribute__ ((noreturn));
|
||||
*/
|
||||
void esp_restart(void) __attribute__ ((noreturn));
|
||||
|
||||
/**
|
||||
* @brief Get reason of last reset
|
||||
* @return See description of esp_reset_reason_t for explanation of each value.
|
||||
*/
|
||||
esp_reset_reason_t esp_reset_reason(void);
|
||||
|
||||
/**
|
||||
* @brief Get the size of available heap.
|
||||
*
|
||||
|
53
components/esp8266/include/internal/esp_system_internal.h
Normal file
53
components/esp8266/include/internal/esp_system_internal.h
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define RTC_SYS_RAM_SIZE 256
|
||||
|
||||
/**
|
||||
* The size of structure must not be larger than 256 bytes and all member varible must be uint32_t type
|
||||
*/
|
||||
struct _rtc_sys_info {
|
||||
uint32_t hint; // software reset reason
|
||||
};
|
||||
|
||||
extern struct _rtc_sys_info rtc_sys_info;
|
||||
|
||||
/**
|
||||
* @brief Internal function to get SoC reset reason at system initialization
|
||||
*/
|
||||
void esp_reset_reason_init(void);
|
||||
|
||||
/**
|
||||
* @brief Internal function to set reset reason hint
|
||||
*
|
||||
* The hint is used do distinguish different reset reasons when software reset
|
||||
* is performed.
|
||||
*
|
||||
* The hint is stored in RTC store register, RTC_RESET_CAUSE_REG.
|
||||
*
|
||||
* @param hint Desired esp_reset_reason_t value for the real reset reason
|
||||
*/
|
||||
void esp_reset_reason_set_hint(esp_reset_reason_t hint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -4,3 +4,5 @@ PROVIDE ( uart0 = 0x60000000 );
|
||||
PROVIDE ( uart1 = 0x60000f00 );
|
||||
|
||||
PROVIDE ( frc1 = 0x60000600 );
|
||||
|
||||
PROVIDE ( rtc_sys_info = 0x60001100 );
|
@ -1,5 +1,5 @@
|
||||
gwen:
|
||||
core: 676f3f3
|
||||
core: 5ce569c
|
||||
net80211: 2e4e807
|
||||
pp: cf2f721
|
||||
wpa: 4e2372f
|
||||
|
Binary file not shown.
145
components/esp8266/source/reset_reason.c
Normal file
145
components/esp8266/source/reset_reason.c
Normal file
@ -0,0 +1,145 @@
|
||||
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include <string.h>
|
||||
#include "esp_system.h"
|
||||
#include "internal/esp_system_internal.h"
|
||||
#include "esp8266/rtc_register.h"
|
||||
#include "esp8266/rom_functions.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_libc.h"
|
||||
|
||||
#if CONFIG_RESET_REASON
|
||||
|
||||
#define RTC_RESET_SW_CAUSE_REG RTC_STORE0
|
||||
#define RTC_RESET_HW_CAUSE_REG RTC_STATE1
|
||||
#define RTC_WAKEUP_HW_CAUSE_REG RTC_STATE2
|
||||
|
||||
#define RTC_RESET_HW_CAUSE_LSB 0
|
||||
#define RTC_RESET_HW_CAUSE_MSB 3
|
||||
|
||||
#define RTC_WAKEUP_HW_CAUSE_LSB 8
|
||||
#define RTC_WAKEUP_HW_CAUSE_MSB 13
|
||||
|
||||
static const char *TAG = "reset_reason";
|
||||
static uint32_t s_reset_reason;
|
||||
|
||||
static inline void esp_reset_reason_clear_hint()
|
||||
{
|
||||
rtc_sys_info.hint = 0;
|
||||
}
|
||||
|
||||
static inline uint32_t esp_reset_reason_get_hint(uint32_t hw_reset)
|
||||
{
|
||||
if (hw_reset == POWERON_RESET && rtc_sys_info.hint != ESP_RST_SW) {
|
||||
uint32_t *p = (uint32_t *)&rtc_sys_info;
|
||||
|
||||
for (int i = 0; i < RTC_SYS_RAM_SIZE / sizeof(uint32_t); i++)
|
||||
*p++ = 0;
|
||||
}
|
||||
|
||||
return rtc_sys_info.hint;
|
||||
}
|
||||
|
||||
static inline uint32_t esp_rtc_get_reset_reason(void)
|
||||
{
|
||||
return GET_PERI_REG_BITS(RTC_RESET_HW_CAUSE_REG, RTC_RESET_HW_CAUSE_MSB, RTC_RESET_HW_CAUSE_LSB);
|
||||
}
|
||||
|
||||
#if CONFIG_RESET_REASON_CHECK_WAKEUP
|
||||
static inline uint32_t esp_rtc_get_wakeup_reason(void)
|
||||
{
|
||||
return GET_PERI_REG_BITS(RTC_WAKEUP_HW_CAUSE_REG, RTC_WAKEUP_HW_CAUSE_MSB, RTC_WAKEUP_HW_CAUSE_LSB);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline uint32_t get_reset_reason(uint32_t rtc_reset_reason, uint32_t reset_reason_hint)
|
||||
{
|
||||
switch (rtc_reset_reason) {
|
||||
case POWERON_RESET:
|
||||
if (reset_reason_hint == ESP_RST_SW)
|
||||
return reset_reason_hint;
|
||||
return ESP_RST_POWERON;
|
||||
case EXT_RESET:
|
||||
if (reset_reason_hint == ESP_RST_DEEPSLEEP) {
|
||||
return reset_reason_hint;
|
||||
}
|
||||
return ESP_RST_EXT;
|
||||
case SW_RESET:
|
||||
if (reset_reason_hint == ESP_RST_PANIC ||
|
||||
reset_reason_hint == ESP_RST_BROWNOUT ||
|
||||
reset_reason_hint == ESP_RST_TASK_WDT) {
|
||||
return reset_reason_hint;
|
||||
}
|
||||
return ESP_RST_SW;
|
||||
case DEEPSLEEP_RESET:
|
||||
return ESP_RST_DEEPSLEEP;
|
||||
case OWDT_RESET:
|
||||
return ESP_RST_WDT;
|
||||
case SDIO_RESET:
|
||||
return ESP_RST_SDIO;
|
||||
default:
|
||||
return ESP_RST_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Internal function to get SoC reset reason at system initialization
|
||||
*/
|
||||
void esp_reset_reason_init(void)
|
||||
{
|
||||
const uint32_t hw_reset = esp_rtc_get_reset_reason();
|
||||
#if CONFIG_RESET_REASON_CHECK_WAKEUP
|
||||
const uint32_t hw_wakeup = esp_rtc_get_wakeup_reason();
|
||||
#else
|
||||
const uint32_t hw_wakeup = 0;
|
||||
#endif
|
||||
const uint32_t hint = esp_reset_reason_get_hint(hw_reset);
|
||||
|
||||
s_reset_reason = get_reset_reason(hw_reset, hint);
|
||||
if (hint != ESP_RST_UNKNOWN) {
|
||||
esp_reset_reason_clear_hint();
|
||||
}
|
||||
|
||||
ESP_EARLY_LOGI(TAG, "RTC reset %u wakeup %u store %u, reason is %u", hw_reset, hw_wakeup, hint, s_reset_reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Internal function to set reset reason hint
|
||||
*/
|
||||
void esp_reset_reason_set_hint(esp_reset_reason_t hint)
|
||||
{
|
||||
rtc_sys_info.hint = hint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get reason of last reset
|
||||
*/
|
||||
esp_reset_reason_t esp_reset_reason(void)
|
||||
{
|
||||
return (esp_reset_reason_t)s_reset_reason;
|
||||
}
|
||||
|
||||
#else /* CONFIG_RESET_REASON */
|
||||
|
||||
/**
|
||||
* null function for pass compiling
|
||||
*/
|
||||
void esp_reset_reason_set_hint(esp_reset_reason_t hint)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif /* CONFIG_RESET_REASON */
|
@ -29,6 +29,7 @@
|
||||
#include "esp_heap_caps_init.h"
|
||||
#include "esp_task_wdt.h"
|
||||
#include "internal/esp_wifi_internal.h"
|
||||
#include "internal/esp_system_internal.h"
|
||||
|
||||
#define FLASH_MAP_ADDR 0x40200000
|
||||
#define FLASH_MAP_SIZE 0x00100000
|
||||
@ -68,6 +69,10 @@ static void user_init_entry(void *param)
|
||||
|
||||
esp_wifi_set_rx_pbuf_mem_type(WIFI_RX_PBUF_DRAM);
|
||||
|
||||
#if CONFIG_RESET_REASON
|
||||
esp_reset_reason_init();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_TASK_WDT
|
||||
esp_task_wdt_init();
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user