log watchdog

This commit is contained in:
oarcher 2024-07-21 22:21:03 +02:00
parent d0cefb4a08
commit f6e67462e7
2 changed files with 38 additions and 17 deletions

View file

@ -1,10 +1,42 @@
#ifdef USE_ESP_IDF #ifdef USE_ESP_IDF
#include "modem_component.h" #include "modem_component.h"
#include "helpers.h"
#include "esphome/core/log.h"
#include "esphome/core/application.h"
#include <esp_idf_version.h>
#include <esp_task_wdt.h>
namespace esphome { namespace esphome {
namespace modem { namespace modem {
Watchdog::Watchdog(u_int32_t timeout_s) {
this->timeout_s_ = timeout_s;
this->start_time_ms_ = millis();
this->set_wdt_(timeout_s);
ESP_LOGV(TAG, "Watchog timeout init: %ds", timeout_s);
}
Watchdog::~Watchdog() {
this->set_wdt_(CONFIG_TASK_WDT_TIMEOUT_S);
ESP_LOGV(TAG, "Watchog timeout reset to default after %.1fs", float(millis() - this->start_time_ms_) / 1000);
}
void Watchdog::set_wdt_(uint32_t timeout_s) {
#if ESP_IDF_VERSION_MAJOR >= 5
esp_task_wdt_config_t wdt_config = {
.timeout_ms = timeout_s * 1000,
.idle_core_mask = 0x03,
.trigger_panic = true,
};
esp_task_wdt_reconfigure(&wdt_config);
#else
esp_task_wdt_init(timeout_s, true);
#endif // ESP_IDF_VERSION_MAJOR
}
std::string command_result_to_string(command_result err) { std::string command_result_to_string(command_result err) {
std::string res = "UNKNOWN"; std::string res = "UNKNOWN";
switch (err) { switch (err) {

View file

@ -6,9 +6,6 @@
#include <cxx_include/esp_modem_api.hpp> #include <cxx_include/esp_modem_api.hpp>
#include <esp_idf_version.h>
#include <esp_task_wdt.h>
namespace esphome { namespace esphome {
namespace modem { namespace modem {
@ -20,23 +17,15 @@ std::string state_to_string(ModemComponentState state);
// When deleted, will restore default WDT // When deleted, will restore default WDT
class Watchdog { class Watchdog {
public: public:
Watchdog(int timeout_s) { this->set_wdt_(timeout_s); } Watchdog(u_int32_t timeout_s);
~Watchdog() { this->set_wdt_(CONFIG_TASK_WDT_TIMEOUT_S); } ~Watchdog();
private: private:
void set_wdt_(uint32_t timeout_s) { uint32_t timeout_s_;
#if ESP_IDF_VERSION_MAJOR >= 5 uint64_t start_time_ms_;
esp_task_wdt_config_t wdt_config = {
.timeout_ms = timeout_s * 1000, void set_wdt_(uint32_t timeout_s);
.idle_core_mask = 0x03,
.trigger_panic = true,
};
esp_task_wdt_reconfigure(&wdt_config);
#else
esp_task_wdt_init(timeout_s, true);
#endif // ESP_IDF_VERSION_MAJOR
}
}; };
} // namespace modem } // namespace modem