Clockwork

A colleague prototyped a system health monitor that prints periodic status ticks using a FreeRTOS software timer. The timer callback fires every 100ms and prints "TICK:<n>" (where n counts from 1). After 5 ticks, a monitoring task stops the timer and prints "DONE".

Software timers run inside the FreeRTOS timer service (daemon) task, which it shares with every other software timer. That means a callback must stay short: a long-running or indefinitely-blocking callback delays every other timer in the system. A few bytes of UART output is fine; waiting inside the callback on an event that may never arrive is not.

Available FreeRTOS APIs: xTimerCreate(name, period, auto_reload, timer_id, callback) xTimerStart(timer, block_time) xTimerStop(timer, block_time) xTimerGetTimerDaemonTaskMemory() (not needed, handled by config) xTaskCreate(function, name, stack_size, param, priority, handle) vTaskStartScheduler() vTaskDelay(ticks) pdMS_TO_TICKS(ms) pdTRUE / pdFALSE portMAX_DELAY configMINIMAL_STACK_SIZE configTIMER_TASK_PRIORITY

Include timers.h for the software timer APIs.

Loading the interactive arena.