Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an interrupt handler function.
FreeRTOS
void [1](void) {
// ISR code here
}Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that conflicts with FreeRTOS API functions.
Adding parameters to the ISR function.
✗ Incorrect
The interrupt handler function must have a proper name, here 'vMyISR' is used as an example.
2fill in blank
mediumComplete the code to send data to a queue from an ISR.
FreeRTOS
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xQueueSendFromISR([1], &data, &xHigherPriorityTaskWoken);Attempts:
3 left
💡 Hint
Common Mistakes
Passing a semaphore handle instead of a queue handle.
Using a task handle instead of a queue handle.
✗ Incorrect
The function xQueueSendFromISR requires a queue handle as the first argument.
3fill in blank
hardFix the error in the ISR by correctly calling the yield function.
FreeRTOS
if (xHigherPriorityTaskWoken) { [1](xHigherPriorityTaskWoken); }
Attempts:
3 left
💡 Hint
Common Mistakes
Calling vTaskDelay inside ISR.
Calling scheduler start function inside ISR.
✗ Incorrect
portYIELD_FROM_ISR(xHigherPriorityTaskWoken) is the correct macro to request a context switch from an ISR.
4fill in blank
hardFill both blanks to create a deferred processing task that waits on a queue.
FreeRTOS
void vDeferredTask(void *pvParameters) {
uint32_t ulReceivedValue;
for(;;) {
if (xQueueReceive([1], &ulReceivedValue, [2]) == pdPASS) {
// Process the received value
}
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using a semaphore handle instead of a queue handle.
Using pdFALSE as block time which means no wait.
✗ Incorrect
The task waits indefinitely on the queue 'xQueue' using portMAX_DELAY to block.
5fill in blank
hardFill all three blanks to correctly create a queue, start the deferred task, and send data from ISR.
FreeRTOS
QueueHandle_t [1]; void vSetup() { [2] = xQueueCreate(10, sizeof(uint32_t)); xTaskCreate(vDeferredTask, "Deferred", 1000, NULL, 2, NULL); } void vMyISR(void) { uint32_t ulData = 42; BaseType_t xHigherPriorityTaskWoken = pdFALSE; xQueueSendFromISR([3], &ulData, &xHigherPriorityTaskWoken); if (xHigherPriorityTaskWoken) { portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for the queue handle.
Using a semaphore handle instead of a queue handle.
✗ Incorrect
The same queue handle 'xQueue' is used to create the queue, send data from ISR, and referenced in the task.
