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