Bird
0
0

Identify the error in this code snippet intended to delay a task for 200 milliseconds:

medium📝 Debug Q14 of 15
FreeRTOS - Task Scheduling
Identify the error in this code snippet intended to delay a task for 200 milliseconds:
void Task(void *params) {
    while(1) {
        doWork();
        vTaskDelay(200);
    }
}
AvTaskDelay cannot be used inside a while loop
BdoWork() must be called after vTaskDelay()
CThe task function must return a value
DvTaskDelay should use pdMS_TO_TICKS(200) to convert milliseconds
Step-by-Step Solution
Solution:
  1. Step 1: Check vTaskDelay argument

    The argument 200 is treated as ticks, not milliseconds. To delay 200 ms, convert using pdMS_TO_TICKS(200).
  2. Step 2: Verify other code parts

    Calling doWork() before delay is valid. The task function returns void, which is correct.
  3. Final Answer:

    vTaskDelay should use pdMS_TO_TICKS(200) to convert milliseconds -> Option D
  4. Quick Check:

    Convert ms to ticks with pdMS_TO_TICKS() [OK]
Quick Trick: Always convert ms to ticks before passing to vTaskDelay() [OK]
Common Mistakes:
  • Passing milliseconds directly to vTaskDelay()
  • Thinking vTaskDelay can't be in loops
  • Expecting task functions to return values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes