2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 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. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
32 #ifndef INC_FREERTOS_H
\r
33 #error "include FreeRTOS.h" must appear in source files before "include semphr.h"
\r
38 typedef QueueHandle_t SemaphoreHandle_t;
\r
40 #define semBINARY_SEMAPHORE_QUEUE_LENGTH ( ( uint8_t ) 1U )
\r
41 #define semSEMAPHORE_QUEUE_ITEM_LENGTH ( ( uint8_t ) 0U )
\r
42 #define semGIVE_BLOCK_TIME ( ( TickType_t ) 0U )
\r
47 * <pre>vSemaphoreCreateBinary( SemaphoreHandle_t xSemaphore )</pre>
\r
49 * In many usage scenarios it is faster and more memory efficient to use a
\r
50 * direct to task notification in place of a binary semaphore!
\r
51 * http://www.freertos.org/RTOS-task-notifications.html
\r
53 * This old vSemaphoreCreateBinary() macro is now deprecated in favour of the
\r
54 * xSemaphoreCreateBinary() function. Note that binary semaphores created using
\r
55 * the vSemaphoreCreateBinary() macro are created in a state such that the
\r
56 * first call to 'take' the semaphore would pass, whereas binary semaphores
\r
57 * created using xSemaphoreCreateBinary() are created in a state such that the
\r
58 * the semaphore must first be 'given' before it can be 'taken'.
\r
60 * <i>Macro</i> that implements a semaphore by using the existing queue mechanism.
\r
61 * The queue length is 1 as this is a binary semaphore. The data size is 0
\r
62 * as we don't want to actually store any data - we just want to know if the
\r
63 * queue is empty or full.
\r
65 * This type of semaphore can be used for pure synchronisation between tasks or
\r
66 * between an interrupt and a task. The semaphore need not be given back once
\r
67 * obtained, so one task/interrupt can continuously 'give' the semaphore while
\r
68 * another continuously 'takes' the semaphore. For this reason this type of
\r
69 * semaphore does not use a priority inheritance mechanism. For an alternative
\r
70 * that does use priority inheritance see xSemaphoreCreateMutex().
\r
72 * @param xSemaphore Handle to the created semaphore. Should be of type SemaphoreHandle_t.
\r
76 SemaphoreHandle_t xSemaphore = NULL;
\r
78 void vATask( void * pvParameters )
\r
80 // Semaphore cannot be used before a call to vSemaphoreCreateBinary ().
\r
81 // This is a macro so pass the variable in directly.
\r
82 vSemaphoreCreateBinary( xSemaphore );
\r
84 if( xSemaphore != NULL )
\r
86 // The semaphore was created successfully.
\r
87 // The semaphore can now be used.
\r
91 * \defgroup vSemaphoreCreateBinary vSemaphoreCreateBinary
\r
92 * \ingroup Semaphores
\r
94 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
95 #define vSemaphoreCreateBinary( xSemaphore ) \
\r
97 ( xSemaphore ) = xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE ); \
\r
98 if( ( xSemaphore ) != NULL ) \
\r
100 ( void ) xSemaphoreGive( ( xSemaphore ) ); \
\r
107 * <pre>SemaphoreHandle_t xSemaphoreCreateBinary( void )</pre>
\r
109 * Creates a new binary semaphore instance, and returns a handle by which the
\r
110 * new semaphore can be referenced.
\r
112 * In many usage scenarios it is faster and more memory efficient to use a
\r
113 * direct to task notification in place of a binary semaphore!
\r
114 * http://www.freertos.org/RTOS-task-notifications.html
\r
116 * Internally, within the FreeRTOS implementation, binary semaphores use a block
\r
117 * of memory, in which the semaphore structure is stored. If a binary semaphore
\r
118 * is created using xSemaphoreCreateBinary() then the required memory is
\r
119 * automatically dynamically allocated inside the xSemaphoreCreateBinary()
\r
120 * function. (see http://www.freertos.org/a00111.html). If a binary semaphore
\r
121 * is created using xSemaphoreCreateBinaryStatic() then the application writer
\r
122 * must provide the memory. xSemaphoreCreateBinaryStatic() therefore allows a
\r
123 * binary semaphore to be created without using any dynamic memory allocation.
\r
125 * The old vSemaphoreCreateBinary() macro is now deprecated in favour of this
\r
126 * xSemaphoreCreateBinary() function. Note that binary semaphores created using
\r
127 * the vSemaphoreCreateBinary() macro are created in a state such that the
\r
128 * first call to 'take' the semaphore would pass, whereas binary semaphores
\r
129 * created using xSemaphoreCreateBinary() are created in a state such that the
\r
130 * the semaphore must first be 'given' before it can be 'taken'.
\r
132 * This type of semaphore can be used for pure synchronisation between tasks or
\r
133 * between an interrupt and a task. The semaphore need not be given back once
\r
134 * obtained, so one task/interrupt can continuously 'give' the semaphore while
\r
135 * another continuously 'takes' the semaphore. For this reason this type of
\r
136 * semaphore does not use a priority inheritance mechanism. For an alternative
\r
137 * that does use priority inheritance see xSemaphoreCreateMutex().
\r
139 * @return Handle to the created semaphore, or NULL if the memory required to
\r
140 * hold the semaphore's data structures could not be allocated.
\r
144 SemaphoreHandle_t xSemaphore = NULL;
\r
146 void vATask( void * pvParameters )
\r
148 // Semaphore cannot be used before a call to xSemaphoreCreateBinary().
\r
149 // This is a macro so pass the variable in directly.
\r
150 xSemaphore = xSemaphoreCreateBinary();
\r
152 if( xSemaphore != NULL )
\r
154 // The semaphore was created successfully.
\r
155 // The semaphore can now be used.
\r
159 * \defgroup xSemaphoreCreateBinary xSemaphoreCreateBinary
\r
160 * \ingroup Semaphores
\r
162 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
163 #define xSemaphoreCreateBinary() xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE )
\r
168 * <pre>SemaphoreHandle_t xSemaphoreCreateBinaryStatic( StaticSemaphore_t *pxSemaphoreBuffer )</pre>
\r
170 * Creates a new binary semaphore instance, and returns a handle by which the
\r
171 * new semaphore can be referenced.
\r
173 * NOTE: In many usage scenarios it is faster and more memory efficient to use a
\r
174 * direct to task notification in place of a binary semaphore!
\r
175 * http://www.freertos.org/RTOS-task-notifications.html
\r
177 * Internally, within the FreeRTOS implementation, binary semaphores use a block
\r
178 * of memory, in which the semaphore structure is stored. If a binary semaphore
\r
179 * is created using xSemaphoreCreateBinary() then the required memory is
\r
180 * automatically dynamically allocated inside the xSemaphoreCreateBinary()
\r
181 * function. (see http://www.freertos.org/a00111.html). If a binary semaphore
\r
182 * is created using xSemaphoreCreateBinaryStatic() then the application writer
\r
183 * must provide the memory. xSemaphoreCreateBinaryStatic() therefore allows a
\r
184 * binary semaphore to be created without using any dynamic memory allocation.
\r
186 * This type of semaphore can be used for pure synchronisation between tasks or
\r
187 * between an interrupt and a task. The semaphore need not be given back once
\r
188 * obtained, so one task/interrupt can continuously 'give' the semaphore while
\r
189 * another continuously 'takes' the semaphore. For this reason this type of
\r
190 * semaphore does not use a priority inheritance mechanism. For an alternative
\r
191 * that does use priority inheritance see xSemaphoreCreateMutex().
\r
193 * @param pxSemaphoreBuffer Must point to a variable of type StaticSemaphore_t,
\r
194 * which will then be used to hold the semaphore's data structure, removing the
\r
195 * need for the memory to be allocated dynamically.
\r
197 * @return If the semaphore is created then a handle to the created semaphore is
\r
198 * returned. If pxSemaphoreBuffer is NULL then NULL is returned.
\r
202 SemaphoreHandle_t xSemaphore = NULL;
\r
203 StaticSemaphore_t xSemaphoreBuffer;
\r
205 void vATask( void * pvParameters )
\r
207 // Semaphore cannot be used before a call to xSemaphoreCreateBinary().
\r
208 // The semaphore's data structures will be placed in the xSemaphoreBuffer
\r
209 // variable, the address of which is passed into the function. The
\r
210 // function's parameter is not NULL, so the function will not attempt any
\r
211 // dynamic memory allocation, and therefore the function will not return
\r
213 xSemaphore = xSemaphoreCreateBinary( &xSemaphoreBuffer );
\r
215 // Rest of task code goes here.
\r
218 * \defgroup xSemaphoreCreateBinaryStatic xSemaphoreCreateBinaryStatic
\r
219 * \ingroup Semaphores
\r
221 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
222 #define xSemaphoreCreateBinaryStatic( pxStaticSemaphore ) xQueueGenericCreateStatic( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticSemaphore, queueQUEUE_TYPE_BINARY_SEMAPHORE )
\r
223 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
227 * <pre>xSemaphoreTake(
\r
228 * SemaphoreHandle_t xSemaphore,
\r
229 * TickType_t xBlockTime
\r
232 * <i>Macro</i> to obtain a semaphore. The semaphore must have previously been
\r
233 * created with a call to xSemaphoreCreateBinary(), xSemaphoreCreateMutex() or
\r
234 * xSemaphoreCreateCounting().
\r
236 * @param xSemaphore A handle to the semaphore being taken - obtained when
\r
237 * the semaphore was created.
\r
239 * @param xBlockTime The time in ticks to wait for the semaphore to become
\r
240 * available. The macro portTICK_PERIOD_MS can be used to convert this to a
\r
241 * real time. A block time of zero can be used to poll the semaphore. A block
\r
242 * time of portMAX_DELAY can be used to block indefinitely (provided
\r
243 * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h).
\r
245 * @return pdTRUE if the semaphore was obtained. pdFALSE
\r
246 * if xBlockTime expired without the semaphore becoming available.
\r
250 SemaphoreHandle_t xSemaphore = NULL;
\r
252 // A task that creates a semaphore.
\r
253 void vATask( void * pvParameters )
\r
255 // Create the semaphore to guard a shared resource.
\r
256 xSemaphore = xSemaphoreCreateBinary();
\r
259 // A task that uses the semaphore.
\r
260 void vAnotherTask( void * pvParameters )
\r
262 // ... Do other things.
\r
264 if( xSemaphore != NULL )
\r
266 // See if we can obtain the semaphore. If the semaphore is not available
\r
267 // wait 10 ticks to see if it becomes free.
\r
268 if( xSemaphoreTake( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
\r
270 // We were able to obtain the semaphore and can now access the
\r
271 // shared resource.
\r
275 // We have finished accessing the shared resource. Release the
\r
277 xSemaphoreGive( xSemaphore );
\r
281 // We could not obtain the semaphore and can therefore not access
\r
282 // the shared resource safely.
\r
287 * \defgroup xSemaphoreTake xSemaphoreTake
\r
288 * \ingroup Semaphores
\r
290 #define xSemaphoreTake( xSemaphore, xBlockTime ) xQueueSemaphoreTake( ( xSemaphore ), ( xBlockTime ) )
\r
294 * xSemaphoreTakeRecursive(
\r
295 * SemaphoreHandle_t xMutex,
\r
296 * TickType_t xBlockTime
\r
299 * <i>Macro</i> to recursively obtain, or 'take', a mutex type semaphore.
\r
300 * The mutex must have previously been created using a call to
\r
301 * xSemaphoreCreateRecursiveMutex();
\r
303 * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this
\r
304 * macro to be available.
\r
306 * This macro must not be used on mutexes created using xSemaphoreCreateMutex().
\r
308 * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
\r
309 * doesn't become available again until the owner has called
\r
310 * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
\r
311 * if a task successfully 'takes' the same mutex 5 times then the mutex will
\r
312 * not be available to any other task until it has also 'given' the mutex back
\r
313 * exactly five times.
\r
315 * @param xMutex A handle to the mutex being obtained. This is the
\r
316 * handle returned by xSemaphoreCreateRecursiveMutex();
\r
318 * @param xBlockTime The time in ticks to wait for the semaphore to become
\r
319 * available. The macro portTICK_PERIOD_MS can be used to convert this to a
\r
320 * real time. A block time of zero can be used to poll the semaphore. If
\r
321 * the task already owns the semaphore then xSemaphoreTakeRecursive() will
\r
322 * return immediately no matter what the value of xBlockTime.
\r
324 * @return pdTRUE if the semaphore was obtained. pdFALSE if xBlockTime
\r
325 * expired without the semaphore becoming available.
\r
329 SemaphoreHandle_t xMutex = NULL;
\r
331 // A task that creates a mutex.
\r
332 void vATask( void * pvParameters )
\r
334 // Create the mutex to guard a shared resource.
\r
335 xMutex = xSemaphoreCreateRecursiveMutex();
\r
338 // A task that uses the mutex.
\r
339 void vAnotherTask( void * pvParameters )
\r
341 // ... Do other things.
\r
343 if( xMutex != NULL )
\r
345 // See if we can obtain the mutex. If the mutex is not available
\r
346 // wait 10 ticks to see if it becomes free.
\r
347 if( xSemaphoreTakeRecursive( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
\r
349 // We were able to obtain the mutex and can now access the
\r
350 // shared resource.
\r
353 // For some reason due to the nature of the code further calls to
\r
354 // xSemaphoreTakeRecursive() are made on the same mutex. In real
\r
355 // code these would not be just sequential calls as this would make
\r
356 // no sense. Instead the calls are likely to be buried inside
\r
357 // a more complex call structure.
\r
358 xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
\r
359 xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
\r
361 // The mutex has now been 'taken' three times, so will not be
\r
362 // available to another task until it has also been given back
\r
363 // three times. Again it is unlikely that real code would have
\r
364 // these calls sequentially, but instead buried in a more complex
\r
365 // call structure. This is just for illustrative purposes.
\r
366 xSemaphoreGiveRecursive( xMutex );
\r
367 xSemaphoreGiveRecursive( xMutex );
\r
368 xSemaphoreGiveRecursive( xMutex );
\r
370 // Now the mutex can be taken by other tasks.
\r
374 // We could not obtain the mutex and can therefore not access
\r
375 // the shared resource safely.
\r
380 * \defgroup xSemaphoreTakeRecursive xSemaphoreTakeRecursive
\r
381 * \ingroup Semaphores
\r
383 #if( configUSE_RECURSIVE_MUTEXES == 1 )
\r
384 #define xSemaphoreTakeRecursive( xMutex, xBlockTime ) xQueueTakeMutexRecursive( ( xMutex ), ( xBlockTime ) )
\r
389 * <pre>xSemaphoreGive( SemaphoreHandle_t xSemaphore )</pre>
\r
391 * <i>Macro</i> to release a semaphore. The semaphore must have previously been
\r
392 * created with a call to xSemaphoreCreateBinary(), xSemaphoreCreateMutex() or
\r
393 * xSemaphoreCreateCounting(). and obtained using sSemaphoreTake().
\r
395 * This macro must not be used from an ISR. See xSemaphoreGiveFromISR () for
\r
396 * an alternative which can be used from an ISR.
\r
398 * This macro must also not be used on semaphores created using
\r
399 * xSemaphoreCreateRecursiveMutex().
\r
401 * @param xSemaphore A handle to the semaphore being released. This is the
\r
402 * handle returned when the semaphore was created.
\r
404 * @return pdTRUE if the semaphore was released. pdFALSE if an error occurred.
\r
405 * Semaphores are implemented using queues. An error can occur if there is
\r
406 * no space on the queue to post a message - indicating that the
\r
407 * semaphore was not first obtained correctly.
\r
411 SemaphoreHandle_t xSemaphore = NULL;
\r
413 void vATask( void * pvParameters )
\r
415 // Create the semaphore to guard a shared resource.
\r
416 xSemaphore = vSemaphoreCreateBinary();
\r
418 if( xSemaphore != NULL )
\r
420 if( xSemaphoreGive( xSemaphore ) != pdTRUE )
\r
422 // We would expect this call to fail because we cannot give
\r
423 // a semaphore without first "taking" it!
\r
426 // Obtain the semaphore - don't block if the semaphore is not
\r
427 // immediately available.
\r
428 if( xSemaphoreTake( xSemaphore, ( TickType_t ) 0 ) )
\r
430 // We now have the semaphore and can access the shared resource.
\r
434 // We have finished accessing the shared resource so can free the
\r
436 if( xSemaphoreGive( xSemaphore ) != pdTRUE )
\r
438 // We would not expect this call to fail because we must have
\r
439 // obtained the semaphore to get here.
\r
445 * \defgroup xSemaphoreGive xSemaphoreGive
\r
446 * \ingroup Semaphores
\r
448 #define xSemaphoreGive( xSemaphore ) xQueueGenericSend( ( QueueHandle_t ) ( xSemaphore ), NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK )
\r
452 * <pre>xSemaphoreGiveRecursive( SemaphoreHandle_t xMutex )</pre>
\r
454 * <i>Macro</i> to recursively release, or 'give', a mutex type semaphore.
\r
455 * The mutex must have previously been created using a call to
\r
456 * xSemaphoreCreateRecursiveMutex();
\r
458 * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this
\r
459 * macro to be available.
\r
461 * This macro must not be used on mutexes created using xSemaphoreCreateMutex().
\r
463 * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
\r
464 * doesn't become available again until the owner has called
\r
465 * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
\r
466 * if a task successfully 'takes' the same mutex 5 times then the mutex will
\r
467 * not be available to any other task until it has also 'given' the mutex back
\r
468 * exactly five times.
\r
470 * @param xMutex A handle to the mutex being released, or 'given'. This is the
\r
471 * handle returned by xSemaphoreCreateMutex();
\r
473 * @return pdTRUE if the semaphore was given.
\r
477 SemaphoreHandle_t xMutex = NULL;
\r
479 // A task that creates a mutex.
\r
480 void vATask( void * pvParameters )
\r
482 // Create the mutex to guard a shared resource.
\r
483 xMutex = xSemaphoreCreateRecursiveMutex();
\r
486 // A task that uses the mutex.
\r
487 void vAnotherTask( void * pvParameters )
\r
489 // ... Do other things.
\r
491 if( xMutex != NULL )
\r
493 // See if we can obtain the mutex. If the mutex is not available
\r
494 // wait 10 ticks to see if it becomes free.
\r
495 if( xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 ) == pdTRUE )
\r
497 // We were able to obtain the mutex and can now access the
\r
498 // shared resource.
\r
501 // For some reason due to the nature of the code further calls to
\r
502 // xSemaphoreTakeRecursive() are made on the same mutex. In real
\r
503 // code these would not be just sequential calls as this would make
\r
504 // no sense. Instead the calls are likely to be buried inside
\r
505 // a more complex call structure.
\r
506 xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
\r
507 xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
\r
509 // The mutex has now been 'taken' three times, so will not be
\r
510 // available to another task until it has also been given back
\r
511 // three times. Again it is unlikely that real code would have
\r
512 // these calls sequentially, it would be more likely that the calls
\r
513 // to xSemaphoreGiveRecursive() would be called as a call stack
\r
514 // unwound. This is just for demonstrative purposes.
\r
515 xSemaphoreGiveRecursive( xMutex );
\r
516 xSemaphoreGiveRecursive( xMutex );
\r
517 xSemaphoreGiveRecursive( xMutex );
\r
519 // Now the mutex can be taken by other tasks.
\r
523 // We could not obtain the mutex and can therefore not access
\r
524 // the shared resource safely.
\r
529 * \defgroup xSemaphoreGiveRecursive xSemaphoreGiveRecursive
\r
530 * \ingroup Semaphores
\r
532 #if( configUSE_RECURSIVE_MUTEXES == 1 )
\r
533 #define xSemaphoreGiveRecursive( xMutex ) xQueueGiveMutexRecursive( ( xMutex ) )
\r
539 xSemaphoreGiveFromISR(
\r
540 SemaphoreHandle_t xSemaphore,
\r
541 BaseType_t *pxHigherPriorityTaskWoken
\r
544 * <i>Macro</i> to release a semaphore. The semaphore must have previously been
\r
545 * created with a call to xSemaphoreCreateBinary() or xSemaphoreCreateCounting().
\r
547 * Mutex type semaphores (those created using a call to xSemaphoreCreateMutex())
\r
548 * must not be used with this macro.
\r
550 * This macro can be used from an ISR.
\r
552 * @param xSemaphore A handle to the semaphore being released. This is the
\r
553 * handle returned when the semaphore was created.
\r
555 * @param pxHigherPriorityTaskWoken xSemaphoreGiveFromISR() will set
\r
556 * *pxHigherPriorityTaskWoken to pdTRUE if giving the semaphore caused a task
\r
557 * to unblock, and the unblocked task has a priority higher than the currently
\r
558 * running task. If xSemaphoreGiveFromISR() sets this value to pdTRUE then
\r
559 * a context switch should be requested before the interrupt is exited.
\r
561 * @return pdTRUE if the semaphore was successfully given, otherwise errQUEUE_FULL.
\r
565 \#define LONG_TIME 0xffff
\r
566 \#define TICKS_TO_WAIT 10
\r
567 SemaphoreHandle_t xSemaphore = NULL;
\r
569 // Repetitive task.
\r
570 void vATask( void * pvParameters )
\r
574 // We want this task to run every 10 ticks of a timer. The semaphore
\r
575 // was created before this task was started.
\r
577 // Block waiting for the semaphore to become available.
\r
578 if( xSemaphoreTake( xSemaphore, LONG_TIME ) == pdTRUE )
\r
580 // It is time to execute.
\r
584 // We have finished our task. Return to the top of the loop where
\r
585 // we will block on the semaphore until it is time to execute
\r
586 // again. Note when using the semaphore for synchronisation with an
\r
587 // ISR in this manner there is no need to 'give' the semaphore back.
\r
593 void vTimerISR( void * pvParameters )
\r
595 static uint8_t ucLocalTickCount = 0;
\r
596 static BaseType_t xHigherPriorityTaskWoken;
\r
598 // A timer tick has occurred.
\r
600 // ... Do other time functions.
\r
602 // Is it time for vATask () to run?
\r
603 xHigherPriorityTaskWoken = pdFALSE;
\r
604 ucLocalTickCount++;
\r
605 if( ucLocalTickCount >= TICKS_TO_WAIT )
\r
607 // Unblock the task by releasing the semaphore.
\r
608 xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );
\r
610 // Reset the count so we release the semaphore again in 10 ticks time.
\r
611 ucLocalTickCount = 0;
\r
614 if( xHigherPriorityTaskWoken != pdFALSE )
\r
616 // We can force a context switch here. Context switching from an
\r
617 // ISR uses port specific syntax. Check the demo task for your port
\r
618 // to find the syntax required.
\r
622 * \defgroup xSemaphoreGiveFromISR xSemaphoreGiveFromISR
\r
623 * \ingroup Semaphores
\r
625 #define xSemaphoreGiveFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueGiveFromISR( ( QueueHandle_t ) ( xSemaphore ), ( pxHigherPriorityTaskWoken ) )
\r
630 xSemaphoreTakeFromISR(
\r
631 SemaphoreHandle_t xSemaphore,
\r
632 BaseType_t *pxHigherPriorityTaskWoken
\r
635 * <i>Macro</i> to take a semaphore from an ISR. The semaphore must have
\r
636 * previously been created with a call to xSemaphoreCreateBinary() or
\r
637 * xSemaphoreCreateCounting().
\r
639 * Mutex type semaphores (those created using a call to xSemaphoreCreateMutex())
\r
640 * must not be used with this macro.
\r
642 * This macro can be used from an ISR, however taking a semaphore from an ISR
\r
643 * is not a common operation. It is likely to only be useful when taking a
\r
644 * counting semaphore when an interrupt is obtaining an object from a resource
\r
645 * pool (when the semaphore count indicates the number of resources available).
\r
647 * @param xSemaphore A handle to the semaphore being taken. This is the
\r
648 * handle returned when the semaphore was created.
\r
650 * @param pxHigherPriorityTaskWoken xSemaphoreTakeFromISR() will set
\r
651 * *pxHigherPriorityTaskWoken to pdTRUE if taking the semaphore caused a task
\r
652 * to unblock, and the unblocked task has a priority higher than the currently
\r
653 * running task. If xSemaphoreTakeFromISR() sets this value to pdTRUE then
\r
654 * a context switch should be requested before the interrupt is exited.
\r
656 * @return pdTRUE if the semaphore was successfully taken, otherwise
\r
659 #define xSemaphoreTakeFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueReceiveFromISR( ( QueueHandle_t ) ( xSemaphore ), NULL, ( pxHigherPriorityTaskWoken ) )
\r
663 * <pre>SemaphoreHandle_t xSemaphoreCreateMutex( void )</pre>
\r
665 * Creates a new mutex type semaphore instance, and returns a handle by which
\r
666 * the new mutex can be referenced.
\r
668 * Internally, within the FreeRTOS implementation, mutex semaphores use a block
\r
669 * of memory, in which the mutex structure is stored. If a mutex is created
\r
670 * using xSemaphoreCreateMutex() then the required memory is automatically
\r
671 * dynamically allocated inside the xSemaphoreCreateMutex() function. (see
\r
672 * http://www.freertos.org/a00111.html). If a mutex is created using
\r
673 * xSemaphoreCreateMutexStatic() then the application writer must provided the
\r
674 * memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to be created
\r
675 * without using any dynamic memory allocation.
\r
677 * Mutexes created using this function can be accessed using the xSemaphoreTake()
\r
678 * and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and
\r
679 * xSemaphoreGiveRecursive() macros must not be used.
\r
681 * This type of semaphore uses a priority inheritance mechanism so a task
\r
682 * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
\r
683 * semaphore it is no longer required.
\r
685 * Mutex type semaphores cannot be used from within interrupt service routines.
\r
687 * See xSemaphoreCreateBinary() for an alternative implementation that can be
\r
688 * used for pure synchronisation (where one task or interrupt always 'gives' the
\r
689 * semaphore and another always 'takes' the semaphore) and from within interrupt
\r
690 * service routines.
\r
692 * @return If the mutex was successfully created then a handle to the created
\r
693 * semaphore is returned. If there was not enough heap to allocate the mutex
\r
694 * data structures then NULL is returned.
\r
698 SemaphoreHandle_t xSemaphore;
\r
700 void vATask( void * pvParameters )
\r
702 // Semaphore cannot be used before a call to xSemaphoreCreateMutex().
\r
703 // This is a macro so pass the variable in directly.
\r
704 xSemaphore = xSemaphoreCreateMutex();
\r
706 if( xSemaphore != NULL )
\r
708 // The semaphore was created successfully.
\r
709 // The semaphore can now be used.
\r
713 * \defgroup xSemaphoreCreateMutex xSemaphoreCreateMutex
\r
714 * \ingroup Semaphores
\r
716 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
717 #define xSemaphoreCreateMutex() xQueueCreateMutex( queueQUEUE_TYPE_MUTEX )
\r
722 * <pre>SemaphoreHandle_t xSemaphoreCreateMutexStatic( StaticSemaphore_t *pxMutexBuffer )</pre>
\r
724 * Creates a new mutex type semaphore instance, and returns a handle by which
\r
725 * the new mutex can be referenced.
\r
727 * Internally, within the FreeRTOS implementation, mutex semaphores use a block
\r
728 * of memory, in which the mutex structure is stored. If a mutex is created
\r
729 * using xSemaphoreCreateMutex() then the required memory is automatically
\r
730 * dynamically allocated inside the xSemaphoreCreateMutex() function. (see
\r
731 * http://www.freertos.org/a00111.html). If a mutex is created using
\r
732 * xSemaphoreCreateMutexStatic() then the application writer must provided the
\r
733 * memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to be created
\r
734 * without using any dynamic memory allocation.
\r
736 * Mutexes created using this function can be accessed using the xSemaphoreTake()
\r
737 * and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and
\r
738 * xSemaphoreGiveRecursive() macros must not be used.
\r
740 * This type of semaphore uses a priority inheritance mechanism so a task
\r
741 * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
\r
742 * semaphore it is no longer required.
\r
744 * Mutex type semaphores cannot be used from within interrupt service routines.
\r
746 * See xSemaphoreCreateBinary() for an alternative implementation that can be
\r
747 * used for pure synchronisation (where one task or interrupt always 'gives' the
\r
748 * semaphore and another always 'takes' the semaphore) and from within interrupt
\r
749 * service routines.
\r
751 * @param pxMutexBuffer Must point to a variable of type StaticSemaphore_t,
\r
752 * which will be used to hold the mutex's data structure, removing the need for
\r
753 * the memory to be allocated dynamically.
\r
755 * @return If the mutex was successfully created then a handle to the created
\r
756 * mutex is returned. If pxMutexBuffer was NULL then NULL is returned.
\r
760 SemaphoreHandle_t xSemaphore;
\r
761 StaticSemaphore_t xMutexBuffer;
\r
763 void vATask( void * pvParameters )
\r
765 // A mutex cannot be used before it has been created. xMutexBuffer is
\r
766 // into xSemaphoreCreateMutexStatic() so no dynamic memory allocation is
\r
768 xSemaphore = xSemaphoreCreateMutexStatic( &xMutexBuffer );
\r
770 // As no dynamic memory allocation was performed, xSemaphore cannot be NULL,
\r
771 // so there is no need to check it.
\r
774 * \defgroup xSemaphoreCreateMutexStatic xSemaphoreCreateMutexStatic
\r
775 * \ingroup Semaphores
\r
777 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
778 #define xSemaphoreCreateMutexStatic( pxMutexBuffer ) xQueueCreateMutexStatic( queueQUEUE_TYPE_MUTEX, ( pxMutexBuffer ) )
\r
779 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
784 * <pre>SemaphoreHandle_t xSemaphoreCreateRecursiveMutex( void )</pre>
\r
786 * Creates a new recursive mutex type semaphore instance, and returns a handle
\r
787 * by which the new recursive mutex can be referenced.
\r
789 * Internally, within the FreeRTOS implementation, recursive mutexs use a block
\r
790 * of memory, in which the mutex structure is stored. If a recursive mutex is
\r
791 * created using xSemaphoreCreateRecursiveMutex() then the required memory is
\r
792 * automatically dynamically allocated inside the
\r
793 * xSemaphoreCreateRecursiveMutex() function. (see
\r
794 * http://www.freertos.org/a00111.html). If a recursive mutex is created using
\r
795 * xSemaphoreCreateRecursiveMutexStatic() then the application writer must
\r
796 * provide the memory that will get used by the mutex.
\r
797 * xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to
\r
798 * be created without using any dynamic memory allocation.
\r
800 * Mutexes created using this macro can be accessed using the
\r
801 * xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The
\r
802 * xSemaphoreTake() and xSemaphoreGive() macros must not be used.
\r
804 * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
\r
805 * doesn't become available again until the owner has called
\r
806 * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
\r
807 * if a task successfully 'takes' the same mutex 5 times then the mutex will
\r
808 * not be available to any other task until it has also 'given' the mutex back
\r
809 * exactly five times.
\r
811 * This type of semaphore uses a priority inheritance mechanism so a task
\r
812 * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
\r
813 * semaphore it is no longer required.
\r
815 * Mutex type semaphores cannot be used from within interrupt service routines.
\r
817 * See xSemaphoreCreateBinary() for an alternative implementation that can be
\r
818 * used for pure synchronisation (where one task or interrupt always 'gives' the
\r
819 * semaphore and another always 'takes' the semaphore) and from within interrupt
\r
820 * service routines.
\r
822 * @return xSemaphore Handle to the created mutex semaphore. Should be of type
\r
823 * SemaphoreHandle_t.
\r
827 SemaphoreHandle_t xSemaphore;
\r
829 void vATask( void * pvParameters )
\r
831 // Semaphore cannot be used before a call to xSemaphoreCreateMutex().
\r
832 // This is a macro so pass the variable in directly.
\r
833 xSemaphore = xSemaphoreCreateRecursiveMutex();
\r
835 if( xSemaphore != NULL )
\r
837 // The semaphore was created successfully.
\r
838 // The semaphore can now be used.
\r
842 * \defgroup xSemaphoreCreateRecursiveMutex xSemaphoreCreateRecursiveMutex
\r
843 * \ingroup Semaphores
\r
845 #if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_RECURSIVE_MUTEXES == 1 ) )
\r
846 #define xSemaphoreCreateRecursiveMutex() xQueueCreateMutex( queueQUEUE_TYPE_RECURSIVE_MUTEX )
\r
851 * <pre>SemaphoreHandle_t xSemaphoreCreateRecursiveMutexStatic( StaticSemaphore_t *pxMutexBuffer )</pre>
\r
853 * Creates a new recursive mutex type semaphore instance, and returns a handle
\r
854 * by which the new recursive mutex can be referenced.
\r
856 * Internally, within the FreeRTOS implementation, recursive mutexs use a block
\r
857 * of memory, in which the mutex structure is stored. If a recursive mutex is
\r
858 * created using xSemaphoreCreateRecursiveMutex() then the required memory is
\r
859 * automatically dynamically allocated inside the
\r
860 * xSemaphoreCreateRecursiveMutex() function. (see
\r
861 * http://www.freertos.org/a00111.html). If a recursive mutex is created using
\r
862 * xSemaphoreCreateRecursiveMutexStatic() then the application writer must
\r
863 * provide the memory that will get used by the mutex.
\r
864 * xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to
\r
865 * be created without using any dynamic memory allocation.
\r
867 * Mutexes created using this macro can be accessed using the
\r
868 * xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The
\r
869 * xSemaphoreTake() and xSemaphoreGive() macros must not be used.
\r
871 * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
\r
872 * doesn't become available again until the owner has called
\r
873 * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
\r
874 * if a task successfully 'takes' the same mutex 5 times then the mutex will
\r
875 * not be available to any other task until it has also 'given' the mutex back
\r
876 * exactly five times.
\r
878 * This type of semaphore uses a priority inheritance mechanism so a task
\r
879 * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
\r
880 * semaphore it is no longer required.
\r
882 * Mutex type semaphores cannot be used from within interrupt service routines.
\r
884 * See xSemaphoreCreateBinary() for an alternative implementation that can be
\r
885 * used for pure synchronisation (where one task or interrupt always 'gives' the
\r
886 * semaphore and another always 'takes' the semaphore) and from within interrupt
\r
887 * service routines.
\r
889 * @param pxMutexBuffer Must point to a variable of type StaticSemaphore_t,
\r
890 * which will then be used to hold the recursive mutex's data structure,
\r
891 * removing the need for the memory to be allocated dynamically.
\r
893 * @return If the recursive mutex was successfully created then a handle to the
\r
894 * created recursive mutex is returned. If pxMutexBuffer was NULL then NULL is
\r
899 SemaphoreHandle_t xSemaphore;
\r
900 StaticSemaphore_t xMutexBuffer;
\r
902 void vATask( void * pvParameters )
\r
904 // A recursive semaphore cannot be used before it is created. Here a
\r
905 // recursive mutex is created using xSemaphoreCreateRecursiveMutexStatic().
\r
906 // The address of xMutexBuffer is passed into the function, and will hold
\r
907 // the mutexes data structures - so no dynamic memory allocation will be
\r
909 xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xMutexBuffer );
\r
911 // As no dynamic memory allocation was performed, xSemaphore cannot be NULL,
\r
912 // so there is no need to check it.
\r
915 * \defgroup xSemaphoreCreateRecursiveMutexStatic xSemaphoreCreateRecursiveMutexStatic
\r
916 * \ingroup Semaphores
\r
918 #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_RECURSIVE_MUTEXES == 1 ) )
\r
919 #define xSemaphoreCreateRecursiveMutexStatic( pxStaticSemaphore ) xQueueCreateMutexStatic( queueQUEUE_TYPE_RECURSIVE_MUTEX, pxStaticSemaphore )
\r
920 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
924 * <pre>SemaphoreHandle_t xSemaphoreCreateCounting( UBaseType_t uxMaxCount, UBaseType_t uxInitialCount )</pre>
\r
926 * Creates a new counting semaphore instance, and returns a handle by which the
\r
927 * new counting semaphore can be referenced.
\r
929 * In many usage scenarios it is faster and more memory efficient to use a
\r
930 * direct to task notification in place of a counting semaphore!
\r
931 * http://www.freertos.org/RTOS-task-notifications.html
\r
933 * Internally, within the FreeRTOS implementation, counting semaphores use a
\r
934 * block of memory, in which the counting semaphore structure is stored. If a
\r
935 * counting semaphore is created using xSemaphoreCreateCounting() then the
\r
936 * required memory is automatically dynamically allocated inside the
\r
937 * xSemaphoreCreateCounting() function. (see
\r
938 * http://www.freertos.org/a00111.html). If a counting semaphore is created
\r
939 * using xSemaphoreCreateCountingStatic() then the application writer can
\r
940 * instead optionally provide the memory that will get used by the counting
\r
941 * semaphore. xSemaphoreCreateCountingStatic() therefore allows a counting
\r
942 * semaphore to be created without using any dynamic memory allocation.
\r
944 * Counting semaphores are typically used for two things:
\r
946 * 1) Counting events.
\r
948 * In this usage scenario an event handler will 'give' a semaphore each time
\r
949 * an event occurs (incrementing the semaphore count value), and a handler
\r
950 * task will 'take' a semaphore each time it processes an event
\r
951 * (decrementing the semaphore count value). The count value is therefore
\r
952 * the difference between the number of events that have occurred and the
\r
953 * number that have been processed. In this case it is desirable for the
\r
954 * initial count value to be zero.
\r
956 * 2) Resource management.
\r
958 * In this usage scenario the count value indicates the number of resources
\r
959 * available. To obtain control of a resource a task must first obtain a
\r
960 * semaphore - decrementing the semaphore count value. When the count value
\r
961 * reaches zero there are no free resources. When a task finishes with the
\r
962 * resource it 'gives' the semaphore back - incrementing the semaphore count
\r
963 * value. In this case it is desirable for the initial count value to be
\r
964 * equal to the maximum count value, indicating that all resources are free.
\r
966 * @param uxMaxCount The maximum count value that can be reached. When the
\r
967 * semaphore reaches this value it can no longer be 'given'.
\r
969 * @param uxInitialCount The count value assigned to the semaphore when it is
\r
972 * @return Handle to the created semaphore. Null if the semaphore could not be
\r
977 SemaphoreHandle_t xSemaphore;
\r
979 void vATask( void * pvParameters )
\r
981 SemaphoreHandle_t xSemaphore = NULL;
\r
983 // Semaphore cannot be used before a call to xSemaphoreCreateCounting().
\r
984 // The max value to which the semaphore can count should be 10, and the
\r
985 // initial value assigned to the count should be 0.
\r
986 xSemaphore = xSemaphoreCreateCounting( 10, 0 );
\r
988 if( xSemaphore != NULL )
\r
990 // The semaphore was created successfully.
\r
991 // The semaphore can now be used.
\r
995 * \defgroup xSemaphoreCreateCounting xSemaphoreCreateCounting
\r
996 * \ingroup Semaphores
\r
998 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
999 #define xSemaphoreCreateCounting( uxMaxCount, uxInitialCount ) xQueueCreateCountingSemaphore( ( uxMaxCount ), ( uxInitialCount ) )
\r
1004 * <pre>SemaphoreHandle_t xSemaphoreCreateCountingStatic( UBaseType_t uxMaxCount, UBaseType_t uxInitialCount, StaticSemaphore_t *pxSemaphoreBuffer )</pre>
\r
1006 * Creates a new counting semaphore instance, and returns a handle by which the
\r
1007 * new counting semaphore can be referenced.
\r
1009 * In many usage scenarios it is faster and more memory efficient to use a
\r
1010 * direct to task notification in place of a counting semaphore!
\r
1011 * http://www.freertos.org/RTOS-task-notifications.html
\r
1013 * Internally, within the FreeRTOS implementation, counting semaphores use a
\r
1014 * block of memory, in which the counting semaphore structure is stored. If a
\r
1015 * counting semaphore is created using xSemaphoreCreateCounting() then the
\r
1016 * required memory is automatically dynamically allocated inside the
\r
1017 * xSemaphoreCreateCounting() function. (see
\r
1018 * http://www.freertos.org/a00111.html). If a counting semaphore is created
\r
1019 * using xSemaphoreCreateCountingStatic() then the application writer must
\r
1020 * provide the memory. xSemaphoreCreateCountingStatic() therefore allows a
\r
1021 * counting semaphore to be created without using any dynamic memory allocation.
\r
1023 * Counting semaphores are typically used for two things:
\r
1025 * 1) Counting events.
\r
1027 * In this usage scenario an event handler will 'give' a semaphore each time
\r
1028 * an event occurs (incrementing the semaphore count value), and a handler
\r
1029 * task will 'take' a semaphore each time it processes an event
\r
1030 * (decrementing the semaphore count value). The count value is therefore
\r
1031 * the difference between the number of events that have occurred and the
\r
1032 * number that have been processed. In this case it is desirable for the
\r
1033 * initial count value to be zero.
\r
1035 * 2) Resource management.
\r
1037 * In this usage scenario the count value indicates the number of resources
\r
1038 * available. To obtain control of a resource a task must first obtain a
\r
1039 * semaphore - decrementing the semaphore count value. When the count value
\r
1040 * reaches zero there are no free resources. When a task finishes with the
\r
1041 * resource it 'gives' the semaphore back - incrementing the semaphore count
\r
1042 * value. In this case it is desirable for the initial count value to be
\r
1043 * equal to the maximum count value, indicating that all resources are free.
\r
1045 * @param uxMaxCount The maximum count value that can be reached. When the
\r
1046 * semaphore reaches this value it can no longer be 'given'.
\r
1048 * @param uxInitialCount The count value assigned to the semaphore when it is
\r
1051 * @param pxSemaphoreBuffer Must point to a variable of type StaticSemaphore_t,
\r
1052 * which will then be used to hold the semaphore's data structure, removing the
\r
1053 * need for the memory to be allocated dynamically.
\r
1055 * @return If the counting semaphore was successfully created then a handle to
\r
1056 * the created counting semaphore is returned. If pxSemaphoreBuffer was NULL
\r
1057 * then NULL is returned.
\r
1061 SemaphoreHandle_t xSemaphore;
\r
1062 StaticSemaphore_t xSemaphoreBuffer;
\r
1064 void vATask( void * pvParameters )
\r
1066 SemaphoreHandle_t xSemaphore = NULL;
\r
1068 // Counting semaphore cannot be used before they have been created. Create
\r
1069 // a counting semaphore using xSemaphoreCreateCountingStatic(). The max
\r
1070 // value to which the semaphore can count is 10, and the initial value
\r
1071 // assigned to the count will be 0. The address of xSemaphoreBuffer is
\r
1072 // passed in and will be used to hold the semaphore structure, so no dynamic
\r
1073 // memory allocation will be used.
\r
1074 xSemaphore = xSemaphoreCreateCounting( 10, 0, &xSemaphoreBuffer );
\r
1076 // No memory allocation was attempted so xSemaphore cannot be NULL, so there
\r
1077 // is no need to check its value.
\r
1080 * \defgroup xSemaphoreCreateCountingStatic xSemaphoreCreateCountingStatic
\r
1081 * \ingroup Semaphores
\r
1083 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
1084 #define xSemaphoreCreateCountingStatic( uxMaxCount, uxInitialCount, pxSemaphoreBuffer ) xQueueCreateCountingSemaphoreStatic( ( uxMaxCount ), ( uxInitialCount ), ( pxSemaphoreBuffer ) )
\r
1085 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
1089 * <pre>void vSemaphoreDelete( SemaphoreHandle_t xSemaphore );</pre>
\r
1091 * Delete a semaphore. This function must be used with care. For example,
\r
1092 * do not delete a mutex type semaphore if the mutex is held by a task.
\r
1094 * @param xSemaphore A handle to the semaphore to be deleted.
\r
1096 * \defgroup vSemaphoreDelete vSemaphoreDelete
\r
1097 * \ingroup Semaphores
\r
1099 #define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( QueueHandle_t ) ( xSemaphore ) )
\r
1103 * <pre>TaskHandle_t xSemaphoreGetMutexHolder( SemaphoreHandle_t xMutex );</pre>
\r
1105 * If xMutex is indeed a mutex type semaphore, return the current mutex holder.
\r
1106 * If xMutex is not a mutex type semaphore, or the mutex is available (not held
\r
1107 * by a task), return NULL.
\r
1109 * Note: This is a good way of determining if the calling task is the mutex
\r
1110 * holder, but not a good way of determining the identity of the mutex holder as
\r
1111 * the holder may change between the function exiting and the returned value
\r
1114 #define xSemaphoreGetMutexHolder( xSemaphore ) xQueueGetMutexHolder( ( xSemaphore ) )
\r
1118 * <pre>TaskHandle_t xSemaphoreGetMutexHolderFromISR( SemaphoreHandle_t xMutex );</pre>
\r
1120 * If xMutex is indeed a mutex type semaphore, return the current mutex holder.
\r
1121 * If xMutex is not a mutex type semaphore, or the mutex is available (not held
\r
1122 * by a task), return NULL.
\r
1125 #define xSemaphoreGetMutexHolderFromISR( xSemaphore ) xQueueGetMutexHolderFromISR( ( xSemaphore ) )
\r
1129 * <pre>UBaseType_t uxSemaphoreGetCount( SemaphoreHandle_t xSemaphore );</pre>
\r
1131 * If the semaphore is a counting semaphore then uxSemaphoreGetCount() returns
\r
1132 * its current count value. If the semaphore is a binary semaphore then
\r
1133 * uxSemaphoreGetCount() returns 1 if the semaphore is available, and 0 if the
\r
1134 * semaphore is not available.
\r
1137 #define uxSemaphoreGetCount( xSemaphore ) uxQueueMessagesWaiting( ( QueueHandle_t ) ( xSemaphore ) )
\r
1139 #endif /* SEMAPHORE_H */
\r