Chapter 2. API Reference
xHigherPriorityTaskWoken = pdFALSE;
ucLocalTickCount++;
if( ucLocalTickCount >= TICKS_TO_WAIT )
{
// Unblock the task by releasing the semaphore.
xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );
// Reset the count so we release the semaphore again in 10 ticks time.
ucLocalTickCount = 0;
}
if( xHigherPriorityTaskWoken != pdFALSE )
{
// We can force a context switch here.
// ISR uses port specific syntax.
// to find the syntax required.
}
}
Return pdTRUE if the semaphore was successfully given, otherwise errQUEUE_FULL.
Parameters
• xSemaphore: A handle to the semaphore being released. This is the handle returned when the
semaphore was created.
• pxHigherPriorityTaskWoken: xSemaphoreGiveFromISR() will set *pxHigherPriority-
TaskWoken to pdTRUE if giving the semaphore caused a task to unblock, and the unblocked task
has a priority higher than the currently running task. If xSemaphoreGiveFromISR() sets this value
to pdTRUE then a context switch should be requested before the interrupt is exited.
xSemaphoreTakeFromISR(xSemaphore, pxHigherPriorityTaskWoken)
Macro to take a semaphore from an ISR. The semaphore must have previously been created with a call to
xSemaphoreCreateBinary() or xSemaphoreCreateCounting().
Mutex type semaphores (those created using a call to xSemaphoreCreateMutex()) must not be used with this
macro.
This macro can be used from an ISR, however taking a semaphore from an ISR is not a common operation. It
is likely to only be useful when taking a counting semaphore when an interrupt is obtaining an object from a
resource pool (when the semaphore count indicates the number of resources available).
Return pdTRUE if the semaphore was successfully taken, otherwise pdFALSE
Parameters
• xSemaphore: A handle to the semaphore being taken. This is the handle returned when the
semaphore was created.
• [out] pxHigherPriorityTaskWoken: xSemaphoreTakeFromISR() will set *pxHigher-
PriorityTaskWoken to pdTRUE if taking the semaphore caused a task to unblock, and the unblocked
task has a priority higher than the currently running task. If xSemaphoreTakeFromISR() sets this
value to pdTRUE then a context switch should be requested before the interrupt is exited.
xSemaphoreCreateMutex()
Creates a new mutex type semaphore instance, and returns a handle by which the new mutex can be referenced.
Internally, within the FreeRTOS implementation, mutex semaphores use a block of memory, in which
the mutex structure is stored. If a mutex is created using xSemaphoreCreateMutex() then the required
memory is automatically dynamically allocated inside the xSemaphoreCreateMutex() function. (see
//www.FreeRTOS.org/a00111.html). If a mutex is created using xSemaphoreCreateMutexStatic() then the
application writer must provided the memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to
be created without using any dynamic memory allocation.
Mutexes created using this function can be accessed using the xSemaphoreTake() and xSemaphoreGive()
macros. The xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros must not be used.
This type of semaphore uses a priority inheritance mechanism so a task 'taking' a semaphore MUST ALWAYS
Espressif Systems
Check the demo task for your port
908
Submit Document Feedback
(continued from previous page)
Context switching from an
https:
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?
Questions and answers