Espressif ESP32-S2 Programming Manual page 914

Table of Contents

Advertisement

Chapter 2. API Reference
//
Rest of task code goes
}
Return If the semaphore is created then a handle to the created semaphore is returned. If pxSemaphoreBuffer
is NULL then NULL is returned.
Parameters
• pxStaticSemaphore: Must point to a variable of type StaticSemaphore_t, which will then be
used to hold the semaphore's data structure, removing the need for the memory to be allocated
dynamically.
xSemaphoreTake(xSemaphore, xBlockTime)
Macro to obtain a semaphore. The semaphore must have previously been created with a call to xSemaphoreCre-
ateBinary(), xSemaphoreCreateMutex() or xSemaphoreCreateCounting().
param xSemaphore A handle to the semaphore being taken - obtained when the semaphore was created.
param xBlockTime The time in ticks to wait for the semaphore to become available.
portTICK_PERIOD_MS can be used to convert this to a real time. A block time of zero can be used to
poll the semaphore. A block time of portMAX_DELAY can be used to block indefinitely (provided IN-
CLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h).
Example usage:
SemaphoreHandle_t xSemaphore
//
A task that creates a
void vATask( void
{
//
Create the semaphore to guard a shared
vSemaphoreCreateBinary( xSemaphore );
}
//
A task that uses the
void vAnotherTask( void
{
// ...
Do other
if( xSemaphore
{
//
See
if
//
wait
10
if( xSemaphoreTake( xSemaphore, ( TickType_t )
{
//
We were able to obtain the semaphore
//
shared
// ...
//
We have finished accessing the shared
// semaphore.
xSemaphoreGive( xSemaphore );
}
else
{
//
We could
//
the shared resource
}
}
}
Return pdTRUE if the semaphore was obtained. pdFALSE if xBlockTime expired without the semaphore
Espressif Systems
here.
=
NULL;
semaphore.
*
pvParameters )
semaphore.
*
pvParameters )
things.
!=
NULL )
we can obtain the
semaphore.
ticks to see
if
it becomes
resource.
not
obtain the semaphore
safely.
Submit Document Feedback
resource.
If the semaphore
free.
10
and
can now access the
resource.
and
can therefore
903
(continued from previous page)
The macro
is not
available
)
==
pdTRUE )
Release the
not
access
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?

Questions and answers

Table of Contents

Save PDF