Complete the code to notify a task from an ISR using FreeRTOS.
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
/* Notify the task */
xTaskNotifyGiveFromISR(taskHandle, [1]);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);The second argument to xTaskNotifyGiveFromISR must be a pointer to xHigherPriorityTaskWoken so the ISR can inform the scheduler if a context switch is needed.
Complete the code to wait for a notification in a task.
void vTaskFunction(void *pvParameters) {
for(;;) {
ulTaskNotifyTake(pdTRUE, [1]);
/* Process notification */
}
}Using portMAX_DELAY makes the task wait indefinitely for a notification.
Fix the error in the ISR notification code to correctly notify the task and request a context switch if needed.
void vISR_Handler(void) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
/* Notify the task */
xTaskNotifyGiveFromISR(taskHandle, [1]);
if(xHigherPriorityTaskWoken) {
[2];
}
}The notification function requires the address of xHigherPriorityTaskWoken. Then, if it is set, portYIELD_FROM_ISR() is called with that variable to request a context switch.
Fill both blanks to create a dictionary comprehension that maps task names to their notification counts only if the count is greater than zero.
notification_counts = {taskName: [1] for taskName, count in taskNotifications.items() if count [2] 0}The comprehension maps each taskName to its count only if the count is greater than zero.
Fill all three blanks to create a task notification handler that clears the notification, waits for a notification, and processes it if received.
void vTaskNotificationHandler(void *pvParameters) {
for(;;) {
ulTaskNotifyTake([1], [2]);
if([3]) {
/* Process notification */
}
}
}The function ulTaskNotifyTake is called with pdTRUE to clear the notification on entry and portMAX_DELAY to wait indefinitely. The returned value is checked to see if a notification was received.