2 FreeRTOS.org V5.0.4 - Copyright (C) 2003-2008 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 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
50 #ifndef INC_FREERTOS_H
\r
51 #error "#include FreeRTOS.h" must appear in source files before "#include queue.h"
\r
63 typedef void * xQueueHandle;
\r
65 /* For internal use only. */
\r
66 #define queueSEND_TO_BACK ( 0 )
\r
67 #define queueSEND_TO_FRONT ( 1 )
\r
73 xQueueHandle xQueueCreate(
\r
74 unsigned portBASE_TYPE uxQueueLength,
\r
75 unsigned portBASE_TYPE uxItemSize
\r
79 * Creates a new queue instance. This allocates the storage required by the
\r
80 * new queue and returns a handle for the queue.
\r
82 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
84 * @param uxItemSize The number of bytes each item in the queue will require.
\r
85 * Items are queued by copy, not by reference, so this is the number of bytes
\r
86 * that will be copied for each posted item. Each item on the queue must be
\r
89 * @return If the queue is successfully create then a handle to the newly
\r
90 * created queue is returned. If the queue cannot be created then 0 is
\r
97 portCHAR ucMessageID;
\r
98 portCHAR ucData[ 20 ];
\r
101 void vATask( void *pvParameters )
\r
103 xQueueHandle xQueue1, xQueue2;
\r
105 // Create a queue capable of containing 10 unsigned long values.
\r
106 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
109 // Queue was not created and must not be used.
\r
112 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
113 // These should be passed by pointer as they contain a lot of data.
\r
114 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
117 // Queue was not created and must not be used.
\r
120 // ... Rest of task code.
\r
123 * \defgroup xQueueCreate xQueueCreate
\r
124 * \ingroup QueueManagement
\r
126 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
131 portBASE_TYPE xQueueSendToToFront(
\r
132 xQueueHandle xQueue,
\r
133 const void * pvItemToQueue,
\r
134 portTickType xTicksToWait
\r
138 * This is a macro that calls xQueueGenericSend().
\r
140 * Post an item to the front of a queue. The item is queued by copy, not by
\r
141 * reference. This function must not be called from an interrupt service
\r
142 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
145 * @param xQueue The handle to the queue on which the item is to be posted.
\r
147 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
148 * queue. The size of the items the queue will hold was defined when the
\r
149 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
150 * into the queue storage area.
\r
152 * @param xTicksToWait The maximum amount of time the task should block
\r
153 * waiting for space to become available on the queue, should it already
\r
154 * be full. The call will return immediately if this is set to 0. The
\r
155 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
156 * should be used to convert to real time if this is required.
\r
158 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
164 portCHAR ucMessageID;
\r
165 portCHAR ucData[ 20 ];
\r
168 unsigned portLONG ulVar = 10UL;
\r
170 void vATask( void *pvParameters )
\r
172 xQueueHandle xQueue1, xQueue2;
\r
173 struct AMessage *pxMessage;
\r
175 // Create a queue capable of containing 10 unsigned long values.
\r
176 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
178 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
179 // These should be passed by pointer as they contain a lot of data.
\r
180 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
186 // Send an unsigned long. Wait for 10 ticks for space to become
\r
187 // available if necessary.
\r
188 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
190 // Failed to post the message, even after 10 ticks.
\r
196 // Send a pointer to a struct AMessage object. Don't block if the
\r
197 // queue is already full.
\r
198 pxMessage = & xMessage;
\r
199 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
202 // ... Rest of task code.
\r
205 * \defgroup xQueueSend xQueueSend
\r
206 * \ingroup QueueManagement
\r
208 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
213 portBASE_TYPE xQueueSendToBack(
\r
214 xQueueHandle xQueue,
\r
215 const void * pvItemToQueue,
\r
216 portTickType xTicksToWait
\r
220 * This is a macro that calls xQueueGenericSend().
\r
222 * Post an item to the back of a queue. The item is queued by copy, not by
\r
223 * reference. This function must not be called from an interrupt service
\r
224 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
227 * @param xQueue The handle to the queue on which the item is to be posted.
\r
229 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
230 * queue. The size of the items the queue will hold was defined when the
\r
231 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
232 * into the queue storage area.
\r
234 * @param xTicksToWait The maximum amount of time the task should block
\r
235 * waiting for space to become available on the queue, should it already
\r
236 * be full. The call will return immediately if this is set to 0. The
\r
237 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
238 * should be used to convert to real time if this is required.
\r
240 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
246 portCHAR ucMessageID;
\r
247 portCHAR ucData[ 20 ];
\r
250 unsigned portLONG ulVar = 10UL;
\r
252 void vATask( void *pvParameters )
\r
254 xQueueHandle xQueue1, xQueue2;
\r
255 struct AMessage *pxMessage;
\r
257 // Create a queue capable of containing 10 unsigned long values.
\r
258 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
260 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
261 // These should be passed by pointer as they contain a lot of data.
\r
262 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
268 // Send an unsigned long. Wait for 10 ticks for space to become
\r
269 // available if necessary.
\r
270 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
272 // Failed to post the message, even after 10 ticks.
\r
278 // Send a pointer to a struct AMessage object. Don't block if the
\r
279 // queue is already full.
\r
280 pxMessage = & xMessage;
\r
281 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
284 // ... Rest of task code.
\r
287 * \defgroup xQueueSend xQueueSend
\r
288 * \ingroup QueueManagement
\r
290 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
295 portBASE_TYPE xQueueSend(
\r
296 xQueueHandle xQueue,
\r
297 const void * pvItemToQueue,
\r
298 portTickType xTicksToWait
\r
302 * This is a macro that calls xQueueGenericSend(). It is included for
\r
303 * backward compatibility with versions of FreeRTOS.org that did not
\r
304 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
305 * equivalent to xQueueSendToBack().
\r
307 * Post an item on a queue. The item is queued by copy, not by reference.
\r
308 * This function must not be called from an interrupt service routine.
\r
309 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
311 * @param xQueue The handle to the queue on which the item is to be posted.
\r
313 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
314 * queue. The size of the items the queue will hold was defined when the
\r
315 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
316 * into the queue storage area.
\r
318 * @param xTicksToWait The maximum amount of time the task should block
\r
319 * waiting for space to become available on the queue, should it already
\r
320 * be full. The call will return immediately if this is set to 0. The
\r
321 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
322 * should be used to convert to real time if this is required.
\r
324 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
330 portCHAR ucMessageID;
\r
331 portCHAR ucData[ 20 ];
\r
334 unsigned portLONG ulVar = 10UL;
\r
336 void vATask( void *pvParameters )
\r
338 xQueueHandle xQueue1, xQueue2;
\r
339 struct AMessage *pxMessage;
\r
341 // Create a queue capable of containing 10 unsigned long values.
\r
342 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
344 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
345 // These should be passed by pointer as they contain a lot of data.
\r
346 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
352 // Send an unsigned long. Wait for 10 ticks for space to become
\r
353 // available if necessary.
\r
354 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
356 // Failed to post the message, even after 10 ticks.
\r
362 // Send a pointer to a struct AMessage object. Don't block if the
\r
363 // queue is already full.
\r
364 pxMessage = & xMessage;
\r
365 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
368 // ... Rest of task code.
\r
371 * \defgroup xQueueSend xQueueSend
\r
372 * \ingroup QueueManagement
\r
374 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
380 portBASE_TYPE xQueueGenericSend(
\r
381 xQueueHandle xQueue,
\r
382 const void * pvItemToQueue,
\r
383 portTickType xTicksToWait
\r
384 portBASE_TYPE xCopyPosition
\r
388 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
389 * xQueueSendToBack() are used in place of calling this function directly.
\r
391 * Post an item on a queue. The item is queued by copy, not by reference.
\r
392 * This function must not be called from an interrupt service routine.
\r
393 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
395 * @param xQueue The handle to the queue on which the item is to be posted.
\r
397 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
398 * queue. The size of the items the queue will hold was defined when the
\r
399 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
400 * into the queue storage area.
\r
402 * @param xTicksToWait The maximum amount of time the task should block
\r
403 * waiting for space to become available on the queue, should it already
\r
404 * be full. The call will return immediately if this is set to 0. The
\r
405 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
406 * should be used to convert to real time if this is required.
\r
408 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
409 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
410 * at the front of the queue (for high priority messages).
\r
412 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
418 portCHAR ucMessageID;
\r
419 portCHAR ucData[ 20 ];
\r
422 unsigned portLONG ulVar = 10UL;
\r
424 void vATask( void *pvParameters )
\r
426 xQueueHandle xQueue1, xQueue2;
\r
427 struct AMessage *pxMessage;
\r
429 // Create a queue capable of containing 10 unsigned long values.
\r
430 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
432 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
433 // These should be passed by pointer as they contain a lot of data.
\r
434 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
440 // Send an unsigned long. Wait for 10 ticks for space to become
\r
441 // available if necessary.
\r
442 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
444 // Failed to post the message, even after 10 ticks.
\r
450 // Send a pointer to a struct AMessage object. Don't block if the
\r
451 // queue is already full.
\r
452 pxMessage = & xMessage;
\r
453 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
456 // ... Rest of task code.
\r
459 * \defgroup xQueueSend xQueueSend
\r
460 * \ingroup QueueManagement
\r
462 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
467 portBASE_TYPE xQueuePeek(
\r
468 xQueueHandle xQueue,
\r
470 portTickType xTicksToWait
\r
473 * This is a macro that calls the xQueueGenericReceive() function.
\r
475 * Receive an item from a queue without removing the item from the queue.
\r
476 * The item is received by copy so a buffer of adequate size must be
\r
477 * provided. The number of bytes copied into the buffer was defined when
\r
478 * the queue was created.
\r
480 * Successfully received items remain on the queue so will be returned again
\r
481 * by the next call, or a call to xQueueReceive().
\r
483 * This macro must not be used in an interrupt service routine.
\r
485 * @param pxQueue The handle to the queue from which the item is to be
\r
488 * @param pvBuffer Pointer to the buffer into which the received item will
\r
491 * @param xTicksToWait The maximum amount of time the task should block
\r
492 * waiting for an item to receive should the queue be empty at the time
\r
493 * of the call. The time is defined in tick periods so the constant
\r
494 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
496 * @return pdTRUE if an item was successfully received from the queue,
\r
497 * otherwise pdFALSE.
\r
503 portCHAR ucMessageID;
\r
504 portCHAR ucData[ 20 ];
\r
507 xQueueHandle xQueue;
\r
509 // Task to create a queue and post a value.
\r
510 void vATask( void *pvParameters )
\r
512 struct AMessage *pxMessage;
\r
514 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
515 // These should be passed by pointer as they contain a lot of data.
\r
516 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
519 // Failed to create the queue.
\r
524 // Send a pointer to a struct AMessage object. Don't block if the
\r
525 // queue is already full.
\r
526 pxMessage = & xMessage;
\r
527 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
529 // ... Rest of task code.
\r
532 // Task to peek the data from the queue.
\r
533 void vADifferentTask( void *pvParameters )
\r
535 struct AMessage *pxRxedMessage;
\r
539 // Peek a message on the created queue. Block for 10 ticks if a
\r
540 // message is not immediately available.
\r
541 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
543 // pcRxedMessage now points to the struct AMessage variable posted
\r
544 // by vATask, but the item still remains on the queue.
\r
548 // ... Rest of task code.
\r
551 * \defgroup xQueueReceive xQueueReceive
\r
552 * \ingroup QueueManagement
\r
554 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
559 portBASE_TYPE xQueueReceive(
\r
560 xQueueHandle xQueue,
\r
562 portTickType xTicksToWait
\r
565 * This is a macro that calls the xQueueGenericReceive() function.
\r
567 * Receive an item from a queue. The item is received by copy so a buffer of
\r
568 * adequate size must be provided. The number of bytes copied into the buffer
\r
569 * was defined when the queue was created.
\r
571 * Successfully received items are removed from the queue.
\r
573 * This function must not be used in an interrupt service routine. See
\r
574 * xQueueReceiveFromISR for an alternative that can.
\r
576 * @param pxQueue The handle to the queue from which the item is to be
\r
579 * @param pvBuffer Pointer to the buffer into which the received item will
\r
582 * @param xTicksToWait The maximum amount of time the task should block
\r
583 * waiting for an item to receive should the queue be empty at the time
\r
584 * of the call. The time is defined in tick periods so the constant
\r
585 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
587 * @return pdTRUE if an item was successfully received from the queue,
\r
588 * otherwise pdFALSE.
\r
594 portCHAR ucMessageID;
\r
595 portCHAR ucData[ 20 ];
\r
598 xQueueHandle xQueue;
\r
600 // Task to create a queue and post a value.
\r
601 void vATask( void *pvParameters )
\r
603 struct AMessage *pxMessage;
\r
605 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
606 // These should be passed by pointer as they contain a lot of data.
\r
607 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
610 // Failed to create the queue.
\r
615 // Send a pointer to a struct AMessage object. Don't block if the
\r
616 // queue is already full.
\r
617 pxMessage = & xMessage;
\r
618 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
620 // ... Rest of task code.
\r
623 // Task to receive from the queue.
\r
624 void vADifferentTask( void *pvParameters )
\r
626 struct AMessage *pxRxedMessage;
\r
630 // Receive a message on the created queue. Block for 10 ticks if a
\r
631 // message is not immediately available.
\r
632 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
634 // pcRxedMessage now points to the struct AMessage variable posted
\r
639 // ... Rest of task code.
\r
642 * \defgroup xQueueReceive xQueueReceive
\r
643 * \ingroup QueueManagement
\r
645 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
651 portBASE_TYPE xQueueGenericReceive(
\r
652 xQueueHandle xQueue,
\r
654 portTickType xTicksToWait
\r
655 portBASE_TYPE xJustPeek
\r
658 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
659 * this function directly.
\r
661 * Receive an item from a queue. The item is received by copy so a buffer of
\r
662 * adequate size must be provided. The number of bytes copied into the buffer
\r
663 * was defined when the queue was created.
\r
665 * This function must not be used in an interrupt service routine. See
\r
666 * xQueueReceiveFromISR for an alternative that can.
\r
668 * @param pxQueue The handle to the queue from which the item is to be
\r
671 * @param pvBuffer Pointer to the buffer into which the received item will
\r
674 * @param xTicksToWait The maximum amount of time the task should block
\r
675 * waiting for an item to receive should the queue be empty at the time
\r
676 * of the call. The time is defined in tick periods so the constant
\r
677 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
679 * @param xJustPeek When set to true, the item received from the queue is not
\r
680 * actually removed from the queue - meaning a subsequent call to
\r
681 * xQueueReceive() will return the same item. When set to false, the item
\r
682 * being received from the queue is also removed from the queue.
\r
684 * @return pdTRUE if an item was successfully received from the queue,
\r
685 * otherwise pdFALSE.
\r
691 portCHAR ucMessageID;
\r
692 portCHAR ucData[ 20 ];
\r
695 xQueueHandle xQueue;
\r
697 // Task to create a queue and post a value.
\r
698 void vATask( void *pvParameters )
\r
700 struct AMessage *pxMessage;
\r
702 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
703 // These should be passed by pointer as they contain a lot of data.
\r
704 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
707 // Failed to create the queue.
\r
712 // Send a pointer to a struct AMessage object. Don't block if the
\r
713 // queue is already full.
\r
714 pxMessage = & xMessage;
\r
715 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
717 // ... Rest of task code.
\r
720 // Task to receive from the queue.
\r
721 void vADifferentTask( void *pvParameters )
\r
723 struct AMessage *pxRxedMessage;
\r
727 // Receive a message on the created queue. Block for 10 ticks if a
\r
728 // message is not immediately available.
\r
729 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
731 // pcRxedMessage now points to the struct AMessage variable posted
\r
736 // ... Rest of task code.
\r
739 * \defgroup xQueueReceive xQueueReceive
\r
740 * \ingroup QueueManagement
\r
742 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
746 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
748 * Return the number of messages stored in a queue.
\r
750 * @param xQueue A handle to the queue being queried.
\r
752 * @return The number of messages available in the queue.
\r
754 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
755 * \ingroup QueueManagement
\r
757 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
761 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
763 * Delete a queue - freeing all the memory allocated for storing of items
\r
764 * placed on the queue.
\r
766 * @param xQueue A handle to the queue to be deleted.
\r
768 * \page vQueueDelete vQueueDelete
\r
769 * \ingroup QueueManagement
\r
771 void vQueueDelete( xQueueHandle xQueue );
\r
776 portBASE_TYPE xQueueSendToFrontFromISR(
\r
777 xQueueHandle pxQueue,
\r
778 const void *pvItemToQueue,
\r
779 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
783 * This is a macro that calls xQueueGenericSendFromISR().
\r
785 * Post an item to the front of a queue. It is safe to use this macro from
\r
786 * within an interrupt service routine.
\r
788 * Items are queued by copy not reference so it is preferable to only
\r
789 * queue small items, especially when called from an ISR. In most cases
\r
790 * it would be preferable to store a pointer to the item being queued.
\r
792 * @param xQueue The handle to the queue on which the item is to be posted.
\r
794 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
795 * queue. The size of the items the queue will hold was defined when the
\r
796 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
797 * into the queue storage area.
\r
799 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
\r
800 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
801 * to unblock, and the unblocked task has a priority higher than the currently
\r
802 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
\r
803 * a context switch should be requested before the interrupt is exited.
\r
805 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
808 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
811 void vBufferISR( void )
\r
814 portBASE_TYPE xHigherPrioritTaskWoken;
\r
816 // We have not woken a task at the start of the ISR.
\r
817 xHigherPriorityTaskWoken = pdFALSE;
\r
819 // Loop until the buffer is empty.
\r
822 // Obtain a byte from the buffer.
\r
823 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
826 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
828 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
830 // Now the buffer is empty we can switch context if necessary.
\r
831 if( xHigherPriorityTaskWoken )
\r
838 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
839 * \ingroup QueueManagement
\r
841 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_FRONT )
\r
847 portBASE_TYPE xQueueSendToBackFromISR(
\r
848 xQueueHandle pxQueue,
\r
849 const void *pvItemToQueue,
\r
850 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
854 * This is a macro that calls xQueueGenericSendFromISR().
\r
856 * Post an item to the back of a queue. It is safe to use this macro from
\r
857 * within an interrupt service routine.
\r
859 * Items are queued by copy not reference so it is preferable to only
\r
860 * queue small items, especially when called from an ISR. In most cases
\r
861 * it would be preferable to store a pointer to the item being queued.
\r
863 * @param xQueue The handle to the queue on which the item is to be posted.
\r
865 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
866 * queue. The size of the items the queue will hold was defined when the
\r
867 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
868 * into the queue storage area.
\r
870 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
\r
871 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
872 * to unblock, and the unblocked task has a priority higher than the currently
\r
873 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
\r
874 * a context switch should be requested before the interrupt is exited.
\r
876 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
879 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
882 void vBufferISR( void )
\r
885 portBASE_TYPE xHigherPriorityTaskWoken;
\r
887 // We have not woken a task at the start of the ISR.
\r
888 xHigherPriorityTaskWoken = pdFALSE;
\r
890 // Loop until the buffer is empty.
\r
893 // Obtain a byte from the buffer.
\r
894 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
897 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
899 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
901 // Now the buffer is empty we can switch context if necessary.
\r
902 if( xHigherPriorityTaskWoken )
\r
909 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
910 * \ingroup QueueManagement
\r
912 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
917 portBASE_TYPE xQueueSendFromISR(
\r
918 xQueueHandle pxQueue,
\r
919 const void *pvItemToQueue,
\r
920 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
924 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
925 * for backward compatibility with versions of FreeRTOS.org that did not
\r
926 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
929 * Post an item to the back of a queue. It is safe to use this function from
\r
930 * within an interrupt service routine.
\r
932 * Items are queued by copy not reference so it is preferable to only
\r
933 * queue small items, especially when called from an ISR. In most cases
\r
934 * it would be preferable to store a pointer to the item being queued.
\r
936 * @param xQueue The handle to the queue on which the item is to be posted.
\r
938 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
939 * queue. The size of the items the queue will hold was defined when the
\r
940 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
941 * into the queue storage area.
\r
943 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
\r
944 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
945 * to unblock, and the unblocked task has a priority higher than the currently
\r
946 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
947 * a context switch should be requested before the interrupt is exited.
\r
949 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
952 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
955 void vBufferISR( void )
\r
958 portBASE_TYPE xHigherPriorityTaskWoken;
\r
960 // We have not woken a task at the start of the ISR.
\r
961 xHigherPriorityTaskWoken = pdFALSE;
\r
963 // Loop until the buffer is empty.
\r
966 // Obtain a byte from the buffer.
\r
967 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
970 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
972 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
974 // Now the buffer is empty we can switch context if necessary.
\r
975 if( xHigherPriorityTaskWoken )
\r
977 // Actual macro used here is port specific.
\r
978 taskYIELD_FROM_ISR ();
\r
983 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
984 * \ingroup QueueManagement
\r
986 #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
991 portBASE_TYPE xQueueGenericSendFromISR(
\r
992 xQueueHandle pxQueue,
\r
993 const void *pvItemToQueue,
\r
994 portBASE_TYPE *pxHigherPriorityTaskWoken,
\r
995 portBASE_TYPE xCopyPosition
\r
999 * It is preferred that the macros xQueueSendFromISR(),
\r
1000 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1001 * of calling this function directly.
\r
1003 * Post an item on a queue. It is safe to use this function from within an
\r
1004 * interrupt service routine.
\r
1006 * Items are queued by copy not reference so it is preferable to only
\r
1007 * queue small items, especially when called from an ISR. In most cases
\r
1008 * it would be preferable to store a pointer to the item being queued.
\r
1010 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1012 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1013 * queue. The size of the items the queue will hold was defined when the
\r
1014 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1015 * into the queue storage area.
\r
1017 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
\r
1018 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1019 * to unblock, and the unblocked task has a priority higher than the currently
\r
1020 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
\r
1021 * a context switch should be requested before the interrupt is exited.
\r
1023 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1024 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1025 * at the front of the queue (for high priority messages).
\r
1027 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1030 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1033 void vBufferISR( void )
\r
1036 portBASE_TYPE xHigherPriorityTaskWokenByPost;
\r
1038 // We have not woken a task at the start of the ISR.
\r
1039 xHigherPriorityTaskWokenByPost = pdFALSE;
\r
1041 // Loop until the buffer is empty.
\r
1044 // Obtain a byte from the buffer.
\r
1045 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1047 // Post each byte.
\r
1048 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
\r
1050 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1052 // Now the buffer is empty we can switch context if necessary. Note that the
\r
1053 // name of the yield function required is port specific.
\r
1054 if( xHigherPriorityTaskWokenByPost )
\r
1056 taskYIELD_YIELD_FROM_ISR();
\r
1061 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1062 * \ingroup QueueManagement
\r
1064 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
\r
1069 portBASE_TYPE xQueueReceiveFromISR(
\r
1070 xQueueHandle pxQueue,
\r
1072 portBASE_TYPE *pxTaskWoken
\r
1076 * Receive an item from a queue. It is safe to use this function from within an
\r
1077 * interrupt service routine.
\r
1079 * @param pxQueue The handle to the queue from which the item is to be
\r
1082 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1085 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1086 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1087 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1088 * remain unchanged.
\r
1090 * @return pdTRUE if an item was successfully received from the queue,
\r
1091 * otherwise pdFALSE.
\r
1096 xQueueHandle xQueue;
\r
1098 // Function to create a queue and post some values.
\r
1099 void vAFunction( void *pvParameters )
\r
1101 portCHAR cValueToPost;
\r
1102 const portTickType xBlockTime = ( portTickType )0xff;
\r
1104 // Create a queue capable of containing 10 characters.
\r
1105 xQueue = xQueueCreate( 10, sizeof( portCHAR ) );
\r
1108 // Failed to create the queue.
\r
1113 // Post some characters that will be used within an ISR. If the queue
\r
1114 // is full then this task will block for xBlockTime ticks.
\r
1115 cValueToPost = 'a';
\r
1116 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1117 cValueToPost = 'b';
\r
1118 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1120 // ... keep posting characters ... this task may block when the queue
\r
1123 cValueToPost = 'c';
\r
1124 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1127 // ISR that outputs all the characters received on the queue.
\r
1128 void vISR_Routine( void )
\r
1130 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1131 portCHAR cRxedChar;
\r
1133 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1135 // A character was received. Output the character now.
\r
1136 vOutputCharacter( cRxedChar );
\r
1138 // If removing the character from the queue woke the task that was
\r
1139 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1140 // pdTRUE. No matter how many times this loop iterates only one
\r
1141 // task will be woken.
\r
1144 if( cTaskWokenByPost != ( portCHAR ) pdFALSE;
\r
1150 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1151 * \ingroup QueueManagement
\r
1153 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1156 * Utilities to query queue that are safe to use from an ISR. These utilities
\r
1157 * should be used only from witin an ISR, or within a critical section.
\r
1159 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
\r
1160 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
\r
1161 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
\r
1165 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1166 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1167 * xQueueGenericReceive().
\r
1169 * The source code that implements the alternative (Alt) API is much
\r
1170 * simpler because it executes everything from within a critical section.
\r
1171 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1172 * preferred fully featured API too. The fully featured API has more
\r
1173 * complex code that takes longer to execute, but makes much less use of
\r
1174 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1175 * responsiveness to gain execution speed, whereas the fully featured API
\r
1176 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1178 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1179 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1180 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
1181 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
1182 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
1183 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
1186 * The functions defined above are for passing data to and from tasks. The
\r
1187 * functions below are the equivalents for passing data to and from
\r
1190 * These functions are called from the co-routine macro implementation and
\r
1191 * should not be called directly from application code. Instead use the macro
\r
1192 * wrappers defined within croutine.h.
\r
1194 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1195 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1196 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1197 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1200 * For internal use only. Use xSemaphoreCreateMutex() or
\r
1201 * xSemaphoreCreateCounting() instead of calling these functions directly.
\r
1203 xQueueHandle xQueueCreateMutex( void );
\r
1204 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1207 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1208 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1210 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
\r
1211 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex );
\r
1214 * The registry is provided as a means for kernel aware debuggers to
\r
1215 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
\r
1216 * a queue, semaphore or mutex handle to the registry if you want the handle
\r
1217 * to be available to a kernel aware debugger. If you are not using a kernel
\r
1218 * aware debugger then this function can be ignored.
\r
1220 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
\r
1221 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
\r
1222 * within FreeRTOSConfig.h for the registry to be available. Its value
\r
1223 * does not effect the number of queues, semaphores and mutexes that can be
\r
1224 * created - just the number that the registry can hold.
\r
1226 * @param xQueue The handle of the queue being added to the registry. This
\r
1227 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
\r
1228 * handles can also be passed in here.
\r
1230 * @param pcName The name to be associated with the handle. This is the
\r
1231 * name that the kernel aware debugger will display.
\r
1233 #if configQUEUE_REGISTRY_SIZE > 0
\r
1234 void vQueueAddToRegistry( xQueueHandle xQueue, signed portCHAR *pcName );
\r
1240 #ifdef __cplusplus
\r
1244 #endif /* QUEUE_H */
\r