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