| /* |
| * Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd. |
| * |
| * SPDX-License-Identifier: Apache-2.0 |
| */ |
| |
| #include <bootloader_wdt.h> |
| #include <hal/wdt_hal.h> |
| #include "soc/rtc.h" |
| |
| void bootloader_wdt_feed(void) |
| { |
| wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &RTCCNTL}; |
| wdt_hal_write_protect_disable(&rtc_wdt_ctx); |
| wdt_hal_feed(&rtc_wdt_ctx); |
| wdt_hal_write_protect_enable(&rtc_wdt_ctx); |
| } |
| |
| void bootloader_config_wdt(void) |
| { |
| wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &RTCCNTL}; |
| wdt_hal_write_protect_disable(&rtc_wdt_ctx); |
| wdt_hal_set_flashboot_en(&rtc_wdt_ctx, false); |
| wdt_hal_write_protect_enable(&rtc_wdt_ctx); |
| |
| #ifdef CONFIG_ESP_MCUBOOT_WDT_ENABLE |
| wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false); |
| uint32_t stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000); |
| wdt_hal_write_protect_disable(&rtc_wdt_ctx); |
| wdt_hal_config_stage(&rtc_wdt_ctx, WDT_STAGE0, stage_timeout_ticks, WDT_STAGE_ACTION_RESET_RTC); |
| wdt_hal_enable(&rtc_wdt_ctx); |
| wdt_hal_write_protect_enable(&rtc_wdt_ctx); |
| #endif |
| |
| wdt_hal_context_t wdt_ctx = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; |
| wdt_hal_write_protect_disable(&wdt_ctx); |
| wdt_hal_set_flashboot_en(&wdt_ctx, false); |
| wdt_hal_write_protect_enable(&wdt_ctx); |
| } |