0
0
FreeRTOSprogramming~20 mins

Why scheduling determines real-time behavior in FreeRTOS - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Real-Time Scheduling Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of task scheduling with preemption

Consider two FreeRTOS tasks with different priorities. Task A has higher priority than Task B. Task B starts first and then Task A is created. What will be the output sequence of the print statements?

FreeRTOS
void TaskA(void *pvParameters) {
    for (;;) {
        printf("A\n");
        vTaskDelay(pdMS_TO_TICKS(100));
    }
}

void TaskB(void *pvParameters) {
    printf("B\n");
    vTaskDelay(pdMS_TO_TICKS(50));
    xTaskCreate(TaskA, "TaskA", 1000, NULL, 2, NULL);
    for (;;) {
        printf("B\n");
        vTaskDelay(pdMS_TO_TICKS(100));
    }
}

int main() {
    xTaskCreate(TaskB, "TaskB", 1000, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}
AB\nA\nB\nA\nB\nA\n...
BA\nB\nA\nB\nA\nB\n...
CB\nB\nB\nA\nA\nA\n...
DA\nA\nA\nB\nB\nB\n...
Attempts:
2 left
💡 Hint

Remember that higher priority tasks preempt lower priority ones immediately.

🧠 Conceptual
intermediate
1:30remaining
Effect of scheduling policy on real-time guarantees

Which scheduling policy in FreeRTOS best ensures that high priority tasks meet their deadlines?

ARandom scheduling of tasks
BRound-robin scheduling with equal priority for all tasks
CCooperative scheduling without preemption
DPreemptive priority-based scheduling
Attempts:
2 left
💡 Hint

Think about which policy allows immediate switching to important tasks.

🔧 Debug
advanced
2:30remaining
Identify the scheduling issue causing missed deadlines

A FreeRTOS system has a high priority task that sometimes misses its deadline. The code snippet below shows the task creation and delay. What scheduling issue is causing the missed deadline?

FreeRTOS
xTaskCreate(HighPriorityTask, "High", 1000, NULL, 3, NULL);

void HighPriorityTask(void *pvParameters) {
    for (;;) {
        // Critical work
        vTaskDelay(pdMS_TO_TICKS(200));
    }
}

xTaskCreate(LowPriorityTask, "Low", 1000, NULL, 1, NULL);

void LowPriorityTask(void *pvParameters) {
    for (;;) {
        // Long blocking operation
        vTaskDelay(pdMS_TO_TICKS(500));
    }
}
AHigh priority task misses deadline because it uses vTaskDelay too long
BHigh priority task is starved because low priority task has higher priority
CLow priority task blocks high priority task due to cooperative scheduling
DHigh priority task is preempted by low priority task due to priority inversion
Attempts:
2 left
💡 Hint

Consider how scheduling works when preemption is disabled or cooperative.

📝 Syntax
advanced
1:30remaining
Identify the syntax error affecting task scheduling

Which option contains a syntax error that will prevent the FreeRTOS scheduler from starting?

FreeRTOS
void main() {
    xTaskCreate(Task1, "Task1", 1000, NULL, 2, NULL);
    xTaskCreate(Task2, "Task2", 1000, NULL, 1, NULL);
    vTaskStartScheduler()
}

void Task1(void *pvParameters) {
    for (;;) {
        // Task code
    }
}

void Task2(void *pvParameters) {
    for (;;) {
        // Task code
    }
}
AUsing void main() instead of int main()
BMissing semicolon after vTaskStartScheduler() call
CTask function missing void parameter type
DIncorrect task priority values (negative numbers)
Attempts:
2 left
💡 Hint

Check for missing punctuation that causes compilation failure.

🚀 Application
expert
3:00remaining
Design a scheduling strategy to guarantee real-time response

You have three tasks: SensorRead (high priority), DataProcessing (medium priority), and Logging (low priority). SensorRead must respond within 10ms. DataProcessing can be delayed up to 100ms. Logging is non-critical. Which scheduling approach best guarantees SensorRead meets its deadline?

AAssign SensorRead highest priority with preemptive scheduling; DataProcessing medium priority; Logging lowest priority
BAssign equal priority to all tasks and use round-robin scheduling
CUse cooperative scheduling with SensorRead yielding after completion
DAssign Logging highest priority to reduce CPU idle time
Attempts:
2 left
💡 Hint

Think about how priority and preemption affect response time.