2 FreeRTOS.org V5.2.0 - 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 it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the Free Software Foundation and modified by the FreeRTOS exception.
\r
10 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
15 You should have received a copy of the GNU General Public License along
\r
16 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
17 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
19 A special exception to the GPL is included to allow you to distribute a
\r
20 combined work that includes FreeRTOS.org without being obliged to provide
\r
21 the source code for any proprietary components. See the licensing section
\r
22 of http://www.FreeRTOS.org for full details.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
52 #ifndef INC_FREERTOS_H
\r
53 #error "#include FreeRTOS.h" must appear in source files before "#include queue.h"
\r
65 typedef void * xQueueHandle;
\r
67 /* For internal use only. */
\r
68 #define queueSEND_TO_BACK ( 0 )
\r
69 #define queueSEND_TO_FRONT ( 1 )
\r
75 xQueueHandle xQueueCreate(
\r
76 unsigned portBASE_TYPE uxQueueLength,
\r
77 unsigned portBASE_TYPE uxItemSize
\r
81 * Creates a new queue instance. This allocates the storage required by the
\r
82 * new queue and returns a handle for the queue.
\r
84 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
86 * @param uxItemSize The number of bytes each item in the queue will require.
\r
87 * Items are queued by copy, not by reference, so this is the number of bytes
\r
88 * that will be copied for each posted item. Each item on the queue must be
\r
91 * @return If the queue is successfully create then a handle to the newly
\r
92 * created queue is returned. If the queue cannot be created then 0 is
\r
99 portCHAR ucMessageID;
\r
100 portCHAR ucData[ 20 ];
\r
103 void vATask( void *pvParameters )
\r
105 xQueueHandle xQueue1, xQueue2;
\r
107 // Create a queue capable of containing 10 unsigned long values.
\r
108 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
111 // Queue was not created and must not be used.
\r
114 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
115 // These should be passed by pointer as they contain a lot of data.
\r
116 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
119 // Queue was not created and must not be used.
\r
122 // ... Rest of task code.
\r
125 * \defgroup xQueueCreate xQueueCreate
\r
126 * \ingroup QueueManagement
\r
128 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
133 portBASE_TYPE xQueueSendToToFront(
\r
134 xQueueHandle xQueue,
\r
135 const void * pvItemToQueue,
\r
136 portTickType xTicksToWait
\r
140 * This is a macro that calls xQueueGenericSend().
\r
142 * Post an item to the front of a queue. The item is queued by copy, not by
\r
143 * reference. This function must not be called from an interrupt service
\r
144 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
147 * @param xQueue The handle to the queue on which the item is to be posted.
\r
149 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
150 * queue. The size of the items the queue will hold was defined when the
\r
151 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
152 * into the queue storage area.
\r
154 * @param xTicksToWait The maximum amount of time the task should block
\r
155 * waiting for space to become available on the queue, should it already
\r
156 * be full. The call will return immediately if this is set to 0 and the
\r
157 * queue is full. The time is defined in tick periods so the constant
\r
158 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
160 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
166 portCHAR ucMessageID;
\r
167 portCHAR ucData[ 20 ];
\r
170 unsigned portLONG ulVar = 10UL;
\r
172 void vATask( void *pvParameters )
\r
174 xQueueHandle xQueue1, xQueue2;
\r
175 struct AMessage *pxMessage;
\r
177 // Create a queue capable of containing 10 unsigned long values.
\r
178 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
180 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
181 // These should be passed by pointer as they contain a lot of data.
\r
182 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
188 // Send an unsigned long. Wait for 10 ticks for space to become
\r
189 // available if necessary.
\r
190 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
192 // Failed to post the message, even after 10 ticks.
\r
198 // Send a pointer to a struct AMessage object. Don't block if the
\r
199 // queue is already full.
\r
200 pxMessage = & xMessage;
\r
201 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
204 // ... Rest of task code.
\r
207 * \defgroup xQueueSend xQueueSend
\r
208 * \ingroup QueueManagement
\r
210 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
215 portBASE_TYPE xQueueSendToBack(
\r
216 xQueueHandle xQueue,
\r
217 const void * pvItemToQueue,
\r
218 portTickType xTicksToWait
\r
222 * This is a macro that calls xQueueGenericSend().
\r
224 * Post an item to the back of a queue. The item is queued by copy, not by
\r
225 * reference. This function must not be called from an interrupt service
\r
226 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
229 * @param xQueue The handle to the queue on which the item is to be posted.
\r
231 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
232 * queue. The size of the items the queue will hold was defined when the
\r
233 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
234 * into the queue storage area.
\r
236 * @param xTicksToWait The maximum amount of time the task should block
\r
237 * waiting for space to become available on the queue, should it already
\r
238 * be full. The call will return immediately if this is set to 0 and the queue
\r
239 * is full. The time is defined in tick periods so the constant
\r
240 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
242 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
248 portCHAR ucMessageID;
\r
249 portCHAR ucData[ 20 ];
\r
252 unsigned portLONG ulVar = 10UL;
\r
254 void vATask( void *pvParameters )
\r
256 xQueueHandle xQueue1, xQueue2;
\r
257 struct AMessage *pxMessage;
\r
259 // Create a queue capable of containing 10 unsigned long values.
\r
260 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
262 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
263 // These should be passed by pointer as they contain a lot of data.
\r
264 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
270 // Send an unsigned long. Wait for 10 ticks for space to become
\r
271 // available if necessary.
\r
272 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
274 // Failed to post the message, even after 10 ticks.
\r
280 // Send a pointer to a struct AMessage object. Don't block if the
\r
281 // queue is already full.
\r
282 pxMessage = & xMessage;
\r
283 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
286 // ... Rest of task code.
\r
289 * \defgroup xQueueSend xQueueSend
\r
290 * \ingroup QueueManagement
\r
292 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
297 portBASE_TYPE xQueueSend(
\r
298 xQueueHandle xQueue,
\r
299 const void * pvItemToQueue,
\r
300 portTickType xTicksToWait
\r
304 * This is a macro that calls xQueueGenericSend(). It is included for
\r
305 * backward compatibility with versions of FreeRTOS.org that did not
\r
306 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
307 * equivalent to xQueueSendToBack().
\r
309 * Post an item on a queue. The item is queued by copy, not by reference.
\r
310 * This function must not be called from an interrupt service routine.
\r
311 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
313 * @param xQueue The handle to the queue on which the item is to be posted.
\r
315 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
316 * queue. The size of the items the queue will hold was defined when the
\r
317 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
318 * into the queue storage area.
\r
320 * @param xTicksToWait The maximum amount of time the task should block
\r
321 * waiting for space to become available on the queue, should it already
\r
322 * be full. The call will return immediately if this is set to 0 and the
\r
323 * queue is full. The time is defined in tick periods so the constant
\r
324 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
326 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
332 portCHAR ucMessageID;
\r
333 portCHAR ucData[ 20 ];
\r
336 unsigned portLONG ulVar = 10UL;
\r
338 void vATask( void *pvParameters )
\r
340 xQueueHandle xQueue1, xQueue2;
\r
341 struct AMessage *pxMessage;
\r
343 // Create a queue capable of containing 10 unsigned long values.
\r
344 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
346 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
347 // These should be passed by pointer as they contain a lot of data.
\r
348 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
354 // Send an unsigned long. Wait for 10 ticks for space to become
\r
355 // available if necessary.
\r
356 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
358 // Failed to post the message, even after 10 ticks.
\r
364 // Send a pointer to a struct AMessage object. Don't block if the
\r
365 // queue is already full.
\r
366 pxMessage = & xMessage;
\r
367 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
370 // ... Rest of task code.
\r
373 * \defgroup xQueueSend xQueueSend
\r
374 * \ingroup QueueManagement
\r
376 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
382 portBASE_TYPE xQueueGenericSend(
\r
383 xQueueHandle xQueue,
\r
384 const void * pvItemToQueue,
\r
385 portTickType xTicksToWait
\r
386 portBASE_TYPE xCopyPosition
\r
390 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
391 * xQueueSendToBack() are used in place of calling this function directly.
\r
393 * Post an item on a queue. The item is queued by copy, not by reference.
\r
394 * This function must not be called from an interrupt service routine.
\r
395 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
397 * @param xQueue The handle to the queue on which the item is to be posted.
\r
399 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
400 * queue. The size of the items the queue will hold was defined when the
\r
401 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
402 * into the queue storage area.
\r
404 * @param xTicksToWait The maximum amount of time the task should block
\r
405 * waiting for space to become available on the queue, should it already
\r
406 * be full. The call will return immediately if this is set to 0 and the
\r
407 * queue is full. The time is defined in tick periods so the constant
\r
408 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
410 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
411 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
412 * at the front of the queue (for high priority messages).
\r
414 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
420 portCHAR ucMessageID;
\r
421 portCHAR ucData[ 20 ];
\r
424 unsigned portLONG ulVar = 10UL;
\r
426 void vATask( void *pvParameters )
\r
428 xQueueHandle xQueue1, xQueue2;
\r
429 struct AMessage *pxMessage;
\r
431 // Create a queue capable of containing 10 unsigned long values.
\r
432 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
434 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
435 // These should be passed by pointer as they contain a lot of data.
\r
436 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
442 // Send an unsigned long. Wait for 10 ticks for space to become
\r
443 // available if necessary.
\r
444 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
446 // Failed to post the message, even after 10 ticks.
\r
452 // Send a pointer to a struct AMessage object. Don't block if the
\r
453 // queue is already full.
\r
454 pxMessage = & xMessage;
\r
455 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
458 // ... Rest of task code.
\r
461 * \defgroup xQueueSend xQueueSend
\r
462 * \ingroup QueueManagement
\r
464 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
469 portBASE_TYPE xQueuePeek(
\r
470 xQueueHandle xQueue,
\r
472 portTickType xTicksToWait
\r
475 * This is a macro that calls the xQueueGenericReceive() function.
\r
477 * Receive an item from a queue without removing the item from the queue.
\r
478 * The item is received by copy so a buffer of adequate size must be
\r
479 * provided. The number of bytes copied into the buffer was defined when
\r
480 * the queue was created.
\r
482 * Successfully received items remain on the queue so will be returned again
\r
483 * by the next call, or a call to xQueueReceive().
\r
485 * This macro must not be used in an interrupt service routine.
\r
487 * @param pxQueue The handle to the queue from which the item is to be
\r
490 * @param pvBuffer Pointer to the buffer into which the received item will
\r
493 * @param xTicksToWait The maximum amount of time the task should block
\r
494 * waiting for an item to receive should the queue be empty at the time
\r
495 * of the call. The time is defined in tick periods so the constant
\r
496 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
497 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
\r
500 * @return pdTRUE if an item was successfully received from the queue,
\r
501 * otherwise pdFALSE.
\r
507 portCHAR ucMessageID;
\r
508 portCHAR ucData[ 20 ];
\r
511 xQueueHandle xQueue;
\r
513 // Task to create a queue and post a value.
\r
514 void vATask( void *pvParameters )
\r
516 struct AMessage *pxMessage;
\r
518 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
519 // These should be passed by pointer as they contain a lot of data.
\r
520 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
523 // Failed to create the queue.
\r
528 // Send a pointer to a struct AMessage object. Don't block if the
\r
529 // queue is already full.
\r
530 pxMessage = & xMessage;
\r
531 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
533 // ... Rest of task code.
\r
536 // Task to peek the data from the queue.
\r
537 void vADifferentTask( void *pvParameters )
\r
539 struct AMessage *pxRxedMessage;
\r
543 // Peek a message on the created queue. Block for 10 ticks if a
\r
544 // message is not immediately available.
\r
545 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
547 // pcRxedMessage now points to the struct AMessage variable posted
\r
548 // by vATask, but the item still remains on the queue.
\r
552 // ... Rest of task code.
\r
555 * \defgroup xQueueReceive xQueueReceive
\r
556 * \ingroup QueueManagement
\r
558 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
563 portBASE_TYPE xQueueReceive(
\r
564 xQueueHandle xQueue,
\r
566 portTickType xTicksToWait
\r
569 * This is a macro that calls the xQueueGenericReceive() function.
\r
571 * Receive an item from a queue. The item is received by copy so a buffer of
\r
572 * adequate size must be provided. The number of bytes copied into the buffer
\r
573 * was defined when the queue was created.
\r
575 * Successfully received items are removed from the queue.
\r
577 * This function must not be used in an interrupt service routine. See
\r
578 * xQueueReceiveFromISR for an alternative that can.
\r
580 * @param pxQueue The handle to the queue from which the item is to be
\r
583 * @param pvBuffer Pointer to the buffer into which the received item will
\r
586 * @param xTicksToWait The maximum amount of time the task should block
\r
587 * waiting for an item to receive should the queue be empty at the time
\r
588 * of the call. xQueueReceive() will return immediately if xTicksToWait
\r
589 * is zero and the queue is empty. The time is defined in tick periods so the
\r
590 * constant portTICK_RATE_MS should be used to convert to real time if this is
\r
593 * @return pdTRUE if an item was successfully received from the queue,
\r
594 * otherwise pdFALSE.
\r
600 portCHAR ucMessageID;
\r
601 portCHAR ucData[ 20 ];
\r
604 xQueueHandle xQueue;
\r
606 // Task to create a queue and post a value.
\r
607 void vATask( void *pvParameters )
\r
609 struct AMessage *pxMessage;
\r
611 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
612 // These should be passed by pointer as they contain a lot of data.
\r
613 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
616 // Failed to create the queue.
\r
621 // Send a pointer to a struct AMessage object. Don't block if the
\r
622 // queue is already full.
\r
623 pxMessage = & xMessage;
\r
624 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
626 // ... Rest of task code.
\r
629 // Task to receive from the queue.
\r
630 void vADifferentTask( void *pvParameters )
\r
632 struct AMessage *pxRxedMessage;
\r
636 // Receive a message on the created queue. Block for 10 ticks if a
\r
637 // message is not immediately available.
\r
638 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
640 // pcRxedMessage now points to the struct AMessage variable posted
\r
645 // ... Rest of task code.
\r
648 * \defgroup xQueueReceive xQueueReceive
\r
649 * \ingroup QueueManagement
\r
651 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
657 portBASE_TYPE xQueueGenericReceive(
\r
658 xQueueHandle xQueue,
\r
660 portTickType xTicksToWait
\r
661 portBASE_TYPE xJustPeek
\r
664 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
665 * this function directly.
\r
667 * Receive an item from a queue. The item is received by copy so a buffer of
\r
668 * adequate size must be provided. The number of bytes copied into the buffer
\r
669 * was defined when the queue was created.
\r
671 * This function must not be used in an interrupt service routine. See
\r
672 * xQueueReceiveFromISR for an alternative that can.
\r
674 * @param pxQueue The handle to the queue from which the item is to be
\r
677 * @param pvBuffer Pointer to the buffer into which the received item will
\r
680 * @param xTicksToWait The maximum amount of time the task should block
\r
681 * waiting for an item to receive should the queue be empty at the time
\r
682 * of the call. The time is defined in tick periods so the constant
\r
683 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
684 * xQueueGenericReceive() will return immediately if the queue is empty and
\r
685 * xTicksToWait is 0.
\r
687 * @param xJustPeek When set to true, the item received from the queue is not
\r
688 * actually removed from the queue - meaning a subsequent call to
\r
689 * xQueueReceive() will return the same item. When set to false, the item
\r
690 * being received from the queue is also removed from the queue.
\r
692 * @return pdTRUE if an item was successfully received from the queue,
\r
693 * otherwise pdFALSE.
\r
699 portCHAR ucMessageID;
\r
700 portCHAR ucData[ 20 ];
\r
703 xQueueHandle xQueue;
\r
705 // Task to create a queue and post a value.
\r
706 void vATask( void *pvParameters )
\r
708 struct AMessage *pxMessage;
\r
710 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
711 // These should be passed by pointer as they contain a lot of data.
\r
712 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
715 // Failed to create the queue.
\r
720 // Send a pointer to a struct AMessage object. Don't block if the
\r
721 // queue is already full.
\r
722 pxMessage = & xMessage;
\r
723 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
725 // ... Rest of task code.
\r
728 // Task to receive from the queue.
\r
729 void vADifferentTask( void *pvParameters )
\r
731 struct AMessage *pxRxedMessage;
\r
735 // Receive a message on the created queue. Block for 10 ticks if a
\r
736 // message is not immediately available.
\r
737 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
739 // pcRxedMessage now points to the struct AMessage variable posted
\r
744 // ... Rest of task code.
\r
747 * \defgroup xQueueReceive xQueueReceive
\r
748 * \ingroup QueueManagement
\r
750 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
754 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
756 * Return the number of messages stored in a queue.
\r
758 * @param xQueue A handle to the queue being queried.
\r
760 * @return The number of messages available in the queue.
\r
762 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
763 * \ingroup QueueManagement
\r
765 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
769 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
771 * Delete a queue - freeing all the memory allocated for storing of items
\r
772 * placed on the queue.
\r
774 * @param xQueue A handle to the queue to be deleted.
\r
776 * \page vQueueDelete vQueueDelete
\r
777 * \ingroup QueueManagement
\r
779 void vQueueDelete( xQueueHandle xQueue );
\r
784 portBASE_TYPE xQueueSendToFrontFromISR(
\r
785 xQueueHandle pxQueue,
\r
786 const void *pvItemToQueue,
\r
787 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
791 * This is a macro that calls xQueueGenericSendFromISR().
\r
793 * Post an item to the front of a queue. It is safe to use this macro from
\r
794 * within an interrupt service routine.
\r
796 * Items are queued by copy not reference so it is preferable to only
\r
797 * queue small items, especially when called from an ISR. In most cases
\r
798 * it would be preferable to store a pointer to the item being queued.
\r
800 * @param xQueue The handle to the queue on which the item is to be posted.
\r
802 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
803 * queue. The size of the items the queue will hold was defined when the
\r
804 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
805 * into the queue storage area.
\r
807 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
\r
808 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
809 * to unblock, and the unblocked task has a priority higher than the currently
\r
810 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
\r
811 * a context switch should be requested before the interrupt is exited.
\r
813 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
816 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
819 void vBufferISR( void )
\r
822 portBASE_TYPE xHigherPrioritTaskWoken;
\r
824 // We have not woken a task at the start of the ISR.
\r
825 xHigherPriorityTaskWoken = pdFALSE;
\r
827 // Loop until the buffer is empty.
\r
830 // Obtain a byte from the buffer.
\r
831 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
834 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
836 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
838 // Now the buffer is empty we can switch context if necessary.
\r
839 if( xHigherPriorityTaskWoken )
\r
846 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
847 * \ingroup QueueManagement
\r
849 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_FRONT )
\r
855 portBASE_TYPE xQueueSendToBackFromISR(
\r
856 xQueueHandle pxQueue,
\r
857 const void *pvItemToQueue,
\r
858 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
862 * This is a macro that calls xQueueGenericSendFromISR().
\r
864 * Post an item to the back of a queue. It is safe to use this macro from
\r
865 * within an interrupt service routine.
\r
867 * Items are queued by copy not reference so it is preferable to only
\r
868 * queue small items, especially when called from an ISR. In most cases
\r
869 * it would be preferable to store a pointer to the item being queued.
\r
871 * @param xQueue The handle to the queue on which the item is to be posted.
\r
873 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
874 * queue. The size of the items the queue will hold was defined when the
\r
875 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
876 * into the queue storage area.
\r
878 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
\r
879 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
880 * to unblock, and the unblocked task has a priority higher than the currently
\r
881 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
\r
882 * a context switch should be requested before the interrupt is exited.
\r
884 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
887 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
890 void vBufferISR( void )
\r
893 portBASE_TYPE xHigherPriorityTaskWoken;
\r
895 // We have not woken a task at the start of the ISR.
\r
896 xHigherPriorityTaskWoken = pdFALSE;
\r
898 // Loop until the buffer is empty.
\r
901 // Obtain a byte from the buffer.
\r
902 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
905 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
907 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
909 // Now the buffer is empty we can switch context if necessary.
\r
910 if( xHigherPriorityTaskWoken )
\r
917 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
918 * \ingroup QueueManagement
\r
920 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
925 portBASE_TYPE xQueueSendFromISR(
\r
926 xQueueHandle pxQueue,
\r
927 const void *pvItemToQueue,
\r
928 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
932 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
933 * for backward compatibility with versions of FreeRTOS.org that did not
\r
934 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
937 * Post an item to the back of a queue. It is safe to use this function from
\r
938 * within an interrupt service routine.
\r
940 * Items are queued by copy not reference so it is preferable to only
\r
941 * queue small items, especially when called from an ISR. In most cases
\r
942 * it would be preferable to store a pointer to the item being queued.
\r
944 * @param xQueue The handle to the queue on which the item is to be posted.
\r
946 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
947 * queue. The size of the items the queue will hold was defined when the
\r
948 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
949 * into the queue storage area.
\r
951 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
\r
952 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
953 * to unblock, and the unblocked task has a priority higher than the currently
\r
954 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
955 * a context switch should be requested before the interrupt is exited.
\r
957 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
960 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
963 void vBufferISR( void )
\r
966 portBASE_TYPE xHigherPriorityTaskWoken;
\r
968 // We have not woken a task at the start of the ISR.
\r
969 xHigherPriorityTaskWoken = pdFALSE;
\r
971 // Loop until the buffer is empty.
\r
974 // Obtain a byte from the buffer.
\r
975 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
978 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
980 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
982 // Now the buffer is empty we can switch context if necessary.
\r
983 if( xHigherPriorityTaskWoken )
\r
985 // Actual macro used here is port specific.
\r
986 taskYIELD_FROM_ISR ();
\r
991 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
992 * \ingroup QueueManagement
\r
994 #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
999 portBASE_TYPE xQueueGenericSendFromISR(
\r
1000 xQueueHandle pxQueue,
\r
1001 const void *pvItemToQueue,
\r
1002 portBASE_TYPE *pxHigherPriorityTaskWoken,
\r
1003 portBASE_TYPE xCopyPosition
\r
1007 * It is preferred that the macros xQueueSendFromISR(),
\r
1008 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1009 * of calling this function directly.
\r
1011 * Post an item on a queue. It is safe to use this function from within an
\r
1012 * interrupt service routine.
\r
1014 * Items are queued by copy not reference so it is preferable to only
\r
1015 * queue small items, especially when called from an ISR. In most cases
\r
1016 * it would be preferable to store a pointer to the item being queued.
\r
1018 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1020 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1021 * queue. The size of the items the queue will hold was defined when the
\r
1022 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1023 * into the queue storage area.
\r
1025 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
\r
1026 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1027 * to unblock, and the unblocked task has a priority higher than the currently
\r
1028 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
\r
1029 * a context switch should be requested before the interrupt is exited.
\r
1031 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1032 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1033 * at the front of the queue (for high priority messages).
\r
1035 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1038 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1041 void vBufferISR( void )
\r
1044 portBASE_TYPE xHigherPriorityTaskWokenByPost;
\r
1046 // We have not woken a task at the start of the ISR.
\r
1047 xHigherPriorityTaskWokenByPost = pdFALSE;
\r
1049 // Loop until the buffer is empty.
\r
1052 // Obtain a byte from the buffer.
\r
1053 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1055 // Post each byte.
\r
1056 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
\r
1058 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1060 // Now the buffer is empty we can switch context if necessary. Note that the
\r
1061 // name of the yield function required is port specific.
\r
1062 if( xHigherPriorityTaskWokenByPost )
\r
1064 taskYIELD_YIELD_FROM_ISR();
\r
1069 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1070 * \ingroup QueueManagement
\r
1072 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
\r
1077 portBASE_TYPE xQueueReceiveFromISR(
\r
1078 xQueueHandle pxQueue,
\r
1080 portBASE_TYPE *pxTaskWoken
\r
1084 * Receive an item from a queue. It is safe to use this function from within an
\r
1085 * interrupt service routine.
\r
1087 * @param pxQueue The handle to the queue from which the item is to be
\r
1090 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1093 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1094 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1095 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1096 * remain unchanged.
\r
1098 * @return pdTRUE if an item was successfully received from the queue,
\r
1099 * otherwise pdFALSE.
\r
1104 xQueueHandle xQueue;
\r
1106 // Function to create a queue and post some values.
\r
1107 void vAFunction( void *pvParameters )
\r
1109 portCHAR cValueToPost;
\r
1110 const portTickType xBlockTime = ( portTickType )0xff;
\r
1112 // Create a queue capable of containing 10 characters.
\r
1113 xQueue = xQueueCreate( 10, sizeof( portCHAR ) );
\r
1116 // Failed to create the queue.
\r
1121 // Post some characters that will be used within an ISR. If the queue
\r
1122 // is full then this task will block for xBlockTime ticks.
\r
1123 cValueToPost = 'a';
\r
1124 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1125 cValueToPost = 'b';
\r
1126 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1128 // ... keep posting characters ... this task may block when the queue
\r
1131 cValueToPost = 'c';
\r
1132 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1135 // ISR that outputs all the characters received on the queue.
\r
1136 void vISR_Routine( void )
\r
1138 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1139 portCHAR cRxedChar;
\r
1141 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1143 // A character was received. Output the character now.
\r
1144 vOutputCharacter( cRxedChar );
\r
1146 // If removing the character from the queue woke the task that was
\r
1147 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1148 // pdTRUE. No matter how many times this loop iterates only one
\r
1149 // task will be woken.
\r
1152 if( cTaskWokenByPost != ( portCHAR ) pdFALSE;
\r
1158 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1159 * \ingroup QueueManagement
\r
1161 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1164 * Utilities to query queue that are safe to use from an ISR. These utilities
\r
1165 * should be used only from witin an ISR, or within a critical section.
\r
1167 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
\r
1168 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
\r
1169 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
\r
1173 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1174 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1175 * xQueueGenericReceive().
\r
1177 * The source code that implements the alternative (Alt) API is much
\r
1178 * simpler because it executes everything from within a critical section.
\r
1179 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1180 * preferred fully featured API too. The fully featured API has more
\r
1181 * complex code that takes longer to execute, but makes much less use of
\r
1182 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1183 * responsiveness to gain execution speed, whereas the fully featured API
\r
1184 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1186 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1187 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1188 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
1189 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
1190 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
1191 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
1194 * The functions defined above are for passing data to and from tasks. The
\r
1195 * functions below are the equivalents for passing data to and from
\r
1198 * These functions are called from the co-routine macro implementation and
\r
1199 * should not be called directly from application code. Instead use the macro
\r
1200 * wrappers defined within croutine.h.
\r
1202 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1203 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1204 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1205 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1208 * For internal use only. Use xSemaphoreCreateMutex() or
\r
1209 * xSemaphoreCreateCounting() instead of calling these functions directly.
\r
1211 xQueueHandle xQueueCreateMutex( void );
\r
1212 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1215 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1216 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1218 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
\r
1219 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex );
\r
1222 * The registry is provided as a means for kernel aware debuggers to
\r
1223 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
\r
1224 * a queue, semaphore or mutex handle to the registry if you want the handle
\r
1225 * to be available to a kernel aware debugger. If you are not using a kernel
\r
1226 * aware debugger then this function can be ignored.
\r
1228 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
\r
1229 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
\r
1230 * within FreeRTOSConfig.h for the registry to be available. Its value
\r
1231 * does not effect the number of queues, semaphores and mutexes that can be
\r
1232 * created - just the number that the registry can hold.
\r
1234 * @param xQueue The handle of the queue being added to the registry. This
\r
1235 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
\r
1236 * handles can also be passed in here.
\r
1238 * @param pcName The name to be associated with the handle. This is the
\r
1239 * name that the kernel aware debugger will display.
\r
1241 #if configQUEUE_REGISTRY_SIZE > 0
\r
1242 void vQueueAddToRegistry( xQueueHandle xQueue, signed portCHAR *pcName );
\r
1248 #ifdef __cplusplus
\r
1252 #endif /* QUEUE_H */
\r