</>EmbeddedInterview

What are FreeRTOS task notifications?

MediumRTOS & Real-Time Systems

Short answer: Every FreeRTOS task has a built-in 32-bit notification value and state (an array of them since v10.4). Another task or an ISR can notify the task by incrementing the value, setting bits in it, or overwriting it, and the task can block waiting for a notification. Notifications are faster and use less RAM than semaphores, queues or event groups because no separate kernel object is needed, but only the owning task can wait on them and they cannot buffer multiple data items.

As a lightweight binary/counting semaphore (ISR → task)

static TaskHandle_t rx_task_handle;

void DMA_IRQHandler(void)
{
    BaseType_t woken = pdFALSE;
    clear_dma_flags();
    vTaskNotifyGiveFromISR(rx_task_handle, &woken);    /* increment the notification value */
    portYIELD_FROM_ISR(woken);
}

void rx_task(void *p)
{
    for (;;) {
        uint32_t n = ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(100));  /* pdTRUE: clear to 0 (binary) */
        if (n == 0) { /* timeout */ continue; }
        process_dma_buffer();
    }
}

As event bits: xTaskNotify(task, BIT_X, eSetBits) and xTaskNotifyWait(0, ULONG_MAX, &bits, timeout).

As a mailbox for a value: xTaskNotify(task, value, eSetValueWithOverwrite).

Advantages: about 45% faster than a binary semaphore and no extra RAM; ideal for "this ISR wakes that one handler task", which is the most common synchronisation in drivers.

Limitations

  • Only one task (the target) can wait; you cannot broadcast to several tasks.
  • One 32-bit value per index: it cannot queue several data items.
  • The sender cannot block waiting for the receiver to consume a notification (no back-pressure).
  • If several unrelated sources use the same notification index, they can interfere: use separate indexes or bits.