0
0
FreeRTOSprogramming~20 mins

What is an RTOS in FreeRTOS - Practice Questions & Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RTOS Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding RTOS Basics

Which statement best describes what an RTOS (Real-Time Operating System) is?

AA software that delays all tasks to run them sequentially after a fixed time.
BAn operating system designed to handle tasks within strict timing constraints.
CA system that only runs one task at a time without multitasking.
DAn operating system mainly used for desktop computers and laptops.
Attempts:
2 left
💡 Hint

Think about systems that need to respond quickly and predictably.

Predict Output
intermediate
2:00remaining
RTOS Task Scheduling Output

Consider this FreeRTOS code snippet that creates two tasks with different priorities. What will be the output?

FreeRTOS
void Task1(void *pvParameters) {
  for(;;) {
    printf("Task1 running\n");
    vTaskDelay(1000 / portTICK_PERIOD_MS);
  }
}

void Task2(void *pvParameters) {
  for(;;) {
    printf("Task2 running\n");
    vTaskDelay(500 / portTICK_PERIOD_MS);
  }
}

int main() {
  xTaskCreate(Task1, "Task1", 1000, NULL, 1, NULL);
  xTaskCreate(Task2, "Task2", 1000, NULL, 2, NULL);
  vTaskStartScheduler();
  return 0;
}
ANo output because tasks do not run without an infinite loop.
BTask1 running\nTask1 running\nTask2 running\nTask1 running\nTask2 running\nTask1 running\n...
CTask1 running\nTask2 running\nTask1 running\nTask2 running\nTask1 running\nTask2 running\n...
DTask2 running\nTask2 running\nTask1 running\nTask2 running\nTask2 running\nTask1 running\n...
Attempts:
2 left
💡 Hint

Higher priority tasks run more often and can preempt lower priority tasks.

🔧 Debug
advanced
2:30remaining
Identifying RTOS Deadlock Scenario

What error will this FreeRTOS code cause?

SemaphoreHandle_t xSemaphore;

void TaskA(void *pvParameters) {
  xSemaphoreTake(xSemaphore, portMAX_DELAY);
  // Critical section
  xSemaphoreTake(xSemaphore, portMAX_DELAY);
  xSemaphoreGive(xSemaphore);
  xSemaphoreGive(xSemaphore);
  vTaskDelete(NULL);
}

void TaskB(void *pvParameters) {
  xSemaphoreTake(xSemaphore, portMAX_DELAY);
  // Critical section
  xSemaphoreGive(xSemaphore);
  vTaskDelete(NULL);
}

int main() {
  xSemaphore = xSemaphoreCreateMutex();
  xTaskCreate(TaskA, "TaskA", 1000, NULL, 1, NULL);
  xTaskCreate(TaskB, "TaskB", 1000, NULL, 1, NULL);
  vTaskStartScheduler();
  return 0;
}
ADeadlock because TaskA tries to take the same mutex twice without giving it back.
BStack overflow due to infinite recursion in TaskA.
CNo error; tasks run normally and release the semaphore correctly.
DMemory leak because semaphore is never deleted.
Attempts:
2 left
💡 Hint

Think about what happens when a task tries to take a mutex it already holds.

📝 Syntax
advanced
1:30remaining
Correct FreeRTOS Task Creation Syntax

Which option shows the correct syntax to create a FreeRTOS task that runs a function named MyTask?

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

Remember that the task function name is passed as a pointer without parentheses.

🚀 Application
expert
3:00remaining
Choosing the Best RTOS Feature for a Time-Critical Application

You are designing a system that must respond to sensor input within 5 milliseconds consistently. Which RTOS feature is most important to ensure this?

ARound-robin scheduling to give equal CPU time to all tasks.
BIdle task to save power when no tasks are running.
CPriority-based preemptive scheduling to guarantee high-priority task execution.
DDynamic memory allocation for flexible task creation.
Attempts:
2 left
💡 Hint

Think about how to make sure the most important task runs immediately when needed.