Merge pull request #13411 from s-hadinger/twdt_to_tasmota

Move TWDT watchdog from esp-idf to Tasmota
This commit is contained in:
Theo Arends 2021-10-21 16:59:39 +02:00 committed by GitHub
commit af85cbedb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 0 deletions

View File

@ -348,6 +348,7 @@
#define ZIGBEE_DISTINCT_TOPICS false // [SetOption89] Enable unique device topic based on Zigbee device ShortAddr
#define ZIGBEE_RMV_ZBRECEIVED false // [SetOption100] Remove ZbReceived form JSON message
#define ZIGBEE_INDEX_EP false // [SetOption101] Add the source endpoint as suffix to attributes, ex `Power3` instead of `Power` if sent from endpoint 3
#define WATCHDOG_TASK_SECONDS 5 // [ESP32 only] Task Watchdog Timer (TWDT) time in seconds - detecting Tasmota running for a prolonged period of time without yielding with `esp_task_wdt_reset()`
/*********************************************************************************************\
* END OF SECTION 1

View File

@ -66,6 +66,35 @@ void OsWatchTicker(void)
}
}
#ifdef ESP32
#include "esp_task_wdt.h"
void TWDTInit(void) {
// enable Task Watchdog Timer
esp_task_wdt_init(WATCHDOG_TASK_SECONDS, true);
// if (ret != ESP_OK) { AddLog(LOG_LEVEL_ERROR, "HDW: cannot init Task WDT %i", ret); }
esp_task_wdt_add(nullptr);
// if (ret != ESP_OK) { AddLog(LOG_LEVEL_ERROR, "HDW: cannot start Task WDT %i", ret); }
}
void TWDTRestore(void) {
// restore default WDT values
esp_task_wdt_init(WATCHDOG_TASK_SECONDS, false);
}
void TWDTLoop(void) {
esp_task_wdt_reset();
}
// custom handler
extern "C" {
void __attribute__((weak)) esp_task_wdt_isr_user_handler(void)
{
Serial.printf(">>>>>----------\n");
}
}
#endif
void OsWatchInit(void)
{
oswatch_blocked_loop = RtcSettings.oswatch_blocked_loop;

View File

@ -317,6 +317,9 @@ void setup(void) {
SettingsLoad();
SettingsDelta();
#ifdef ESP32
TWDTInit(); // Start Task WDT for ESP32 - FreeRTOS only
#endif
OsWatchInit();
TasmotaGlobal.seriallog_level = Settings->seriallog_level;
@ -509,6 +512,9 @@ void Scheduler(void) {
#endif // USE_DISCOVERY
#endif // ESP8266
#ifdef ESP32
TWDTLoop();
#endif
OsWatchLoop();
ButtonLoop();
SwitchLoop();

View File

@ -2794,6 +2794,9 @@ void HandleUploadLoop(void) {
Web.upload_error = 2; // Not enough space
return;
}
#ifdef ESP32
TWDTLoop();
#endif
if (upload.totalSize && !(upload.totalSize % 102400)) {
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPLOAD "Progress %d kB"), upload.totalSize / 1024);
}

View File

@ -308,6 +308,7 @@ extern "C" {
// ESP object
int32_t l_yield(bvm *vm);
int32_t l_yield(bvm *vm) {
TWDTLoop(); // reset watchdog
BrTimeoutYield(); // reset timeout
be_return_nil(vm);
}
@ -545,6 +546,8 @@ void berry_log(const char * berry_buf) {
if (berry.log.log.length() >= BERRY_MAX_LOGS) {
berry.log.log.remove(berry.log.log.head());
}
} else {
TWDTLoop(); // if REPL, printing resets the WDT
}
// AddLog(LOG_LEVEL_INFO, PSTR("[Add to log] %s"), berry_buf);
berry.log.addString(berry_buf, pre_delimiter, "\n");