0
0
FreeRTOSprogramming~20 mins

Why tasks are the building blocks in FreeRTOS - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
FreeRTOS Task Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why are tasks considered the building blocks in FreeRTOS?

In FreeRTOS, tasks are fundamental. Which statement best explains why tasks are called the building blocks?

ATasks are only used to initialize hardware and then stop running.
BTasks are used only for memory management and do not affect program flow.
CTasks replace interrupts and handle all hardware events directly.
DTasks allow multiple functions to run independently and share CPU time, enabling multitasking.
Attempts:
2 left
💡 Hint

Think about how FreeRTOS manages different jobs at the same time.

Predict Output
intermediate
2:00remaining
What is the output of this FreeRTOS task creation code?

Consider the following FreeRTOS code snippet. What will be the output on the console?

FreeRTOS
void vTaskCode( void * pvParameters ) {
    for( ;; ) {
        printf("Task running\n");
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}

int main(void) {
    xTaskCreate(vTaskCode, "Task1", 1000, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}
ATask running (printed every second indefinitely)
BProgram crashes because vTaskDelay is called outside a task
CCompilation error due to missing task handle
DNo output because the task is never started
Attempts:
2 left
💡 Hint

Remember that vTaskStartScheduler starts the tasks created.

🔧 Debug
advanced
2:00remaining
Identify the error in this FreeRTOS task creation snippet

Look at the code below. What error will occur when running this code?

FreeRTOS
void vTaskCode( void * pvParameters ) {
    for( ;; ) {
        // Task code here
    }
}

int main(void) {
    BaseType_t result = xTaskCreate(vTaskCode, "Task1", 1000, NULL, 1, NULL);
    if (result != pdPASS) {
        printf("Task creation failed\n");
    }
    // Missing vTaskStartScheduler call
    return 0;
}
AThe program will run normally and print "Task creation failed"
BCompilation error due to missing task function prototype
CThe task will never run because vTaskStartScheduler is not called
DRuntime error because task stack size is too small
Attempts:
2 left
💡 Hint

Think about what starts the FreeRTOS scheduler.

📝 Syntax
advanced
2:00remaining
Which option correctly creates a FreeRTOS task?

Choose the code snippet that correctly creates a FreeRTOS task named "Task1" with priority 2.

AxTaskCreate(Task1Function, "Task1", 512, NULL, 2, NULL);
BxTaskCreate(Task1Function, Task1, 512, NULL, 2, NULL);
CxTaskCreate("Task1", Task1Function, 512, NULL, 2, NULL);
DxTaskCreate(Task1Function, "Task1", 512, NULL, "2", NULL);
Attempts:
2 left
💡 Hint

Check the order and types of parameters for xTaskCreate.

🚀 Application
expert
2:00remaining
How many tasks are running after this code executes?

Given the code below, how many tasks will be running after vTaskStartScheduler() is called?

FreeRTOS
void vTask1(void *pvParameters) { for(;;) {} }
void vTask2(void *pvParameters) { for(;;) {} }

int main(void) {
    xTaskCreate(vTask1, "Task1", 1000, NULL, 1, NULL);
    xTaskCreate(vTask2, "Task2", 1000, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}
A1
B3
C2
D0
Attempts:
2 left
💡 Hint

Don't forget the idle task created automatically by the scheduler.