Bird
Raised Fist0
FreeRTOSprogramming~20 mins

xTaskNotify() with value in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
πŸŽ–οΈ
FreeRTOS Notification Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this FreeRTOS task notification example?

Consider the following FreeRTOS code snippet where a task is notified with a value. What will be the value printed by the task?

FreeRTOS
#include "FreeRTOS.h"
#include "task.h"
#include <stdio.h>

TaskHandle_t xTaskHandle = NULL;

void vTaskFunction(void *pvParameters) {
    uint32_t ulNotificationValue = 0;
    xTaskNotifyWait(0x00, 0xffffffff, &ulNotificationValue, portMAX_DELAY);
    printf("Notification value: %lu\n", ulNotificationValue);
    vTaskDelete(NULL);
}

int main(void) {
    xTaskCreate(vTaskFunction, "Task", configMINIMAL_STACK_SIZE, NULL, 1, &xTaskHandle);
    vTaskStartScheduler();
    vTaskDelay(10);
    xTaskNotify(xTaskHandle, 1234, eSetValueWithOverwrite);
    return 0;
}
ANotification value: 0
BNotification value: 1234
CNotification value: 1
DNotification value: 4294967295
Attempts:
2 left
πŸ’‘ Hint

Remember that xTaskNotifyWait receives the notification value sent by xTaskNotify when using eSetValueWithOverwrite.

🧠 Conceptual
intermediate
1:30remaining
Which notification action updates the task notification value by adding the new value?

In FreeRTOS, xTaskNotify() can perform different actions on the task's notification value. Which action adds the new value to the current notification value?

AeSetBits
BeSetValueWithoutOverwrite
CeSetValueWithOverwrite
DeIncrement
Attempts:
2 left
πŸ’‘ Hint

Think about bitwise operations and how notification values can be combined.

❓ Predict Output
advanced
2:00remaining
What happens if you call xTaskNotify() with eSetValueWithoutOverwrite when the notification value is already non-zero?

Given a task with a current notification value of 5, what will be the notification value after calling xTaskNotify() with value 10 and action eSetValueWithoutOverwrite?

FreeRTOS
uint32_t ulValue = 5;
// Assume task notification value is currently 5
// Call:
xTaskNotify(xTaskHandle, 10, eSetValueWithoutOverwrite);
// Then task reads notification value
ANotification value remains 5
BNotification value becomes 10
CNotification value becomes 15
DNotification value resets to 0
Attempts:
2 left
πŸ’‘ Hint

Check what eSetValueWithoutOverwrite does if the notification value is not zero.

πŸ”§ Debug
advanced
2:30remaining
Why does this code cause the task to never unblock after xTaskNotify()?

Examine the code below. The task waits for a notification, but never prints the notification value. What is the likely cause?

FreeRTOS
void vTaskFunction(void *pvParameters) {
    uint32_t ulNotificationValue = 0;
    xTaskNotifyWait(0x00, 0xffffffff, &ulNotificationValue, 1000 / portTICK_PERIOD_MS);
    printf("Notification value: %lu\n", ulNotificationValue);
    vTaskDelete(NULL);
}

// In main or another task:
xTaskNotify(xTaskHandle, 42, eSetValueWithOverwrite);
// But task never prints anything
AThe notification value is overwritten with zero inside the task
BThe notification wait timeout is too long, blocking indefinitely
CThe task handle passed to xTaskNotify is NULL
DThe task notification is sent before the task starts waiting, so it misses the notification
Attempts:
2 left
πŸ’‘ Hint

Consider the timing of when the notification is sent versus when the task waits.

πŸš€ Application
expert
3:00remaining
How to atomically increment a task's notification value and unblock the task?

You want to safely increment a task's notification value by 1 and unblock the task if it is waiting. Which xTaskNotify() action should you use?

AeSetBits
BeSetValueWithOverwrite
CeIncrement
DeSetValueWithoutOverwrite
Attempts:
2 left
πŸ’‘ Hint

Think about which action increments the notification value atomically.

Practice

(1/5)
1.

What does the xTaskNotify() function primarily do in FreeRTOS?

easy
A. Creates a new task in the system
B. Deletes a task from the scheduler
C. Sends a notification value from one task to another
D. Suspends the current task indefinitely

Solution

  1. Step 1: Understand the purpose of xTaskNotify()

    The function is designed to send a notification value or signal from one task to another in FreeRTOS.
  2. Step 2: Compare with other task functions

    Creating, deleting, or suspending tasks are done by other FreeRTOS functions, not xTaskNotify().
  3. Final Answer:

    Sends a notification value from one task to another -> Option C
  4. Quick Check:

    xTaskNotify() sends notification value [OK]
