2 FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not it can be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
79 #ifndef INC_FREERTOS_H
\r
80 #error "include FreeRTOS.h" must appear in source files before "include queue.h"
\r
88 #include "mpu_wrappers.h"
\r
91 * Type by which queues are referenced. For example, a call to xQueueCreate()
\r
92 * returns an xQueueHandle variable that can then be used as a parameter to
\r
93 * xQueueSend(), xQueueReceive(), etc.
\r
95 typedef void * xQueueHandle;
\r
98 * Type by which queue sets are referenced. For example, a call to
\r
99 * xQueueCreateSet() returns an xQueueSet variable that can then be used as a
\r
100 * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc.
\r
102 typedef void * xQueueSetHandle;
\r
105 * Queue sets can contain both queues and semaphores, so the
\r
106 * xQueueSetMemberHandle is defined as a type to be used where a parameter or
\r
107 * return value can be either an xQueueHandle or an xSemaphoreHandle.
\r
109 typedef void * xQueueSetMemberHandle;
\r
111 /* For internal use only. */
\r
112 #define queueSEND_TO_BACK ( 0 )
\r
113 #define queueSEND_TO_FRONT ( 1 )
\r
114 #define queueOVERWRITE ( 2 )
\r
116 /* For internal use only. These definitions *must* match those in queue.c. */
\r
117 #define queueQUEUE_TYPE_BASE ( 0U )
\r
118 #define queueQUEUE_TYPE_SET ( 0U )
\r
119 #define queueQUEUE_TYPE_MUTEX ( 1U )
\r
120 #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( 2U )
\r
121 #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( 3U )
\r
122 #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( 4U )
\r
127 xQueueHandle xQueueCreate(
\r
128 unsigned portBASE_TYPE uxQueueLength,
\r
129 unsigned portBASE_TYPE uxItemSize
\r
133 * Creates a new queue instance. This allocates the storage required by the
\r
134 * new queue and returns a handle for the queue.
\r
136 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
138 * @param uxItemSize The number of bytes each item in the queue will require.
\r
139 * Items are queued by copy, not by reference, so this is the number of bytes
\r
140 * that will be copied for each posted item. Each item on the queue must be
\r
143 * @return If the queue is successfully create then a handle to the newly
\r
144 * created queue is returned. If the queue cannot be created then 0 is
\r
155 void vATask( void *pvParameters )
\r
157 xQueueHandle xQueue1, xQueue2;
\r
159 // Create a queue capable of containing 10 unsigned long values.
\r
160 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
163 // Queue was not created and must not be used.
\r
166 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
167 // These should be passed by pointer as they contain a lot of data.
\r
168 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
171 // Queue was not created and must not be used.
\r
174 // ... Rest of task code.
\r
177 * \defgroup xQueueCreate xQueueCreate
\r
178 * \ingroup QueueManagement
\r
180 #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( uxQueueLength, uxItemSize, queueQUEUE_TYPE_BASE )
\r
185 portBASE_TYPE xQueueSendToToFront(
\r
186 xQueueHandle xQueue,
\r
187 const void * pvItemToQueue,
\r
188 portTickType xTicksToWait
\r
192 * This is a macro that calls xQueueGenericSend().
\r
194 * Post an item to the front of a queue. The item is queued by copy, not by
\r
195 * reference. This function must not be called from an interrupt service
\r
196 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
199 * @param xQueue The handle to the queue on which the item is to be posted.
\r
201 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
202 * queue. The size of the items the queue will hold was defined when the
\r
203 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
204 * into the queue storage area.
\r
206 * @param xTicksToWait The maximum amount of time the task should block
\r
207 * waiting for space to become available on the queue, should it already
\r
208 * be full. The call will return immediately if this is set to 0 and the
\r
209 * queue is full. The time is defined in tick periods so the constant
\r
210 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
212 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
222 unsigned long ulVar = 10UL;
\r
224 void vATask( void *pvParameters )
\r
226 xQueueHandle xQueue1, xQueue2;
\r
227 struct AMessage *pxMessage;
\r
229 // Create a queue capable of containing 10 unsigned long values.
\r
230 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
232 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
233 // These should be passed by pointer as they contain a lot of data.
\r
234 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
240 // Send an unsigned long. Wait for 10 ticks for space to become
\r
241 // available if necessary.
\r
242 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
244 // Failed to post the message, even after 10 ticks.
\r
250 // Send a pointer to a struct AMessage object. Don't block if the
\r
251 // queue is already full.
\r
252 pxMessage = & xMessage;
\r
253 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
256 // ... Rest of task code.
\r
259 * \defgroup xQueueSend xQueueSend
\r
260 * \ingroup QueueManagement
\r
262 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
\r
267 portBASE_TYPE xQueueSendToBack(
\r
268 xQueueHandle xQueue,
\r
269 const void * pvItemToQueue,
\r
270 portTickType xTicksToWait
\r
274 * This is a macro that calls xQueueGenericSend().
\r
276 * Post an item to the back of a queue. The item is queued by copy, not by
\r
277 * reference. This function must not be called from an interrupt service
\r
278 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
281 * @param xQueue The handle to the queue on which the item is to be posted.
\r
283 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
284 * queue. The size of the items the queue will hold was defined when the
\r
285 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
286 * into the queue storage area.
\r
288 * @param xTicksToWait The maximum amount of time the task should block
\r
289 * waiting for space to become available on the queue, should it already
\r
290 * be full. The call will return immediately if this is set to 0 and the queue
\r
291 * is full. The time is defined in tick periods so the constant
\r
292 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
294 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
304 unsigned long ulVar = 10UL;
\r
306 void vATask( void *pvParameters )
\r
308 xQueueHandle xQueue1, xQueue2;
\r
309 struct AMessage *pxMessage;
\r
311 // Create a queue capable of containing 10 unsigned long values.
\r
312 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
314 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
315 // These should be passed by pointer as they contain a lot of data.
\r
316 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
322 // Send an unsigned long. Wait for 10 ticks for space to become
\r
323 // available if necessary.
\r
324 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
326 // Failed to post the message, even after 10 ticks.
\r
332 // Send a pointer to a struct AMessage object. Don't block if the
\r
333 // queue is already full.
\r
334 pxMessage = & xMessage;
\r
335 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
338 // ... Rest of task code.
\r
341 * \defgroup xQueueSend xQueueSend
\r
342 * \ingroup QueueManagement
\r
344 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
\r
349 portBASE_TYPE xQueueSend(
\r
350 xQueueHandle xQueue,
\r
351 const void * pvItemToQueue,
\r
352 portTickType xTicksToWait
\r
356 * This is a macro that calls xQueueGenericSend(). It is included for
\r
357 * backward compatibility with versions of FreeRTOS.org that did not
\r
358 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
359 * equivalent to xQueueSendToBack().
\r
361 * Post an item on a queue. The item is queued by copy, not by reference.
\r
362 * This function must not be called from an interrupt service routine.
\r
363 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
365 * @param xQueue The handle to the queue on which the item is to be posted.
\r
367 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
368 * queue. The size of the items the queue will hold was defined when the
\r
369 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
370 * into the queue storage area.
\r
372 * @param xTicksToWait The maximum amount of time the task should block
\r
373 * waiting for space to become available on the queue, should it already
\r
374 * be full. The call will return immediately if this is set to 0 and the
\r
375 * queue is full. The time is defined in tick periods so the constant
\r
376 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
378 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
388 unsigned long ulVar = 10UL;
\r
390 void vATask( void *pvParameters )
\r
392 xQueueHandle xQueue1, xQueue2;
\r
393 struct AMessage *pxMessage;
\r
395 // Create a queue capable of containing 10 unsigned long values.
\r
396 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
398 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
399 // These should be passed by pointer as they contain a lot of data.
\r
400 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
406 // Send an unsigned long. Wait for 10 ticks for space to become
\r
407 // available if necessary.
\r
408 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
410 // Failed to post the message, even after 10 ticks.
\r
416 // Send a pointer to a struct AMessage object. Don't block if the
\r
417 // queue is already full.
\r
418 pxMessage = & xMessage;
\r
419 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
422 // ... Rest of task code.
\r
425 * \defgroup xQueueSend xQueueSend
\r
426 * \ingroup QueueManagement
\r
428 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
\r
433 portBASE_TYPE xQueueOverwrite(
\r
434 xQueueHandle xQueue,
\r
435 const void * pvItemToQueue,
\r
439 * Only for use with queues that can hold a single item - so the queue is either
\r
442 * Post an item on a queue. If the queue is already full then overwrite the
\r
443 * value held in the queue. The item is queued by copy, not by reference.
\r
444 * This function must not be called from an interrupt service routine.
\r
445 * See xQueueOverwriteFromISR () for an alternative which may be used in an ISR.
\r
447 * @param xQueue The handle to the queue on which the item is to be posted.
\r
449 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
450 * queue. The size of the items the queue will hold was defined when the
\r
451 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
452 * into the queue storage area.
\r
454 * @return xQueueOverwrite() is a macro that calls xQueueGenericSend(), and
\r
455 * therefore has the same return values as xQueueSendToFront(). However, as
\r
456 * xQueueOverwrite() will write to the queue even when the queue is full pdPASS
\r
457 * will be returned in all cases (errQUEUE_FULL will never be returned).
\r
462 void vFunction( void *pvParameters )
\r
464 xQueueHandle xQueue;
\r
465 unsigned long ulVarToSend, ulValReceived;
\r
467 // Create a queue to hold one unsigned long value. It is strongly
\r
468 // recommended *not* to use xQueueOverwrite() on queues that can
\r
469 // contain more than one value, and doing so will trigger an assertion
\r
470 // if configASSERT() is defined.
\r
471 xQueue = xQueueCreate( 1, sizeof( unsigned long ) );
\r
473 // Write the value 10 to the queue using xQueueOverwrite().
\r
475 xQueueOverwrite( xQueue, &ulVarToSend );
\r
477 // Peeking the queue should now return 10, but leave the value 10 in
\r
478 // the queue. A block time of zero is used as it is known that the
\r
479 // queue holds a value.
\r
481 xQueuePeek( xQueue, &ulValReceived, 0 );
\r
483 if( ulValReceived != 10 )
\r
488 // The queue is still full. Use xQueueOverwrite() to overwrite the
\r
489 // value held in the queue with 100.
\r
491 xQueueOverwrite( xQueue, &ulVarToSend );
\r
493 // This time read from the queue, leaving the queue empty once more.
\r
494 // A block time of 0 is used again.
\r
495 xQueueReceive( xQueue, &ulValReceived, 0 );
\r
497 // The value read should be the last value written, even though the
\r
498 // queue was already full when the value was written.
\r
499 if( ulValReceived != 100 )
\r
507 * \defgroup xQueueOverwrite xQueueOverwrite
\r
508 * \ingroup QueueManagement
\r
510 #define xQueueOverwrite( xQueue, pvItemToQueue ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )
\r
516 portBASE_TYPE xQueueGenericSend(
\r
517 xQueueHandle xQueue,
\r
518 const void * pvItemToQueue,
\r
519 portTickType xTicksToWait
\r
520 portBASE_TYPE xCopyPosition
\r
524 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
525 * xQueueSendToBack() are used in place of calling this function directly.
\r
527 * Post an item on a queue. The item is queued by copy, not by reference.
\r
528 * This function must not be called from an interrupt service routine.
\r
529 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
531 * @param xQueue The handle to the queue on which the item is to be posted.
\r
533 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
534 * queue. The size of the items the queue will hold was defined when the
\r
535 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
536 * into the queue storage area.
\r
538 * @param xTicksToWait The maximum amount of time the task should block
\r
539 * waiting for space to become available on the queue, should it already
\r
540 * be full. The call will return immediately if this is set to 0 and the
\r
541 * queue is full. The time is defined in tick periods so the constant
\r
542 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
544 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
545 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
546 * at the front of the queue (for high priority messages).
\r
548 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
558 unsigned long ulVar = 10UL;
\r
560 void vATask( void *pvParameters )
\r
562 xQueueHandle xQueue1, xQueue2;
\r
563 struct AMessage *pxMessage;
\r
565 // Create a queue capable of containing 10 unsigned long values.
\r
566 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
568 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
569 // These should be passed by pointer as they contain a lot of data.
\r
570 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
576 // Send an unsigned long. Wait for 10 ticks for space to become
\r
577 // available if necessary.
\r
578 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
580 // Failed to post the message, even after 10 ticks.
\r
586 // Send a pointer to a struct AMessage object. Don't block if the
\r
587 // queue is already full.
\r
588 pxMessage = & xMessage;
\r
589 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
592 // ... Rest of task code.
\r
595 * \defgroup xQueueSend xQueueSend
\r
596 * \ingroup QueueManagement
\r
598 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;
\r
603 portBASE_TYPE xQueuePeek(
\r
604 xQueueHandle xQueue,
\r
606 portTickType xTicksToWait
\r
609 * This is a macro that calls the xQueueGenericReceive() function.
\r
611 * Receive an item from a queue without removing the item from the queue.
\r
612 * The item is received by copy so a buffer of adequate size must be
\r
613 * provided. The number of bytes copied into the buffer was defined when
\r
614 * the queue was created.
\r
616 * Successfully received items remain on the queue so will be returned again
\r
617 * by the next call, or a call to xQueueReceive().
\r
619 * This macro must not be used in an interrupt service routine. See
\r
620 * xQueuePeekFromISR() for an alternative that can be called from an interrupt
\r
623 * @param xQueue The handle to the queue from which the item is to be
\r
626 * @param pvBuffer Pointer to the buffer into which the received item will
\r
629 * @param xTicksToWait The maximum amount of time the task should block
\r
630 * waiting for an item to receive should the queue be empty at the time
\r
631 * of the call. The time is defined in tick periods so the constant
\r
632 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
633 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
\r
636 * @return pdTRUE if an item was successfully received from the queue,
\r
637 * otherwise pdFALSE.
\r
647 xQueueHandle xQueue;
\r
649 // Task to create a queue and post a value.
\r
650 void vATask( void *pvParameters )
\r
652 struct AMessage *pxMessage;
\r
654 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
655 // These should be passed by pointer as they contain a lot of data.
\r
656 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
659 // Failed to create the queue.
\r
664 // Send a pointer to a struct AMessage object. Don't block if the
\r
665 // queue is already full.
\r
666 pxMessage = & xMessage;
\r
667 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
669 // ... Rest of task code.
\r
672 // Task to peek the data from the queue.
\r
673 void vADifferentTask( void *pvParameters )
\r
675 struct AMessage *pxRxedMessage;
\r
679 // Peek a message on the created queue. Block for 10 ticks if a
\r
680 // message is not immediately available.
\r
681 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
683 // pcRxedMessage now points to the struct AMessage variable posted
\r
684 // by vATask, but the item still remains on the queue.
\r
688 // ... Rest of task code.
\r
691 * \defgroup xQueueReceive xQueueReceive
\r
692 * \ingroup QueueManagement
\r
694 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
\r
699 portBASE_TYPE xQueuePeekFromISR(
\r
700 xQueueHandle xQueue,
\r
704 * A version of xQueuePeek() that can be called from an interrupt service
\r
707 * Receive an item from a queue without removing the item from the queue.
\r
708 * The item is received by copy so a buffer of adequate size must be
\r
709 * provided. The number of bytes copied into the buffer was defined when
\r
710 * the queue was created.
\r
712 * Successfully received items remain on the queue so will be returned again
\r
713 * by the next call, or a call to xQueueReceive().
\r
715 * @param xQueue The handle to the queue from which the item is to be
\r
718 * @param pvBuffer Pointer to the buffer into which the received item will
\r
721 * @return pdTRUE if an item was successfully received from the queue,
\r
722 * otherwise pdFALSE.
\r
724 * \defgroup xQueuePeekFromISR xQueuePeekFromISR
\r
725 * \ingroup QueueManagement
\r
727 signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, void * const pvBuffer ) PRIVILEGED_FUNCTION;
\r
732 portBASE_TYPE xQueueReceive(
\r
733 xQueueHandle xQueue,
\r
735 portTickType xTicksToWait
\r
738 * This is a macro that calls the xQueueGenericReceive() function.
\r
740 * Receive an item from a queue. The item is received by copy so a buffer of
\r
741 * adequate size must be provided. The number of bytes copied into the buffer
\r
742 * was defined when the queue was created.
\r
744 * Successfully received items are removed from the queue.
\r
746 * This function must not be used in an interrupt service routine. See
\r
747 * xQueueReceiveFromISR for an alternative that can.
\r
749 * @param xQueue The handle to the queue from which the item is to be
\r
752 * @param pvBuffer Pointer to the buffer into which the received item will
\r
755 * @param xTicksToWait The maximum amount of time the task should block
\r
756 * waiting for an item to receive should the queue be empty at the time
\r
757 * of the call. xQueueReceive() will return immediately if xTicksToWait
\r
758 * is zero and the queue is empty. The time is defined in tick periods so the
\r
759 * constant portTICK_RATE_MS should be used to convert to real time if this is
\r
762 * @return pdTRUE if an item was successfully received from the queue,
\r
763 * otherwise pdFALSE.
\r
773 xQueueHandle xQueue;
\r
775 // Task to create a queue and post a value.
\r
776 void vATask( void *pvParameters )
\r
778 struct AMessage *pxMessage;
\r
780 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
781 // These should be passed by pointer as they contain a lot of data.
\r
782 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
785 // Failed to create the queue.
\r
790 // Send a pointer to a struct AMessage object. Don't block if the
\r
791 // queue is already full.
\r
792 pxMessage = & xMessage;
\r
793 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
795 // ... Rest of task code.
\r
798 // Task to receive from the queue.
\r
799 void vADifferentTask( void *pvParameters )
\r
801 struct AMessage *pxRxedMessage;
\r
805 // Receive a message on the created queue. Block for 10 ticks if a
\r
806 // message is not immediately available.
\r
807 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
809 // pcRxedMessage now points to the struct AMessage variable posted
\r
814 // ... Rest of task code.
\r
817 * \defgroup xQueueReceive xQueueReceive
\r
818 * \ingroup QueueManagement
\r
820 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
\r
826 portBASE_TYPE xQueueGenericReceive(
\r
827 xQueueHandle xQueue,
\r
829 portTickType xTicksToWait
\r
830 portBASE_TYPE xJustPeek
\r
833 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
834 * this function directly.
\r
836 * Receive an item from a queue. The item is received by copy so a buffer of
\r
837 * adequate size must be provided. The number of bytes copied into the buffer
\r
838 * was defined when the queue was created.
\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. The time is defined in tick periods so the constant
\r
852 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
853 * xQueueGenericReceive() will return immediately if the queue is empty and
\r
854 * xTicksToWait is 0.
\r
856 * @param xJustPeek When set to true, the item received from the queue is not
\r
857 * actually removed from the queue - meaning a subsequent call to
\r
858 * xQueueReceive() will return the same item. When set to false, the item
\r
859 * being received from the queue is also removed from the queue.
\r
861 * @return pdTRUE if an item was successfully received from the queue,
\r
862 * otherwise pdFALSE.
\r
872 xQueueHandle xQueue;
\r
874 // Task to create a queue and post a value.
\r
875 void vATask( void *pvParameters )
\r
877 struct AMessage *pxMessage;
\r
879 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
880 // These should be passed by pointer as they contain a lot of data.
\r
881 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
884 // Failed to create the queue.
\r
889 // Send a pointer to a struct AMessage object. Don't block if the
\r
890 // queue is already full.
\r
891 pxMessage = & xMessage;
\r
892 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
894 // ... Rest of task code.
\r
897 // Task to receive from the queue.
\r
898 void vADifferentTask( void *pvParameters )
\r
900 struct AMessage *pxRxedMessage;
\r
904 // Receive a message on the created queue. Block for 10 ticks if a
\r
905 // message is not immediately available.
\r
906 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
908 // pcRxedMessage now points to the struct AMessage variable posted
\r
913 // ... Rest of task code.
\r
916 * \defgroup xQueueReceive xQueueReceive
\r
917 * \ingroup QueueManagement
\r
919 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek ) PRIVILEGED_FUNCTION;
\r
923 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
925 * Return the number of messages stored in a queue.
\r
927 * @param xQueue A handle to the queue being queried.
\r
929 * @return The number of messages available in the queue.
\r
931 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
932 * \ingroup QueueManagement
\r
934 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
\r
938 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
940 * Delete a queue - freeing all the memory allocated for storing of items
\r
941 * placed on the queue.
\r
943 * @param xQueue A handle to the queue to be deleted.
\r
945 * \page vQueueDelete vQueueDelete
\r
946 * \ingroup QueueManagement
\r
948 void vQueueDelete( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
\r
953 portBASE_TYPE xQueueSendToFrontFromISR(
\r
954 xQueueHandle xQueue,
\r
955 const void *pvItemToQueue,
\r
956 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
960 * This is a macro that calls xQueueGenericSendFromISR().
\r
962 * Post an item to the front of a queue. It is safe to use this macro from
\r
963 * within an interrupt service routine.
\r
965 * Items are queued by copy not reference so it is preferable to only
\r
966 * queue small items, especially when called from an ISR. In most cases
\r
967 * it would be preferable to store a pointer to the item being queued.
\r
969 * @param xQueue The handle to the queue on which the item is to be posted.
\r
971 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
972 * queue. The size of the items the queue will hold was defined when the
\r
973 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
974 * into the queue storage area.
\r
976 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
\r
977 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
978 * to unblock, and the unblocked task has a priority higher than the currently
\r
979 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
\r
980 * a context switch should be requested before the interrupt is exited.
\r
982 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
985 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
988 void vBufferISR( void )
\r
991 portBASE_TYPE xHigherPrioritTaskWoken;
\r
993 // We have not woken a task at the start of the ISR.
\r
994 xHigherPriorityTaskWoken = pdFALSE;
\r
996 // Loop until the buffer is empty.
\r
999 // Obtain a byte from the buffer.
\r
1000 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1003 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
1005 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1007 // Now the buffer is empty we can switch context if necessary.
\r
1008 if( xHigherPriorityTaskWoken )
\r
1015 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1016 * \ingroup QueueManagement
\r
1018 #define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
\r
1024 portBASE_TYPE xQueueSendToBackFromISR(
\r
1025 xQueueHandle xQueue,
\r
1026 const void *pvItemToQueue,
\r
1027 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
1031 * This is a macro that calls xQueueGenericSendFromISR().
\r
1033 * Post an item to the back of a queue. It is safe to use this macro from
\r
1034 * within an interrupt service routine.
\r
1036 * Items are queued by copy not reference so it is preferable to only
\r
1037 * queue small items, especially when called from an ISR. In most cases
\r
1038 * it would be preferable to store a pointer to the item being queued.
\r
1040 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1042 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1043 * queue. The size of the items the queue will hold was defined when the
\r
1044 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1045 * into the queue storage area.
\r
1047 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
\r
1048 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1049 * to unblock, and the unblocked task has a priority higher than the currently
\r
1050 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
\r
1051 * a context switch should be requested before the interrupt is exited.
\r
1053 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1056 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1059 void vBufferISR( void )
\r
1062 portBASE_TYPE xHigherPriorityTaskWoken;
\r
1064 // We have not woken a task at the start of the ISR.
\r
1065 xHigherPriorityTaskWoken = pdFALSE;
\r
1067 // Loop until the buffer is empty.
\r
1070 // Obtain a byte from the buffer.
\r
1071 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1074 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
1076 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1078 // Now the buffer is empty we can switch context if necessary.
\r
1079 if( xHigherPriorityTaskWoken )
\r
1086 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1087 * \ingroup QueueManagement
\r
1089 #define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
\r
1094 portBASE_TYPE xQueueOverwriteFromISR(
\r
1095 xQueueHandle xQueue,
\r
1096 const void * pvItemToQueue,
\r
1097 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
1101 * A version of xQueueOverwrite() that can be used from an interrupt service
\r
1104 * Only for use with queues that can hold a single item - so the queue is either
\r
1107 * Post an item on a queue. If the queue is already full then overwrite the
\r
1108 * value held in the queue. The item is queued by copy, not by reference.
\r
1110 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1112 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1113 * queue. The size of the items the queue will hold was defined when the
\r
1114 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1115 * into the queue storage area.
\r
1117 * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set
\r
1118 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1119 * to unblock, and the unblocked task has a priority higher than the currently
\r
1120 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
1121 * a context switch should be requested before the interrupt is exited.
\r
1123 * @return xQueueOverwriteFromISR() is a macro that calls
\r
1124 * xQueueGenericSendFromISR(), and therefore has the same return values as
\r
1125 * xQueueSendToFrontFromISR(). However, as xQueueOverwriteFromISR() will write
\r
1126 * to the queue even when the queue is full pdPASS will be returned in all cases
\r
1127 * (errQUEUE_FULL will never be returned).
\r
1132 xQueueHandle xQueue;
\r
1134 void vFunction( void *pvParameters )
\r
1136 // Create a queue to hold one unsigned long value. It is strongly
\r
1137 // recommended *not* to use xQueueOverwrite() on queues that can
\r
1138 // contain more than one value, and doing so will trigger an assertion
\r
1139 // if configASSERT() is defined.
\r
1140 xQueue = xQueueCreate( 1, sizeof( unsigned long ) );
\r
1143 void vAnInterruptHandler( void )
\r
1145 // xHigherPriorityTaskWoken must be set to pdFALSE before it is used.
\r
1146 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
1147 unsigned long ulVarToSend, ulValReceived;
\r
1149 // Write the value 10 to the queue using xQueueOverwriteFromISR().
\r
1151 xQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
\r
1153 // The queue is full, but calling xQueueOverwriteFromISR() again will still
\r
1154 // pass because the value held in the queue will be overwritten with the
\r
1156 ulVarToSend = 100;
\r
1157 xQueueOverwrite( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );
\r
1159 // Reading from the queue will now return 100.
\r
1164 * \defgroup xQueueOverwriteFromISR xQueueOverwriteFromISR
\r
1165 * \ingroup QueueManagement
\r
1167 #define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE )
\r
1172 portBASE_TYPE xQueueSendFromISR(
\r
1173 xQueueHandle xQueue,
\r
1174 const void *pvItemToQueue,
\r
1175 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
1179 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
1180 * for backward compatibility with versions of FreeRTOS.org that did not
\r
1181 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
1184 * Post an item to the back of a queue. It is safe to use this function from
\r
1185 * within an interrupt service routine.
\r
1187 * Items are queued by copy not reference so it is preferable to only
\r
1188 * queue small items, especially when called from an ISR. In most cases
\r
1189 * it would be preferable to store a pointer to the item being queued.
\r
1191 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1193 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1194 * queue. The size of the items the queue will hold was defined when the
\r
1195 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1196 * into the queue storage area.
\r
1198 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
\r
1199 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1200 * to unblock, and the unblocked task has a priority higher than the currently
\r
1201 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
1202 * a context switch should be requested before the interrupt is exited.
\r
1204 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1207 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1210 void vBufferISR( void )
\r
1213 portBASE_TYPE xHigherPriorityTaskWoken;
\r
1215 // We have not woken a task at the start of the ISR.
\r
1216 xHigherPriorityTaskWoken = pdFALSE;
\r
1218 // Loop until the buffer is empty.
\r
1221 // Obtain a byte from the buffer.
\r
1222 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1225 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
1227 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1229 // Now the buffer is empty we can switch context if necessary.
\r
1230 if( xHigherPriorityTaskWoken )
\r
1232 // Actual macro used here is port specific.
\r
1233 taskYIELD_FROM_ISR ();
\r
1238 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1239 * \ingroup QueueManagement
\r
1241 #define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
\r
1246 portBASE_TYPE xQueueGenericSendFromISR(
\r
1247 xQueueHandle xQueue,
\r
1248 const void *pvItemToQueue,
\r
1249 portBASE_TYPE *pxHigherPriorityTaskWoken,
\r
1250 portBASE_TYPE xCopyPosition
\r
1254 * It is preferred that the macros xQueueSendFromISR(),
\r
1255 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1256 * of calling this function directly.
\r
1258 * Post an item on a queue. It is safe to use this function from within an
\r
1259 * interrupt service routine.
\r
1261 * Items are queued by copy not reference so it is preferable to only
\r
1262 * queue small items, especially when called from an ISR. In most cases
\r
1263 * it would be preferable to store a pointer to the item being queued.
\r
1265 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1267 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1268 * queue. The size of the items the queue will hold was defined when the
\r
1269 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1270 * into the queue storage area.
\r
1272 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
\r
1273 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1274 * to unblock, and the unblocked task has a priority higher than the currently
\r
1275 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
\r
1276 * a context switch should be requested before the interrupt is exited.
\r
1278 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1279 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1280 * at the front of the queue (for high priority messages).
\r
1282 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1285 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1288 void vBufferISR( void )
\r
1291 portBASE_TYPE xHigherPriorityTaskWokenByPost;
\r
1293 // We have not woken a task at the start of the ISR.
\r
1294 xHigherPriorityTaskWokenByPost = pdFALSE;
\r
1296 // Loop until the buffer is empty.
\r
1299 // Obtain a byte from the buffer.
\r
1300 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1302 // Post each byte.
\r
1303 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
\r
1305 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1307 // Now the buffer is empty we can switch context if necessary. Note that the
\r
1308 // name of the yield function required is port specific.
\r
1309 if( xHigherPriorityTaskWokenByPost )
\r
1311 taskYIELD_YIELD_FROM_ISR();
\r
1316 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1317 * \ingroup QueueManagement
\r
1319 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle xQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;
\r
1324 portBASE_TYPE xQueueReceiveFromISR(
\r
1325 xQueueHandle xQueue,
\r
1327 portBASE_TYPE *pxTaskWoken
\r
1331 * Receive an item from a queue. It is safe to use this function from within an
\r
1332 * interrupt service routine.
\r
1334 * @param xQueue The handle to the queue from which the item is to be
\r
1337 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1340 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1341 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1342 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1343 * remain unchanged.
\r
1345 * @return pdTRUE if an item was successfully received from the queue,
\r
1346 * otherwise pdFALSE.
\r
1351 xQueueHandle xQueue;
\r
1353 // Function to create a queue and post some values.
\r
1354 void vAFunction( void *pvParameters )
\r
1356 char cValueToPost;
\r
1357 const portTickType xBlockTime = ( portTickType )0xff;
\r
1359 // Create a queue capable of containing 10 characters.
\r
1360 xQueue = xQueueCreate( 10, sizeof( char ) );
\r
1363 // Failed to create the queue.
\r
1368 // Post some characters that will be used within an ISR. If the queue
\r
1369 // is full then this task will block for xBlockTime ticks.
\r
1370 cValueToPost = 'a';
\r
1371 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1372 cValueToPost = 'b';
\r
1373 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1375 // ... keep posting characters ... this task may block when the queue
\r
1378 cValueToPost = 'c';
\r
1379 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1382 // ISR that outputs all the characters received on the queue.
\r
1383 void vISR_Routine( void )
\r
1385 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1388 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1390 // A character was received. Output the character now.
\r
1391 vOutputCharacter( cRxedChar );
\r
1393 // If removing the character from the queue woke the task that was
\r
1394 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1395 // pdTRUE. No matter how many times this loop iterates only one
\r
1396 // task will be woken.
\r
1399 if( cTaskWokenByPost != ( char ) pdFALSE;
\r
1405 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1406 * \ingroup QueueManagement
\r
1408 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
\r
1411 * Utilities to query queues that are safe to use from an ISR. These utilities
\r
1412 * should be used only from witin an ISR, or within a critical section.
\r
1414 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
\r
1415 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
\r
1416 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
\r
1420 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1421 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1422 * xQueueGenericReceive().
\r
1424 * The source code that implements the alternative (Alt) API is much
\r
1425 * simpler because it executes everything from within a critical section.
\r
1426 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1427 * preferred fully featured API too. The fully featured API has more
\r
1428 * complex code that takes longer to execute, but makes much less use of
\r
1429 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1430 * responsiveness to gain execution speed, whereas the fully featured API
\r
1431 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1433 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1434 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1435 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
\r
1436 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
\r
1437 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
\r
1438 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
\r
1441 * The functions defined above are for passing data to and from tasks. The
\r
1442 * functions below are the equivalents for passing data to and from
\r
1445 * These functions are called from the co-routine macro implementation and
\r
1446 * should not be called directly from application code. Instead use the macro
\r
1447 * wrappers defined within croutine.h.
\r
1449 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle xQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1450 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle xQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1451 signed portBASE_TYPE xQueueCRSend( xQueueHandle xQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1452 signed portBASE_TYPE xQueueCRReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1455 * For internal use only. Use xSemaphoreCreateMutex(),
\r
1456 * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
\r
1457 * these functions directly.
\r
1459 xQueueHandle xQueueCreateMutex( unsigned char ucQueueType ) PRIVILEGED_FUNCTION;
\r
1460 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount ) PRIVILEGED_FUNCTION;
\r
1461 void* xQueueGetMutexHolder( xQueueHandle xSemaphore ) PRIVILEGED_FUNCTION;
\r
1464 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1465 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1467 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime ) PRIVILEGED_FUNCTION;
\r
1468 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex ) PRIVILEGED_FUNCTION;
\r
1471 * Reset a queue back to its original empty state. pdPASS is returned if the
\r
1472 * queue is successfully reset. pdFAIL is returned if the queue could not be
\r
1473 * reset because there are tasks blocked on the queue waiting to either
\r
1474 * receive from the queue or send to the queue.
\r
1476 #define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE )
\r
1479 * The registry is provided as a means for kernel aware debuggers to
\r
1480 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
\r
1481 * a queue, semaphore or mutex handle to the registry if you want the handle
\r
1482 * to be available to a kernel aware debugger. If you are not using a kernel
\r
1483 * aware debugger then this function can be ignored.
\r
1485 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
\r
1486 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
\r
1487 * within FreeRTOSConfig.h for the registry to be available. Its value
\r
1488 * does not effect the number of queues, semaphores and mutexes that can be
\r
1489 * created - just the number that the registry can hold.
\r
1491 * @param xQueue The handle of the queue being added to the registry. This
\r
1492 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
\r
1493 * handles can also be passed in here.
\r
1495 * @param pcName The name to be associated with the handle. This is the
\r
1496 * name that the kernel aware debugger will display.
\r
1498 #if configQUEUE_REGISTRY_SIZE > 0U
\r
1499 void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcName ) PRIVILEGED_FUNCTION;
\r
1503 * The registry is provided as a means for kernel aware debuggers to
\r
1504 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
\r
1505 * a queue, semaphore or mutex handle to the registry if you want the handle
\r
1506 * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to
\r
1507 * remove the queue, semaphore or mutex from the register. If you are not using
\r
1508 * a kernel aware debugger then this function can be ignored.
\r
1510 * @param xQueue The handle of the queue being removed from the registry.
\r
1512 #if configQUEUE_REGISTRY_SIZE > 0U
\r
1513 void vQueueUnregisterQueue( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
\r
1517 * Generic version of the queue creation function, which is in turn called by
\r
1518 * any queue, semaphore or mutex creation function or macro.
\r
1520 xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType ) PRIVILEGED_FUNCTION;
\r
1523 * Queue sets provide a mechanism to allow a task to block (pend) on a read
\r
1524 * operation from multiple queues or semaphores simultaneously.
\r
1526 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
\r
1529 * A queue set must be explicitly created using a call to xQueueCreateSet()
\r
1530 * before it can be used. Once created, standard FreeRTOS queues and semaphores
\r
1531 * can be added to the set using calls to xQueueAddToSet().
\r
1532 * xQueueSelectFromSet() is then used to determine which, if any, of the queues
\r
1533 * or semaphores contained in the set is in a state where a queue read or
\r
1534 * semaphore take operation would be successful.
\r
1536 * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
\r
1537 * for reasons why queue sets are very rarely needed in practice as there are
\r
1538 * simpler methods of blocking on multiple objects.
\r
1540 * Note 2: Blocking on a queue set that contains a mutex will not cause the
\r
1541 * mutex holder to inherit the priority of the blocked task.
\r
1543 * Note 3: An additional 4 bytes of RAM is required for each space in a every
\r
1544 * queue added to a queue set. Therefore counting semaphores that have a high
\r
1545 * maximum count value should not be added to a queue set.
\r
1547 * Note 4: A receive (in the case of a queue) or take (in the case of a
\r
1548 * semaphore) operation must not be performed on a member of a queue set unless
\r
1549 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
\r
1551 * @param uxEventQueueLength Queue sets store events that occur on
\r
1552 * the queues and semaphores contained in the set. uxEventQueueLength specifies
\r
1553 * the maximum number of events that can be queued at once. To be absolutely
\r
1554 * certain that events are not lost uxEventQueueLength should be set to the
\r
1555 * total sum of the length of the queues added to the set, where binary
\r
1556 * semaphores and mutexes have a length of 1, and counting semaphores have a
\r
1557 * length set by their maximum count value. Examples:
\r
1558 * + If a queue set is to hold a queue of length 5, another queue of length 12,
\r
1559 * and a binary semaphore, then uxEventQueueLength should be set to
\r
1560 * (5 + 12 + 1), or 18.
\r
1561 * + If a queue set is to hold three binary semaphores then uxEventQueueLength
\r
1562 * should be set to (1 + 1 + 1 ), or 3.
\r
1563 * + If a queue set is to hold a counting semaphore that has a maximum count of
\r
1564 * 5, and a counting semaphore that has a maximum count of 3, then
\r
1565 * uxEventQueueLength should be set to (5 + 3), or 8.
\r
1567 * @return If the queue set is created successfully then a handle to the created
\r
1568 * queue set is returned. Otherwise NULL is returned.
\r
1570 xQueueSetHandle xQueueCreateSet( unsigned portBASE_TYPE uxEventQueueLength ) PRIVILEGED_FUNCTION;
\r
1573 * Adds a queue or semaphore to a queue set that was previously created by a
\r
1574 * call to xQueueCreateSet().
\r
1576 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
\r
1579 * Note 1: A receive (in the case of a queue) or take (in the case of a
\r
1580 * semaphore) operation must not be performed on a member of a queue set unless
\r
1581 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
\r
1583 * @param xQueueOrSemaphore The handle of the queue or semaphore being added to
\r
1584 * the queue set (cast to an xQueueSetMemberHandle type).
\r
1586 * @param xQueueSet The handle of the queue set to which the queue or semaphore
\r
1589 * @return If the queue or semaphore was successfully added to the queue set
\r
1590 * then pdPASS is returned. If the queue could not be successfully added to the
\r
1591 * queue set because it is already a member of a different queue set then pdFAIL
\r
1594 portBASE_TYPE xQueueAddToSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet ) PRIVILEGED_FUNCTION;
\r
1597 * Removes a queue or semaphore from a queue set. A queue or semaphore can only
\r
1598 * be removed from a set if the queue or semaphore is empty.
\r
1600 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
\r
1603 * @param xQueueOrSemaphore The handle of the queue or semaphore being removed
\r
1604 * from the queue set (cast to an xQueueSetMemberHandle type).
\r
1606 * @param xQueueSet The handle of the queue set in which the queue or semaphore
\r
1609 * @return If the queue or semaphore was successfully removed from the queue set
\r
1610 * then pdPASS is returned. If the queue was not in the queue set, or the
\r
1611 * queue (or semaphore) was not empty, then pdFAIL is returned.
\r
1613 portBASE_TYPE xQueueRemoveFromSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet ) PRIVILEGED_FUNCTION;
\r
1616 * xQueueSelectFromSet() selects from the members of a queue set a queue or
\r
1617 * semaphore that either contains data (in the case of a queue) or is available
\r
1618 * to take (in the case of a semaphore). xQueueSelectFromSet() effectively
\r
1619 * allows a task to block (pend) on a read operation on all the queues and
\r
1620 * semaphores in a queue set simultaneously.
\r
1622 * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this
\r
1625 * Note 1: See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html
\r
1626 * for reasons why queue sets are very rarely needed in practice as there are
\r
1627 * simpler methods of blocking on multiple objects.
\r
1629 * Note 2: Blocking on a queue set that contains a mutex will not cause the
\r
1630 * mutex holder to inherit the priority of the blocked task.
\r
1632 * Note 3: A receive (in the case of a queue) or take (in the case of a
\r
1633 * semaphore) operation must not be performed on a member of a queue set unless
\r
1634 * a call to xQueueSelectFromSet() has first returned a handle to that set member.
\r
1636 * @param xQueueSet The queue set on which the task will (potentially) block.
\r
1638 * @param xBlockTimeTicks The maximum time, in ticks, that the calling task will
\r
1639 * remain in the Blocked state (with other tasks executing) to wait for a member
\r
1640 * of the queue set to be ready for a successful queue read or semaphore take
\r
1643 * @return xQueueSelectFromSet() will return the handle of a queue (cast to
\r
1644 * a xQueueSetMemberHandle type) contained in the queue set that contains data,
\r
1645 * or the handle of a semaphore (cast to a xQueueSetMemberHandle type) contained
\r
1646 * in the queue set that is available, or NULL if no such queue or semaphore
\r
1647 * exists before before the specified block time expires.
\r
1649 xQueueSetMemberHandle xQueueSelectFromSet( xQueueSetHandle xQueueSet, portTickType xBlockTimeTicks ) PRIVILEGED_FUNCTION;
\r
1652 * A version of xQueueSelectFromSet() that can be used from an ISR.
\r
1654 xQueueSetMemberHandle xQueueSelectFromSetFromISR( xQueueSetHandle xQueueSet ) PRIVILEGED_FUNCTION;
\r
1656 /* Not public API functions. */
\r
1657 void vQueueWaitForMessageRestricted( xQueueHandle xQueue, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;
\r
1658 portBASE_TYPE xQueueGenericReset( xQueueHandle xQueue, portBASE_TYPE xNewQueue ) PRIVILEGED_FUNCTION;
\r
1659 void vQueueSetQueueNumber( xQueueHandle xQueue, unsigned char ucQueueNumber ) PRIVILEGED_FUNCTION;
\r
1660 unsigned char ucQueueGetQueueNumber( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
\r
1661 unsigned char ucQueueGetQueueType( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;
\r
1664 #ifdef __cplusplus
\r
1668 #endif /* QUEUE_H */
\r