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