To reduce calls to micros() in loopTask(). Proposal to move micros() call into separate task. #317
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Guys thanks for your work, the arduino-esp32 is the rock!
Maybe I am wrong, but I suppose we can decrease the load on CPU core by removing constant call in infinity loop to micros() in loopTask() which is defined in \cores\esp32\main.cpp
void loopTask(void *pvParameters)
{
setup();
for(;;) {
micros(); //update overflow << -- This one might be moved out into separate task
loop();
}
}
The idea is to move micros() call into separate task with high priority, which optionally might be run on second core.
Please check the possible solution:
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
}
}
In this case we will be sure that we won't miss micros() overflow, because standard overflow cycle at 240Mhz is 178956970.625 uS, so the half of them will be enough to check.
Also please note, using existing code in /master without the patch proposed above we have potential issue which might appear if someone try to set vTaskDelay() for more than 17 sec in main loop()