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