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