2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 This file is part of the FreeRTOS distribution.
9 FreeRTOS is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License (version 2) as published by the
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
13 ***************************************************************************
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
15 >>! distribute a combined work that includes FreeRTOS without being !<<
16 >>! obliged to provide the source code for proprietary components !<<
17 >>! outside of the FreeRTOS kernel. !<<
18 ***************************************************************************
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
23 link: http://www.freertos.org/a00114.html
25 ***************************************************************************
27 * FreeRTOS provides completely free yet professionally developed, *
28 * robust, strictly quality controlled, supported, and cross *
29 * platform software that is more than just the market leader, it *
30 * is the industry's de facto standard. *
32 * Help yourself get started quickly while simultaneously helping *
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
34 * tutorial book, reference manual, or both: *
35 * http://www.FreeRTOS.org/Documentation *
37 ***************************************************************************
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40 the FAQ page "My application does not run, what could be wrong?". Have you
41 defined configASSERT()?
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
44 embedded software for free we request you assist our global community by
45 participating in the support forum.
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
48 be as productive as possible as early as possible. Now you can receive
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50 Ltd, and the world's leading authority on the world's leading RTOS.
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61 licenses offer ticketed support, indemnification and commercial middleware.
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64 engineered and independently SIL3 certified version for use in safety and
65 mission critical applications that require provable dependability.
74 #ifndef INC_FREERTOS_H
75 #error "include FreeRTOS.h" must appear in source files before "include queue.h"
84 * Type by which queues are referenced. For example, a call to xQueueCreate()
85 * returns an QueueHandle_t variable that can then be used as a parameter to
86 * xQueueSend(), xQueueReceive(), etc.
88 typedef void * QueueHandle_t;
91 * Type by which queue sets are referenced. For example, a call to
92 * xQueueCreateSet() returns an xQueueSet variable that can then be used as a
93 * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc.
95 typedef void * QueueSetHandle_t;
98 * Queue sets can contain both queues and semaphores, so the
99 * QueueSetMemberHandle_t is defined as a type to be used where a parameter or
100 * return value can be either an QueueHandle_t or an SemaphoreHandle_t.
102 typedef void * QueueSetMemberHandle_t;
104 /* For internal use only. */
105 #define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
106 #define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
107 #define queueOVERWRITE ( ( BaseType_t ) 2 )
109 /* For internal use only. These definitions *must* match those in queue.c. */
110 #define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U )
111 #define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )
112 #define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U )
113 #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
114 #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
115 #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
120 QueueHandle_t xQueueCreate(
121 UBaseType_t uxQueueLength,
122 UBaseType_t uxItemSize
126 * Creates a new queue instance, and returns a handle by which the new queue
129 * Internally, within the FreeRTOS implementation, queues use two blocks of
130 * memory. The first block is used to hold the queue's data structures. The
131 * second block is used to hold items placed into the queue. If a queue is
132 * created using xQueueCreate() then both blocks of memory are automatically
133 * dynamically allocated inside the xQueueCreate() function. (see
134 * http://www.freertos.org/a00111.html). If a queue is created using
135 * xQueueCreateStatic() then the application writer must provide the memory that
136 * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
137 * be created without using any dynamic memory allocation.
139 * http://www.FreeRTOS.org/Embedded-RTOS-Queues.html
141 * @param uxQueueLength The maximum number of items that the queue can contain.
143 * @param uxItemSize The number of bytes each item in the queue will require.
144 * Items are queued by copy, not by reference, so this is the number of bytes
145 * that will be copied for each posted item. Each item on the queue must be
148 * @return If the queue is successfully create then a handle to the newly
149 * created queue is returned. If the queue cannot be created then 0 is
160 void vATask( void *pvParameters )
162 QueueHandle_t xQueue1, xQueue2;
164 // Create a queue capable of containing 10 uint32_t values.
165 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
168 // Queue was not created and must not be used.
171 // Create a queue capable of containing 10 pointers to AMessage structures.
172 // These should be passed by pointer as they contain a lot of data.
173 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
176 // Queue was not created and must not be used.
179 // ... Rest of task code.
182 * \defgroup xQueueCreate xQueueCreate
183 * \ingroup QueueManagement
185 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
186 #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) )
192 QueueHandle_t xQueueCreateStatic(
193 UBaseType_t uxQueueLength,
194 UBaseType_t uxItemSize,
195 uint8_t *pucQueueStorageBuffer,
196 StaticQueue_t *pxQueueBuffer
200 * Creates a new queue instance, and returns a handle by which the new queue
203 * Internally, within the FreeRTOS implementation, queues use two blocks of
204 * memory. The first block is used to hold the queue's data structures. The
205 * second block is used to hold items placed into the queue. If a queue is
206 * created using xQueueCreate() then both blocks of memory are automatically
207 * dynamically allocated inside the xQueueCreate() function. (see
208 * http://www.freertos.org/a00111.html). If a queue is created using
209 * xQueueCreateStatic() then the application writer must provide the memory that
210 * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
211 * be created without using any dynamic memory allocation.
213 * http://www.FreeRTOS.org/Embedded-RTOS-Queues.html
215 * @param uxQueueLength The maximum number of items that the queue can contain.
217 * @param uxItemSize The number of bytes each item in the queue will require.
218 * Items are queued by copy, not by reference, so this is the number of bytes
219 * that will be copied for each posted item. Each item on the queue must be
222 * @param pucQueueStorageBuffer If uxItemSize is not zero then
223 * pucQueueStorageBuffer must point to a uint8_t array that is at least large
224 * enough to hold the maximum number of items that can be in the queue at any
225 * one time - which is ( uxQueueLength * uxItemsSize ) bytes. If uxItemSize is
226 * zero then pucQueueStorageBuffer can be NULL.
228 * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which
229 * will be used to hold the queue's data structure.
231 * @return If the queue is created then a handle to the created queue is
232 * returned. If pxQueueBuffer is NULL then NULL is returned.
242 #define QUEUE_LENGTH 10
243 #define ITEM_SIZE sizeof( uint32_t )
245 // xQueueBuffer will hold the queue structure.
246 StaticQueue_t xQueueBuffer;
248 // ucQueueStorage will hold the items posted to the queue. Must be at least
249 // [(queue length) * ( queue item size)] bytes long.
250 uint8_t ucQueueStorage[ QUEUE_LENGTH * ITEM_SIZE ];
252 void vATask( void *pvParameters )
254 QueueHandle_t xQueue1;
256 // Create a queue capable of containing 10 uint32_t values.
257 xQueue1 = xQueueCreate( QUEUE_LENGTH, // The number of items the queue can hold.
258 ITEM_SIZE // The size of each item in the queue
259 &( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue.
260 &xQueueBuffer ); // The buffer that will hold the queue structure.
262 // The queue is guaranteed to be created successfully as no dynamic memory
263 // allocation is used. Therefore xQueue1 is now a handle to a valid queue.
265 // ... Rest of task code.
268 * \defgroup xQueueCreateStatic xQueueCreateStatic
269 * \ingroup QueueManagement
271 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
272 #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) )
273 #endif /* configSUPPORT_STATIC_ALLOCATION */
278 BaseType_t xQueueSendToToFront(
279 QueueHandle_t xQueue,
280 const void *pvItemToQueue,
281 TickType_t xTicksToWait
285 * This is a macro that calls xQueueGenericSend().
287 * Post an item to the front of a queue. The item is queued by copy, not by
288 * reference. This function must not be called from an interrupt service
289 * routine. See xQueueSendFromISR () for an alternative which may be used
292 * @param xQueue The handle to the queue on which the item is to be posted.
294 * @param pvItemToQueue A pointer to the item that is to be placed on the
295 * queue. The size of the items the queue will hold was defined when the
296 * queue was created, so this many bytes will be copied from pvItemToQueue
297 * into the queue storage area.
299 * @param xTicksToWait The maximum amount of time the task should block
300 * waiting for space to become available on the queue, should it already
301 * be full. The call will return immediately if this is set to 0 and the
302 * queue is full. The time is defined in tick periods so the constant
303 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
305 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
315 uint32_t ulVar = 10UL;
317 void vATask( void *pvParameters )
319 QueueHandle_t xQueue1, xQueue2;
320 struct AMessage *pxMessage;
322 // Create a queue capable of containing 10 uint32_t values.
323 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
325 // Create a queue capable of containing 10 pointers to AMessage structures.
326 // These should be passed by pointer as they contain a lot of data.
327 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
333 // Send an uint32_t. Wait for 10 ticks for space to become
334 // available if necessary.
335 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
337 // Failed to post the message, even after 10 ticks.
343 // Send a pointer to a struct AMessage object. Don't block if the
344 // queue is already full.
345 pxMessage = & xMessage;
346 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
349 // ... Rest of task code.
352 * \defgroup xQueueSend xQueueSend
353 * \ingroup QueueManagement
355 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
360 BaseType_t xQueueSendToBack(
361 QueueHandle_t xQueue,
362 const void *pvItemToQueue,
363 TickType_t xTicksToWait
367 * This is a macro that calls xQueueGenericSend().
369 * Post an item to the back of a queue. The item is queued by copy, not by
370 * reference. This function must not be called from an interrupt service
371 * routine. See xQueueSendFromISR () for an alternative which may be used
374 * @param xQueue The handle to the queue on which the item is to be posted.
376 * @param pvItemToQueue A pointer to the item that is to be placed on the
377 * queue. The size of the items the queue will hold was defined when the
378 * queue was created, so this many bytes will be copied from pvItemToQueue
379 * into the queue storage area.
381 * @param xTicksToWait The maximum amount of time the task should block
382 * waiting for space to become available on the queue, should it already
383 * be full. The call will return immediately if this is set to 0 and the queue
384 * is full. The time is defined in tick periods so the constant
385 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
387 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
397 uint32_t ulVar = 10UL;
399 void vATask( void *pvParameters )
401 QueueHandle_t xQueue1, xQueue2;
402 struct AMessage *pxMessage;
404 // Create a queue capable of containing 10 uint32_t values.
405 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
407 // Create a queue capable of containing 10 pointers to AMessage structures.
408 // These should be passed by pointer as they contain a lot of data.
409 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
415 // Send an uint32_t. Wait for 10 ticks for space to become
416 // available if necessary.
417 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
419 // Failed to post the message, even after 10 ticks.
425 // Send a pointer to a struct AMessage object. Don't block if the
426 // queue is already full.
427 pxMessage = & xMessage;
428 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
431 // ... Rest of task code.
434 * \defgroup xQueueSend xQueueSend
435 * \ingroup QueueManagement
437 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
442 BaseType_t xQueueSend(
443 QueueHandle_t xQueue,
444 const void * pvItemToQueue,
445 TickType_t xTicksToWait
449 * This is a macro that calls xQueueGenericSend(). It is included for
450 * backward compatibility with versions of FreeRTOS.org that did not
451 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
452 * equivalent to xQueueSendToBack().
454 * Post an item on a queue. The item is queued by copy, not by reference.
455 * This function must not be called from an interrupt service routine.
456 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
458 * @param xQueue The handle to the queue on which the item is to be posted.
460 * @param pvItemToQueue A pointer to the item that is to be placed on the
461 * queue. The size of the items the queue will hold was defined when the
462 * queue was created, so this many bytes will be copied from pvItemToQueue
463 * into the queue storage area.
465 * @param xTicksToWait The maximum amount of time the task should block
466 * waiting for space to become available on the queue, should it already
467 * be full. The call will return immediately if this is set to 0 and the
468 * queue is full. The time is defined in tick periods so the constant
469 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
471 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
481 uint32_t ulVar = 10UL;
483 void vATask( void *pvParameters )
485 QueueHandle_t xQueue1, xQueue2;
486 struct AMessage *pxMessage;
488 // Create a queue capable of containing 10 uint32_t values.
489 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
491 // Create a queue capable of containing 10 pointers to AMessage structures.
492 // These should be passed by pointer as they contain a lot of data.
493 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
499 // Send an uint32_t. Wait for 10 ticks for space to become
500 // available if necessary.
501 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
503 // Failed to post the message, even after 10 ticks.
509 // Send a pointer to a struct AMessage object. Don't block if the
510 // queue is already full.
511 pxMessage = & xMessage;
512 xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
515 // ... Rest of task code.
518 * \defgroup xQueueSend xQueueSend
519 * \ingroup QueueManagement
521 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
526 BaseType_t xQueueOverwrite(
527 QueueHandle_t xQueue,
528 const void * pvItemToQueue
532 * Only for use with queues that have a length of one - so the queue is either
535 * Post an item on a queue. If the queue is already full then overwrite the
536 * value held in the queue. The item is queued by copy, not by reference.
538 * This function must not be called from an interrupt service routine.
539 * See xQueueOverwriteFromISR () for an alternative which may be used in an ISR.
541 * @param xQueue The handle of the queue to which the data is being sent.
543 * @param pvItemToQueue A pointer to the item that is to be placed on the
544 * queue. The size of the items the queue will hold was defined when the
545 * queue was created, so this many bytes will be copied from pvItemToQueue
546 * into the queue storage area.
548 * @return xQueueOverwrite() is a macro that calls xQueueGenericSend(), and
549 * therefore has the same return values as xQueueSendToFront(). However, pdPASS
550 * is the only value that can be returned because xQueueOverwrite() will write
551 * to the queue even when the queue is already full.
556 void vFunction( void *pvParameters )
558 QueueHandle_t xQueue;
559 uint32_t ulVarToSend, ulValReceived;
561 // Create a queue to hold one uint32_t value. It is strongly
562 // recommended *not* to use xQueueOverwrite() on queues that can
563 // contain more than one value, and doing so will trigger an assertion
564 // if configASSERT() is defined.
565 xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
567 // Write the value 10 to the queue using xQueueOverwrite().
569 xQueueOverwrite( xQueue, &ulVarToSend );
571 // Peeking the queue should now return 10, but leave the value 10 in
572 // the queue. A block time of zero is used as it is known that the
573 // queue holds a value.
575 xQueuePeek( xQueue, &ulValReceived, 0 );
577 if( ulValReceived != 10 )
579 // Error unless the item was removed by a different task.
582 // The queue is still full. Use xQueueOverwrite() to overwrite the
583 // value held in the queue with 100.
585 xQueueOverwrite( xQueue, &ulVarToSend );
587 // This time read from the queue, leaving the queue empty once more.
588 // A block time of 0 is used again.
589 xQueueReceive( xQueue, &ulValReceived, 0 );
591 // The value read should be the last value written, even though the
592 // queue was already full when the value was written.
593 if( ulValReceived != 100 )
601 * \defgroup xQueueOverwrite xQueueOverwrite
602 * \ingroup QueueManagement
604 #define xQueueOverwrite( xQueue, pvItemToQueue ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )
610 BaseType_t xQueueGenericSend(
611 QueueHandle_t xQueue,
612 const void * pvItemToQueue,
613 TickType_t xTicksToWait
614 BaseType_t xCopyPosition
618 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
619 * xQueueSendToBack() are used in place of calling this function directly.
621 * Post an item on a queue. The item is queued by copy, not by reference.
622 * This function must not be called from an interrupt service routine.
623 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
625 * @param xQueue The handle to the queue on which the item is to be posted.
627 * @param pvItemToQueue A pointer to the item that is to be placed on the
628 * queue. The size of the items the queue will hold was defined when the
629 * queue was created, so this many bytes will be copied from pvItemToQueue
630 * into the queue storage area.
632 * @param xTicksToWait The maximum amount of time the task should block
633 * waiting for space to become available on the queue, should it already
634 * be full. The call will return immediately if this is set to 0 and the
635 * queue is full. The time is defined in tick periods so the constant
636 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
638 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
639 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
640 * at the front of the queue (for high priority messages).
642 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
652 uint32_t ulVar = 10UL;
654 void vATask( void *pvParameters )
656 QueueHandle_t xQueue1, xQueue2;
657 struct AMessage *pxMessage;
659 // Create a queue capable of containing 10 uint32_t values.
660 xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
662 // Create a queue capable of containing 10 pointers to AMessage structures.
663 // These should be passed by pointer as they contain a lot of data.
664 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
670 // Send an uint32_t. Wait for 10 ticks for space to become
671 // available if necessary.
672 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS )
674 // Failed to post the message, even after 10 ticks.
680 // Send a pointer to a struct AMessage object. Don't block if the
681 // queue is already full.
682 pxMessage = & xMessage;
683 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK );
686 // ... Rest of task code.
689 * \defgroup xQueueSend xQueueSend
690 * \ingroup QueueManagement
692 BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
697 BaseType_t xQueuePeek(
698 QueueHandle_t xQueue,
700 TickType_t xTicksToWait
703 * This is a macro that calls the xQueueGenericReceive() function.
705 * Receive an item from a queue without removing the item from the queue.
706 * The item is received by copy so a buffer of adequate size must be
707 * provided. The number of bytes copied into the buffer was defined when
708 * the queue was created.
710 * Successfully received items remain on the queue so will be returned again
711 * by the next call, or a call to xQueueReceive().
713 * This macro must not be used in an interrupt service routine. See
714 * xQueuePeekFromISR() for an alternative that can be called from an interrupt
717 * @param xQueue The handle to the queue from which the item is to be
720 * @param pvBuffer Pointer to the buffer into which the received item will
723 * @param xTicksToWait The maximum amount of time the task should block
724 * waiting for an item to receive should the queue be empty at the time
725 * of the call. The time is defined in tick periods so the constant
726 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
727 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
730 * @return pdTRUE if an item was successfully received from the queue,
741 QueueHandle_t xQueue;
743 // Task to create a queue and post a value.
744 void vATask( void *pvParameters )
746 struct AMessage *pxMessage;
748 // Create a queue capable of containing 10 pointers to AMessage structures.
749 // These should be passed by pointer as they contain a lot of data.
750 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
753 // Failed to create the queue.
758 // Send a pointer to a struct AMessage object. Don't block if the
759 // queue is already full.
760 pxMessage = & xMessage;
761 xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
763 // ... Rest of task code.
766 // Task to peek the data from the queue.
767 void vADifferentTask( void *pvParameters )
769 struct AMessage *pxRxedMessage;
773 // Peek a message on the created queue. Block for 10 ticks if a
774 // message is not immediately available.
775 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
777 // pcRxedMessage now points to the struct AMessage variable posted
778 // by vATask, but the item still remains on the queue.
782 // ... Rest of task code.
785 * \defgroup xQueueReceive xQueueReceive
786 * \ingroup QueueManagement
788 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
793 BaseType_t xQueuePeekFromISR(
794 QueueHandle_t xQueue,
798 * A version of xQueuePeek() that can be called from an interrupt service
801 * Receive an item from a queue without removing the item from the queue.
802 * The item is received by copy so a buffer of adequate size must be
803 * provided. The number of bytes copied into the buffer was defined when
804 * the queue was created.
806 * Successfully received items remain on the queue so will be returned again
807 * by the next call, or a call to xQueueReceive().
809 * @param xQueue The handle to the queue from which the item is to be
812 * @param pvBuffer Pointer to the buffer into which the received item will
815 * @return pdTRUE if an item was successfully received from the queue,
818 * \defgroup xQueuePeekFromISR xQueuePeekFromISR
819 * \ingroup QueueManagement
821 BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void * const pvBuffer ) PRIVILEGED_FUNCTION;
826 BaseType_t xQueueReceive(
827 QueueHandle_t xQueue,
829 TickType_t xTicksToWait
832 * This is a macro that calls the xQueueGenericReceive() function.
834 * Receive an item from a queue. The item is received by copy so a buffer of
835 * adequate size must be provided. The number of bytes copied into the buffer
836 * was defined when the queue was created.
838 * Successfully received items are removed from the queue.
840 * This function must not be used in an interrupt service routine. See
841 * xQueueReceiveFromISR for an alternative that can.
843 * @param xQueue The handle to the queue from which the item is to be
846 * @param pvBuffer Pointer to the buffer into which the received item will
849 * @param xTicksToWait The maximum amount of time the task should block
850 * waiting for an item to receive should the queue be empty at the time
851 * of the call. xQueueReceive() will return immediately if xTicksToWait
852 * is zero and the queue is empty. The time is defined in tick periods so the
853 * constant portTICK_PERIOD_MS should be used to convert to real time if this is
856 * @return pdTRUE if an item was successfully received from the queue,
867 QueueHandle_t xQueue;
869 // Task to create a queue and post a value.
870 void vATask( void *pvParameters )
872 struct AMessage *pxMessage;
874 // Create a queue capable of containing 10 pointers to AMessage structures.
875 // These should be passed by pointer as they contain a lot of data.
876 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
879 // Failed to create the queue.
884 // Send a pointer to a struct AMessage object. Don't block if the
885 // queue is already full.
886 pxMessage = & xMessage;
887 xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
889 // ... Rest of task code.
892 // Task to receive from the queue.
893 void vADifferentTask( void *pvParameters )
895 struct AMessage *pxRxedMessage;
899 // Receive a message on the created queue. Block for 10 ticks if a
900 // message is not immediately available.
901 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
903 // pcRxedMessage now points to the struct AMessage variable posted
908 // ... Rest of task code.
911 * \defgroup xQueueReceive xQueueReceive
912 * \ingroup QueueManagement
914 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
920 BaseType_t xQueueGenericReceive(
921 QueueHandle_t xQueue,
923 TickType_t xTicksToWait
927 * It is preferred that the macro xQueueReceive() be used rather than calling
928 * this function directly.
930 * Receive an item from a queue. The item is received by copy so a buffer of
931 * adequate size must be provided. The number of bytes copied into the buffer
932 * was defined when the queue was created.
934 * This function must not be used in an interrupt service routine. See
935 * xQueueReceiveFromISR for an alternative that can.
937 * @param xQueue The handle to the queue from which the item is to be
940 * @param pvBuffer Pointer to the buffer into which the received item will
943 * @param xTicksToWait The maximum amount of time the task should block
944 * waiting for an item to receive should the queue be empty at the time
945 * of the call. The time is defined in tick periods so the constant
946 * portTICK_PERIOD_MS should be used to convert to real time if this is required.
947 * xQueueGenericReceive() will return immediately if the queue is empty and
950 * @param xJustPeek When set to true, the item received from the queue is not
951 * actually removed from the queue - meaning a subsequent call to
952 * xQueueReceive() will return the same item. When set to false, the item
953 * being received from the queue is also removed from the queue.
955 * @return pdTRUE if an item was successfully received from the queue,
966 QueueHandle_t xQueue;
968 // Task to create a queue and post a value.
969 void vATask( void *pvParameters )
971 struct AMessage *pxMessage;
973 // Create a queue capable of containing 10 pointers to AMessage structures.
974 // These should be passed by pointer as they contain a lot of data.
975 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
978 // Failed to create the queue.
983 // Send a pointer to a struct AMessage object. Don't block if the
984 // queue is already full.
985 pxMessage = & xMessage;
986 xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
988 // ... Rest of task code.
991 // Task to receive from the queue.
992 void vADifferentTask( void *pvParameters )
994 struct AMessage *pxRxedMessage;
998 // Receive a message on the created queue. Block for 10 ticks if a
999 // message is not immediately available.
1000 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
1002 // pcRxedMessage now points to the struct AMessage variable posted
1007 // ... Rest of task code.
1010 * \defgroup xQueueReceive xQueueReceive
1011 * \ingroup QueueManagement
1013 BaseType_t xQueueGenericReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait, const BaseType_t xJustPeek ) PRIVILEGED_FUNCTION;
1017 * <pre>UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );</pre>
1019 * Return the number of messages stored in a queue.
1021 * @param xQueue A handle to the queue being queried.
1023 * @return The number of messages available in the queue.
1025 * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
1026 * \ingroup QueueManagement
1028 UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1032 * <pre>UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue );</pre>
1034 * Return the number of free spaces available in a queue. This is equal to the
1035 * number of items that can be sent to the queue before the queue becomes full
1036 * if no items are removed.
1038 * @param xQueue A handle to the queue being queried.
1040 * @return The number of spaces available in the queue.
1042 * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
1043 * \ingroup QueueManagement
1045 UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1049 * <pre>void vQueueDelete( QueueHandle_t xQueue );</pre>
1051 * Delete a queue - freeing all the memory allocated for storing of items
1052 * placed on the queue.
1054 * @param xQueue A handle to the queue to be deleted.
1056 * \defgroup vQueueDelete vQueueDelete
1057 * \ingroup QueueManagement
1059 void vQueueDelete( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1064 BaseType_t xQueueSendToFrontFromISR(
1065 QueueHandle_t xQueue,
1066 const void *pvItemToQueue,
1067 BaseType_t *pxHigherPriorityTaskWoken
1071 * This is a macro that calls xQueueGenericSendFromISR().
1073 * Post an item to the front of a queue. It is safe to use this macro from
1074 * within an interrupt service routine.
1076 * Items are queued by copy not reference so it is preferable to only
1077 * queue small items, especially when called from an ISR. In most cases
1078 * it would be preferable to store a pointer to the item being queued.
1080 * @param xQueue The handle to the queue on which the item is to be posted.
1082 * @param pvItemToQueue A pointer to the item that is to be placed on the
1083 * queue. The size of the items the queue will hold was defined when the
1084 * queue was created, so this many bytes will be copied from pvItemToQueue
1085 * into the queue storage area.
1087 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
1088 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1089 * to unblock, and the unblocked task has a priority higher than the currently
1090 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
1091 * a context switch should be requested before the interrupt is exited.
1093 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1096 * Example usage for buffered IO (where the ISR can obtain more than one value
1099 void vBufferISR( void )
1102 BaseType_t xHigherPrioritTaskWoken;
1104 // We have not woken a task at the start of the ISR.
1105 xHigherPriorityTaskWoken = pdFALSE;
1107 // Loop until the buffer is empty.
1110 // Obtain a byte from the buffer.
1111 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1114 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1116 } while( portINPUT_BYTE( BUFFER_COUNT ) );
1118 // Now the buffer is empty we can switch context if necessary.
1119 if( xHigherPriorityTaskWoken )
1126 * \defgroup xQueueSendFromISR xQueueSendFromISR
1127 * \ingroup QueueManagement
1129 #define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
1135 BaseType_t xQueueSendToBackFromISR(
1136 QueueHandle_t xQueue,
1137 const void *pvItemToQueue,
1138 BaseType_t *pxHigherPriorityTaskWoken
1142 * This is a macro that calls xQueueGenericSendFromISR().
1144 * Post an item to the back of a queue. It is safe to use this macro from
1145 * within an interrupt service routine.
1147 * Items are queued by copy not reference so it is preferable to only
1148 * queue small items, especially when called from an ISR. In most cases
1149 * it would be preferable to store a pointer to the item being queued.
1151 * @param xQueue The handle to the queue on which the item is to be posted.
1153 * @param pvItemToQueue A pointer to the item that is to be placed on the
1154 * queue. The size of the items the queue will hold was defined when the
1155 * queue was created, so this many bytes will be copied from pvItemToQueue
1156 * into the queue storage area.
1158 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
1159 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1160 * to unblock, and the unblocked task has a priority higher than the currently
1161 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
1162 * a context switch should be requested before the interrupt is exited.
1164 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1167 * Example usage for buffered IO (where the ISR can obtain more than one value
1170 void vBufferISR( void )
1173 BaseType_t xHigherPriorityTaskWoken;
1175 // We have not woken a task at the start of the ISR.
1176 xHigherPriorityTaskWoken = pdFALSE;
1178 // Loop until the buffer is empty.
1181 // Obtain a byte from the buffer.
1182 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1185 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1187 } while( portINPUT_BYTE( BUFFER_COUNT ) );
1189 // Now the buffer is empty we can switch context if necessary.
1190 if( xHigherPriorityTaskWoken )
1197 * \defgroup xQueueSendFromISR xQueueSendFromISR
1198 * \ingroup QueueManagement
1200 #define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1205 BaseType_t xQueueOverwriteFromISR(
1206 QueueHandle_t xQueue,
1207 const void * pvItemToQueue,
1208 BaseType_t *pxHigherPriorityTaskWoken
1212 * A version of xQueueOverwrite() that can be used in an interrupt service
1215 * Only for use with queues that can hold a single item - so the queue is either
1218 * Post an item on a queue. If the queue is already full then overwrite the
1219 * value held in the queue. The item is queued by copy, not by reference.
1221 * @param xQueue The handle to the queue on which the item is to be posted.
1223 * @param pvItemToQueue A pointer to the item that is to be placed on the
1224 * queue. The size of the items the queue will hold was defined when the
1225 * queue was created, so this many bytes will be copied from pvItemToQueue
1226 * into the queue storage area.
1228 * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set
1229 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1230 * to unblock, and the unblocked task has a priority higher than the currently
1231 * running task. If xQueueOverwriteFromISR() sets this value to pdTRUE then
1232 * a context switch should be requested before the interrupt is exited.
1234 * @return xQueueOverwriteFromISR() is a macro that calls
1235 * xQueueGenericSendFromISR(), and therefore has the same return values as
1236 * xQueueSendToFrontFromISR(). However, pdPASS is the only value that can be
1237 * returned because xQueueOverwriteFromISR() will write to the queue even when
1238 * the queue is already full.
1243 QueueHandle_t xQueue;
1245 void vFunction( void *pvParameters )
1247 // Create a queue to hold one uint32_t value. It is strongly
1248 // recommended *not* to use xQueueOverwriteFromISR() on queues that can
1249 // contain more than one value, and doing so will trigger an assertion
1250 // if configASSERT() is defined.
1251 xQueue = xQueueCreate( 1, sizeof( uint32_t ) );
1254 void vAnInterruptHandler( void )
1256 // xHigherPriorityTaskWoken must be set to pdFALSE before it is used.
1257 BaseType_t xHigherPriorityTaskWoken = pdFALSE;
1258 uint32_t ulVarToSend, ulValReceived;
1260 // Write the value 10 to the queue using xQueueOverwriteFromISR().
1262 xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
1264 // The queue is full, but calling xQueueOverwriteFromISR() again will still
1265 // pass because the value held in the queue will be overwritten with the
1268 xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
1270 // Reading from the queue will now return 100.
1274 if( xHigherPrioritytaskWoken == pdTRUE )
1276 // Writing to the queue caused a task to unblock and the unblocked task
1277 // has a priority higher than or equal to the priority of the currently
1278 // executing task (the task this interrupt interrupted). Perform a context
1279 // switch so this interrupt returns directly to the unblocked task.
1280 portYIELD_FROM_ISR(); // or portEND_SWITCHING_ISR() depending on the port.
1284 * \defgroup xQueueOverwriteFromISR xQueueOverwriteFromISR
1285 * \ingroup QueueManagement
1287 #define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE )
1292 BaseType_t xQueueSendFromISR(
1293 QueueHandle_t xQueue,
1294 const void *pvItemToQueue,
1295 BaseType_t *pxHigherPriorityTaskWoken
1299 * This is a macro that calls xQueueGenericSendFromISR(). It is included
1300 * for backward compatibility with versions of FreeRTOS.org that did not
1301 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
1304 * Post an item to the back of a queue. It is safe to use this function from
1305 * within an interrupt service routine.
1307 * Items are queued by copy not reference so it is preferable to only
1308 * queue small items, especially when called from an ISR. In most cases
1309 * it would be preferable to store a pointer to the item being queued.
1311 * @param xQueue The handle to the queue on which the item is to be posted.
1313 * @param pvItemToQueue A pointer to the item that is to be placed on the
1314 * queue. The size of the items the queue will hold was defined when the
1315 * queue was created, so this many bytes will be copied from pvItemToQueue
1316 * into the queue storage area.
1318 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
1319 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1320 * to unblock, and the unblocked task has a priority higher than the currently
1321 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
1322 * a context switch should be requested before the interrupt is exited.
1324 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1327 * Example usage for buffered IO (where the ISR can obtain more than one value
1330 void vBufferISR( void )
1333 BaseType_t xHigherPriorityTaskWoken;
1335 // We have not woken a task at the start of the ISR.
1336 xHigherPriorityTaskWoken = pdFALSE;
1338 // Loop until the buffer is empty.
1341 // Obtain a byte from the buffer.
1342 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1345 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
1347 } while( portINPUT_BYTE( BUFFER_COUNT ) );
1349 // Now the buffer is empty we can switch context if necessary.
1350 if( xHigherPriorityTaskWoken )
1352 // Actual macro used here is port specific.
1353 portYIELD_FROM_ISR ();
1358 * \defgroup xQueueSendFromISR xQueueSendFromISR
1359 * \ingroup QueueManagement
1361 #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
1366 BaseType_t xQueueGenericSendFromISR(
1367 QueueHandle_t xQueue,
1368 const void *pvItemToQueue,
1369 BaseType_t *pxHigherPriorityTaskWoken,
1370 BaseType_t xCopyPosition
1374 * It is preferred that the macros xQueueSendFromISR(),
1375 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
1376 * of calling this function directly. xQueueGiveFromISR() is an
1377 * equivalent for use by semaphores that don't actually copy any data.
1379 * Post an item on a queue. It is safe to use this function from within an
1380 * interrupt service routine.
1382 * Items are queued by copy not reference so it is preferable to only
1383 * queue small items, especially when called from an ISR. In most cases
1384 * it would be preferable to store a pointer to the item being queued.
1386 * @param xQueue The handle to the queue on which the item is to be posted.
1388 * @param pvItemToQueue A pointer to the item that is to be placed on the
1389 * queue. The size of the items the queue will hold was defined when the
1390 * queue was created, so this many bytes will be copied from pvItemToQueue
1391 * into the queue storage area.
1393 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
1394 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1395 * to unblock, and the unblocked task has a priority higher than the currently
1396 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
1397 * a context switch should be requested before the interrupt is exited.
1399 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
1400 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
1401 * at the front of the queue (for high priority messages).
1403 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1406 * Example usage for buffered IO (where the ISR can obtain more than one value
1409 void vBufferISR( void )
1412 BaseType_t xHigherPriorityTaskWokenByPost;
1414 // We have not woken a task at the start of the ISR.
1415 xHigherPriorityTaskWokenByPost = pdFALSE;
1417 // Loop until the buffer is empty.
1420 // Obtain a byte from the buffer.
1421 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1424 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
1426 } while( portINPUT_BYTE( BUFFER_COUNT ) );
1428 // Now the buffer is empty we can switch context if necessary. Note that the
1429 // name of the yield function required is port specific.
1430 if( xHigherPriorityTaskWokenByPost )
1432 taskYIELD_YIELD_FROM_ISR();
1437 * \defgroup xQueueSendFromISR xQueueSendFromISR
1438 * \ingroup QueueManagement
1440 BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const void * const pvItemToQueue, BaseType_t * const pxHigherPriorityTaskWoken, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;
1441 BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1446 BaseType_t xQueueReceiveFromISR(
1447 QueueHandle_t xQueue,
1449 BaseType_t *pxTaskWoken
1453 * Receive an item from a queue. It is safe to use this function from within an
1454 * interrupt service routine.
1456 * @param xQueue The handle to the queue from which the item is to be
1459 * @param pvBuffer Pointer to the buffer into which the received item will
1462 * @param pxTaskWoken A task may be blocked waiting for space to become
1463 * available on the queue. If xQueueReceiveFromISR causes such a task to
1464 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
1467 * @return pdTRUE if an item was successfully received from the queue,
1468 * otherwise pdFALSE.
1473 QueueHandle_t xQueue;
1475 // Function to create a queue and post some values.
1476 void vAFunction( void *pvParameters )
1479 const TickType_t xTicksToWait = ( TickType_t )0xff;
1481 // Create a queue capable of containing 10 characters.
1482 xQueue = xQueueCreate( 10, sizeof( char ) );
1485 // Failed to create the queue.
1490 // Post some characters that will be used within an ISR. If the queue
1491 // is full then this task will block for xTicksToWait ticks.
1493 xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1495 xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1497 // ... keep posting characters ... this task may block when the queue
1501 xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
1504 // ISR that outputs all the characters received on the queue.
1505 void vISR_Routine( void )
1507 BaseType_t xTaskWokenByReceive = pdFALSE;
1510 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
1512 // A character was received. Output the character now.
1513 vOutputCharacter( cRxedChar );
1515 // If removing the character from the queue woke the task that was
1516 // posting onto the queue cTaskWokenByReceive will have been set to
1517 // pdTRUE. No matter how many times this loop iterates only one
1518 // task will be woken.
1521 if( cTaskWokenByPost != ( char ) pdFALSE;
1527 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
1528 * \ingroup QueueManagement
1530 BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue, void * const pvBuffer, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
1533 * Utilities to query queues that are safe to use from an ISR. These utilities
1534 * should be used only from witin an ISR, or within a critical section.
1536 BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1537 BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1538 UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1541 * The functions defined above are for passing data to and from tasks. The
1542 * functions below are the equivalents for passing data to and from
1545 * These functions are called from the co-routine macro implementation and
1546 * should not be called directly from application code. Instead use the macro
1547 * wrappers defined within croutine.h.
1549 BaseType_t xQueueCRSendFromISR( QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t xCoRoutinePreviouslyWoken );
1550 BaseType_t xQueueCRReceiveFromISR( QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxTaskWoken );
1551 BaseType_t xQueueCRSend( QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait );
1552 BaseType_t xQueueCRReceive( QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait );
1555 * For internal use only. Use xSemaphoreCreateMutex(),
1556 * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
1557 * these functions directly.
1559 QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1560 QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION;
1561 QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;
1562 QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION;
1563 void* xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
1566 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
1567 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
1569 BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1570 BaseType_t xQueueGiveMutexRecursive( QueueHandle_t pxMutex ) PRIVILEGED_FUNCTION;
1573 * Reset a queue back to its original empty state. The return value is now
1574 * obsolete and is always set to pdPASS.
1576 #define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE )
1579 * The registry is provided as a means for kernel aware debuggers to
1580 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1581 * a queue, semaphore or mutex handle to the registry if you want the handle
1582 * to be available to a kernel aware debugger. If you are not using a kernel
1583 * aware debugger then this function can be ignored.
1585 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
1586 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
1587 * within FreeRTOSConfig.h for the registry to be available. Its value
1588 * does not effect the number of queues, semaphores and mutexes that can be
1589 * created - just the number that the registry can hold.
1591 * @param xQueue The handle of the queue being added to the registry. This
1592 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
1593 * handles can also be passed in here.
1595 * @param pcName The name to be associated with the handle. This is the
1596 * name that the kernel aware debugger will display. The queue registry only
1597 * stores a pointer to the string - so the string must be persistent (global or
1598 * preferably in ROM/Flash), not on the stack.
1600 #if( configQUEUE_REGISTRY_SIZE > 0 )
1601 void vQueueAddToRegistry( QueueHandle_t xQueue, const char *pcName ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1605 * The registry is provided as a means for kernel aware debuggers to
1606 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1607 * a queue, semaphore or mutex handle to the registry if you want the handle
1608 * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to
1609 * remove the queue, semaphore or mutex from the register. If you are not using
1610 * a kernel aware debugger then this function can be ignored.
1612 * @param xQueue The handle of the queue being removed from the registry.
1614 #if( configQUEUE_REGISTRY_SIZE > 0 )
1615 void vQueueUnregisterQueue( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1619 * The queue registry is provided as a means for kernel aware debuggers to
1620 * locate queues, semaphores and mutexes. Call pcQueueGetName() to look
1621 * up and return the name of a queue in the queue registry from the queue's
1624 * @param xQueue The handle of the queue the name of which will be returned.
1625 * @return If the queue is in the registry then a pointer to the name of the
1626 * queue is returned. If the queue is not in the registry then NULL is
1629 #if( configQUEUE_REGISTRY_SIZE > 0 )
1630 const char *pcQueueGetName( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1634 * Generic version of the function used to creaet a queue using dynamic memory
1635 * allocation. This is called by other functions and macros that create other
1636 * RTOS objects that use the queue structure as their base.
1638 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
1639 QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1643 * Generic version of the function used to creaet a queue using dynamic memory
1644 * allocation. This is called by other functions and macros that create other
1645 * RTOS objects that use the queue structure as their base.
1647 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
1648 QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
1652 * Queue sets provide a mechanism to allow a task to block (pend) on a read
1653 * operation from multiple queues or semaphores simultaneously.
1655 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1658 * A queue set must be explicitly created using a call to xQueueCreateSet()
1659 * before it can be used. Once created, standard FreeRTOS queues and semaphores
1660 * can be added to the set using calls to xQueueAddToSet().
1661 * xQueueSelectFromSet() is then used to determine which, if any, of the queues
1662 * or semaphores contained in the set is in a state where a queue read or
1663 * semaphore take operation would be successful.
1665 * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1666 * for reasons why queue sets are very rarely needed in practice as there are
1667 * simpler methods of blocking on multiple objects.
1669 * Note 2: Blocking on a queue set that contains a mutex will not cause the
1670 * mutex holder to inherit the priority of the blocked task.
1672 * Note 3: An additional 4 bytes of RAM is required for each space in a every
1673 * queue added to a queue set. Therefore counting semaphores that have a high
1674 * maximum count value should not be added to a queue set.
1676 * Note 4: A receive (in the case of a queue) or take (in the case of a
1677 * semaphore) operation must not be performed on a member of a queue set unless
1678 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1680 * @param uxEventQueueLength Queue sets store events that occur on
1681 * the queues and semaphores contained in the set. uxEventQueueLength specifies
1682 * the maximum number of events that can be queued at once. To be absolutely
1683 * certain that events are not lost uxEventQueueLength should be set to the
1684 * total sum of the length of the queues added to the set, where binary
1685 * semaphores and mutexes have a length of 1, and counting semaphores have a
1686 * length set by their maximum count value. Examples:
1687 * + If a queue set is to hold a queue of length 5, another queue of length 12,
1688 * and a binary semaphore, then uxEventQueueLength should be set to
1689 * (5 + 12 + 1), or 18.
1690 * + If a queue set is to hold three binary semaphores then uxEventQueueLength
1691 * should be set to (1 + 1 + 1 ), or 3.
1692 * + If a queue set is to hold a counting semaphore that has a maximum count of
1693 * 5, and a counting semaphore that has a maximum count of 3, then
1694 * uxEventQueueLength should be set to (5 + 3), or 8.
1696 * @return If the queue set is created successfully then a handle to the created
1697 * queue set is returned. Otherwise NULL is returned.
1699 QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength ) PRIVILEGED_FUNCTION;
1702 * Adds a queue or semaphore to a queue set that was previously created by a
1703 * call to xQueueCreateSet().
1705 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1708 * Note 1: A receive (in the case of a queue) or take (in the case of a
1709 * semaphore) operation must not be performed on a member of a queue set unless
1710 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1712 * @param xQueueOrSemaphore The handle of the queue or semaphore being added to
1713 * the queue set (cast to an QueueSetMemberHandle_t type).
1715 * @param xQueueSet The handle of the queue set to which the queue or semaphore
1718 * @return If the queue or semaphore was successfully added to the queue set
1719 * then pdPASS is returned. If the queue could not be successfully added to the
1720 * queue set because it is already a member of a different queue set then pdFAIL
1723 BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1726 * Removes a queue or semaphore from a queue set. A queue or semaphore can only
1727 * be removed from a set if the queue or semaphore is empty.
1729 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1732 * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
1733 * from the queue set (cast to an QueueSetMemberHandle_t type).
1735 * @param xQueueSet The handle of the queue set in which the queue or semaphore
1738 * @return If the queue or semaphore was successfully removed from the queue set
1739 * then pdPASS is returned. If the queue was not in the queue set, or the
1740 * queue (or semaphore) was not empty, then pdFAIL is returned.
1742 BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1745 * xQueueSelectFromSet() selects from the members of a queue set a queue or
1746 * semaphore that either contains data (in the case of a queue) or is available
1747 * to take (in the case of a semaphore). xQueueSelectFromSet() effectively
1748 * allows a task to block (pend) on a read operation on all the queues and
1749 * semaphores in a queue set simultaneously.
1751 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
1754 * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
1755 * for reasons why queue sets are very rarely needed in practice as there are
1756 * simpler methods of blocking on multiple objects.
1758 * Note 2: Blocking on a queue set that contains a mutex will not cause the
1759 * mutex holder to inherit the priority of the blocked task.
1761 * Note 3: A receive (in the case of a queue) or take (in the case of a
1762 * semaphore) operation must not be performed on a member of a queue set unless
1763 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
1765 * @param xQueueSet The queue set on which the task will (potentially) block.
1767 * @param xTicksToWait The maximum time, in ticks, that the calling task will
1768 * remain in the Blocked state (with other tasks executing) to wait for a member
1769 * of the queue set to be ready for a successful queue read or semaphore take
1772 * @return xQueueSelectFromSet() will return the handle of a queue (cast to
1773 * a QueueSetMemberHandle_t type) contained in the queue set that contains data,
1774 * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained
1775 * in the queue set that is available, or NULL if no such queue or semaphore
1776 * exists before before the specified block time expires.
1778 QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
1781 * A version of xQueueSelectFromSet() that can be used from an ISR.
1783 QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) PRIVILEGED_FUNCTION;
1785 /* Not public API functions. */
1786 void vQueueWaitForMessageRestricted( QueueHandle_t xQueue, TickType_t xTicksToWait, const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
1787 BaseType_t xQueueGenericReset( QueueHandle_t xQueue, BaseType_t xNewQueue ) PRIVILEGED_FUNCTION;
1788 void vQueueSetQueueNumber( QueueHandle_t xQueue, UBaseType_t uxQueueNumber ) PRIVILEGED_FUNCTION;
1789 UBaseType_t uxQueueGetQueueNumber( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1790 uint8_t ucQueueGetQueueType( QueueHandle_t xQueue ) PRIVILEGED_FUNCTION;
1797 #endif /* QUEUE_H */