Skip to the content.
« Previous Index Next »

Firmware Coding Standard — Power Management (FreeRTOS)

1) Purpose

Define how firmware manages power consumption using FreeRTOS and hardware features. Ensure predictable entry/exit from low-power states, no data loss, and consistent wakeup behavior.


2) Principles


3) FreeRTOS Integration


4) Task & Driver Rules


5) Power Modes


6) Retention & State Saving


7) Time & Tick Handling


8) Testing & Measurement


9) Anti-Patterns


10) Review Checklist (Power)


11) CI/Lint Gates


12) Example Patterns

PM manager task

void pm_task(void *arg) {
    for (;;) {
        EventBits_t sys_state = xEventGroupWaitBits(sysEvt, EVT_IDLE, pdTRUE, pdTRUE, portMAX_DELAY);

        if (sys_state & EVT_IDLE) {
            if (can_enter_stop_mode()) {
                enter_stop_mode();
            }
        }
    }
}

Tickless idle override

void vPortSuppressTicksAndSleep(TickType_t expectedIdleTime) {
    if (expectedIdleTime > MIN_SLEEP_TICKS) {
        prepare_for_sleep();
        enter_sleep_mode();   // WFI/WFE or vendor HAL
        restore_after_sleep();
    }
}

Wake source logging

uint32_t src = hw_get_wakeup_source();
LOG_INFO("PM", "Wake from source=0x%08X", src);

« Previous Index Next »