1 /*
2 * Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <bootloader_wdt.h>
8 #include <hal/wdt_hal.h>
9 #include "soc/rtc.h"
10
bootloader_wdt_feed(void)11 void bootloader_wdt_feed(void)
12 {
13 wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &RTCCNTL};
14 wdt_hal_write_protect_disable(&rtc_wdt_ctx);
15 wdt_hal_feed(&rtc_wdt_ctx);
16 wdt_hal_write_protect_enable(&rtc_wdt_ctx);
17 }
18
bootloader_config_wdt(void)19 void bootloader_config_wdt(void)
20 {
21 wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &RTCCNTL};
22 wdt_hal_write_protect_disable(&rtc_wdt_ctx);
23 wdt_hal_set_flashboot_en(&rtc_wdt_ctx, false);
24 wdt_hal_write_protect_enable(&rtc_wdt_ctx);
25
26 #ifdef CONFIG_ESP_MCUBOOT_WDT_ENABLE
27 wdt_hal_init(&rtc_wdt_ctx, WDT_RWDT, 0, false);
28 uint32_t stage_timeout_ticks = (uint32_t)((uint64_t)CONFIG_BOOTLOADER_WDT_TIME_MS * rtc_clk_slow_freq_get_hz() / 1000);
29 wdt_hal_write_protect_disable(&rtc_wdt_ctx);
30 wdt_hal_config_stage(&rtc_wdt_ctx, WDT_STAGE0, stage_timeout_ticks, WDT_STAGE_ACTION_RESET_RTC);
31 wdt_hal_enable(&rtc_wdt_ctx);
32 wdt_hal_write_protect_enable(&rtc_wdt_ctx);
33 #endif
34
35 wdt_hal_context_t wdt_ctx = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
36 wdt_hal_write_protect_disable(&wdt_ctx);
37 wdt_hal_set_flashboot_en(&wdt_ctx, false);
38 wdt_hal_write_protect_enable(&wdt_ctx);
39 }
40