2 FreeRTOS.org V5.1.1 - 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 and the
\r
155 * queue is full. The time is defined in tick periods so the constant
\r
156 * portTICK_RATE_MS 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 and the queue
\r
237 * is full. The time is defined in tick periods so the constant
\r
238 * portTICK_RATE_MS 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 and the
\r
321 * queue is full. The time is defined in tick periods so the constant
\r
322 * portTICK_RATE_MS 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 and the
\r
405 * queue is full. The time is defined in tick periods so the constant
\r
406 * portTICK_RATE_MS 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
495 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
\r
498 * @return pdTRUE if an item was successfully received from the queue,
\r
499 * otherwise pdFALSE.
\r
505 portCHAR ucMessageID;
\r
506 portCHAR ucData[ 20 ];
\r
509 xQueueHandle xQueue;
\r
511 // Task to create a queue and post a value.
\r
512 void vATask( void *pvParameters )
\r
514 struct AMessage *pxMessage;
\r
516 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
517 // These should be passed by pointer as they contain a lot of data.
\r
518 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
521 // Failed to create the queue.
\r
526 // Send a pointer to a struct AMessage object. Don't block if the
\r
527 // queue is already full.
\r
528 pxMessage = & xMessage;
\r
529 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
531 // ... Rest of task code.
\r
534 // Task to peek the data from the queue.
\r
535 void vADifferentTask( void *pvParameters )
\r
537 struct AMessage *pxRxedMessage;
\r
541 // Peek a message on the created queue. Block for 10 ticks if a
\r
542 // message is not immediately available.
\r
543 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
545 // pcRxedMessage now points to the struct AMessage variable posted
\r
546 // by vATask, but the item still remains on the queue.
\r
550 // ... Rest of task code.
\r
553 * \defgroup xQueueReceive xQueueReceive
\r
554 * \ingroup QueueManagement
\r
556 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
561 portBASE_TYPE xQueueReceive(
\r
562 xQueueHandle xQueue,
\r
564 portTickType xTicksToWait
\r
567 * This is a macro that calls the xQueueGenericReceive() function.
\r
569 * Receive an item from a queue. The item is received by copy so a buffer of
\r
570 * adequate size must be provided. The number of bytes copied into the buffer
\r
571 * was defined when the queue was created.
\r
573 * Successfully received items are removed from the queue.
\r
575 * This function must not be used in an interrupt service routine. See
\r
576 * xQueueReceiveFromISR for an alternative that can.
\r
578 * @param pxQueue The handle to the queue from which the item is to be
\r
581 * @param pvBuffer Pointer to the buffer into which the received item will
\r
584 * @param xTicksToWait The maximum amount of time the task should block
\r
585 * waiting for an item to receive should the queue be empty at the time
\r
586 * of the call. xQueueReceive() will return immediately if xTicksToWait
\r
587 * is zero and the queue is empty. The time is defined in tick periods so the
\r
588 * constant portTICK_RATE_MS should be used to convert to real time if this is
\r
591 * @return pdTRUE if an item was successfully received from the queue,
\r
592 * otherwise pdFALSE.
\r
598 portCHAR ucMessageID;
\r
599 portCHAR ucData[ 20 ];
\r
602 xQueueHandle xQueue;
\r
604 // Task to create a queue and post a value.
\r
605 void vATask( void *pvParameters )
\r
607 struct AMessage *pxMessage;
\r
609 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
610 // These should be passed by pointer as they contain a lot of data.
\r
611 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
614 // Failed to create the queue.
\r
619 // Send a pointer to a struct AMessage object. Don't block if the
\r
620 // queue is already full.
\r
621 pxMessage = & xMessage;
\r
622 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
624 // ... Rest of task code.
\r
627 // Task to receive from the queue.
\r
628 void vADifferentTask( void *pvParameters )
\r
630 struct AMessage *pxRxedMessage;
\r
634 // Receive a message on the created queue. Block for 10 ticks if a
\r
635 // message is not immediately available.
\r
636 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
638 // pcRxedMessage now points to the struct AMessage variable posted
\r
643 // ... Rest of task code.
\r
646 * \defgroup xQueueReceive xQueueReceive
\r
647 * \ingroup QueueManagement
\r
649 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
655 portBASE_TYPE xQueueGenericReceive(
\r
656 xQueueHandle xQueue,
\r
658 portTickType xTicksToWait
\r
659 portBASE_TYPE xJustPeek
\r
662 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
663 * this function directly.
\r
665 * Receive an item from a queue. The item is received by copy so a buffer of
\r
666 * adequate size must be provided. The number of bytes copied into the buffer
\r
667 * was defined when the queue was created.
\r
669 * This function must not be used in an interrupt service routine. See
\r
670 * xQueueReceiveFromISR for an alternative that can.
\r
672 * @param pxQueue The handle to the queue from which the item is to be
\r
675 * @param pvBuffer Pointer to the buffer into which the received item will
\r
678 * @param xTicksToWait The maximum amount of time the task should block
\r
679 * waiting for an item to receive should the queue be empty at the time
\r
680 * of the call. The time is defined in tick periods so the constant
\r
681 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
682 * xQueueGenericReceive() will return immediately if the queue is empty and
\r
683 * xTicksToWait is 0.
\r
685 * @param xJustPeek When set to true, the item received from the queue is not
\r
686 * actually removed from the queue - meaning a subsequent call to
\r
687 * xQueueReceive() will return the same item. When set to false, the item
\r
688 * being received from the queue is also removed from the queue.
\r
690 * @return pdTRUE if an item was successfully received from the queue,
\r
691 * otherwise pdFALSE.
\r
697 portCHAR ucMessageID;
\r
698 portCHAR ucData[ 20 ];
\r
701 xQueueHandle xQueue;
\r
703 // Task to create a queue and post a value.
\r
704 void vATask( void *pvParameters )
\r
706 struct AMessage *pxMessage;
\r
708 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
709 // These should be passed by pointer as they contain a lot of data.
\r
710 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
713 // Failed to create the queue.
\r
718 // Send a pointer to a struct AMessage object. Don't block if the
\r
719 // queue is already full.
\r
720 pxMessage = & xMessage;
\r
721 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
723 // ... Rest of task code.
\r
726 // Task to receive from the queue.
\r
727 void vADifferentTask( void *pvParameters )
\r
729 struct AMessage *pxRxedMessage;
\r
733 // Receive a message on the created queue. Block for 10 ticks if a
\r
734 // message is not immediately available.
\r
735 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
737 // pcRxedMessage now points to the struct AMessage variable posted
\r
742 // ... Rest of task code.
\r
745 * \defgroup xQueueReceive xQueueReceive
\r
746 * \ingroup QueueManagement
\r
748 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
752 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
754 * Return the number of messages stored in a queue.
\r
756 * @param xQueue A handle to the queue being queried.
\r
758 * @return The number of messages available in the queue.
\r
760 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
761 * \ingroup QueueManagement
\r
763 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
767 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
769 * Delete a queue - freeing all the memory allocated for storing of items
\r
770 * placed on the queue.
\r
772 * @param xQueue A handle to the queue to be deleted.
\r
774 * \page vQueueDelete vQueueDelete
\r
775 * \ingroup QueueManagement
\r
777 void vQueueDelete( xQueueHandle xQueue );
\r
782 portBASE_TYPE xQueueSendToFrontFromISR(
\r
783 xQueueHandle pxQueue,
\r
784 const void *pvItemToQueue,
\r
785 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
789 * This is a macro that calls xQueueGenericSendFromISR().
\r
791 * Post an item to the front of a queue. It is safe to use this macro from
\r
792 * within an interrupt service routine.
\r
794 * Items are queued by copy not reference so it is preferable to only
\r
795 * queue small items, especially when called from an ISR. In most cases
\r
796 * it would be preferable to store a pointer to the item being queued.
\r
798 * @param xQueue The handle to the queue on which the item is to be posted.
\r
800 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
801 * queue. The size of the items the queue will hold was defined when the
\r
802 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
803 * into the queue storage area.
\r
805 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
\r
806 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
807 * to unblock, and the unblocked task has a priority higher than the currently
\r
808 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
\r
809 * a context switch should be requested before the interrupt is exited.
\r
811 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
814 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
817 void vBufferISR( void )
\r
820 portBASE_TYPE xHigherPrioritTaskWoken;
\r
822 // We have not woken a task at the start of the ISR.
\r
823 xHigherPriorityTaskWoken = pdFALSE;
\r
825 // Loop until the buffer is empty.
\r
828 // Obtain a byte from the buffer.
\r
829 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
832 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
834 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
836 // Now the buffer is empty we can switch context if necessary.
\r
837 if( xHigherPriorityTaskWoken )
\r
844 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
845 * \ingroup QueueManagement
\r
847 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_FRONT )
\r
853 portBASE_TYPE xQueueSendToBackFromISR(
\r
854 xQueueHandle pxQueue,
\r
855 const void *pvItemToQueue,
\r
856 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
860 * This is a macro that calls xQueueGenericSendFromISR().
\r
862 * Post an item to the back of a queue. It is safe to use this macro from
\r
863 * within an interrupt service routine.
\r
865 * Items are queued by copy not reference so it is preferable to only
\r
866 * queue small items, especially when called from an ISR. In most cases
\r
867 * it would be preferable to store a pointer to the item being queued.
\r
869 * @param xQueue The handle to the queue on which the item is to be posted.
\r
871 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
872 * queue. The size of the items the queue will hold was defined when the
\r
873 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
874 * into the queue storage area.
\r
876 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
\r
877 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
878 * to unblock, and the unblocked task has a priority higher than the currently
\r
879 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
\r
880 * a context switch should be requested before the interrupt is exited.
\r
882 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
885 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
888 void vBufferISR( void )
\r
891 portBASE_TYPE xHigherPriorityTaskWoken;
\r
893 // We have not woken a task at the start of the ISR.
\r
894 xHigherPriorityTaskWoken = pdFALSE;
\r
896 // Loop until the buffer is empty.
\r
899 // Obtain a byte from the buffer.
\r
900 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
903 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
905 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
907 // Now the buffer is empty we can switch context if necessary.
\r
908 if( xHigherPriorityTaskWoken )
\r
915 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
916 * \ingroup QueueManagement
\r
918 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
923 portBASE_TYPE xQueueSendFromISR(
\r
924 xQueueHandle pxQueue,
\r
925 const void *pvItemToQueue,
\r
926 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
930 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
931 * for backward compatibility with versions of FreeRTOS.org that did not
\r
932 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
935 * Post an item to the back of a queue. It is safe to use this function from
\r
936 * within an interrupt service routine.
\r
938 * Items are queued by copy not reference so it is preferable to only
\r
939 * queue small items, especially when called from an ISR. In most cases
\r
940 * it would be preferable to store a pointer to the item being queued.
\r
942 * @param xQueue The handle to the queue on which the item is to be posted.
\r
944 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
945 * queue. The size of the items the queue will hold was defined when the
\r
946 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
947 * into the queue storage area.
\r
949 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
\r
950 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
951 * to unblock, and the unblocked task has a priority higher than the currently
\r
952 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
953 * a context switch should be requested before the interrupt is exited.
\r
955 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
958 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
961 void vBufferISR( void )
\r
964 portBASE_TYPE xHigherPriorityTaskWoken;
\r
966 // We have not woken a task at the start of the ISR.
\r
967 xHigherPriorityTaskWoken = pdFALSE;
\r
969 // Loop until the buffer is empty.
\r
972 // Obtain a byte from the buffer.
\r
973 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
976 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
978 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
980 // Now the buffer is empty we can switch context if necessary.
\r
981 if( xHigherPriorityTaskWoken )
\r
983 // Actual macro used here is port specific.
\r
984 taskYIELD_FROM_ISR ();
\r
989 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
990 * \ingroup QueueManagement
\r
992 #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
997 portBASE_TYPE xQueueGenericSendFromISR(
\r
998 xQueueHandle pxQueue,
\r
999 const void *pvItemToQueue,
\r
1000 portBASE_TYPE *pxHigherPriorityTaskWoken,
\r
1001 portBASE_TYPE xCopyPosition
\r
1005 * It is preferred that the macros xQueueSendFromISR(),
\r
1006 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1007 * of calling this function directly.
\r
1009 * Post an item on a queue. It is safe to use this function from within an
\r
1010 * interrupt service routine.
\r
1012 * Items are queued by copy not reference so it is preferable to only
\r
1013 * queue small items, especially when called from an ISR. In most cases
\r
1014 * it would be preferable to store a pointer to the item being queued.
\r
1016 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1018 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1019 * queue. The size of the items the queue will hold was defined when the
\r
1020 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1021 * into the queue storage area.
\r
1023 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
\r
1024 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1025 * to unblock, and the unblocked task has a priority higher than the currently
\r
1026 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
\r
1027 * a context switch should be requested before the interrupt is exited.
\r
1029 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1030 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1031 * at the front of the queue (for high priority messages).
\r
1033 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1036 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1039 void vBufferISR( void )
\r
1042 portBASE_TYPE xHigherPriorityTaskWokenByPost;
\r
1044 // We have not woken a task at the start of the ISR.
\r
1045 xHigherPriorityTaskWokenByPost = pdFALSE;
\r
1047 // Loop until the buffer is empty.
\r
1050 // Obtain a byte from the buffer.
\r
1051 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1053 // Post each byte.
\r
1054 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
\r
1056 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1058 // Now the buffer is empty we can switch context if necessary. Note that the
\r
1059 // name of the yield function required is port specific.
\r
1060 if( xHigherPriorityTaskWokenByPost )
\r
1062 taskYIELD_YIELD_FROM_ISR();
\r
1067 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1068 * \ingroup QueueManagement
\r
1070 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
\r
1075 portBASE_TYPE xQueueReceiveFromISR(
\r
1076 xQueueHandle pxQueue,
\r
1078 portBASE_TYPE *pxTaskWoken
\r
1082 * Receive an item from a queue. It is safe to use this function from within an
\r
1083 * interrupt service routine.
\r
1085 * @param pxQueue The handle to the queue from which the item is to be
\r
1088 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1091 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1092 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1093 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1094 * remain unchanged.
\r
1096 * @return pdTRUE if an item was successfully received from the queue,
\r
1097 * otherwise pdFALSE.
\r
1102 xQueueHandle xQueue;
\r
1104 // Function to create a queue and post some values.
\r
1105 void vAFunction( void *pvParameters )
\r
1107 portCHAR cValueToPost;
\r
1108 const portTickType xBlockTime = ( portTickType )0xff;
\r
1110 // Create a queue capable of containing 10 characters.
\r
1111 xQueue = xQueueCreate( 10, sizeof( portCHAR ) );
\r
1114 // Failed to create the queue.
\r
1119 // Post some characters that will be used within an ISR. If the queue
\r
1120 // is full then this task will block for xBlockTime ticks.
\r
1121 cValueToPost = 'a';
\r
1122 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1123 cValueToPost = 'b';
\r
1124 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1126 // ... keep posting characters ... this task may block when the queue
\r
1129 cValueToPost = 'c';
\r
1130 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1133 // ISR that outputs all the characters received on the queue.
\r
1134 void vISR_Routine( void )
\r
1136 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1137 portCHAR cRxedChar;
\r
1139 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1141 // A character was received. Output the character now.
\r
1142 vOutputCharacter( cRxedChar );
\r
1144 // If removing the character from the queue woke the task that was
\r
1145 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1146 // pdTRUE. No matter how many times this loop iterates only one
\r
1147 // task will be woken.
\r
1150 if( cTaskWokenByPost != ( portCHAR ) pdFALSE;
\r
1156 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1157 * \ingroup QueueManagement
\r
1159 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1162 * Utilities to query queue that are safe to use from an ISR. These utilities
\r
1163 * should be used only from witin an ISR, or within a critical section.
\r
1165 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
\r
1166 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
\r
1167 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
\r
1171 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1172 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1173 * xQueueGenericReceive().
\r
1175 * The source code that implements the alternative (Alt) API is much
\r
1176 * simpler because it executes everything from within a critical section.
\r
1177 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1178 * preferred fully featured API too. The fully featured API has more
\r
1179 * complex code that takes longer to execute, but makes much less use of
\r
1180 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1181 * responsiveness to gain execution speed, whereas the fully featured API
\r
1182 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1184 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1185 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1186 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
1187 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
1188 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
1189 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
1192 * The functions defined above are for passing data to and from tasks. The
\r
1193 * functions below are the equivalents for passing data to and from
\r
1196 * These functions are called from the co-routine macro implementation and
\r
1197 * should not be called directly from application code. Instead use the macro
\r
1198 * wrappers defined within croutine.h.
\r
1200 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1201 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1202 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1203 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1206 * For internal use only. Use xSemaphoreCreateMutex() or
\r
1207 * xSemaphoreCreateCounting() instead of calling these functions directly.
\r
1209 xQueueHandle xQueueCreateMutex( void );
\r
1210 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1213 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1214 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1216 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
\r
1217 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex );
\r
1220 * The registry is provided as a means for kernel aware debuggers to
\r
1221 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
\r
1222 * a queue, semaphore or mutex handle to the registry if you want the handle
\r
1223 * to be available to a kernel aware debugger. If you are not using a kernel
\r
1224 * aware debugger then this function can be ignored.
\r
1226 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
\r
1227 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
\r
1228 * within FreeRTOSConfig.h for the registry to be available. Its value
\r
1229 * does not effect the number of queues, semaphores and mutexes that can be
\r
1230 * created - just the number that the registry can hold.
\r
1232 * @param xQueue The handle of the queue being added to the registry. This
\r
1233 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
\r
1234 * handles can also be passed in here.
\r
1236 * @param pcName The name to be associated with the handle. This is the
\r
1237 * name that the kernel aware debugger will display.
\r
1239 #if configQUEUE_REGISTRY_SIZE > 0
\r
1240 void vQueueAddToRegistry( xQueueHandle xQueue, signed portCHAR *pcName );
\r
1246 #ifdef __cplusplus
\r
1250 #endif /* QUEUE_H */
\r