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