Hint: Remember: xTaskNotify() sends signals between tasks [OK]
Common Mistakes:
  • Confusing xTaskNotify() with task creation functions
  • Thinking it suspends or deletes tasks
  • Assuming it handles task priorities
2.

Which of the following is the correct syntax to send a notification with a value using xTaskNotify()?

BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );
easy
A. xTaskNotify(taskHandle, 10, eSetBits);
B. xTaskNotify(10, taskHandle, eSetValueWithOverwrite);
C. xTaskNotify(taskHandle, eSetValueWithoutOverwrite, 10);
D. xTaskNotify(eSetValueWithOverwrite, taskHandle, 10);

Solution

  1. Step 1: Identify parameter order in xTaskNotify()

    The correct order is: TaskHandle_t, uint32_t value, eNotifyAction.
  2. Step 2: Match options to correct order

    xTaskNotify(taskHandle, 10, eSetBits); matches the correct order: taskHandle, 10, eSetBits. Others mix parameter order incorrectly.
  3. Final Answer:

    xTaskNotify(taskHandle, 10, eSetBits); -> Option A
  4. Quick Check:

    Correct parameter order: task, value, action [OK]
Hint: Remember parameter order: task, value, action [OK]
Common Mistakes:
  • Swapping value and task handle parameters
  • Using wrong enum for eNotifyAction
  • Passing parameters in wrong order
3.

Consider the following code snippet:

uint32_t notifiedValue = 0;

// Task A sends notification
xTaskNotify(taskBHandle, 0x04, eSetBits);

// Task B waits for notification
xTaskNotifyWait(0x00, 0xFFFFFFFF, Β¬ifiedValue, portMAX_DELAY);

// What is the value of notifiedValue after notification?
medium
A. 0x04
B. 0x00
C. 0xFFFFFFFF
D. Undefined

Solution

  1. Step 1: Understand eSetBits action

    eSetBits sets bits in the notification value. Since initial is 0, setting bit 0x04 results in notifiedValue = 0x04.
  2. Step 2: Check xTaskNotifyWait parameters

    It clears bits 0x00 (none) and waits indefinitely, storing the notified bits in notifiedValue.
  3. Final Answer:

    0x04 -> Option A
  4. Quick Check:

    eSetBits sets bits = 0x04 [OK]
Hint: eSetBits adds bits to notified value [OK]
Common Mistakes:
  • Assuming notifiedValue remains zero
  • Confusing eSetBits with eSetValueWithoutOverwrite
  • Ignoring the effect of xTaskNotifyWait
4.

Identify the error in the following code snippet using xTaskNotify():

BaseType_t status;
status = xTaskNotify(NULL, 5, eSetValueWithOverwrite);
if(status == pdPASS) {
    // Notification sent
}
medium
A. Missing return statement in function
B. Using eSetValueWithOverwrite is invalid
C. Notification value must be zero
D. Passing NULL as task handle causes error

Solution

  1. Step 1: Check task handle parameter

    xTaskNotify requires a valid task handle; NULL is invalid and causes failure.
  2. Step 2: Validate other parameters

    eSetValueWithOverwrite and value 5 are valid; no return statement needed here.
  3. Final Answer:

    Passing NULL as task handle causes error -> Option D
  4. Quick Check:

    Task handle NULL invalid [OK]
Hint: Task handle must never be NULL [OK]
Common Mistakes:
  • Passing NULL as task handle
  • Thinking notification value must be zero
  • Confusing eNotifyAction enums
5.

You want to send a notification value from Task A to Task B, but only if Task B's current notification value is zero. Which eNotifyAction should you use with xTaskNotify() to achieve this?

hard
A. eSetValueWithOverwrite
B. eSetValueWithoutOverwrite
C. eIncrement
D. eNoAction

Solution

  1. Step 1: Understand eNotifyAction options

    eSetValueWithoutOverwrite sets the notification value only if it is currently zero.
  2. Step 2: Compare with other actions

    eSetValueWithOverwrite always overwrites; eIncrement adds 1; eNoAction sends no value.
  3. Final Answer:

    eSetValueWithoutOverwrite -> Option B
  4. Quick Check:

    Set only if zero = eSetValueWithoutOverwrite [OK]
Hint: Use eSetValueWithoutOverwrite to avoid overwriting [OK]
Common Mistakes:
  • Using eSetValueWithOverwrite and overwriting value
  • Choosing eIncrement which changes value incorrectly
  • Selecting eNoAction which sends no value
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard