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