Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a task pool with FreeRTOS.
FreeRTOS
xTaskCreate([1], "Task1", 1000, NULL, 1, NULL);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using xQueueCreate instead of a task function.
Passing NULL as the task function.
Confusing task creation with semaphore or queue creation.
✗ Incorrect
The function vTaskFunction is the task function passed to xTaskCreate to create a task.
2fill in blank
mediumComplete the code to initialize a queue for task communication.
FreeRTOS
QueueHandle_t xQueue = [1](10, sizeof(int));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using xTaskCreate instead of xQueueCreate.
Using semaphore creation functions instead of queue creation.
Confusing queue creation with task delay.
✗ Incorrect
xQueueCreate creates a queue with a specified length and item size for task communication.
3fill in blank
hardFix the error in the task pool code by completing the missing function call.
FreeRTOS
if (xTaskCreate(vTaskFunction, "Task", 1000, NULL, 1, &[1]) != pdPASS) { // Handle error }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a queue or semaphore handle instead of a task handle.
Passing NULL when a handle pointer is needed.
Confusing timer handles with task handles.
✗ Incorrect
The last argument to xTaskCreate is a pointer to a TaskHandle_t variable, here named xTaskHandle.
4fill in blank
hardFill both blanks to create a task pool that dynamically handles workload.
FreeRTOS
for (int i = 0; i < [1]; i++) { xTaskCreate(vTaskFunction, "Task", 1000, NULL, [2], NULL); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero tasks or zero priority which disables tasks.
Using too few tasks to handle workload.
Using priority zero which is invalid.
✗ Incorrect
Creating 10 tasks with priority 1 allows a dynamic task pool to handle workload efficiently.
5fill in blank
hardFill all three blanks to implement a task pool that processes data from a queue.
FreeRTOS
void vTaskFunction(void *pvParameters) {
int data;
while (1) {
if (xQueueReceive([1], &data, [2]) == pdPASS) {
processData(data);
}
vTaskDelay([3]);
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL instead of the queue handle.
Using zero timeout instead of portMAX_DELAY.
Using zero delay which causes tight looping.
✗ Incorrect
The task receives data from xQueue, waits indefinitely (portMAX_DELAY), and delays 100 ms between checks.