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

Conversation

sm-framerelay
Copy link

@sm-framerelay sm-framerelay commented Apr 16, 2017

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()

…ved out of main program loop into separate task
@sm-framerelay sm-framerelay changed the title To reduce calls to micros() in loopTask(). Proposal to move micros() call to separate task. To reduce calls to micros() in loopTask(). Proposal to move micros() call into separate task. Apr 16, 2017
@me-no-dev
Copy link
Member

I've tried that and it lead to issues. Also I do not want another task on that CPU that is spun all the time because it will lead to more issues with things like bitbang and others. Current implementation takes under 1us to execute and I do not think that it's a problem or clogging the CPU.

@me-no-dev me-no-dev closed this Aug 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants