ESP32 Arduino understanding FreeRTOS

Thread Starter

zazas321

Joined Nov 29, 2015
913
Hello. I have a question regarding to FreeRTOS on arduino. I just recently came up with this problem in my head and since then I cannot cannot stand still unless I figure out exactly how it works.

Lets imagine I have registered 2 tasks:
task1 - Imagine the task1 has the highest priority and is repeatedly being called every 10ms and it takes 5ms to complete.
task2 - Task2 has lower priority repeatedly being called every 100ms and it takes 10ms to complete.
QUESTIONS:
1.Does that mean that task2 will never get executed????? Imagine a scenario where task2 is started but since it takes 10ms to execute, task1 is going to interrupt it because it is being called every 10ms and it has higher priority?

2. What if I have 2 tasks on the same priority and they are being called repeatedly. Every 100ms. Lets say for whatever reason task1 takes long time to complete lets say 50ms, is there any chance that this task will be interrupted by task2 or the scheduler must wait for it to finish even though it will take longer than 100ms?



Please help me understand how FreeRTOS works..

Code:
// Now set up two tasks to run independently.
  xTaskCreatePinnedToCore(
    task1
    ,  "task"   // A name just for humans
    ,  1024  // This stack size can be checked & adjusted by reading the Stack Highwater
    ,  NULL
    ,  3  // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
    ,  NULL
    ,  ARDUINO_RUNNING_CORE);

  xTaskCreatePinnedToCore(
    task2
    ,  "task2"
    ,  1024  // Stack size
    ,  NULL
    ,  1  // Priority
    ,  NULL
    ,  ARDUINO_RUNNING_CORE);

  // Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started.
}


void task1(void *parameters){
    vTaskDelay(10); // lets say this is 10ms
    //Lets imagine this task is doing something and it takes 5ms to fully complete
    delay(5);


}

void task2(void *parameters){
    vTaskDelay(100);
    //lets say t his is another random task and it takes 10ms seconds to complete
     delay(10);
}
 
Top