0
0
FreeRTOSprogramming~20 mins

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

Choose your learning style9 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.