0
0
FreeRTOSprogramming~10 mins

Hard real-time vs soft real-time in FreeRTOS - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - Hard real-time vs soft real-time
Task starts
Deadline check
Deadline met?
Continue normal
Next task
Hard RT: system fail
Tasks start and check deadlines. If met, continue normally. If missed, soft real-time systems degrade gracefully, hard real-time systems fail immediately.
Execution Sample
FreeRTOS
void Task(void *params) {
  TickType_t start = xTaskGetTickCount();
  // Do work
  if (xTaskGetTickCount() - start > DEADLINE) {
    // Deadline missed
  }
}
This code checks if a task finishes before its deadline and handles deadline misses.
Execution Table
StepActionTime (ticks)Deadline (ticks)Deadline Met?System Response
1Task starts10050N/ARunning
2Task does work16050N/ARunning
3Check deadline16050No (160-100=60 > 50?)Deadline missed
4Soft RT response16050NoContinue with degraded quality
5Hard RT response16050NoSystem fails or resets
💡 Execution stops after deadline check and system response to deadline miss.
Variable Tracker
VariableStartAfter Step 2After Step 3Final
start100100100100
current_timeN/A160160160
deadline50505050
deadline_metN/AN/ANoNo
Key Moments - 2 Insights
Why does the system fail immediately in hard real-time but not in soft real-time?
Because in hard real-time (see execution_table step 5), missing a deadline is critical and causes failure, while soft real-time (step 4) allows continuing with degraded performance.
How is the deadline checked in the code?
By comparing the elapsed time (current_time - start) with the deadline value, as shown in execution_table step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the deadline checked?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Check the 'Action' column for 'Check deadline' in execution_table.
According to variable_tracker, what is the value of 'deadline_met' after step 3?
ANo
BYes
CN/A
DUndefined
💡 Hint
Look at the 'deadline_met' row and the 'After Step 3' column in variable_tracker.
If the task finishes before the deadline, what would the system response be in a hard real-time system?
ADegrade quality
BSystem fails
CContinue normal operation
DReset system
💡 Hint
Refer to concept_flow where meeting the deadline leads to normal continuation.
Concept Snapshot
Hard real-time: Missing deadlines causes system failure.
Soft real-time: Missing deadlines causes degraded performance.
Check deadlines by comparing elapsed time to deadline.
Hard RT is strict; soft RT is flexible.
Use FreeRTOS tick counts to measure time.
Full Transcript
In real-time systems, tasks must finish work before deadlines. Hard real-time systems fail immediately if deadlines are missed. Soft real-time systems allow continuing with reduced quality. The code example shows checking elapsed time against a deadline. Execution steps trace task start, work, deadline check, and system response. Variables track start time, current time, deadline, and if deadline was met. Key moments clarify why hard RT fails on misses and how deadlines are checked. Quizzes test understanding of steps and variable values. Remember: hard RT is strict, soft RT is forgiving.