xref: /aosp_15_r20/external/pigweed/pw_sync_freertos/docs.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_sync_freertos:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker================
4*61c4878aSAndroid Build Coastguard Workerpw_sync_freertos
5*61c4878aSAndroid Build Coastguard Worker================
6*61c4878aSAndroid Build Coastguard WorkerThis is a set of backends for pw_sync based on FreeRTOS.
7*61c4878aSAndroid Build Coastguard Worker
8*61c4878aSAndroid Build Coastguard Worker--------------------------------
9*61c4878aSAndroid Build Coastguard WorkerCritical Section Lock Primitives
10*61c4878aSAndroid Build Coastguard Worker--------------------------------
11*61c4878aSAndroid Build Coastguard Worker
12*61c4878aSAndroid Build Coastguard WorkerMutex & TimedMutex
13*61c4878aSAndroid Build Coastguard Worker==================
14*61c4878aSAndroid Build Coastguard WorkerThe FreeRTOS backend for the Mutex and TimedMutex use ``StaticSemaphore_t`` as
15*61c4878aSAndroid Build Coastguard Workerthe underlying type. It is created using ``xSemaphoreCreateMutexStatic`` as part
16*61c4878aSAndroid Build Coastguard Workerof the constructors and cleaned up using ``vSemaphoreDelete`` in the
17*61c4878aSAndroid Build Coastguard Workerdestructors.
18*61c4878aSAndroid Build Coastguard Worker
19*61c4878aSAndroid Build Coastguard Worker.. Note::
20*61c4878aSAndroid Build Coastguard Worker  Static allocation support is required in your FreeRTOS configuration, i.e.
21*61c4878aSAndroid Build Coastguard Worker  ``configSUPPORT_STATIC_ALLOCATION == 1``.
22*61c4878aSAndroid Build Coastguard Worker
23*61c4878aSAndroid Build Coastguard WorkerInterruptSpinLock
24*61c4878aSAndroid Build Coastguard Worker=================
25*61c4878aSAndroid Build Coastguard WorkerThe FreeRTOS backend for InterruptSpinLock is backed by ``UBaseType_t`` and a
26*61c4878aSAndroid Build Coastguard Worker``bool`` which permits these objects to stash the saved interrupt mask and to
27*61c4878aSAndroid Build Coastguard Workerdetect accidental recursive locking.
28*61c4878aSAndroid Build Coastguard Worker
29*61c4878aSAndroid Build Coastguard WorkerThis object uses ``taskENTER_CRITICAL_FROM_ISR`` and
30*61c4878aSAndroid Build Coastguard Worker``taskEXIT_CRITICAL_FROM_ISR`` from interrupt contexts, and
31*61c4878aSAndroid Build Coastguard Worker``taskENTER_CRITICAL`` and ``taskEXIT_CRITICAL`` in all other contexts.
32*61c4878aSAndroid Build Coastguard Worker``vTaskSuspendAll`` and ``xTaskResumeAll`` are additionally used within
33*61c4878aSAndroid Build Coastguard Workerlock/unlock respectively when called from task context in the scheduler-enabled
34*61c4878aSAndroid Build Coastguard Workerstate.
35*61c4878aSAndroid Build Coastguard Worker
36*61c4878aSAndroid Build Coastguard Worker.. Note::
37*61c4878aSAndroid Build Coastguard Worker  Scheduler State API support is required in your FreeRTOS Configuration, i.e.
38*61c4878aSAndroid Build Coastguard Worker  ``INCLUDE_xTaskGetSchedulerState == 1``.
39*61c4878aSAndroid Build Coastguard Worker
40*61c4878aSAndroid Build Coastguard Worker.. warning::
41*61c4878aSAndroid Build Coastguard Worker  ``taskENTER_CRITICAL_FROM_ISR`` only disables interrupts with priority at or
42*61c4878aSAndroid Build Coastguard Worker  below ``configMAX_SYSCALL_INTERRUPT_PRIORITY``. Therefore, it is unsafe to
43*61c4878aSAndroid Build Coastguard Worker  use InterruptSpinLock from higher-priority interrupts, even if they are not
44*61c4878aSAndroid Build Coastguard Worker  non-maskable interrupts. This is consistent with the rest of the FreeRTOS
45*61c4878aSAndroid Build Coastguard Worker  APIs, see the `FreeRTOS kernel interrupt priority documentation
46*61c4878aSAndroid Build Coastguard Worker  <https://www.freertos.org/a00110.html#kernel_priority>`_ for more details.
47*61c4878aSAndroid Build Coastguard Worker
48*61c4878aSAndroid Build Coastguard WorkerDesign Notes
49*61c4878aSAndroid Build Coastguard Worker------------
50*61c4878aSAndroid Build Coastguard WorkerFreeRTOS does not supply an interrupt spin-lock API, so this backend provides
51*61c4878aSAndroid Build Coastguard Workera suitable implementation using a compbination of both critical section and
52*61c4878aSAndroid Build Coastguard Workerschduler APIs provided by FreeRTOS.
53*61c4878aSAndroid Build Coastguard Worker
54*61c4878aSAndroid Build Coastguard WorkerThis design is influenced by the following factors:
55*61c4878aSAndroid Build Coastguard Worker
56*61c4878aSAndroid Build Coastguard Worker- FreeRTOS support for both synchronous and asynchronous yield behavior in
57*61c4878aSAndroid Build Coastguard Worker  different ports.
58*61c4878aSAndroid Build Coastguard Worker- Critical sections behave differently depending on whether or not yield is
59*61c4878aSAndroid Build Coastguard Worker  synchronous or asynchronous.
60*61c4878aSAndroid Build Coastguard Worker- Users must be allowed to call functions that result in a call to yield
61*61c4878aSAndroid Build Coastguard Worker  while an InterruptSpinLock is held.
62*61c4878aSAndroid Build Coastguard Worker- The signaling mechanisms in FreeRTOS all internally call yield to preempt
63*61c4878aSAndroid Build Coastguard Worker  the currently-running task in the event that a higher-priority task is
64*61c4878aSAndroid Build Coastguard Worker  unblocked during execution.
65*61c4878aSAndroid Build Coastguard Worker
66*61c4878aSAndroid Build Coastguard WorkerSynchronous and Asynchronous Yield
67*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
68*61c4878aSAndroid Build Coastguard WorkerIn FreeRTOS, any kernel API call that results in a higher-priority task being
69*61c4878aSAndroid Build Coastguard Workermade “ready” triggers a call to ``taskYIELD()``.
70*61c4878aSAndroid Build Coastguard Worker
71*61c4878aSAndroid Build Coastguard WorkerIn some ports, this results in an immediate context switch directly from
72*61c4878aSAndroid Build Coastguard Workerwithin the API - this is known as synchronous yielding behavior.
73*61c4878aSAndroid Build Coastguard Worker
74*61c4878aSAndroid Build Coastguard WorkerIn other cases, this results in a software-triggered interrupt
75*61c4878aSAndroid Build Coastguard Workerbeing pended - and depending on the state of interrupts being masked, this
76*61c4878aSAndroid Build Coastguard Workerresults in thread-scheduling being deferred until interrupts are unmasked.
77*61c4878aSAndroid Build Coastguard WorkerThis is known as asynchronous yielding behavior.
78*61c4878aSAndroid Build Coastguard Worker
79*61c4878aSAndroid Build Coastguard WorkerAs part of a yield, it is left to the port-specific code to call
80*61c4878aSAndroid Build Coastguard Workerthe FreeRTOS ``vTaskSwitchContext()`` function to swap current/ready tasks.
81*61c4878aSAndroid Build Coastguard WorkerThis function will select the next task to run, and swap it for the
82*61c4878aSAndroid Build Coastguard Workercurrently executing task.
83*61c4878aSAndroid Build Coastguard Worker
84*61c4878aSAndroid Build Coastguard WorkerYield Within a Critical Section
85*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86*61c4878aSAndroid Build Coastguard WorkerA FreeRTOS critical section provides an interrupt-disabled context that ensures
87*61c4878aSAndroid Build Coastguard Workerthat a thread of execution cannot be interrupted by incoming ISRs.
88*61c4878aSAndroid Build Coastguard Worker
89*61c4878aSAndroid Build Coastguard WorkerIf a port implements asynchronous yield, any calls to ``taskYIELD()`` that
90*61c4878aSAndroid Build Coastguard Workeroccur during execution of a critical section will not be handled until the
91*61c4878aSAndroid Build Coastguard Workerinterrupts are re-enabled at the end of the critical section.  As a result,
92*61c4878aSAndroid Build Coastguard Workerany higher priority tasks that are unblocked will not preempt the current task
93*61c4878aSAndroid Build Coastguard Workerfrom within the critical section. In these ports, a critical section alone is
94*61c4878aSAndroid Build Coastguard Workersufficient to prevent any interruption to code flow - be it from preempting
95*61c4878aSAndroid Build Coastguard Workertasks or ISRs.
96*61c4878aSAndroid Build Coastguard Worker
97*61c4878aSAndroid Build Coastguard WorkerIf a port implements synchronous yield, then a context switch to a
98*61c4878aSAndroid Build Coastguard Workerhigher-priority ready task can occur within a critical section as a result
99*61c4878aSAndroid Build Coastguard Workerof a kernel API unblocking a higher-prirority task. When this occurs, the
100*61c4878aSAndroid Build Coastguard Workerhigher-priority task will be swapped in immediately, and its interrupt-enabled
101*61c4878aSAndroid Build Coastguard Workerstatus applied to the CPU core. This typically causes interrupts to be
102*61c4878aSAndroid Build Coastguard Workerre-enabled as a result of the context switch, which is an unintended
103*61c4878aSAndroid Build Coastguard Workerside-effect for tasks that presume to have exclusive access to the CPU,
104*61c4878aSAndroid Build Coastguard Workerleading to logic errors and broken assumptions.
105*61c4878aSAndroid Build Coastguard Worker
106*61c4878aSAndroid Build Coastguard WorkerIn short, any code that uses a FreeRTOS interrupt-disabled critical section
107*61c4878aSAndroid Build Coastguard Workeralone to provide an interrupt-safe context is subject to port-specific behavior
108*61c4878aSAndroid Build Coastguard Workerif it calls kernel APIs that can unblock tasks. A critical section alone is
109*61c4878aSAndroid Build Coastguard Workerinsufficient to implement InterruptSpinLock correctly.
110*61c4878aSAndroid Build Coastguard Worker
111*61c4878aSAndroid Build Coastguard WorkerYielding with Scheduling Suspended
112*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
113*61c4878aSAndroid Build Coastguard WorkerIf a task is unblocked while the scheduler is suspended, the task is moved
114*61c4878aSAndroid Build Coastguard Workerto a "pending ready-list", and a flag is set to ensure that tasks are
115*61c4878aSAndroid Build Coastguard Workerscheduled as necessary once the scheduler is resumed.  Once scheduling
116*61c4878aSAndroid Build Coastguard Workerresumes, any tasks that were unblocked while the scheduler was suspended
117*61c4878aSAndroid Build Coastguard Workerare processed immediately, and rescheduling/preemption resumes at that time.
118*61c4878aSAndroid Build Coastguard Worker
119*61c4878aSAndroid Build Coastguard WorkerIn the event that a call to ``taskYIELD()`` occurs directly while the
120*61c4878aSAndroid Build Coastguard Workerscheduler is suspended, the result is that ``vTaskSwitchContext()`` switches
121*61c4878aSAndroid Build Coastguard Workerback to the currently running task.  This is a guard-rail that short-circuits
122*61c4878aSAndroid Build Coastguard Workerany attempts to bypass the scheduler-suspended state manually.
123*61c4878aSAndroid Build Coastguard Worker
124*61c4878aSAndroid Build Coastguard WorkerCritical Section with Suspended Scheduling
125*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126*61c4878aSAndroid Build Coastguard WorkerIt is important to note that a critical section may be entered while the
127*61c4878aSAndroid Build Coastguard Workerscheduler is also disabled. In such a state, the system observes FreeRTOS'
128*61c4878aSAndroid Build Coastguard Workercontract that threads are not re-scheduled while the scheduler is supsended,
129*61c4878aSAndroid Build Coastguard Workerwith the benefit that ISRs may not break the atomicity of code executing
130*61c4878aSAndroid Build Coastguard Workerwhile the lock is held.
131*61c4878aSAndroid Build Coastguard Worker
132*61c4878aSAndroid Build Coastguard WorkerThis state is also compatible with either synchronous or asynchronous
133*61c4878aSAndroid Build Coastguard Workeryield behavior:
134*61c4878aSAndroid Build Coastguard Worker
135*61c4878aSAndroid Build Coastguard Worker- In the synchronous cases, the result of a call to yield is that
136*61c4878aSAndroid Build Coastguard Worker  ``vTaskSwitchContext`` is invoked immediately, with the current task being
137*61c4878aSAndroid Build Coastguard Worker  restored.
138*61c4878aSAndroid Build Coastguard Worker- In the Asynchronous case, the result of a call to yield is that the context
139*61c4878aSAndroid Build Coastguard Worker  switch interrupt is deferred until the end of the critical section.
140*61c4878aSAndroid Build Coastguard Worker
141*61c4878aSAndroid Build Coastguard WorkerThis is sufficient to satisfy the requirements implement an InterruptSpinLock
142*61c4878aSAndroid Build Coastguard Workerfor any FreeRTOS target.
143*61c4878aSAndroid Build Coastguard Worker
144*61c4878aSAndroid Build Coastguard Worker--------------------
145*61c4878aSAndroid Build Coastguard WorkerSignaling Primitives
146*61c4878aSAndroid Build Coastguard Worker--------------------
147*61c4878aSAndroid Build Coastguard Worker
148*61c4878aSAndroid Build Coastguard WorkerThreadNotification & TimedThreadNotification
149*61c4878aSAndroid Build Coastguard Worker============================================
150*61c4878aSAndroid Build Coastguard WorkerAn optimized FreeRTOS backend for the ThreadNotification and
151*61c4878aSAndroid Build Coastguard WorkerTimedThreadNotification is provided using Task Notifications. It is backed by a
152*61c4878aSAndroid Build Coastguard Worker``TaskHandle_t`` and a ``bool`` which permits these objects to track the
153*61c4878aSAndroid Build Coastguard Workernotification value outside of the task's TCB (AKA FreeRTOS Task Notification
154*61c4878aSAndroid Build Coastguard WorkerState and Value).
155*61c4878aSAndroid Build Coastguard Worker
156*61c4878aSAndroid Build Coastguard Worker.. Warning::
157*61c4878aSAndroid Build Coastguard Worker  By default this backend uses the task notification at index 0, just like
158*61c4878aSAndroid Build Coastguard Worker  FreeRTOS Stream and Message Buffers. If you want to maintain the state of a
159*61c4878aSAndroid Build Coastguard Worker  task notification across blocking acquiring calls to ThreadNotifications, then
160*61c4878aSAndroid Build Coastguard Worker  you must do one of the following:
161*61c4878aSAndroid Build Coastguard Worker
162*61c4878aSAndroid Build Coastguard Worker  1. Adjust ``PW_SYNC_FREERTOS_CONFIG_THREAD_NOTIFICATION_INDEX`` to an index
163*61c4878aSAndroid Build Coastguard Worker     which does not collide with existing incompatible use.
164*61c4878aSAndroid Build Coastguard Worker  2. Migrate your existing use of task notifications away from index 0.
165*61c4878aSAndroid Build Coastguard Worker  3. Do not use this optimized backend and instead use the binary semaphore
166*61c4878aSAndroid Build Coastguard Worker     backends for ThreadNotifications
167*61c4878aSAndroid Build Coastguard Worker     (``pw_sync:binary_semaphore_thread_notification_backend``).
168*61c4878aSAndroid Build Coastguard Worker
169*61c4878aSAndroid Build Coastguard Worker  You are using any of the following Task Notification APIs, it means you are
170*61c4878aSAndroid Build Coastguard Worker  using notification indices:
171*61c4878aSAndroid Build Coastguard Worker
172*61c4878aSAndroid Build Coastguard Worker  - ``xTaskNotify`` / ``xTaskNotifyIndexed``
173*61c4878aSAndroid Build Coastguard Worker  - ``xTaskNotifyFromISR`` / ``xTaskNotifyIndexedFromISR``
174*61c4878aSAndroid Build Coastguard Worker  - ``xTaskNotifyGive`` / ``xTaskNotifyGiveIndexed``
175*61c4878aSAndroid Build Coastguard Worker  - ``xTaskNotifyGiveFromISR`` / ``xTaskNotifyGiveIndexedFromISR``
176*61c4878aSAndroid Build Coastguard Worker  - ``xTaskNotifyAndQuery`` / ``xTaskNotifyAndQueryIndexed``
177*61c4878aSAndroid Build Coastguard Worker  - ``xTaskNotifyAndQueryFromISR`` / ``xTaskNotifyAndQueryIndexedFromISR``
178*61c4878aSAndroid Build Coastguard Worker  - ``ulTaskNotifyTake`` / ``ulTaskNotifyTakeIndexed``
179*61c4878aSAndroid Build Coastguard Worker  - ``xTaskNotifyWait`` / ``xTaskNotifyWaitIndexed``
180*61c4878aSAndroid Build Coastguard Worker  - ``xTaskNotifyStateClear`` / ``xTaskNotifyStateClearIndexed``
181*61c4878aSAndroid Build Coastguard Worker  - ``ulTaskNotifyValueClear`` / ``ulTaskNotifyValueClearIndexed``
182*61c4878aSAndroid Build Coastguard Worker
183*61c4878aSAndroid Build Coastguard Worker  APIs without ``Indexed`` in the name use index 0 implicitly.
184*61c4878aSAndroid Build Coastguard Worker
185*61c4878aSAndroid Build Coastguard Worker  Prior to FreeRTOS V10.4.0 each task had a single "notification index", and all
186*61c4878aSAndroid Build Coastguard Worker  task notification API functions operated on that implicit index of 0.
187*61c4878aSAndroid Build Coastguard Worker
188*61c4878aSAndroid Build Coastguard WorkerThis backend is compatible with sharing the notification index
189*61c4878aSAndroid Build Coastguard Workerwith native FreeRTOS
190*61c4878aSAndroid Build Coastguard Worker`Stream and Message Buffers <https://www.freertos.org/RTOS-task-notifications.html>`_
191*61c4878aSAndroid Build Coastguard Workerat index 0.
192*61c4878aSAndroid Build Coastguard Worker
193*61c4878aSAndroid Build Coastguard WorkerJust like FreeRTOS Stream and Message Buffers, this backend uses the task
194*61c4878aSAndroid Build Coastguard Workernotification index only within callsites where the task must block until a
195*61c4878aSAndroid Build Coastguard Workernotification is received or a timeout occurs. The notification index's state is
196*61c4878aSAndroid Build Coastguard Workeralways cleaned up before returning. The notification index is never used when
197*61c4878aSAndroid Build Coastguard Workerthe acquiring task is not going to block.
198*61c4878aSAndroid Build Coastguard Worker
199*61c4878aSAndroid Build Coastguard Worker.. Note::
200*61c4878aSAndroid Build Coastguard Worker  Task notification support is required in your FreeRTOS configuration, i.e.
201*61c4878aSAndroid Build Coastguard Worker  ``configUSE_TASK_NOTIFICATIONS == 1``.
202*61c4878aSAndroid Build Coastguard Worker
203*61c4878aSAndroid Build Coastguard WorkerDesign Notes
204*61c4878aSAndroid Build Coastguard Worker------------
205*61c4878aSAndroid Build Coastguard WorkerYou may ask, why are Task Notifications used at all given the risk associated
206*61c4878aSAndroid Build Coastguard Workerwith global notification index allocations? It turns out there's no other
207*61c4878aSAndroid Build Coastguard Workerlightweight mechanism to unblock a task in FreeRTOS.
208*61c4878aSAndroid Build Coastguard Worker
209*61c4878aSAndroid Build Coastguard WorkerTask suspension (i.e. ``vTaskSuspend``, ``vTaskResume``, &
210*61c4878aSAndroid Build Coastguard Worker``vTaskResumeFromISR``) seems like a good fit, however ``xTaskResumeAll`` does
211*61c4878aSAndroid Build Coastguard Workernot participate in reference counting and will wake up all suspended tasks
212*61c4878aSAndroid Build Coastguard Workerwhether you want it to or not.
213*61c4878aSAndroid Build Coastguard Worker
214*61c4878aSAndroid Build Coastguard WorkerLastly, there's also ``xTaskAbortDelay`` but there is no interrupt safe
215*61c4878aSAndroid Build Coastguard Workerequivalent of this API. Note that it uses ``vTaskSuspendAll`` internally for
216*61c4878aSAndroid Build Coastguard Workerthe critical section which is not interrupt safe. If in the future an interrupt
217*61c4878aSAndroid Build Coastguard Workersafe version of this API is offerred, then this would be a great alternative!
218*61c4878aSAndroid Build Coastguard Worker
219*61c4878aSAndroid Build Coastguard WorkerLastly, we want to briefly explain how Task Notifications actually work in
220*61c4878aSAndroid Build Coastguard WorkerFreeRTOS to show why you cannot directly share notification indeces even if the
221*61c4878aSAndroid Build Coastguard Workerbits used in the ``ulNotifiedValue`` are unique. This is a very common source of
222*61c4878aSAndroid Build Coastguard Workerbugs when using FreeRTOS and partially why Pigweed does not recommend using the
223*61c4878aSAndroid Build Coastguard Workernative Task Notification APIs directly.
224*61c4878aSAndroid Build Coastguard Worker
225*61c4878aSAndroid Build Coastguard WorkerFreeRTOS Task Notifications use a task's TCB's ``ucNotifyState`` to capture the
226*61c4878aSAndroid Build Coastguard Workernotification state even when the task is not blocked. This state transitions
227*61c4878aSAndroid Build Coastguard Worker``taskNOT_WAITING_NOTIFICATION`` to ``task_NOTIFICATION_RECEIVED`` if the task
228*61c4878aSAndroid Build Coastguard Workerever notified. This notification state is used to determine whether the next
229*61c4878aSAndroid Build Coastguard Workertask notification wait call should block, irrespective of the notification
230*61c4878aSAndroid Build Coastguard Workervalue.
231*61c4878aSAndroid Build Coastguard Worker
232*61c4878aSAndroid Build Coastguard WorkerIn order to enable this optimized backend, native task notifications are only
233*61c4878aSAndroid Build Coastguard Workerused when the task needs to block. If a timeout occurs the task unregisters for
234*61c4878aSAndroid Build Coastguard Workernotifications and clears the notification state before returning. This exact
235*61c4878aSAndroid Build Coastguard Workermechanism is used by FreeRTOS internally for their Stream and Message Buffer
236*61c4878aSAndroid Build Coastguard Workerimplementations.
237*61c4878aSAndroid Build Coastguard Worker
238*61c4878aSAndroid Build Coastguard WorkerOne other thing to note is that FreeRTOS has undocumented side effects between
239*61c4878aSAndroid Build Coastguard Worker``vTaskSuspend`` and ``xTaskNotifyWait``. If a thread is suspended via
240*61c4878aSAndroid Build Coastguard Worker``vTaskSuspend`` while blocked on ``xTaskNotifyWait``, the wait is aborted
241*61c4878aSAndroid Build Coastguard Workerregardless of the timeout (even if the request was indefinite) and the thread
242*61c4878aSAndroid Build Coastguard Workeris resumed whenever ``vTaskResume`` is invoked.
243*61c4878aSAndroid Build Coastguard Worker
244*61c4878aSAndroid Build Coastguard WorkerBinarySemaphore
245*61c4878aSAndroid Build Coastguard Worker===============
246*61c4878aSAndroid Build Coastguard WorkerThe FreeRTOS backend for the BinarySemaphore uses ``StaticSemaphore_t`` as the
247*61c4878aSAndroid Build Coastguard Workerunderlying type. It is created using ``xSemaphoreCreateBinaryStatic`` as part
248*61c4878aSAndroid Build Coastguard Workerof the constructor and cleaned up using ``vSemaphoreDelete`` in the destructor.
249*61c4878aSAndroid Build Coastguard Worker
250*61c4878aSAndroid Build Coastguard Worker.. Note::
251*61c4878aSAndroid Build Coastguard Worker  Static allocation support is required in your FreeRTOS configuration, i.e.
252*61c4878aSAndroid Build Coastguard Worker  ``configSUPPORT_STATIC_ALLOCATION == 1``.
253*61c4878aSAndroid Build Coastguard Worker
254*61c4878aSAndroid Build Coastguard WorkerCountingSemaphore
255*61c4878aSAndroid Build Coastguard Worker=================
256*61c4878aSAndroid Build Coastguard WorkerThe FreeRTOS backend for the CountingSemaphore uses ``StaticSemaphore_t`` as the
257*61c4878aSAndroid Build Coastguard Workerunderlying type. It is created using ``xSemaphoreCreateCountingStatic`` as part
258*61c4878aSAndroid Build Coastguard Workerof the constructor and cleaned up using ``vSemaphoreDelete`` in the destructor.
259*61c4878aSAndroid Build Coastguard Worker
260*61c4878aSAndroid Build Coastguard Worker.. Note::
261*61c4878aSAndroid Build Coastguard Worker  Counting semaphore support is required in your FreeRTOS configuration, i.e.
262*61c4878aSAndroid Build Coastguard Worker  ``configUSE_COUNTING_SEMAPHORES == 1``.
263*61c4878aSAndroid Build Coastguard Worker.. Note::
264*61c4878aSAndroid Build Coastguard Worker  Static allocation support is required in your FreeRTOS configuration, i.e.
265*61c4878aSAndroid Build Coastguard Worker  ``configSUPPORT_STATIC_ALLOCATION == 1``.
266