esp_xt_wdt.h 1.6 KB

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