Consider a FreeRTOS task that calls ulTaskNotifyTake(pdTRUE, 0) after receiving a single notification. What value does ulTaskNotifyTake() return?
/* Assume the task has received exactly one notification count before this call */ uint32_t count = ulTaskNotifyTake(pdTRUE, 0); printf("%u", count);
Think about what pdTRUE does to the notification count.
When ulTaskNotifyTake(pdTRUE, 0) is called, it returns the current notification count and then clears it to zero. Since the task had exactly one notification, the function returns 1.
A task receives 3 notifications before calling ulTaskNotifyTake(pdTRUE, 0). What is the return value?
/* Notifications sent 3 times before this call */ uint32_t count = ulTaskNotifyTake(pdTRUE, 0); printf("%u", count);
Count accumulates with counting notifications.
Each notification increments the count. Calling ulTaskNotifyTake(pdTRUE, 0) returns the total count (3) and clears it.
A task has a notification count of 2. It calls ulTaskNotifyTake(pdFALSE, 0). What is the return value and the new notification count?
/* Notification count is 2 before call */ uint32_t count = ulTaskNotifyTake(pdFALSE, 0); printf("%u", count); // What is the notification count now?
Clear count flag controls if count resets after reading.
With pdFALSE, the count is returned but not cleared, so it stays at 2.
A task calls ulTaskNotifyTake(pdTRUE, 10) but no notification is pending. What happens?
uint32_t count = ulTaskNotifyTake(pdTRUE, 10); printf("%u", count);
Timeout controls how long the function waits for notification.
The function blocks up to the timeout (10 ticks). If no notification arrives, it returns 0.
Which statement correctly describes the difference between ulTaskNotifyTake() and xTaskNotifyWait() when used for counting notifications?
Think about what each function returns and how they handle notification counts.
ulTaskNotifyTake() returns the notification count and optionally clears it, useful for counting notifications. xTaskNotifyWait() waits for a notification and returns a status indicating if one was received, but does not provide the count.