From 7532796847fe915f32cb2f20433541a097f8fbdb Mon Sep 17 00:00:00 2001 From: smelnyk Date: Sun, 16 Apr 2017 14:01:34 +0300 Subject: [PATCH] Power consumption optimization. Infinity micros() calling has been moved out of main program loop into separate task --- cores/esp32/main.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/cores/esp32/main.cpp b/cores/esp32/main.cpp index 6afea108f17..460684b0a1a 100644 --- a/cores/esp32/main.cpp +++ b/cores/esp32/main.cpp @@ -14,15 +14,30 @@ void loopTask(void *pvParameters) { setup(); for(;;) { - micros(); //update overflow loop(); } } +void vMicrosOverflowTask(void *pvParameters) +{ + // In order no to miss overflow it will be enought to check micros() each half of full overflow + static const uint32_t taskDelayMs = UINT32_MAX + / CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ // one full overflow occurs in uS + / 1000 // in millisec + / 2 // half of full overflow cycle + / portTICK_PERIOD_MS; // RTOS const to convert in ms + + for (;;){ + micros(); //update overflow + vTaskDelay(taskDelayMs); // ~ each 9 sec at 240Mhz + } +} + extern "C" void app_main() { initArduino(); - xTaskCreatePinnedToCore(loopTask, "loopTask", 4096, NULL, 1, NULL, ARDUINO_RUNNING_CORE); + xTaskCreatePinnedToCore(vMicrosOverflowTask, "microsTask", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL, ARDUINO_RUNNING_CORE); + xTaskCreatePinnedToCore(loopTask, "loopTask", 4096, NULL, 1, NULL, ARDUINO_RUNNING_CORE); } #endif