2 * FreeRTOS Kernel V10.3.0
\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
25 * 1 tab == 4 spaces!
\r
31 #ifndef INC_FREERTOS_H
\r
32 #error "include FreeRTOS.h" must appear in source files before "include semphr.h"
\r
37 typedef QueueHandle_t SemaphoreHandle_t;
\r
39 #define semBINARY_SEMAPHORE_QUEUE_LENGTH ( ( uint8_t ) 1U )
\r
40 #define semSEMAPHORE_QUEUE_ITEM_LENGTH ( ( uint8_t ) 0U )
\r
41 #define semGIVE_BLOCK_TIME ( ( TickType_t ) 0U )
\r
46 * <pre>vSemaphoreCreateBinary( SemaphoreHandle_t xSemaphore )</pre>
\r
48 * In many usage scenarios it is faster and more memory efficient to use a
\r
49 * direct to task notification in place of a binary semaphore!
\r
50 * http://www.freertos.org/RTOS-task-notifications.html
\r
52 * This old vSemaphoreCreateBinary() macro is now deprecated in favour of the
\r
53 * xSemaphoreCreateBinary() function. Note that binary semaphores created using
\r
54 * the vSemaphoreCreateBinary() macro are created in a state such that the
\r
55 * first call to 'take' the semaphore would pass, whereas binary semaphores
\r
56 * created using xSemaphoreCreateBinary() are created in a state such that the
\r
57 * the semaphore must first be 'given' before it can be 'taken'.
\r
59 * <i>Macro</i> that implements a semaphore by using the existing queue mechanism.
\r
60 * The queue length is 1 as this is a binary semaphore. The data size is 0
\r
61 * as we don't want to actually store any data - we just want to know if the
\r
62 * queue is empty or full.
\r
64 * This type of semaphore can be used for pure synchronisation between tasks or
\r
65 * between an interrupt and a task. The semaphore need not be given back once
\r
66 * obtained, so one task/interrupt can continuously 'give' the semaphore while
\r
67 * another continuously 'takes' the semaphore. For this reason this type of
\r
68 * semaphore does not use a priority inheritance mechanism. For an alternative
\r
69 * that does use priority inheritance see xSemaphoreCreateMutex().
\r
71 * @param xSemaphore Handle to the created semaphore. Should be of type SemaphoreHandle_t.
\r
75 SemaphoreHandle_t xSemaphore = NULL;
\r
77 void vATask( void * pvParameters )
\r
79 // Semaphore cannot be used before a call to vSemaphoreCreateBinary ().
\r
80 // This is a macro so pass the variable in directly.
\r
81 vSemaphoreCreateBinary( xSemaphore );
\r
83 if( xSemaphore != NULL )
\r
85 // The semaphore was created successfully.
\r
86 // The semaphore can now be used.
\r
90 * \defgroup vSemaphoreCreateBinary vSemaphoreCreateBinary
\r
91 * \ingroup Semaphores
\r
93 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
94 #define vSemaphoreCreateBinary( xSemaphore ) \
\r
96 ( xSemaphore ) = xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE ); \
\r
97 if( ( xSemaphore ) != NULL ) \
\r
99 ( void ) xSemaphoreGive( ( xSemaphore ) ); \
\r
106 * <pre>SemaphoreHandle_t xSemaphoreCreateBinary( void )</pre>
\r
108 * Creates a new binary semaphore instance, and returns a handle by which the
\r
109 * new semaphore can be referenced.
\r
111 * In many usage scenarios it is faster and more memory efficient to use a
\r
112 * direct to task notification in place of a binary semaphore!
\r
113 * http://www.freertos.org/RTOS-task-notifications.html
\r
115 * Internally, within the FreeRTOS implementation, binary semaphores use a block
\r
116 * of memory, in which the semaphore structure is stored. If a binary semaphore
\r
117 * is created using xSemaphoreCreateBinary() then the required memory is
\r
118 * automatically dynamically allocated inside the xSemaphoreCreateBinary()
\r
119 * function. (see http://www.freertos.org/a00111.html). If a binary semaphore
\r
120 * is created using xSemaphoreCreateBinaryStatic() then the application writer
\r
121 * must provide the memory. xSemaphoreCreateBinaryStatic() therefore allows a
\r
122 * binary semaphore to be created without using any dynamic memory allocation.
\r
124 * The old vSemaphoreCreateBinary() macro is now deprecated in favour of this
\r
125 * xSemaphoreCreateBinary() function. Note that binary semaphores created using
\r
126 * the vSemaphoreCreateBinary() macro are created in a state such that the
\r
127 * first call to 'take' the semaphore would pass, whereas binary semaphores
\r
128 * created using xSemaphoreCreateBinary() are created in a state such that the
\r
129 * the semaphore must first be 'given' before it can be 'taken'.
\r
131 * This type of semaphore can be used for pure synchronisation between tasks or
\r
132 * between an interrupt and a task. The semaphore need not be given back once
\r
133 * obtained, so one task/interrupt can continuously 'give' the semaphore while
\r
134 * another continuously 'takes' the semaphore. For this reason this type of
\r
135 * semaphore does not use a priority inheritance mechanism. For an alternative
\r
136 * that does use priority inheritance see xSemaphoreCreateMutex().
\r
138 * @return Handle to the created semaphore, or NULL if the memory required to
\r
139 * hold the semaphore's data structures could not be allocated.
\r
143 SemaphoreHandle_t xSemaphore = NULL;
\r
145 void vATask( void * pvParameters )
\r
147 // Semaphore cannot be used before a call to xSemaphoreCreateBinary().
\r
148 // This is a macro so pass the variable in directly.
\r
149 xSemaphore = xSemaphoreCreateBinary();
\r
151 if( xSemaphore != NULL )
\r
153 // The semaphore was created successfully.
\r
154 // The semaphore can now be used.
\r
158 * \defgroup xSemaphoreCreateBinary xSemaphoreCreateBinary
\r
159 * \ingroup Semaphores
\r
161 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
162 #define xSemaphoreCreateBinary() xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE )
\r
167 * <pre>SemaphoreHandle_t xSemaphoreCreateBinaryStatic( StaticSemaphore_t *pxSemaphoreBuffer )</pre>
\r
169 * Creates a new binary semaphore instance, and returns a handle by which the
\r
170 * new semaphore can be referenced.
\r
172 * NOTE: In many usage scenarios it is faster and more memory efficient to use a
\r
173 * direct to task notification in place of a binary semaphore!
\r
174 * http://www.freertos.org/RTOS-task-notifications.html
\r
176 * Internally, within the FreeRTOS implementation, binary semaphores use a block
\r
177 * of memory, in which the semaphore structure is stored. If a binary semaphore
\r
178 * is created using xSemaphoreCreateBinary() then the required memory is
\r
179 * automatically dynamically allocated inside the xSemaphoreCreateBinary()
\r
180 * function. (see http://www.freertos.org/a00111.html). If a binary semaphore
\r
181 * is created using xSemaphoreCreateBinaryStatic() then the application writer
\r
182 * must provide the memory. xSemaphoreCreateBinaryStatic() therefore allows a
\r
183 * binary semaphore to be created without using any dynamic memory allocation.
\r
185 * This type of semaphore can be used for pure synchronisation between tasks or
\r
186 * between an interrupt and a task. The semaphore need not be given back once
\r
187 * obtained, so one task/interrupt can continuously 'give' the semaphore while
\r
188 * another continuously 'takes' the semaphore. For this reason this type of
\r
189 * semaphore does not use a priority inheritance mechanism. For an alternative
\r
190 * that does use priority inheritance see xSemaphoreCreateMutex().
\r
192 * @param pxSemaphoreBuffer Must point to a variable of type StaticSemaphore_t,
\r
193 * which will then be used to hold the semaphore's data structure, removing the
\r
194 * need for the memory to be allocated dynamically.
\r
196 * @return If the semaphore is created then a handle to the created semaphore is
\r
197 * returned. If pxSemaphoreBuffer is NULL then NULL is returned.
\r
201 SemaphoreHandle_t xSemaphore = NULL;
\r
202 StaticSemaphore_t xSemaphoreBuffer;
\r
204 void vATask( void * pvParameters )
\r
206 // Semaphore cannot be used before a call to xSemaphoreCreateBinary().
\r
207 // The semaphore's data structures will be placed in the xSemaphoreBuffer
\r
208 // variable, the address of which is passed into the function. The
\r
209 // function's parameter is not NULL, so the function will not attempt any
\r
210 // dynamic memory allocation, and therefore the function will not return
\r
212 xSemaphore = xSemaphoreCreateBinary( &xSemaphoreBuffer );
\r
214 // Rest of task code goes here.
\r
217 * \defgroup xSemaphoreCreateBinaryStatic xSemaphoreCreateBinaryStatic
\r
218 * \ingroup Semaphores
\r
220 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
221 #define xSemaphoreCreateBinaryStatic( pxStaticSemaphore ) xQueueGenericCreateStatic( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticSemaphore, queueQUEUE_TYPE_BINARY_SEMAPHORE )
\r
222 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
226 * <pre>xSemaphoreTake(
\r
227 * SemaphoreHandle_t xSemaphore,
\r
228 * TickType_t xBlockTime
\r
231 * <i>Macro</i> to obtain a semaphore. The semaphore must have previously been
\r
232 * created with a call to xSemaphoreCreateBinary(), xSemaphoreCreateMutex() or
\r
233 * xSemaphoreCreateCounting().
\r
235 * @param xSemaphore A handle to the semaphore being taken - obtained when
\r
236 * the semaphore was created.
\r
238 * @param xBlockTime The time in ticks to wait for the semaphore to become
\r
239 * available. The macro portTICK_PERIOD_MS can be used to convert this to a
\r
240 * real time. A block time of zero can be used to poll the semaphore. A block
\r
241 * time of portMAX_DELAY can be used to block indefinitely (provided
\r
242 * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h).
\r
244 * @return pdTRUE if the semaphore was obtained. pdFALSE
\r
245 * if xBlockTime expired without the semaphore becoming available.
\r
249 SemaphoreHandle_t xSemaphore = NULL;
\r
251 // A task that creates a semaphore.
\r
252 void vATask( void * pvParameters )
\r
254 // Create the semaphore to guard a shared resource.
\r
255 xSemaphore = xSemaphoreCreateBinary();
\r
258 // A task that uses the semaphore.
\r
259 void vAnotherTask( void * pvParameters )
\r
261 // ... Do other things.
\r
263 if( xSemaphore != NULL )
\r
265 // See if we can obtain the semaphore. If the semaphore is not available
\r
266 // wait 10 ticks to see if it becomes free.
\r
267 if( xSemaphoreTake( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
\r
269 // We were able to obtain the semaphore and can now access the
\r
270 // shared resource.
\r
274 // We have finished accessing the shared resource. Release the
\r
276 xSemaphoreGive( xSemaphore );
\r
280 // We could not obtain the semaphore and can therefore not access
\r
281 // the shared resource safely.
\r
286 * \defgroup xSemaphoreTake xSemaphoreTake
\r
287 * \ingroup Semaphores
\r
289 #define xSemaphoreTake( xSemaphore, xBlockTime ) xQueueSemaphoreTake( ( xSemaphore ), ( xBlockTime ) )
\r
293 * xSemaphoreTakeRecursive(
\r
294 * SemaphoreHandle_t xMutex,
\r
295 * TickType_t xBlockTime
\r
298 * <i>Macro</i> to recursively obtain, or 'take', a mutex type semaphore.
\r
299 * The mutex must have previously been created using a call to
\r
300 * xSemaphoreCreateRecursiveMutex();
\r
302 * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this
\r
303 * macro to be available.
\r
305 * This macro must not be used on mutexes created using xSemaphoreCreateMutex().
\r
307 * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
\r
308 * doesn't become available again until the owner has called
\r
309 * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
\r
310 * if a task successfully 'takes' the same mutex 5 times then the mutex will
\r
311 * not be available to any other task until it has also 'given' the mutex back
\r
312 * exactly five times.
\r
314 * @param xMutex A handle to the mutex being obtained. This is the
\r
315 * handle returned by xSemaphoreCreateRecursiveMutex();
\r
317 * @param xBlockTime The time in ticks to wait for the semaphore to become
\r
318 * available. The macro portTICK_PERIOD_MS can be used to convert this to a
\r
319 * real time. A block time of zero can be used to poll the semaphore. If
\r
320 * the task already owns the semaphore then xSemaphoreTakeRecursive() will
\r
321 * return immediately no matter what the value of xBlockTime.
\r
323 * @return pdTRUE if the semaphore was obtained. pdFALSE if xBlockTime
\r
324 * expired without the semaphore becoming available.
\r
328 SemaphoreHandle_t xMutex = NULL;
\r
330 // A task that creates a mutex.
\r
331 void vATask( void * pvParameters )
\r
333 // Create the mutex to guard a shared resource.
\r
334 xMutex = xSemaphoreCreateRecursiveMutex();
\r
337 // A task that uses the mutex.
\r
338 void vAnotherTask( void * pvParameters )
\r
340 // ... Do other things.
\r
342 if( xMutex != NULL )
\r
344 // See if we can obtain the mutex. If the mutex is not available
\r
345 // wait 10 ticks to see if it becomes free.
\r
346 if( xSemaphoreTakeRecursive( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
\r
348 // We were able to obtain the mutex and can now access the
\r
349 // shared resource.
\r
352 // For some reason due to the nature of the code further calls to
\r
353 // xSemaphoreTakeRecursive() are made on the same mutex. In real
\r
354 // code these would not be just sequential calls as this would make
\r
355 // no sense. Instead the calls are likely to be buried inside
\r
356 // a more complex call structure.
\r
357 xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
\r
358 xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
\r
360 // The mutex has now been 'taken' three times, so will not be
\r
361 // available to another task until it has also been given back
\r
362 // three times. Again it is unlikely that real code would have
\r
363 // these calls sequentially, but instead buried in a more complex
\r
364 // call structure. This is just for illustrative purposes.
\r
365 xSemaphoreGiveRecursive( xMutex );
\r
366 xSemaphoreGiveRecursive( xMutex );
\r
367 xSemaphoreGiveRecursive( xMutex );
\r
369 // Now the mutex can be taken by other tasks.
\r
373 // We could not obtain the mutex and can therefore not access
\r
374 // the shared resource safely.
\r
379 * \defgroup xSemaphoreTakeRecursive xSemaphoreTakeRecursive
\r
380 * \ingroup Semaphores
\r
382 #if( configUSE_RECURSIVE_MUTEXES == 1 )
\r
383 #define xSemaphoreTakeRecursive( xMutex, xBlockTime ) xQueueTakeMutexRecursive( ( xMutex ), ( xBlockTime ) )
\r
388 * <pre>xSemaphoreGive( SemaphoreHandle_t xSemaphore )</pre>
\r
390 * <i>Macro</i> to release a semaphore. The semaphore must have previously been
\r
391 * created with a call to xSemaphoreCreateBinary(), xSemaphoreCreateMutex() or
\r
392 * xSemaphoreCreateCounting(). and obtained using sSemaphoreTake().
\r
394 * This macro must not be used from an ISR. See xSemaphoreGiveFromISR () for
\r
395 * an alternative which can be used from an ISR.
\r
397 * This macro must also not be used on semaphores created using
\r
398 * xSemaphoreCreateRecursiveMutex().
\r
400 * @param xSemaphore A handle to the semaphore being released. This is the
\r
401 * handle returned when the semaphore was created.
\r
403 * @return pdTRUE if the semaphore was released. pdFALSE if an error occurred.
\r
404 * Semaphores are implemented using queues. An error can occur if there is
\r
405 * no space on the queue to post a message - indicating that the
\r
406 * semaphore was not first obtained correctly.
\r
410 SemaphoreHandle_t xSemaphore = NULL;
\r
412 void vATask( void * pvParameters )
\r
414 // Create the semaphore to guard a shared resource.
\r
415 xSemaphore = vSemaphoreCreateBinary();
\r
417 if( xSemaphore != NULL )
\r
419 if( xSemaphoreGive( xSemaphore ) != pdTRUE )
\r
421 // We would expect this call to fail because we cannot give
\r
422 // a semaphore without first "taking" it!
\r
425 // Obtain the semaphore - don't block if the semaphore is not
\r
426 // immediately available.
\r
427 if( xSemaphoreTake( xSemaphore, ( TickType_t ) 0 ) )
\r
429 // We now have the semaphore and can access the shared resource.
\r
433 // We have finished accessing the shared resource so can free the
\r
435 if( xSemaphoreGive( xSemaphore ) != pdTRUE )
\r
437 // We would not expect this call to fail because we must have
\r
438 // obtained the semaphore to get here.
\r
444 * \defgroup xSemaphoreGive xSemaphoreGive
\r
445 * \ingroup Semaphores
\r
447 #define xSemaphoreGive( xSemaphore ) xQueueGenericSend( ( QueueHandle_t ) ( xSemaphore ), NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK )
\r
451 * <pre>xSemaphoreGiveRecursive( SemaphoreHandle_t xMutex )</pre>
\r
453 * <i>Macro</i> to recursively release, or 'give', a mutex type semaphore.
\r
454 * The mutex must have previously been created using a call to
\r
455 * xSemaphoreCreateRecursiveMutex();
\r
457 * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this
\r
458 * macro to be available.
\r
460 * This macro must not be used on mutexes created using xSemaphoreCreateMutex().
\r
462 * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
\r
463 * doesn't become available again until the owner has called
\r
464 * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
\r
465 * if a task successfully 'takes' the same mutex 5 times then the mutex will
\r
466 * not be available to any other task until it has also 'given' the mutex back
\r
467 * exactly five times.
\r
469 * @param xMutex A handle to the mutex being released, or 'given'. This is the
\r
470 * handle returned by xSemaphoreCreateMutex();
\r
472 * @return pdTRUE if the semaphore was given.
\r
476 SemaphoreHandle_t xMutex = NULL;
\r
478 // A task that creates a mutex.
\r
479 void vATask( void * pvParameters )
\r
481 // Create the mutex to guard a shared resource.
\r
482 xMutex = xSemaphoreCreateRecursiveMutex();
\r
485 // A task that uses the mutex.
\r
486 void vAnotherTask( void * pvParameters )
\r
488 // ... Do other things.
\r
490 if( xMutex != NULL )
\r
492 // See if we can obtain the mutex. If the mutex is not available
\r
493 // wait 10 ticks to see if it becomes free.
\r
494 if( xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 ) == pdTRUE )
\r
496 // We were able to obtain the mutex and can now access the
\r
497 // shared resource.
\r
500 // For some reason due to the nature of the code further calls to
\r
501 // xSemaphoreTakeRecursive() are made on the same mutex. In real
\r
502 // code these would not be just sequential calls as this would make
\r
503 // no sense. Instead the calls are likely to be buried inside
\r
504 // a more complex call structure.
\r
505 xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
\r
506 xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
\r
508 // The mutex has now been 'taken' three times, so will not be
\r
509 // available to another task until it has also been given back
\r
510 // three times. Again it is unlikely that real code would have
\r
511 // these calls sequentially, it would be more likely that the calls
\r
512 // to xSemaphoreGiveRecursive() would be called as a call stack
\r
513 // unwound. This is just for demonstrative purposes.
\r
514 xSemaphoreGiveRecursive( xMutex );
\r
515 xSemaphoreGiveRecursive( xMutex );
\r
516 xSemaphoreGiveRecursive( xMutex );
\r
518 // Now the mutex can be taken by other tasks.
\r
522 // We could not obtain the mutex and can therefore not access
\r
523 // the shared resource safely.
\r
528 * \defgroup xSemaphoreGiveRecursive xSemaphoreGiveRecursive
\r
529 * \ingroup Semaphores
\r
531 #if( configUSE_RECURSIVE_MUTEXES == 1 )
\r
532 #define xSemaphoreGiveRecursive( xMutex ) xQueueGiveMutexRecursive( ( xMutex ) )
\r
538 xSemaphoreGiveFromISR(
\r
539 SemaphoreHandle_t xSemaphore,
\r
540 BaseType_t *pxHigherPriorityTaskWoken
\r
543 * <i>Macro</i> to release a semaphore. The semaphore must have previously been
\r
544 * created with a call to xSemaphoreCreateBinary() or xSemaphoreCreateCounting().
\r
546 * Mutex type semaphores (those created using a call to xSemaphoreCreateMutex())
\r
547 * must not be used with this macro.
\r
549 * This macro can be used from an ISR.
\r
551 * @param xSemaphore A handle to the semaphore being released. This is the
\r
552 * handle returned when the semaphore was created.
\r
554 * @param pxHigherPriorityTaskWoken xSemaphoreGiveFromISR() will set
\r
555 * *pxHigherPriorityTaskWoken to pdTRUE if giving the semaphore caused a task
\r
556 * to unblock, and the unblocked task has a priority higher than the currently
\r
557 * running task. If xSemaphoreGiveFromISR() sets this value to pdTRUE then
\r
558 * a context switch should be requested before the interrupt is exited.
\r
560 * @return pdTRUE if the semaphore was successfully given, otherwise errQUEUE_FULL.
\r
564 \#define LONG_TIME 0xffff
\r
565 \#define TICKS_TO_WAIT 10
\r
566 SemaphoreHandle_t xSemaphore = NULL;
\r
568 // Repetitive task.
\r
569 void vATask( void * pvParameters )
\r
573 // We want this task to run every 10 ticks of a timer. The semaphore
\r
574 // was created before this task was started.
\r
576 // Block waiting for the semaphore to become available.
\r
577 if( xSemaphoreTake( xSemaphore, LONG_TIME ) == pdTRUE )
\r
579 // It is time to execute.
\r
583 // We have finished our task. Return to the top of the loop where
\r
584 // we will block on the semaphore until it is time to execute
\r
585 // again. Note when using the semaphore for synchronisation with an
\r
586 // ISR in this manner there is no need to 'give' the semaphore back.
\r
592 void vTimerISR( void * pvParameters )
\r
594 static uint8_t ucLocalTickCount = 0;
\r
595 static BaseType_t xHigherPriorityTaskWoken;
\r
597 // A timer tick has occurred.
\r
599 // ... Do other time functions.
\r
601 // Is it time for vATask () to run?
\r
602 xHigherPriorityTaskWoken = pdFALSE;
\r
603 ucLocalTickCount++;
\r
604 if( ucLocalTickCount >= TICKS_TO_WAIT )
\r
606 // Unblock the task by releasing the semaphore.
\r
607 xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );
\r
609 // Reset the count so we release the semaphore again in 10 ticks time.
\r
610 ucLocalTickCount = 0;
\r
613 if( xHigherPriorityTaskWoken != pdFALSE )
\r
615 // We can force a context switch here. Context switching from an
\r
616 // ISR uses port specific syntax. Check the demo task for your port
\r
617 // to find the syntax required.
\r
621 * \defgroup xSemaphoreGiveFromISR xSemaphoreGiveFromISR
\r
622 * \ingroup Semaphores
\r
624 #define xSemaphoreGiveFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueGiveFromISR( ( QueueHandle_t ) ( xSemaphore ), ( pxHigherPriorityTaskWoken ) )
\r
629 xSemaphoreTakeFromISR(
\r
630 SemaphoreHandle_t xSemaphore,
\r
631 BaseType_t *pxHigherPriorityTaskWoken
\r
634 * <i>Macro</i> to take a semaphore from an ISR. The semaphore must have
\r
635 * previously been created with a call to xSemaphoreCreateBinary() or
\r
636 * xSemaphoreCreateCounting().
\r
638 * Mutex type semaphores (those created using a call to xSemaphoreCreateMutex())
\r
639 * must not be used with this macro.
\r
641 * This macro can be used from an ISR, however taking a semaphore from an ISR
\r
642 * is not a common operation. It is likely to only be useful when taking a
\r
643 * counting semaphore when an interrupt is obtaining an object from a resource
\r
644 * pool (when the semaphore count indicates the number of resources available).
\r
646 * @param xSemaphore A handle to the semaphore being taken. This is the
\r
647 * handle returned when the semaphore was created.
\r
649 * @param pxHigherPriorityTaskWoken xSemaphoreTakeFromISR() will set
\r
650 * *pxHigherPriorityTaskWoken to pdTRUE if taking the semaphore caused a task
\r
651 * to unblock, and the unblocked task has a priority higher than the currently
\r
652 * running task. If xSemaphoreTakeFromISR() sets this value to pdTRUE then
\r
653 * a context switch should be requested before the interrupt is exited.
\r
655 * @return pdTRUE if the semaphore was successfully taken, otherwise
\r
658 #define xSemaphoreTakeFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueReceiveFromISR( ( QueueHandle_t ) ( xSemaphore ), NULL, ( pxHigherPriorityTaskWoken ) )
\r
662 * <pre>SemaphoreHandle_t xSemaphoreCreateMutex( void )</pre>
\r
664 * Creates a new mutex type semaphore instance, and returns a handle by which
\r
665 * the new mutex can be referenced.
\r
667 * Internally, within the FreeRTOS implementation, mutex semaphores use a block
\r
668 * of memory, in which the mutex structure is stored. If a mutex is created
\r
669 * using xSemaphoreCreateMutex() then the required memory is automatically
\r
670 * dynamically allocated inside the xSemaphoreCreateMutex() function. (see
\r
671 * http://www.freertos.org/a00111.html). If a mutex is created using
\r
672 * xSemaphoreCreateMutexStatic() then the application writer must provided the
\r
673 * memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to be created
\r
674 * without using any dynamic memory allocation.
\r
676 * Mutexes created using this function can be accessed using the xSemaphoreTake()
\r
677 * and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and
\r
678 * xSemaphoreGiveRecursive() macros must not be used.
\r
680 * This type of semaphore uses a priority inheritance mechanism so a task
\r
681 * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
\r
682 * semaphore it is no longer required.
\r
684 * Mutex type semaphores cannot be used from within interrupt service routines.
\r
686 * See xSemaphoreCreateBinary() for an alternative implementation that can be
\r
687 * used for pure synchronisation (where one task or interrupt always 'gives' the
\r
688 * semaphore and another always 'takes' the semaphore) and from within interrupt
\r
689 * service routines.
\r
691 * @return If the mutex was successfully created then a handle to the created
\r
692 * semaphore is returned. If there was not enough heap to allocate the mutex
\r
693 * data structures then NULL is returned.
\r
697 SemaphoreHandle_t xSemaphore;
\r
699 void vATask( void * pvParameters )
\r
701 // Semaphore cannot be used before a call to xSemaphoreCreateMutex().
\r
702 // This is a macro so pass the variable in directly.
\r
703 xSemaphore = xSemaphoreCreateMutex();
\r
705 if( xSemaphore != NULL )
\r
707 // The semaphore was created successfully.
\r
708 // The semaphore can now be used.
\r
712 * \defgroup xSemaphoreCreateMutex xSemaphoreCreateMutex
\r
713 * \ingroup Semaphores
\r
715 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
716 #define xSemaphoreCreateMutex() xQueueCreateMutex( queueQUEUE_TYPE_MUTEX )
\r
721 * <pre>SemaphoreHandle_t xSemaphoreCreateMutexStatic( StaticSemaphore_t *pxMutexBuffer )</pre>
\r
723 * Creates a new mutex type semaphore instance, and returns a handle by which
\r
724 * the new mutex can be referenced.
\r
726 * Internally, within the FreeRTOS implementation, mutex semaphores use a block
\r
727 * of memory, in which the mutex structure is stored. If a mutex is created
\r
728 * using xSemaphoreCreateMutex() then the required memory is automatically
\r
729 * dynamically allocated inside the xSemaphoreCreateMutex() function. (see
\r
730 * http://www.freertos.org/a00111.html). If a mutex is created using
\r
731 * xSemaphoreCreateMutexStatic() then the application writer must provided the
\r
732 * memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to be created
\r
733 * without using any dynamic memory allocation.
\r
735 * Mutexes created using this function can be accessed using the xSemaphoreTake()
\r
736 * and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and
\r
737 * xSemaphoreGiveRecursive() macros must not be used.
\r
739 * This type of semaphore uses a priority inheritance mechanism so a task
\r
740 * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
\r
741 * semaphore it is no longer required.
\r
743 * Mutex type semaphores cannot be used from within interrupt service routines.
\r
745 * See xSemaphoreCreateBinary() for an alternative implementation that can be
\r
746 * used for pure synchronisation (where one task or interrupt always 'gives' the
\r
747 * semaphore and another always 'takes' the semaphore) and from within interrupt
\r
748 * service routines.
\r
750 * @param pxMutexBuffer Must point to a variable of type StaticSemaphore_t,
\r
751 * which will be used to hold the mutex's data structure, removing the need for
\r
752 * the memory to be allocated dynamically.
\r
754 * @return If the mutex was successfully created then a handle to the created
\r
755 * mutex is returned. If pxMutexBuffer was NULL then NULL is returned.
\r
759 SemaphoreHandle_t xSemaphore;
\r
760 StaticSemaphore_t xMutexBuffer;
\r
762 void vATask( void * pvParameters )
\r
764 // A mutex cannot be used before it has been created. xMutexBuffer is
\r
765 // into xSemaphoreCreateMutexStatic() so no dynamic memory allocation is
\r
767 xSemaphore = xSemaphoreCreateMutexStatic( &xMutexBuffer );
\r
769 // As no dynamic memory allocation was performed, xSemaphore cannot be NULL,
\r
770 // so there is no need to check it.
\r
773 * \defgroup xSemaphoreCreateMutexStatic xSemaphoreCreateMutexStatic
\r
774 * \ingroup Semaphores
\r
776 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
777 #define xSemaphoreCreateMutexStatic( pxMutexBuffer ) xQueueCreateMutexStatic( queueQUEUE_TYPE_MUTEX, ( pxMutexBuffer ) )
\r
778 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
783 * <pre>SemaphoreHandle_t xSemaphoreCreateRecursiveMutex( void )</pre>
\r
785 * Creates a new recursive mutex type semaphore instance, and returns a handle
\r
786 * by which the new recursive mutex can be referenced.
\r
788 * Internally, within the FreeRTOS implementation, recursive mutexs use a block
\r
789 * of memory, in which the mutex structure is stored. If a recursive mutex is
\r
790 * created using xSemaphoreCreateRecursiveMutex() then the required memory is
\r
791 * automatically dynamically allocated inside the
\r
792 * xSemaphoreCreateRecursiveMutex() function. (see
\r
793 * http://www.freertos.org/a00111.html). If a recursive mutex is created using
\r
794 * xSemaphoreCreateRecursiveMutexStatic() then the application writer must
\r
795 * provide the memory that will get used by the mutex.
\r
796 * xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to
\r
797 * be created without using any dynamic memory allocation.
\r
799 * Mutexes created using this macro can be accessed using the
\r
800 * xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The
\r
801 * xSemaphoreTake() and xSemaphoreGive() macros must not be used.
\r
803 * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
\r
804 * doesn't become available again until the owner has called
\r
805 * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
\r
806 * if a task successfully 'takes' the same mutex 5 times then the mutex will
\r
807 * not be available to any other task until it has also 'given' the mutex back
\r
808 * exactly five times.
\r
810 * This type of semaphore uses a priority inheritance mechanism so a task
\r
811 * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
\r
812 * semaphore it is no longer required.
\r
814 * Mutex type semaphores cannot be used from within interrupt service routines.
\r
816 * See xSemaphoreCreateBinary() for an alternative implementation that can be
\r
817 * used for pure synchronisation (where one task or interrupt always 'gives' the
\r
818 * semaphore and another always 'takes' the semaphore) and from within interrupt
\r
819 * service routines.
\r
821 * @return xSemaphore Handle to the created mutex semaphore. Should be of type
\r
822 * SemaphoreHandle_t.
\r
826 SemaphoreHandle_t xSemaphore;
\r
828 void vATask( void * pvParameters )
\r
830 // Semaphore cannot be used before a call to xSemaphoreCreateMutex().
\r
831 // This is a macro so pass the variable in directly.
\r
832 xSemaphore = xSemaphoreCreateRecursiveMutex();
\r
834 if( xSemaphore != NULL )
\r
836 // The semaphore was created successfully.
\r
837 // The semaphore can now be used.
\r
841 * \defgroup xSemaphoreCreateRecursiveMutex xSemaphoreCreateRecursiveMutex
\r
842 * \ingroup Semaphores
\r
844 #if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_RECURSIVE_MUTEXES == 1 ) )
\r
845 #define xSemaphoreCreateRecursiveMutex() xQueueCreateMutex( queueQUEUE_TYPE_RECURSIVE_MUTEX )
\r
850 * <pre>SemaphoreHandle_t xSemaphoreCreateRecursiveMutexStatic( StaticSemaphore_t *pxMutexBuffer )</pre>
\r
852 * Creates a new recursive mutex type semaphore instance, and returns a handle
\r
853 * by which the new recursive mutex can be referenced.
\r
855 * Internally, within the FreeRTOS implementation, recursive mutexs use a block
\r
856 * of memory, in which the mutex structure is stored. If a recursive mutex is
\r
857 * created using xSemaphoreCreateRecursiveMutex() then the required memory is
\r
858 * automatically dynamically allocated inside the
\r
859 * xSemaphoreCreateRecursiveMutex() function. (see
\r
860 * http://www.freertos.org/a00111.html). If a recursive mutex is created using
\r
861 * xSemaphoreCreateRecursiveMutexStatic() then the application writer must
\r
862 * provide the memory that will get used by the mutex.
\r
863 * xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to
\r
864 * be created without using any dynamic memory allocation.
\r
866 * Mutexes created using this macro can be accessed using the
\r
867 * xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The
\r
868 * xSemaphoreTake() and xSemaphoreGive() macros must not be used.
\r
870 * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
\r
871 * doesn't become available again until the owner has called
\r
872 * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
\r
873 * if a task successfully 'takes' the same mutex 5 times then the mutex will
\r
874 * not be available to any other task until it has also 'given' the mutex back
\r
875 * exactly five times.
\r
877 * This type of semaphore uses a priority inheritance mechanism so a task
\r
878 * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
\r
879 * semaphore it is no longer required.
\r
881 * Mutex type semaphores cannot be used from within interrupt service routines.
\r
883 * See xSemaphoreCreateBinary() for an alternative implementation that can be
\r
884 * used for pure synchronisation (where one task or interrupt always 'gives' the
\r
885 * semaphore and another always 'takes' the semaphore) and from within interrupt
\r
886 * service routines.
\r
888 * @param pxMutexBuffer Must point to a variable of type StaticSemaphore_t,
\r
889 * which will then be used to hold the recursive mutex's data structure,
\r
890 * removing the need for the memory to be allocated dynamically.
\r
892 * @return If the recursive mutex was successfully created then a handle to the
\r
893 * created recursive mutex is returned. If pxMutexBuffer was NULL then NULL is
\r
898 SemaphoreHandle_t xSemaphore;
\r
899 StaticSemaphore_t xMutexBuffer;
\r
901 void vATask( void * pvParameters )
\r
903 // A recursive semaphore cannot be used before it is created. Here a
\r
904 // recursive mutex is created using xSemaphoreCreateRecursiveMutexStatic().
\r
905 // The address of xMutexBuffer is passed into the function, and will hold
\r
906 // the mutexes data structures - so no dynamic memory allocation will be
\r
908 xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xMutexBuffer );
\r
910 // As no dynamic memory allocation was performed, xSemaphore cannot be NULL,
\r
911 // so there is no need to check it.
\r
914 * \defgroup xSemaphoreCreateRecursiveMutexStatic xSemaphoreCreateRecursiveMutexStatic
\r
915 * \ingroup Semaphores
\r
917 #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_RECURSIVE_MUTEXES == 1 ) )
\r
918 #define xSemaphoreCreateRecursiveMutexStatic( pxStaticSemaphore ) xQueueCreateMutexStatic( queueQUEUE_TYPE_RECURSIVE_MUTEX, pxStaticSemaphore )
\r
919 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
923 * <pre>SemaphoreHandle_t xSemaphoreCreateCounting( UBaseType_t uxMaxCount, UBaseType_t uxInitialCount )</pre>
\r
925 * Creates a new counting semaphore instance, and returns a handle by which the
\r
926 * new counting semaphore can be referenced.
\r
928 * In many usage scenarios it is faster and more memory efficient to use a
\r
929 * direct to task notification in place of a counting semaphore!
\r
930 * http://www.freertos.org/RTOS-task-notifications.html
\r
932 * Internally, within the FreeRTOS implementation, counting semaphores use a
\r
933 * block of memory, in which the counting semaphore structure is stored. If a
\r
934 * counting semaphore is created using xSemaphoreCreateCounting() then the
\r
935 * required memory is automatically dynamically allocated inside the
\r
936 * xSemaphoreCreateCounting() function. (see
\r
937 * http://www.freertos.org/a00111.html). If a counting semaphore is created
\r
938 * using xSemaphoreCreateCountingStatic() then the application writer can
\r
939 * instead optionally provide the memory that will get used by the counting
\r
940 * semaphore. xSemaphoreCreateCountingStatic() therefore allows a counting
\r
941 * semaphore to be created without using any dynamic memory allocation.
\r
943 * Counting semaphores are typically used for two things:
\r
945 * 1) Counting events.
\r
947 * In this usage scenario an event handler will 'give' a semaphore each time
\r
948 * an event occurs (incrementing the semaphore count value), and a handler
\r
949 * task will 'take' a semaphore each time it processes an event
\r
950 * (decrementing the semaphore count value). The count value is therefore
\r
951 * the difference between the number of events that have occurred and the
\r
952 * number that have been processed. In this case it is desirable for the
\r
953 * initial count value to be zero.
\r
955 * 2) Resource management.
\r
957 * In this usage scenario the count value indicates the number of resources
\r
958 * available. To obtain control of a resource a task must first obtain a
\r
959 * semaphore - decrementing the semaphore count value. When the count value
\r
960 * reaches zero there are no free resources. When a task finishes with the
\r
961 * resource it 'gives' the semaphore back - incrementing the semaphore count
\r
962 * value. In this case it is desirable for the initial count value to be
\r
963 * equal to the maximum count value, indicating that all resources are free.
\r
965 * @param uxMaxCount The maximum count value that can be reached. When the
\r
966 * semaphore reaches this value it can no longer be 'given'.
\r
968 * @param uxInitialCount The count value assigned to the semaphore when it is
\r
971 * @return Handle to the created semaphore. Null if the semaphore could not be
\r
976 SemaphoreHandle_t xSemaphore;
\r
978 void vATask( void * pvParameters )
\r
980 SemaphoreHandle_t xSemaphore = NULL;
\r
982 // Semaphore cannot be used before a call to xSemaphoreCreateCounting().
\r
983 // The max value to which the semaphore can count should be 10, and the
\r
984 // initial value assigned to the count should be 0.
\r
985 xSemaphore = xSemaphoreCreateCounting( 10, 0 );
\r
987 if( xSemaphore != NULL )
\r
989 // The semaphore was created successfully.
\r
990 // The semaphore can now be used.
\r
994 * \defgroup xSemaphoreCreateCounting xSemaphoreCreateCounting
\r
995 * \ingroup Semaphores
\r
997 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
\r
998 #define xSemaphoreCreateCounting( uxMaxCount, uxInitialCount ) xQueueCreateCountingSemaphore( ( uxMaxCount ), ( uxInitialCount ) )
\r
1003 * <pre>SemaphoreHandle_t xSemaphoreCreateCountingStatic( UBaseType_t uxMaxCount, UBaseType_t uxInitialCount, StaticSemaphore_t *pxSemaphoreBuffer )</pre>
\r
1005 * Creates a new counting semaphore instance, and returns a handle by which the
\r
1006 * new counting semaphore can be referenced.
\r
1008 * In many usage scenarios it is faster and more memory efficient to use a
\r
1009 * direct to task notification in place of a counting semaphore!
\r
1010 * http://www.freertos.org/RTOS-task-notifications.html
\r
1012 * Internally, within the FreeRTOS implementation, counting semaphores use a
\r
1013 * block of memory, in which the counting semaphore structure is stored. If a
\r
1014 * counting semaphore is created using xSemaphoreCreateCounting() then the
\r
1015 * required memory is automatically dynamically allocated inside the
\r
1016 * xSemaphoreCreateCounting() function. (see
\r
1017 * http://www.freertos.org/a00111.html). If a counting semaphore is created
\r
1018 * using xSemaphoreCreateCountingStatic() then the application writer must
\r
1019 * provide the memory. xSemaphoreCreateCountingStatic() therefore allows a
\r
1020 * counting semaphore to be created without using any dynamic memory allocation.
\r
1022 * Counting semaphores are typically used for two things:
\r
1024 * 1) Counting events.
\r
1026 * In this usage scenario an event handler will 'give' a semaphore each time
\r
1027 * an event occurs (incrementing the semaphore count value), and a handler
\r
1028 * task will 'take' a semaphore each time it processes an event
\r
1029 * (decrementing the semaphore count value). The count value is therefore
\r
1030 * the difference between the number of events that have occurred and the
\r
1031 * number that have been processed. In this case it is desirable for the
\r
1032 * initial count value to be zero.
\r
1034 * 2) Resource management.
\r
1036 * In this usage scenario the count value indicates the number of resources
\r
1037 * available. To obtain control of a resource a task must first obtain a
\r
1038 * semaphore - decrementing the semaphore count value. When the count value
\r
1039 * reaches zero there are no free resources. When a task finishes with the
\r
1040 * resource it 'gives' the semaphore back - incrementing the semaphore count
\r
1041 * value. In this case it is desirable for the initial count value to be
\r
1042 * equal to the maximum count value, indicating that all resources are free.
\r
1044 * @param uxMaxCount The maximum count value that can be reached. When the
\r
1045 * semaphore reaches this value it can no longer be 'given'.
\r
1047 * @param uxInitialCount The count value assigned to the semaphore when it is
\r
1050 * @param pxSemaphoreBuffer Must point to a variable of type StaticSemaphore_t,
\r
1051 * which will then be used to hold the semaphore's data structure, removing the
\r
1052 * need for the memory to be allocated dynamically.
\r
1054 * @return If the counting semaphore was successfully created then a handle to
\r
1055 * the created counting semaphore is returned. If pxSemaphoreBuffer was NULL
\r
1056 * then NULL is returned.
\r
1060 SemaphoreHandle_t xSemaphore;
\r
1061 StaticSemaphore_t xSemaphoreBuffer;
\r
1063 void vATask( void * pvParameters )
\r
1065 SemaphoreHandle_t xSemaphore = NULL;
\r
1067 // Counting semaphore cannot be used before they have been created. Create
\r
1068 // a counting semaphore using xSemaphoreCreateCountingStatic(). The max
\r
1069 // value to which the semaphore can count is 10, and the initial value
\r
1070 // assigned to the count will be 0. The address of xSemaphoreBuffer is
\r
1071 // passed in and will be used to hold the semaphore structure, so no dynamic
\r
1072 // memory allocation will be used.
\r
1073 xSemaphore = xSemaphoreCreateCounting( 10, 0, &xSemaphoreBuffer );
\r
1075 // No memory allocation was attempted so xSemaphore cannot be NULL, so there
\r
1076 // is no need to check its value.
\r
1079 * \defgroup xSemaphoreCreateCountingStatic xSemaphoreCreateCountingStatic
\r
1080 * \ingroup Semaphores
\r
1082 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
\r
1083 #define xSemaphoreCreateCountingStatic( uxMaxCount, uxInitialCount, pxSemaphoreBuffer ) xQueueCreateCountingSemaphoreStatic( ( uxMaxCount ), ( uxInitialCount ), ( pxSemaphoreBuffer ) )
\r
1084 #endif /* configSUPPORT_STATIC_ALLOCATION */
\r
1088 * <pre>void vSemaphoreDelete( SemaphoreHandle_t xSemaphore );</pre>
\r
1090 * Delete a semaphore. This function must be used with care. For example,
\r
1091 * do not delete a mutex type semaphore if the mutex is held by a task.
\r
1093 * @param xSemaphore A handle to the semaphore to be deleted.
\r
1095 * \defgroup vSemaphoreDelete vSemaphoreDelete
\r
1096 * \ingroup Semaphores
\r
1098 #define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( QueueHandle_t ) ( xSemaphore ) )
\r
1102 * <pre>TaskHandle_t xSemaphoreGetMutexHolder( SemaphoreHandle_t xMutex );</pre>
\r
1104 * If xMutex is indeed a mutex type semaphore, return the current mutex holder.
\r
1105 * If xMutex is not a mutex type semaphore, or the mutex is available (not held
\r
1106 * by a task), return NULL.
\r
1108 * Note: This is a good way of determining if the calling task is the mutex
\r
1109 * holder, but not a good way of determining the identity of the mutex holder as
\r
1110 * the holder may change between the function exiting and the returned value
\r
1113 #define xSemaphoreGetMutexHolder( xSemaphore ) xQueueGetMutexHolder( ( xSemaphore ) )
\r
1117 * <pre>TaskHandle_t xSemaphoreGetMutexHolderFromISR( SemaphoreHandle_t xMutex );</pre>
\r
1119 * If xMutex is indeed a mutex type semaphore, return the current mutex holder.
\r
1120 * If xMutex is not a mutex type semaphore, or the mutex is available (not held
\r
1121 * by a task), return NULL.
\r
1124 #define xSemaphoreGetMutexHolderFromISR( xSemaphore ) xQueueGetMutexHolderFromISR( ( xSemaphore ) )
\r
1128 * <pre>UBaseType_t uxSemaphoreGetCount( SemaphoreHandle_t xSemaphore );</pre>
\r
1130 * If the semaphore is a counting semaphore then uxSemaphoreGetCount() returns
\r
1131 * its current count value. If the semaphore is a binary semaphore then
\r
1132 * uxSemaphoreGetCount() returns 1 if the semaphore is available, and 0 if the
\r
1133 * semaphore is not available.
\r
1136 #define uxSemaphoreGetCount( xSemaphore ) uxQueueMessagesWaiting( ( QueueHandle_t ) ( xSemaphore ) )
\r
1138 #endif /* SEMAPHORE_H */
\r