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