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