0
0
FreeRTOSprogramming~20 mins

Idle task and idle hook in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
FreeRTOS Idle 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 the idle hook function?

Consider the following FreeRTOS idle hook function code snippet. What will be printed repeatedly when the system is idle?

FreeRTOS
void vApplicationIdleHook(void) {
    static int count = 0;
    count++;
    if (count % 1000 == 0) {
        printf("Idle hook called %d times\n", count);
    }
}
AIdle hook called 1000 times\nIdle hook called 2000 times\nIdle hook called 3000 times\n...
BIdle hook called 1 times\nIdle hook called 2 times\nIdle hook called 3 times\n...
CNo output will be printed because idle hook is never called.
DCompilation error due to missing return statement.
Attempts:
2 left
💡 Hint

The idle hook runs repeatedly when no other tasks are ready. The count increments each call.

🧠 Conceptual
intermediate
1:30remaining
What is the main purpose of the FreeRTOS idle task?

In FreeRTOS, what is the primary role of the idle task?

ATo manage memory allocation and deallocation automatically.
BTo run user application code with highest priority.
CTo execute when no other tasks are ready, keeping the CPU busy or in low power mode.
DTo handle interrupts and hardware events.
Attempts:
2 left
💡 Hint

Think about what happens when no tasks are ready to run.

🔧 Debug
advanced
2:00remaining
Why does this idle hook cause a stack overflow?

Examine the following idle hook code. Why might it cause a stack overflow?

FreeRTOS
void vApplicationIdleHook(void) {
    char buffer[1024];
    memset(buffer, 0, sizeof(buffer));
    // Do some processing
}
AThere is no stack overflow; code is safe.
BThe memset function is not allowed in idle hook and causes error.
CIdle hook cannot declare local variables.
DThe buffer is too large for the idle task stack, causing overflow.
Attempts:
2 left
💡 Hint

Consider the size of the idle task stack and local variables.

📝 Syntax
advanced
1:30remaining
Which idle hook implementation is syntactically correct?

Choose the syntactically correct FreeRTOS idle hook function implementation.

Avoid vApplicationIdleHook(void) { /* empty */ }
Bvoid vApplicationIdleHook(void) { return 0; }
Cvoid vApplicationIdleHook(void) { int x =; }
Dvoid vApplicationIdleHook() { while(1) {} }
Attempts:
2 left
💡 Hint

Check function signature and valid C syntax.

🚀 Application
expert
2:30remaining
How to safely perform background cleanup in the idle hook?

You want to perform low priority cleanup tasks in the FreeRTOS idle hook without blocking other tasks. Which approach is best?

ADisable interrupts inside <code>vApplicationIdleHook</code> and run cleanup code.
BSet a flag in <code>vApplicationIdleHook</code> and perform cleanup in a low priority task.
CPerform all cleanup directly inside <code>vApplicationIdleHook</code> with long loops.
DCall <code>vTaskDelay</code> inside <code>vApplicationIdleHook</code> to wait during cleanup.
Attempts:
2 left
💡 Hint

Consider responsiveness and what the idle hook should do quickly.