Bird
0
0

This FreeRTOS code snippet does not behave as expected. What is the main problem?

medium📝 Debug Q14 of 15
FreeRTOS - RTOS Fundamentals
This FreeRTOS code snippet does not behave as expected. What is the main problem?
void Task(void *pvParameters) {
  while(1) {
    // Do some work
    vTaskDelay(1000);
  }
}

int main() {
  xTaskCreate(Task, "Task", 1000, NULL, 1, NULL);
  vTaskStartScheduler();
  return 0;
}
AvTaskStartScheduler should be called before creating tasks
BvTaskDelay needs pdMS_TO_TICKS macro for delay time
CxTaskCreate missing priority parameter
DTask function must return an int
Step-by-Step Solution
Solution:
  1. Step 1: Check vTaskDelay usage

    vTaskDelay expects ticks, but 1000 is milliseconds; pdMS_TO_TICKS converts ms to ticks.
  2. Step 2: Identify correct delay call

    Correct call is vTaskDelay(pdMS_TO_TICKS(1000)) to delay 1000 ms properly.
  3. Final Answer:

    vTaskDelay needs pdMS_TO_TICKS macro for delay time -> Option B
  4. Quick Check:

    Delay in ticks, not ms [OK]
Quick Trick: Always convert ms to ticks with pdMS_TO_TICKS [OK]
Common Mistakes:
  • Passing milliseconds directly to vTaskDelay
  • Thinking task functions must return int
  • Calling scheduler before creating tasks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes