Bird
Raised Fist0
FreeRTOSprogramming~10 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. Which statement best describes a hard real-time system in FreeRTOS?
easy
A. Tasks can miss deadlines occasionally without major issues.
B. Tasks run only when the CPU is idle.
C. Tasks must meet deadlines strictly without any misses.
D. Tasks have no timing constraints.

Solution

  1. Step 1: Understand hard real-time definition

    Hard real-time means deadlines are strict and must never be missed.
  2. Step 2: Compare options with definition

    The statement 'Tasks must meet deadlines strictly without any misses' matches the definition of hard real-time.
  3. Final Answer:

    Tasks must meet deadlines strictly without any misses. -> Option C
  4. Quick Check:

    Hard real-time = strict deadlines [OK]
Hint: Hard real-time means no deadline misses allowed [OK]
Common Mistakes:
  • Confusing hard real-time with soft real-time
  • Thinking tasks run only when CPU is idle
  • Ignoring timing constraints
2. Which FreeRTOS API function is used to delay a task for a specific time period?
easy
A. vTaskDelay()
B. xTaskCreate()
C. vTaskStartScheduler()
D. xQueueSend()

Solution

  1. Step 1: Identify delay function in FreeRTOS

    vTaskDelay() pauses a task for a given tick count, controlling timing.
  2. Step 2: Check other options

    xTaskCreate() creates tasks, vTaskStartScheduler() starts the OS, xQueueSend() sends to queues.
  3. Final Answer:

    vTaskDelay() -> Option A
  4. Quick Check:

    Delay task = vTaskDelay() [OK]
Hint: Delay tasks with vTaskDelay() in FreeRTOS [OK]
Common Mistakes:
  • Confusing task creation with delay
  • Using scheduler start as delay
  • Mixing queue functions with delays
3. Consider this FreeRTOS task priority setup:
Task A priority = 3
Task B priority = 2
Task C priority = 1
If Task A blocks for 100ms using vTaskDelay(), which task runs next?
medium
A. Task A again immediately
B. Task B
C. Task C
D. No task runs until Task A finishes delay

Solution

  1. Step 1: Understand task priorities and blocking

    Task A has highest priority (3) but blocks for 100ms, so it is not ready.
  2. Step 2: Identify next highest priority ready task

    Task B has priority 2 and is ready, so it runs next.
  3. Final Answer:

    Task B -> Option B
  4. Quick Check:

    Next task after blocking = highest ready priority [OK]
Hint: Next runs highest priority ready task after delay [OK]
Common Mistakes:
  • Assuming blocked task runs immediately
  • Ignoring task priorities
  • Thinking no task runs during delay
4. Identify the error in this FreeRTOS code snippet for a hard real-time task:
void vTaskFunction(void *pvParameters) {
  while(1) {
    // Critical processing
    vTaskDelay(1000);
  }
}
What is the problem?
medium
A. vTaskDelay should be replaced with vTaskDelete.
B. The task function lacks a return statement.
C. The infinite loop will crash FreeRTOS.
D. Using vTaskDelay causes deadline misses in hard real-time tasks.

Solution

  1. Step 1: Analyze vTaskDelay in hard real-time context

    vTaskDelay pauses the task, which can cause missing strict deadlines in hard real-time.
  2. Step 2: Check other options for correctness

    Return statement is not needed in infinite loop, infinite loops are normal, vTaskDelete deletes task, not delay.
  3. Final Answer:

    Using vTaskDelay causes deadline misses in hard real-time tasks. -> Option D
  4. Quick Check:

    Hard real-time tasks avoid vTaskDelay [OK]
Hint: Hard real-time tasks avoid delays that cause misses [OK]
Common Mistakes:
  • Thinking infinite loops crash FreeRTOS
  • Confusing vTaskDelay with task deletion
  • Expecting return in infinite loops
5. You need to design a FreeRTOS system where some tasks must never miss deadlines (hard real-time), and others can miss occasionally (soft real-time). Which approach best achieves this?
hard
A. Assign highest priorities to hard real-time tasks and use vTaskDelay carefully for soft real-time tasks.
B. Use vTaskDelay for all tasks to simplify timing.
C. Assign equal priorities to all tasks and rely on round-robin scheduling.
D. Run hard real-time tasks only when soft real-time tasks are idle.

Solution

  1. Step 1: Understand priority and delay roles in FreeRTOS

    Hard real-time tasks need highest priority to avoid preemption and deadline misses.
  2. Step 2: Use vTaskDelay carefully for soft real-time tasks

    Soft real-time tasks can tolerate delays, so vTaskDelay helps manage their timing without affecting hard real-time tasks.
  3. Step 3: Evaluate other options

    Equal priorities or running hard real-time tasks only when soft are idle do not guarantee deadlines.
  4. Final Answer:

    Assign highest priorities to hard real-time tasks and use vTaskDelay carefully for soft real-time tasks. -> Option A
  5. Quick Check:

    Priority + careful delay = mixed real-time system [OK]
Hint: Prioritize hard real-time tasks highest, delay soft tasks [OK]
Common Mistakes:
  • Giving equal priority to all tasks
  • Using delays in hard real-time tasks
  • Running hard real-time tasks only after soft tasks
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard