]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - os/7.4.0/include/os/queue.h
Remove the name of the platform from the OS folder name
[pes-rpp/rpp-lib.git] / os / 7.4.0 / include / os / queue.h
1 /*
2     FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
3
4     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT
5     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     ***************************************************************************
8      *                                                                       *
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *
10      *    Complete, revised, and edited pdf reference manuals are also       *
11      *    available.                                                         *
12      *                                                                       *
13      *    Purchasing FreeRTOS documentation will not only help you, by       *
14      *    ensuring you get running as quickly as possible and with an        *
15      *    in-depth knowledge of how to use FreeRTOS, it will also help       *
16      *    the FreeRTOS project to continue with its mission of providing     *
17      *    professional grade, cross platform, de facto standard solutions    *
18      *    for microcontrollers - completely free of charge!                  *
19      *                                                                       *
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *
21      *                                                                       *
22      *    Thank you for using FreeRTOS, and thank you for your support!      *
23      *                                                                       *
24     ***************************************************************************
25
26
27     This file is part of the FreeRTOS distribution.
28
29     FreeRTOS is free software; you can redistribute it and/or modify it under
30     the terms of the GNU General Public License (version 2) as published by the
31     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
32
33     >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
34     distribute a combined work that includes FreeRTOS without being obliged to
35     provide the source code for proprietary components outside of the FreeRTOS
36     kernel.
37
38     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
39     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
40     FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
41     details. You should have received a copy of the GNU General Public License
42     and the FreeRTOS license exception along with FreeRTOS; if not itcan be
43     viewed here: http://www.freertos.org/a00114.html and also obtained by
44     writing to Real Time Engineers Ltd., contact details for whom are available
45     on the FreeRTOS WEB site.
46
47     1 tab == 4 spaces!
48
49     ***************************************************************************
50      *                                                                       *
51      *    Having a problem?  Start by reading the FAQ "My application does   *
52      *    not run, what could be wrong?"                                     *
53      *                                                                       *
54      *    http://www.FreeRTOS.org/FAQHelp.html                               *
55      *                                                                       *
56     ***************************************************************************
57
58
59     http://www.FreeRTOS.org - Documentation, books, training, latest versions,
60     license and Real Time Engineers Ltd. contact details.
61
62     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
63     including FreeRTOS+Trace - an indispensable productivity tool, and our new
64     fully thread aware and reentrant UDP/IP stack.
65
66     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
67     Integrity Systems, who sell the code with commercial support,
68     indemnification and middleware, under the OpenRTOS brand.
69
70     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
71     engineered and independently SIL3 certified version for use in safety and
72     mission critical applications that require provable dependability.
73 */
74
75
76 #ifndef QUEUE_H
77 #define QUEUE_H
78
79 #ifndef INC_FREERTOS_H
80     #error "include FreeRTOS.h" must appear in source files before "include queue.h"
81 #endif
82
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86
87
88 #include "os/mpu_wrappers.h"
89
90 /**
91  * Type by which queues are referenced.  For example, a call to xQueueCreate()
92  * returns an xQueueHandle variable that can then be used as a parameter to
93  * xQueueSend(), xQueueReceive(), etc.
94  */
95 typedef void * xQueueHandle;
96
97 /**
98  * Type by which queue sets are referenced.  For example, a call to
99  * xQueueCreateSet() returns an xQueueSet variable that can then be used as a
100  * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc.
101  */
102 typedef void * xQueueSetHandle;
103
104 /**
105  * Queue sets can contain both queues and semaphores, so the
106  * xQueueSetMemberHandle is defined as a type to be used where a parameter or
107  * return value can be either an xQueueHandle or an xSemaphoreHandle.
108  */
109 typedef void * xQueueSetMemberHandle;
110
111 /* For internal use only. */
112 #define queueSEND_TO_BACK   ( 0 )
113 #define queueSEND_TO_FRONT  ( 1 )
114
115 /* For internal use only.  These definitions *must* match those in queue.c. */
116 #define queueQUEUE_TYPE_BASE                ( 0U )
117 #define queueQUEUE_TYPE_SET                 ( 0U )
118 #define queueQUEUE_TYPE_MUTEX               ( 1U )
119 #define queueQUEUE_TYPE_COUNTING_SEMAPHORE  ( 2U )
120 #define queueQUEUE_TYPE_BINARY_SEMAPHORE    ( 3U )
121 #define queueQUEUE_TYPE_RECURSIVE_MUTEX     ( 4U )
122
123 /**
124  * queue. h
125  * <pre>
126  xQueueHandle xQueueCreate(
127                               unsigned portBASE_TYPE uxQueueLength,
128                               unsigned portBASE_TYPE uxItemSize
129                           );
130  * </pre>
131  *
132  * Creates a new queue instance.  This allocates the storage required by the
133  * new queue and returns a handle for the queue.
134  *
135  * @param uxQueueLength The maximum number of items that the queue can contain.
136  *
137  * @param uxItemSize The number of bytes each item in the queue will require.
138  * Items are queued by copy, not by reference, so this is the number of bytes
139  * that will be copied for each posted item.  Each item on the queue must be
140  * the same size.
141  *
142  * @return If the queue is successfully create then a handle to the newly
143  * created queue is returned.  If the queue cannot be created then 0 is
144  * returned.
145  *
146  * Example usage:
147    <pre>
148  struct AMessage
149  {
150     char ucMessageID;
151     char ucData[ 20 ];
152  };
153
154  void vATask( void *pvParameters )
155  {
156  xQueueHandle xQueue1, xQueue2;
157
158     // Create a queue capable of containing 10 unsigned long values.
159     xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
160     if( xQueue1 == 0 )
161     {
162         // Queue was not created and must not be used.
163     }
164
165     // Create a queue capable of containing 10 pointers to AMessage structures.
166     // These should be passed by pointer as they contain a lot of data.
167     xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
168     if( xQueue2 == 0 )
169     {
170         // Queue was not created and must not be used.
171     }
172
173     // ... Rest of task code.
174  }
175  </pre>
176  * @ingroup QueueManagement
177  */
178 #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( uxQueueLength, uxItemSize, queueQUEUE_TYPE_BASE )
179
180 /**
181  * queue. h
182  * <pre>
183  portBASE_TYPE xQueueSendToToFront(
184                                    xQueueHandle xQueue,
185                                    const void   *   pvItemToQueue,
186                                    portTickType xTicksToWait
187                                );
188  * </pre>
189  *
190  * This is a macro that calls xQueueGenericSend().
191  *
192  * Post an item to the front of a queue.  The item is queued by copy, not by
193  * reference.  This function must not be called from an interrupt service
194  * routine.  See xQueueSendFromISR () for an alternative which may be used
195  * in an ISR.
196  *
197  * @param xQueue The handle to the queue on which the item is to be posted.
198  *
199  * @param pvItemToQueue A pointer to the item that is to be placed on the
200  * queue.  The size of the items the queue will hold was defined when the
201  * queue was created, so this many bytes will be copied from pvItemToQueue
202  * into the queue storage area.
203  *
204  * @param xTicksToWait The maximum amount of time the task should block
205  * waiting for space to become available on the queue, should it already
206  * be full.  The call will return immediately if this is set to 0 and the
207  * queue is full.  The time is defined in tick periods so the constant
208  * portTICK_RATE_MS should be used to convert to real time if this is required.
209  *
210  * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
211  *
212  * Example usage:
213    <pre>
214  struct AMessage
215  {
216     char ucMessageID;
217     char ucData[ 20 ];
218  } xMessage;
219
220  unsigned long ulVar = 10UL;
221
222  void vATask( void *pvParameters )
223  {
224  xQueueHandle xQueue1, xQueue2;
225  struct AMessage *pxMessage;
226
227     // Create a queue capable of containing 10 unsigned long values.
228     xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
229
230     // Create a queue capable of containing 10 pointers to AMessage structures.
231     // These should be passed by pointer as they contain a lot of data.
232     xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
233
234     // ...
235
236     if( xQueue1 != 0 )
237     {
238         // Send an unsigned long.  Wait for 10 ticks for space to become
239         // available if necessary.
240         if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
241         {
242             // Failed to post the message, even after 10 ticks.
243         }
244     }
245
246     if( xQueue2 != 0 )
247     {
248         // Send a pointer to a struct AMessage object.  Don't block if the
249         // queue is already full.
250         pxMessage = & xMessage;
251         xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
252     }
253
254     // ... Rest of task code.
255  }
256  </pre>
257  * @ingroup QueueManagement
258  */
259 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
260
261 /**
262  * queue. h
263  * <pre>
264  portBASE_TYPE xQueueSendToBack(
265                                    xQueueHandle xQueue,
266                                    const    void    *   pvItemToQueue,
267                                    portTickType xTicksToWait
268                                );
269  * </pre>
270  *
271  * This is a macro that calls xQueueGenericSend().
272  *
273  * Post an item to the back of a queue.  The item is queued by copy, not by
274  * reference.  This function must not be called from an interrupt service
275  * routine.  See xQueueSendFromISR () for an alternative which may be used
276  * in an ISR.
277  *
278  * @param xQueue The handle to the queue on which the item is to be posted.
279  *
280  * @param pvItemToQueue A pointer to the item that is to be placed on the
281  * queue.  The size of the items the queue will hold was defined when the
282  * queue was created, so this many bytes will be copied from pvItemToQueue
283  * into the queue storage area.
284  *
285  * @param xTicksToWait The maximum amount of time the task should block
286  * waiting for space to become available on the queue, should it already
287  * be full.  The call will return immediately if this is set to 0 and the queue
288  * is full.  The  time is defined in tick periods so the constant
289  * portTICK_RATE_MS should be used to convert to real time if this is required.
290  *
291  * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
292  *
293  * Example usage:
294    <pre>
295  struct AMessage
296  {
297     char ucMessageID;
298     char ucData[ 20 ];
299  } xMessage;
300
301  unsigned long ulVar = 10UL;
302
303  void vATask( void *pvParameters )
304  {
305  xQueueHandle xQueue1, xQueue2;
306  struct AMessage *pxMessage;
307
308     // Create a queue capable of containing 10 unsigned long values.
309     xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
310
311     // Create a queue capable of containing 10 pointers to AMessage structures.
312     // These should be passed by pointer as they contain a lot of data.
313     xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
314
315     // ...
316
317     if( xQueue1 != 0 )
318     {
319         // Send an unsigned long.  Wait for 10 ticks for space to become
320         // available if necessary.
321         if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
322         {
323             // Failed to post the message, even after 10 ticks.
324         }
325     }
326
327     if( xQueue2 != 0 )
328     {
329         // Send a pointer to a struct AMessage object.  Don't block if the
330         // queue is already full.
331         pxMessage = & xMessage;
332         xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
333     }
334
335     // ... Rest of task code.
336  }
337  </pre>
338  * @ingroup QueueManagement
339  */
340 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
341
342 /**
343  * queue. h
344  * <pre>
345  portBASE_TYPE xQueueSend(
346                               xQueueHandle xQueue,
347                               const void * pvItemToQueue,
348                               portTickType xTicksToWait
349                          );
350  * </pre>
351  *
352  * This is a macro that calls xQueueGenericSend().  It is included for
353  * backward compatibility with versions of FreeRTOS.org that did not
354  * include the xQueueSendToFront() and xQueueSendToBack() macros.  It is
355  * equivalent to xQueueSendToBack().
356  *
357  * Post an item on a queue.  The item is queued by copy, not by reference.
358  * This function must not be called from an interrupt service routine.
359  * See xQueueSendFromISR () for an alternative which may be used in an ISR.
360  *
361  * @param xQueue The handle to the queue on which the item is to be posted.
362  *
363  * @param pvItemToQueue A pointer to the item that is to be placed on the
364  * queue.  The size of the items the queue will hold was defined when the
365  * queue was created, so this many bytes will be copied from pvItemToQueue
366  * into the queue storage area.
367  *
368  * @param xTicksToWait The maximum amount of time the task should block
369  * waiting for space to become available on the queue, should it already
370  * be full.  The call will return immediately if this is set to 0 and the
371  * queue is full.  The time is defined in tick periods so the constant
372  * portTICK_RATE_MS should be used to convert to real time if this is required.
373  *
374  * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
375  *
376  * Example usage:
377    <pre>
378  struct AMessage
379  {
380     char ucMessageID;
381     char ucData[ 20 ];
382  } xMessage;
383
384  unsigned long ulVar = 10UL;
385
386  void vATask( void *pvParameters )
387  {
388  xQueueHandle xQueue1, xQueue2;
389  struct AMessage *pxMessage;
390
391     // Create a queue capable of containing 10 unsigned long values.
392     xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
393
394     // Create a queue capable of containing 10 pointers to AMessage structures.
395     // These should be passed by pointer as they contain a lot of data.
396     xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
397
398     // ...
399
400     if( xQueue1 != 0 )
401     {
402         // Send an unsigned long.  Wait for 10 ticks for space to become
403         // available if necessary.
404         if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
405         {
406             // Failed to post the message, even after 10 ticks.
407         }
408     }
409
410     if( xQueue2 != 0 )
411     {
412         // Send a pointer to a struct AMessage object.  Don't block if the
413         // queue is already full.
414         pxMessage = & xMessage;
415         xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
416     }
417
418     // ... Rest of task code.
419  }
420  </pre>
421  * @ingroup QueueManagement
422  */
423 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
424
425
426 /**
427  * queue. h
428  * <pre>
429  portBASE_TYPE xQueueGenericSend(
430                                     xQueueHandle xQueue,
431                                     const void * pvItemToQueue,
432                                     portTickType xTicksToWait
433                                     portBASE_TYPE xCopyPosition
434                                 );
435  * </pre>
436  *
437  * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
438  * xQueueSendToBack() are used in place of calling this function directly.
439  *
440  * Post an item on a queue.  The item is queued by copy, not by reference.
441  * This function must not be called from an interrupt service routine.
442  * See xQueueSendFromISR () for an alternative which may be used in an ISR.
443  *
444  * @param xQueue The handle to the queue on which the item is to be posted.
445  *
446  * @param pvItemToQueue A pointer to the item that is to be placed on the
447  * queue.  The size of the items the queue will hold was defined when the
448  * queue was created, so this many bytes will be copied from pvItemToQueue
449  * into the queue storage area.
450  *
451  * @param xTicksToWait The maximum amount of time the task should block
452  * waiting for space to become available on the queue, should it already
453  * be full.  The call will return immediately if this is set to 0 and the
454  * queue is full.  The time is defined in tick periods so the constant
455  * portTICK_RATE_MS should be used to convert to real time if this is required.
456  *
457  * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
458  * item at the back of the queue, or queueSEND_TO_FRONT to place the item
459  * at the front of the queue (for high priority messages).
460  *
461  * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
462  *
463  * Example usage:
464    <pre>
465  struct AMessage
466  {
467     char ucMessageID;
468     char ucData[ 20 ];
469  } xMessage;
470
471  unsigned long ulVar = 10UL;
472
473  void vATask( void *pvParameters )
474  {
475  xQueueHandle xQueue1, xQueue2;
476  struct AMessage *pxMessage;
477
478     // Create a queue capable of containing 10 unsigned long values.
479     xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
480
481     // Create a queue capable of containing 10 pointers to AMessage structures.
482     // These should be passed by pointer as they contain a lot of data.
483     xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
484
485     // ...
486
487     if( xQueue1 != 0 )
488     {
489         // Send an unsigned long.  Wait for 10 ticks for space to become
490         // available if necessary.
491         if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
492         {
493             // Failed to post the message, even after 10 ticks.
494         }
495     }
496
497     if( xQueue2 != 0 )
498     {
499         // Send a pointer to a struct AMessage object.  Don't block if the
500         // queue is already full.
501         pxMessage = & xMessage;
502         xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
503     }
504
505     // ... Rest of task code.
506  }
507  </pre>
508  * @ingroup QueueManagement
509  */
510 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
511
512 /**
513  * queue. h
514  * <pre>
515  portBASE_TYPE xQueuePeek(
516                              xQueueHandle xQueue,
517                              void *pvBuffer,
518                              portTickType xTicksToWait
519                          );</pre>
520  *
521  * This is a macro that calls the xQueueGenericReceive() function.
522  *
523  * Receive an item from a queue without removing the item from the queue.
524  * The item is received by copy so a buffer of adequate size must be
525  * provided.  The number of bytes copied into the buffer was defined when
526  * the queue was created.
527  *
528  * Successfully received items remain on the queue so will be returned again
529  * by the next call, or a call to xQueueReceive().
530  *
531  * This macro must not be used in an interrupt service routine.
532  *
533  * @param xQueue The handle to the queue from which the item is to be
534  * received.
535  *
536  * @param pvBuffer Pointer to the buffer into which the received item will
537  * be copied.
538  *
539  * @param xTicksToWait The maximum amount of time the task should block
540  * waiting for an item to receive should the queue be empty at the time
541  * of the call.  The time is defined in tick periods so the constant
542  * portTICK_RATE_MS should be used to convert to real time if this is required.
543  * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
544  * is empty.
545  *
546  * @return pdTRUE if an item was successfully received from the queue,
547  * otherwise pdFALSE.
548  *
549  * Example usage:
550    <pre>
551  struct AMessage
552  {
553     char ucMessageID;
554     char ucData[ 20 ];
555  } xMessage;
556
557  xQueueHandle xQueue;
558
559  // Task to create a queue and post a value.
560  void vATask( void *pvParameters )
561  {
562  struct AMessage *pxMessage;
563
564     // Create a queue capable of containing 10 pointers to AMessage structures.
565     // These should be passed by pointer as they contain a lot of data.
566     xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
567     if( xQueue == 0 )
568     {
569         // Failed to create the queue.
570     }
571
572     // ...
573
574     // Send a pointer to a struct AMessage object.  Don't block if the
575     // queue is already full.
576     pxMessage = & xMessage;
577     xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
578
579     // ... Rest of task code.
580  }
581
582  // Task to peek the data from the queue.
583  void vADifferentTask( void *pvParameters )
584  {
585  struct AMessage *pxRxedMessage;
586
587     if( xQueue != 0 )
588     {
589         // Peek a message on the created queue.  Block for 10 ticks if a
590         // message is not immediately available.
591         if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
592         {
593             // pcRxedMessage now points to the struct AMessage variable posted
594             // by vATask, but the item still remains on the queue.
595         }
596     }
597
598     // ... Rest of task code.
599  }
600  </pre>
601  * @ingroup QueueManagement
602  */
603 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
604
605 /**
606  * queue. h
607  * <pre>
608  portBASE_TYPE xQueueReceive(
609                                  xQueueHandle xQueue,
610                                  void *pvBuffer,
611                                  portTickType xTicksToWait
612                             );</pre>
613  *
614  * This is a macro that calls the xQueueGenericReceive() function.
615  *
616  * Receive an item from a queue.  The item is received by copy so a buffer of
617  * adequate size must be provided.  The number of bytes copied into the buffer
618  * was defined when the queue was created.
619  *
620  * Successfully received items are removed from the queue.
621  *
622  * This function must not be used in an interrupt service routine.  See
623  * xQueueReceiveFromISR for an alternative that can.
624  *
625  * @param xQueue The handle to the queue from which the item is to be
626  * received.
627  *
628  * @param pvBuffer Pointer to the buffer into which the received item will
629  * be copied.
630  *
631  * @param xTicksToWait The maximum amount of time the task should block
632  * waiting for an item to receive should the queue be empty at the time
633  * of the call.  xQueueReceive() will return immediately if xTicksToWait
634  * is zero and the queue is empty.  The time is defined in tick periods so the
635  * constant portTICK_RATE_MS should be used to convert to real time if this is
636  * required.
637  *
638  * @return pdTRUE if an item was successfully received from the queue,
639  * otherwise pdFALSE.
640  *
641  * Example usage:
642    <pre>
643  struct AMessage
644  {
645     char ucMessageID;
646     char ucData[ 20 ];
647  } xMessage;
648
649  xQueueHandle xQueue;
650
651  // Task to create a queue and post a value.
652  void vATask( void *pvParameters )
653  {
654  struct AMessage *pxMessage;
655
656     // Create a queue capable of containing 10 pointers to AMessage structures.
657     // These should be passed by pointer as they contain a lot of data.
658     xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
659     if( xQueue == 0 )
660     {
661         // Failed to create the queue.
662     }
663
664     // ...
665
666     // Send a pointer to a struct AMessage object.  Don't block if the
667     // queue is already full.
668     pxMessage = & xMessage;
669     xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
670
671     // ... Rest of task code.
672  }
673
674  // Task to receive from the queue.
675  void vADifferentTask( void *pvParameters )
676  {
677  struct AMessage *pxRxedMessage;
678
679     if( xQueue != 0 )
680     {
681         // Receive a message on the created queue.  Block for 10 ticks if a
682         // message is not immediately available.
683         if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
684         {
685             // pcRxedMessage now points to the struct AMessage variable posted
686             // by vATask.
687         }
688     }
689
690     // ... Rest of task code.
691  }
692  </pre>
693  * @ingroup QueueManagement
694  */
695 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
696
697
698 /**
699  * queue. h
700  * <pre>
701  portBASE_TYPE xQueueGenericReceive(
702                                        xQueueHandle xQueue,
703                                        void *pvBuffer,
704                                        portTickType xTicksToWait
705                                        portBASE_TYPE    xJustPeek
706                                     );</pre>
707  *
708  * It is preferred that the macro xQueueReceive() be used rather than calling
709  * this function directly.
710  *
711  * Receive an item from a queue.  The item is received by copy so a buffer of
712  * adequate size must be provided.  The number of bytes copied into the buffer
713  * was defined when the queue was created.
714  *
715  * This function must not be used in an interrupt service routine.  See
716  * xQueueReceiveFromISR for an alternative that can.
717  *
718  * @param xQueue The handle to the queue from which the item is to be
719  * received.
720  *
721  * @param pvBuffer Pointer to the buffer into which the received item will
722  * be copied.
723  *
724  * @param xTicksToWait The maximum amount of time the task should block
725  * waiting for an item to receive should the queue be empty at the time
726  * of the call.  The time is defined in tick periods so the constant
727  * portTICK_RATE_MS should be used to convert to real time if this is required.
728  * xQueueGenericReceive() will return immediately if the queue is empty and
729  * xTicksToWait is 0.
730  *
731  * @param xJustPeek When set to true, the item received from the queue is not
732  * actually removed from the queue - meaning a subsequent call to
733  * xQueueReceive() will return the same item.  When set to false, the item
734  * being received from the queue is also removed from the queue.
735  *
736  * @return pdTRUE if an item was successfully received from the queue,
737  * otherwise pdFALSE.
738  *
739  * Example usage:
740    <pre>
741  struct AMessage
742  {
743     char ucMessageID;
744     char ucData[ 20 ];
745  } xMessage;
746
747  xQueueHandle xQueue;
748
749  // Task to create a queue and post a value.
750  void vATask( void *pvParameters )
751  {
752  struct AMessage *pxMessage;
753
754     // Create a queue capable of containing 10 pointers to AMessage structures.
755     // These should be passed by pointer as they contain a lot of data.
756     xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
757     if( xQueue == 0 )
758     {
759         // Failed to create the queue.
760     }
761
762     // ...
763
764     // Send a pointer to a struct AMessage object.  Don't block if the
765     // queue is already full.
766     pxMessage = & xMessage;
767     xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
768
769     // ... Rest of task code.
770  }
771
772  // Task to receive from the queue.
773  void vADifferentTask( void *pvParameters )
774  {
775  struct AMessage *pxRxedMessage;
776
777     if( xQueue != 0 )
778     {
779         // Receive a message on the created queue.  Block for 10 ticks if a
780         // message is not immediately available.
781         if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
782         {
783             // pcRxedMessage now points to the struct AMessage variable posted
784             // by vATask.
785         }
786     }
787
788     // ... Rest of task code.
789  }
790  </pre>
791  * @ingroup QueueManagement
792  */
793 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
794
795 /**
796  * queue. h
797  * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
798  *
799  * Return the number of messages stored in a queue.
800  *
801  * @param xQueue A handle to the queue being queried.
802  *
803  * @return The number of messages available in the queue.
804  *
805  * @ingroup QueueManagement
806  */
807 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
808
809 /**
810  * queue. h
811  * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
812  *
813  * Delete a queue - freeing all the memory allocated for storing of items
814  * placed on the queue.
815  *
816  * @param xQueue A handle to the queue to be deleted.
817  *
818  * @ingroup QueueManagement
819  */
820 void vQueueDelete( xQueueHandle xQueue );
821
822 /**
823  * queue. h
824  * <pre>
825  portBASE_TYPE xQueueSendToFrontFromISR(
826                                          xQueueHandle xQueue,
827                                          const void *pvItemToQueue,
828                                          portBASE_TYPE *pxHigherPriorityTaskWoken
829                                       );
830  </pre>
831  *
832  * This is a macro that calls xQueueGenericSendFromISR().
833  *
834  * Post an item to the front of a queue.  It is safe to use this macro from
835  * within an interrupt service routine.
836  *
837  * Items are queued by copy not reference so it is preferable to only
838  * queue small items, especially when called from an ISR.  In most cases
839  * it would be preferable to store a pointer to the item being queued.
840  *
841  * @param xQueue The handle to the queue on which the item is to be posted.
842  *
843  * @param pvItemToQueue A pointer to the item that is to be placed on the
844  * queue.  The size of the items the queue will hold was defined when the
845  * queue was created, so this many bytes will be copied from pvItemToQueue
846  * into the queue storage area.
847  *
848  * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
849  * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
850  * to unblock, and the unblocked task has a priority higher than the currently
851  * running task.  If xQueueSendToFromFromISR() sets this value to pdTRUE then
852  * a context switch should be requested before the interrupt is exited.
853  *
854  * @return pdTRUE if the data was successfully sent to the queue, otherwise
855  * errQUEUE_FULL.
856  *
857  * Example usage for buffered IO (where the ISR can obtain more than one value
858  * per call):
859    <pre>
860  void vBufferISR( void )
861  {
862  char cIn;
863  portBASE_TYPE xHigherPrioritTaskWoken;
864
865     // We have not woken a task at the start of the ISR.
866     xHigherPriorityTaskWoken = pdFALSE;
867
868     // Loop until the buffer is empty.
869     do
870     {
871         // Obtain a byte from the buffer.
872         cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
873
874         // Post the byte.
875         xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
876
877     } while( portINPUT_BYTE( BUFFER_COUNT ) );
878
879     // Now the buffer is empty we can switch context if necessary.
880     if( xHigherPriorityTaskWoken )
881     {
882         taskYIELD ();
883     }
884  }
885  </pre>
886  *
887  * @ingroup QueueManagement
888  */
889 #define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
890
891
892 /**
893  * queue. h
894  * <pre>
895  portBASE_TYPE xQueueSendToBackFromISR(
896                                          xQueueHandle xQueue,
897                                          const void *pvItemToQueue,
898                                          portBASE_TYPE *pxHigherPriorityTaskWoken
899                                       );
900  </pre>
901  *
902  * This is a macro that calls xQueueGenericSendFromISR().
903  *
904  * Post an item to the back of a queue.  It is safe to use this macro from
905  * within an interrupt service routine.
906  *
907  * Items are queued by copy not reference so it is preferable to only
908  * queue small items, especially when called from an ISR.  In most cases
909  * it would be preferable to store a pointer to the item being queued.
910  *
911  * @param xQueue The handle to the queue on which the item is to be posted.
912  *
913  * @param pvItemToQueue A pointer to the item that is to be placed on the
914  * queue.  The size of the items the queue will hold was defined when the
915  * queue was created, so this many bytes will be copied from pvItemToQueue
916  * into the queue storage area.
917  *
918  * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
919  * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
920  * to unblock, and the unblocked task has a priority higher than the currently
921  * running task.  If xQueueSendToBackFromISR() sets this value to pdTRUE then
922  * a context switch should be requested before the interrupt is exited.
923  *
924  * @return pdTRUE if the data was successfully sent to the queue, otherwise
925  * errQUEUE_FULL.
926  *
927  * Example usage for buffered IO (where the ISR can obtain more than one value
928  * per call):
929    <pre>
930  void vBufferISR( void )
931  {
932  char cIn;
933  portBASE_TYPE xHigherPriorityTaskWoken;
934
935     // We have not woken a task at the start of the ISR.
936     xHigherPriorityTaskWoken = pdFALSE;
937
938     // Loop until the buffer is empty.
939     do
940     {
941         // Obtain a byte from the buffer.
942         cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
943
944         // Post the byte.
945         xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
946
947     } while( portINPUT_BYTE( BUFFER_COUNT ) );
948
949     // Now the buffer is empty we can switch context if necessary.
950     if( xHigherPriorityTaskWoken )
951     {
952         taskYIELD ();
953     }
954  }
955  </pre>
956  *
957  * @ingroup QueueManagement
958  */
959 #define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
960
961 /**
962  * queue. h
963  * <pre>
964  portBASE_TYPE xQueueSendFromISR(
965                                      xQueueHandle xQueue,
966                                      const void *pvItemToQueue,
967                                      portBASE_TYPE *pxHigherPriorityTaskWoken
968                                 );
969  </pre>
970  *
971  * This is a macro that calls xQueueGenericSendFromISR().  It is included
972  * for backward compatibility with versions of FreeRTOS.org that did not
973  * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
974  * macros.
975  *
976  * Post an item to the back of a queue.  It is safe to use this function from
977  * within an interrupt service routine.
978  *
979  * Items are queued by copy not reference so it is preferable to only
980  * queue small items, especially when called from an ISR.  In most cases
981  * it would be preferable to store a pointer to the item being queued.
982  *
983  * @param xQueue The handle to the queue on which the item is to be posted.
984  *
985  * @param pvItemToQueue A pointer to the item that is to be placed on the
986  * queue.  The size of the items the queue will hold was defined when the
987  * queue was created, so this many bytes will be copied from pvItemToQueue
988  * into the queue storage area.
989  *
990  * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
991  * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
992  * to unblock, and the unblocked task has a priority higher than the currently
993  * running task.  If xQueueSendFromISR() sets this value to pdTRUE then
994  * a context switch should be requested before the interrupt is exited.
995  *
996  * @return pdTRUE if the data was successfully sent to the queue, otherwise
997  * errQUEUE_FULL.
998  *
999  * Example usage for buffered IO (where the ISR can obtain more than one value
1000  * per call):
1001    <pre>
1002  void vBufferISR( void )
1003  {
1004  char cIn;
1005  portBASE_TYPE xHigherPriorityTaskWoken;
1006
1007     // We have not woken a task at the start of the ISR.
1008     xHigherPriorityTaskWoken = pdFALSE;
1009
1010     // Loop until the buffer is empty.
1011     do
1012     {
1013         // Obtain a byte from the buffer.
1014         cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1015
1016         // Post the byte.
1017         xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1018
1019     } while( portINPUT_BYTE( BUFFER_COUNT ) );
1020
1021     // Now the buffer is empty we can switch context if necessary.
1022     if( xHigherPriorityTaskWoken )
1023     {
1024         // Actual macro used here is port specific.
1025         taskYIELD_FROM_ISR ();
1026     }
1027  }
1028  </pre>
1029  *
1030  * @ingroup QueueManagement
1031  */
1032 #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1033
1034 /**
1035  * queue. h
1036  * <pre>
1037  portBASE_TYPE xQueueGenericSendFromISR(
1038                                            xQueueHandle     xQueue,
1039                                            const    void    *pvItemToQueue,
1040                                            portBASE_TYPE    *pxHigherPriorityTaskWoken,
1041                                            portBASE_TYPE    xCopyPosition
1042                                        );
1043  </pre>
1044  *
1045  * It is preferred that the macros xQueueSendFromISR(),
1046  * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
1047  * of calling this function directly.
1048  *
1049  * Post an item on a queue.  It is safe to use this function from within an
1050  * interrupt service routine.
1051  *
1052  * Items are queued by copy not reference so it is preferable to only
1053  * queue small items, especially when called from an ISR.  In most cases
1054  * it would be preferable to store a pointer to the item being queued.
1055  *
1056  * @param xQueue The handle to the queue on which the item is to be posted.
1057  *
1058  * @param pvItemToQueue A pointer to the item that is to be placed on the
1059  * queue.  The size of the items the queue will hold was defined when the
1060  * queue was created, so this many bytes will be copied from pvItemToQueue
1061  * into the queue storage area.
1062  *
1063  * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
1064  * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1065  * to unblock, and the unblocked task has a priority higher than the currently
1066  * running task.  If xQueueGenericSendFromISR() sets this value to pdTRUE then
1067  * a context switch should be requested before the interrupt is exited.
1068  *
1069  * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
1070  * item at the back of the queue, or queueSEND_TO_FRONT to place the item
1071  * at the front of the queue (for high priority messages).
1072  *
1073  * @return pdTRUE if the data was successfully sent to the queue, otherwise
1074  * errQUEUE_FULL.
1075  *
1076  * Example usage for buffered IO (where the ISR can obtain more than one value
1077  * per call):
1078    <pre>
1079  void vBufferISR( void )
1080  {
1081  char cIn;
1082  portBASE_TYPE xHigherPriorityTaskWokenByPost;
1083
1084     // We have not woken a task at the start of the ISR.
1085     xHigherPriorityTaskWokenByPost = pdFALSE;
1086
1087     // Loop until the buffer is empty.
1088     do
1089     {
1090         // Obtain a byte from the buffer.
1091         cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1092
1093         // Post each byte.
1094         xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
1095
1096     } while( portINPUT_BYTE( BUFFER_COUNT ) );
1097
1098     // Now the buffer is empty we can switch context if necessary.  Note that the
1099     // name of the yield function required is port specific.
1100     if( xHigherPriorityTaskWokenByPost )
1101     {
1102         taskYIELD_YIELD_FROM_ISR();
1103     }
1104  }
1105  </pre>
1106  *
1107  * @ingroup QueueManagement
1108  */
1109 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle xQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
1110
1111 /**
1112  * queue. h
1113  * <pre>
1114  portBASE_TYPE xQueueReceiveFromISR(
1115                                        xQueueHandle xQueue,
1116                                        void *pvBuffer,
1117                                        portBASE_TYPE *pxTaskWoken
1118                                    );
1119  * </pre>
1120  *
1121  * Receive an item from a queue.  It is safe to use this function from within an
1122  * interrupt service routine.
1123  *
1124  * @param xQueue The handle to the queue from which the item is to be
1125  * received.
1126  *
1127  * @param pvBuffer Pointer to the buffer into which the received item will
1128  * be copied.
1129  *
1130  * @param pxTaskWoken A task may be blocked waiting for space to become
1131  * available on the queue.  If xQueueReceiveFromISR causes such a task to
1132  * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
1133  * remain unchanged.
1134  *
1135  * @return pdTRUE if an item was successfully received from the queue,
1136  * otherwise pdFALSE.
1137  *
1138  * Example usage:
1139    <pre>
1140
1141  xQueueHandle xQueue;
1142
1143  // Function to create a queue and post some values.
1144  void vAFunction( void *pvParameters )
1145  {
1146  char cValueToPost;
1147  const portTickType xBlockTime = ( portTickType )0xff;
1148
1149     // Create a queue capable of containing 10 characters.
1150     xQueue = xQueueCreate( 10, sizeof( char ) );
1151     if( xQueue == 0 )
1152     {
1153         // Failed to create the queue.
1154     }
1155
1156     // ...
1157
1158     // Post some characters that will be used within an ISR.  If the queue
1159     // is full then this task will block for xBlockTime ticks.
1160     cValueToPost = 'a';
1161     xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
1162     cValueToPost = 'b';
1163     xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
1164
1165     // ... keep posting characters ... this task may block when the queue
1166     // becomes full.
1167
1168     cValueToPost = 'c';
1169     xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
1170  }
1171
1172  // ISR that outputs all the characters received on the queue.
1173  void vISR_Routine( void )
1174  {
1175  portBASE_TYPE xTaskWokenByReceive = pdFALSE;
1176  char cRxedChar;
1177
1178     while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
1179     {
1180         // A character was received.  Output the character now.
1181         vOutputCharacter( cRxedChar );
1182
1183         // If removing the character from the queue woke the task that was
1184         // posting onto the queue cTaskWokenByReceive will have been set to
1185         // pdTRUE.  No matter how many times this loop iterates only one
1186         // task will be woken.
1187     }
1188
1189     if( cTaskWokenByPost != ( char ) pdFALSE;
1190     {
1191         taskYIELD ();
1192     }
1193  }
1194  </pre>
1195  * @ingroup QueueManagement
1196  */
1197 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken );
1198
1199 /*
1200  * Utilities to query queues that are safe to use from an ISR.  These utilities
1201  * should be used only from witin an ISR, or within a critical section.
1202  */
1203 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle xQueue );
1204 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle xQueue );
1205 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle xQueue );
1206
1207
1208 /*
1209  * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
1210  * Likewise xQueueAltGenericReceive() is an alternative version of
1211  * xQueueGenericReceive().
1212  *
1213  * The source code that implements the alternative (Alt) API is much
1214  * simpler  because it executes everything from within a critical section.
1215  * This is  the approach taken by many other RTOSes, but FreeRTOS.org has the
1216  * preferred fully featured API too.  The fully featured API has more
1217  * complex  code that takes longer to execute, but makes much less use of
1218  * critical sections.  Therefore the alternative API sacrifices interrupt
1219  * responsiveness to gain execution speed, whereas the fully featured API
1220  * sacrifices execution speed to ensure better interrupt responsiveness.
1221  */
1222 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
1223 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
1224 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
1225 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
1226 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
1227 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
1228
1229 /*
1230  * The functions defined above are for passing data to and from tasks.  The
1231  * functions below are the equivalents for passing data to and from
1232  * co-routines.
1233  *
1234  * These functions are called from the co-routine macro implementation and
1235  * should not be called directly from application code.  Instead use the macro
1236  * wrappers defined within croutine.h.
1237  */
1238 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle xQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
1239 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle xQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
1240 signed portBASE_TYPE xQueueCRSend( xQueueHandle xQueue, const void *pvItemToQueue, portTickType xTicksToWait );
1241 signed portBASE_TYPE xQueueCRReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait );
1242
1243 /*
1244  * For internal use only.  Use xSemaphoreCreateMutex(),
1245  * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
1246  * these functions directly.
1247  */
1248 xQueueHandle xQueueCreateMutex( unsigned char ucQueueType );
1249 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
1250 void* xQueueGetMutexHolder( xQueueHandle xSemaphore );
1251
1252 /*
1253  * For internal use only.  Use xSemaphoreTakeMutexRecursive() or
1254  * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
1255  */
1256 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
1257 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex );
1258
1259 /*
1260  * Reset a queue back to its original empty state.  pdPASS is returned if the
1261  * queue is successfully reset.  pdFAIL is returned if the queue could not be
1262  * reset because there are tasks blocked on the queue waiting to either
1263  * receive from the queue or send to the queue.
1264  */
1265 #define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE )
1266
1267 /*
1268  * The registry is provided as a means for kernel aware debuggers to
1269  * locate queues, semaphores and mutexes.  Call vQueueAddToRegistry() add
1270  * a queue, semaphore or mutex handle to the registry if you want the handle
1271  * to be available to a kernel aware debugger.  If you are not using a kernel
1272  * aware debugger then this function can be ignored.
1273  *
1274  * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
1275  * registry can hold.  configQUEUE_REGISTRY_SIZE must be greater than 0
1276  * within FreeRTOSConfig.h for the registry to be available.  Its value
1277  * does not effect the number of queues, semaphores and mutexes that can be
1278  * created - just the number that the registry can hold.
1279  *
1280  * @param xQueue The handle of the queue being added to the registry.  This
1281  * is the handle returned by a call to xQueueCreate().  Semaphore and mutex
1282  * handles can also be passed in here.
1283  *
1284  * @param pcName The name to be associated with the handle.  This is the
1285  * name that the kernel aware debugger will display.
1286  */
1287 #if configQUEUE_REGISTRY_SIZE > 0U
1288     void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcName );
1289 #endif
1290
1291 /*
1292  * Generic version of the queue creation function, which is in turn called by
1293  * any queue, semaphore or mutex creation function or macro.
1294  */
1295 xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType );
1296
1297 /*
1298  * Queue sets provide a mechanism to allow a task to block (pend) on a read
1299  * operation from multiple queues or semaphores simultaneously.
1300  *
1301  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1302  * function.
1303  *
1304  * A queue set must be explicitly created using a call to xQueueCreateSet()
1305  * before it can be used.  Once created, standard FreeRTOS queues and semaphores
1306  * can be added to the set using calls to xQueueAddToSet().
1307  * xQueueSelectFromSet() is then used to determine which, if any, of the queues
1308  * or semaphores contained in the set is in a state where a queue read or
1309  * semaphore take operation would be successful.
1310  *
1311  * Note 1:  See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1312  * for reasons why queue sets are very rarely needed in practice as there are
1313  * simpler methods of blocking on multiple objects.
1314  *
1315  * Note 2:  Blocking on a queue set that contains a mutex will not cause the
1316  * mutex holder to inherit the priority of the blocked task.
1317  *
1318  * Note 3:  An additional 4 bytes of RAM is required for each space in a every
1319  * queue added to a queue set.  Therefore counting semaphores that have a high
1320  * maximum count value should not be added to a queue set.
1321  *
1322  * Note 4:  A receive (in the case of a queue) or take (in the case of a
1323  * semaphore) operation must not be performed on a member of a queue set unless
1324  * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1325  *
1326  * @param uxEventQueueLength Queue sets store events that occur on
1327  * the queues and semaphores contained in the set.  uxEventQueueLength specifies
1328  * the maximum number of events that can be queued at once.  To be absolutely
1329  * certain that events are not lost uxEventQueueLength should be set to the
1330  * total sum of the length of the queues added to the set, where binary
1331  * semaphores and mutexes have a length of 1, and counting semaphores have a
1332  * length set by their maximum count value.  Examples:
1333  *  + If a queue set is to hold a queue of length 5, another queue of length 12,
1334  *    and a binary semaphore, then uxEventQueueLength should be set to
1335  *    (5 + 12 + 1), or 18.
1336  *  + If a queue set is to hold three binary semaphores then uxEventQueueLength
1337  *    should be set to (1 + 1 + 1 ), or 3.
1338  *  + If a queue set is to hold a counting semaphore that has a maximum count of
1339  *    5, and a counting semaphore that has a maximum count of 3, then
1340  *    uxEventQueueLength should be set to (5 + 3), or 8.
1341  *
1342  * @return If the queue set is created successfully then a handle to the created
1343  * queue set is returned.  Otherwise NULL is returned.
1344  */
1345 xQueueSetHandle xQueueCreateSet( unsigned portBASE_TYPE uxEventQueueLength );
1346
1347 /*
1348  * Adds a queue or semaphore to a queue set that was previously created by a
1349  * call to xQueueCreateSet().
1350  *
1351  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1352  * function.
1353  *
1354  * Note 1:  A receive (in the case of a queue) or take (in the case of a
1355  * semaphore) operation must not be performed on a member of a queue set unless
1356  * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1357  *
1358  * @param xQueueOrSemaphore The handle of the queue or semaphore being added to
1359  * the queue set (cast to an xQueueSetMemberHandle type).
1360  *
1361  * @param xQueueSet The handle of the queue set to which the queue or semaphore
1362  * is being added.
1363  *
1364  * @return If the queue or semaphore was successfully added to the queue set
1365  * then pdPASS is returned.  If the queue could not be successfully added to the
1366  * queue set because it is already a member of a different queue set then pdFAIL
1367  * is returned.
1368  */
1369 portBASE_TYPE xQueueAddToSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet );
1370
1371 /*
1372  * Removes a queue or semaphore from a queue set.  A queue or semaphore can only
1373  * be removed from a set if the queue or semaphore is empty.
1374  *
1375  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1376  * function.
1377  *
1378  * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
1379  * from the queue set (cast to an xQueueSetMemberHandle type).
1380  *
1381  * @param xQueueSet The handle of the queue set in which the queue or semaphore
1382  * is included.
1383  *
1384  * @return If the queue or semaphore was successfully removed from the queue set
1385  * then pdPASS is returned.  If the queue was not in the queue set, or the
1386  * queue (or semaphore) was not empty, then pdFAIL is returned.
1387  */
1388 portBASE_TYPE xQueueRemoveFromSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet );
1389
1390 /*
1391  * xQueueSelectFromSet() selects from the members of a queue set a queue or
1392  * semaphore that either contains data (in the case of a queue) or is available
1393  * to take (in the case of a semaphore).  xQueueSelectFromSet() effectively
1394  * allows a task to block (pend) on a read operation on all the queues and
1395  * semaphores in a queue set simultaneously.
1396  *
1397  * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1398  * function.
1399  *
1400  * Note 1:  See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1401  * for reasons why queue sets are very rarely needed in practice as there are
1402  * simpler methods of blocking on multiple objects.
1403  *
1404  * Note 2:  Blocking on a queue set that contains a mutex will not cause the
1405  * mutex holder to inherit the priority of the blocked task.
1406  *
1407  * Note 3:  A receive (in the case of a queue) or take (in the case of a
1408  * semaphore) operation must not be performed on a member of a queue set unless
1409  * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1410  *
1411  * @param xQueueSet The queue set on which the task will (potentially) block.
1412  *
1413  * @param xBlockTimeTicks The maximum time, in ticks, that the calling task will
1414  * remain in the Blocked state (with other tasks executing) to wait for a member
1415  * of the queue set to be ready for a successful queue read or semaphore take
1416  * operation.
1417  *
1418  * @return xQueueSelectFromSet() will return the handle of a queue (cast to
1419  * a xQueueSetMemberHandle type) contained in the queue set that contains data,
1420  * or the handle of a semaphore (cast to a xQueueSetMemberHandle type) contained
1421  * in the queue set that is available, or NULL if no such queue or semaphore
1422  * exists before before the specified block time expires.
1423  */
1424 xQueueSetMemberHandle xQueueSelectFromSet( xQueueSetHandle xQueueSet, portTickType xBlockTimeTicks );
1425
1426 /*
1427  * A version of xQueueSelectFromSet() that can be used from an ISR.
1428  */
1429 xQueueSetMemberHandle xQueueSelectFromSetFromISR( xQueueSetHandle xQueueSet );
1430
1431 /* Not public API functions. */
1432 void vQueueWaitForMessageRestricted( xQueueHandle xQueue, portTickType xTicksToWait );
1433 portBASE_TYPE xQueueGenericReset( xQueueHandle xQueue, portBASE_TYPE xNewQueue );
1434 void vQueueSetQueueNumber( xQueueHandle xQueue, unsigned char ucQueueNumber ) PRIVILEGED_FUNCTION;
1435 unsigned char ucQueueGetQueueType( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
1436
1437
1438 #ifdef __cplusplus
1439 }
1440 #endif
1441
1442 #endif /* QUEUE_H */
1443