About Task Notifications

hi,
i hope my bad writing skill doesn’t bother you.

I studied about Task Notifications using FreeRTOS Tutorial, and I found a sentece.

RAM Footprint Benefits of Task Notifications
Likewise, using a task notification to send an event or data to a task requires significantly less
RAM than using a queue, semaphore or event group to perform an equivalent operation. This
is because each communication object (queue, semaphore or event group) must be created
before it can be used, whereas enabling task notification functionality has a fixed overhead of
just eight bytes of RAM per task

and also i found this on freertos homepage

Setting configUSE_TASK_NOTIFICATIONS to 0 will exclude direct to task notification functionality and its associated API from the build.
Each task consumes 8 additional bytes of RAM when direct to task notifications are included in the build.

both said 8bytes for each Task.
but also I found this on the community tab.

Beginning with FreeRTOS V10.4.0, each task has an array of notifications. Before that, each task had a single notification. Each notification comprises a 32-bit value and a Boolean state, which together consume just 5 bytes of RAM.

so I tried to figure it out through checking by my self.
first, I set " configUSE_TASK_NOTIFICATIONS " 1, and check the memory left, and tried when it’s set 0.
but when it was 0, i can’t build with errors.

error configUSE_TASK-NOTIFICATIONS must be set to 1 to build stream_buffer.c

i know it’s not a critical or major problem.
but still I just wanna know which one is correct.
8bytes? or 5bytes?

thank you so much

It is clear when you look at this code - FreeRTOS-Kernel/tasks.c at main · FreeRTOS/FreeRTOS-Kernel · GitHub

    #if ( configUSE_TASK_NOTIFICATIONS == 1 )
        volatile uint32_t ulNotifiedValue[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];
        volatile uint8_t ucNotifyState[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];
    #endif

For each notification entry, it is sizeof(uint32_t) + sizeof(uint8_t) = 4 + 1 = 5 bytes .

stream_buffer.c requires task notifications - you should exclude it from your build.

EDIT -
This PR updates the task notification entry size in the book - Fix size of task task notification entry in TCB by aggarg · Pull Request #82 · FreeRTOS/FreeRTOS-Kernel-Book · GitHub.

We will update the website documentation as well. Thank you for reporting this!

1 Like

Hi,

It is a great answer for me.
Thank you so much.

I am just learning FreeRTOS now,
I hope I can be a person helping people soon.

Thank you.

Best Regards,

oh Hi, me again.

I’m stuck at this point.
same chapter (task notification) in Mastering-the-FreeRTOS-Real-time-Kernel.

In the Example 10.1 (it was named as Example 24),

const TickType_t xInterruptFrequency = pdMS_TO_TICKS( 500UL );
static void vHandlerTask( void *pvParameters )
{
...
` ulEventsToProcess = ulTaskNotifyTake( pdTRUE, xMaxExpectedBlockTime );`
 if( ulEventsToProcess != 0 )
 {
 while( ulEventsToProcess > 0 )
   {
 vPrintString( "Handler task - Processing event.\r\n" );
` ulEventsToProcess--;`
   }
 }

I thought this example was for checking ‘task notification can be used like binary semaphore’.
but if I give a notification like, 3times in ISR, then Handler Task will get notification value as 3.
then following the code ulEventsToProcess = ulTaskNotifyTake(pdTRUE, xMaxExpectedBlockTime); it will be ulEventsToProcess = 3.
after then, while(ulEventsToProcess > 0) will run 3times (3 ->2 → 1 ->break).

How it’s meaning Notification is same with Binary Semaphore.
if I am right, in a same context, Using binary semaphore will print 2times only.

I’m just confusing and I think I am thinking wrong way.
if there is something I am missing in this Example, please tell me.

thank you so much.

Best Regards,

Besides the great book do you now FreeRTOS task notifications, fast Real Time Operating System (RTOS) event mechanism ?