Esp32 dual core multi task and priorities
Posted: Wed Dec 28, 2022 1:20 am
task1 : webServerTask,
task2 : guiTask (use mutex)
I assigned task1 to cpu0 and task2 to cpu1 using the xTaskCreatePinnedToCore function in esp32. Then I expected task1 and task2 to run concurrently on each other’s cpu regardless of their respective priorities, isn’t that right?
If I increase the priority of task1 over task2, task2 will not run. If I set the priorities to be the same, both tasks will run. Even if I assign tasks to different CPUs, does the execution of the tasks differ according to their priority? Or is it related to the use of semaphore in task2?
Task1 and Task2 are implemented as below:
task2 : guiTask (use mutex)
I assigned task1 to cpu0 and task2 to cpu1 using the xTaskCreatePinnedToCore function in esp32. Then I expected task1 and task2 to run concurrently on each other’s cpu regardless of their respective priorities, isn’t that right?
If I increase the priority of task1 over task2, task2 will not run. If I set the priorities to be the same, both tasks will run. Even if I assign tasks to different CPUs, does the execution of the tasks differ according to their priority? Or is it related to the use of semaphore in task2?
Code: Select all
case 1: webServerTask run, guiTask does not work (priority: task1 > task2, task2 with mutex)
xTaskCreatePinnedToCore(webServerTask, "webServer", 4096, NULL, 2, NULL, 0);
xTaskCreatePinnedToCore(guiTask, "gui", 4096 * 2, NULL, 1, NULL, 1);
case 2: both webServerTask and guiTask run (priority: task1 = task2, task2 with mutex)
xTaskCreatePinnedToCore(webServerTask, "webServer", 4096, NULL, 1, NULL, 0);
xTaskCreatePinnedToCore(guiTask, "gui", 4096 * 2, NULL, 1, NULL, 1);
case 3: both webServerTask and guiTask run (priority: task1 > task2, task2 without mutex)
xTaskCreatePinnedToCore(webServerTask, "webServer", 4096, NULL, 2, NULL, 0);
xTaskCreatePinnedToCore(guiTask, "gui", 4096 * 2, NULL, 1, NULL, 1);
Code: Select all
static void webServerTask(void *pvParameters)
{
// initialize wifi and the web server
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
vTaskDelay(500 / portTICK_PERIOD_MS);
Serial.print(".");
}
// Run the web server loop indefinitely
while(1)
{
WiFiClient client = server.available();
if (client)
{
...
}
vTaskDelay(10 / portTICK_PERIOD_MS);
}
}
static void guiTask(void *pvParameter)
{
xGuiSemaphore = xSemaphoreCreateMutex();
... // display
while (1)
{
vTaskDelay(pdMS_TO_TICKS(10));
if (pdTRUE == xSemaphoreTake(xGuiSemaphore, portMAX_DELAY))
{
lv_task_handler();
xSemaphoreGive(xGuiSemaphore);
}
}
}