Skip to content

Instantly share code, notes, and snippets.

@Lucianovici
Created February 23, 2019 21:43
Show Gist options
  • Save Lucianovici/1a671502438c92fc5c049dc0604eb73f to your computer and use it in GitHub Desktop.
Save Lucianovici/1a671502438c92fc5c049dc0604eb73f to your computer and use it in GitHub Desktop.
ESP32 Watchdog on two cores
/**
* Monopolizing two cores that should reset the watchdog timer.
*/
#include "esp_attr.h"
#include "esp_log.h"
#include "esp_system.h"
#include "esp_task_wdt.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "sdkconfig.h"
#define ESP_WDT_TIMEOUT_S 4
const char *TAG = "PoC";
void firstCore(void *args) {
ESP_ERROR_CHECK(esp_task_wdt_add(NULL));
ESP_ERROR_CHECK(esp_task_wdt_status(NULL));
for (uint32_t x = 0; x < UINT32_MAX; x++) {
ESP_ERROR_CHECK(esp_task_wdt_reset());
vTaskDelay(10 / portTICK_RATE_MS);
// This lets the the task scheduler to give time to the other task.
if (x % 1000 == 0) vTaskDelay(10/ portTICK_RATE_MS);
}
ESP_ERROR_CHECK(esp_task_wdt_delete(NULL));
}
void secondCore(void *args) {
ESP_ERROR_CHECK(esp_task_wdt_add(NULL));
ESP_ERROR_CHECK(esp_task_wdt_status(NULL));
for (uint32_t x = 0; x < UINT32_MAX; x++) {
ESP_ERROR_CHECK(esp_task_wdt_reset());
// This lets the the task scheduler to give time to the other task.
if (x % 1000 == 0) vTaskDelay(10 / portTICK_RATE_MS);
}
ESP_ERROR_CHECK(esp_task_wdt_delete(NULL));
}
extern "C" {
void app_main();
}
void app_main() {
vTaskDelay(2000 / portTICK_RATE_MS);
ESP_LOGI(TAG, "START app_main!");
ESP_ERROR_CHECK(esp_task_wdt_init(ESP_WDT_TIMEOUT_S, false));
xTaskCreatePinnedToCore(&firstCore, "firstCore", configMINIMAL_STACK_SIZE * 6, NULL, 2 | portPRIVILEGE_BIT, NULL, PRO_CPU_NUM);
xTaskCreatePinnedToCore(&secondCore, "secondCore", configMINIMAL_STACK_SIZE * 6, NULL, 2 | portPRIVILEGE_BIT, NULL, APP_CPU_NUM);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment