Bird
0
0

Consider the following FreeRTOS task code snippet:

medium📝 Predict Output Q4 of 15
FreeRTOS - Task Scheduling
Consider the following FreeRTOS task code snippet:
TickType_t xLastWakeTime = xTaskGetTickCount();
for (;;) {
    vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(250));
    printf("Heartbeat\n");
}

What is the expected interval between each "Heartbeat" print?
AIt depends on the task execution time
BApproximately 500 milliseconds
CApproximately 100 milliseconds
DApproximately 250 milliseconds
Step-by-Step Solution
Solution:
  1. Step 1: Understand vTaskDelayUntil()

    This function delays a task until a fixed time relative to the last wake time.
  2. Step 2: Analyze the delay period

    The delay is set to pdMS_TO_TICKS(250), which converts 250 ms to ticks.
  3. Step 3: Calculate interval

    Since the delay is relative to the last wake time, the task runs every 250 ms regardless of execution time.
  4. Final Answer:

    Approximately 250 milliseconds -> Option D
  5. Quick Check:

    Delay period matches print interval [OK]
Quick Trick: vTaskDelayUntil keeps fixed intervals, ignoring execution time [OK]
Common Mistakes:
  • Assuming delay adds to execution time causing longer intervals
  • Confusing vTaskDelay with vTaskDelayUntil behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes