Skip to the content.
« Previous Index Next »

Firmware Coding Standard — Timing & Timebase (FreeRTOS)

1) Purpose

Define strict rules for using time in firmware: system tick, delays, scheduling, and handling overflow. Ensure timing is deterministic, portable, and free from hidden jitter.


2) Principles


3) Tick Configuration


4) Task Timing Rules


5) Timer Services


6) ISRs & Time


7) Overflow Handling


8) Jitter & Latency Budgets


9) Anti-Patterns


10) Review Checklist (Timing)


11) CI/Lint Gates


12) Example Patterns

Periodic task with jitter control

static void task_comms(void *arg)
{
    const TickType_t period = pdMS_TO_TICKS(10);
    TickType_t next = xTaskGetTickCount();

    for (;;) {
        next += period;
        comms_poll();  // bounded < 2ms
        vTaskDelayUntil(&next, period);
    }
}

Timeout check (wrap-safe)

TickType_t start = xTaskGetTickCount();
while ((TickType_t)(xTaskGetTickCount() - start) < pdMS_TO_TICKS(200)) {
    if (is_ready()) break;
}

Static timer

static StaticTimer_t ledTimerCb;
static TimerHandle_t ledTimerH;

ledTimerH = xTimerCreateStatic(
    "ledBlink",
    pdMS_TO_TICKS(500),
    pdTRUE,        // auto-reload
    NULL,
    led_blink_cb,
    &ledTimerCb
);

« Previous Index Next »