0
0
FreeRTOSprogramming~10 mins

Why tasks are the building blocks in FreeRTOS - Visual Breakdown

Choose your learning style9 modes available
Concept Flow - Why tasks are the building blocks
Start FreeRTOS Scheduler
Create Tasks
Each Task Runs Independently
Scheduler Switches Between Tasks
Tasks Communicate and Synchronize
System Performs Multiple Jobs Concurrently
This flow shows how FreeRTOS starts by creating tasks, each running independently, and the scheduler switches between them to perform multiple jobs at once.
Execution Sample
FreeRTOS
void Task1(void *pvParameters) {
  while(1) {
    // Do Task1 work
  }
}

void Task2(void *pvParameters) {
  while(1) {
    // Do Task2 work
  }
}
Two tasks run infinite loops doing their own work independently under FreeRTOS scheduler.
Execution Table
StepActionTask1 StateTask2 StateScheduler Behavior
1Start SchedulerReadyReadyScheduler starts and prepares tasks
2Run Task1RunningReadyScheduler runs Task1 first
3Task1 does workRunningReadyTask1 executes its code
4Switch to Task2ReadyRunningScheduler switches to Task2
5Task2 does workReadyRunningTask2 executes its code
6Switch back to Task1RunningReadyScheduler switches back to Task1
7Repeat switchingRunning/ReadyRunning/ReadyTasks run concurrently by switching
8System runs multiple tasksRunning/ReadyRunning/ReadyTasks are building blocks for multitasking
💡 FreeRTOS scheduler runs indefinitely switching between tasks to perform multitasking.
Variable Tracker
VariableStartAfter Step 2After Step 4After Step 6Final
Task1 StateReadyRunningReadyRunningRunning/Ready
Task2 StateReadyReadyRunningReadyRunning/Ready
Scheduler BehaviorIdleRuns Task1Switches to Task2Switches to Task1Switches tasks continuously
Key Moments - 3 Insights
Why does the scheduler switch between tasks instead of running one task fully first?
Because tasks run infinite loops, the scheduler must switch to give each task time to run, as shown in steps 4 and 6 in the execution_table.
Are tasks running at the same time or one after another?
Tasks appear to run at the same time by the scheduler switching quickly between them, not truly simultaneously, as seen in the alternating 'Running' states in the execution_table.
Why are tasks called building blocks in FreeRTOS?
Because each task does a part of the system's job independently and the scheduler combines them to do many jobs together, as summarized in step 8 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is Task1 state at Step 4?
AReady
BRunning
CBlocked
DSuspended
💡 Hint
Check the 'Task1 State' column at Step 4 in the execution_table.
At which step does the scheduler switch from Task1 to Task2?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Look at the 'Scheduler Behavior' column to find when switching happens.
If Task2 never yields, how would the scheduler behavior change in the table?
AScheduler keeps switching tasks normally
BScheduler stops running Task2
CScheduler runs Task2 continuously, Task1 stays Ready
DBoth tasks run simultaneously
💡 Hint
Think about what happens if one task never stops running in a multitasking system.
Concept Snapshot
FreeRTOS uses tasks as independent units of work.
Each task runs in a loop and the scheduler switches between them.
This switching creates multitasking on a single CPU.
Tasks are the building blocks because they let the system do many jobs.
Scheduler manages task states: Running, Ready, Blocked.
Without tasks, multitasking is not possible.
Full Transcript
In FreeRTOS, tasks are the basic units that do work. The scheduler starts and creates tasks, each running its own infinite loop. The scheduler switches between tasks to give each a chance to run. This switching is what creates multitasking. Tasks are called building blocks because each does part of the system's job independently. The execution table shows how Task1 and Task2 alternate running states as the scheduler switches between them. This switching continues indefinitely, allowing the system to perform multiple jobs at once. Beginners often wonder why the scheduler switches tasks instead of running one fully; the answer is tasks run forever, so switching is needed. Also, tasks don't run truly simultaneously but appear to by fast switching. If a task never yields, the scheduler runs it continuously, blocking others. Understanding tasks and scheduler behavior is key to mastering FreeRTOS multitasking.