0
0
FreeRTOSprogramming~10 mins

ISR-to-task notification pattern in FreeRTOS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to notify a task from an ISR using FreeRTOS.

FreeRTOS
BaseType_t xHigherPriorityTaskWoken = pdFALSE;

/* Notify the task */
xTaskNotifyGiveFromISR(taskHandle, [1]);

portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
Drag options to blanks, or click blank then click option'
ANULL
BpdFALSE
CpdTRUE
D&xHigherPriorityTaskWoken
Attempts:
3 left
💡 Hint
Common Mistakes
Passing NULL instead of the pointer to xHigherPriorityTaskWoken
Passing pdTRUE or pdFALSE directly instead of the pointer
Not passing any argument
2fill in blank
medium

Complete the code to wait for a notification in a task.

FreeRTOS
void vTaskFunction(void *pvParameters) {
    for(;;) {
        ulTaskNotifyTake(pdTRUE, [1]);
        /* Process notification */
    }
}
Drag options to blanks, or click blank then click option'
AportMAX_DELAY
B0
CpdFALSE
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 which causes no wait
Using pdFALSE which is not a valid block time
Using a numeric value without understanding its meaning
3fill in blank
hard

Fix the error in the ISR notification code to correctly notify the task and request a context switch if needed.

FreeRTOS
void vISR_Handler(void) {
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;

    /* Notify the task */
    xTaskNotifyGiveFromISR(taskHandle, [1]);

    if(xHigherPriorityTaskWoken) {
        [2];
    }
}
Drag options to blanks, or click blank then click option'
A&xHigherPriorityTaskWoken
BxHigherPriorityTaskWoken
CportYIELD_FROM_ISR(xHigherPriorityTaskWoken)
DportYIELD_FROM_ISR(0)
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the variable instead of its address
Calling portYIELD_FROM_ISR with 0 or no argument
Not calling portYIELD_FROM_ISR at all
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps task names to their notification counts only if the count is greater than zero.

FreeRTOS
notification_counts = {taskName: [1] for taskName, count in taskNotifications.items() if count [2] 0}
Drag options to blanks, or click blank then click option'
Acount
B==
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality instead of greater than
Using less than instead of greater than
Using taskName instead of count as value
5fill in blank
hard

Fill all three blanks to create a task notification handler that clears the notification, waits for a notification, and processes it if received.

FreeRTOS
void vTaskNotificationHandler(void *pvParameters) {
    for(;;) {
        ulTaskNotifyTake([1], [2]);
        if([3]) {
            /* Process notification */
        }
    }
}
Drag options to blanks, or click blank then click option'
ApdTRUE
BportMAX_DELAY
CulTaskNotifyTake(pdTRUE, portMAX_DELAY)
DulTaskNotifyTake(pdFALSE, 0)
Attempts:
3 left
💡 Hint
Common Mistakes
Not clearing the notification on entry
Using zero block time causing no wait
Not checking the return value before processing