#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_task_wdt.h"
void app_main() {
printf("Hello, Wokwi!\n");
esp_task_wdt_user_handle_t user_handle = NULL; // <-- move here, before if/else
// Get the reset reason
esp_reset_reason_t reset_reason = esp_reset_reason();
// Check if reset was caused by task watchdog
if (reset_reason == ESP_RST_TASK_WDT) {
printf("success\n");
} else {
printf("Reset reason: %d (not task WDT)\n", reset_reason);
printf("Setting up watchdog to trigger...\n");
// Configure the task watchdog with 2 second timeout
esp_task_wdt_config_t wdt_config = {
.timeout_ms = 2000,
.trigger_panic = false // This will cause panic and restart
};
esp_task_wdt_reconfigure(&wdt_config);
// Add user "42" to the watchdog
//esp_task_wdt_user_handle_t user_handle;
esp_task_wdt_add_user("42", &user_handle);
printf("Watchdog user '42' added. Feeding watchdog for 5 seconds...\n");
for (int i = 0; i < 5; i++) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
esp_task_wdt_reset_user(user_handle);
}
printf("Stopped feeding watchdog. Will trigger in 2 seconds...\n");
}
bool deleted = false;
bool reset = false;
while (true) {
vTaskDelay(4000 / portTICK_PERIOD_MS);
// Intentionally not calling esp_task_wdt_reset_user to trigger the watchdog
printf("Loop..\n");
if (!reset) {
esp_task_wdt_reset_user(user_handle);
reset = true;
}
if (!deleted) {
esp_task_wdt_delete_user(user_handle);
deleted = true;
}
vTaskDelay(1000 / portTICK_PERIOD_MS);
// Intentionally not calling esp_task_wdt_reset_user to trigger the watchdog
printf("Loop..\n");
}
}Loading
esp32-p4-function-ev
esp32-p4-function-ev