ACS ACR89U-A1 User Manual Page 64

  • Download
  • Add to my manuals
  • Print
  • Page
    / 78
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 63
ACR89U-A1 Application Programming Interface info@acs.com.hk
Version 1.01
www.acs.com.hk
Page 64 of 78
Example:
xSemaphoreHandle xMutex;
void vATask( void * pvParameters )
{
// Semaphore cannot be used before a call to
xSemaphoreCreateMutex().
// This is a macro so pass the variable in directly.
xMutex = xSemaphoreCreateRecursiveMutex();
if( xMutex != NULL )
{
// The mutex type semaphore was created successfully.
// The mutex can now be used.
}
}
6.6.5. xSemaphoreTake
This is a macro to obtain a semaphore. The semaphore must have previously been created with a call
to vSemaphoreCreateBinary(), xSemaphoreCreateMutex() or xSemaphoreCreateCounting().
[semphr.h]
signed portBASE_TYPE xSemaphoreTake
(
xSemaphoreHandle xSemaphore,
portTickType xBlockTime
);
Parameters:
xSemaphore [in] A handle to the semaphore being taken - obtained when the semaphore was
created.
xBlockTime [in] The time in ticks to wait for the semaphore to become available. The macro
portTICK_RATE_MS can be used to convert this to a real time. A block time of zero
can be used to poll the semaphore. Specifying the block time as portMAX_DELAY
will cause the task to block indefinitely (without a timeout).
Returns:
signed portBASE_TYPE pdTRUE if the semaphore was obtained. pdFALSE if xBlockTime expired
without the semaphore becoming available.
Example:
xSemaphoreHandle 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.
Page view 63
1 2 ... 59 60 61 62 63 64 65 66 67 68 69 ... 77 78

Comments to this Manuals

No comments