Skip to content

To reduce calls to micros() in loopTask(). Proposal to move micros() call into separate task. #317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions cores/esp32/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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