#include <esp_sleep.h>
#ifndef RTC_WDT_STG_SEL_OFF
# define RTC_WDT_STG_SEL_OFF 0
#endif
#ifndef RTC_WDT_STG_SEL_INT
# define RTC_WDT_STG_SEL_INT 1
#endif
#ifndef RTC_WDT_STG_SEL_RESET_CPU
# define RTC_WDT_STG_SEL_RESET_CPU 2
#endif
#ifndef RTC_WDT_STG_SEL_RESET_SYSTEM
# define RTC_WDT_STG_SEL_RESET_SYSTEM 3
#endif
#ifndef RTC_WDT_STG_SEL_RESET_RTC
# define RTC_WDT_STG_SEL_RESET_RTC 4
#endif
#include "rtc_wdt.h" // from ..\Arduino15\packages\esp32\hardware\esp32\2.0.16\tools\sdk\esp32s3\include\esp_hw_support\include\soc
void watchdogResetRTCWDT() {
// rtc_wdt_feed() = linha 130 de C:\Users\Projetos\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\tools\sdk\esp32s3\include\esp_hw_support\include\soc\rtc_wdt.h
// rtc_wdt_feed(); // FAILED
// Trying to access the register directly
// Extract from C:\ESP\esp-idf\components\esp_hw_support\rtc_wdt.c
REG_SET_BIT(RTC_CNTL_WDTFEED_REG, RTC_CNTL_WDT_FEED);
// FAILED}
/*
* @brief Disable the RTC watchdog (RTCWDG).
*/
void watchdogEndRTCWDT() {
// rtc_wdt_disable() = line 123 of ...\Arduino15\packages\esp32\hardware\esp32\2.0.16\tools\sdk\esp32s3\include\esp_hw_support\include\soc\rtc_wdt.h
// rtc_wdt_disable(); // FAILED
// WRITE_PERI_REG(RTC_CNTL_RTC_WDTCONFIG0_REG, 0);
// Trying to access the register directly
// Extract from C:\ESP\esp-idf\components\esp_hw_support\rtc_wdt.c
REG_SET_BIT(RTC_CNTL_WDTFEED_REG, RTC_CNTL_WDT_FEED);
myRtc_wdt_set_stage(RTC_WDT_STAGE0, RTC_WDT_STAGE_ACTION_OFF);
myRtc_wdt_set_stage(RTC_WDT_STAGE1, RTC_WDT_STAGE_ACTION_OFF);
myRtc_wdt_set_stage(RTC_WDT_STAGE2, RTC_WDT_STAGE_ACTION_OFF);
myRtc_wdt_set_stage(RTC_WDT_STAGE3, RTC_WDT_STAGE_ACTION_OFF);
REG_CLR_BIT(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_FLASHBOOT_MOD_EN);
REG_CLR_BIT(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_EN);
}
/**
* @brief Copied rtc_wdt_set_stage() from C:\ESP\esp-idf\components\esp_hw_support\rtc_wdt.c
*/
esp_err_t myRtc_wdt_set_stage(rtc_wdt_stage_t stage, rtc_wdt_stage_action_t stage_sel)
{
if (stage > 3 || stage_sel > 4) {
return ESP_ERR_INVALID_ARG;
}
if (stage == RTC_WDT_STAGE0) {
REG_SET_FIELD(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_STG0, stage_sel);
} else if (stage == RTC_WDT_STAGE1) {
REG_SET_FIELD(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_STG1, stage_sel);
} else if (stage == RTC_WDT_STAGE2) {
REG_SET_FIELD(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_STG2, stage_sel);
} else {
REG_SET_FIELD(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_STG3, stage_sel);
}
return ESP_OK;
}