Bird
Raised Fist0
FreeRTOSprogramming~10 mins

Real-time vs general-purpose OS in FreeRTOS - Interactive Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a FreeRTOS task that prints "Hello World".

FreeRTOS
xTaskCreate([1], "Task1", 1000, NULL, 1, NULL);
Drag options to blanks, or click blank then click option'
AvTaskFunction
BvTaskStartScheduler
CvTaskDelete
DvTaskDelay
Attempts:
3 left
💡 Hint
Common Mistakes
Using scheduler start function instead of task function.
Using delay or delete functions as task function.
2fill in blank
medium

Complete the code to start the FreeRTOS scheduler.

FreeRTOS
int main(void) {
    // Setup code
    [1]();
    for(;;); // Loop forever
}
Drag options to blanks, or click blank then click option'
AvTaskStartScheduler
BxTaskCreate
CvTaskDelay
DvTaskDelete
Attempts:
3 left
💡 Hint
Common Mistakes
Calling task creation instead of starting scheduler.
Using delay or delete functions here.
3fill in blank
hard

Fix the error in the task function to correctly delay the task for 1000 milliseconds.

FreeRTOS
void vTaskFunction(void *pvParameters) {
    for(;;) {
        // Do work
        [1];
    }
}
Drag options to blanks, or click blank then click option'
AvTaskDelay(1000 / portTICK_PERIOD_MS)
BvTaskDelay(1000)
CvTaskDelay(pdMS_TO_TICKS(1000))
DvTaskDelay(1000 * portTICK_PERIOD_MS)
Attempts:
3 left
💡 Hint
Common Mistakes
Passing milliseconds directly without conversion.
Multiplying or dividing by portTICK_PERIOD_MS incorrectly.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps task names to their priorities for tasks with priority greater than 1.

FreeRTOS
task_priorities = {task.name: task[1] for task in tasks if task.priority [2] 1}
Drag options to blanks, or click blank then click option'
A.priority
B>
C<
D.name
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operator.
Accessing wrong attribute for priority.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase task names to their stack sizes for tasks with stack size greater than 512.

FreeRTOS
task_info = { [1]: [2] for task in tasks if task.stack_size [3] 512}
Drag options to blanks, or click blank then click option'
Atask.name.upper()
Btask.stack_size
C>
Dtask.priority
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute for stack size.
Using wrong comparison operator.

Practice

(1/5)
1. Which of the following best describes a real-time operating system (RTOS) like FreeRTOS?
easy
A. It responds quickly and predictably to events.
B. It is designed mainly for running desktop applications.
C. It delays tasks unpredictably to save power.
D. It only runs one task at a time without multitasking.

Solution

  1. Step 1: Understand RTOS purpose

    RTOS is designed to respond quickly and predictably to events, ensuring timing is guaranteed.
  2. Step 2: Compare options

    Options B, C, and D describe general-purpose OS or incorrect behavior.
  3. Final Answer:

    It responds quickly and predictably to events. -> Option A
  4. Quick Check:

    RTOS = predictable quick response [OK]
Hint: RTOS means fast and predictable response to events [OK]
Common Mistakes:
  • Confusing RTOS with general-purpose OS
  • Thinking RTOS delays tasks unpredictably
  • Assuming RTOS runs only one task
2. Which syntax correctly creates a FreeRTOS task in C?
easy
A. createTask(TaskFunction, "Task1", 1000, NULL, 1, NULL);
B. xTaskCreate(TaskFunction, "Task1", 1000, NULL, 1, NULL);
C. xTaskStart(TaskFunction, "Task1", 1000, NULL, 1, NULL);
D. TaskCreate(xTask, "Task1", 1000, NULL, 1, NULL);

Solution

  1. Step 1: Recall FreeRTOS task creation function

    The correct function to create a task is xTaskCreate with parameters: function, name, stack size, parameters, priority, and handle.
  2. Step 2: Check each option

    Only xTaskCreate(TaskFunction, "Task1", 1000, NULL, 1, NULL); uses the correct function name and parameter order. Others use wrong function names.
  3. Final Answer:

    xTaskCreate(TaskFunction, "Task1", 1000, NULL, 1, NULL); -> Option B
  4. Quick Check:

    FreeRTOS task creation = xTaskCreate [OK]
