0
0
FreeRTOSprogramming~20 mins

Why RTOS over bare-metal in FreeRTOS - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RTOS Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use an RTOS instead of bare-metal for multitasking?

Consider a microcontroller project that needs to handle multiple tasks like sensor reading, communication, and user interface. Why might using an RTOS be better than bare-metal programming?

ARTOS allows tasks to run seemingly at the same time by managing task switching automatically.
BBare-metal programming always uses more memory than RTOS.
CRTOS eliminates the need for interrupts completely.
DBare-metal code cannot handle more than one task.
Attempts:
2 left
💡 Hint

Think about how multitasking is handled and what RTOS provides automatically.

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

Given two FreeRTOS tasks with different priorities, what will be printed to the console?

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

void Task2(void *pvParameters) {
  for (;;) {
    printf("Task2 running\n");
    vTaskDelay(pdMS_TO_TICKS(50));
  }
}

int main() {
  xTaskCreate(Task1, "Task1", 1000, NULL, 1, NULL);
  xTaskCreate(Task2, "Task2", 1000, NULL, 2, NULL);
  vTaskStartScheduler();
  return 0;
}
AOnly Task2 running repeatedly.
BTask2 running\nTask1 running\nTask2 running\nTask1 running\n...
COnly Task1 running repeatedly.
DTask1 running\nTask2 running\nTask1 running\nTask2 running\n...
Attempts:
2 left
💡 Hint

Higher priority tasks run before lower priority ones and can preempt them.

🔧 Debug
advanced
2:00remaining
Identify the problem in this bare-metal multitasking attempt

This bare-metal code tries to run two tasks by calling their functions in a loop. What is the main issue?

FreeRTOS
void taskA() {
  while(1) {
    // do something
  }
}

void taskB() {
  while(1) {
    // do something else
  }
}

int main() {
  while(1) {
    taskA();
    taskB();
  }
  return 0;
}
AtaskA never returns, so taskB is never called.
BBoth tasks run simultaneously without issues.
CThe main loop causes a stack overflow.
DtaskB runs before taskA causing a race condition.
Attempts:
2 left
💡 Hint

Consider what happens when a function has an infinite loop.

📝 Syntax
advanced
2:00remaining
Which FreeRTOS API call is correct to create a task?

Choose the correct syntax to create a FreeRTOS task named "MyTask" with priority 3.

AxTaskCreate(MyTask, 3, "MyTask", 1000, NULL, NULL);
BxTaskCreate("MyTask", MyTask, 1000, NULL, 3, NULL);
CxTaskCreate("MyTask", 1000, MyTask, NULL, 3, NULL);
DxTaskCreate(MyTask, "MyTask", 1000, NULL, 3, NULL);
Attempts:
2 left
💡 Hint

Check the order of parameters: function pointer, name, stack size, parameters, priority, handle.

🚀 Application
expert
3:00remaining
How does RTOS improve responsiveness compared to bare-metal?

In a system with multiple time-critical tasks, how does using an RTOS improve responsiveness over bare-metal programming?

ARTOS disables all interrupts to avoid delays, improving responsiveness.
BRTOS runs all tasks in parallel on multiple cores automatically.
CRTOS uses preemptive scheduling to switch tasks immediately when higher priority tasks become ready.
DBare-metal systems cannot use interrupts, so RTOS is needed for responsiveness.
Attempts:
2 left
💡 Hint

Think about how RTOS handles task priorities and switching.