Software timers in FreeRTOS let you schedule functions to run after a delay or periodically without blocking the CPU. This helps keep the system responsive.
void vTimerCallback(TimerHandle_t xTimer) {
printf("Timer expired\n");
}
int main() {
TimerHandle_t xTimer = xTimerCreate("Timer", pdMS_TO_TICKS(1000), pdFALSE, NULL, vTimerCallback);
xTimerStart(xTimer, 0);
vTaskStartScheduler();
return 0;
}The timer is created to run once (pdFALSE) after 1000ms, so the callback prints "Timer expired" exactly once.
void vTimerCallback(TimerHandle_t xTimer) {
vTaskDelay(pdMS_TO_TICKS(500));
printf("Delayed inside timer callback\n");
}Timer callbacks run in the timer service task context and cannot call blocking functions like vTaskDelay. Doing so causes runtime errors.
void vTimerCallback(TimerHandle_t xTimer) {
printf("Tick\n");
}Option D uses pdMS_TO_TICKS(500) to convert 500ms to ticks and pdTRUE to make the timer periodic.
Software timers let the CPU enter low-power sleep modes and only wake when the timer expires, reducing power use compared to busy-wait loops that keep CPU active.
