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 <stdint.h> 10 11 #include "esp_err.h" 12 #include "esp_intr_alloc.h" 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 /** 19 * @brief esp_xt_wdt configuration struct 20 * 21 */ 22 typedef struct { 23 uint8_t timeout; /*!< Watchdog timeout */ 24 bool auto_backup_clk_enable; /*!< Enable automatic switch to backup clock at timeout */ 25 } esp_xt_wdt_config_t; 26 27 /* Callback function for WDT interrupt*/ 28 typedef void (*esp_xt_callback_t)(void *arg); 29 30 /** 31 * @brief Initializes the xtal32k watchdog timer 32 * 33 * @param cfg Pointer to configuration struct 34 * @return esp_err_t 35 * - ESP_OK: XTWDT was successfully enabled 36 * - ESP_ERR_NO_MEM: Failed to allocate ISR 37 */ 38 esp_err_t esp_xt_wdt_init(const esp_xt_wdt_config_t *cfg); 39 40 /** 41 * @brief Register a callback function that will be called when the watchdog 42 * times out. 43 * 44 * @note This function will be called from an interrupt context where the cache might be disabled. 45 * Thus the function should be placed in IRAM and must not perform any blocking operations. 46 * 47 * Only one callback function can be registered, any call to esp_xt_wdt_register_callback 48 * will override the previous callback function. 49 * 50 * @param func The callback function to register 51 * @param arg Pointer to argument that will be passed to the callback function 52 */ 53 void esp_xt_wdt_register_callback(esp_xt_callback_t func, void *arg); 54 55 /** 56 * @brief Restores the xtal32k clock and re-enables the WDT 57 * 58 */ 59 void esp_xt_wdt_restore_clk(void); 60 61 #ifdef __cplusplus 62 } 63 #endif 64