Challenge - 5 Problems
ISR-to-task Notification Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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; }
Attempts:
2 left
💡 Hint
The scheduler is not started, so the task does not run to process the notification.
✗ Incorrect
The code creates the task and simulates an ISR call sending notification value 42, but the scheduler is never started (commented out). Therefore, the task never executes and produces no output.
🧠 Conceptual
intermediate1: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?
Attempts:
2 left
💡 Hint
eSetValueWithOverwrite replaces the previous notification value.
✗ Incorrect
Using eSetValueWithOverwrite causes the notification value to be overwritten if multiple notifications arrive before the task processes them. So only the last value is received.
🔧 Debug
advanced2: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);
}Attempts:
2 left
💡 Hint
xTaskNotifyFromISR requires a valid task handle to send notification.
✗ Incorrect
Passing NULL as the task handle to xTaskNotifyFromISR causes a runtime error or undefined behavior because the function expects a valid task handle to notify.
📝 Syntax
advanced1: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?
Attempts:
2 left
💡 Hint
Check the parameters and their order for xTaskNotifyFromISR.
✗ Incorrect
The correct syntax requires the task handle, notification value, action, and pointer to BaseType_t variable for priority yield. Option A matches this exactly.
🚀 Application
expert2: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
}Attempts:
2 left
💡 Hint
eSetBits action combines bits using OR operation.
✗ Incorrect
Using eSetBits causes the notification value bits to be combined (ORed). Sending 0x01, 0x02, and 0x04 results in 0x07 total bits set when the task unblocks.