
Click the above blue text to follow us
Real-time systems are crucial in embedded applications, with the core focus on ensuring tasks are completed within specified time frames. Based on the strictness of deadline adherence, real-time systems are classified into hard real-time and soft real-time.
Hard real-time systems require tasks to meet deadlines 100% of the time; failure to do so can lead to catastrophic consequences, such as in automotive safety systems or medical devices. Soft real-time systems, on the other hand, allow for occasional deadline misses, such as in multimedia streaming.

Real-time systems are categorized based on the strictness of task deadlines:
- Hard real-time systems: Missing a deadline results in system failure. For example, an automotive anti-lock braking system (ABS) must respond within milliseconds.
- Soft real-time systems: Missing a deadline degrades performance but does not cause system failure. For instance, occasional delays in video streaming may cause frame stuttering, but the system continues to operate.
Hard real-time systems require deterministic behavior from the operating system to ensure tasks are completed on time under all circumstances. FreeRTOS provides robust support for real-time applications through its scheduling mechanisms and synchronization tools.
The scheduler in FreeRTOS is central to achieving real-time performance, employing a preemptive priority scheduling algorithm:
- Preemptive scheduling: A high-priority task can immediately interrupt a low-priority task when it becomes ready, ensuring critical tasks are executed in a timely manner.
- Priority assignment: Task priorities range from 0 (lowest) to configMAX_PRIORITIES – 1 (highest), allowing developers to assign priorities based on the real-time requirements of tasks.
By assigning high priorities to time-critical tasks, FreeRTOS ensures these tasks receive CPU time when needed, thus meeting real-time requirements.
FreeRTOS provides the following mechanisms to support real-time applications:
1. Priority inheritance in mutexes
Priority inversion is a common issue in real-time systems, where a high-priority task is blocked by a low-priority task holding a shared resource. FreeRTOS mutexes support priority inheritance, which works as follows:
- When a high-priority task attempts to acquire a mutex held by a low-priority task, the low-priority task’s priority is temporarily raised to that of the high-priority task.
- Once the low-priority task exits the critical section, it releases the mutex and reverts to its original priority.
This ensures that high-priority tasks are not unduly delayed due to resource contention.
2. Interrupt handling
Interrupts are key for quickly responding to external events in real-time systems. FreeRTOS provides efficient interrupt management mechanisms, allowing interrupt service routines (ISRs) to use APIs like xTaskResumeFromISR to wake tasks for rapid event handling. Developers should keep ISRs short to avoid blocking other tasks or increasing latency.
3. Tickless idle mode
FreeRTOS supports a tickless idle mode, which stops periodic tick interrupts when the system is idle, reducing power consumption and minimizing timing jitter in certain scenarios. This is particularly important for applications requiring high-precision timing control.
To configure FreeRTOS to meet near hard real-time requirements, developers should consider the following:
-
Properly assign task priorities: Assign high priorities to time-critical tasks to ensure they are executed first. Avoid assigning the same priority to tasks with different real-time needs to clarify execution order.
-
Use mutexes that support priority inheritance: Use mutexes to protect data consistency and prevent priority inversion when tasks share resources.
-
Optimize interrupt latency: Keep ISRs short and efficient. Use deferred interrupt handling to delegate complex operations to tasks.
-
Optimize task execution: Avoid long-running tasks that block high-priority tasks. Break complex tasks into smaller subtasks to reduce blocking time.
With these configurations, FreeRTOS can meet real-time demands in most cases, although the standard version may not guarantee 100% hard real-time due to hardware limitations or task jitter.
FreeRTOS provides strong real-time support through preemptive priority scheduling, mutex priority inheritance, and efficient interrupt handling. Developers can achieve near hard real-time performance by properly configuring task priorities, using mutexes, and optimizing interrupt handling. For strict hard real-time requirements, extensions like HARETICK can ensure jitter-free deterministic execution.

Click to read the original article for more exciting content~