1 /* 2 * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #pragma once 8 9 #include <stdbool.h> 10 #include <stdint.h> 11 12 #include "hal/xt_wdt_ll.h" 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 typedef struct { 19 rtc_cntl_dev_t *dev; /* Pointer to the RTC register struct */ 20 } xt_wdt_hal_context_t; /* HAL context struct */ 21 22 typedef struct { 23 uint32_t timeout; /* Watchdog timer timeout in RTC_CLK cycles*/ 24 } xt_wdt_hal_config_t; /* HAL config parameter struct */ 25 26 /* ---------------------------- Init and Config ----------------------------- */ 27 28 /** 29 * @brief Initialize the WDTs associated HAL context 30 * 31 * Prepares the register for enabling the WDT and sets the timeout value 32 * 33 * @param hal Pointer to the HAL layer context 34 * @param config Pointer to config struct 35 */ 36 void xt_wdt_hal_init(xt_wdt_hal_context_t *hal, const xt_wdt_hal_config_t *config); 37 38 39 /** 40 * @brief Enable or disable the WDT 41 * 42 * @param hal Pointer to the HAL layer context 43 * @param enable true for enable WDT, false for disable 44 */ 45 void xt_wdt_hal_enable(xt_wdt_hal_context_t *hal, bool enable); 46 47 /** 48 * @brief Enable the automatic RTC backup clock with the given frequency 49 * 50 * Calculates and sets the necessary hardware parameters to meet the desired 51 * backup clock frequency 52 * 53 * @param hal Pointer to the HAL layer context 54 * @param rtc_clk_frequency_khz desired frequency for the backup clock 55 * @return uint32_t the calculated clock factor value 56 */ 57 uint32_t xt_wdt_hal_enable_backup_clk(xt_wdt_hal_context_t *hal, uint32_t rtc_clk_frequency_khz); 58 59 #ifdef __cplusplus 60 } 61 #endif 62