2 FreeRTOS.org V5.1.2 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
31 * This is a concise, step by step, 'hands on' guide that describes both *
\r
32 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
33 * explains numerous examples that are written using the FreeRTOS API. *
\r
34 * Full source code for all the examples is provided in an accompanying *
\r
37 ***************************************************************************
\r
38 ***************************************************************************
\r
40 Please ensure to read the configuration and relevant port sections of the
\r
41 online documentation.
\r
43 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
46 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
49 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
50 licensing and training services.
\r
53 #ifndef INC_FREERTOS_H
\r
54 #error "#include FreeRTOS.h" must appear in source files before "#include queue.h"
\r
66 typedef void * xQueueHandle;
\r
68 /* For internal use only. */
\r
69 #define queueSEND_TO_BACK ( 0 )
\r
70 #define queueSEND_TO_FRONT ( 1 )
\r
76 xQueueHandle xQueueCreate(
\r
77 unsigned portBASE_TYPE uxQueueLength,
\r
78 unsigned portBASE_TYPE uxItemSize
\r
82 * Creates a new queue instance. This allocates the storage required by the
\r
83 * new queue and returns a handle for the queue.
\r
85 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
87 * @param uxItemSize The number of bytes each item in the queue will require.
\r
88 * Items are queued by copy, not by reference, so this is the number of bytes
\r
89 * that will be copied for each posted item. Each item on the queue must be
\r
92 * @return If the queue is successfully create then a handle to the newly
\r
93 * created queue is returned. If the queue cannot be created then 0 is
\r
100 portCHAR ucMessageID;
\r
101 portCHAR ucData[ 20 ];
\r
104 void vATask( void *pvParameters )
\r
106 xQueueHandle xQueue1, xQueue2;
\r
108 // Create a queue capable of containing 10 unsigned long values.
\r
109 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
112 // Queue was not created and must not be used.
\r
115 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
116 // These should be passed by pointer as they contain a lot of data.
\r
117 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
120 // Queue was not created and must not be used.
\r
123 // ... Rest of task code.
\r
126 * \defgroup xQueueCreate xQueueCreate
\r
127 * \ingroup QueueManagement
\r
129 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
134 portBASE_TYPE xQueueSendToToFront(
\r
135 xQueueHandle xQueue,
\r
136 const void * pvItemToQueue,
\r
137 portTickType xTicksToWait
\r
141 * This is a macro that calls xQueueGenericSend().
\r
143 * Post an item to the front of a queue. The item is queued by copy, not by
\r
144 * reference. This function must not be called from an interrupt service
\r
145 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
148 * @param xQueue The handle to the queue on which the item is to be posted.
\r
150 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
151 * queue. The size of the items the queue will hold was defined when the
\r
152 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
153 * into the queue storage area.
\r
155 * @param xTicksToWait The maximum amount of time the task should block
\r
156 * waiting for space to become available on the queue, should it already
\r
157 * be full. The call will return immediately if this is set to 0 and the
\r
158 * queue is full. The time is defined in tick periods so the constant
\r
159 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
161 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
167 portCHAR ucMessageID;
\r
168 portCHAR ucData[ 20 ];
\r
171 unsigned portLONG ulVar = 10UL;
\r
173 void vATask( void *pvParameters )
\r
175 xQueueHandle xQueue1, xQueue2;
\r
176 struct AMessage *pxMessage;
\r
178 // Create a queue capable of containing 10 unsigned long values.
\r
179 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
181 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
182 // These should be passed by pointer as they contain a lot of data.
\r
183 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
189 // Send an unsigned long. Wait for 10 ticks for space to become
\r
190 // available if necessary.
\r
191 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
193 // Failed to post the message, even after 10 ticks.
\r
199 // Send a pointer to a struct AMessage object. Don't block if the
\r
200 // queue is already full.
\r
201 pxMessage = & xMessage;
\r
202 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
205 // ... Rest of task code.
\r
208 * \defgroup xQueueSend xQueueSend
\r
209 * \ingroup QueueManagement
\r
211 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
216 portBASE_TYPE xQueueSendToBack(
\r
217 xQueueHandle xQueue,
\r
218 const void * pvItemToQueue,
\r
219 portTickType xTicksToWait
\r
223 * This is a macro that calls xQueueGenericSend().
\r
225 * Post an item to the back of a queue. The item is queued by copy, not by
\r
226 * reference. This function must not be called from an interrupt service
\r
227 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
230 * @param xQueue The handle to the queue on which the item is to be posted.
\r
232 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
233 * queue. The size of the items the queue will hold was defined when the
\r
234 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
235 * into the queue storage area.
\r
237 * @param xTicksToWait The maximum amount of time the task should block
\r
238 * waiting for space to become available on the queue, should it already
\r
239 * be full. The call will return immediately if this is set to 0 and the queue
\r
240 * is full. The time is defined in tick periods so the constant
\r
241 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
243 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
249 portCHAR ucMessageID;
\r
250 portCHAR ucData[ 20 ];
\r
253 unsigned portLONG ulVar = 10UL;
\r
255 void vATask( void *pvParameters )
\r
257 xQueueHandle xQueue1, xQueue2;
\r
258 struct AMessage *pxMessage;
\r
260 // Create a queue capable of containing 10 unsigned long values.
\r
261 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
263 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
264 // These should be passed by pointer as they contain a lot of data.
\r
265 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
271 // Send an unsigned long. Wait for 10 ticks for space to become
\r
272 // available if necessary.
\r
273 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
275 // Failed to post the message, even after 10 ticks.
\r
281 // Send a pointer to a struct AMessage object. Don't block if the
\r
282 // queue is already full.
\r
283 pxMessage = & xMessage;
\r
284 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
287 // ... Rest of task code.
\r
290 * \defgroup xQueueSend xQueueSend
\r
291 * \ingroup QueueManagement
\r
293 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
298 portBASE_TYPE xQueueSend(
\r
299 xQueueHandle xQueue,
\r
300 const void * pvItemToQueue,
\r
301 portTickType xTicksToWait
\r
305 * This is a macro that calls xQueueGenericSend(). It is included for
\r
306 * backward compatibility with versions of FreeRTOS.org that did not
\r
307 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
308 * equivalent to xQueueSendToBack().
\r
310 * Post an item on a queue. The item is queued by copy, not by reference.
\r
311 * This function must not be called from an interrupt service routine.
\r
312 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
314 * @param xQueue The handle to the queue on which the item is to be posted.
\r
316 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
317 * queue. The size of the items the queue will hold was defined when the
\r
318 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
319 * into the queue storage area.
\r
321 * @param xTicksToWait The maximum amount of time the task should block
\r
322 * waiting for space to become available on the queue, should it already
\r
323 * be full. The call will return immediately if this is set to 0 and the
\r
324 * queue is full. The time is defined in tick periods so the constant
\r
325 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
327 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
333 portCHAR ucMessageID;
\r
334 portCHAR ucData[ 20 ];
\r
337 unsigned portLONG ulVar = 10UL;
\r
339 void vATask( void *pvParameters )
\r
341 xQueueHandle xQueue1, xQueue2;
\r
342 struct AMessage *pxMessage;
\r
344 // Create a queue capable of containing 10 unsigned long values.
\r
345 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
347 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
348 // These should be passed by pointer as they contain a lot of data.
\r
349 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
355 // Send an unsigned long. Wait for 10 ticks for space to become
\r
356 // available if necessary.
\r
357 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
359 // Failed to post the message, even after 10 ticks.
\r
365 // Send a pointer to a struct AMessage object. Don't block if the
\r
366 // queue is already full.
\r
367 pxMessage = & xMessage;
\r
368 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
371 // ... Rest of task code.
\r
374 * \defgroup xQueueSend xQueueSend
\r
375 * \ingroup QueueManagement
\r
377 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
383 portBASE_TYPE xQueueGenericSend(
\r
384 xQueueHandle xQueue,
\r
385 const void * pvItemToQueue,
\r
386 portTickType xTicksToWait
\r
387 portBASE_TYPE xCopyPosition
\r
391 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
392 * xQueueSendToBack() are used in place of calling this function directly.
\r
394 * Post an item on a queue. The item is queued by copy, not by reference.
\r
395 * This function must not be called from an interrupt service routine.
\r
396 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
398 * @param xQueue The handle to the queue on which the item is to be posted.
\r
400 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
401 * queue. The size of the items the queue will hold was defined when the
\r
402 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
403 * into the queue storage area.
\r
405 * @param xTicksToWait The maximum amount of time the task should block
\r
406 * waiting for space to become available on the queue, should it already
\r
407 * be full. The call will return immediately if this is set to 0 and the
\r
408 * queue is full. The time is defined in tick periods so the constant
\r
409 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
411 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
412 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
413 * at the front of the queue (for high priority messages).
\r
415 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
421 portCHAR ucMessageID;
\r
422 portCHAR ucData[ 20 ];
\r
425 unsigned portLONG ulVar = 10UL;
\r
427 void vATask( void *pvParameters )
\r
429 xQueueHandle xQueue1, xQueue2;
\r
430 struct AMessage *pxMessage;
\r
432 // Create a queue capable of containing 10 unsigned long values.
\r
433 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
435 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
436 // These should be passed by pointer as they contain a lot of data.
\r
437 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
443 // Send an unsigned long. Wait for 10 ticks for space to become
\r
444 // available if necessary.
\r
445 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
447 // Failed to post the message, even after 10 ticks.
\r
453 // Send a pointer to a struct AMessage object. Don't block if the
\r
454 // queue is already full.
\r
455 pxMessage = & xMessage;
\r
456 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
459 // ... Rest of task code.
\r
462 * \defgroup xQueueSend xQueueSend
\r
463 * \ingroup QueueManagement
\r
465 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
470 portBASE_TYPE xQueuePeek(
\r
471 xQueueHandle xQueue,
\r
473 portTickType xTicksToWait
\r
476 * This is a macro that calls the xQueueGenericReceive() function.
\r
478 * Receive an item from a queue without removing the item from the queue.
\r
479 * The item is received by copy so a buffer of adequate size must be
\r
480 * provided. The number of bytes copied into the buffer was defined when
\r
481 * the queue was created.
\r
483 * Successfully received items remain on the queue so will be returned again
\r
484 * by the next call, or a call to xQueueReceive().
\r
486 * This macro must not be used in an interrupt service routine.
\r
488 * @param pxQueue The handle to the queue from which the item is to be
\r
491 * @param pvBuffer Pointer to the buffer into which the received item will
\r
494 * @param xTicksToWait The maximum amount of time the task should block
\r
495 * waiting for an item to receive should the queue be empty at the time
\r
496 * of the call. The time is defined in tick periods so the constant
\r
497 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
498 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
\r
501 * @return pdTRUE if an item was successfully received from the queue,
\r
502 * otherwise pdFALSE.
\r
508 portCHAR ucMessageID;
\r
509 portCHAR ucData[ 20 ];
\r
512 xQueueHandle xQueue;
\r
514 // Task to create a queue and post a value.
\r
515 void vATask( void *pvParameters )
\r
517 struct AMessage *pxMessage;
\r
519 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
520 // These should be passed by pointer as they contain a lot of data.
\r
521 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
524 // Failed to create the queue.
\r
529 // Send a pointer to a struct AMessage object. Don't block if the
\r
530 // queue is already full.
\r
531 pxMessage = & xMessage;
\r
532 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
534 // ... Rest of task code.
\r
537 // Task to peek the data from the queue.
\r
538 void vADifferentTask( void *pvParameters )
\r
540 struct AMessage *pxRxedMessage;
\r
544 // Peek a message on the created queue. Block for 10 ticks if a
\r
545 // message is not immediately available.
\r
546 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
548 // pcRxedMessage now points to the struct AMessage variable posted
\r
549 // by vATask, but the item still remains on the queue.
\r
553 // ... Rest of task code.
\r
556 * \defgroup xQueueReceive xQueueReceive
\r
557 * \ingroup QueueManagement
\r
559 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
564 portBASE_TYPE xQueueReceive(
\r
565 xQueueHandle xQueue,
\r
567 portTickType xTicksToWait
\r
570 * This is a macro that calls the xQueueGenericReceive() function.
\r
572 * Receive an item from a queue. The item is received by copy so a buffer of
\r
573 * adequate size must be provided. The number of bytes copied into the buffer
\r
574 * was defined when the queue was created.
\r
576 * Successfully received items are removed from the queue.
\r
578 * This function must not be used in an interrupt service routine. See
\r
579 * xQueueReceiveFromISR for an alternative that can.
\r
581 * @param pxQueue The handle to the queue from which the item is to be
\r
584 * @param pvBuffer Pointer to the buffer into which the received item will
\r
587 * @param xTicksToWait The maximum amount of time the task should block
\r
588 * waiting for an item to receive should the queue be empty at the time
\r
589 * of the call. xQueueReceive() will return immediately if xTicksToWait
\r
590 * is zero and the queue is empty. The time is defined in tick periods so the
\r
591 * constant portTICK_RATE_MS should be used to convert to real time if this is
\r
594 * @return pdTRUE if an item was successfully received from the queue,
\r
595 * otherwise pdFALSE.
\r
601 portCHAR ucMessageID;
\r
602 portCHAR ucData[ 20 ];
\r
605 xQueueHandle xQueue;
\r
607 // Task to create a queue and post a value.
\r
608 void vATask( void *pvParameters )
\r
610 struct AMessage *pxMessage;
\r
612 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
613 // These should be passed by pointer as they contain a lot of data.
\r
614 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
617 // Failed to create the queue.
\r
622 // Send a pointer to a struct AMessage object. Don't block if the
\r
623 // queue is already full.
\r
624 pxMessage = & xMessage;
\r
625 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
627 // ... Rest of task code.
\r
630 // Task to receive from the queue.
\r
631 void vADifferentTask( void *pvParameters )
\r
633 struct AMessage *pxRxedMessage;
\r
637 // Receive a message on the created queue. Block for 10 ticks if a
\r
638 // message is not immediately available.
\r
639 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
641 // pcRxedMessage now points to the struct AMessage variable posted
\r
646 // ... Rest of task code.
\r
649 * \defgroup xQueueReceive xQueueReceive
\r
650 * \ingroup QueueManagement
\r
652 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
658 portBASE_TYPE xQueueGenericReceive(
\r
659 xQueueHandle xQueue,
\r
661 portTickType xTicksToWait
\r
662 portBASE_TYPE xJustPeek
\r
665 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
666 * this function directly.
\r
668 * Receive an item from a queue. The item is received by copy so a buffer of
\r
669 * adequate size must be provided. The number of bytes copied into the buffer
\r
670 * was defined when the queue was created.
\r
672 * This function must not be used in an interrupt service routine. See
\r
673 * xQueueReceiveFromISR for an alternative that can.
\r
675 * @param pxQueue The handle to the queue from which the item is to be
\r
678 * @param pvBuffer Pointer to the buffer into which the received item will
\r
681 * @param xTicksToWait The maximum amount of time the task should block
\r
682 * waiting for an item to receive should the queue be empty at the time
\r
683 * of the call. The time is defined in tick periods so the constant
\r
684 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
685 * xQueueGenericReceive() will return immediately if the queue is empty and
\r
686 * xTicksToWait is 0.
\r
688 * @param xJustPeek When set to true, the item received from the queue is not
\r
689 * actually removed from the queue - meaning a subsequent call to
\r
690 * xQueueReceive() will return the same item. When set to false, the item
\r
691 * being received from the queue is also removed from the queue.
\r
693 * @return pdTRUE if an item was successfully received from the queue,
\r
694 * otherwise pdFALSE.
\r
700 portCHAR ucMessageID;
\r
701 portCHAR ucData[ 20 ];
\r
704 xQueueHandle xQueue;
\r
706 // Task to create a queue and post a value.
\r
707 void vATask( void *pvParameters )
\r
709 struct AMessage *pxMessage;
\r
711 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
712 // These should be passed by pointer as they contain a lot of data.
\r
713 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
716 // Failed to create the queue.
\r
721 // Send a pointer to a struct AMessage object. Don't block if the
\r
722 // queue is already full.
\r
723 pxMessage = & xMessage;
\r
724 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
726 // ... Rest of task code.
\r
729 // Task to receive from the queue.
\r
730 void vADifferentTask( void *pvParameters )
\r
732 struct AMessage *pxRxedMessage;
\r
736 // Receive a message on the created queue. Block for 10 ticks if a
\r
737 // message is not immediately available.
\r
738 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
740 // pcRxedMessage now points to the struct AMessage variable posted
\r
745 // ... Rest of task code.
\r
748 * \defgroup xQueueReceive xQueueReceive
\r
749 * \ingroup QueueManagement
\r
751 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
755 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
757 * Return the number of messages stored in a queue.
\r
759 * @param xQueue A handle to the queue being queried.
\r
761 * @return The number of messages available in the queue.
\r
763 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
764 * \ingroup QueueManagement
\r
766 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
770 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
772 * Delete a queue - freeing all the memory allocated for storing of items
\r
773 * placed on the queue.
\r
775 * @param xQueue A handle to the queue to be deleted.
\r
777 * \page vQueueDelete vQueueDelete
\r
778 * \ingroup QueueManagement
\r
780 void vQueueDelete( xQueueHandle xQueue );
\r
785 portBASE_TYPE xQueueSendToFrontFromISR(
\r
786 xQueueHandle pxQueue,
\r
787 const void *pvItemToQueue,
\r
788 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
792 * This is a macro that calls xQueueGenericSendFromISR().
\r
794 * Post an item to the front of a queue. It is safe to use this macro from
\r
795 * within an interrupt service routine.
\r
797 * Items are queued by copy not reference so it is preferable to only
\r
798 * queue small items, especially when called from an ISR. In most cases
\r
799 * it would be preferable to store a pointer to the item being queued.
\r
801 * @param xQueue The handle to the queue on which the item is to be posted.
\r
803 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
804 * queue. The size of the items the queue will hold was defined when the
\r
805 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
806 * into the queue storage area.
\r
808 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
\r
809 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
810 * to unblock, and the unblocked task has a priority higher than the currently
\r
811 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
\r
812 * a context switch should be requested before the interrupt is exited.
\r
814 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
817 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
820 void vBufferISR( void )
\r
823 portBASE_TYPE xHigherPrioritTaskWoken;
\r
825 // We have not woken a task at the start of the ISR.
\r
826 xHigherPriorityTaskWoken = pdFALSE;
\r
828 // Loop until the buffer is empty.
\r
831 // Obtain a byte from the buffer.
\r
832 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
835 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
837 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
839 // Now the buffer is empty we can switch context if necessary.
\r
840 if( xHigherPriorityTaskWoken )
\r
847 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
848 * \ingroup QueueManagement
\r
850 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_FRONT )
\r
856 portBASE_TYPE xQueueSendToBackFromISR(
\r
857 xQueueHandle pxQueue,
\r
858 const void *pvItemToQueue,
\r
859 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
863 * This is a macro that calls xQueueGenericSendFromISR().
\r
865 * Post an item to the back of a queue. It is safe to use this macro from
\r
866 * within an interrupt service routine.
\r
868 * Items are queued by copy not reference so it is preferable to only
\r
869 * queue small items, especially when called from an ISR. In most cases
\r
870 * it would be preferable to store a pointer to the item being queued.
\r
872 * @param xQueue The handle to the queue on which the item is to be posted.
\r
874 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
875 * queue. The size of the items the queue will hold was defined when the
\r
876 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
877 * into the queue storage area.
\r
879 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
\r
880 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
881 * to unblock, and the unblocked task has a priority higher than the currently
\r
882 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
\r
883 * a context switch should be requested before the interrupt is exited.
\r
885 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
888 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
891 void vBufferISR( void )
\r
894 portBASE_TYPE xHigherPriorityTaskWoken;
\r
896 // We have not woken a task at the start of the ISR.
\r
897 xHigherPriorityTaskWoken = pdFALSE;
\r
899 // Loop until the buffer is empty.
\r
902 // Obtain a byte from the buffer.
\r
903 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
906 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
908 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
910 // Now the buffer is empty we can switch context if necessary.
\r
911 if( xHigherPriorityTaskWoken )
\r
918 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
919 * \ingroup QueueManagement
\r
921 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
926 portBASE_TYPE xQueueSendFromISR(
\r
927 xQueueHandle pxQueue,
\r
928 const void *pvItemToQueue,
\r
929 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
933 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
934 * for backward compatibility with versions of FreeRTOS.org that did not
\r
935 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
938 * Post an item to the back of a queue. It is safe to use this function from
\r
939 * within an interrupt service routine.
\r
941 * Items are queued by copy not reference so it is preferable to only
\r
942 * queue small items, especially when called from an ISR. In most cases
\r
943 * it would be preferable to store a pointer to the item being queued.
\r
945 * @param xQueue The handle to the queue on which the item is to be posted.
\r
947 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
948 * queue. The size of the items the queue will hold was defined when the
\r
949 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
950 * into the queue storage area.
\r
952 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
\r
953 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
954 * to unblock, and the unblocked task has a priority higher than the currently
\r
955 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
956 * a context switch should be requested before the interrupt is exited.
\r
958 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
961 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
964 void vBufferISR( void )
\r
967 portBASE_TYPE xHigherPriorityTaskWoken;
\r
969 // We have not woken a task at the start of the ISR.
\r
970 xHigherPriorityTaskWoken = pdFALSE;
\r
972 // Loop until the buffer is empty.
\r
975 // Obtain a byte from the buffer.
\r
976 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
979 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
981 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
983 // Now the buffer is empty we can switch context if necessary.
\r
984 if( xHigherPriorityTaskWoken )
\r
986 // Actual macro used here is port specific.
\r
987 taskYIELD_FROM_ISR ();
\r
992 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
993 * \ingroup QueueManagement
\r
995 #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
1000 portBASE_TYPE xQueueGenericSendFromISR(
\r
1001 xQueueHandle pxQueue,
\r
1002 const void *pvItemToQueue,
\r
1003 portBASE_TYPE *pxHigherPriorityTaskWoken,
\r
1004 portBASE_TYPE xCopyPosition
\r
1008 * It is preferred that the macros xQueueSendFromISR(),
\r
1009 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1010 * of calling this function directly.
\r
1012 * Post an item on a queue. It is safe to use this function from within an
\r
1013 * interrupt service routine.
\r
1015 * Items are queued by copy not reference so it is preferable to only
\r
1016 * queue small items, especially when called from an ISR. In most cases
\r
1017 * it would be preferable to store a pointer to the item being queued.
\r
1019 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1021 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1022 * queue. The size of the items the queue will hold was defined when the
\r
1023 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1024 * into the queue storage area.
\r
1026 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
\r
1027 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1028 * to unblock, and the unblocked task has a priority higher than the currently
\r
1029 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
\r
1030 * a context switch should be requested before the interrupt is exited.
\r
1032 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1033 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1034 * at the front of the queue (for high priority messages).
\r
1036 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1039 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1042 void vBufferISR( void )
\r
1045 portBASE_TYPE xHigherPriorityTaskWokenByPost;
\r
1047 // We have not woken a task at the start of the ISR.
\r
1048 xHigherPriorityTaskWokenByPost = pdFALSE;
\r
1050 // Loop until the buffer is empty.
\r
1053 // Obtain a byte from the buffer.
\r
1054 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1056 // Post each byte.
\r
1057 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
\r
1059 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1061 // Now the buffer is empty we can switch context if necessary. Note that the
\r
1062 // name of the yield function required is port specific.
\r
1063 if( xHigherPriorityTaskWokenByPost )
\r
1065 taskYIELD_YIELD_FROM_ISR();
\r
1070 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1071 * \ingroup QueueManagement
\r
1073 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
\r
1078 portBASE_TYPE xQueueReceiveFromISR(
\r
1079 xQueueHandle pxQueue,
\r
1081 portBASE_TYPE *pxTaskWoken
\r
1085 * Receive an item from a queue. It is safe to use this function from within an
\r
1086 * interrupt service routine.
\r
1088 * @param pxQueue The handle to the queue from which the item is to be
\r
1091 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1094 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1095 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1096 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1097 * remain unchanged.
\r
1099 * @return pdTRUE if an item was successfully received from the queue,
\r
1100 * otherwise pdFALSE.
\r
1105 xQueueHandle xQueue;
\r
1107 // Function to create a queue and post some values.
\r
1108 void vAFunction( void *pvParameters )
\r
1110 portCHAR cValueToPost;
\r
1111 const portTickType xBlockTime = ( portTickType )0xff;
\r
1113 // Create a queue capable of containing 10 characters.
\r
1114 xQueue = xQueueCreate( 10, sizeof( portCHAR ) );
\r
1117 // Failed to create the queue.
\r
1122 // Post some characters that will be used within an ISR. If the queue
\r
1123 // is full then this task will block for xBlockTime ticks.
\r
1124 cValueToPost = 'a';
\r
1125 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1126 cValueToPost = 'b';
\r
1127 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1129 // ... keep posting characters ... this task may block when the queue
\r
1132 cValueToPost = 'c';
\r
1133 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1136 // ISR that outputs all the characters received on the queue.
\r
1137 void vISR_Routine( void )
\r
1139 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1140 portCHAR cRxedChar;
\r
1142 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1144 // A character was received. Output the character now.
\r
1145 vOutputCharacter( cRxedChar );
\r
1147 // If removing the character from the queue woke the task that was
\r
1148 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1149 // pdTRUE. No matter how many times this loop iterates only one
\r
1150 // task will be woken.
\r
1153 if( cTaskWokenByPost != ( portCHAR ) pdFALSE;
\r
1159 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1160 * \ingroup QueueManagement
\r
1162 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1165 * Utilities to query queue that are safe to use from an ISR. These utilities
\r
1166 * should be used only from witin an ISR, or within a critical section.
\r
1168 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
\r
1169 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
\r
1170 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
\r
1174 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1175 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1176 * xQueueGenericReceive().
\r
1178 * The source code that implements the alternative (Alt) API is much
\r
1179 * simpler because it executes everything from within a critical section.
\r
1180 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1181 * preferred fully featured API too. The fully featured API has more
\r
1182 * complex code that takes longer to execute, but makes much less use of
\r
1183 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1184 * responsiveness to gain execution speed, whereas the fully featured API
\r
1185 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1187 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1188 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1189 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
1190 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
1191 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
1192 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
1195 * The functions defined above are for passing data to and from tasks. The
\r
1196 * functions below are the equivalents for passing data to and from
\r
1199 * These functions are called from the co-routine macro implementation and
\r
1200 * should not be called directly from application code. Instead use the macro
\r
1201 * wrappers defined within croutine.h.
\r
1203 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1204 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1205 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1206 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1209 * For internal use only. Use xSemaphoreCreateMutex() or
\r
1210 * xSemaphoreCreateCounting() instead of calling these functions directly.
\r
1212 xQueueHandle xQueueCreateMutex( void );
\r
1213 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1216 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1217 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1219 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
\r
1220 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex );
\r
1223 * The registry is provided as a means for kernel aware debuggers to
\r
1224 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
\r
1225 * a queue, semaphore or mutex handle to the registry if you want the handle
\r
1226 * to be available to a kernel aware debugger. If you are not using a kernel
\r
1227 * aware debugger then this function can be ignored.
\r
1229 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
\r
1230 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
\r
1231 * within FreeRTOSConfig.h for the registry to be available. Its value
\r
1232 * does not effect the number of queues, semaphores and mutexes that can be
\r
1233 * created - just the number that the registry can hold.
\r
1235 * @param xQueue The handle of the queue being added to the registry. This
\r
1236 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
\r
1237 * handles can also be passed in here.
\r
1239 * @param pcName The name to be associated with the handle. This is the
\r
1240 * name that the kernel aware debugger will display.
\r
1242 #if configQUEUE_REGISTRY_SIZE > 0
\r
1243 void vQueueAddToRegistry( xQueueHandle xQueue, signed portCHAR *pcName );
\r
1249 #ifdef __cplusplus
\r
1253 #endif /* QUEUE_H */
\r