Bird
Raised Fist0
FreeRTOSprogramming~20 mins

Task function signature in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
FreeRTOS Task Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this FreeRTOS task function signature code?
Consider this FreeRTOS task function signature and its usage. What will be the output when the task runs?
FreeRTOS
void vTaskCode(void *pvParameters) {
    int *p = (int *)pvParameters;
    printf("Value: %d\n", *p);
}

int main() {
    int x = 10;
    vTaskCode(&x);
    return 0;
}
ARuntime error due to invalid pointer
BValue: 0
CCompilation error due to wrong function signature
DValue: 10
Attempts:
2 left
💡 Hint
Remember the task function takes a void pointer parameter which can be cast to any type.
❓ Predict Output
intermediate
2:00remaining
What error occurs with this incorrect FreeRTOS task function signature?
What error will this code produce when compiled or run?
FreeRTOS
void vTaskCode(int pvParameters) {
    printf("Value: %d\n", pvParameters);
}

int main() {
    int x = 5;
    vTaskCode(x);
    return 0;
}
ACompilation error due to wrong parameter type
BPrints: Value: 5
CRuntime error due to invalid pointer
DNo output
Attempts:
2 left
💡 Hint
Check the parameter type expected by FreeRTOS task functions.
🧠 Conceptual
advanced
2:00remaining
Which is the correct FreeRTOS task function signature?
Select the correct function signature for a FreeRTOS task function.
Avoid TaskFunction()
Bint TaskFunction(int pvParameters)
Cvoid TaskFunction(void *pvParameters)
Dvoid TaskFunction(int *pvParameters)
Attempts:
2 left
💡 Hint
FreeRTOS task functions always take a void pointer parameter and return void.
❓ Predict Output
advanced
2:00remaining
What is the output of this FreeRTOS task function with pointer parameter?
What will this code print when the task function runs?
FreeRTOS
void vTaskCode(void *pvParameters) {
    char *msg = (char *)pvParameters;
    printf("Message: %s\n", msg);
}

int main() {
    char message[] = "Hello FreeRTOS";
    vTaskCode(message);
    return 0;
}
AMessage: Hello FreeRTOS
BCompilation error due to wrong cast
CMessage: (null)
DRuntime error due to invalid pointer
Attempts:
2 left
💡 Hint
Casting void pointer to char pointer is valid for string parameters.
🧠 Conceptual
expert
2:00remaining
Why must FreeRTOS task functions have the signature void function(void *pvParameters)?
Choose the best explanation for why FreeRTOS task functions require this signature.
ABecause the scheduler expects a function returning void and taking a generic pointer to pass any data.
BBecause void return type allows returning task status codes to the scheduler.
CBecause the parameter must always be an integer representing task ID.
DBecause FreeRTOS tasks cannot accept any parameters.
Attempts:
2 left
💡 Hint
Think about how the scheduler manages tasks and passes data.

Practice

(1/5)
1.

What is the correct signature for a FreeRTOS task function?

easy
A. int TaskName(int param)
B. void TaskName(void *pvParameters)
C. void TaskName()
D. void TaskName(int *param)

Solution

  1. Step 1: Recall FreeRTOS task function signature

    FreeRTOS tasks must have the signature with return type void and a single void pointer parameter.
  2. Step 2: Match the signature with options

    Only void TaskName(void *pvParameters) matches void TaskName(void *pvParameters) exactly.
  3. Final Answer:

    void TaskName(void *pvParameters) -> Option B
  4. Quick Check:

    Task signature = void TaskName(void *pvParameters) [OK]
Hint: Task functions always return void and take void* parameter [OK]
Common Mistakes:
  • Using int return type instead of void
  • Omitting the void* parameter
  • Using incorrect parameter types
2.

Which of the following is a syntactically correct FreeRTOS task function declaration?

void MyTask(_____)
easy
A. void *pvParameters
B. int param
C. char *name
D. void

Solution

  1. Step 1: Understand parameter type for FreeRTOS tasks

    Task functions must accept a single parameter of type void *.
  2. Step 2: Check each option

    Only void *pvParameters uses void *pvParameters, which is correct syntax.
  3. Final Answer:

    void *pvParameters -> Option A
  4. Quick Check:

    Parameter type = void *pvParameters [OK]
Hint: Task parameter must be void pointer (void*) [OK]
Common Mistakes:
  • Using int or char pointer instead of void pointer
  • Using void without pointer
  • Missing parameter entirely
3.

What will happen if you run this FreeRTOS task function?

void ExampleTask(void *pvParameters) {
    for(;;) {
        // Task code here
    }
}
medium
A. The task will return a value causing runtime error.
B. The task will run once and then exit.
C. The task will cause a compile error.
D. The task will run repeatedly in an infinite loop.

Solution

  1. Step 1: Analyze the task function loop

    The task contains a for(;;) infinite loop, so it runs repeatedly.
  2. Step 2: Understand FreeRTOS task behavior

    Tasks should not return; they run inside infinite loops to keep running.
  3. Final Answer:

    The task will run repeatedly in an infinite loop. -> Option D
  4. Quick Check:

    Infinite loop in task = runs repeatedly [OK]
Hint: FreeRTOS tasks run inside infinite loops [OK]
Common Mistakes:
  • Thinking task runs once and exits
  • Expecting return value from task
  • Confusing infinite loop with error
4.

Identify the error in this FreeRTOS task function:

void FaultyTask(void *pvParameters) {
    int count = 0;
    while(count < 5) {
        count++;
    }
    return;
}
medium
A. The function should not return; it must loop forever.
B. The parameter type is incorrect.
C. The variable count should be a pointer.
D. The while loop condition is invalid syntax.

Solution

  1. Step 1: Check task function return behavior

    FreeRTOS tasks must not return; they should run inside infinite loops.
  2. Step 2: Analyze the code flow

    This task loops 5 times then returns, which is incorrect for FreeRTOS tasks.
  3. Final Answer:

    The function should not return; it must loop forever. -> Option A
  4. Quick Check:

    Tasks must not return, use infinite loop [OK]
Hint: Tasks must never return; use infinite loops [OK]
Common Mistakes:
  • Allowing task to return
  • Changing parameter type incorrectly
  • Misunderstanding loop conditions
5.

You want to pass an integer value to a FreeRTOS task. Which is the correct way to define and use the task function?

void NumberTask(_____)
{
    int received = *(int *)pvParameters;
    for(;;) {
        // Use received value
    }
}
hard
A. void pvParameters
B. int pvParameters
C. void *pvParameters
D. int *pvParameters

Solution

  1. Step 1: Recall task function parameter type

    Task functions must accept a void * parameter to allow any data type.
  2. Step 2: Understand data passing

    The integer is passed via pointer cast from void *, so parameter must be void *pvParameters.
  3. Final Answer:

    void *pvParameters -> Option C
  4. Quick Check:

    Use void* parameter to pass any data type [OK]
Hint: Always use void* parameter to pass data to tasks [OK]
Common Mistakes:
  • Using int instead of void* parameter
  • Using void without pointer
  • Not casting void* to correct type inside task
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