esp_task_wdt.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include "freertos/FreeRTOS.h"
  16. #include "freertos/task.h"
  17. #include "esp_err.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /**
  22. * @brief Initialize the Task Watchdog Timer (TWDT)
  23. *
  24. * This function configures and initializes the TWDT. If the TWDT is already
  25. * initialized when this function is called, this function will update the
  26. * TWDT's timeout period and panic configurations instead. After initializing
  27. * the TWDT, any task can elect to be watched by the TWDT by subscribing to it
  28. * using esp_task_wdt_add().
  29. *
  30. * @param[in] timeout Timeout period of TWDT in seconds
  31. * @param[in] panic Flag that controls whether the panic handler will be
  32. * executed when the TWDT times out
  33. *
  34. * @return
  35. * - ESP_OK: Initialization was successful
  36. * - ESP_ERR_NO_MEM: Initialization failed due to lack of memory
  37. *
  38. * @note esp_task_wdt_init() must only be called after the scheduler
  39. * started
  40. */
  41. esp_err_t esp_task_wdt_init(uint32_t timeout, bool panic);
  42. /**
  43. * @brief Deinitialize the Task Watchdog Timer (TWDT)
  44. *
  45. * This function will deinitialize the TWDT. Calling this function whilst tasks
  46. * are still subscribed to the TWDT, or when the TWDT is already deinitialized,
  47. * will result in an error code being returned.
  48. *
  49. * @return
  50. * - ESP_OK: TWDT successfully deinitialized
  51. * - ESP_ERR_INVALID_STATE: Error, tasks are still subscribed to the TWDT
  52. * - ESP_ERR_NOT_FOUND: Error, TWDT has already been deinitialized
  53. */
  54. esp_err_t esp_task_wdt_deinit(void);
  55. /**
  56. * @brief Subscribe a task to the Task Watchdog Timer (TWDT)
  57. *
  58. * This function subscribes a task to the TWDT. Each subscribed task must
  59. * periodically call esp_task_wdt_reset() to prevent the TWDT from elapsing its
  60. * timeout period. Failure to do so will result in a TWDT timeout. If the task
  61. * being subscribed is one of the Idle Tasks, this function will automatically
  62. * enable esp_task_wdt_reset() to called from the Idle Hook of the Idle Task.
  63. * Calling this function whilst the TWDT is uninitialized or attempting to
  64. * subscribe an already subscribed task will result in an error code being
  65. * returned.
  66. *
  67. * @param[in] handle Handle of the task. Input NULL to subscribe the current
  68. * running task to the TWDT
  69. *
  70. * @return
  71. * - ESP_OK: Successfully subscribed the task to the TWDT
  72. * - ESP_ERR_INVALID_ARG: Error, the task is already subscribed
  73. * - ESP_ERR_NO_MEM: Error, could not subscribe the task due to lack of
  74. * memory
  75. * - ESP_ERR_INVALID_STATE: Error, the TWDT has not been initialized yet
  76. */
  77. esp_err_t esp_task_wdt_add(TaskHandle_t handle);
  78. /**
  79. * @brief Reset the Task Watchdog Timer (TWDT) on behalf of the currently
  80. * running task
  81. *
  82. * This function will reset the TWDT on behalf of the currently running task.
  83. * Each subscribed task must periodically call this function to prevent the
  84. * TWDT from timing out. If one or more subscribed tasks fail to reset the
  85. * TWDT on their own behalf, a TWDT timeout will occur. If the IDLE tasks have
  86. * been subscribed to the TWDT, they will automatically call this function from
  87. * their idle hooks. Calling this function from a task that has not subscribed
  88. * to the TWDT, or when the TWDT is uninitialized will result in an error code
  89. * being returned.
  90. *
  91. * @return
  92. * - ESP_OK: Successfully reset the TWDT on behalf of the currently
  93. * running task
  94. * - ESP_ERR_NOT_FOUND: Error, the current running task has not subscribed
  95. * to the TWDT
  96. * - ESP_ERR_INVALID_STATE: Error, the TWDT has not been initialized yet
  97. */
  98. esp_err_t esp_task_wdt_reset(void);
  99. /**
  100. * @brief Unsubscribes a task from the Task Watchdog Timer (TWDT)
  101. *
  102. * This function will unsubscribe a task from the TWDT. After being
  103. * unsubscribed, the task should no longer call esp_task_wdt_reset(). If the
  104. * task is an IDLE task, this function will automatically disable the calling
  105. * of esp_task_wdt_reset() from the Idle Hook. Calling this function whilst the
  106. * TWDT is uninitialized or attempting to unsubscribe an already unsubscribed
  107. * task from the TWDT will result in an error code being returned.
  108. *
  109. * @param[in] handle Handle of the task. Input NULL to unsubscribe the
  110. * current running task.
  111. *
  112. * @return
  113. * - ESP_OK: Successfully unsubscribed the task from the TWDT
  114. * - ESP_ERR_INVALID_ARG: Error, the task is already unsubscribed
  115. * - ESP_ERR_INVALID_STATE: Error, the TWDT has not been initialized yet
  116. */
  117. esp_err_t esp_task_wdt_delete(TaskHandle_t handle);
  118. /**
  119. * @brief Query whether a task is subscribed to the Task Watchdog Timer (TWDT)
  120. *
  121. * This function will query whether a task is currently subscribed to the TWDT,
  122. * or whether the TWDT is initialized.
  123. *
  124. * @param[in] handle Handle of the task. Input NULL to query the current
  125. * running task.
  126. *
  127. * @return:
  128. * - ESP_OK: The task is currently subscribed to the TWDT
  129. * - ESP_ERR_NOT_FOUND: The task is currently not subscribed to the TWDT
  130. * - ESP_ERR_INVALID_STATE: The TWDT is not initialized, therefore no tasks
  131. * can be subscribed
  132. */
  133. esp_err_t esp_task_wdt_status(TaskHandle_t handle);
  134. #ifdef __cplusplus
  135. }
  136. #endif