#include "Dezibot.h" #include "esp_pm.h" #include "esp_task_wdt.h" Dezibot dezibot; const uint16_t cycleTime = 20e3; esp_pm_lock_handle_t cpuFreqLock; esp_pm_lock_handle_t apbFreqLock; esp_pm_lock_handle_t lightSleepLock; static bool pmLocksCreated = false; void stress_task(void *pvParameters) { // Register with task watchdog ESP_ERROR_CHECK(esp_task_wdt_add(NULL)); // Variables for load generation volatile uint32_t x = 0; TickType_t last_wake_time = xTaskGetTickCount(); while (1) { // Compute-intensive period for (uint32_t i = 0; i < 10000; i++) { x += i; // Mix in some memory operations if (i % 100 == 0) { // Force cache misses occasionally void* temp = malloc(32); if (temp) { free(temp); } } } // Reset watchdog ESP_ERROR_CHECK(esp_task_wdt_reset()); } } void setup() { Serial.begin(115200); // while (!Serial) { // ; // } uint32_t Freq = getCpuFrequencyMhz(); Serial.print("CPU Freq = "); Serial.print(Freq); Serial.println(" MHz"); Freq = getXtalFrequencyMhz(); Serial.print("XTAL Freq = "); Serial.print(Freq); Serial.println(" MHz"); Freq = getApbFrequency(); Serial.print("APB Freq = "); Serial.print(Freq); Serial.println(" Hz"); // Create lock handles for controlling power management features // Parameter arg is always unused and should thus be set to 0 // Ref: https://docs.espressif.com/projects/esp-idf/en/v3.3.6/api-reference/system/power_management.html#enumerations if (!pmLocksCreated) { bool cpuFreqLockSuccess = esp_pm_lock_create(ESP_PM_CPU_FREQ_MAX, 0, "CPU_FREQ_MAX", &cpuFreqLock); bool apbFreqLockSuccess = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "APB_FREQ_MAX", &apbFreqLock); bool lightSleepLockSuccess = esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "NO_LIGHT_SLEEP", &lightSleepLock); if ((cpuFreqLockSuccess && apbFreqLockSuccess && lightSleepLockSuccess)) { pmLocksCreated = true; Serial.println("Sucessfully created handles to control power management features."); } else { Serial.println("Failed to create handles to control power management features!"); } } else { Serial.println("Powermanagement lock handles already created, skipping creation!"); } // Configure Task Watchdog so it does not interfere esp_task_wdt_config_t twdt_config = { .timeout_ms = 30000, .idle_core_mask = (1 << portNUM_PROCESSORS) - 1, .trigger_panic = true }; if (esp_task_wdt_reconfigure(&twdt_config) != ESP_OK) { Serial.println("Failed to reconfigure task watchdog!"); } delay(500); Serial.flush(); Serial.end(); } void blip_io(int times) { constexpr int ioPin = 17; pinMode(ioPin, OUTPUT); for(int i = 0; i