GM6000 Digital Heater Controller
Branch: main
SDX-1330
Main Page
Namespaces
Components
Files
File List
File Members
Bsp
Initech
alpha1-atmel
FreeRTOS
Source
include
semphr.h
1
/*
2
* FreeRTOS Kernel V10.0.0
3
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
*
5
* Permission is hereby granted, free of charge, to any person obtaining a copy of
6
* this software and associated documentation files (the "Software"), to deal in
7
* the Software without restriction, including without limitation the rights to
8
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
* the Software, and to permit persons to whom the Software is furnished to do so,
10
* subject to the following conditions:
11
*
12
* The above copyright notice and this permission notice shall be included in all
13
* copies or substantial portions of the Software. If you wish to use our Amazon
14
* FreeRTOS name, please do so in a fair use way that does not cause confusion.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
*
23
* http://www.FreeRTOS.org
24
* http://aws.amazon.com/freertos
25
*
26
* 1 tab == 4 spaces!
27
*/
28
29
#ifndef SEMAPHORE_H
30
#define SEMAPHORE_H
31
32
#ifndef INC_FREERTOS_H
33
#error "include FreeRTOS.h" must appear in source files before "include semphr.h"
34
#endif
35
36
#include "queue.h"
37
38
typedef
QueueHandle_t SemaphoreHandle_t;
39
40
#define semBINARY_SEMAPHORE_QUEUE_LENGTH ((uint8_t)1U)
41
#define semSEMAPHORE_QUEUE_ITEM_LENGTH ((uint8_t)0U)
42
#define semGIVE_BLOCK_TIME ((TickType_t)0U)
43
44
/**
45
* semphr. h
46
* <pre>vSemaphoreCreateBinary( SemaphoreHandle_t xSemaphore )</pre>
47
*
48
* In many usage scenarios it is faster and more memory efficient to use a
49
* direct to task notification in place of a binary semaphore!
50
* http://www.freertos.org/RTOS-task-notifications.html
51
*
52
* This old vSemaphoreCreateBinary() macro is now deprecated in favour of the
53
* xSemaphoreCreateBinary() function. Note that binary semaphores created using
54
* the vSemaphoreCreateBinary() macro are created in a state such that the
55
* first call to 'take' the semaphore would pass, whereas binary semaphores
56
* created using xSemaphoreCreateBinary() are created in a state such that the
57
* the semaphore must first be 'given' before it can be 'taken'.
58
*
59
* <i>Macro</i> that implements a semaphore by using the existing queue mechanism.
60
* The queue length is 1 as this is a binary semaphore. The data size is 0
61
* as we don't want to actually store any data - we just want to know if the
62
* queue is empty or full.
63
*
64
* This type of semaphore can be used for pure synchronisation between tasks or
65
* between an interrupt and a task. The semaphore need not be given back once
66
* obtained, so one task/interrupt can continuously 'give' the semaphore while
67
* another continuously 'takes' the semaphore. For this reason this type of
68
* semaphore does not use a priority inheritance mechanism. For an alternative
69
* that does use priority inheritance see xSemaphoreCreateMutex().
70
*
71
* @param xSemaphore Handle to the created semaphore. Should be of type SemaphoreHandle_t.
72
*
73
* Example usage:
74
<pre>
75
SemaphoreHandle_t xSemaphore = NULL;
76
77
void vATask( void * pvParameters )
78
{
79
// Semaphore cannot be used before a call to vSemaphoreCreateBinary ().
80
// This is a macro so pass the variable in directly.
81
vSemaphoreCreateBinary( xSemaphore );
82
83
if( xSemaphore != NULL )
84
{
85
// The semaphore was created successfully.
86
// The semaphore can now be used.
87
}
88
}
89
</pre>
90
* \defgroup vSemaphoreCreateBinary vSemaphoreCreateBinary
91
* \ingroup Semaphores
92
*/
93
#if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
94
#define vSemaphoreCreateBinary(xSemaphore) \
95
{ \
96
(xSemaphore) \
97
= xQueueGenericCreate((UBaseType_t)1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE); \
98
if ((xSemaphore) != NULL) { \
99
(void)xSemaphoreGive((xSemaphore)); \
100
} \
101
}
102
#endif
103
104
/**
105
* semphr. h
106
* <pre>SemaphoreHandle_t xSemaphoreCreateBinary( void )</pre>
107
*
108
* Creates a new binary semaphore instance, and returns a handle by which the
109
* new semaphore can be referenced.
110
*
111
* In many usage scenarios it is faster and more memory efficient to use a
112
* direct to task notification in place of a binary semaphore!
113
* http://www.freertos.org/RTOS-task-notifications.html
114
*
115
* Internally, within the FreeRTOS implementation, binary semaphores use a block
116
* of memory, in which the semaphore structure is stored. If a binary semaphore
117
* is created using xSemaphoreCreateBinary() then the required memory is
118
* automatically dynamically allocated inside the xSemaphoreCreateBinary()
119
* function. (see http://www.freertos.org/a00111.html). If a binary semaphore
120
* is created using xSemaphoreCreateBinaryStatic() then the application writer
121
* must provide the memory. xSemaphoreCreateBinaryStatic() therefore allows a
122
* binary semaphore to be created without using any dynamic memory allocation.
123
*
124
* The old vSemaphoreCreateBinary() macro is now deprecated in favour of this
125
* xSemaphoreCreateBinary() function. Note that binary semaphores created using
126
* the vSemaphoreCreateBinary() macro are created in a state such that the
127
* first call to 'take' the semaphore would pass, whereas binary semaphores
128
* created using xSemaphoreCreateBinary() are created in a state such that the
129
* the semaphore must first be 'given' before it can be 'taken'.
130
*
131
* This type of semaphore can be used for pure synchronisation between tasks or
132
* between an interrupt and a task. The semaphore need not be given back once
133
* obtained, so one task/interrupt can continuously 'give' the semaphore while
134
* another continuously 'takes' the semaphore. For this reason this type of
135
* semaphore does not use a priority inheritance mechanism. For an alternative
136
* that does use priority inheritance see xSemaphoreCreateMutex().
137
*
138
* @return Handle to the created semaphore, or NULL if the memory required to
139
* hold the semaphore's data structures could not be allocated.
140
*
141
* Example usage:
142
<pre>
143
SemaphoreHandle_t xSemaphore = NULL;
144
145
void vATask( void * pvParameters )
146
{
147
// Semaphore cannot be used before a call to xSemaphoreCreateBinary().
148
// This is a macro so pass the variable in directly.
149
xSemaphore = xSemaphoreCreateBinary();
150
151
if( xSemaphore != NULL )
152
{
153
// The semaphore was created successfully.
154
// The semaphore can now be used.
155
}
156
}
157
</pre>
158
* \defgroup xSemaphoreCreateBinary xSemaphoreCreateBinary
159
* \ingroup Semaphores
160
*/
161
#if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
162
#define xSemaphoreCreateBinary() \
163
xQueueGenericCreate((UBaseType_t)1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE)
164
#endif
165
166
/**
167
* semphr. h
168
* <pre>SemaphoreHandle_t xSemaphoreCreateBinaryStatic( StaticSemaphore_t *pxSemaphoreBuffer )</pre>
169
*
170
* Creates a new binary semaphore instance, and returns a handle by which the
171
* new semaphore can be referenced.
172
*
173
* NOTE: In many usage scenarios it is faster and more memory efficient to use a
174
* direct to task notification in place of a binary semaphore!
175
* http://www.freertos.org/RTOS-task-notifications.html
176
*
177
* Internally, within the FreeRTOS implementation, binary semaphores use a block
178
* of memory, in which the semaphore structure is stored. If a binary semaphore
179
* is created using xSemaphoreCreateBinary() then the required memory is
180
* automatically dynamically allocated inside the xSemaphoreCreateBinary()
181
* function. (see http://www.freertos.org/a00111.html). If a binary semaphore
182
* is created using xSemaphoreCreateBinaryStatic() then the application writer
183
* must provide the memory. xSemaphoreCreateBinaryStatic() therefore allows a
184
* binary semaphore to be created without using any dynamic memory allocation.
185
*
186
* This type of semaphore can be used for pure synchronisation between tasks or
187
* between an interrupt and a task. The semaphore need not be given back once
188
* obtained, so one task/interrupt can continuously 'give' the semaphore while
189
* another continuously 'takes' the semaphore. For this reason this type of
190
* semaphore does not use a priority inheritance mechanism. For an alternative
191
* that does use priority inheritance see xSemaphoreCreateMutex().
192
*
193
* @param pxSemaphoreBuffer Must point to a variable of type StaticSemaphore_t,
194
* which will then be used to hold the semaphore's data structure, removing the
195
* need for the memory to be allocated dynamically.
196
*
197
* @return If the semaphore is created then a handle to the created semaphore is
198
* returned. If pxSemaphoreBuffer is NULL then NULL is returned.
199
*
200
* Example usage:
201
<pre>
202
SemaphoreHandle_t xSemaphore = NULL;
203
StaticSemaphore_t xSemaphoreBuffer;
204
205
void vATask( void * pvParameters )
206
{
207
// Semaphore cannot be used before a call to xSemaphoreCreateBinary().
208
// The semaphore's data structures will be placed in the xSemaphoreBuffer
209
// variable, the address of which is passed into the function. The
210
// function's parameter is not NULL, so the function will not attempt any
211
// dynamic memory allocation, and therefore the function will not return
212
// return NULL.
213
xSemaphore = xSemaphoreCreateBinary( &xSemaphoreBuffer );
214
215
// Rest of task code goes here.
216
}
217
</pre>
218
* \defgroup xSemaphoreCreateBinaryStatic xSemaphoreCreateBinaryStatic
219
* \ingroup Semaphores
220
*/
221
#if (configSUPPORT_STATIC_ALLOCATION == 1)
222
#define xSemaphoreCreateBinaryStatic(pxStaticSemaphore) \
223
xQueueGenericCreateStatic( \
224
(UBaseType_t)1, semSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticSemaphore, queueQUEUE_TYPE_BINARY_SEMAPHORE)
225
#endif
/* configSUPPORT_STATIC_ALLOCATION */
226
227
/**
228
* semphr. h
229
* <pre>xSemaphoreTake(
230
* SemaphoreHandle_t xSemaphore,
231
* TickType_t xBlockTime
232
* )</pre>
233
*
234
* <i>Macro</i> to obtain a semaphore. The semaphore must have previously been
235
* created with a call to xSemaphoreCreateBinary(), xSemaphoreCreateMutex() or
236
* xSemaphoreCreateCounting().
237
*
238
* @param xSemaphore A handle to the semaphore being taken - obtained when
239
* the semaphore was created.
240
*
241
* @param xBlockTime The time in ticks to wait for the semaphore to become
242
* available. The macro portTICK_PERIOD_MS can be used to convert this to a
243
* real time. A block time of zero can be used to poll the semaphore. A block
244
* time of portMAX_DELAY can be used to block indefinitely (provided
245
* INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h).
246
*
247
* @return pdTRUE if the semaphore was obtained. pdFALSE
248
* if xBlockTime expired without the semaphore becoming available.
249
*
250
* Example usage:
251
<pre>
252
SemaphoreHandle_t xSemaphore = NULL;
253
254
// A task that creates a semaphore.
255
void vATask( void * pvParameters )
256
{
257
// Create the semaphore to guard a shared resource.
258
xSemaphore = xSemaphoreCreateBinary();
259
}
260
261
// A task that uses the semaphore.
262
void vAnotherTask( void * pvParameters )
263
{
264
// ... Do other things.
265
266
if( xSemaphore != NULL )
267
{
268
// See if we can obtain the semaphore. If the semaphore is not available
269
// wait 10 ticks to see if it becomes free.
270
if( xSemaphoreTake( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
271
{
272
// We were able to obtain the semaphore and can now access the
273
// shared resource.
274
275
// ...
276
277
// We have finished accessing the shared resource. Release the
278
// semaphore.
279
xSemaphoreGive( xSemaphore );
280
}
281
else
282
{
283
// We could not obtain the semaphore and can therefore not access
284
// the shared resource safely.
285
}
286
}
287
}
288
</pre>
289
* \defgroup xSemaphoreTake xSemaphoreTake
290
* \ingroup Semaphores
291
*/
292
#define xSemaphoreTake(xSemaphore, xBlockTime) xQueueSemaphoreTake((xSemaphore), (xBlockTime))
293
294
/**
295
* semphr. h
296
* xSemaphoreTakeRecursive(
297
* SemaphoreHandle_t xMutex,
298
* TickType_t xBlockTime
299
* )
300
*
301
* <i>Macro</i> to recursively obtain, or 'take', a mutex type semaphore.
302
* The mutex must have previously been created using a call to
303
* xSemaphoreCreateRecursiveMutex();
304
*
305
* configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this
306
* macro to be available.
307
*
308
* This macro must not be used on mutexes created using xSemaphoreCreateMutex().
309
*
310
* A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
311
* doesn't become available again until the owner has called
312
* xSemaphoreGiveRecursive() for each successful 'take' request. For example,
313
* if a task successfully 'takes' the same mutex 5 times then the mutex will
314
* not be available to any other task until it has also 'given' the mutex back
315
* exactly five times.
316
*
317
* @param xMutex A handle to the mutex being obtained. This is the
318
* handle returned by xSemaphoreCreateRecursiveMutex();
319
*
320
* @param xBlockTime The time in ticks to wait for the semaphore to become
321
* available. The macro portTICK_PERIOD_MS can be used to convert this to a
322
* real time. A block time of zero can be used to poll the semaphore. If
323
* the task already owns the semaphore then xSemaphoreTakeRecursive() will
324
* return immediately no matter what the value of xBlockTime.
325
*
326
* @return pdTRUE if the semaphore was obtained. pdFALSE if xBlockTime
327
* expired without the semaphore becoming available.
328
*
329
* Example usage:
330
<pre>
331
SemaphoreHandle_t xMutex = NULL;
332
333
// A task that creates a mutex.
334
void vATask( void * pvParameters )
335
{
336
// Create the mutex to guard a shared resource.
337
xMutex = xSemaphoreCreateRecursiveMutex();
338
}
339
340
// A task that uses the mutex.
341
void vAnotherTask( void * pvParameters )
342
{
343
// ... Do other things.
344
345
if( xMutex != NULL )
346
{
347
// See if we can obtain the mutex. If the mutex is not available
348
// wait 10 ticks to see if it becomes free.
349
if( xSemaphoreTakeRecursive( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
350
{
351
// We were able to obtain the mutex and can now access the
352
// shared resource.
353
354
// ...
355
// For some reason due to the nature of the code further calls to
356
// xSemaphoreTakeRecursive() are made on the same mutex. In real
357
// code these would not be just sequential calls as this would make
358
// no sense. Instead the calls are likely to be buried inside
359
// a more complex call structure.
360
xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
361
xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
362
363
// The mutex has now been 'taken' three times, so will not be
364
// available to another task until it has also been given back
365
// three times. Again it is unlikely that real code would have
366
// these calls sequentially, but instead buried in a more complex
367
// call structure. This is just for illustrative purposes.
368
xSemaphoreGiveRecursive( xMutex );
369
xSemaphoreGiveRecursive( xMutex );
370
xSemaphoreGiveRecursive( xMutex );
371
372
// Now the mutex can be taken by other tasks.
373
}
374
else
375
{
376
// We could not obtain the mutex and can therefore not access
377
// the shared resource safely.
378
}
379
}
380
}
381
</pre>
382
* \defgroup xSemaphoreTakeRecursive xSemaphoreTakeRecursive
383
* \ingroup Semaphores
384
*/
385
#if (configUSE_RECURSIVE_MUTEXES == 1)
386
#define xSemaphoreTakeRecursive(xMutex, xBlockTime) xQueueTakeMutexRecursive((xMutex), (xBlockTime))
387
#endif
388
389
/**
390
* semphr. h
391
* <pre>xSemaphoreGive( SemaphoreHandle_t xSemaphore )</pre>
392
*
393
* <i>Macro</i> to release a semaphore. The semaphore must have previously been
394
* created with a call to xSemaphoreCreateBinary(), xSemaphoreCreateMutex() or
395
* xSemaphoreCreateCounting(). and obtained using sSemaphoreTake().
396
*
397
* This macro must not be used from an ISR. See xSemaphoreGiveFromISR () for
398
* an alternative which can be used from an ISR.
399
*
400
* This macro must also not be used on semaphores created using
401
* xSemaphoreCreateRecursiveMutex().
402
*
403
* @param xSemaphore A handle to the semaphore being released. This is the
404
* handle returned when the semaphore was created.
405
*
406
* @return pdTRUE if the semaphore was released. pdFALSE if an error occurred.
407
* Semaphores are implemented using queues. An error can occur if there is
408
* no space on the queue to post a message - indicating that the
409
* semaphore was not first obtained correctly.
410
*
411
* Example usage:
412
<pre>
413
SemaphoreHandle_t xSemaphore = NULL;
414
415
void vATask( void * pvParameters )
416
{
417
// Create the semaphore to guard a shared resource.
418
xSemaphore = vSemaphoreCreateBinary();
419
420
if( xSemaphore != NULL )
421
{
422
if( xSemaphoreGive( xSemaphore ) != pdTRUE )
423
{
424
// We would expect this call to fail because we cannot give
425
// a semaphore without first "taking" it!
426
}
427
428
// Obtain the semaphore - don't block if the semaphore is not
429
// immediately available.
430
if( xSemaphoreTake( xSemaphore, ( TickType_t ) 0 ) )
431
{
432
// We now have the semaphore and can access the shared resource.
433
434
// ...
435
436
// We have finished accessing the shared resource so can free the
437
// semaphore.
438
if( xSemaphoreGive( xSemaphore ) != pdTRUE )
439
{
440
// We would not expect this call to fail because we must have
441
// obtained the semaphore to get here.
442
}
443
}
444
}
445
}
446
</pre>
447
* \defgroup xSemaphoreGive xSemaphoreGive
448
* \ingroup Semaphores
449
*/
450
#define xSemaphoreGive(xSemaphore) \
451
xQueueGenericSend((QueueHandle_t)(xSemaphore), NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK)
452
453
/**
454
* semphr. h
455
* <pre>xSemaphoreGiveRecursive( SemaphoreHandle_t xMutex )</pre>
456
*
457
* <i>Macro</i> to recursively release, or 'give', a mutex type semaphore.
458
* The mutex must have previously been created using a call to
459
* xSemaphoreCreateRecursiveMutex();
460
*
461
* configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this
462
* macro to be available.
463
*
464
* This macro must not be used on mutexes created using xSemaphoreCreateMutex().
465
*
466
* A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
467
* doesn't become available again until the owner has called
468
* xSemaphoreGiveRecursive() for each successful 'take' request. For example,
469
* if a task successfully 'takes' the same mutex 5 times then the mutex will
470
* not be available to any other task until it has also 'given' the mutex back
471
* exactly five times.
472
*
473
* @param xMutex A handle to the mutex being released, or 'given'. This is the
474
* handle returned by xSemaphoreCreateMutex();
475
*
476
* @return pdTRUE if the semaphore was given.
477
*
478
* Example usage:
479
<pre>
480
SemaphoreHandle_t xMutex = NULL;
481
482
// A task that creates a mutex.
483
void vATask( void * pvParameters )
484
{
485
// Create the mutex to guard a shared resource.
486
xMutex = xSemaphoreCreateRecursiveMutex();
487
}
488
489
// A task that uses the mutex.
490
void vAnotherTask( void * pvParameters )
491
{
492
// ... Do other things.
493
494
if( xMutex != NULL )
495
{
496
// See if we can obtain the mutex. If the mutex is not available
497
// wait 10 ticks to see if it becomes free.
498
if( xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 ) == pdTRUE )
499
{
500
// We were able to obtain the mutex and can now access the
501
// shared resource.
502
503
// ...
504
// For some reason due to the nature of the code further calls to
505
// xSemaphoreTakeRecursive() are made on the same mutex. In real
506
// code these would not be just sequential calls as this would make
507
// no sense. Instead the calls are likely to be buried inside
508
// a more complex call structure.
509
xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
510
xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
511
512
// The mutex has now been 'taken' three times, so will not be
513
// available to another task until it has also been given back
514
// three times. Again it is unlikely that real code would have
515
// these calls sequentially, it would be more likely that the calls
516
// to xSemaphoreGiveRecursive() would be called as a call stack
517
// unwound. This is just for demonstrative purposes.
518
xSemaphoreGiveRecursive( xMutex );
519
xSemaphoreGiveRecursive( xMutex );
520
xSemaphoreGiveRecursive( xMutex );
521
522
// Now the mutex can be taken by other tasks.
523
}
524
else
525
{
526
// We could not obtain the mutex and can therefore not access
527
// the shared resource safely.
528
}
529
}
530
}
531
</pre>
532
* \defgroup xSemaphoreGiveRecursive xSemaphoreGiveRecursive
533
* \ingroup Semaphores
534
*/
535
#if (configUSE_RECURSIVE_MUTEXES == 1)
536
#define xSemaphoreGiveRecursive(xMutex) xQueueGiveMutexRecursive((xMutex))
537
#endif
538
539
/**
540
* semphr. h
541
* <pre>
542
xSemaphoreGiveFromISR(
543
SemaphoreHandle_t xSemaphore,
544
BaseType_t *pxHigherPriorityTaskWoken
545
)</pre>
546
*
547
* <i>Macro</i> to release a semaphore. The semaphore must have previously been
548
* created with a call to xSemaphoreCreateBinary() or xSemaphoreCreateCounting().
549
*
550
* Mutex type semaphores (those created using a call to xSemaphoreCreateMutex())
551
* must not be used with this macro.
552
*
553
* This macro can be used from an ISR.
554
*
555
* @param xSemaphore A handle to the semaphore being released. This is the
556
* handle returned when the semaphore was created.
557
*
558
* @param pxHigherPriorityTaskWoken xSemaphoreGiveFromISR() will set
559
* *pxHigherPriorityTaskWoken to pdTRUE if giving the semaphore caused a task
560
* to unblock, and the unblocked task has a priority higher than the currently
561
* running task. If xSemaphoreGiveFromISR() sets this value to pdTRUE then
562
* a context switch should be requested before the interrupt is exited.
563
*
564
* @return pdTRUE if the semaphore was successfully given, otherwise errQUEUE_FULL.
565
*
566
* Example usage:
567
<pre>
568
\#define LONG_TIME 0xffff
569
\#define TICKS_TO_WAIT 10
570
SemaphoreHandle_t xSemaphore = NULL;
571
572
// Repetitive task.
573
void vATask( void * pvParameters )
574
{
575
for( ;; )
576
{
577
// We want this task to run every 10 ticks of a timer. The semaphore
578
// was created before this task was started.
579
580
// Block waiting for the semaphore to become available.
581
if( xSemaphoreTake( xSemaphore, LONG_TIME ) == pdTRUE )
582
{
583
// It is time to execute.
584
585
// ...
586
587
// We have finished our task. Return to the top of the loop where
588
// we will block on the semaphore until it is time to execute
589
// again. Note when using the semaphore for synchronisation with an
590
// ISR in this manner there is no need to 'give' the semaphore back.
591
}
592
}
593
}
594
595
// Timer ISR
596
void vTimerISR( void * pvParameters )
597
{
598
static uint8_t ucLocalTickCount = 0;
599
static BaseType_t xHigherPriorityTaskWoken;
600
601
// A timer tick has occurred.
602
603
// ... Do other time functions.
604
605
// Is it time for vATask () to run?
606
xHigherPriorityTaskWoken = pdFALSE;
607
ucLocalTickCount++;
608
if( ucLocalTickCount >= TICKS_TO_WAIT )
609
{
610
// Unblock the task by releasing the semaphore.
611
xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );
612
613
// Reset the count so we release the semaphore again in 10 ticks time.
614
ucLocalTickCount = 0;
615
}
616
617
if( xHigherPriorityTaskWoken != pdFALSE )
618
{
619
// We can force a context switch here. Context switching from an
620
// ISR uses port specific syntax. Check the demo task for your port
621
// to find the syntax required.
622
}
623
}
624
</pre>
625
* \defgroup xSemaphoreGiveFromISR xSemaphoreGiveFromISR
626
* \ingroup Semaphores
627
*/
628
#define xSemaphoreGiveFromISR(xSemaphore, pxHigherPriorityTaskWoken) \
629
xQueueGiveFromISR((QueueHandle_t)(xSemaphore), (pxHigherPriorityTaskWoken))
630
631
/**
632
* semphr. h
633
* <pre>
634
xSemaphoreTakeFromISR(
635
SemaphoreHandle_t xSemaphore,
636
BaseType_t *pxHigherPriorityTaskWoken
637
)</pre>
638
*
639
* <i>Macro</i> to take a semaphore from an ISR. The semaphore must have
640
* previously been created with a call to xSemaphoreCreateBinary() or
641
* xSemaphoreCreateCounting().
642
*
643
* Mutex type semaphores (those created using a call to xSemaphoreCreateMutex())
644
* must not be used with this macro.
645
*
646
* This macro can be used from an ISR, however taking a semaphore from an ISR
647
* is not a common operation. It is likely to only be useful when taking a
648
* counting semaphore when an interrupt is obtaining an object from a resource
649
* pool (when the semaphore count indicates the number of resources available).
650
*
651
* @param xSemaphore A handle to the semaphore being taken. This is the
652
* handle returned when the semaphore was created.
653
*
654
* @param pxHigherPriorityTaskWoken xSemaphoreTakeFromISR() will set
655
* *pxHigherPriorityTaskWoken to pdTRUE if taking the semaphore caused a task
656
* to unblock, and the unblocked task has a priority higher than the currently
657
* running task. If xSemaphoreTakeFromISR() sets this value to pdTRUE then
658
* a context switch should be requested before the interrupt is exited.
659
*
660
* @return pdTRUE if the semaphore was successfully taken, otherwise
661
* pdFALSE
662
*/
663
#define xSemaphoreTakeFromISR(xSemaphore, pxHigherPriorityTaskWoken) \
664
xQueueReceiveFromISR((QueueHandle_t)(xSemaphore), NULL, (pxHigherPriorityTaskWoken))
665
666
/**
667
* semphr. h
668
* <pre>SemaphoreHandle_t xSemaphoreCreateMutex( void )</pre>
669
*
670
* Creates a new mutex type semaphore instance, and returns a handle by which
671
* the new mutex can be referenced.
672
*
673
* Internally, within the FreeRTOS implementation, mutex semaphores use a block
674
* of memory, in which the mutex structure is stored. If a mutex is created
675
* using xSemaphoreCreateMutex() then the required memory is automatically
676
* dynamically allocated inside the xSemaphoreCreateMutex() function. (see
677
* http://www.freertos.org/a00111.html). If a mutex is created using
678
* xSemaphoreCreateMutexStatic() then the application writer must provided the
679
* memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to be created
680
* without using any dynamic memory allocation.
681
*
682
* Mutexes created using this function can be accessed using the xSemaphoreTake()
683
* and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and
684
* xSemaphoreGiveRecursive() macros must not be used.
685
*
686
* This type of semaphore uses a priority inheritance mechanism so a task
687
* 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
688
* semaphore it is no longer required.
689
*
690
* Mutex type semaphores cannot be used from within interrupt service routines.
691
*
692
* See xSemaphoreCreateBinary() for an alternative implementation that can be
693
* used for pure synchronisation (where one task or interrupt always 'gives' the
694
* semaphore and another always 'takes' the semaphore) and from within interrupt
695
* service routines.
696
*
697
* @return If the mutex was successfully created then a handle to the created
698
* semaphore is returned. If there was not enough heap to allocate the mutex
699
* data structures then NULL is returned.
700
*
701
* Example usage:
702
<pre>
703
SemaphoreHandle_t xSemaphore;
704
705
void vATask( void * pvParameters )
706
{
707
// Semaphore cannot be used before a call to xSemaphoreCreateMutex().
708
// This is a macro so pass the variable in directly.
709
xSemaphore = xSemaphoreCreateMutex();
710
711
if( xSemaphore != NULL )
712
{
713
// The semaphore was created successfully.
714
// The semaphore can now be used.
715
}
716
}
717
</pre>
718
* \defgroup xSemaphoreCreateMutex xSemaphoreCreateMutex
719
* \ingroup Semaphores
720
*/
721
#if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
722
#define xSemaphoreCreateMutex() xQueueCreateMutex(queueQUEUE_TYPE_MUTEX)
723
#endif
724
725
/**
726
* semphr. h
727
* <pre>SemaphoreHandle_t xSemaphoreCreateMutexStatic( StaticSemaphore_t *pxMutexBuffer )</pre>
728
*
729
* Creates a new mutex type semaphore instance, and returns a handle by which
730
* the new mutex can be referenced.
731
*
732
* Internally, within the FreeRTOS implementation, mutex semaphores use a block
733
* of memory, in which the mutex structure is stored. If a mutex is created
734
* using xSemaphoreCreateMutex() then the required memory is automatically
735
* dynamically allocated inside the xSemaphoreCreateMutex() function. (see
736
* http://www.freertos.org/a00111.html). If a mutex is created using
737
* xSemaphoreCreateMutexStatic() then the application writer must provided the
738
* memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to be created
739
* without using any dynamic memory allocation.
740
*
741
* Mutexes created using this function can be accessed using the xSemaphoreTake()
742
* and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and
743
* xSemaphoreGiveRecursive() macros must not be used.
744
*
745
* This type of semaphore uses a priority inheritance mechanism so a task
746
* 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
747
* semaphore it is no longer required.
748
*
749
* Mutex type semaphores cannot be used from within interrupt service routines.
750
*
751
* See xSemaphoreCreateBinary() for an alternative implementation that can be
752
* used for pure synchronisation (where one task or interrupt always 'gives' the
753
* semaphore and another always 'takes' the semaphore) and from within interrupt
754
* service routines.
755
*
756
* @param pxMutexBuffer Must point to a variable of type StaticSemaphore_t,
757
* which will be used to hold the mutex's data structure, removing the need for
758
* the memory to be allocated dynamically.
759
*
760
* @return If the mutex was successfully created then a handle to the created
761
* mutex is returned. If pxMutexBuffer was NULL then NULL is returned.
762
*
763
* Example usage:
764
<pre>
765
SemaphoreHandle_t xSemaphore;
766
StaticSemaphore_t xMutexBuffer;
767
768
void vATask( void * pvParameters )
769
{
770
// A mutex cannot be used before it has been created. xMutexBuffer is
771
// into xSemaphoreCreateMutexStatic() so no dynamic memory allocation is
772
// attempted.
773
xSemaphore = xSemaphoreCreateMutexStatic( &xMutexBuffer );
774
775
// As no dynamic memory allocation was performed, xSemaphore cannot be NULL,
776
// so there is no need to check it.
777
}
778
</pre>
779
* \defgroup xSemaphoreCreateMutexStatic xSemaphoreCreateMutexStatic
780
* \ingroup Semaphores
781
*/
782
#if (configSUPPORT_STATIC_ALLOCATION == 1)
783
#define xSemaphoreCreateMutexStatic(pxMutexBuffer) xQueueCreateMutexStatic(queueQUEUE_TYPE_MUTEX, (pxMutexBuffer))
784
#endif
/* configSUPPORT_STATIC_ALLOCATION */
785
786
/**
787
* semphr. h
788
* <pre>SemaphoreHandle_t xSemaphoreCreateRecursiveMutex( void )</pre>
789
*
790
* Creates a new recursive mutex type semaphore instance, and returns a handle
791
* by which the new recursive mutex can be referenced.
792
*
793
* Internally, within the FreeRTOS implementation, recursive mutexs use a block
794
* of memory, in which the mutex structure is stored. If a recursive mutex is
795
* created using xSemaphoreCreateRecursiveMutex() then the required memory is
796
* automatically dynamically allocated inside the
797
* xSemaphoreCreateRecursiveMutex() function. (see
798
* http://www.freertos.org/a00111.html). If a recursive mutex is created using
799
* xSemaphoreCreateRecursiveMutexStatic() then the application writer must
800
* provide the memory that will get used by the mutex.
801
* xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to
802
* be created without using any dynamic memory allocation.
803
*
804
* Mutexes created using this macro can be accessed using the
805
* xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The
806
* xSemaphoreTake() and xSemaphoreGive() macros must not be used.
807
*
808
* A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
809
* doesn't become available again until the owner has called
810
* xSemaphoreGiveRecursive() for each successful 'take' request. For example,
811
* if a task successfully 'takes' the same mutex 5 times then the mutex will
812
* not be available to any other task until it has also 'given' the mutex back
813
* exactly five times.
814
*
815
* This type of semaphore uses a priority inheritance mechanism so a task
816
* 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
817
* semaphore it is no longer required.
818
*
819
* Mutex type semaphores cannot be used from within interrupt service routines.
820
*
821
* See xSemaphoreCreateBinary() for an alternative implementation that can be
822
* used for pure synchronisation (where one task or interrupt always 'gives' the
823
* semaphore and another always 'takes' the semaphore) and from within interrupt
824
* service routines.
825
*
826
* @return xSemaphore Handle to the created mutex semaphore. Should be of type
827
* SemaphoreHandle_t.
828
*
829
* Example usage:
830
<pre>
831
SemaphoreHandle_t xSemaphore;
832
833
void vATask( void * pvParameters )
834
{
835
// Semaphore cannot be used before a call to xSemaphoreCreateMutex().
836
// This is a macro so pass the variable in directly.
837
xSemaphore = xSemaphoreCreateRecursiveMutex();
838
839
if( xSemaphore != NULL )
840
{
841
// The semaphore was created successfully.
842
// The semaphore can now be used.
843
}
844
}
845
</pre>
846
* \defgroup xSemaphoreCreateRecursiveMutex xSemaphoreCreateRecursiveMutex
847
* \ingroup Semaphores
848
*/
849
#if ((configSUPPORT_DYNAMIC_ALLOCATION == 1) && (configUSE_RECURSIVE_MUTEXES == 1))
850
#define xSemaphoreCreateRecursiveMutex() xQueueCreateMutex(queueQUEUE_TYPE_RECURSIVE_MUTEX)
851
#endif
852
853
/**
854
* semphr. h
855
* <pre>SemaphoreHandle_t xSemaphoreCreateRecursiveMutexStatic( StaticSemaphore_t *pxMutexBuffer )</pre>
856
*
857
* Creates a new recursive mutex type semaphore instance, and returns a handle
858
* by which the new recursive mutex can be referenced.
859
*
860
* Internally, within the FreeRTOS implementation, recursive mutexs use a block
861
* of memory, in which the mutex structure is stored. If a recursive mutex is
862
* created using xSemaphoreCreateRecursiveMutex() then the required memory is
863
* automatically dynamically allocated inside the
864
* xSemaphoreCreateRecursiveMutex() function. (see
865
* http://www.freertos.org/a00111.html). If a recursive mutex is created using
866
* xSemaphoreCreateRecursiveMutexStatic() then the application writer must
867
* provide the memory that will get used by the mutex.
868
* xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to
869
* be created without using any dynamic memory allocation.
870
*
871
* Mutexes created using this macro can be accessed using the
872
* xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The
873
* xSemaphoreTake() and xSemaphoreGive() macros must not be used.
874
*
875
* A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
876
* doesn't become available again until the owner has called
877
* xSemaphoreGiveRecursive() for each successful 'take' request. For example,
878
* if a task successfully 'takes' the same mutex 5 times then the mutex will
879
* not be available to any other task until it has also 'given' the mutex back
880
* exactly five times.
881
*
882
* This type of semaphore uses a priority inheritance mechanism so a task
883
* 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
884
* semaphore it is no longer required.
885
*
886
* Mutex type semaphores cannot be used from within interrupt service routines.
887
*
888
* See xSemaphoreCreateBinary() for an alternative implementation that can be
889
* used for pure synchronisation (where one task or interrupt always 'gives' the
890
* semaphore and another always 'takes' the semaphore) and from within interrupt
891
* service routines.
892
*
893
* @param pxMutexBuffer Must point to a variable of type StaticSemaphore_t,
894
* which will then be used to hold the recursive mutex's data structure,
895
* removing the need for the memory to be allocated dynamically.
896
*
897
* @return If the recursive mutex was successfully created then a handle to the
898
* created recursive mutex is returned. If pxMutexBuffer was NULL then NULL is
899
* returned.
900
*
901
* Example usage:
902
<pre>
903
SemaphoreHandle_t xSemaphore;
904
StaticSemaphore_t xMutexBuffer;
905
906
void vATask( void * pvParameters )
907
{
908
// A recursive semaphore cannot be used before it is created. Here a
909
// recursive mutex is created using xSemaphoreCreateRecursiveMutexStatic().
910
// The address of xMutexBuffer is passed into the function, and will hold
911
// the mutexes data structures - so no dynamic memory allocation will be
912
// attempted.
913
xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xMutexBuffer );
914
915
// As no dynamic memory allocation was performed, xSemaphore cannot be NULL,
916
// so there is no need to check it.
917
}
918
</pre>
919
* \defgroup xSemaphoreCreateRecursiveMutexStatic xSemaphoreCreateRecursiveMutexStatic
920
* \ingroup Semaphores
921
*/
922
#if ((configSUPPORT_STATIC_ALLOCATION == 1) && (configUSE_RECURSIVE_MUTEXES == 1))
923
#define xSemaphoreCreateRecursiveMutexStatic(pxStaticSemaphore) \
924
xQueueCreateMutexStatic(queueQUEUE_TYPE_RECURSIVE_MUTEX, pxStaticSemaphore)
925
#endif
/* configSUPPORT_STATIC_ALLOCATION */
926
927
/**
928
* semphr. h
929
* <pre>SemaphoreHandle_t xSemaphoreCreateCounting( UBaseType_t uxMaxCount, UBaseType_t uxInitialCount )</pre>
930
*
931
* Creates a new counting semaphore instance, and returns a handle by which the
932
* new counting semaphore can be referenced.
933
*
934
* In many usage scenarios it is faster and more memory efficient to use a
935
* direct to task notification in place of a counting semaphore!
936
* http://www.freertos.org/RTOS-task-notifications.html
937
*
938
* Internally, within the FreeRTOS implementation, counting semaphores use a
939
* block of memory, in which the counting semaphore structure is stored. If a
940
* counting semaphore is created using xSemaphoreCreateCounting() then the
941
* required memory is automatically dynamically allocated inside the
942
* xSemaphoreCreateCounting() function. (see
943
* http://www.freertos.org/a00111.html). If a counting semaphore is created
944
* using xSemaphoreCreateCountingStatic() then the application writer can
945
* instead optionally provide the memory that will get used by the counting
946
* semaphore. xSemaphoreCreateCountingStatic() therefore allows a counting
947
* semaphore to be created without using any dynamic memory allocation.
948
*
949
* Counting semaphores are typically used for two things:
950
*
951
* 1) Counting events.
952
*
953
* In this usage scenario an event handler will 'give' a semaphore each time
954
* an event occurs (incrementing the semaphore count value), and a handler
955
* task will 'take' a semaphore each time it processes an event
956
* (decrementing the semaphore count value). The count value is therefore
957
* the difference between the number of events that have occurred and the
958
* number that have been processed. In this case it is desirable for the
959
* initial count value to be zero.
960
*
961
* 2) Resource management.
962
*
963
* In this usage scenario the count value indicates the number of resources
964
* available. To obtain control of a resource a task must first obtain a
965
* semaphore - decrementing the semaphore count value. When the count value
966
* reaches zero there are no free resources. When a task finishes with the
967
* resource it 'gives' the semaphore back - incrementing the semaphore count
968
* value. In this case it is desirable for the initial count value to be
969
* equal to the maximum count value, indicating that all resources are free.
970
*
971
* @param uxMaxCount The maximum count value that can be reached. When the
972
* semaphore reaches this value it can no longer be 'given'.
973
*
974
* @param uxInitialCount The count value assigned to the semaphore when it is
975
* created.
976
*
977
* @return Handle to the created semaphore. Null if the semaphore could not be
978
* created.
979
*
980
* Example usage:
981
<pre>
982
SemaphoreHandle_t xSemaphore;
983
984
void vATask( void * pvParameters )
985
{
986
SemaphoreHandle_t xSemaphore = NULL;
987
988
// Semaphore cannot be used before a call to xSemaphoreCreateCounting().
989
// The max value to which the semaphore can count should be 10, and the
990
// initial value assigned to the count should be 0.
991
xSemaphore = xSemaphoreCreateCounting( 10, 0 );
992
993
if( xSemaphore != NULL )
994
{
995
// The semaphore was created successfully.
996
// The semaphore can now be used.
997
}
998
}
999
</pre>
1000
* \defgroup xSemaphoreCreateCounting xSemaphoreCreateCounting
1001
* \ingroup Semaphores
1002
*/
1003
#if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
1004
#define xSemaphoreCreateCounting(uxMaxCount, uxInitialCount) \
1005
xQueueCreateCountingSemaphore((uxMaxCount), (uxInitialCount))
1006
#endif
1007
1008
/**
1009
* semphr. h
1010
* <pre>SemaphoreHandle_t xSemaphoreCreateCountingStatic( UBaseType_t uxMaxCount, UBaseType_t uxInitialCount, StaticSemaphore_t *pxSemaphoreBuffer )</pre>
1011
*
1012
* Creates a new counting semaphore instance, and returns a handle by which the
1013
* new counting semaphore can be referenced.
1014
*
1015
* In many usage scenarios it is faster and more memory efficient to use a
1016
* direct to task notification in place of a counting semaphore!
1017
* http://www.freertos.org/RTOS-task-notifications.html
1018
*
1019
* Internally, within the FreeRTOS implementation, counting semaphores use a
1020
* block of memory, in which the counting semaphore structure is stored. If a
1021
* counting semaphore is created using xSemaphoreCreateCounting() then the
1022
* required memory is automatically dynamically allocated inside the
1023
* xSemaphoreCreateCounting() function. (see
1024
* http://www.freertos.org/a00111.html). If a counting semaphore is created
1025
* using xSemaphoreCreateCountingStatic() then the application writer must
1026
* provide the memory. xSemaphoreCreateCountingStatic() therefore allows a
1027
* counting semaphore to be created without using any dynamic memory allocation.
1028
*
1029
* Counting semaphores are typically used for two things:
1030
*
1031
* 1) Counting events.
1032
*
1033
* In this usage scenario an event handler will 'give' a semaphore each time
1034
* an event occurs (incrementing the semaphore count value), and a handler
1035
* task will 'take' a semaphore each time it processes an event
1036
* (decrementing the semaphore count value). The count value is therefore
1037
* the difference between the number of events that have occurred and the
1038
* number that have been processed. In this case it is desirable for the
1039
* initial count value to be zero.
1040
*
1041
* 2) Resource management.
1042
*
1043
* In this usage scenario the count value indicates the number of resources
1044
* available. To obtain control of a resource a task must first obtain a
1045
* semaphore - decrementing the semaphore count value. When the count value
1046
* reaches zero there are no free resources. When a task finishes with the
1047
* resource it 'gives' the semaphore back - incrementing the semaphore count
1048
* value. In this case it is desirable for the initial count value to be
1049
* equal to the maximum count value, indicating that all resources are free.
1050
*
1051
* @param uxMaxCount The maximum count value that can be reached. When the
1052
* semaphore reaches this value it can no longer be 'given'.
1053
*
1054
* @param uxInitialCount The count value assigned to the semaphore when it is
1055
* created.
1056
*
1057
* @param pxSemaphoreBuffer Must point to a variable of type StaticSemaphore_t,
1058
* which will then be used to hold the semaphore's data structure, removing the
1059
* need for the memory to be allocated dynamically.
1060
*
1061
* @return If the counting semaphore was successfully created then a handle to
1062
* the created counting semaphore is returned. If pxSemaphoreBuffer was NULL
1063
* then NULL is returned.
1064
*
1065
* Example usage:
1066
<pre>
1067
SemaphoreHandle_t xSemaphore;
1068
StaticSemaphore_t xSemaphoreBuffer;
1069
1070
void vATask( void * pvParameters )
1071
{
1072
SemaphoreHandle_t xSemaphore = NULL;
1073
1074
// Counting semaphore cannot be used before they have been created. Create
1075
// a counting semaphore using xSemaphoreCreateCountingStatic(). The max
1076
// value to which the semaphore can count is 10, and the initial value
1077
// assigned to the count will be 0. The address of xSemaphoreBuffer is
1078
// passed in and will be used to hold the semaphore structure, so no dynamic
1079
// memory allocation will be used.
1080
xSemaphore = xSemaphoreCreateCounting( 10, 0, &xSemaphoreBuffer );
1081
1082
// No memory allocation was attempted so xSemaphore cannot be NULL, so there
1083
// is no need to check its value.
1084
}
1085
</pre>
1086
* \defgroup xSemaphoreCreateCountingStatic xSemaphoreCreateCountingStatic
1087
* \ingroup Semaphores
1088
*/
1089
#if (configSUPPORT_STATIC_ALLOCATION == 1)
1090
#define xSemaphoreCreateCountingStatic(uxMaxCount, uxInitialCount, pxSemaphoreBuffer) \
1091
xQueueCreateCountingSemaphoreStatic((uxMaxCount), (uxInitialCount), (pxSemaphoreBuffer))
1092
#endif
/* configSUPPORT_STATIC_ALLOCATION */
1093
1094
/**
1095
* semphr. h
1096
* <pre>void vSemaphoreDelete( SemaphoreHandle_t xSemaphore );</pre>
1097
*
1098
* Delete a semaphore. This function must be used with care. For example,
1099
* do not delete a mutex type semaphore if the mutex is held by a task.
1100
*
1101
* @param xSemaphore A handle to the semaphore to be deleted.
1102
*
1103
* \defgroup vSemaphoreDelete vSemaphoreDelete
1104
* \ingroup Semaphores
1105
*/
1106
#define vSemaphoreDelete(xSemaphore) vQueueDelete((QueueHandle_t)(xSemaphore))
1107
1108
/**
1109
* semphr.h
1110
* <pre>TaskHandle_t xSemaphoreGetMutexHolder( SemaphoreHandle_t xMutex );</pre>
1111
*
1112
* If xMutex is indeed a mutex type semaphore, return the current mutex holder.
1113
* If xMutex is not a mutex type semaphore, or the mutex is available (not held
1114
* by a task), return NULL.
1115
*
1116
* Note: This is a good way of determining if the calling task is the mutex
1117
* holder, but not a good way of determining the identity of the mutex holder as
1118
* the holder may change between the function exiting and the returned value
1119
* being tested.
1120
*/
1121
#define xSemaphoreGetMutexHolder(xSemaphore) xQueueGetMutexHolder((xSemaphore))
1122
1123
/**
1124
* semphr.h
1125
* <pre>TaskHandle_t xSemaphoreGetMutexHolderFromISR( SemaphoreHandle_t xMutex );</pre>
1126
*
1127
* If xMutex is indeed a mutex type semaphore, return the current mutex holder.
1128
* If xMutex is not a mutex type semaphore, or the mutex is available (not held
1129
* by a task), return NULL.
1130
*
1131
*/
1132
#define xSemaphoreGetMutexHolderFromISR(xSemaphore) xQueueGetMutexHolderFromISR((xSemaphore))
1133
1134
/**
1135
* semphr.h
1136
* <pre>UBaseType_t uxSemaphoreGetCount( SemaphoreHandle_t xSemaphore );</pre>
1137
*
1138
* If the semaphore is a counting semaphore then uxSemaphoreGetCount() returns
1139
* its current count value. If the semaphore is a binary semaphore then
1140
* uxSemaphoreGetCount() returns 1 if the semaphore is available, and 0 if the
1141
* semaphore is not available.
1142
*
1143
*/
1144
#define uxSemaphoreGetCount(xSemaphore) uxQueueMessagesWaiting((QueueHandle_t)(xSemaphore))
1145
1146
#endif
/* SEMAPHORE_H */
Generated on Sat Jan 18 2025 22:23:55 for GM6000 Digital Heater Controller by
1.9.8