Task Notifications

FreeRTOS provides a synchronization mechanism called a Task Notification, which allows communication between a task (or an interrupt service routine) and another task. A Task Notification can be used to unblock a task, transitioning it from the Blocked state to the Running state. Unlike a Queue, however, a Task Notification does not support passing data between tasks.  

Developers often choose Task Notifications for their extremely low latency. Unlike queues or semaphores, which can be shared among multiple tasks, a Task Notification is directed to a specific task. This targeted approach allows FreeRTOS to quickly identify and unblock the intended task. Additionally, because Task Notifications do not transmit or receive data, they have a minimal memory footprint. 

Choosing between a Task Notification, a semaphore, or an Event Group depends on the role of the task. If a task can be designed to execute a sequence of instructions without needing additional context—such as what triggered its execution or where to return data—a Task Notification is often the most efficient choice.  Task Notifications are commonly used with interrupt services routines due to their extremely low latency.  This will be covered in a different chapter. 

Initializing a Task Handle 

Before making use of a Task Notification, you will need to initialize a Task Handle.  FreeRTOS provides a primitive type called a TaskHandle_t for this purpose.  The handle can be initialized when a task using xTaskCreate(). 

Taking a Task Notification 

A task can be placed in the Blocked state waiting for a Task Notification using the function ulTaskNotifyTake().

Giving a Task Notification 

A task can be moved into the Ready State by sending a Task Notification using the function xTaskNotifyGive().