Skip to content

Commit

Permalink
Merge branch 'refactor_rtc_wdt_code' into 'master'
Browse files Browse the repository at this point in the history
RTC WDT: refactor code to remove duplicated code

See merge request espressif/esp-idf!16845
  • Loading branch information
o-marshmallow committed Mar 4, 2022
2 parents 0b99238 + 96b362d commit dc25a8a
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 153 deletions.
4 changes: 4 additions & 0 deletions components/esp_hw_support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ if(NOT BOOTLOADER_BUILD)
# [refactor-todo]: requires "driver" for GPIO and RTC (by sleep_gpio and sleep_modes)
list(APPEND priv_requires driver)

if(CONFIG_IDF_TARGET_ESP32 OR CONFIG_IDF_TARGET_ESP32S2)
list(APPEND srcs "rtc_wdt.c")
endif()

else()
# Requires "_esp_error_check_failed()" function
list(APPEND priv_requires "esp_system")
Expand Down
6 changes: 5 additions & 1 deletion components/esp_hw_support/include/soc/rtc_wdt.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -45,6 +45,8 @@ without description where were CPUs when it happened.
#include "soc/rtc_periph.h"
#include "esp_err.h"

#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2

#ifdef __cplusplus
extern "C"
{
Expand Down Expand Up @@ -188,3 +190,5 @@ bool rtc_wdt_is_on(void);
#ifdef __cplusplus
}
#endif

#endif // CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
2 changes: 1 addition & 1 deletion components/esp_hw_support/linker.lf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ entries:
rtc_pm (noflash_text)
rtc_sleep (noflash_text)
rtc_time (noflash_text)
if IDF_TARGET_ESP32C3 = n && IDF_TARGET_ESP32H2 = n && IDF_TARGET_ESP32C2 = n:
if IDF_TARGET_ESP32 = y || IDF_TARGET_ESP32S2 = y:
rtc_wdt (noflash_text)
if IDF_TARGET_ESP32S3 = y:
if SPIRAM_MODE_QUAD = y:
Expand Down
1 change: 0 additions & 1 deletion components/esp_hw_support/port/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set(srcs
"rtc_pm.c"
"rtc_sleep.c"
"rtc_time.c"
"rtc_wdt.c"
"chip_info.c")

if(NOT BOOTLOADER_BUILD)
Expand Down
143 changes: 0 additions & 143 deletions components/esp_hw_support/port/esp32/rtc_wdt.c

This file was deleted.

1 change: 0 additions & 1 deletion components/esp_hw_support/port/esp32s2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set(srcs
"rtc_pm.c"
"rtc_sleep.c"
"rtc_time.c"
"rtc_wdt.c"
"regi2c_ctrl.c"
"chip_info.c"
)
Expand Down
1 change: 0 additions & 1 deletion components/esp_hw_support/port/esp32s3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set(srcs
"rtc_pm.c"
"rtc_sleep.c"
"rtc_time.c"
"rtc_wdt.c"
"chip_info.c"
)

Expand Down
5 changes: 0 additions & 5 deletions components/esp_hw_support/port/esp32s3/rtc_wdt.c

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "soc/efuse_periph.h"
#include "soc/rtc_wdt.h"
#include "soc/rtc.h"
#include "hal/efuse_ll.h"

#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2

bool rtc_wdt_get_protect_status(void)
{
Expand Down Expand Up @@ -87,9 +89,11 @@ esp_err_t rtc_wdt_set_time(rtc_wdt_stage_t stage, unsigned int timeout_ms)
return ESP_ERR_INVALID_ARG;
}
uint32_t timeout = (uint32_t) ((uint64_t) rtc_clk_slow_freq_get_hz() * timeout_ms / 1000);
#if !CONFIG_IDF_TARGET_ESP32
if (stage == RTC_WDT_STAGE0) {
timeout = timeout >> (1 + efuse_ll_get_wdt_delay_sel());
}
#endif
WRITE_PERI_REG(get_addr_reg(stage), timeout);
return ESP_OK;
}
Expand Down Expand Up @@ -142,3 +146,5 @@ bool rtc_wdt_is_on(void)
{
return (REG_GET_BIT(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_EN) != 0) || (REG_GET_BIT(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_FLASHBOOT_MOD_EN) != 0);
}

#endif // CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2

0 comments on commit dc25a8a

Please sign in to comment.