0
0
FreeRTOSprogramming~10 mins

Real-time vs general-purpose OS in FreeRTOS - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - Real-time vs general-purpose OS
Start
Choose OS Type
General-purpose OS
Handles many tasks
May delay tasks
End
This flow shows the choice between general-purpose and real-time OS, highlighting their task handling and timing guarantees.
Execution Sample
FreeRTOS
void taskA(void *params) {
  while(1) {
    // Do work
    vTaskDelay(100 / portTICK_PERIOD_MS);
  }
}

void taskB(void *params) {
  TickType_t lastWakeTime = 0;
  while(1) {
    // Do time-critical work
    vTaskDelayUntil(&lastWakeTime, 50 / portTICK_PERIOD_MS);
  }
}
Two FreeRTOS tasks: taskA uses general delay, taskB uses precise periodic delay for real-time behavior.
Execution Table
StepTaskActionTiming BehaviorResult
1taskAStart loopDelays 100ms after workRuns work, then delays
2taskBStart loopDelays precisely every 50msRuns work exactly on schedule
3taskAAfter delayMay be delayed by other tasksRuns next work cycle
4taskBAfter delayUntilWakes exactly at next 50ms intervalRuns next work cycle on time
5taskARepeatTiming less strictPossible jitter in execution
6taskBRepeatStrict timing maintainedConsistent periodic execution
7ExitN/AInfinite loops, no exitTasks run indefinitely
💡 Tasks run infinite loops; no natural exit, showing continuous scheduling differences.
Variable Tracker
VariableStartAfter 1After 2After 3Final
taskA_delay100ms100ms100ms100ms100ms
taskB_lastWakeTime0ms50ms100ms150mscontinues increasing
Key Moments - 3 Insights
Why does taskB use vTaskDelayUntil instead of vTaskDelay?
vTaskDelayUntil keeps the task running at precise intervals (see execution_table rows 2 and 4), ensuring real-time timing, unlike vTaskDelay which can accumulate delays.
Can taskA guarantee exact timing like taskB?
No, taskA uses vTaskDelay which waits a fixed time after finishing work, so delays from other tasks can cause timing jitter (see execution_table rows 1 and 3).
Why do both tasks run infinite loops?
In FreeRTOS, tasks often run forever to keep doing their jobs repeatedly (see exit_note). This shows continuous scheduling differences between general-purpose and real-time tasks.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the delay time taskA uses after each work cycle?
A100ms
B50ms
C150ms
DNo delay
💡 Hint
Check the 'Timing Behavior' column for taskA in rows 1 and 3.
At which step does taskB wake exactly on schedule using vTaskDelayUntil?
AStep 1
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'Action' and 'Timing Behavior' columns for taskB in the execution_table.
If taskA used vTaskDelayUntil like taskB, what would change in variable_tracker?
AtaskA_delay would become variable
BtaskA_delay would track precise wake times like taskB_lastWakeTime
CtaskB_lastWakeTime would reset to 0
DNo change in variables
💡 Hint
Compare how taskB_lastWakeTime changes in variable_tracker and think about taskA's timing.
Concept Snapshot
Real-time OS guarantees tasks run at precise times using functions like vTaskDelayUntil.
General-purpose OS tasks use simpler delays like vTaskDelay, which may cause timing jitter.
Real-time tasks are critical for time-sensitive work.
FreeRTOS supports both styles with different delay functions.
Use vTaskDelayUntil for strict periodic timing.
Use vTaskDelay for simpler, less strict delays.
Full Transcript
This visual execution compares real-time and general-purpose OS behavior using FreeRTOS tasks. TaskA uses vTaskDelay, which waits a fixed time after work but can be delayed by other tasks, causing timing jitter. TaskB uses vTaskDelayUntil, which wakes the task at precise intervals, ensuring real-time timing. Both tasks run infinite loops to simulate continuous operation. Variable tracking shows taskA_delay stays constant at 100ms, while taskB_lastWakeTime increases precisely every 50ms. Key moments clarify why vTaskDelayUntil is needed for real-time guarantees and why general-purpose delays can cause timing issues. The quiz tests understanding of timing differences and variable changes. The snapshot summarizes key differences and usage in FreeRTOS.