From 9c37441b171e0552208fa6ad49a745825f8ccdd4 Mon Sep 17 00:00:00 2001 From: jingli Date: Wed, 15 Feb 2023 11:54:00 +0800 Subject: [PATCH] wdt: refactor wdt codes to use unified type --- components/bootloader_support/src/bootloader_init.c | 6 +----- .../src/flash_encryption/flash_encrypt.c | 7 ++----- components/esp_gdbstub/src/gdbstub.c | 6 +----- components/esp_hw_support/sleep_modes.c | 6 +----- components/esp_rom/patches/esp_rom_wdt.c | 6 +----- components/esp_system/panic.c | 6 +----- components/esp_system/port/cpu_start.c | 6 +----- components/esp_system/port/soc/esp32c6/clk.c | 2 +- components/esp_system/startup.c | 6 +----- components/hal/esp32/include/hal/rwdt_ll.h | 3 +++ components/hal/esp32c2/include/hal/rwdt_ll.h | 4 ++++ components/hal/esp32c3/include/hal/rwdt_ll.h | 4 ++++ components/hal/esp32c6/include/hal/rwdt_ll.h | 6 +++++- components/hal/esp32h2/include/hal/rwdt_ll.h | 6 +++++- components/hal/esp32h4/include/hal/rwdt_ll.h | 4 ++++ components/hal/esp32s2/include/hal/rwdt_ll.h | 4 ++++ components/hal/esp32s3/include/hal/rwdt_ll.h | 4 ++++ components/hal/include/hal/wdt_hal.h | 11 ++++++----- components/hal/wdt_hal_iram.c | 6 +----- 19 files changed, 50 insertions(+), 53 deletions(-) diff --git a/components/bootloader_support/src/bootloader_init.c b/components/bootloader_support/src/bootloader_init.c index a03a1544f4..e7f9f023e8 100644 --- a/components/bootloader_support/src/bootloader_init.c +++ b/components/bootloader_support/src/bootloader_init.c @@ -61,11 +61,7 @@ void bootloader_config_wdt(void) * protect the remainder of the bootloader process. */ //Disable RWDT flashboot protection. -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 // TODO: IDF-5653 - wdt_hal_context_t rwdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &LP_WDT}; -#else - wdt_hal_context_t rwdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &RTCCNTL}; -#endif + wdt_hal_context_t rwdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); wdt_hal_write_protect_disable(&rwdt_ctx); wdt_hal_set_flashboot_en(&rwdt_ctx, false); wdt_hal_write_protect_enable(&rwdt_ctx); diff --git a/components/bootloader_support/src/flash_encryption/flash_encrypt.c b/components/bootloader_support/src/flash_encryption/flash_encrypt.c index ef74be46e4..7533c69959 100644 --- a/components/bootloader_support/src/flash_encryption/flash_encrypt.c +++ b/components/bootloader_support/src/flash_encryption/flash_encrypt.c @@ -433,11 +433,8 @@ esp_err_t esp_flash_encrypt_region(uint32_t src_addr, size_t data_length) return ESP_FAIL; } -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 // TODO: IDF-5653 - wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &LP_WDT}; -#else - wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &RTCCNTL}; -#endif + wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); + for (size_t i = 0; i < data_length; i += FLASH_SECTOR_SIZE) { wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_feed(&rtc_wdt_ctx); diff --git a/components/esp_gdbstub/src/gdbstub.c b/components/esp_gdbstub/src/gdbstub.c index 67a4f2a4d4..9c502907fe 100644 --- a/components/esp_gdbstub/src/gdbstub.c +++ b/components/esp_gdbstub/src/gdbstub.c @@ -114,11 +114,7 @@ static uint32_t gdbstub_hton(uint32_t i) return __builtin_bswap32(i); } -#if !CONFIG_IDF_TARGET_ESP32C6 && !CONFIG_IDF_TARGET_ESP32H2 // TODO: IDF-5653 -static wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &RTCCNTL}; -#else -static wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &LP_WDT}; -#endif +static wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); static bool rtc_wdt_ctx_enabled = false; static wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; static bool wdt0_context_enabled = false; diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index ad5de434f5..b20540c0d1 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -835,11 +835,7 @@ esp_err_t esp_light_sleep_start(void) periph_inform_out_light_sleep_overhead(s_config.sleep_time_adjustment - sleep_time_overhead_in); // Safety net: enable WDT in case exit from light sleep fails -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 // TODO: IDF-5653 - wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &LP_WDT}; -#else - wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &RTCCNTL}; -#endif + wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); bool wdt_was_enabled = wdt_hal_is_enabled(&rtc_wdt_ctx); // If WDT was enabled in the user code, then do not change it here. if (!wdt_was_enabled) { wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); diff --git a/components/esp_rom/patches/esp_rom_wdt.c b/components/esp_rom/patches/esp_rom_wdt.c index 12541546d7..e4ae660a80 100644 --- a/components/esp_rom/patches/esp_rom_wdt.c +++ b/components/esp_rom/patches/esp_rom_wdt.c @@ -27,11 +27,7 @@ void wdt_hal_init(wdt_hal_context_t *hal, wdt_inst_t wdt_inst, uint32_t prescale } #endif else { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 // ESP32C6-TODO, ESP32H2-TODO: IDF-5653 - hal->rwdt_dev = &LP_WDT; -#else - hal->rwdt_dev = &RTCCNTL; -#endif + hal->rwdt_dev = RWDT_DEV_GET(); } hal->inst = wdt_inst; diff --git a/components/esp_system/panic.c b/components/esp_system/panic.c index 4073564742..4a92cba44f 100644 --- a/components/esp_system/panic.c +++ b/components/esp_system/panic.c @@ -62,11 +62,7 @@ bool g_panic_abort = false; static char *s_panic_abort_details = NULL; -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2// ESP32C6,ESP32H2-TODO: IDF-5653 -static wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &LP_WDT}; -#else -static wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &RTCCNTL}; -#endif +static wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); #if !CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT diff --git a/components/esp_system/port/cpu_start.c b/components/esp_system/port/cpu_start.c index 225dd2ff5b..f641fdc7c0 100644 --- a/components/esp_system/port/cpu_start.c +++ b/components/esp_system/port/cpu_start.c @@ -320,11 +320,7 @@ void IRAM_ATTR call_start_cpu0(void) || rst_reas[1] == RESET_REASON_CORE_RTC_WDT || rst_reas[1] == RESET_REASON_CORE_MWDT0 #endif ) { -#if CONFIG_IDF_TARGET_ESP32C6 // TODO: IDF-5653 - wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &LP_WDT}; -#else - wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &RTCCNTL}; -#endif + wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_disable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx); diff --git a/components/esp_system/port/soc/esp32c6/clk.c b/components/esp_system/port/soc/esp32c6/clk.c index 6243a88141..ebbedac2a5 100644 --- a/components/esp_system/port/soc/esp32c6/clk.c +++ b/components/esp_system/port/soc/esp32c6/clk.c @@ -57,7 +57,7 @@ static const char *TAG = "clk"; // Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec). // This prevents excessive delay before resetting in case the supply voltage is drawdown. // (If frequency is changed from 150kHz to 32kHz then WDT timeout will increased to 1.6sec * 150/32 = 7.5 sec). - wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &LP_WDT}; // TODO: IDF-5653 + wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); uint32_t stage_timeout_ticks = (uint32_t)(1600ULL * rtc_clk_slow_freq_get_hz() / 1000ULL); wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_feed(&rtc_wdt_ctx); diff --git a/components/esp_system/startup.c b/components/esp_system/startup.c index 73b390fca1..4f1b39532a 100644 --- a/components/esp_system/startup.c +++ b/components/esp_system/startup.c @@ -468,11 +468,7 @@ static void start_cpu0_default(void) // Now that the application is about to start, disable boot watchdog #ifndef CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2// ESP32H2, ESP32C6-TODO: IDF-5653 - wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &LP_WDT}; -#else - wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &RTCCNTL}; -#endif + wdt_hal_context_t rtc_wdt_ctx = RWDT_HAL_CONTEXT_DEFAULT(); wdt_hal_write_protect_disable(&rtc_wdt_ctx); wdt_hal_disable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx); diff --git a/components/hal/esp32/include/hal/rwdt_ll.h b/components/hal/esp32/include/hal/rwdt_ll.h index 41a88f9232..bf83efcb81 100644 --- a/components/hal/esp32/include/hal/rwdt_ll.h +++ b/components/hal/esp32/include/hal/rwdt_ll.h @@ -37,6 +37,9 @@ ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_800ns == RTC_WDT_RESET_LENGTH_800_NS, "Ad ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_1_6us == RTC_WDT_RESET_LENGTH_1600_NS, "Add mapping to LL watchdog timeout behavior, since it's no longer naturally compatible with wdt_reset_sig_length_t"); ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_3_2us == RTC_WDT_RESET_LENGTH_3200_NS, "Add mapping to LL watchdog timeout behavior, since it's no longer naturally compatible with wdt_reset_sig_length_t"); +typedef rtc_cntl_dev_t rwdt_dev_t; + +#define RWDT_DEV_GET() &RTCCNTL /** * @brief Enable the RWDT diff --git a/components/hal/esp32c2/include/hal/rwdt_ll.h b/components/hal/esp32c2/include/hal/rwdt_ll.h index 1d88837215..d782b59754 100644 --- a/components/hal/esp32c2/include/hal/rwdt_ll.h +++ b/components/hal/esp32c2/include/hal/rwdt_ll.h @@ -37,6 +37,10 @@ ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_800ns == RTC_WDT_RESET_LENGTH_800_NS, "Ad ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_1_6us == RTC_WDT_RESET_LENGTH_1600_NS, "Add mapping to LL watchdog timeout behavior, since it's no longer naturally compatible with wdt_reset_sig_length_t"); ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_3_2us == RTC_WDT_RESET_LENGTH_3200_NS, "Add mapping to LL watchdog timeout behavior, since it's no longer naturally compatible with wdt_reset_sig_length_t"); +typedef rtc_cntl_dev_t rwdt_dev_t; + +#define RWDT_DEV_GET() &RTCCNTL + /** * @brief Enable the RWDT * diff --git a/components/hal/esp32c3/include/hal/rwdt_ll.h b/components/hal/esp32c3/include/hal/rwdt_ll.h index 83da07fcb3..d943530773 100644 --- a/components/hal/esp32c3/include/hal/rwdt_ll.h +++ b/components/hal/esp32c3/include/hal/rwdt_ll.h @@ -39,6 +39,10 @@ ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_800ns == RTC_WDT_RESET_LENGTH_800_NS, "Ad ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_1_6us == RTC_WDT_RESET_LENGTH_1600_NS, "Add mapping to LL watchdog timeout behavior, since it's no longer naturally compatible with wdt_reset_sig_length_t"); ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_3_2us == RTC_WDT_RESET_LENGTH_3200_NS, "Add mapping to LL watchdog timeout behavior, since it's no longer naturally compatible with wdt_reset_sig_length_t"); +typedef rtc_cntl_dev_t rwdt_dev_t; + +#define RWDT_DEV_GET() &RTCCNTL + /** * @brief Enable the RWDT * diff --git a/components/hal/esp32c6/include/hal/rwdt_ll.h b/components/hal/esp32c6/include/hal/rwdt_ll.h index ca930a8277..f4f0599342 100644 --- a/components/hal/esp32c6/include/hal/rwdt_ll.h +++ b/components/hal/esp32c6/include/hal/rwdt_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -14,6 +14,10 @@ extern "C" { #include "hal/lpwdt_ll.h" +typedef lp_wdt_dev_t rwdt_dev_t; + +#define RWDT_DEV_GET() &LP_WDT + #define rwdt_ll_enable(hw) \ lpwdt_ll_enable(hw) diff --git a/components/hal/esp32h2/include/hal/rwdt_ll.h b/components/hal/esp32h2/include/hal/rwdt_ll.h index b7ae35cc9e..993dd14dc8 100644 --- a/components/hal/esp32h2/include/hal/rwdt_ll.h +++ b/components/hal/esp32h2/include/hal/rwdt_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -15,6 +15,10 @@ extern "C" { #include "hal/lpwdt_ll.h" +typedef lp_wdt_dev_t rwdt_dev_t; + +#define RWDT_DEV_GET() &LP_WDT + #define rwdt_ll_enable(hw) \ lpwdt_ll_enable(hw) diff --git a/components/hal/esp32h4/include/hal/rwdt_ll.h b/components/hal/esp32h4/include/hal/rwdt_ll.h index a00b926425..31aacd8529 100644 --- a/components/hal/esp32h4/include/hal/rwdt_ll.h +++ b/components/hal/esp32h4/include/hal/rwdt_ll.h @@ -36,6 +36,10 @@ ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_800ns == RTC_WDT_RESET_LENGTH_800_NS, "Ad ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_1_6us == RTC_WDT_RESET_LENGTH_1600_NS, "Add mapping to LL watchdog timeout behavior, since it's no longer naturally compatible with wdt_reset_sig_length_t"); ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_3_2us == RTC_WDT_RESET_LENGTH_3200_NS, "Add mapping to LL watchdog timeout behavior, since it's no longer naturally compatible with wdt_reset_sig_length_t"); +typedef rtc_cntl_dev_t rwdt_dev_t; + +#define RWDT_DEV_GET() &RTCCNTL + /** * @brief Enable the RWDT * diff --git a/components/hal/esp32s2/include/hal/rwdt_ll.h b/components/hal/esp32s2/include/hal/rwdt_ll.h index c76a054da0..c326370a8e 100644 --- a/components/hal/esp32s2/include/hal/rwdt_ll.h +++ b/components/hal/esp32s2/include/hal/rwdt_ll.h @@ -39,6 +39,10 @@ ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_800ns == RTC_WDT_RESET_LENGTH_800_NS, "Ad ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_1_6us == RTC_WDT_RESET_LENGTH_1600_NS, "Add mapping to LL watchdog timeout behavior, since it's no longer naturally compatible with wdt_reset_sig_length_t"); ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_3_2us == RTC_WDT_RESET_LENGTH_3200_NS, "Add mapping to LL watchdog timeout behavior, since it's no longer naturally compatible with wdt_reset_sig_length_t"); +typedef rtc_cntl_dev_t rwdt_dev_t; + +#define RWDT_DEV_GET() &RTCCNTL + /** * @brief Enable the RWDT * diff --git a/components/hal/esp32s3/include/hal/rwdt_ll.h b/components/hal/esp32s3/include/hal/rwdt_ll.h index 9b92cda0c8..f7a295a6bf 100644 --- a/components/hal/esp32s3/include/hal/rwdt_ll.h +++ b/components/hal/esp32s3/include/hal/rwdt_ll.h @@ -59,6 +59,10 @@ ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_800ns == RWDT_LL_RESET_LENGTH_800_NS, "Ad ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_1_6us == RWDT_LL_RESET_LENGTH_1600_NS, "Add mapping to LL watchdog timeout behavior, since it's no longer naturally compatible with wdt_reset_sig_length_t"); ESP_STATIC_ASSERT(WDT_RESET_SIG_LENGTH_3_2us == RWDT_LL_RESET_LENGTH_3200_NS, "Add mapping to LL watchdog timeout behavior, since it's no longer naturally compatible with wdt_reset_sig_length_t"); +typedef rtc_cntl_dev_t rwdt_dev_t; + +#define RWDT_DEV_GET() &RTCCNTL + /** * @brief Enable the RWDT * diff --git a/components/hal/include/hal/wdt_hal.h b/components/hal/include/hal/wdt_hal.h index 0fdca62f1d..87a31f6eca 100644 --- a/components/hal/include/hal/wdt_hal.h +++ b/components/hal/include/hal/wdt_hal.h @@ -29,14 +29,15 @@ typedef struct { wdt_inst_t inst; /**< Which WDT instance this HAL context is using (i.e. MWDT0, MWDT1, RWDT)*/ union { timg_dev_t *mwdt_dev; /**< Starting address of the MWDT */ -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 // TODO: IDF-5653 - lp_wdt_dev_t *rwdt_dev; /**< Starting address of the RWDT*/ -#else - rtc_cntl_dev_t *rwdt_dev; /**< Starting address of the RWDT*/ -#endif + rwdt_dev_t *rwdt_dev; /**< Starting address of the RWDT*/ }; } wdt_hal_context_t; +#define RWDT_HAL_CONTEXT_DEFAULT() { \ + .inst = WDT_RWDT, \ + .rwdt_dev = RWDT_DEV_GET() \ +} + /* ---------------------------- Init and Config ----------------------------- */ /** diff --git a/components/hal/wdt_hal_iram.c b/components/hal/wdt_hal_iram.c index 26f5c01265..7739326354 100644 --- a/components/hal/wdt_hal_iram.c +++ b/components/hal/wdt_hal_iram.c @@ -24,11 +24,7 @@ void wdt_hal_init(wdt_hal_context_t *hal, wdt_inst_t wdt_inst, uint32_t prescale } #endif else { -#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 // ESP32C6-TODO, ESP32H2-TODO: IDF-5653 - hal->rwdt_dev = &LP_WDT; -#else - hal->rwdt_dev = &RTCCNTL; -#endif + hal->rwdt_dev = RWDT_DEV_GET(); } hal->inst = wdt_inst;