Espressif ESP32-S2 Programming Manual page 913

Table of Contents

Advertisement

Chapter 2. API Reference
xSemaphoreCreateBinary() are created in a state such that the the semaphore must first be 'given'before it
can be 'taken'.
This type of semaphore can be used for pure synchronisation between tasks or between an interrupt and a
task. The semaphore need not be given back once obtained, so one task/interrupt can continuously'give'the
semaphore while another continuously'takes' the semaphore. For this reason this type of semaphore does not
use a priority inheritance mechanism. For an alternative that does use priority inheritance see xSemaphoreCre-
ateMutex().
Example usage:
SemaphoreHandle_t xSemaphore
void vATask( void
{
//
Semaphore cannot be used before a call to
//
This
is
a macro so
xSemaphore
=
xSemaphoreCreateBinary();
if( xSemaphore
{
//
The semaphore was created
//
The semaphore can now be
}
}
Return Handle to the created semaphore, or NULL if the memory required to hold the semaphore's data
structures could not be allocated.
xSemaphoreCreateBinaryStatic(pxStaticSemaphore)
Creates a new binary semaphore instance, and returns a handle by which the new semaphore can be referenced.
NOTE: In many usage scenarios it is faster and more memory efficient to use a direct to task notification in
place of a binary semaphore!
Internally, within the FreeRTOS implementation, binary semaphores use a block of memory, in which the
semaphore structure is stored. If a binary semaphore is created using xSemaphoreCreateBinary() then the
required memory is automatically dynamically allocated inside the xSemaphoreCreateBinary() function. (see
https://www.FreeRTOS.org/a00111.html). If a binary semaphore is created using xSemaphoreCreateBina-
ryStatic() then the application writer must provide the memory. xSemaphoreCreateBinaryStatic() therefore
allows a binary semaphore to be created without using any dynamic memory allocation.
This type of semaphore can be used for pure synchronisation between tasks or between an interrupt and a
task. The semaphore need not be given back once obtained, so one task/interrupt can continuously'give'the
semaphore while another continuously'takes' the semaphore. For this reason this type of semaphore does not
use a priority inheritance mechanism. For an alternative that does use priority inheritance see xSemaphoreCre-
ateMutex().
Example usage:
SemaphoreHandle_t xSemaphore
StaticSemaphore_t xSemaphoreBuffer;
void vATask( void
{
//
Semaphore cannot be used before a call to xSemaphoreCreateBinary()
// xSemaphoreCreateBinaryStatic().
//
The
semaphore's data structures will be placed in the xSemaphoreBuffer
//
variable, the address of which
//
function's parameter is not NULL, so the function will not attempt any
//
dynamic memory allocation,
//
return
NULL.
xSemaphore
=
xSemaphoreCreateBinaryStatic( &xSemaphoreBuffer );
Espressif Systems
=
NULL;
*
pvParameters )
pass
the variable
!=
NULL )
successfully.
used.
https://www.FreeRTOS.org/RTOS-task-notifications.html
=
NULL;
*
pvParameters )
is
and
therefore the function will
Submit Document Feedback
vSemaphoreCreateBinary().
in
directly.
passed into the
function.
902
or
The
not return
(continues on next page)
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Table of Contents

Save PDF