Bird
Raised Fist0
FreeRTOSprogramming~20 mins

ISR-to-task notification pattern in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
ISR-to-task Notification Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of task notification from ISR
What will be the output of this FreeRTOS code snippet when the ISR sends a notification to the task?
FreeRTOS
#include "FreeRTOS.h"
#include "task.h"
#include <stdio.h>

TaskHandle_t xTaskHandle = NULL;

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

void vISR_Handler(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    xTaskNotifyFromISR(xTaskHandle, 42, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

int main() {
    xTaskCreate(vTaskFunction, "Task", 1000, NULL, 1, &xTaskHandle);
    // Simulate ISR call
    vISR_Handler();
    // Normally scheduler would be started here
    return 0;
}
ANotification received with value: 42
BNotification received with value: 0
CNo output, task never receives notification
DCompilation error due to missing portYIELD_FROM_ISR definition
Attempts:
2 left
💡 Hint
The scheduler is not started, so the task does not run to process the notification.
🧠 Conceptual
intermediate
1:30remaining
Understanding notification value overwrite behavior
If an ISR sends multiple notifications to a task using xTaskNotifyFromISR with eSetValueWithOverwrite before the task processes them, what will the task receive?
AThe task receives the first notification value only
BThe task receives the last notification value sent by the ISR
CThe task receives all notification values in order
DThe task receives a sum of all notification values
Attempts:
2 left
💡 Hint
eSetValueWithOverwrite replaces the previous notification value.
🔧 Debug
advanced
2:00remaining
Identify the error in ISR notification code
What error will occur when running this ISR notification code snippet?
FreeRTOS
void vISR_Handler(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    xTaskNotifyFromISR(NULL, 10, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
ADeadlock because task handle is NULL
BNo error, notification sent successfully
CCompilation error due to missing xHigherPriorityTaskWoken variable
DRuntime error due to NULL task handle passed to xTaskNotifyFromISR
Attempts:
2 left
💡 Hint
xTaskNotifyFromISR requires a valid task handle to send notification.
📝 Syntax
advanced
1:30remaining
Syntax correctness of ISR notification call
Which option shows the correct syntax for sending a notification from an ISR to a task with notification value 5 and using eIncrement action?
AxTaskNotifyFromISR(xTaskHandle, 5, eIncrement, &xHigherPriorityTaskWoken);
BxTaskNotifyFromISR(xTaskHandle, 5, eSetBits, xHigherPriorityTaskWoken);
CxTaskNotifyFromISR(xTaskHandle, 5, eIncrement);
DxTaskNotifyFromISR(xTaskHandle, 5, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
Attempts:
2 left
💡 Hint
Check the parameters and their order for xTaskNotifyFromISR.
🚀 Application
expert
2:30remaining
Determine the number of notifications received by the task
Given the following scenario: An ISR sends three notifications to a task using xTaskNotifyFromISR with eSetBits action, setting bits 0x01, 0x02, and 0x04 respectively, before the task calls xTaskNotifyWait. How many bits will the task receive in total after unblocking?
FreeRTOS
void vISR_Handler(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    xTaskNotifyFromISR(xTaskHandle, 0x01, eSetBits, &xHigherPriorityTaskWoken);
    xTaskNotifyFromISR(xTaskHandle, 0x02, eSetBits, &xHigherPriorityTaskWoken);
    xTaskNotifyFromISR(xTaskHandle, 0x04, eSetBits, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

void vTaskFunction(void *pvParameters) {
    uint32_t ulNotificationValue;
    xTaskNotifyWait(0x00, 0xffffffff, &ulNotificationValue, portMAX_DELAY);
    // ulNotificationValue contains the bits set by ISR
}
AThe task receives 0x07 (bits 0x01 | 0x02 | 0x04 combined)
BThe task receives only the last bit 0x04
CThe task receives 0x03 (bits 0x01 | 0x02 combined)
DThe task receives 0x00 because bits are overwritten
Attempts:
2 left
💡 Hint
eSetBits action combines bits using OR operation.

Practice

(1/5)
1. What is the main purpose of the ISR-to-task notification pattern in FreeRTOS?
easy
A. To allow an interrupt to quickly notify a task to run
B. To create a new task from an ISR
C. To pause a task until an interrupt finishes
D. To disable interrupts during task execution

Solution

  1. Step 1: Understand ISR and task roles

    ISRs handle hardware events quickly, tasks do longer processing.
  2. Step 2: Identify notification purpose

    The pattern lets ISR tell a task to run without delay.
  3. Final Answer:

    To allow an interrupt to quickly notify a task to run -> Option A
  4. Quick Check:

    ISR notifies task [OK]
Hint: ISR signals task to run fast using notifications [OK]
Common Mistakes:
  • Thinking ISR creates tasks
  • Believing tasks pause interrupts
  • Confusing disabling interrupts with notifications
2. Which function is correctly used inside an ISR to notify a task in FreeRTOS?
easy
A. vTaskNotifyGiveFromISR()
B. ulTaskNotifyTake()
C. xTaskCreate()
D. vTaskDelay()

Solution

  1. Step 1: Identify ISR notification function

    Inside ISR, use vTaskNotifyGiveFromISR() to notify tasks.
  2. Step 2: Differentiate task functions

    ulTaskNotifyTake() is used in tasks, not ISRs.
  3. Final Answer:

    vTaskNotifyGiveFromISR() -> Option A
  4. Quick Check:

    Notify from ISR = vTaskNotifyGiveFromISR() [OK]
Hint: Use vTaskNotifyGiveFromISR() inside ISR only [OK]
Common Mistakes:
  • Using ulTaskNotifyTake() inside ISR
  • Calling xTaskCreate() in ISR
  • Using vTaskDelay() inside ISR
3. Given this code snippet, what will be the output printed by the task?
void ISR_Handler() {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    vTaskNotifyGiveFromISR(taskHandle, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

void TaskFunction(void *pvParameters) {
    for(;;) {
        ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
        printf("Task notified!\n");
    }
}
medium
A. No output, task never notified
B. Task notified! (printed each time ISR runs)
C. Compilation error due to missing parameters
D. Task notified! printed once then stops

Solution

  1. Step 1: Analyze ISR notification call

    ISR calls vTaskNotifyGiveFromISR() to notify the task each time it runs.
  2. Step 2: Check task notification wait

    Task waits indefinitely with ulTaskNotifyTake(), then prints on notification.
  3. Final Answer:

    Task notified! (printed each time ISR runs) -> Option B
  4. Quick Check:

    ISR notifies task -> prints each time [OK]
Hint: Task prints after each ISR notification [OK]
Common Mistakes:
  • Assuming task never wakes
  • Confusing function parameters
  • Thinking output prints only once
4. Identify the error in this ISR-to-task notification code snippet:
void ISR_Handler() {
    vTaskNotifyGive(taskHandle);
}

void TaskFunction(void *pvParameters) {
    ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
    printf("Notified\n");
}
medium
A. printf() cannot be used in tasks
B. Missing infinite loop in TaskFunction
C. Incorrect parameter in ulTaskNotifyTake()
D. Using vTaskNotifyGive() inside ISR instead of vTaskNotifyGiveFromISR()

Solution

  1. Step 1: Check ISR notification function

    vTaskNotifyGive() is not safe inside ISR; must use vTaskNotifyGiveFromISR().
  2. Step 2: Verify task code correctness

    TaskFunction can have single call; infinite loop is common but not error here.
  3. Final Answer:

    Using vTaskNotifyGive() inside ISR instead of vTaskNotifyGiveFromISR() -> Option D
  4. Quick Check:

    ISR notification function must end with FromISR [OK]
Hint: Use FromISR suffix functions inside ISRs [OK]
Common Mistakes:
  • Calling task functions inside ISR
  • Ignoring FromISR suffix importance
  • Assuming printf() is disallowed in tasks
5. You want to notify a task from multiple ISRs using ISR-to-task notifications. Which approach ensures the task processes all notifications without missing any?
hard
A. Use vTaskNotifyGiveFromISR() once and ulTaskNotifyTake() once; task processes only one notification
B. Use xTaskNotifyGive() in ISRs and ulTaskNotifyTake() in task with zero timeout
C. Use ulTaskNotifyTake() with clear count and call vTaskNotifyGiveFromISR() in each ISR; task loops to process all notifications
D. Use a global variable incremented in ISRs and checked in task without notifications

Solution

  1. Step 1: Understand multiple ISR notifications

    Each ISR calls vTaskNotifyGiveFromISR() to increment notification count.
  2. Step 2: Task processes all notifications

    Task uses ulTaskNotifyTake(pdTRUE, portMAX_DELAY) in a loop to clear all counts and process each notification.
  3. Final Answer:

    Use ulTaskNotifyTake() with clear count and call vTaskNotifyGiveFromISR() in each ISR; task loops to process all notifications -> Option C
  4. Quick Check:

    Multiple ISR notifications require counting and looping [OK]
Hint: Loop ulTaskNotifyTake() to handle multiple ISR signals [OK]
Common Mistakes:
  • Assuming one notification covers all ISR events
  • Using non-FromISR functions in ISR
  • Ignoring notification count clearing
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