From 890510aecd1732870a603f34702639734759171c Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Wed, 4 Mar 2020 17:12:06 +0800 Subject: [PATCH] esp32, esp32s2: move reset reason source to esp_system --- components/esp32/CMakeLists.txt | 1 - components/esp32s2/CMakeLists.txt | 1 - components/esp32s2/cache_err_int.c | 2 ++ components/esp_system/CMakeLists.txt | 2 +- .../esp_system/port/esp32/CMakeLists.txt | 3 +- .../port}/esp32/reset_reason.c | 0 .../esp_system/port/esp32s2/CMakeLists.txt | 3 +- .../port}/esp32s2/reset_reason.c | 0 components/esp_system/port/panic_handler.c | 5 +++- components/esp_system/reset_reason.c | 30 ------------------- 10 files changed, 11 insertions(+), 36 deletions(-) rename components/{ => esp_system/port}/esp32/reset_reason.c (100%) rename components/{ => esp_system/port}/esp32s2/reset_reason.c (100%) delete mode 100644 components/esp_system/reset_reason.c diff --git a/components/esp32/CMakeLists.txt b/components/esp32/CMakeLists.txt index 269ca7020..51d524d32 100644 --- a/components/esp32/CMakeLists.txt +++ b/components/esp32/CMakeLists.txt @@ -24,7 +24,6 @@ else() "intr_alloc.c" "pm_esp32.c" "pm_trace.c" - "reset_reason.c" "sleep_modes.c" "spiram.c" "spiram_psram.c" diff --git a/components/esp32s2/CMakeLists.txt b/components/esp32s2/CMakeLists.txt index ff6d7038c..f1cf31f4b 100644 --- a/components/esp32s2/CMakeLists.txt +++ b/components/esp32s2/CMakeLists.txt @@ -21,7 +21,6 @@ else() "intr_alloc.c" "pm_esp32s2.c" "pm_trace.c" - "reset_reason.c" "sleep_modes.c" "spiram.c" "spiram_psram.c" diff --git a/components/esp32s2/cache_err_int.c b/components/esp32s2/cache_err_int.c index ab7328456..966479456 100644 --- a/components/esp32s2/cache_err_int.c +++ b/components/esp32s2/cache_err_int.c @@ -78,5 +78,7 @@ void esp_cache_err_int_init(void) int IRAM_ATTR esp_cache_err_get_cpuid(void) { + // TODO: The description for this seem to indicate that when cache is not in error + // state, return -1. return PRO_CPU_NUM; } diff --git a/components/esp_system/CMakeLists.txt b/components/esp_system/CMakeLists.txt index fbc5c49c1..7e5b4d57c 100644 --- a/components/esp_system/CMakeLists.txt +++ b/components/esp_system/CMakeLists.txt @@ -1,4 +1,4 @@ -idf_component_register(SRCS "panic.c" "reset_reason.c" "system_api.c" +idf_component_register(SRCS "panic.c" "system_api.c" INCLUDE_DIRS include PRIV_INCLUDE_DIRS private_include PRIV_REQUIRES spi_flash app_update diff --git a/components/esp_system/port/esp32/CMakeLists.txt b/components/esp_system/port/esp32/CMakeLists.txt index ed1a5652d..ca83bcc61 100644 --- a/components/esp_system/port/esp32/CMakeLists.txt +++ b/components/esp_system/port/esp32/CMakeLists.txt @@ -1 +1,2 @@ -target_sources(${COMPONENT_LIB} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/dport_panic_highint_hdl.S") \ No newline at end of file +target_sources(${COMPONENT_LIB} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/dport_panic_highint_hdl.S" + "${CMAKE_CURRENT_LIST_DIR}/reset_reason.c") diff --git a/components/esp32/reset_reason.c b/components/esp_system/port/esp32/reset_reason.c similarity index 100% rename from components/esp32/reset_reason.c rename to components/esp_system/port/esp32/reset_reason.c diff --git a/components/esp_system/port/esp32s2/CMakeLists.txt b/components/esp_system/port/esp32s2/CMakeLists.txt index ed1a5652d..ca83bcc61 100644 --- a/components/esp_system/port/esp32s2/CMakeLists.txt +++ b/components/esp_system/port/esp32s2/CMakeLists.txt @@ -1 +1,2 @@ -target_sources(${COMPONENT_LIB} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/dport_panic_highint_hdl.S") \ No newline at end of file +target_sources(${COMPONENT_LIB} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/dport_panic_highint_hdl.S" + "${CMAKE_CURRENT_LIST_DIR}/reset_reason.c") diff --git a/components/esp32s2/reset_reason.c b/components/esp_system/port/esp32s2/reset_reason.c similarity index 100% rename from components/esp32s2/reset_reason.c rename to components/esp_system/port/esp32s2/reset_reason.c diff --git a/components/esp_system/port/panic_handler.c b/components/esp_system/port/panic_handler.c index f1f410609..57ad3c552 100644 --- a/components/esp_system/port/panic_handler.c +++ b/components/esp_system/port/panic_handler.c @@ -517,6 +517,7 @@ static __attribute__((noreturn)) void esp_digital_reset(void) #if CONFIG_IDF_TARGET_ESP32 esp_cpu_unstall(PRO_CPU_NUM); #endif + // reset the digital part SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_SYS_RST); while (true) { @@ -527,7 +528,9 @@ static __attribute__((noreturn)) void esp_digital_reset(void) void __attribute__((noreturn)) panic_restart(void) { // If resetting because of a cache error, reset the digital part - if (esp_cache_err_get_cpuid() != -1) { + // Make sure that the reset reason is not a generic panic reason as well on ESP32S2, + // as esp_cache_err_get_cpuid always returns PRO_CPU_NUM + if (esp_cache_err_get_cpuid() != -1 && esp_reset_reason_get_hint() != ESP_RST_PANIC) { esp_digital_reset(); } else { esp_restart_noos(); diff --git a/components/esp_system/reset_reason.c b/components/esp_system/reset_reason.c deleted file mode 100644 index a4bebbfb9..000000000 --- a/components/esp_system/reset_reason.c +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2015-2016 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 "esp_private/system_internal.h" - -/* These two weak stubs for esp_reset_reason_{get,set}_hint are used when - * the application does not call esp_reset_reason() function, and - * reset_reason.c is not linked into the output file. - */ -void __attribute__((weak)) esp_reset_reason_set_hint(esp_reset_reason_t hint) -{ -} - -esp_reset_reason_t __attribute__((weak)) esp_reset_reason_get_hint(void) -{ - return ESP_RST_UNKNOWN; -} -