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