
In real-time embedded systems, performance and resource efficiency are critical to design success. Traditional real-time operating systems (RTOS) provide mechanisms such as queues, signals, and event groups to synchronize tasks and enable communication. FreeRTOS and SAFERTOS also offer a lighter-weight mechanism for some use cases: task notifications.
What are task notifications?
Task notifications are a lightweight alternative to traditional RTOS synchronization objects. In FreeRTOS/SAFERTOS, each task has a 32-bit notification value. Notifications can be used to unblock tasks and update the notification value in flexible ways, including:
- Set the notification value without overwriting the previous value
- Update the notification value
- Set specific bits within the notification value
- Increment the notification value
This flexibility allows task notifications to replace separate synchronization objects, such as queues or semaphores, in certain scenarios. When used appropriately, task notifications can significantly improve runtime and memory efficiency.
Task notifications vs traditional mechanisms
Binary semaphore: In traditional designs, a binary semaphore can be used when only one task needs to receive a signal. However, using a binary semaphore requires a queue control structure. Task notifications eliminate that structure, reducing RAM usage and simplifying internal RTOS processing.
Event groups: Event groups represent a set of binary flags, each with a specific meaning. A 32-bit task notification value can be used as a collection of binary flags, providing a more efficient alternative to managing a dedicated event group object.
Advantages
- Speed: Unblocking a task with a task notification is about 45% faster than unblocking with a binary semaphore. This is a significant improvement for time-sensitive applications.
- Memory savings: Task notifications reduce the need for additional RTOS control structures such as queues or semaphores, lowering RAM usage, which is important in resource-constrained systems.
Limitations
Task notifications provide substantial performance benefits but have usage constraints:
- Single-receiver restriction: Task notifications are suitable when there is a single receiving task. They are not appropriate when multiple tasks need to receive the same event or notification.
- Non-blocking send: Unlike queues, if a notification is already pending, sending a task notification does not block the sending task. It is possible to configure the notification to "not overwrite the old value" to prevent a new notification from replacing an unprocessed one.
Typical use cases
- Task synchronization: When one task needs to notify or unblock another task.
- Interrupt handling: Task notifications can act as a lightweight binary semaphore between an ISR (interrupt service routine) and a task to unblock the task after an interrupt.
- Event flag management: The bits of a task notification value can serve as event flags, with each bit representing a different flag, reducing the need for a dedicated event group object.
Conclusion
For developers aiming to optimize the performance and resource usage of embedded systems, task notifications are a practical tool. In single-receiver scenarios, replacing traditional synchronization mechanisms with task notifications can yield notable improvements in execution speed and memory efficiency.
Every millisecond and byte matters in real-time systems. Whether handling task synchronization, ISR interactions, or event flag management, task notifications offer a streamlined and efficient option.
FreeRTOS v10.4.0 and later support notification arrays. SAFERTOS is a safety-oriented RTOS based on the FreeRTOS functional model.
ALLPCB