Hint: FreeRTOS task creation always uses xTaskCreate() [OK]
Common Mistakes:
  • Using incorrect function names like createTask or xTaskStart
  • Mixing up parameter order
  • Omitting required parameters
3. Given this FreeRTOS code snippet, what will be the output sequence printed?
void Task1(void *pvParameters) {
  for (int i = 0; i < 3; i++) {
    printf("Task1: %d\n", i);
    vTaskDelay(10);
  }
  vTaskDelete(NULL);
}

void Task2(void *pvParameters) {
  for (int i = 0; i < 3; i++) {
    printf("Task2: %d\n", i);
    vTaskDelay(10);
  }
  vTaskDelete(NULL);
}
medium
A. Task1: 0 Task1: 1 Task1: 2 Task2: 0 Task2: 1 Task2: 2
B. Task2: 0 Task2: 1 Task2: 2 Task1: 0 Task1: 1 Task1: 2
C. Task1: 0 Task2: 1 Task1: 2 Task2: 0 Task1: 1 Task2: 2
D. Task1: 0 Task2: 0 Task1: 1 Task2: 1 Task1: 2 Task2: 2

Solution

  1. Step 1: Understand vTaskDelay effect

    vTaskDelay causes the current task to pause, allowing other tasks of equal priority to run.
  2. Step 2: Trace task execution order

    Task1 prints 0, delays; Task2 runs, prints 0, delays; then Task1 prints 1, and so on, alternating output.
  3. Final Answer:

    Task1: 0 Task2: 0 Task1: 1 Task2: 1 Task1: 2 Task2: 2 -> Option D
  4. Quick Check:

    vTaskDelay causes task switching, so output alternates [OK]
Hint: vTaskDelay switches tasks, output alternates between tasks [OK]
Common Mistakes:
  • Assuming one task runs fully before the other
  • Ignoring vTaskDelay effect
  • Mixing output order
4. Identify the error in this FreeRTOS task creation code:
void Task(void *pvParameters) {
  while(1) {
    // Task code
  }
}

int main() {
  xTaskCreate(Task, "Task", 1000, NULL, 1, NULL);
  return 0;
}
medium
A. The task function must call vTaskDelete(NULL) to end.
B. Stack size 1000 is too large and causes error.
C. vTaskStartScheduler() is missing and should be added.
D. The task function should not have an infinite loop.

Solution

  1. Step 1: Analyze main function

    A task is created with xTaskCreate, but the scheduler is never started.
  2. Step 2: Recall FreeRTOS startup

    vTaskStartScheduler() must be called after creating initial tasks to begin scheduling and multitasking.
  3. Final Answer:

    vTaskStartScheduler() is missing and should be added. -> Option C
  4. Quick Check:

    FreeRTOS requires vTaskStartScheduler() call [OK]
Hint: vTaskStartScheduler() starts the RTOS scheduler [OK]
Common Mistakes:
  • Thinking infinite loop is wrong in RTOS tasks
  • Missing vTaskStartScheduler call
  • Assuming stack size causes error
5. You are designing a system that must control a robotic arm with precise timing to avoid damage. Which OS choice is best and why?
hard
A. Use a real-time OS like FreeRTOS because it guarantees predictable timing.
B. Use a real-time OS because it delays tasks unpredictably to save power.
C. Use a general-purpose OS because it has better user interfaces.
D. Use a general-purpose OS because it handles many tasks simultaneously.

Solution

  1. Step 1: Identify system requirements

    Precise timing is critical to avoid damage, so predictable response is needed.
  2. Step 2: Match OS type to requirement

    Real-time OS guarantees predictable timing; general-purpose OS may delay unpredictably.
  3. Final Answer:

    Use a real-time OS like FreeRTOS because it guarantees predictable timing. -> Option A
  4. Quick Check:

    Precise timing needs RTOS, not general OS [OK]
Hint: Precise timing needs RTOS, not general OS [OK]
Common Mistakes:
  • Choosing general-purpose OS for timing-critical tasks
  • Confusing power saving with timing guarantees
  • Ignoring predictability requirement
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard