What is the execution context of a FreeRTOS timer callback function?
A FreeRTOS timer callback function runs in the context of the Timer Service/Daemon task, not in the context of the task that created the timer.
Click to reveal answer
beginner
Why should FreeRTOS timer callbacks avoid blocking calls?
Because timer callbacks run in the Timer Service task, blocking calls can delay other timers and system operations, causing timing issues.
Click to reveal answer
intermediate
Can FreeRTOS timer callbacks call API functions that block or wait for a semaphore?
No, timer callbacks should only call FreeRTOS API functions that are safe to use from the Timer Service task and must not block or wait for semaphores.
Click to reveal answer
intermediate
How can you safely communicate from a timer callback to a task?
Use thread-safe mechanisms like queues or event groups to send data or signals from the timer callback to a task for processing.
Click to reveal answer
advanced
What happens if a timer callback takes too long to execute?
If a timer callback runs too long, it can delay the Timer Service task, causing other timers to expire late and potentially disrupting system timing.
Click to reveal answer
In which task context does a FreeRTOS timer callback run?
ATimer Service/Daemon task
BThe task that created the timer
CInterrupt Service Routine (ISR)
DIdle task
✗ Incorrect
Timer callbacks run in the Timer Service/Daemon task context, not in the creating task or ISR.
Which of the following is safe to do inside a FreeRTOS timer callback?
ABlock waiting for a semaphore
BCall vTaskDelay()
CSend data to a queue
DPerform a long computation
✗ Incorrect
Sending data to a queue is safe and non-blocking; blocking or long operations should be avoided in timer callbacks.
What is a recommended way to handle complex processing triggered by a timer callback?
AUse a queue to notify a task to process
BDisable the timer during processing
CCall vTaskDelay() inside the callback
DDo all processing inside the timer callback
✗ Incorrect
Use a queue or other synchronization to notify a task to handle complex or blocking processing.
What could happen if a timer callback blocks or runs too long?
ANothing, it is safe
BThe system will reset immediately
CThe callback will run in parallel
DOther timers may be delayed
✗ Incorrect
Blocking or long callbacks delay the Timer Service task, causing other timers to expire late.
Which FreeRTOS API function is safe to call inside a timer callback?
AxSemaphoreTake() with block time
BxQueueSend() with zero block time
CvTaskDelay()
DxTaskCreate()
✗ Incorrect
xQueueSend() with zero block time is safe; blocking or task creation functions are not safe inside timer callbacks.
Explain the execution context of a FreeRTOS timer callback and why it matters.
Think about which task runs the callback and how that affects what you can do inside it.
You got /3 concepts.
Describe best practices for handling long or blocking operations triggered by a FreeRTOS timer callback.
Consider how to keep the Timer Service task responsive.
You got /3 concepts.
Practice
(1/5)
1. In FreeRTOS, where does a timer callback function execute when a timer expires?
easy
A. Inside the main application task context
B. Inside an interrupt service routine (ISR)
C. Inside the timer service task context
D. Inside a hardware timer peripheral
Solution
Step 1: Understand timer callback execution
Timer callbacks in FreeRTOS run when the timer expires, but not in the main task or ISR context.
Step 2: Identify the correct context
The timer callback runs inside the timer service task context, which is a dedicated task for handling timers.
Final Answer:
Inside the timer service task context -> Option C
Quick Check:
Timer callback context = timer service task [OK]
Hint: Timer callbacks run in timer service task, not main or ISR [OK]
Common Mistakes:
Thinking timer callbacks run in ISR context
Assuming callbacks run in main application task
Confusing hardware timer peripheral with callback context
2. Which of the following is the correct way to define a FreeRTOS timer callback function?
easy
A. void TimerCallback(TimerHandle_t xTimer)
B. void TimerCallback(void)
C. int TimerCallback(int timerId)
D. void TimerCallback(void *param)
Solution
Step 1: Recall FreeRTOS timer callback signature
The callback function must accept a TimerHandle_t parameter representing the timer.
Step 2: Match the correct function signature
Only the signature with void TimerCallback(TimerHandle_t xTimer) matches FreeRTOS requirements.
Final Answer:
void TimerCallback(TimerHandle_t xTimer) -> Option A
The timer is created with 1 second period, one-shot, and started, but vTaskStartScheduler() is missing.
Step 2: Check scheduler requirement
FreeRTOS timers require the scheduler (and timer service task) to be running via vTaskStartScheduler(); without it, the callback never executes, producing no output.
Final Answer:
No output -> Option B
Quick Check:
Missing vTaskStartScheduler() = no callback execution [OK]
A. Using vTaskDelay inside timer callback blocks timer service task
B. Missing return statement in callback
C. Incorrect parameter type in callback
D. printf cannot be used in timer callbacks
Solution
Step 1: Understand timer callback context
Timer callbacks run inside the timer service task, which handles all timers sequentially.
Step 2: Analyze use of vTaskDelay in callback
Calling vTaskDelay blocks the timer service task, delaying other timers and causing timing issues.
Final Answer:
Using vTaskDelay inside timer callback blocks timer service task -> Option A
Quick Check:
Blocking calls in timer callback delay all timers [OK]
Hint: Never block or delay inside timer callbacks [OK]
Common Mistakes:
Thinking callbacks can safely block or delay
Assuming missing return causes error
Believing printf is disallowed in callbacks
5. You want to toggle an LED every 500ms using a FreeRTOS timer. Which approach correctly uses the timer callback without blocking the timer service task?