0
0
FreeRTOSprogramming~20 mins

Why design patterns ensure reliable multi-tasking in FreeRTOS - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
FreeRTOS Multi-tasking Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How do design patterns help in FreeRTOS multi-tasking?

Which statement best explains why design patterns improve reliability in FreeRTOS multi-tasking?

AThey automatically detect and fix bugs in task code during runtime.
BThey increase the CPU clock speed to handle more tasks simultaneously.
CThey provide reusable solutions that manage task synchronization and resource sharing effectively.
DThey eliminate the need for task priorities by running all tasks sequentially.
Attempts:
2 left
💡 Hint

Think about how design patterns help organize code and manage shared resources.

Predict Output
intermediate
2:00remaining
Output of a FreeRTOS task synchronization example

What is the output of this FreeRTOS code snippet that uses a binary semaphore to synchronize two tasks?

FreeRTOS
SemaphoreHandle_t xSemaphore;

void Task1(void *pvParameters) {
    xSemaphoreTake(xSemaphore, portMAX_DELAY);
    printf("Task1 running\n");
    xSemaphoreGive(xSemaphore);
    vTaskDelete(NULL);
}

void Task2(void *pvParameters) {
    printf("Task2 running\n");
    xSemaphoreGive(xSemaphore);
    vTaskDelete(NULL);
}

int main() {
    xSemaphore = xSemaphoreCreateBinary();
    xTaskCreate(Task1, "Task1", 1000, NULL, 1, NULL);
    xTaskCreate(Task2, "Task2", 1000, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}
A
Task2 running
B
Task1 running
Task2 running
C
Task1 running
D
Task2 running
Task1 running
Attempts:
2 left
💡 Hint

Consider which task gives the semaphore and which waits for it.

🔧 Debug
advanced
2:00remaining
Identify the cause of a deadlock in FreeRTOS tasks

Given two tasks that each wait for a semaphore held by the other, what is the cause of the deadlock?

FreeRTOS
SemaphoreHandle_t sem1, sem2;

void TaskA(void *pvParameters) {
    xSemaphoreTake(sem1, portMAX_DELAY);
    vTaskDelay(10);
    xSemaphoreTake(sem2, portMAX_DELAY);
    // ...
}

void TaskB(void *pvParameters) {
    xSemaphoreTake(sem2, portMAX_DELAY);
    vTaskDelay(10);
    xSemaphoreTake(sem1, portMAX_DELAY);
    // ...
}
AThe delay function causes the tasks to miss semaphore signals.
BBoth tasks wait indefinitely for semaphores held by each other, causing a deadlock.
CThe semaphores are not created before tasks start, causing a null pointer error.
DThe tasks have the same priority, so one never runs.
Attempts:
2 left
💡 Hint

Think about what happens when two tasks wait on each other's resources.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in FreeRTOS task creation

Which option contains the correct syntax to create a FreeRTOS task?

FreeRTOS
void vTaskCode(void *pvParameters) {
    for(;;) {
        // Task code
    }
}
AxTaskCreate(vTaskCode, "Task", 1000, NULL, 1, NULL);
BxTaskCreate(vTaskCode, Task, 1000, NULL, 1, NULL);
CxTaskCreate(&vTaskCode, "Task", 1000, NULL, 1, NULL);
DxTaskCreate(vTaskCode(), "Task", 1000, NULL, 1, NULL);
Attempts:
2 left
💡 Hint

Check the function pointer and string syntax.

🚀 Application
expert
3:00remaining
Choosing the right design pattern for task communication

You need to design a FreeRTOS system where multiple producer tasks send data to a single consumer task safely and efficiently. Which design pattern is best suited for this scenario?

AUsing a message queue to buffer data between producers and consumer.
BUsing global variables accessed directly by all tasks.
CUsing a mutex to lock the consumer task while producers run.
DUsing event groups to signal task completion only.
Attempts:
2 left
💡 Hint

Think about how to safely pass data between tasks without conflicts.