diff --git a/components/task/include/task.hpp b/components/task/include/task.hpp index 9bfa990ea..72b499e62 100644 --- a/components/task/include/task.hpp +++ b/components/task/include/task.hpp @@ -228,6 +228,8 @@ class Task : public espp::BaseComponent { * @brief Start the task watchdog for this task. * @return true if the watchdog was started, false otherwise. * @note This function is only available on ESP + * @note This function will do nothing unless CONFIG_ESP_TASK_WDT_EN is + * enabled in the menuconfig. Default is y (enabled). */ bool start_watchdog(); @@ -235,6 +237,8 @@ class Task : public espp::BaseComponent { * @brief Stop the task watchdog for this task. * @return true if the watchdog was stopped, false otherwise. * @note This function is only available on ESP + * @note This function will do nothing unless CONFIG_ESP_TASK_WDT_EN is + * enabled in the menuconfig. Default is y (enabled). */ bool stop_watchdog(); @@ -244,6 +248,8 @@ class Task : public espp::BaseComponent { * @param panic_on_timeout Whether or not to panic on timeout. * @return true if the watchdog was initialized, false otherwise. * @note This function is only available on ESP + * @note This function will do nothing unless CONFIG_ESP_TASK_WDT_EN is + * enabled in the menuconfig. Default is y (enabled). * @note This function will not monitor the idle tasks. * @note If the watchdog has not been configured, then this function will call * `esp_task_wdt_init`, otherwise it will then call @@ -257,6 +263,8 @@ class Task : public espp::BaseComponent { * @param panic_on_timeout Whether or not to panic on timeout. * @return true if the watchdog was initialized, false otherwise. * @note This function is only available on ESP + * @note This function will do nothing unless CONFIG_ESP_TASK_WDT_EN is + * enabled in the menuconfig. Default is y (enabled). * @note This function will not monitor the idle tasks. * @note If the watchdog has not been configured, then this function will call * `esp_task_wdt_init`, otherwise it will then call @@ -272,6 +280,8 @@ class Task : public espp::BaseComponent { * @return std::string containing the task watchdog info, or an empty string * if there was no timeout or there was an error retrieving the info. * @note This function is only available on ESP + * @note This function will do nothing unless CONFIG_ESP_TASK_WDT_EN is + * enabled in the menuconfig. Default is y (enabled). * @note This function will only return info for tasks which are still * registered with the watchdog. If you call this after you have called * stop_watchdog() for a task, then even if the task triggered the @@ -295,7 +305,7 @@ class Task : public espp::BaseComponent { * @note This function is only available on ESP */ static std::string get_info(const Task &task); -#endif +#endif // ESP_PLATFORM /** * @brief Get the ID for this Task's thread / task context. diff --git a/components/task/src/task.cpp b/components/task/src/task.cpp index 6b2488f07..a8f30e23d 100644 --- a/components/task/src/task.cpp +++ b/components/task/src/task.cpp @@ -108,6 +108,10 @@ bool Task::stop() { #if defined(ESP_PLATFORM) bool Task::start_watchdog() { +#if !CONFIG_ESP_TASK_WDT_EN + logger_.debug("Watchdog not enabled in the configuration, cannot start watchdog!"); + return false; +#else if (!started_) { logger_.warn("Task not started, cannot start watchdog!"); return false; @@ -131,9 +135,14 @@ bool Task::start_watchdog() { // everything is good, set the flag watchdog_started_ = true; return true; +#endif // CONFIG_ESP_TASK_WDT_EN } bool Task::stop_watchdog() { +#if !CONFIG_ESP_TASK_WDT_EN + logger_.debug("Watchdog not enabled in the configuration, cannot stop watchdog!"); + return false; +#else if (!watchdog_started_) { logger_.debug("Watchdog already stopped!"); return false; @@ -152,9 +161,13 @@ bool Task::stop_watchdog() { logger_.error("Failed to stop watchdog for task '{}'", name_); } return err == ESP_OK; +#endif // CONFIG_ESP_TASK_WDT_EN } bool Task::configure_task_watchdog(uint32_t timeout_ms, bool panic_on_timeout) { +#if !CONFIG_ESP_TASK_WDT_EN + return false; +#else esp_task_wdt_config_t config; memset(&config, 0, sizeof(config)); config.timeout_ms = timeout_ms; @@ -171,6 +184,7 @@ bool Task::configure_task_watchdog(uint32_t timeout_ms, bool panic_on_timeout) { return false; } return err == ESP_OK; +#endif // CONFIG_ESP_TASK_WDT_EN } bool Task::configure_task_watchdog(const std::chrono::milliseconds &timeout, @@ -179,6 +193,10 @@ bool Task::configure_task_watchdog(const std::chrono::milliseconds &timeout, } std::string Task::get_watchdog_info(std::error_code &ec) { +#if !CONFIG_ESP_TASK_WDT_EN + ec = std::make_error_code(std::errc::operation_not_supported); + return ""; +#else std::string info = ""; auto err = esp_task_wdt_print_triggered_tasks( [](void *arg, const char *msg) { @@ -192,8 +210,9 @@ std::string Task::get_watchdog_info(std::error_code &ec) { ec = std::make_error_code(std::errc::io_error); } return info; +#endif // CONFIG_ESP_TASK_WDT_EN } -#endif +#endif // ESP_PLATFORM void Task::notify_and_join() { { @@ -256,7 +275,7 @@ void Task::thread_function() { started_ = false; break; } -#if defined(ESP_PLATFORM) +#if defined(ESP_PLATFORM) && CONFIG_ESP_TASK_WDT_EN // check if the watchdog is enabled if (watchdog_started_) { auto err = esp_task_wdt_reset(); diff --git a/components/timer/include/high_resolution_timer.hpp b/components/timer/include/high_resolution_timer.hpp index 936a36a00..53c826ccf 100644 --- a/components/timer/include/high_resolution_timer.hpp +++ b/components/timer/include/high_resolution_timer.hpp @@ -74,11 +74,15 @@ class HighResolutionTimer : public espp::BaseComponent { /// Start the watchdog timer /// @return True if the watchdog timer was started successfully, false /// otherwise + /// @note This function will do nothing unless CONFIG_ESP_TASK_WDT_EN is + /// enabled in the menuconfig. Default is y (enabled). bool start_watchdog(); /// Stop the watchdog timer /// @return True if the watchdog timer was stopped successfully, false /// otherwise + /// @note This function will do nothing unless CONFIG_ESP_TASK_WDT_EN is + /// enabled in the menuconfig. Default is y (enabled). bool stop_watchdog(); /// Check if the timer is running diff --git a/components/timer/include/timer.hpp b/components/timer/include/timer.hpp index 90030c151..306b0078a 100644 --- a/components/timer/include/timer.hpp +++ b/components/timer/include/timer.hpp @@ -122,6 +122,8 @@ class Timer : public BaseComponent { /// @brief Start the task watchdog for the timer. /// @return true if the watchdog was started, false otherwise. /// @note This function is only available on ESP + /// @note This function will do nothing unless CONFIG_ESP_TASK_WDT_EN is + /// enabled in the menuconfig. Default is y (enabled). /// @see stop_watchdog() /// @see Task::start_watchdog() /// @see Task::stop_watchdog() @@ -130,11 +132,13 @@ class Timer : public BaseComponent { /// @brief Stop the task watchdog for the timer. /// @return true if the watchdog was stopped, false otherwise. /// @note This function is only available on ESP + /// @note This function will do nothing unless CONFIG_ESP_TASK_WDT_EN is + /// enabled in the menuconfig. Default is y (enabled). /// @see start_watchdog() /// @see Task::start_watchdog() /// @see Task::stop_watchdog() bool stop_watchdog(); -#endif +#endif // ESP_PLATFORM || _DOXYGEN_ /// @brief Set the period of the timer. /// @details Sets the period of the timer. diff --git a/components/timer/src/high_resolution_timer.cpp b/components/timer/src/high_resolution_timer.cpp index c4f560acb..2b0f53860 100644 --- a/components/timer/src/high_resolution_timer.cpp +++ b/components/timer/src/high_resolution_timer.cpp @@ -60,6 +60,10 @@ bool HighResolutionTimer::start(uint64_t period_us, bool oneshot) { } bool HighResolutionTimer::start_watchdog() { +#if !CONFIG_ESP_TASK_WDT_EN + logger_.debug("Watchdog timer not enabled in sdkconfig"); + return false; +#else if (wdt_handle_) { logger_.debug("Watchdog timer already running"); return false; @@ -75,9 +79,14 @@ bool HighResolutionTimer::start_watchdog() { return false; } return true; +#endif // CONFIG_ESP_TASK_WDT_EN } bool HighResolutionTimer::stop_watchdog() { +#if !CONFIG_ESP_TASK_WDT_EN + logger_.debug("Watchdog timer not enabled in sdkconfig"); + return false; +#else if (!wdt_handle_) { logger_.debug("Watchdog timer not running"); return false; @@ -89,6 +98,7 @@ bool HighResolutionTimer::stop_watchdog() { } wdt_handle_ = nullptr; return true; +#endif // CONFIG_ESP_TASK_WDT_EN } bool HighResolutionTimer::oneshot(uint64_t timeout_us) { return start(timeout_us, true); } @@ -157,7 +167,9 @@ void HighResolutionTimer::handle_timer_callback() { if (callback_) { callback_(); } +#if CONFIG_ESP_TASK_WDT_EN if (wdt_handle_) { esp_task_wdt_reset_user(wdt_handle_); } +#endif // CONFIG_ESP_TASK_WDT_EN }