0
0
FreeRTOSprogramming~10 mins

Task states (Ready, Running, Blocked, Suspended) in FreeRTOS - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Task states (Ready, Running, Blocked, Suspended)
Task Created
Ready State
Scheduler Picks Task
Running State
Blocked
Ready
Tasks move between states: Ready means waiting to run, Running means executing, Blocked means waiting for event/time, Suspended means paused by user. Scheduler controls transitions.
Execution Sample
FreeRTOS
void vTaskFunction(void *pvParameters) {
  for(;;) {
    // Running
    vTaskDelay(1000); // Blocked
  }
}
A task runs, then calls vTaskDelay to block itself for 1000 ticks, then becomes ready again after delay.
Execution Table
StepTask StateActionReason/TriggerNext State
1ReadyScheduler selects taskHighest priority ready taskRunning
2RunningTask executes codeNormal executionRunning
3RunningCalls vTaskDelay(1000)Task requests delayBlocked
4BlockedDelay timer counts downWaiting for 1000 ticksBlocked
5BlockedDelay expiresTimer reaches zeroReady
6ReadyScheduler selects task againTask is highest priority readyRunning
7RunningTask resumes executionAfter delayRunning
💡 Task cycles between Running, Blocked (delay), Ready states repeatedly as scheduler runs.
Variable Tracker
VariableStartAfter Step 3After Step 5After Step 7
Task StateReadyBlockedReadyRunning
Delay Timer0100000
Key Moments - 3 Insights
Why does the task move from Running to Blocked after calling vTaskDelay?
Because vTaskDelay makes the task wait for a set time, so it cannot run until the delay expires (see execution_table step 3).
What is the difference between Ready and Running states?
Ready means the task can run but is waiting for the CPU; Running means the task is currently executing (see steps 1 and 2).
How does a Suspended state differ from Blocked?
Suspended is paused by user action and won't run until resumed; Blocked waits for events or time and resumes automatically (not shown in sample but important).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the task state immediately after calling vTaskDelay?
ABlocked
BReady
CRunning
DSuspended
💡 Hint
Check execution_table row 3 where vTaskDelay is called and state changes.
At which step does the task become Ready again after being Blocked?
AStep 4
BStep 6
CStep 5
DStep 7
💡 Hint
Look for when the delay expires and task moves from Blocked to Ready in execution_table.
If the task never called vTaskDelay, which states would it cycle through?
ARunning and Blocked only
BReady and Running only
CBlocked and Suspended only
DSuspended and Ready only
💡 Hint
Refer to variable_tracker and execution_table showing delay causes Blocked state.
Concept Snapshot
Task states in FreeRTOS:
- Ready: waiting to run
- Running: currently executing
- Blocked: waiting for event/time
- Suspended: paused by user
Scheduler moves tasks between these states based on events and priorities.
Full Transcript
In FreeRTOS, tasks move through states: Ready means the task is waiting to run; Running means it is executing on the CPU. When a task calls vTaskDelay, it moves to Blocked state, waiting for the delay to expire. After the delay, it returns to Ready, waiting for the scheduler to run it again. Suspended state is when the task is paused by user action and won't run until resumed. The scheduler controls these transitions based on priorities and events.