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