blob: 197043b3463424b16af930ed3662ae8312e893ed [file] [log] [blame]
Shubham Kulkarnic75b3c72021-07-20 11:43:28 +05301/*
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>
Almir Okato1dc71362022-04-14 01:18:07 -03009#include "soc/rtc.h"
Shubham Kulkarnic75b3c72021-07-20 11:43:28 +053010
11void 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}
Almir Okato1dc71362022-04-14 01:18:07 -030018
19void 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}