Skip to the content.
« Previous Index Next »

Firmware Coding Standard — Task Synchronization (FreeRTOS)

It focuses on determinism, safety, and clarity.

1) Principles


2) Primitive Selection (Use This Guide)


3) Rules by Primitive

A. Direct-to-Task Notifications

B. Queues

C. Stream/Message Buffers

D. Event Groups

E. Mutexes & Semaphores


4) ISR & Critical Sections


5) Deadlock, Priority Inversion, and Contention


6) Time & Units


7) Memory Visibility & “volatile”


8) Startup, Shutdown, and Errors


9) Observability & Tuning


10) Anti-Patterns (Do Not Do)


11) Review Checklist (Sync-Focused)


Quick Patterns (snippets)

Notify (counting)

// ISR
vTaskNotifyGiveFromISR(taskH, &hpw); portYIELD_FROM_ISR(hpw);

// Task
ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(50));

Queue (pointer payload, zero-copy)

typedef struct { uint8_t *buf; size_t len; } msg_t;
xQueueSend(q, &msg, pdMS_TO_TICKS(10));

Event barrier (ALL, auto-clear)

xEventGroupWaitBits(eg, A|B|C, pdTRUE, pdTRUE, pdMS_TO_TICKS(100));

Mutex (no blocking inside critical section)

xSemaphoreTake(mtx, pdMS_TO_TICKS(5));
do_work_quickly();
xSemaphoreGive(mtx);

« Previous Index Next »