SemaphoreHandle_t xSemaphore = NULL;
/* A task that creates a semaphore. */
void vATask( void * pvParameters )
{
/* Create the semaphore to guard a shared resource. As we are using
the semaphore for mutual exclusion we create a mutex semaphore
rather than a binary semaphore. */
xSemaphore = xSemaphoreCreateMutex();
}
/* A task that uses the semaphore. */
void vAnotherTask( void * pvParameters )
{
/* ... Do other things. */
if( xSemaphore != NULL )
{
/* See if we can obtain the semaphore. If the semaphore is not
available wait 10 ticks to see if it becomes free. */
if( xSemaphoreTake( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
{
/* We were able to obtain the semaphore and can now access the
shared resource. */
/* ... */
/* We have finished accessing the shared resource. Release the
semaphore. */
xSemaphoreGive( xSemaphore );
}
else
{
/* We could not obtain the semaphore and can therefore not access
the shared resource safely. */
}
}
}
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|
Latest News
NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS. Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019 Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed. View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS. Careers
FreeRTOS and other embedded software careers at AWS. FreeRTOS Partners
|
|||||||||||||||||||||||