2 * FreeRTOS Kernel V10.3.1
\r
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
30 #ifndef INC_FREERTOS_H
\r
31 #error "include FreeRTOS.h" must appear in source files before "include semphr.h"
\r
36 typedef QueueHandle_t SemaphoreHandle_t;
\r
38 #define semBINARY_SEMAPHORE_QUEUE_LENGTH ( ( uint8_t ) 1U )
\r
39 #define semSEMAPHORE_QUEUE_ITEM_LENGTH ( ( uint8_t ) 0U )
\r
40 #define semGIVE_BLOCK_TIME ( ( TickType_t ) 0U )
\r
45 * <pre>vSemaphoreCreateBinary( SemaphoreHandle_t xSemaphore )</pre>
\r
47 * In many usage scenarios it is faster and more memory efficient to use a
\r
48 * direct to task notification in place of a binary semaphore!
\r
49 * http://www.freertos.org/RTOS-task-notifications.html
\r
51 * This old vSemaphoreCreateBinary() macro is now deprecated in favour of the
\r
52 * xSemaphoreCreateBinary() function. Note that binary semaphores created using
\r
53 * the vSemaphoreCreateBinary() macro are created in a state such that the
\r
54 * first call to 'take' the semaphore would pass, whereas binary semaphores
\r
55 * created using xSemaphoreCreateBinary() are created in a state such that the
\r
56 * the semaphore must first be 'given' before it can be 'taken'.
\r
58 * <i>Macro</i> that implements a semaphore by using the existing queue mechanism.
\r
59 * The queue length is 1 as this is a binary semaphore. The data size is 0
\r
60 * as we don't want to actually store any data - we just want to know if the
\r
61 * queue is empty or full.
\r
63 * This type of semaphore can be used for pure synchronisation between tasks or
\r
64 * between an interrupt and a task. The semaphore need not be given back once
\r
65 * obtained, so one task/interrupt can continuously 'give' the semaphore while
\r
66 * another continuously 'takes' the semaphore. For this reason this type of
\r
67 * semaphore does not use a priority inheritance mechanism. For an alternative
\r
68 * that does use priority inheritance see xSemaphoreCreateMutex().
\r
70 * @param xSemaphore Handle to the created semaphore. Should be of type SemaphoreHandle_t.
\r
74 * SemaphoreHandle_t xSemaphore = NULL;
\r
76 * void vATask( void * pvParameters )
\r
78 * // Semaphore cannot be used before a call to vSemaphoreCreateBinary ().
\r
79 * // This is a macro so pass the variable in directly.
\r
80 * vSemaphoreCreateBinary( xSemaphore );
\r
82 * if( xSemaphore != NULL )
\r
84 * // The semaphore was created successfully.
\r
85 * // The semaphore can now be used.
\r
89 * \defgroup vSemaphoreCreateBinary vSemaphoreCreateBinary
\r
90 * \ingroup Semaphores
\r
92 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
93 #define vSemaphoreCreateBinary( xSemaphore ) \
\r
95 ( xSemaphore ) = xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE ); \
\r
96 if( ( xSemaphore ) != NULL ) \
\r
98 ( void ) xSemaphoreGive( ( xSemaphore ) ); \
\r
105 * <pre>SemaphoreHandle_t xSemaphoreCreateBinary( void )</pre>
\r
107 * Creates a new binary semaphore instance, and returns a handle by which the
\r
108 * new semaphore can be referenced.
\r
110 * In many usage scenarios it is faster and more memory efficient to use a
\r
111 * direct to task notification in place of a binary semaphore!
\r
112 * http://www.freertos.org/RTOS-task-notifications.html
\r
114 * Internally, within the FreeRTOS implementation, binary semaphores use a block
\r
115 * of memory, in which the semaphore structure is stored. If a binary semaphore
\r
116 * is created using xSemaphoreCreateBinary() then the required memory is
\r
117 * automatically dynamically allocated inside the xSemaphoreCreateBinary()
\r
118 * function. (see http://www.freertos.org/a00111.html). If a binary semaphore
\r
119 * is created using xSemaphoreCreateBinaryStatic() then the application writer
\r
120 * must provide the memory. xSemaphoreCreateBinaryStatic() therefore allows a
\r
121 * binary semaphore to be created without using any dynamic memory allocation.
\r
123 * The old vSemaphoreCreateBinary() macro is now deprecated in favour of this
\r
124 * xSemaphoreCreateBinary() function. Note that binary semaphores created using
\r
125 * the vSemaphoreCreateBinary() macro are created in a state such that the
\r
126 * first call to 'take' the semaphore would pass, whereas binary semaphores
\r
127 * created using xSemaphoreCreateBinary() are created in a state such that the
\r
128 * the semaphore must first be 'given' before it can be 'taken'.
\r
130 * This type of semaphore can be used for pure synchronisation between tasks or
\r
131 * between an interrupt and a task. The semaphore need not be given back once
\r
132 * obtained, so one task/interrupt can continuously 'give' the semaphore while
\r
133 * another continuously 'takes' the semaphore. For this reason this type of
\r
134 * semaphore does not use a priority inheritance mechanism. For an alternative
\r
135 * that does use priority inheritance see xSemaphoreCreateMutex().
\r
137 * @return Handle to the created semaphore, or NULL if the memory required to
\r
138 * hold the semaphore's data structures could not be allocated.
\r
142 * SemaphoreHandle_t xSemaphore = NULL;
\r
144 * void vATask( void * pvParameters )
\r
146 * // Semaphore cannot be used before a call to xSemaphoreCreateBinary().
\r
147 * // This is a macro so pass the variable in directly.
\r
148 * xSemaphore = xSemaphoreCreateBinary();
\r
150 * if( xSemaphore != NULL )
\r
152 * // The semaphore was created successfully.
\r
153 * // The semaphore can now be used.
\r
157 * \defgroup xSemaphoreCreateBinary xSemaphoreCreateBinary
\r
158 * \ingroup Semaphores
\r
160 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
161 #define xSemaphoreCreateBinary() xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE )
\r
166 * <pre>SemaphoreHandle_t xSemaphoreCreateBinaryStatic( StaticSemaphore_t *pxSemaphoreBuffer )</pre>
\r
168 * Creates a new binary semaphore instance, and returns a handle by which the
\r
169 * new semaphore can be referenced.
\r
171 * NOTE: In many usage scenarios it is faster and more memory efficient to use a
\r
172 * direct to task notification in place of a binary semaphore!
\r
173 * http://www.freertos.org/RTOS-task-notifications.html
\r
175 * Internally, within the FreeRTOS implementation, binary semaphores use a block
\r
176 * of memory, in which the semaphore structure is stored. If a binary semaphore
\r
177 * is created using xSemaphoreCreateBinary() then the required memory is
\r
178 * automatically dynamically allocated inside the xSemaphoreCreateBinary()
\r
179 * function. (see http://www.freertos.org/a00111.html). If a binary semaphore
\r
180 * is created using xSemaphoreCreateBinaryStatic() then the application writer
\r
181 * must provide the memory. xSemaphoreCreateBinaryStatic() therefore allows a
\r
182 * binary semaphore to be created without using any dynamic memory allocation.
\r
184 * This type of semaphore can be used for pure synchronisation between tasks or
\r
185 * between an interrupt and a task. The semaphore need not be given back once
\r
186 * obtained, so one task/interrupt can continuously 'give' the semaphore while
\r
187 * another continuously 'takes' the semaphore. For this reason this type of
\r
188 * semaphore does not use a priority inheritance mechanism. For an alternative
\r
189 * that does use priority inheritance see xSemaphoreCreateMutex().
\r
191 * @param pxSemaphoreBuffer Must point to a variable of type StaticSemaphore_t,
\r
192 * which will then be used to hold the semaphore's data structure, removing the
\r
193 * need for the memory to be allocated dynamically.
\r
195 * @return If the semaphore is created then a handle to the created semaphore is
\r
196 * returned. If pxSemaphoreBuffer is NULL then NULL is returned.
\r
200 * SemaphoreHandle_t xSemaphore = NULL;
\r
201 * StaticSemaphore_t xSemaphoreBuffer;
\r
203 * void vATask( void * pvParameters )
\r
205 * // Semaphore cannot be used before a call to xSemaphoreCreateBinary().
\r
206 * // The semaphore's data structures will be placed in the xSemaphoreBuffer
\r
207 * // variable, the address of which is passed into the function. The
\r
208 * // function's parameter is not NULL, so the function will not attempt any
\r
209 * // dynamic memory allocation, and therefore the function will not return
\r
211 * xSemaphore = xSemaphoreCreateBinary( &xSemaphoreBuffer );
\r
213 * // Rest of task code goes here.
\r
216 * \defgroup xSemaphoreCreateBinaryStatic xSemaphoreCreateBinaryStatic
\r
217 * \ingroup Semaphores
\r
219 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
220 #define xSemaphoreCreateBinaryStatic( pxStaticSemaphore ) xQueueGenericCreateStatic( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticSemaphore, queueQUEUE_TYPE_BINARY_SEMAPHORE )
\r
221 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
225 * <pre>xSemaphoreTake(
\r
226 * SemaphoreHandle_t xSemaphore,
\r
227 * TickType_t xBlockTime
\r
230 * <i>Macro</i> to obtain a semaphore. The semaphore must have previously been
\r
231 * created with a call to xSemaphoreCreateBinary(), xSemaphoreCreateMutex() or
\r
232 * xSemaphoreCreateCounting().
\r
234 * @param xSemaphore A handle to the semaphore being taken - obtained when
\r
235 * the semaphore was created.
\r
237 * @param xBlockTime The time in ticks to wait for the semaphore to become
\r
238 * available. The macro portTICK_PERIOD_MS can be used to convert this to a
\r
239 * real time. A block time of zero can be used to poll the semaphore. A block
\r
240 * time of portMAX_DELAY can be used to block indefinitely (provided
\r
241 * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h).
\r
243 * @return pdTRUE if the semaphore was obtained. pdFALSE
\r
244 * if xBlockTime expired without the semaphore becoming available.
\r
248 * SemaphoreHandle_t xSemaphore = NULL;
\r
250 * // A task that creates a semaphore.
\r
251 * void vATask( void * pvParameters )
\r
253 * // Create the semaphore to guard a shared resource.
\r
254 * xSemaphore = xSemaphoreCreateBinary();
\r
257 * // A task that uses the semaphore.
\r
258 * void vAnotherTask( void * pvParameters )
\r
260 * // ... Do other things.
\r
262 * if( xSemaphore != NULL )
\r
264 * // See if we can obtain the semaphore. If the semaphore is not available
\r
265 * // wait 10 ticks to see if it becomes free.
\r
266 * if( xSemaphoreTake( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
\r
268 * // We were able to obtain the semaphore and can now access the
\r
269 * // shared resource.
\r
273 * // We have finished accessing the shared resource. Release the
\r
275 * xSemaphoreGive( xSemaphore );
\r
279 * // We could not obtain the semaphore and can therefore not access
\r
280 * // the shared resource safely.
\r
285 * \defgroup xSemaphoreTake xSemaphoreTake
\r
286 * \ingroup Semaphores
\r
288 #define xSemaphoreTake( xSemaphore, xBlockTime ) xQueueSemaphoreTake( ( xSemaphore ), ( xBlockTime ) )
\r
292 * xSemaphoreTakeRecursive(
\r
293 * SemaphoreHandle_t xMutex,
\r
294 * TickType_t xBlockTime
\r
297 * <i>Macro</i> to recursively obtain, or 'take', a mutex type semaphore.
\r
298 * The mutex must have previously been created using a call to
\r
299 * xSemaphoreCreateRecursiveMutex();
\r
301 * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this
\r
302 * macro to be available.
\r
304 * This macro must not be used on mutexes created using xSemaphoreCreateMutex().
\r
306 * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
\r
307 * doesn't become available again until the owner has called
\r
308 * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
\r
309 * if a task successfully 'takes' the same mutex 5 times then the mutex will
\r
310 * not be available to any other task until it has also 'given' the mutex back
\r
311 * exactly five times.
\r
313 * @param xMutex A handle to the mutex being obtained. This is the
\r
314 * handle returned by xSemaphoreCreateRecursiveMutex();
\r
316 * @param xBlockTime The time in ticks to wait for the semaphore to become
\r
317 * available. The macro portTICK_PERIOD_MS can be used to convert this to a
\r
318 * real time. A block time of zero can be used to poll the semaphore. If
\r
319 * the task already owns the semaphore then xSemaphoreTakeRecursive() will
\r
320 * return immediately no matter what the value of xBlockTime.
\r
322 * @return pdTRUE if the semaphore was obtained. pdFALSE if xBlockTime
\r
323 * expired without the semaphore becoming available.
\r
327 * SemaphoreHandle_t xMutex = NULL;
\r
329 * // A task that creates a mutex.
\r
330 * void vATask( void * pvParameters )
\r
332 * // Create the mutex to guard a shared resource.
\r
333 * xMutex = xSemaphoreCreateRecursiveMutex();
\r
336 * // A task that uses the mutex.
\r
337 * void vAnotherTask( void * pvParameters )
\r
339 * // ... Do other things.
\r
341 * if( xMutex != NULL )
\r
343 * // See if we can obtain the mutex. If the mutex is not available
\r
344 * // wait 10 ticks to see if it becomes free.
\r
345 * if( xSemaphoreTakeRecursive( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
\r
347 * // We were able to obtain the mutex and can now access the
\r
348 * // shared resource.
\r
351 * // For some reason due to the nature of the code further calls to
\r
352 * // xSemaphoreTakeRecursive() are made on the same mutex. In real
\r
353 * // code these would not be just sequential calls as this would make
\r
354 * // no sense. Instead the calls are likely to be buried inside
\r
355 * // a more complex call structure.
\r
356 * xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
\r
357 * xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
\r
359 * // The mutex has now been 'taken' three times, so will not be
\r
360 * // available to another task until it has also been given back
\r
361 * // three times. Again it is unlikely that real code would have
\r
362 * // these calls sequentially, but instead buried in a more complex
\r
363 * // call structure. This is just for illustrative purposes.
\r
364 * xSemaphoreGiveRecursive( xMutex );
\r
365 * xSemaphoreGiveRecursive( xMutex );
\r
366 * xSemaphoreGiveRecursive( xMutex );
\r
368 * // Now the mutex can be taken by other tasks.
\r
372 * // We could not obtain the mutex and can therefore not access
\r
373 * // the shared resource safely.
\r
378 * \defgroup xSemaphoreTakeRecursive xSemaphoreTakeRecursive
\r
379 * \ingroup Semaphores
\r
381 #if ( configUSE_RECURSIVE_MUTEXES == 1 )
\r
382 #define xSemaphoreTakeRecursive( xMutex, xBlockTime ) xQueueTakeMutexRecursive( ( xMutex ), ( xBlockTime ) )
\r
387 * <pre>xSemaphoreGive( SemaphoreHandle_t xSemaphore )</pre>
\r
389 * <i>Macro</i> to release a semaphore. The semaphore must have previously been
\r
390 * created with a call to xSemaphoreCreateBinary(), xSemaphoreCreateMutex() or
\r
391 * xSemaphoreCreateCounting(). and obtained using sSemaphoreTake().
\r
393 * This macro must not be used from an ISR. See xSemaphoreGiveFromISR () for
\r
394 * an alternative which can be used from an ISR.
\r
396 * This macro must also not be used on semaphores created using
\r
397 * xSemaphoreCreateRecursiveMutex().
\r
399 * @param xSemaphore A handle to the semaphore being released. This is the
\r
400 * handle returned when the semaphore was created.
\r
402 * @return pdTRUE if the semaphore was released. pdFALSE if an error occurred.
\r
403 * Semaphores are implemented using queues. An error can occur if there is
\r
404 * no space on the queue to post a message - indicating that the
\r
405 * semaphore was not first obtained correctly.
\r
409 * SemaphoreHandle_t xSemaphore = NULL;
\r
411 * void vATask( void * pvParameters )
\r
413 * // Create the semaphore to guard a shared resource.
\r
414 * xSemaphore = vSemaphoreCreateBinary();
\r
416 * if( xSemaphore != NULL )
\r
418 * if( xSemaphoreGive( xSemaphore ) != pdTRUE )
\r
420 * // We would expect this call to fail because we cannot give
\r
421 * // a semaphore without first "taking" it!
\r
424 * // Obtain the semaphore - don't block if the semaphore is not
\r
425 * // immediately available.
\r
426 * if( xSemaphoreTake( xSemaphore, ( TickType_t ) 0 ) )
\r
428 * // We now have the semaphore and can access the shared resource.
\r
432 * // We have finished accessing the shared resource so can free the
\r
434 * if( xSemaphoreGive( xSemaphore ) != pdTRUE )
\r
436 * // We would not expect this call to fail because we must have
\r
437 * // obtained the semaphore to get here.
\r
443 * \defgroup xSemaphoreGive xSemaphoreGive
\r
444 * \ingroup Semaphores
\r
446 #define xSemaphoreGive( xSemaphore ) xQueueGenericSend( ( QueueHandle_t ) ( xSemaphore ), NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK )
\r
450 * <pre>xSemaphoreGiveRecursive( SemaphoreHandle_t xMutex )</pre>
\r
452 * <i>Macro</i> to recursively release, or 'give', a mutex type semaphore.
\r
453 * The mutex must have previously been created using a call to
\r
454 * xSemaphoreCreateRecursiveMutex();
\r
456 * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this
\r
457 * macro to be available.
\r
459 * This macro must not be used on mutexes created using xSemaphoreCreateMutex().
\r
461 * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
\r
462 * doesn't become available again until the owner has called
\r
463 * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
\r
464 * if a task successfully 'takes' the same mutex 5 times then the mutex will
\r
465 * not be available to any other task until it has also 'given' the mutex back
\r
466 * exactly five times.
\r
468 * @param xMutex A handle to the mutex being released, or 'given'. This is the
\r
469 * handle returned by xSemaphoreCreateMutex();
\r
471 * @return pdTRUE if the semaphore was given.
\r
475 * SemaphoreHandle_t xMutex = NULL;
\r
477 * // A task that creates a mutex.
\r
478 * void vATask( void * pvParameters )
\r
480 * // Create the mutex to guard a shared resource.
\r
481 * xMutex = xSemaphoreCreateRecursiveMutex();
\r
484 * // A task that uses the mutex.
\r
485 * void vAnotherTask( void * pvParameters )
\r
487 * // ... Do other things.
\r
489 * if( xMutex != NULL )
\r
491 * // See if we can obtain the mutex. If the mutex is not available
\r
492 * // wait 10 ticks to see if it becomes free.
\r
493 * if( xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 ) == pdTRUE )
\r
495 * // We were able to obtain the mutex and can now access the
\r
496 * // shared resource.
\r
499 * // For some reason due to the nature of the code further calls to
\r
500 * // xSemaphoreTakeRecursive() are made on the same mutex. In real
\r
501 * // code these would not be just sequential calls as this would make
\r
502 * // no sense. Instead the calls are likely to be buried inside
\r
503 * // a more complex call structure.
\r
504 * xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
\r
505 * xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
\r
507 * // The mutex has now been 'taken' three times, so will not be
\r
508 * // available to another task until it has also been given back
\r
509 * // three times. Again it is unlikely that real code would have
\r
510 * // these calls sequentially, it would be more likely that the calls
\r
511 * // to xSemaphoreGiveRecursive() would be called as a call stack
\r
512 * // unwound. This is just for demonstrative purposes.
\r
513 * xSemaphoreGiveRecursive( xMutex );
\r
514 * xSemaphoreGiveRecursive( xMutex );
\r
515 * xSemaphoreGiveRecursive( xMutex );
\r
517 * // Now the mutex can be taken by other tasks.
\r
521 * // We could not obtain the mutex and can therefore not access
\r
522 * // the shared resource safely.
\r
527 * \defgroup xSemaphoreGiveRecursive xSemaphoreGiveRecursive
\r
528 * \ingroup Semaphores
\r
530 #if ( configUSE_RECURSIVE_MUTEXES == 1 )
\r
531 #define xSemaphoreGiveRecursive( xMutex ) xQueueGiveMutexRecursive( ( xMutex ) )
\r
537 * xSemaphoreGiveFromISR(
\r
538 * SemaphoreHandle_t xSemaphore,
\r
539 * BaseType_t *pxHigherPriorityTaskWoken
\r
542 * <i>Macro</i> to release a semaphore. The semaphore must have previously been
\r
543 * created with a call to xSemaphoreCreateBinary() or xSemaphoreCreateCounting().
\r
545 * Mutex type semaphores (those created using a call to xSemaphoreCreateMutex())
\r
546 * must not be used with this macro.
\r
548 * This macro can be used from an ISR.
\r
550 * @param xSemaphore A handle to the semaphore being released. This is the
\r
551 * handle returned when the semaphore was created.
\r
553 * @param pxHigherPriorityTaskWoken xSemaphoreGiveFromISR() will set
\r
554 * *pxHigherPriorityTaskWoken to pdTRUE if giving the semaphore caused a task
\r
555 * to unblock, and the unblocked task has a priority higher than the currently
\r
556 * running task. If xSemaphoreGiveFromISR() sets this value to pdTRUE then
\r
557 * a context switch should be requested before the interrupt is exited.
\r
559 * @return pdTRUE if the semaphore was successfully given, otherwise errQUEUE_FULL.
\r
563 \#define LONG_TIME 0xffff
\r
564 \#define TICKS_TO_WAIT 10
\r
565 * SemaphoreHandle_t xSemaphore = NULL;
\r
567 * // Repetitive task.
\r
568 * void vATask( void * pvParameters )
\r
572 * // We want this task to run every 10 ticks of a timer. The semaphore
\r
573 * // was created before this task was started.
\r
575 * // Block waiting for the semaphore to become available.
\r
576 * if( xSemaphoreTake( xSemaphore, LONG_TIME ) == pdTRUE )
\r
578 * // It is time to execute.
\r
582 * // We have finished our task. Return to the top of the loop where
\r
583 * // we will block on the semaphore until it is time to execute
\r
584 * // again. Note when using the semaphore for synchronisation with an
\r
585 * // ISR in this manner there is no need to 'give' the semaphore back.
\r
591 * void vTimerISR( void * pvParameters )
\r
593 * static uint8_t ucLocalTickCount = 0;
\r
594 * static BaseType_t xHigherPriorityTaskWoken;
\r
596 * // A timer tick has occurred.
\r
598 * // ... Do other time functions.
\r
600 * // Is it time for vATask () to run?
\r
601 * xHigherPriorityTaskWoken = pdFALSE;
\r
602 * ucLocalTickCount++;
\r
603 * if( ucLocalTickCount >= TICKS_TO_WAIT )
\r
605 * // Unblock the task by releasing the semaphore.
\r
606 * xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );
\r
608 * // Reset the count so we release the semaphore again in 10 ticks time.
\r
609 * ucLocalTickCount = 0;
\r
612 * if( xHigherPriorityTaskWoken != pdFALSE )
\r
614 * // We can force a context switch here. Context switching from an
\r
615 * // ISR uses port specific syntax. Check the demo task for your port
\r
616 * // to find the syntax required.
\r
620 * \defgroup xSemaphoreGiveFromISR xSemaphoreGiveFromISR
\r
621 * \ingroup Semaphores
\r
623 #define xSemaphoreGiveFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueGiveFromISR( ( QueueHandle_t ) ( xSemaphore ), ( pxHigherPriorityTaskWoken ) )
\r
628 * xSemaphoreTakeFromISR(
\r
629 * SemaphoreHandle_t xSemaphore,
\r
630 * BaseType_t *pxHigherPriorityTaskWoken
\r
633 * <i>Macro</i> to take a semaphore from an ISR. The semaphore must have
\r
634 * previously been created with a call to xSemaphoreCreateBinary() or
\r
635 * xSemaphoreCreateCounting().
\r
637 * Mutex type semaphores (those created using a call to xSemaphoreCreateMutex())
\r
638 * must not be used with this macro.
\r
640 * This macro can be used from an ISR, however taking a semaphore from an ISR
\r
641 * is not a common operation. It is likely to only be useful when taking a
\r
642 * counting semaphore when an interrupt is obtaining an object from a resource
\r
643 * pool (when the semaphore count indicates the number of resources available).
\r
645 * @param xSemaphore A handle to the semaphore being taken. This is the
\r
646 * handle returned when the semaphore was created.
\r
648 * @param pxHigherPriorityTaskWoken xSemaphoreTakeFromISR() will set
\r
649 * *pxHigherPriorityTaskWoken to pdTRUE if taking the semaphore caused a task
\r
650 * to unblock, and the unblocked task has a priority higher than the currently
\r
651 * running task. If xSemaphoreTakeFromISR() sets this value to pdTRUE then
\r
652 * a context switch should be requested before the interrupt is exited.
\r
654 * @return pdTRUE if the semaphore was successfully taken, otherwise
\r
657 #define xSemaphoreTakeFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueReceiveFromISR( ( QueueHandle_t ) ( xSemaphore ), NULL, ( pxHigherPriorityTaskWoken ) )
\r
661 * <pre>SemaphoreHandle_t xSemaphoreCreateMutex( void )</pre>
\r
663 * Creates a new mutex type semaphore instance, and returns a handle by which
\r
664 * the new mutex can be referenced.
\r
666 * Internally, within the FreeRTOS implementation, mutex semaphores use a block
\r
667 * of memory, in which the mutex structure is stored. If a mutex is created
\r
668 * using xSemaphoreCreateMutex() then the required memory is automatically
\r
669 * dynamically allocated inside the xSemaphoreCreateMutex() function. (see
\r
670 * http://www.freertos.org/a00111.html). If a mutex is created using
\r
671 * xSemaphoreCreateMutexStatic() then the application writer must provided the
\r
672 * memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to be created
\r
673 * without using any dynamic memory allocation.
\r
675 * Mutexes created using this function can be accessed using the xSemaphoreTake()
\r
676 * and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and
\r
677 * xSemaphoreGiveRecursive() macros must not be used.
\r
679 * This type of semaphore uses a priority inheritance mechanism so a task
\r
680 * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
\r
681 * semaphore it is no longer required.
\r
683 * Mutex type semaphores cannot be used from within interrupt service routines.
\r
685 * See xSemaphoreCreateBinary() for an alternative implementation that can be
\r
686 * used for pure synchronisation (where one task or interrupt always 'gives' the
\r
687 * semaphore and another always 'takes' the semaphore) and from within interrupt
\r
688 * service routines.
\r
690 * @return If the mutex was successfully created then a handle to the created
\r
691 * semaphore is returned. If there was not enough heap to allocate the mutex
\r
692 * data structures then NULL is returned.
\r
696 * SemaphoreHandle_t xSemaphore;
\r
698 * void vATask( void * pvParameters )
\r
700 * // Semaphore cannot be used before a call to xSemaphoreCreateMutex().
\r
701 * // This is a macro so pass the variable in directly.
\r
702 * xSemaphore = xSemaphoreCreateMutex();
\r
704 * if( xSemaphore != NULL )
\r
706 * // The semaphore was created successfully.
\r
707 * // The semaphore can now be used.
\r
711 * \defgroup xSemaphoreCreateMutex xSemaphoreCreateMutex
\r
712 * \ingroup Semaphores
\r
714 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
715 #define xSemaphoreCreateMutex() xQueueCreateMutex( queueQUEUE_TYPE_MUTEX )
\r
720 * <pre>SemaphoreHandle_t xSemaphoreCreateMutexStatic( StaticSemaphore_t *pxMutexBuffer )</pre>
\r
722 * Creates a new mutex type semaphore instance, and returns a handle by which
\r
723 * the new mutex can be referenced.
\r
725 * Internally, within the FreeRTOS implementation, mutex semaphores use a block
\r
726 * of memory, in which the mutex structure is stored. If a mutex is created
\r
727 * using xSemaphoreCreateMutex() then the required memory is automatically
\r
728 * dynamically allocated inside the xSemaphoreCreateMutex() function. (see
\r
729 * http://www.freertos.org/a00111.html). If a mutex is created using
\r
730 * xSemaphoreCreateMutexStatic() then the application writer must provided the
\r
731 * memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to be created
\r
732 * without using any dynamic memory allocation.
\r
734 * Mutexes created using this function can be accessed using the xSemaphoreTake()
\r
735 * and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and
\r
736 * xSemaphoreGiveRecursive() macros must not be used.
\r
738 * This type of semaphore uses a priority inheritance mechanism so a task
\r
739 * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
\r
740 * semaphore it is no longer required.
\r
742 * Mutex type semaphores cannot be used from within interrupt service routines.
\r
744 * See xSemaphoreCreateBinary() for an alternative implementation that can be
\r
745 * used for pure synchronisation (where one task or interrupt always 'gives' the
\r
746 * semaphore and another always 'takes' the semaphore) and from within interrupt
\r
747 * service routines.
\r
749 * @param pxMutexBuffer Must point to a variable of type StaticSemaphore_t,
\r
750 * which will be used to hold the mutex's data structure, removing the need for
\r
751 * the memory to be allocated dynamically.
\r
753 * @return If the mutex was successfully created then a handle to the created
\r
754 * mutex is returned. If pxMutexBuffer was NULL then NULL is returned.
\r
758 * SemaphoreHandle_t xSemaphore;
\r
759 * StaticSemaphore_t xMutexBuffer;
\r
761 * void vATask( void * pvParameters )
\r
763 * // A mutex cannot be used before it has been created. xMutexBuffer is
\r
764 * // into xSemaphoreCreateMutexStatic() so no dynamic memory allocation is
\r
766 * xSemaphore = xSemaphoreCreateMutexStatic( &xMutexBuffer );
\r
768 * // As no dynamic memory allocation was performed, xSemaphore cannot be NULL,
\r
769 * // so there is no need to check it.
\r
772 * \defgroup xSemaphoreCreateMutexStatic xSemaphoreCreateMutexStatic
\r
773 * \ingroup Semaphores
\r
775 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
776 #define xSemaphoreCreateMutexStatic( pxMutexBuffer ) xQueueCreateMutexStatic( queueQUEUE_TYPE_MUTEX, ( pxMutexBuffer ) )
\r
777 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
782 * <pre>SemaphoreHandle_t xSemaphoreCreateRecursiveMutex( void )</pre>
\r
784 * Creates a new recursive mutex type semaphore instance, and returns a handle
\r
785 * by which the new recursive mutex can be referenced.
\r
787 * Internally, within the FreeRTOS implementation, recursive mutexs use a block
\r
788 * of memory, in which the mutex structure is stored. If a recursive mutex is
\r
789 * created using xSemaphoreCreateRecursiveMutex() then the required memory is
\r
790 * automatically dynamically allocated inside the
\r
791 * xSemaphoreCreateRecursiveMutex() function. (see
\r
792 * http://www.freertos.org/a00111.html). If a recursive mutex is created using
\r
793 * xSemaphoreCreateRecursiveMutexStatic() then the application writer must
\r
794 * provide the memory that will get used by the mutex.
\r
795 * xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to
\r
796 * be created without using any dynamic memory allocation.
\r
798 * Mutexes created using this macro can be accessed using the
\r
799 * xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The
\r
800 * xSemaphoreTake() and xSemaphoreGive() macros must not be used.
\r
802 * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
\r
803 * doesn't become available again until the owner has called
\r
804 * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
\r
805 * if a task successfully 'takes' the same mutex 5 times then the mutex will
\r
806 * not be available to any other task until it has also 'given' the mutex back
\r
807 * exactly five times.
\r
809 * This type of semaphore uses a priority inheritance mechanism so a task
\r
810 * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
\r
811 * semaphore it is no longer required.
\r
813 * Mutex type semaphores cannot be used from within interrupt service routines.
\r
815 * See xSemaphoreCreateBinary() for an alternative implementation that can be
\r
816 * used for pure synchronisation (where one task or interrupt always 'gives' the
\r
817 * semaphore and another always 'takes' the semaphore) and from within interrupt
\r
818 * service routines.
\r
820 * @return xSemaphore Handle to the created mutex semaphore. Should be of type
\r
821 * SemaphoreHandle_t.
\r
825 * SemaphoreHandle_t xSemaphore;
\r
827 * void vATask( void * pvParameters )
\r
829 * // Semaphore cannot be used before a call to xSemaphoreCreateMutex().
\r
830 * // This is a macro so pass the variable in directly.
\r
831 * xSemaphore = xSemaphoreCreateRecursiveMutex();
\r
833 * if( xSemaphore != NULL )
\r
835 * // The semaphore was created successfully.
\r
836 * // The semaphore can now be used.
\r
840 * \defgroup xSemaphoreCreateRecursiveMutex xSemaphoreCreateRecursiveMutex
\r
841 * \ingroup Semaphores
\r
843 #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_RECURSIVE_MUTEXES == 1 ) )
\r
844 #define xSemaphoreCreateRecursiveMutex() xQueueCreateMutex( queueQUEUE_TYPE_RECURSIVE_MUTEX )
\r
849 * <pre>SemaphoreHandle_t xSemaphoreCreateRecursiveMutexStatic( StaticSemaphore_t *pxMutexBuffer )</pre>
\r
851 * Creates a new recursive mutex type semaphore instance, and returns a handle
\r
852 * by which the new recursive mutex can be referenced.
\r
854 * Internally, within the FreeRTOS implementation, recursive mutexs use a block
\r
855 * of memory, in which the mutex structure is stored. If a recursive mutex is
\r
856 * created using xSemaphoreCreateRecursiveMutex() then the required memory is
\r
857 * automatically dynamically allocated inside the
\r
858 * xSemaphoreCreateRecursiveMutex() function. (see
\r
859 * http://www.freertos.org/a00111.html). If a recursive mutex is created using
\r
860 * xSemaphoreCreateRecursiveMutexStatic() then the application writer must
\r
861 * provide the memory that will get used by the mutex.
\r
862 * xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to
\r
863 * be created without using any dynamic memory allocation.
\r
865 * Mutexes created using this macro can be accessed using the
\r
866 * xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The
\r
867 * xSemaphoreTake() and xSemaphoreGive() macros must not be used.
\r
869 * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
\r
870 * doesn't become available again until the owner has called
\r
871 * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
\r
872 * if a task successfully 'takes' the same mutex 5 times then the mutex will
\r
873 * not be available to any other task until it has also 'given' the mutex back
\r
874 * exactly five times.
\r
876 * This type of semaphore uses a priority inheritance mechanism so a task
\r
877 * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
\r
878 * semaphore it is no longer required.
\r
880 * Mutex type semaphores cannot be used from within interrupt service routines.
\r
882 * See xSemaphoreCreateBinary() for an alternative implementation that can be
\r
883 * used for pure synchronisation (where one task or interrupt always 'gives' the
\r
884 * semaphore and another always 'takes' the semaphore) and from within interrupt
\r
885 * service routines.
\r
887 * @param pxMutexBuffer Must point to a variable of type StaticSemaphore_t,
\r
888 * which will then be used to hold the recursive mutex's data structure,
\r
889 * removing the need for the memory to be allocated dynamically.
\r
891 * @return If the recursive mutex was successfully created then a handle to the
\r
892 * created recursive mutex is returned. If pxMutexBuffer was NULL then NULL is
\r
897 * SemaphoreHandle_t xSemaphore;
\r
898 * StaticSemaphore_t xMutexBuffer;
\r
900 * void vATask( void * pvParameters )
\r
902 * // A recursive semaphore cannot be used before it is created. Here a
\r
903 * // recursive mutex is created using xSemaphoreCreateRecursiveMutexStatic().
\r
904 * // The address of xMutexBuffer is passed into the function, and will hold
\r
905 * // the mutexes data structures - so no dynamic memory allocation will be
\r
907 * xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xMutexBuffer );
\r
909 * // As no dynamic memory allocation was performed, xSemaphore cannot be NULL,
\r
910 * // so there is no need to check it.
\r
913 * \defgroup xSemaphoreCreateRecursiveMutexStatic xSemaphoreCreateRecursiveMutexStatic
\r
914 * \ingroup Semaphores
\r
916 #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_RECURSIVE_MUTEXES == 1 ) )
\r
917 #define xSemaphoreCreateRecursiveMutexStatic( pxStaticSemaphore ) xQueueCreateMutexStatic( queueQUEUE_TYPE_RECURSIVE_MUTEX, pxStaticSemaphore )
\r
918 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
922 * <pre>SemaphoreHandle_t xSemaphoreCreateCounting( UBaseType_t uxMaxCount, UBaseType_t uxInitialCount )</pre>
\r
924 * Creates a new counting semaphore instance, and returns a handle by which the
\r
925 * new counting semaphore can be referenced.
\r
927 * In many usage scenarios it is faster and more memory efficient to use a
\r
928 * direct to task notification in place of a counting semaphore!
\r
929 * http://www.freertos.org/RTOS-task-notifications.html
\r
931 * Internally, within the FreeRTOS implementation, counting semaphores use a
\r
932 * block of memory, in which the counting semaphore structure is stored. If a
\r
933 * counting semaphore is created using xSemaphoreCreateCounting() then the
\r
934 * required memory is automatically dynamically allocated inside the
\r
935 * xSemaphoreCreateCounting() function. (see
\r
936 * http://www.freertos.org/a00111.html). If a counting semaphore is created
\r
937 * using xSemaphoreCreateCountingStatic() then the application writer can
\r
938 * instead optionally provide the memory that will get used by the counting
\r
939 * semaphore. xSemaphoreCreateCountingStatic() therefore allows a counting
\r
940 * semaphore to be created without using any dynamic memory allocation.
\r
942 * Counting semaphores are typically used for two things:
\r
944 * 1) Counting events.
\r
946 * In this usage scenario an event handler will 'give' a semaphore each time
\r
947 * an event occurs (incrementing the semaphore count value), and a handler
\r
948 * task will 'take' a semaphore each time it processes an event
\r
949 * (decrementing the semaphore count value). The count value is therefore
\r
950 * the difference between the number of events that have occurred and the
\r
951 * number that have been processed. In this case it is desirable for the
\r
952 * initial count value to be zero.
\r
954 * 2) Resource management.
\r
956 * In this usage scenario the count value indicates the number of resources
\r
957 * available. To obtain control of a resource a task must first obtain a
\r
958 * semaphore - decrementing the semaphore count value. When the count value
\r
959 * reaches zero there are no free resources. When a task finishes with the
\r
960 * resource it 'gives' the semaphore back - incrementing the semaphore count
\r
961 * value. In this case it is desirable for the initial count value to be
\r
962 * equal to the maximum count value, indicating that all resources are free.
\r
964 * @param uxMaxCount The maximum count value that can be reached. When the
\r
965 * semaphore reaches this value it can no longer be 'given'.
\r
967 * @param uxInitialCount The count value assigned to the semaphore when it is
\r
970 * @return Handle to the created semaphore. Null if the semaphore could not be
\r
975 * SemaphoreHandle_t xSemaphore;
\r
977 * void vATask( void * pvParameters )
\r
979 * SemaphoreHandle_t xSemaphore = NULL;
\r
981 * // Semaphore cannot be used before a call to xSemaphoreCreateCounting().
\r
982 * // The max value to which the semaphore can count should be 10, and the
\r
983 * // initial value assigned to the count should be 0.
\r
984 * xSemaphore = xSemaphoreCreateCounting( 10, 0 );
\r
986 * if( xSemaphore != NULL )
\r
988 * // The semaphore was created successfully.
\r
989 * // The semaphore can now be used.
\r
993 * \defgroup xSemaphoreCreateCounting xSemaphoreCreateCounting
\r
994 * \ingroup Semaphores
\r
996 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
997 #define xSemaphoreCreateCounting( uxMaxCount, uxInitialCount ) xQueueCreateCountingSemaphore( ( uxMaxCount ), ( uxInitialCount ) )
\r
1002 * <pre>SemaphoreHandle_t xSemaphoreCreateCountingStatic( UBaseType_t uxMaxCount, UBaseType_t uxInitialCount, StaticSemaphore_t *pxSemaphoreBuffer )</pre>
\r
1004 * Creates a new counting semaphore instance, and returns a handle by which the
\r
1005 * new counting semaphore can be referenced.
\r
1007 * In many usage scenarios it is faster and more memory efficient to use a
\r
1008 * direct to task notification in place of a counting semaphore!
\r
1009 * http://www.freertos.org/RTOS-task-notifications.html
\r
1011 * Internally, within the FreeRTOS implementation, counting semaphores use a
\r
1012 * block of memory, in which the counting semaphore structure is stored. If a
\r
1013 * counting semaphore is created using xSemaphoreCreateCounting() then the
\r
1014 * required memory is automatically dynamically allocated inside the
\r
1015 * xSemaphoreCreateCounting() function. (see
\r
1016 * http://www.freertos.org/a00111.html). If a counting semaphore is created
\r
1017 * using xSemaphoreCreateCountingStatic() then the application writer must
\r
1018 * provide the memory. xSemaphoreCreateCountingStatic() therefore allows a
\r
1019 * counting semaphore to be created without using any dynamic memory allocation.
\r
1021 * Counting semaphores are typically used for two things:
\r
1023 * 1) Counting events.
\r
1025 * In this usage scenario an event handler will 'give' a semaphore each time
\r
1026 * an event occurs (incrementing the semaphore count value), and a handler
\r
1027 * task will 'take' a semaphore each time it processes an event
\r
1028 * (decrementing the semaphore count value). The count value is therefore
\r
1029 * the difference between the number of events that have occurred and the
\r
1030 * number that have been processed. In this case it is desirable for the
\r
1031 * initial count value to be zero.
\r
1033 * 2) Resource management.
\r
1035 * In this usage scenario the count value indicates the number of resources
\r
1036 * available. To obtain control of a resource a task must first obtain a
\r
1037 * semaphore - decrementing the semaphore count value. When the count value
\r
1038 * reaches zero there are no free resources. When a task finishes with the
\r
1039 * resource it 'gives' the semaphore back - incrementing the semaphore count
\r
1040 * value. In this case it is desirable for the initial count value to be
\r
1041 * equal to the maximum count value, indicating that all resources are free.
\r
1043 * @param uxMaxCount The maximum count value that can be reached. When the
\r
1044 * semaphore reaches this value it can no longer be 'given'.
\r
1046 * @param uxInitialCount The count value assigned to the semaphore when it is
\r
1049 * @param pxSemaphoreBuffer Must point to a variable of type StaticSemaphore_t,
\r
1050 * which will then be used to hold the semaphore's data structure, removing the
\r
1051 * need for the memory to be allocated dynamically.
\r
1053 * @return If the counting semaphore was successfully created then a handle to
\r
1054 * the created counting semaphore is returned. If pxSemaphoreBuffer was NULL
\r
1055 * then NULL is returned.
\r
1059 * SemaphoreHandle_t xSemaphore;
\r
1060 * StaticSemaphore_t xSemaphoreBuffer;
\r
1062 * void vATask( void * pvParameters )
\r
1064 * SemaphoreHandle_t xSemaphore = NULL;
\r
1066 * // Counting semaphore cannot be used before they have been created. Create
\r
1067 * // a counting semaphore using xSemaphoreCreateCountingStatic(). The max
\r
1068 * // value to which the semaphore can count is 10, and the initial value
\r
1069 * // assigned to the count will be 0. The address of xSemaphoreBuffer is
\r
1070 * // passed in and will be used to hold the semaphore structure, so no dynamic
\r
1071 * // memory allocation will be used.
\r
1072 * xSemaphore = xSemaphoreCreateCounting( 10, 0, &xSemaphoreBuffer );
\r
1074 * // No memory allocation was attempted so xSemaphore cannot be NULL, so there
\r
1075 * // is no need to check its value.
\r
1078 * \defgroup xSemaphoreCreateCountingStatic xSemaphoreCreateCountingStatic
\r
1079 * \ingroup Semaphores
\r
1081 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
1082 #define xSemaphoreCreateCountingStatic( uxMaxCount, uxInitialCount, pxSemaphoreBuffer ) xQueueCreateCountingSemaphoreStatic( ( uxMaxCount ), ( uxInitialCount ), ( pxSemaphoreBuffer ) )
\r
1083 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
1087 * <pre>void vSemaphoreDelete( SemaphoreHandle_t xSemaphore );</pre>
\r
1089 * Delete a semaphore. This function must be used with care. For example,
\r
1090 * do not delete a mutex type semaphore if the mutex is held by a task.
\r
1092 * @param xSemaphore A handle to the semaphore to be deleted.
\r
1094 * \defgroup vSemaphoreDelete vSemaphoreDelete
\r
1095 * \ingroup Semaphores
\r
1097 #define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( QueueHandle_t ) ( xSemaphore ) )
\r
1101 * <pre>TaskHandle_t xSemaphoreGetMutexHolder( SemaphoreHandle_t xMutex );</pre>
\r
1103 * If xMutex is indeed a mutex type semaphore, return the current mutex holder.
\r
1104 * If xMutex is not a mutex type semaphore, or the mutex is available (not held
\r
1105 * by a task), return NULL.
\r
1107 * Note: This is a good way of determining if the calling task is the mutex
\r
1108 * holder, but not a good way of determining the identity of the mutex holder as
\r
1109 * the holder may change between the function exiting and the returned value
\r
1112 #define xSemaphoreGetMutexHolder( xSemaphore ) xQueueGetMutexHolder( ( xSemaphore ) )
\r
1116 * <pre>TaskHandle_t xSemaphoreGetMutexHolderFromISR( SemaphoreHandle_t xMutex );</pre>
\r
1118 * If xMutex is indeed a mutex type semaphore, return the current mutex holder.
\r
1119 * If xMutex is not a mutex type semaphore, or the mutex is available (not held
\r
1120 * by a task), return NULL.
\r
1123 #define xSemaphoreGetMutexHolderFromISR( xSemaphore ) xQueueGetMutexHolderFromISR( ( xSemaphore ) )
\r
1127 * <pre>UBaseType_t uxSemaphoreGetCount( SemaphoreHandle_t xSemaphore );</pre>
\r
1129 * If the semaphore is a counting semaphore then uxSemaphoreGetCount() returns
\r
1130 * its current count value. If the semaphore is a binary semaphore then
\r
1131 * uxSemaphoreGetCount() returns 1 if the semaphore is available, and 0 if the
\r
1132 * semaphore is not available.
\r
1135 #define uxSemaphoreGetCount( xSemaphore ) uxQueueMessagesWaiting( ( QueueHandle_t ) ( xSemaphore ) )
\r
1137 #endif /* SEMAPHORE_H */
\r