Complete the code to define a timer callback function with the correct parameter type.
void TimerCallback([1] xTimer) {
// Timer callback code here
}The timer callback function in FreeRTOS receives a parameter of type TimerHandle_t, which is a handle to the timer that expired.
Complete the code to start a FreeRTOS timer inside its callback function.
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
void TimerCallback(TimerHandle_t xTimer) {
xTimerStartFromISR(xTimer, [1]);
}When calling xTimerStartFromISR, the block time parameter should be zero because blocking is not allowed in an ISR context.
Fix the error in the timer callback function to correctly notify a task from ISR context.
void TimerCallback(TimerHandle_t xTimer) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR(xTaskToNotify, [1], &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}The third parameter of vTaskNotifyGiveFromISR is a pointer to BaseType_t variable that indicates if a context switch is required. Passing xHigherPriorityTaskWoken by reference is correct.
Fill both blanks to correctly create and start a one-shot FreeRTOS timer.
TimerHandle_t xTimer = xTimerCreate("OneShotTimer", pdMS_TO_TICKS(1000), [1], NULL, TimerCallback); if (xTimer != NULL) { xTimerStart(xTimer, [2]); }
The third parameter of xTimerCreate is uxAutoReload. For a one-shot timer, it should be pdFALSE. The block time for xTimerStart can be portMAX_DELAY to wait indefinitely for the command to be sent.
Fill all three blanks to implement a timer callback that stops the timer and sends a notification to a task.
void TimerCallback(TimerHandle_t xTimer) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xTimerStop(xTimer, [1]);
vTaskNotifyGiveFromISR([2], &xHigherPriorityTaskWoken);
[3](xHigherPriorityTaskWoken);
}In the timer callback, xTimerStop is called with zero block time because blocking is not allowed. The task to notify is xTaskToNotify. Finally, portYIELD_FROM_ISR is called with xHigherPriorityTaskWoken to request a context switch if needed.
