My code uses both cores of the ESP32 and seems to work well. I have pinned one task to each core with infinite loops. However, the loops don't have delay() or vTaskDelay() in them and I was wondering if that would cause issues with the pinned tasks blocking other system/housekeeping tasks from executing, as discussed in this thread.
(ESP32 - using 2nd core)
Unlike the code in the above thread though, I don't have delay() or vTaskDelay() in my code, and I am still not facing any reboot issues. So, even though Task1 and Task2 never finish, are the tasks yielding between each iteration of the for(;;) loops and letting the system /housekeeping tasks run?
A sketch of my code is below (based on this). Also, loop() is empty following the advice in the thread above.
TaskHandle_t Task1, Task2;
long t1 = 0;
long t2 = 0;
void Task1code(void *parameter) {
for (;;) {
if (millis() - t1 > 20) {
t1 = millis();
// CODE TO BE EXECUTED EVERY 20ms
// ...
// Should I add vTaskDelay() here?
}
}
}
void Task2code(void *parameter) {
for (;;) {
if (millis() - t2 > 30) {
t2 = millis();
// CODE TO BE EXECUTED EVERY 30ms
// ...
// Should I add vTaskDelay() here?
}
}
}
xTaskCreatePinnedToCore(
Task1code, /* Task function. */
"Task1", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
1, /* priority of the task */
&Task1, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
xTaskCreatePinnedToCore(
Task2code, /* Task function. */
"Task2", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
1, /* priority of the task */
&Task2, /* Task handle to keep track of created task */
1); /* pin task to core 1 */