2 FreeRTOS V7.3.0 - Copyright (C) 2012 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
32 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
33 distribute a combined work that includes FreeRTOS without being obliged to
\r
34 provide the source code for proprietary components outside of the FreeRTOS
\r
35 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
36 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
37 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
38 more details. You should have received a copy of the GNU General Public
\r
39 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
40 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
41 by writing to Richard Barry, contact details for whom are available on the
\r
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\r
62 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
63 the code with commercial support, indemnification, and middleware, under
\r
64 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
65 provide a safety engineered and independently SIL3 certified version under
\r
66 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
73 #ifndef INC_FREERTOS_H
\r
74 #error "include FreeRTOS.h" must appear in source files before "include queue.h"
\r
82 #include "mpu_wrappers.h"
\r
85 * Type by which queues are referenced. For example, a call to xQueueCreate
\r
86 * returns (via a pointer parameter) an xQueueHandle variable that can then
\r
87 * be used as a parameter to xQueueSend(), xQueueReceive(), etc.
\r
89 typedef void * xQueueHandle;
\r
92 /* For internal use only. */
\r
93 #define queueSEND_TO_BACK ( 0 )
\r
94 #define queueSEND_TO_FRONT ( 1 )
\r
96 /* For internal use only. These definitions *must* match those in queue.c. */
\r
97 #define queueQUEUE_TYPE_BASE ( 0U )
\r
98 #define queueQUEUE_TYPE_MUTEX ( 1U )
\r
99 #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( 2U )
\r
100 #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( 3U )
\r
101 #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( 4U )
\r
106 xQueueHandle xQueueCreate(
\r
107 unsigned portBASE_TYPE uxQueueLength,
\r
108 unsigned portBASE_TYPE uxItemSize
\r
112 * Creates a new queue instance. This allocates the storage required by the
\r
113 * new queue and returns a handle for the queue.
\r
115 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
117 * @param uxItemSize The number of bytes each item in the queue will require.
\r
118 * Items are queued by copy, not by reference, so this is the number of bytes
\r
119 * that will be copied for each posted item. Each item on the queue must be
\r
122 * @return If the queue is successfully create then a handle to the newly
\r
123 * created queue is returned. If the queue cannot be created then 0 is
\r
134 void vATask( void *pvParameters )
\r
136 xQueueHandle xQueue1, xQueue2;
\r
138 // Create a queue capable of containing 10 unsigned long values.
\r
139 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
142 // Queue was not created and must not be used.
\r
145 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
146 // These should be passed by pointer as they contain a lot of data.
\r
147 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
150 // Queue was not created and must not be used.
\r
153 // ... Rest of task code.
\r
156 * \defgroup xQueueCreate xQueueCreate
\r
157 * \ingroup QueueManagement
\r
159 #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( uxQueueLength, uxItemSize, queueQUEUE_TYPE_BASE )
\r
164 portBASE_TYPE xQueueSendToToFront(
\r
165 xQueueHandle xQueue,
\r
166 const void * pvItemToQueue,
\r
167 portTickType xTicksToWait
\r
171 * This is a macro that calls xQueueGenericSend().
\r
173 * Post an item to the front of a queue. The item is queued by copy, not by
\r
174 * reference. This function must not be called from an interrupt service
\r
175 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
178 * @param xQueue The handle to the queue on which the item is to be posted.
\r
180 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
181 * queue. The size of the items the queue will hold was defined when the
\r
182 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
183 * into the queue storage area.
\r
185 * @param xTicksToWait The maximum amount of time the task should block
\r
186 * waiting for space to become available on the queue, should it already
\r
187 * be full. The call will return immediately if this is set to 0 and the
\r
188 * queue is full. The time is defined in tick periods so the constant
\r
189 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
191 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
201 unsigned long ulVar = 10UL;
\r
203 void vATask( void *pvParameters )
\r
205 xQueueHandle xQueue1, xQueue2;
\r
206 struct AMessage *pxMessage;
\r
208 // Create a queue capable of containing 10 unsigned long values.
\r
209 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
211 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
212 // These should be passed by pointer as they contain a lot of data.
\r
213 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
219 // Send an unsigned long. Wait for 10 ticks for space to become
\r
220 // available if necessary.
\r
221 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
223 // Failed to post the message, even after 10 ticks.
\r
229 // Send a pointer to a struct AMessage object. Don't block if the
\r
230 // queue is already full.
\r
231 pxMessage = & xMessage;
\r
232 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
235 // ... Rest of task code.
\r
238 * \defgroup xQueueSend xQueueSend
\r
239 * \ingroup QueueManagement
\r
241 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
\r
246 portBASE_TYPE xQueueSendToBack(
\r
247 xQueueHandle xQueue,
\r
248 const void * pvItemToQueue,
\r
249 portTickType xTicksToWait
\r
253 * This is a macro that calls xQueueGenericSend().
\r
255 * Post an item to the back of a queue. The item is queued by copy, not by
\r
256 * reference. This function must not be called from an interrupt service
\r
257 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
260 * @param xQueue The handle to the queue on which the item is to be posted.
\r
262 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
263 * queue. The size of the items the queue will hold was defined when the
\r
264 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
265 * into the queue storage area.
\r
267 * @param xTicksToWait The maximum amount of time the task should block
\r
268 * waiting for space to become available on the queue, should it already
\r
269 * be full. The call will return immediately if this is set to 0 and the queue
\r
270 * is full. The time is defined in tick periods so the constant
\r
271 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
273 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
283 unsigned long ulVar = 10UL;
\r
285 void vATask( void *pvParameters )
\r
287 xQueueHandle xQueue1, xQueue2;
\r
288 struct AMessage *pxMessage;
\r
290 // Create a queue capable of containing 10 unsigned long values.
\r
291 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
293 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
294 // These should be passed by pointer as they contain a lot of data.
\r
295 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
301 // Send an unsigned long. Wait for 10 ticks for space to become
\r
302 // available if necessary.
\r
303 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
305 // Failed to post the message, even after 10 ticks.
\r
311 // Send a pointer to a struct AMessage object. Don't block if the
\r
312 // queue is already full.
\r
313 pxMessage = & xMessage;
\r
314 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
317 // ... Rest of task code.
\r
320 * \defgroup xQueueSend xQueueSend
\r
321 * \ingroup QueueManagement
\r
323 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
\r
328 portBASE_TYPE xQueueSend(
\r
329 xQueueHandle xQueue,
\r
330 const void * pvItemToQueue,
\r
331 portTickType xTicksToWait
\r
335 * This is a macro that calls xQueueGenericSend(). It is included for
\r
336 * backward compatibility with versions of FreeRTOS.org that did not
\r
337 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
338 * equivalent to xQueueSendToBack().
\r
340 * Post an item on a queue. The item is queued by copy, not by reference.
\r
341 * This function must not be called from an interrupt service routine.
\r
342 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
344 * @param xQueue The handle to the queue on which the item is to be posted.
\r
346 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
347 * queue. The size of the items the queue will hold was defined when the
\r
348 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
349 * into the queue storage area.
\r
351 * @param xTicksToWait The maximum amount of time the task should block
\r
352 * waiting for space to become available on the queue, should it already
\r
353 * be full. The call will return immediately if this is set to 0 and the
\r
354 * queue is full. The time is defined in tick periods so the constant
\r
355 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
357 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
367 unsigned long ulVar = 10UL;
\r
369 void vATask( void *pvParameters )
\r
371 xQueueHandle xQueue1, xQueue2;
\r
372 struct AMessage *pxMessage;
\r
374 // Create a queue capable of containing 10 unsigned long values.
\r
375 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
377 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
378 // These should be passed by pointer as they contain a lot of data.
\r
379 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
385 // Send an unsigned long. Wait for 10 ticks for space to become
\r
386 // available if necessary.
\r
387 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
389 // Failed to post the message, even after 10 ticks.
\r
395 // Send a pointer to a struct AMessage object. Don't block if the
\r
396 // queue is already full.
\r
397 pxMessage = & xMessage;
\r
398 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
401 // ... Rest of task code.
\r
404 * \defgroup xQueueSend xQueueSend
\r
405 * \ingroup QueueManagement
\r
407 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
\r
413 portBASE_TYPE xQueueGenericSend(
\r
414 xQueueHandle xQueue,
\r
415 const void * pvItemToQueue,
\r
416 portTickType xTicksToWait
\r
417 portBASE_TYPE xCopyPosition
\r
421 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
422 * xQueueSendToBack() are used in place of calling this function directly.
\r
424 * Post an item on a queue. The item is queued by copy, not by reference.
\r
425 * This function must not be called from an interrupt service routine.
\r
426 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
428 * @param xQueue The handle to the queue on which the item is to be posted.
\r
430 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
431 * queue. The size of the items the queue will hold was defined when the
\r
432 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
433 * into the queue storage area.
\r
435 * @param xTicksToWait The maximum amount of time the task should block
\r
436 * waiting for space to become available on the queue, should it already
\r
437 * be full. The call will return immediately if this is set to 0 and the
\r
438 * queue is full. The time is defined in tick periods so the constant
\r
439 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
441 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
442 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
443 * at the front of the queue (for high priority messages).
\r
445 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
455 unsigned long ulVar = 10UL;
\r
457 void vATask( void *pvParameters )
\r
459 xQueueHandle xQueue1, xQueue2;
\r
460 struct AMessage *pxMessage;
\r
462 // Create a queue capable of containing 10 unsigned long values.
\r
463 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
465 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
466 // These should be passed by pointer as they contain a lot of data.
\r
467 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
473 // Send an unsigned long. Wait for 10 ticks for space to become
\r
474 // available if necessary.
\r
475 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
477 // Failed to post the message, even after 10 ticks.
\r
483 // Send a pointer to a struct AMessage object. Don't block if the
\r
484 // queue is already full.
\r
485 pxMessage = & xMessage;
\r
486 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
489 // ... Rest of task code.
\r
492 * \defgroup xQueueSend xQueueSend
\r
493 * \ingroup QueueManagement
\r
495 signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
500 portBASE_TYPE xQueuePeek(
\r
501 xQueueHandle xQueue,
\r
503 portTickType xTicksToWait
\r
506 * This is a macro that calls the xQueueGenericReceive() function.
\r
508 * Receive an item from a queue without removing the item from the queue.
\r
509 * The item is received by copy so a buffer of adequate size must be
\r
510 * provided. The number of bytes copied into the buffer was defined when
\r
511 * the queue was created.
\r
513 * Successfully received items remain on the queue so will be returned again
\r
514 * by the next call, or a call to xQueueReceive().
\r
516 * This macro must not be used in an interrupt service routine.
\r
518 * @param pxQueue The handle to the queue from which the item is to be
\r
521 * @param pvBuffer Pointer to the buffer into which the received item will
\r
524 * @param xTicksToWait The maximum amount of time the task should block
\r
525 * waiting for an item to receive should the queue be empty at the time
\r
526 * of the call. The time is defined in tick periods so the constant
\r
527 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
528 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
\r
531 * @return pdTRUE if an item was successfully received from the queue,
\r
532 * otherwise pdFALSE.
\r
542 xQueueHandle xQueue;
\r
544 // Task to create a queue and post a value.
\r
545 void vATask( void *pvParameters )
\r
547 struct AMessage *pxMessage;
\r
549 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
550 // These should be passed by pointer as they contain a lot of data.
\r
551 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
554 // Failed to create the queue.
\r
559 // Send a pointer to a struct AMessage object. Don't block if the
\r
560 // queue is already full.
\r
561 pxMessage = & xMessage;
\r
562 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
564 // ... Rest of task code.
\r
567 // Task to peek the data from the queue.
\r
568 void vADifferentTask( void *pvParameters )
\r
570 struct AMessage *pxRxedMessage;
\r
574 // Peek a message on the created queue. Block for 10 ticks if a
\r
575 // message is not immediately available.
\r
576 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
578 // pcRxedMessage now points to the struct AMessage variable posted
\r
579 // by vATask, but the item still remains on the queue.
\r
583 // ... Rest of task code.
\r
586 * \defgroup xQueueReceive xQueueReceive
\r
587 * \ingroup QueueManagement
\r
589 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
\r
594 portBASE_TYPE xQueueReceive(
\r
595 xQueueHandle xQueue,
\r
597 portTickType xTicksToWait
\r
600 * This is a macro that calls the xQueueGenericReceive() function.
\r
602 * Receive an item from a queue. The item is received by copy so a buffer of
\r
603 * adequate size must be provided. The number of bytes copied into the buffer
\r
604 * was defined when the queue was created.
\r
606 * Successfully received items are removed from the queue.
\r
608 * This function must not be used in an interrupt service routine. See
\r
609 * xQueueReceiveFromISR for an alternative that can.
\r
611 * @param pxQueue The handle to the queue from which the item is to be
\r
614 * @param pvBuffer Pointer to the buffer into which the received item will
\r
617 * @param xTicksToWait The maximum amount of time the task should block
\r
618 * waiting for an item to receive should the queue be empty at the time
\r
619 * of the call. xQueueReceive() will return immediately if xTicksToWait
\r
620 * is zero and the queue is empty. The time is defined in tick periods so the
\r
621 * constant portTICK_RATE_MS should be used to convert to real time if this is
\r
624 * @return pdTRUE if an item was successfully received from the queue,
\r
625 * otherwise pdFALSE.
\r
635 xQueueHandle xQueue;
\r
637 // Task to create a queue and post a value.
\r
638 void vATask( void *pvParameters )
\r
640 struct AMessage *pxMessage;
\r
642 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
643 // These should be passed by pointer as they contain a lot of data.
\r
644 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
647 // Failed to create the queue.
\r
652 // Send a pointer to a struct AMessage object. Don't block if the
\r
653 // queue is already full.
\r
654 pxMessage = & xMessage;
\r
655 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
657 // ... Rest of task code.
\r
660 // Task to receive from the queue.
\r
661 void vADifferentTask( void *pvParameters )
\r
663 struct AMessage *pxRxedMessage;
\r
667 // Receive a message on the created queue. Block for 10 ticks if a
\r
668 // message is not immediately available.
\r
669 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
671 // pcRxedMessage now points to the struct AMessage variable posted
\r
676 // ... Rest of task code.
\r
679 * \defgroup xQueueReceive xQueueReceive
\r
680 * \ingroup QueueManagement
\r
682 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
\r
688 portBASE_TYPE xQueueGenericReceive(
\r
689 xQueueHandle xQueue,
\r
691 portTickType xTicksToWait
\r
692 portBASE_TYPE xJustPeek
\r
695 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
696 * this function directly.
\r
698 * Receive an item from a queue. The item is received by copy so a buffer of
\r
699 * adequate size must be provided. The number of bytes copied into the buffer
\r
700 * was defined when the queue was created.
\r
702 * This function must not be used in an interrupt service routine. See
\r
703 * xQueueReceiveFromISR for an alternative that can.
\r
705 * @param pxQueue The handle to the queue from which the item is to be
\r
708 * @param pvBuffer Pointer to the buffer into which the received item will
\r
711 * @param xTicksToWait The maximum amount of time the task should block
\r
712 * waiting for an item to receive should the queue be empty at the time
\r
713 * of the call. The time is defined in tick periods so the constant
\r
714 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
715 * xQueueGenericReceive() will return immediately if the queue is empty and
\r
716 * xTicksToWait is 0.
\r
718 * @param xJustPeek When set to true, the item received from the queue is not
\r
719 * actually removed from the queue - meaning a subsequent call to
\r
720 * xQueueReceive() will return the same item. When set to false, the item
\r
721 * being received from the queue is also removed from the queue.
\r
723 * @return pdTRUE if an item was successfully received from the queue,
\r
724 * otherwise pdFALSE.
\r
734 xQueueHandle xQueue;
\r
736 // Task to create a queue and post a value.
\r
737 void vATask( void *pvParameters )
\r
739 struct AMessage *pxMessage;
\r
741 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
742 // These should be passed by pointer as they contain a lot of data.
\r
743 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
746 // Failed to create the queue.
\r
751 // Send a pointer to a struct AMessage object. Don't block if the
\r
752 // queue is already full.
\r
753 pxMessage = & xMessage;
\r
754 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
756 // ... Rest of task code.
\r
759 // Task to receive from the queue.
\r
760 void vADifferentTask( void *pvParameters )
\r
762 struct AMessage *pxRxedMessage;
\r
766 // Receive a message on the created queue. Block for 10 ticks if a
\r
767 // message is not immediately available.
\r
768 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
770 // pcRxedMessage now points to the struct AMessage variable posted
\r
775 // ... Rest of task code.
\r
778 * \defgroup xQueueReceive xQueueReceive
\r
779 * \ingroup QueueManagement
\r
781 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
785 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
787 * Return the number of messages stored in a queue.
\r
789 * @param xQueue A handle to the queue being queried.
\r
791 * @return The number of messages available in the queue.
\r
793 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
794 * \ingroup QueueManagement
\r
796 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
800 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
802 * Delete a queue - freeing all the memory allocated for storing of items
\r
803 * placed on the queue.
\r
805 * @param xQueue A handle to the queue to be deleted.
\r
807 * \page vQueueDelete vQueueDelete
\r
808 * \ingroup QueueManagement
\r
810 void vQueueDelete( xQueueHandle pxQueue );
\r
815 portBASE_TYPE xQueueSendToFrontFromISR(
\r
816 xQueueHandle pxQueue,
\r
817 const void *pvItemToQueue,
\r
818 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
822 * This is a macro that calls xQueueGenericSendFromISR().
\r
824 * Post an item to the front of a queue. It is safe to use this macro from
\r
825 * within an interrupt service routine.
\r
827 * Items are queued by copy not reference so it is preferable to only
\r
828 * queue small items, especially when called from an ISR. In most cases
\r
829 * it would be preferable to store a pointer to the item being queued.
\r
831 * @param xQueue The handle to the queue on which the item is to be posted.
\r
833 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
834 * queue. The size of the items the queue will hold was defined when the
\r
835 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
836 * into the queue storage area.
\r
838 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
\r
839 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
840 * to unblock, and the unblocked task has a priority higher than the currently
\r
841 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
\r
842 * a context switch should be requested before the interrupt is exited.
\r
844 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
847 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
850 void vBufferISR( void )
\r
853 portBASE_TYPE xHigherPrioritTaskWoken;
\r
855 // We have not woken a task at the start of the ISR.
\r
856 xHigherPriorityTaskWoken = pdFALSE;
\r
858 // Loop until the buffer is empty.
\r
861 // Obtain a byte from the buffer.
\r
862 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
865 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
867 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
869 // Now the buffer is empty we can switch context if necessary.
\r
870 if( xHigherPriorityTaskWoken )
\r
877 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
878 * \ingroup QueueManagement
\r
880 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
\r
886 portBASE_TYPE xQueueSendToBackFromISR(
\r
887 xQueueHandle pxQueue,
\r
888 const void *pvItemToQueue,
\r
889 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
893 * This is a macro that calls xQueueGenericSendFromISR().
\r
895 * Post an item to the back of a queue. It is safe to use this macro from
\r
896 * within an interrupt service routine.
\r
898 * Items are queued by copy not reference so it is preferable to only
\r
899 * queue small items, especially when called from an ISR. In most cases
\r
900 * it would be preferable to store a pointer to the item being queued.
\r
902 * @param xQueue The handle to the queue on which the item is to be posted.
\r
904 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
905 * queue. The size of the items the queue will hold was defined when the
\r
906 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
907 * into the queue storage area.
\r
909 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
\r
910 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
911 * to unblock, and the unblocked task has a priority higher than the currently
\r
912 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
\r
913 * a context switch should be requested before the interrupt is exited.
\r
915 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
918 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
921 void vBufferISR( void )
\r
924 portBASE_TYPE xHigherPriorityTaskWoken;
\r
926 // We have not woken a task at the start of the ISR.
\r
927 xHigherPriorityTaskWoken = pdFALSE;
\r
929 // Loop until the buffer is empty.
\r
932 // Obtain a byte from the buffer.
\r
933 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
936 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
938 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
940 // Now the buffer is empty we can switch context if necessary.
\r
941 if( xHigherPriorityTaskWoken )
\r
948 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
949 * \ingroup QueueManagement
\r
951 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
\r
956 portBASE_TYPE xQueueSendFromISR(
\r
957 xQueueHandle pxQueue,
\r
958 const void *pvItemToQueue,
\r
959 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
963 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
964 * for backward compatibility with versions of FreeRTOS.org that did not
\r
965 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
968 * Post an item to the back of a queue. It is safe to use this function from
\r
969 * within an interrupt service routine.
\r
971 * Items are queued by copy not reference so it is preferable to only
\r
972 * queue small items, especially when called from an ISR. In most cases
\r
973 * it would be preferable to store a pointer to the item being queued.
\r
975 * @param xQueue The handle to the queue on which the item is to be posted.
\r
977 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
978 * queue. The size of the items the queue will hold was defined when the
\r
979 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
980 * into the queue storage area.
\r
982 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
\r
983 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
984 * to unblock, and the unblocked task has a priority higher than the currently
\r
985 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
986 * a context switch should be requested before the interrupt is exited.
\r
988 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
991 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
994 void vBufferISR( void )
\r
997 portBASE_TYPE xHigherPriorityTaskWoken;
\r
999 // We have not woken a task at the start of the ISR.
\r
1000 xHigherPriorityTaskWoken = pdFALSE;
\r
1002 // Loop until the buffer is empty.
\r
1005 // Obtain a byte from the buffer.
\r
1006 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1009 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
1011 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1013 // Now the buffer is empty we can switch context if necessary.
\r
1014 if( xHigherPriorityTaskWoken )
\r
1016 // Actual macro used here is port specific.
\r
1017 taskYIELD_FROM_ISR ();
\r
1022 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1023 * \ingroup QueueManagement
\r
1025 #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
\r
1030 portBASE_TYPE xQueueGenericSendFromISR(
\r
1031 xQueueHandle pxQueue,
\r
1032 const void *pvItemToQueue,
\r
1033 portBASE_TYPE *pxHigherPriorityTaskWoken,
\r
1034 portBASE_TYPE xCopyPosition
\r
1038 * It is preferred that the macros xQueueSendFromISR(),
\r
1039 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1040 * of calling this function directly.
\r
1042 * Post an item on a queue. It is safe to use this function from within an
\r
1043 * interrupt service routine.
\r
1045 * Items are queued by copy not reference so it is preferable to only
\r
1046 * queue small items, especially when called from an ISR. In most cases
\r
1047 * it would be preferable to store a pointer to the item being queued.
\r
1049 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1051 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1052 * queue. The size of the items the queue will hold was defined when the
\r
1053 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1054 * into the queue storage area.
\r
1056 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
\r
1057 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1058 * to unblock, and the unblocked task has a priority higher than the currently
\r
1059 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
\r
1060 * a context switch should be requested before the interrupt is exited.
\r
1062 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1063 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1064 * at the front of the queue (for high priority messages).
\r
1066 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1069 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1072 void vBufferISR( void )
\r
1075 portBASE_TYPE xHigherPriorityTaskWokenByPost;
\r
1077 // We have not woken a task at the start of the ISR.
\r
1078 xHigherPriorityTaskWokenByPost = pdFALSE;
\r
1080 // Loop until the buffer is empty.
\r
1083 // Obtain a byte from the buffer.
\r
1084 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1086 // Post each byte.
\r
1087 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
\r
1089 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1091 // Now the buffer is empty we can switch context if necessary. Note that the
\r
1092 // name of the yield function required is port specific.
\r
1093 if( xHigherPriorityTaskWokenByPost )
\r
1095 taskYIELD_YIELD_FROM_ISR();
\r
1100 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1101 * \ingroup QueueManagement
\r
1103 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
\r
1108 portBASE_TYPE xQueueReceiveFromISR(
\r
1109 xQueueHandle pxQueue,
\r
1111 portBASE_TYPE *pxTaskWoken
\r
1115 * Receive an item from a queue. It is safe to use this function from within an
\r
1116 * interrupt service routine.
\r
1118 * @param pxQueue The handle to the queue from which the item is to be
\r
1121 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1124 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1125 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1126 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1127 * remain unchanged.
\r
1129 * @return pdTRUE if an item was successfully received from the queue,
\r
1130 * otherwise pdFALSE.
\r
1135 xQueueHandle xQueue;
\r
1137 // Function to create a queue and post some values.
\r
1138 void vAFunction( void *pvParameters )
\r
1140 char cValueToPost;
\r
1141 const portTickType xBlockTime = ( portTickType )0xff;
\r
1143 // Create a queue capable of containing 10 characters.
\r
1144 xQueue = xQueueCreate( 10, sizeof( char ) );
\r
1147 // Failed to create the queue.
\r
1152 // Post some characters that will be used within an ISR. If the queue
\r
1153 // is full then this task will block for xBlockTime ticks.
\r
1154 cValueToPost = 'a';
\r
1155 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1156 cValueToPost = 'b';
\r
1157 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1159 // ... keep posting characters ... this task may block when the queue
\r
1162 cValueToPost = 'c';
\r
1163 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1166 // ISR that outputs all the characters received on the queue.
\r
1167 void vISR_Routine( void )
\r
1169 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1172 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1174 // A character was received. Output the character now.
\r
1175 vOutputCharacter( cRxedChar );
\r
1177 // If removing the character from the queue woke the task that was
\r
1178 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1179 // pdTRUE. No matter how many times this loop iterates only one
\r
1180 // task will be woken.
\r
1183 if( cTaskWokenByPost != ( char ) pdFALSE;
\r
1189 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1190 * \ingroup QueueManagement
\r
1192 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken );
\r
1195 * Utilities to query queues that are safe to use from an ISR. These utilities
\r
1196 * should be used only from witin an ISR, or within a critical section.
\r
1198 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
\r
1199 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
\r
1200 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
\r
1204 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1205 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1206 * xQueueGenericReceive().
\r
1208 * The source code that implements the alternative (Alt) API is much
\r
1209 * simpler because it executes everything from within a critical section.
\r
1210 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1211 * preferred fully featured API too. The fully featured API has more
\r
1212 * complex code that takes longer to execute, but makes much less use of
\r
1213 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1214 * responsiveness to gain execution speed, whereas the fully featured API
\r
1215 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1217 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1218 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1219 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
\r
1220 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
\r
1221 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
\r
1222 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
\r
1225 * The functions defined above are for passing data to and from tasks. The
\r
1226 * functions below are the equivalents for passing data to and from
\r
1229 * These functions are called from the co-routine macro implementation and
\r
1230 * should not be called directly from application code. Instead use the macro
\r
1231 * wrappers defined within croutine.h.
\r
1233 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1234 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1235 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1236 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1239 * For internal use only. Use xSemaphoreCreateMutex(),
\r
1240 * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
\r
1241 * these functions directly.
\r
1243 xQueueHandle xQueueCreateMutex( unsigned char ucQueueType );
\r
1244 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1245 void* xQueueGetMutexHolder( xQueueHandle xSemaphore );
\r
1248 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1249 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1251 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime );
\r
1252 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex );
\r
1255 * Reset a queue back to its original empty state. pdPASS is returned if the
\r
1256 * queue is successfully reset. pdFAIL is returned if the queue could not be
\r
1257 * reset because there are tasks blocked on the queue waiting to either
\r
1258 * receive from the queue or send to the queue.
\r
1260 #define xQueueReset( pxQueue ) xQueueGenericReset( pxQueue, pdFALSE )
\r
1263 * The registry is provided as a means for kernel aware debuggers to
\r
1264 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
\r
1265 * a queue, semaphore or mutex handle to the registry if you want the handle
\r
1266 * to be available to a kernel aware debugger. If you are not using a kernel
\r
1267 * aware debugger then this function can be ignored.
\r
1269 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
\r
1270 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
\r
1271 * within FreeRTOSConfig.h for the registry to be available. Its value
\r
1272 * does not effect the number of queues, semaphores and mutexes that can be
\r
1273 * created - just the number that the registry can hold.
\r
1275 * @param xQueue The handle of the queue being added to the registry. This
\r
1276 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
\r
1277 * handles can also be passed in here.
\r
1279 * @param pcName The name to be associated with the handle. This is the
\r
1280 * name that the kernel aware debugger will display.
\r
1282 #if configQUEUE_REGISTRY_SIZE > 0U
\r
1283 void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcName );
\r
1287 * Generic version of the queue creation function, which is in turn called by
\r
1288 * any queue, semaphore or mutex creation function or macro.
\r
1290 xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType );
\r
1292 /* Not public API functions. */
\r
1293 void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait );
\r
1294 portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue );
\r
1297 #ifdef __cplusplus
\r
1301 #endif /* QUEUE_H */
\r