2 FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
71 #ifndef INC_FREERTOS_H
\r
72 #error "include FreeRTOS.h" must appear in source files before "include queue.h"
\r
80 #include "mpu_wrappers.h"
\r
83 * Type by which queues are referenced. For example, a call to xQueueCreate
\r
84 * returns (via a pointer parameter) an xQueueHandle variable that can then
\r
85 * be used as a parameter to xQueueSend(), xQueueReceive(), etc.
\r
87 typedef void * xQueueHandle;
\r
90 /* For internal use only. */
\r
91 #define queueSEND_TO_BACK ( 0 )
\r
92 #define queueSEND_TO_FRONT ( 1 )
\r
94 /* For internal use only. These definitions *must* match those in queue.c. */
\r
95 #define queueQUEUE_TYPE_BASE ( 0U )
\r
96 #define queueQUEUE_TYPE_MUTEX ( 1U )
\r
97 #define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( 2U )
\r
98 #define queueQUEUE_TYPE_BINARY_SEMAPHORE ( 3U )
\r
99 #define queueQUEUE_TYPE_RECURSIVE_MUTEX ( 4U )
\r
104 xQueueHandle xQueueCreate(
\r
105 unsigned portBASE_TYPE uxQueueLength,
\r
106 unsigned portBASE_TYPE uxItemSize
\r
110 * Creates a new queue instance. This allocates the storage required by the
\r
111 * new queue and returns a handle for the queue.
\r
113 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
115 * @param uxItemSize The number of bytes each item in the queue will require.
\r
116 * Items are queued by copy, not by reference, so this is the number of bytes
\r
117 * that will be copied for each posted item. Each item on the queue must be
\r
120 * @return If the queue is successfully create then a handle to the newly
\r
121 * created queue is returned. If the queue cannot be created then 0 is
\r
132 void vATask( void *pvParameters )
\r
134 xQueueHandle xQueue1, xQueue2;
\r
136 // Create a queue capable of containing 10 unsigned long values.
\r
137 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
140 // Queue was not created and must not be used.
\r
143 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
144 // These should be passed by pointer as they contain a lot of data.
\r
145 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
148 // Queue was not created and must not be used.
\r
151 // ... Rest of task code.
\r
154 * \defgroup xQueueCreate xQueueCreate
\r
155 * \ingroup QueueManagement
\r
157 #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( uxQueueLength, uxItemSize, queueQUEUE_TYPE_BASE )
\r
162 portBASE_TYPE xQueueSendToToFront(
\r
163 xQueueHandle xQueue,
\r
164 const void * pvItemToQueue,
\r
165 portTickType xTicksToWait
\r
169 * This is a macro that calls xQueueGenericSend().
\r
171 * Post an item to the front of a queue. The item is queued by copy, not by
\r
172 * reference. This function must not be called from an interrupt service
\r
173 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
176 * @param xQueue The handle to the queue on which the item is to be posted.
\r
178 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
179 * queue. The size of the items the queue will hold was defined when the
\r
180 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
181 * into the queue storage area.
\r
183 * @param xTicksToWait The maximum amount of time the task should block
\r
184 * waiting for space to become available on the queue, should it already
\r
185 * be full. The call will return immediately if this is set to 0 and the
\r
186 * queue is full. The time is defined in tick periods so the constant
\r
187 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
189 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
199 unsigned long ulVar = 10UL;
\r
201 void vATask( void *pvParameters )
\r
203 xQueueHandle xQueue1, xQueue2;
\r
204 struct AMessage *pxMessage;
\r
206 // Create a queue capable of containing 10 unsigned long values.
\r
207 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
209 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
210 // These should be passed by pointer as they contain a lot of data.
\r
211 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
217 // Send an unsigned long. Wait for 10 ticks for space to become
\r
218 // available if necessary.
\r
219 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
221 // Failed to post the message, even after 10 ticks.
\r
227 // Send a pointer to a struct AMessage object. Don't block if the
\r
228 // queue is already full.
\r
229 pxMessage = & xMessage;
\r
230 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
233 // ... Rest of task code.
\r
236 * \defgroup xQueueSend xQueueSend
\r
237 * \ingroup QueueManagement
\r
239 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
\r
244 portBASE_TYPE xQueueSendToBack(
\r
245 xQueueHandle xQueue,
\r
246 const void * pvItemToQueue,
\r
247 portTickType xTicksToWait
\r
251 * This is a macro that calls xQueueGenericSend().
\r
253 * Post an item to the back of a queue. The item is queued by copy, not by
\r
254 * reference. This function must not be called from an interrupt service
\r
255 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
258 * @param xQueue The handle to the queue on which the item is to be posted.
\r
260 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
261 * queue. The size of the items the queue will hold was defined when the
\r
262 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
263 * into the queue storage area.
\r
265 * @param xTicksToWait The maximum amount of time the task should block
\r
266 * waiting for space to become available on the queue, should it already
\r
267 * be full. The call will return immediately if this is set to 0 and the queue
\r
268 * is full. The time is defined in tick periods so the constant
\r
269 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
271 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
281 unsigned long ulVar = 10UL;
\r
283 void vATask( void *pvParameters )
\r
285 xQueueHandle xQueue1, xQueue2;
\r
286 struct AMessage *pxMessage;
\r
288 // Create a queue capable of containing 10 unsigned long values.
\r
289 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
291 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
292 // These should be passed by pointer as they contain a lot of data.
\r
293 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
299 // Send an unsigned long. Wait for 10 ticks for space to become
\r
300 // available if necessary.
\r
301 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
303 // Failed to post the message, even after 10 ticks.
\r
309 // Send a pointer to a struct AMessage object. Don't block if the
\r
310 // queue is already full.
\r
311 pxMessage = & xMessage;
\r
312 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
315 // ... Rest of task code.
\r
318 * \defgroup xQueueSend xQueueSend
\r
319 * \ingroup QueueManagement
\r
321 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
\r
326 portBASE_TYPE xQueueSend(
\r
327 xQueueHandle xQueue,
\r
328 const void * pvItemToQueue,
\r
329 portTickType xTicksToWait
\r
333 * This is a macro that calls xQueueGenericSend(). It is included for
\r
334 * backward compatibility with versions of FreeRTOS.org that did not
\r
335 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
336 * equivalent to xQueueSendToBack().
\r
338 * Post an item on a queue. The item is queued by copy, not by reference.
\r
339 * This function must not be called from an interrupt service routine.
\r
340 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
342 * @param xQueue The handle to the queue on which the item is to be posted.
\r
344 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
345 * queue. The size of the items the queue will hold was defined when the
\r
346 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
347 * into the queue storage area.
\r
349 * @param xTicksToWait The maximum amount of time the task should block
\r
350 * waiting for space to become available on the queue, should it already
\r
351 * be full. The call will return immediately if this is set to 0 and the
\r
352 * queue is full. The time is defined in tick periods so the constant
\r
353 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
355 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
365 unsigned long ulVar = 10UL;
\r
367 void vATask( void *pvParameters )
\r
369 xQueueHandle xQueue1, xQueue2;
\r
370 struct AMessage *pxMessage;
\r
372 // Create a queue capable of containing 10 unsigned long values.
\r
373 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
375 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
376 // These should be passed by pointer as they contain a lot of data.
\r
377 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
383 // Send an unsigned long. Wait for 10 ticks for space to become
\r
384 // available if necessary.
\r
385 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
387 // Failed to post the message, even after 10 ticks.
\r
393 // Send a pointer to a struct AMessage object. Don't block if the
\r
394 // queue is already full.
\r
395 pxMessage = & xMessage;
\r
396 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
399 // ... Rest of task code.
\r
402 * \defgroup xQueueSend xQueueSend
\r
403 * \ingroup QueueManagement
\r
405 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
\r
411 portBASE_TYPE xQueueGenericSend(
\r
412 xQueueHandle xQueue,
\r
413 const void * pvItemToQueue,
\r
414 portTickType xTicksToWait
\r
415 portBASE_TYPE xCopyPosition
\r
419 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
420 * xQueueSendToBack() are used in place of calling this function directly.
\r
422 * Post an item on a queue. The item is queued by copy, not by reference.
\r
423 * This function must not be called from an interrupt service routine.
\r
424 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
426 * @param xQueue The handle to the queue on which the item is to be posted.
\r
428 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
429 * queue. The size of the items the queue will hold was defined when the
\r
430 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
431 * into the queue storage area.
\r
433 * @param xTicksToWait The maximum amount of time the task should block
\r
434 * waiting for space to become available on the queue, should it already
\r
435 * be full. The call will return immediately if this is set to 0 and the
\r
436 * queue is full. The time is defined in tick periods so the constant
\r
437 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
439 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
440 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
441 * at the front of the queue (for high priority messages).
\r
443 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
453 unsigned long ulVar = 10UL;
\r
455 void vATask( void *pvParameters )
\r
457 xQueueHandle xQueue1, xQueue2;
\r
458 struct AMessage *pxMessage;
\r
460 // Create a queue capable of containing 10 unsigned long values.
\r
461 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
463 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
464 // These should be passed by pointer as they contain a lot of data.
\r
465 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
471 // Send an unsigned long. Wait for 10 ticks for space to become
\r
472 // available if necessary.
\r
473 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
475 // Failed to post the message, even after 10 ticks.
\r
481 // Send a pointer to a struct AMessage object. Don't block if the
\r
482 // queue is already full.
\r
483 pxMessage = & xMessage;
\r
484 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
487 // ... Rest of task code.
\r
490 * \defgroup xQueueSend xQueueSend
\r
491 * \ingroup QueueManagement
\r
493 signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
498 portBASE_TYPE xQueuePeek(
\r
499 xQueueHandle xQueue,
\r
501 portTickType xTicksToWait
\r
504 * This is a macro that calls the xQueueGenericReceive() function.
\r
506 * Receive an item from a queue without removing the item from the queue.
\r
507 * The item is received by copy so a buffer of adequate size must be
\r
508 * provided. The number of bytes copied into the buffer was defined when
\r
509 * the queue was created.
\r
511 * Successfully received items remain on the queue so will be returned again
\r
512 * by the next call, or a call to xQueueReceive().
\r
514 * This macro must not be used in an interrupt service routine.
\r
516 * @param pxQueue The handle to the queue from which the item is to be
\r
519 * @param pvBuffer Pointer to the buffer into which the received item will
\r
522 * @param xTicksToWait The maximum amount of time the task should block
\r
523 * waiting for an item to receive should the queue be empty at the time
\r
524 * of the call. The time is defined in tick periods so the constant
\r
525 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
526 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
\r
529 * @return pdTRUE if an item was successfully received from the queue,
\r
530 * otherwise pdFALSE.
\r
540 xQueueHandle xQueue;
\r
542 // Task to create a queue and post a value.
\r
543 void vATask( void *pvParameters )
\r
545 struct AMessage *pxMessage;
\r
547 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
548 // These should be passed by pointer as they contain a lot of data.
\r
549 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
552 // Failed to create the queue.
\r
557 // Send a pointer to a struct AMessage object. Don't block if the
\r
558 // queue is already full.
\r
559 pxMessage = & xMessage;
\r
560 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
562 // ... Rest of task code.
\r
565 // Task to peek the data from the queue.
\r
566 void vADifferentTask( void *pvParameters )
\r
568 struct AMessage *pxRxedMessage;
\r
572 // Peek a message on the created queue. Block for 10 ticks if a
\r
573 // message is not immediately available.
\r
574 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
576 // pcRxedMessage now points to the struct AMessage variable posted
\r
577 // by vATask, but the item still remains on the queue.
\r
581 // ... Rest of task code.
\r
584 * \defgroup xQueueReceive xQueueReceive
\r
585 * \ingroup QueueManagement
\r
587 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
\r
592 portBASE_TYPE xQueueReceive(
\r
593 xQueueHandle xQueue,
\r
595 portTickType xTicksToWait
\r
598 * This is a macro that calls the xQueueGenericReceive() function.
\r
600 * Receive an item from a queue. The item is received by copy so a buffer of
\r
601 * adequate size must be provided. The number of bytes copied into the buffer
\r
602 * was defined when the queue was created.
\r
604 * Successfully received items are removed from the queue.
\r
606 * This function must not be used in an interrupt service routine. See
\r
607 * xQueueReceiveFromISR for an alternative that can.
\r
609 * @param pxQueue The handle to the queue from which the item is to be
\r
612 * @param pvBuffer Pointer to the buffer into which the received item will
\r
615 * @param xTicksToWait The maximum amount of time the task should block
\r
616 * waiting for an item to receive should the queue be empty at the time
\r
617 * of the call. xQueueReceive() will return immediately if xTicksToWait
\r
618 * is zero and the queue is empty. The time is defined in tick periods so the
\r
619 * constant portTICK_RATE_MS should be used to convert to real time if this is
\r
622 * @return pdTRUE if an item was successfully received from the queue,
\r
623 * otherwise pdFALSE.
\r
633 xQueueHandle xQueue;
\r
635 // Task to create a queue and post a value.
\r
636 void vATask( void *pvParameters )
\r
638 struct AMessage *pxMessage;
\r
640 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
641 // These should be passed by pointer as they contain a lot of data.
\r
642 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
645 // Failed to create the queue.
\r
650 // Send a pointer to a struct AMessage object. Don't block if the
\r
651 // queue is already full.
\r
652 pxMessage = & xMessage;
\r
653 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
655 // ... Rest of task code.
\r
658 // Task to receive from the queue.
\r
659 void vADifferentTask( void *pvParameters )
\r
661 struct AMessage *pxRxedMessage;
\r
665 // Receive a message on the created queue. Block for 10 ticks if a
\r
666 // message is not immediately available.
\r
667 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
669 // pcRxedMessage now points to the struct AMessage variable posted
\r
674 // ... Rest of task code.
\r
677 * \defgroup xQueueReceive xQueueReceive
\r
678 * \ingroup QueueManagement
\r
680 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
\r
686 portBASE_TYPE xQueueGenericReceive(
\r
687 xQueueHandle xQueue,
\r
689 portTickType xTicksToWait
\r
690 portBASE_TYPE xJustPeek
\r
693 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
694 * this function directly.
\r
696 * Receive an item from a queue. The item is received by copy so a buffer of
\r
697 * adequate size must be provided. The number of bytes copied into the buffer
\r
698 * was defined when the queue was created.
\r
700 * This function must not be used in an interrupt service routine. See
\r
701 * xQueueReceiveFromISR for an alternative that can.
\r
703 * @param pxQueue The handle to the queue from which the item is to be
\r
706 * @param pvBuffer Pointer to the buffer into which the received item will
\r
709 * @param xTicksToWait The maximum amount of time the task should block
\r
710 * waiting for an item to receive should the queue be empty at the time
\r
711 * of the call. The time is defined in tick periods so the constant
\r
712 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
713 * xQueueGenericReceive() will return immediately if the queue is empty and
\r
714 * xTicksToWait is 0.
\r
716 * @param xJustPeek When set to true, the item received from the queue is not
\r
717 * actually removed from the queue - meaning a subsequent call to
\r
718 * xQueueReceive() will return the same item. When set to false, the item
\r
719 * being received from the queue is also removed from the queue.
\r
721 * @return pdTRUE if an item was successfully received from the queue,
\r
722 * otherwise pdFALSE.
\r
732 xQueueHandle xQueue;
\r
734 // Task to create a queue and post a value.
\r
735 void vATask( void *pvParameters )
\r
737 struct AMessage *pxMessage;
\r
739 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
740 // These should be passed by pointer as they contain a lot of data.
\r
741 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
744 // Failed to create the queue.
\r
749 // Send a pointer to a struct AMessage object. Don't block if the
\r
750 // queue is already full.
\r
751 pxMessage = & xMessage;
\r
752 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
754 // ... Rest of task code.
\r
757 // Task to receive from the queue.
\r
758 void vADifferentTask( void *pvParameters )
\r
760 struct AMessage *pxRxedMessage;
\r
764 // Receive a message on the created queue. Block for 10 ticks if a
\r
765 // message is not immediately available.
\r
766 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
768 // pcRxedMessage now points to the struct AMessage variable posted
\r
773 // ... Rest of task code.
\r
776 * \defgroup xQueueReceive xQueueReceive
\r
777 * \ingroup QueueManagement
\r
779 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
783 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
785 * Return the number of messages stored in a queue.
\r
787 * @param xQueue A handle to the queue being queried.
\r
789 * @return The number of messages available in the queue.
\r
791 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
792 * \ingroup QueueManagement
\r
794 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
798 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
800 * Delete a queue - freeing all the memory allocated for storing of items
\r
801 * placed on the queue.
\r
803 * @param xQueue A handle to the queue to be deleted.
\r
805 * \page vQueueDelete vQueueDelete
\r
806 * \ingroup QueueManagement
\r
808 void vQueueDelete( xQueueHandle pxQueue );
\r
813 portBASE_TYPE xQueueSendToFrontFromISR(
\r
814 xQueueHandle pxQueue,
\r
815 const void *pvItemToQueue,
\r
816 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
820 * This is a macro that calls xQueueGenericSendFromISR().
\r
822 * Post an item to the front of a queue. It is safe to use this macro from
\r
823 * within an interrupt service routine.
\r
825 * Items are queued by copy not reference so it is preferable to only
\r
826 * queue small items, especially when called from an ISR. In most cases
\r
827 * it would be preferable to store a pointer to the item being queued.
\r
829 * @param xQueue The handle to the queue on which the item is to be posted.
\r
831 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
832 * queue. The size of the items the queue will hold was defined when the
\r
833 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
834 * into the queue storage area.
\r
836 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
\r
837 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
838 * to unblock, and the unblocked task has a priority higher than the currently
\r
839 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
\r
840 * a context switch should be requested before the interrupt is exited.
\r
842 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
845 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
848 void vBufferISR( void )
\r
851 portBASE_TYPE xHigherPrioritTaskWoken;
\r
853 // We have not woken a task at the start of the ISR.
\r
854 xHigherPriorityTaskWoken = pdFALSE;
\r
856 // Loop until the buffer is empty.
\r
859 // Obtain a byte from the buffer.
\r
860 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
863 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
865 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
867 // Now the buffer is empty we can switch context if necessary.
\r
868 if( xHigherPriorityTaskWoken )
\r
875 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
876 * \ingroup QueueManagement
\r
878 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
\r
884 portBASE_TYPE xQueueSendToBackFromISR(
\r
885 xQueueHandle pxQueue,
\r
886 const void *pvItemToQueue,
\r
887 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
891 * This is a macro that calls xQueueGenericSendFromISR().
\r
893 * Post an item to the back of a queue. It is safe to use this macro from
\r
894 * within an interrupt service routine.
\r
896 * Items are queued by copy not reference so it is preferable to only
\r
897 * queue small items, especially when called from an ISR. In most cases
\r
898 * it would be preferable to store a pointer to the item being queued.
\r
900 * @param xQueue The handle to the queue on which the item is to be posted.
\r
902 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
903 * queue. The size of the items the queue will hold was defined when the
\r
904 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
905 * into the queue storage area.
\r
907 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
\r
908 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
909 * to unblock, and the unblocked task has a priority higher than the currently
\r
910 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
\r
911 * a context switch should be requested before the interrupt is exited.
\r
913 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
916 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
919 void vBufferISR( void )
\r
922 portBASE_TYPE xHigherPriorityTaskWoken;
\r
924 // We have not woken a task at the start of the ISR.
\r
925 xHigherPriorityTaskWoken = pdFALSE;
\r
927 // Loop until the buffer is empty.
\r
930 // Obtain a byte from the buffer.
\r
931 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
934 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
936 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
938 // Now the buffer is empty we can switch context if necessary.
\r
939 if( xHigherPriorityTaskWoken )
\r
946 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
947 * \ingroup QueueManagement
\r
949 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
\r
954 portBASE_TYPE xQueueSendFromISR(
\r
955 xQueueHandle pxQueue,
\r
956 const void *pvItemToQueue,
\r
957 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
961 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
962 * for backward compatibility with versions of FreeRTOS.org that did not
\r
963 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
966 * Post an item to the back of a queue. It is safe to use this function from
\r
967 * within an interrupt service routine.
\r
969 * Items are queued by copy not reference so it is preferable to only
\r
970 * queue small items, especially when called from an ISR. In most cases
\r
971 * it would be preferable to store a pointer to the item being queued.
\r
973 * @param xQueue The handle to the queue on which the item is to be posted.
\r
975 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
976 * queue. The size of the items the queue will hold was defined when the
\r
977 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
978 * into the queue storage area.
\r
980 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
\r
981 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
982 * to unblock, and the unblocked task has a priority higher than the currently
\r
983 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
984 * a context switch should be requested before the interrupt is exited.
\r
986 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
989 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
992 void vBufferISR( void )
\r
995 portBASE_TYPE xHigherPriorityTaskWoken;
\r
997 // We have not woken a task at the start of the ISR.
\r
998 xHigherPriorityTaskWoken = pdFALSE;
\r
1000 // Loop until the buffer is empty.
\r
1003 // Obtain a byte from the buffer.
\r
1004 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1007 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
1009 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1011 // Now the buffer is empty we can switch context if necessary.
\r
1012 if( xHigherPriorityTaskWoken )
\r
1014 // Actual macro used here is port specific.
\r
1015 taskYIELD_FROM_ISR ();
\r
1020 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1021 * \ingroup QueueManagement
\r
1023 #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
\r
1028 portBASE_TYPE xQueueGenericSendFromISR(
\r
1029 xQueueHandle pxQueue,
\r
1030 const void *pvItemToQueue,
\r
1031 portBASE_TYPE *pxHigherPriorityTaskWoken,
\r
1032 portBASE_TYPE xCopyPosition
\r
1036 * It is preferred that the macros xQueueSendFromISR(),
\r
1037 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1038 * of calling this function directly.
\r
1040 * Post an item on a queue. It is safe to use this function from within an
\r
1041 * interrupt service routine.
\r
1043 * Items are queued by copy not reference so it is preferable to only
\r
1044 * queue small items, especially when called from an ISR. In most cases
\r
1045 * it would be preferable to store a pointer to the item being queued.
\r
1047 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1049 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1050 * queue. The size of the items the queue will hold was defined when the
\r
1051 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1052 * into the queue storage area.
\r
1054 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
\r
1055 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1056 * to unblock, and the unblocked task has a priority higher than the currently
\r
1057 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
\r
1058 * a context switch should be requested before the interrupt is exited.
\r
1060 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1061 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1062 * at the front of the queue (for high priority messages).
\r
1064 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1067 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1070 void vBufferISR( void )
\r
1073 portBASE_TYPE xHigherPriorityTaskWokenByPost;
\r
1075 // We have not woken a task at the start of the ISR.
\r
1076 xHigherPriorityTaskWokenByPost = pdFALSE;
\r
1078 // Loop until the buffer is empty.
\r
1081 // Obtain a byte from the buffer.
\r
1082 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1084 // Post each byte.
\r
1085 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
\r
1087 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1089 // Now the buffer is empty we can switch context if necessary. Note that the
\r
1090 // name of the yield function required is port specific.
\r
1091 if( xHigherPriorityTaskWokenByPost )
\r
1093 taskYIELD_YIELD_FROM_ISR();
\r
1098 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1099 * \ingroup QueueManagement
\r
1101 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
\r
1106 portBASE_TYPE xQueueReceiveFromISR(
\r
1107 xQueueHandle pxQueue,
\r
1109 portBASE_TYPE *pxTaskWoken
\r
1113 * Receive an item from a queue. It is safe to use this function from within an
\r
1114 * interrupt service routine.
\r
1116 * @param pxQueue The handle to the queue from which the item is to be
\r
1119 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1122 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1123 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1124 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1125 * remain unchanged.
\r
1127 * @return pdTRUE if an item was successfully received from the queue,
\r
1128 * otherwise pdFALSE.
\r
1133 xQueueHandle xQueue;
\r
1135 // Function to create a queue and post some values.
\r
1136 void vAFunction( void *pvParameters )
\r
1138 char cValueToPost;
\r
1139 const portTickType xBlockTime = ( portTickType )0xff;
\r
1141 // Create a queue capable of containing 10 characters.
\r
1142 xQueue = xQueueCreate( 10, sizeof( char ) );
\r
1145 // Failed to create the queue.
\r
1150 // Post some characters that will be used within an ISR. If the queue
\r
1151 // is full then this task will block for xBlockTime ticks.
\r
1152 cValueToPost = 'a';
\r
1153 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1154 cValueToPost = 'b';
\r
1155 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1157 // ... keep posting characters ... this task may block when the queue
\r
1160 cValueToPost = 'c';
\r
1161 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1164 // ISR that outputs all the characters received on the queue.
\r
1165 void vISR_Routine( void )
\r
1167 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1170 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1172 // A character was received. Output the character now.
\r
1173 vOutputCharacter( cRxedChar );
\r
1175 // If removing the character from the queue woke the task that was
\r
1176 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1177 // pdTRUE. No matter how many times this loop iterates only one
\r
1178 // task will be woken.
\r
1181 if( cTaskWokenByPost != ( char ) pdFALSE;
\r
1187 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1188 * \ingroup QueueManagement
\r
1190 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken );
\r
1193 * Utilities to query queues that are safe to use from an ISR. These utilities
\r
1194 * should be used only from witin an ISR, or within a critical section.
\r
1196 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
\r
1197 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
\r
1198 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
\r
1202 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1203 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1204 * xQueueGenericReceive().
\r
1206 * The source code that implements the alternative (Alt) API is much
\r
1207 * simpler because it executes everything from within a critical section.
\r
1208 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1209 * preferred fully featured API too. The fully featured API has more
\r
1210 * complex code that takes longer to execute, but makes much less use of
\r
1211 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1212 * responsiveness to gain execution speed, whereas the fully featured API
\r
1213 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1215 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1216 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1217 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
\r
1218 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
\r
1219 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
\r
1220 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
\r
1223 * The functions defined above are for passing data to and from tasks. The
\r
1224 * functions below are the equivalents for passing data to and from
\r
1227 * These functions are called from the co-routine macro implementation and
\r
1228 * should not be called directly from application code. Instead use the macro
\r
1229 * wrappers defined within croutine.h.
\r
1231 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1232 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1233 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1234 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1237 * For internal use only. Use xSemaphoreCreateMutex(),
\r
1238 * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
\r
1239 * these functions directly.
\r
1241 xQueueHandle xQueueCreateMutex( unsigned char ucQueueType );
\r
1242 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1243 void* xQueueGetMutexHolder( xQueueHandle xSemaphore );
\r
1246 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1247 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1249 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime );
\r
1250 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex );
\r
1253 * Reset a queue back to its original empty state. pdPASS is returned if the
\r
1254 * queue is successfully reset. pdFAIL is returned if the queue could not be
\r
1255 * reset because there are tasks blocked on the queue waiting to either
\r
1256 * receive from the queue or send to the queue.
\r
1258 #define xQueueReset( pxQueue ) xQueueGenericReset( pxQueue, pdFALSE )
\r
1261 * The registry is provided as a means for kernel aware debuggers to
\r
1262 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
\r
1263 * a queue, semaphore or mutex handle to the registry if you want the handle
\r
1264 * to be available to a kernel aware debugger. If you are not using a kernel
\r
1265 * aware debugger then this function can be ignored.
\r
1267 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
\r
1268 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
\r
1269 * within FreeRTOSConfig.h for the registry to be available. Its value
\r
1270 * does not effect the number of queues, semaphores and mutexes that can be
\r
1271 * created - just the number that the registry can hold.
\r
1273 * @param xQueue The handle of the queue being added to the registry. This
\r
1274 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
\r
1275 * handles can also be passed in here.
\r
1277 * @param pcName The name to be associated with the handle. This is the
\r
1278 * name that the kernel aware debugger will display.
\r
1280 #if configQUEUE_REGISTRY_SIZE > 0U
\r
1281 void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcName );
\r
1285 * Generic version of the queue creation function, which is in turn called by
\r
1286 * any queue, semaphore or mutex creation function or macro.
\r
1288 xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType );
\r
1290 /* Not public API functions. */
\r
1291 void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait );
\r
1292 portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue );
\r
1295 #ifdef __cplusplus
\r
1299 #endif /* QUEUE_H */
\r