2 FreeRTOS V7.0.2 - Copyright (C) 2011 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 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
58 #ifndef INC_FREERTOS_H
\r
59 #error "#include FreeRTOS.h" must appear in source files before "#include queue.h"
\r
67 #include "os_mpu_wrappers.h"
\r
70 * Type by which queues are referenced. For example, a call to xQueueCreate
\r
71 * returns (via a pointer parameter) an xQueueHandle variable that can then
\r
72 * be used as a parameter to xQueueSend(), xQueueReceive(), etc.
\r
74 typedef void * xQueueHandle;
\r
77 /* For internal use only. */
\r
78 #define queueSEND_TO_BACK ( 0 )
\r
79 #define queueSEND_TO_FRONT ( 1 )
\r
85 xQueueHandle xQueueCreate(
\r
86 unsigned portBASE_TYPE uxQueueLength,
\r
87 unsigned portBASE_TYPE uxItemSize
\r
91 * Creates a new queue instance. This allocates the storage required by the
\r
92 * new queue and returns a handle for the queue.
\r
94 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
96 * @param uxItemSize The number of bytes each item in the queue will require.
\r
97 * Items are queued by copy, not by reference, so this is the number of bytes
\r
98 * that will be copied for each posted item. Each item on the queue must be
\r
101 * @return If the queue is successfully create then a handle to the newly
\r
102 * created queue is returned. If the queue cannot be created then 0 is
\r
113 void vATask( void *pvParameters )
\r
115 xQueueHandle xQueue1, xQueue2;
\r
117 // Create a queue capable of containing 10 unsigned long values.
\r
118 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
121 // Queue was not created and must not be used.
\r
124 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
125 // These should be passed by pointer as they contain a lot of data.
\r
126 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
129 // Queue was not created and must not be used.
\r
132 // ... Rest of task code.
\r
135 * \defgroup xQueueCreate xQueueCreate
\r
136 * \ingroup QueueManagement
\r
138 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
143 portBASE_TYPE xQueueSendToToFront(
\r
144 xQueueHandle xQueue,
\r
145 const void * pvItemToQueue,
\r
146 portTickType xTicksToWait
\r
150 * This is a macro that calls xQueueGenericSend().
\r
152 * Post an item to the front of a queue. The item is queued by copy, not by
\r
153 * reference. This function must not be called from an interrupt service
\r
154 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
157 * @param xQueue The handle to the queue on which the item is to be posted.
\r
159 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
160 * queue. The size of the items the queue will hold was defined when the
\r
161 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
162 * into the queue storage area.
\r
164 * @param xTicksToWait The maximum amount of time the task should block
\r
165 * waiting for space to become available on the queue, should it already
\r
166 * be full. The call will return immediately if this is set to 0 and the
\r
167 * queue is full. The time is defined in tick periods so the constant
\r
168 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
170 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
180 unsigned long ulVar = 10UL;
\r
182 void vATask( void *pvParameters )
\r
184 xQueueHandle xQueue1, xQueue2;
\r
185 struct AMessage *pxMessage;
\r
187 // Create a queue capable of containing 10 unsigned long values.
\r
188 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
190 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
191 // These should be passed by pointer as they contain a lot of data.
\r
192 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
198 // Send an unsigned long. Wait for 10 ticks for space to become
\r
199 // available if necessary.
\r
200 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
202 // Failed to post the message, even after 10 ticks.
\r
208 // Send a pointer to a struct AMessage object. Don't block if the
\r
209 // queue is already full.
\r
210 pxMessage = & xMessage;
\r
211 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
214 // ... Rest of task code.
\r
217 * \defgroup xQueueSend xQueueSend
\r
218 * \ingroup QueueManagement
\r
220 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
\r
225 portBASE_TYPE xQueueSendToBack(
\r
226 xQueueHandle xQueue,
\r
227 const void * pvItemToQueue,
\r
228 portTickType xTicksToWait
\r
232 * This is a macro that calls xQueueGenericSend().
\r
234 * Post an item to the back of a queue. The item is queued by copy, not by
\r
235 * reference. This function must not be called from an interrupt service
\r
236 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
239 * @param xQueue The handle to the queue on which the item is to be posted.
\r
241 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
242 * queue. The size of the items the queue will hold was defined when the
\r
243 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
244 * into the queue storage area.
\r
246 * @param xTicksToWait The maximum amount of time the task should block
\r
247 * waiting for space to become available on the queue, should it already
\r
248 * be full. The call will return immediately if this is set to 0 and the queue
\r
249 * is full. The time is defined in tick periods so the constant
\r
250 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
252 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
262 unsigned long ulVar = 10UL;
\r
264 void vATask( void *pvParameters )
\r
266 xQueueHandle xQueue1, xQueue2;
\r
267 struct AMessage *pxMessage;
\r
269 // Create a queue capable of containing 10 unsigned long values.
\r
270 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
272 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
273 // These should be passed by pointer as they contain a lot of data.
\r
274 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
280 // Send an unsigned long. Wait for 10 ticks for space to become
\r
281 // available if necessary.
\r
282 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
284 // Failed to post the message, even after 10 ticks.
\r
290 // Send a pointer to a struct AMessage object. Don't block if the
\r
291 // queue is already full.
\r
292 pxMessage = & xMessage;
\r
293 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
296 // ... Rest of task code.
\r
299 * \defgroup xQueueSend xQueueSend
\r
300 * \ingroup QueueManagement
\r
302 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
\r
307 portBASE_TYPE xQueueSend(
\r
308 xQueueHandle xQueue,
\r
309 const void * pvItemToQueue,
\r
310 portTickType xTicksToWait
\r
314 * This is a macro that calls xQueueGenericSend(). It is included for
\r
315 * backward compatibility with versions of FreeRTOS.org that did not
\r
316 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
317 * equivalent to xQueueSendToBack().
\r
319 * Post an item on a queue. The item is queued by copy, not by reference.
\r
320 * This function must not be called from an interrupt service routine.
\r
321 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
323 * @param xQueue The handle to the queue on which the item is to be posted.
\r
325 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
326 * queue. The size of the items the queue will hold was defined when the
\r
327 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
328 * into the queue storage area.
\r
330 * @param xTicksToWait The maximum amount of time the task should block
\r
331 * waiting for space to become available on the queue, should it already
\r
332 * be full. The call will return immediately if this is set to 0 and the
\r
333 * queue is full. The time is defined in tick periods so the constant
\r
334 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
336 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
346 unsigned long ulVar = 10UL;
\r
348 void vATask( void *pvParameters )
\r
350 xQueueHandle xQueue1, xQueue2;
\r
351 struct AMessage *pxMessage;
\r
353 // Create a queue capable of containing 10 unsigned long values.
\r
354 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
356 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
357 // These should be passed by pointer as they contain a lot of data.
\r
358 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
364 // Send an unsigned long. Wait for 10 ticks for space to become
\r
365 // available if necessary.
\r
366 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
368 // Failed to post the message, even after 10 ticks.
\r
374 // Send a pointer to a struct AMessage object. Don't block if the
\r
375 // queue is already full.
\r
376 pxMessage = & xMessage;
\r
377 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
380 // ... Rest of task code.
\r
383 * \defgroup xQueueSend xQueueSend
\r
384 * \ingroup QueueManagement
\r
386 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
\r
392 portBASE_TYPE xQueueGenericSend(
\r
393 xQueueHandle xQueue,
\r
394 const void * pvItemToQueue,
\r
395 portTickType xTicksToWait
\r
396 portBASE_TYPE xCopyPosition
\r
400 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
401 * xQueueSendToBack() are used in place of calling this function directly.
\r
403 * Post an item on a queue. The item is queued by copy, not by reference.
\r
404 * This function must not be called from an interrupt service routine.
\r
405 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
407 * @param xQueue The handle to the queue on which the item is to be posted.
\r
409 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
410 * queue. The size of the items the queue will hold was defined when the
\r
411 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
412 * into the queue storage area.
\r
414 * @param xTicksToWait The maximum amount of time the task should block
\r
415 * waiting for space to become available on the queue, should it already
\r
416 * be full. The call will return immediately if this is set to 0 and the
\r
417 * queue is full. The time is defined in tick periods so the constant
\r
418 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
420 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
421 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
422 * at the front of the queue (for high priority messages).
\r
424 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
434 unsigned long ulVar = 10UL;
\r
436 void vATask( void *pvParameters )
\r
438 xQueueHandle xQueue1, xQueue2;
\r
439 struct AMessage *pxMessage;
\r
441 // Create a queue capable of containing 10 unsigned long values.
\r
442 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
444 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
445 // These should be passed by pointer as they contain a lot of data.
\r
446 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
452 // Send an unsigned long. Wait for 10 ticks for space to become
\r
453 // available if necessary.
\r
454 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
456 // Failed to post the message, even after 10 ticks.
\r
462 // Send a pointer to a struct AMessage object. Don't block if the
\r
463 // queue is already full.
\r
464 pxMessage = & xMessage;
\r
465 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
468 // ... Rest of task code.
\r
471 * \defgroup xQueueSend xQueueSend
\r
472 * \ingroup QueueManagement
\r
474 signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
479 portBASE_TYPE xQueuePeek(
\r
480 xQueueHandle xQueue,
\r
482 portTickType xTicksToWait
\r
485 * This is a macro that calls the xQueueGenericReceive() function.
\r
487 * Receive an item from a queue without removing the item from the queue.
\r
488 * The item is received by copy so a buffer of adequate size must be
\r
489 * provided. The number of bytes copied into the buffer was defined when
\r
490 * the queue was created.
\r
492 * Successfully received items remain on the queue so will be returned again
\r
493 * by the next call, or a call to xQueueReceive().
\r
495 * This macro must not be used in an interrupt service routine.
\r
497 * @param pxQueue The handle to the queue from which the item is to be
\r
500 * @param pvBuffer Pointer to the buffer into which the received item will
\r
503 * @param xTicksToWait The maximum amount of time the task should block
\r
504 * waiting for an item to receive should the queue be empty at the time
\r
505 * of the call. The time is defined in tick periods so the constant
\r
506 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
507 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
\r
510 * @return pdTRUE if an item was successfully received from the queue,
\r
511 * otherwise pdFALSE.
\r
521 xQueueHandle xQueue;
\r
523 // Task to create a queue and post a value.
\r
524 void vATask( void *pvParameters )
\r
526 struct AMessage *pxMessage;
\r
528 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
529 // These should be passed by pointer as they contain a lot of data.
\r
530 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
533 // Failed to create the queue.
\r
538 // Send a pointer to a struct AMessage object. Don't block if the
\r
539 // queue is already full.
\r
540 pxMessage = & xMessage;
\r
541 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
543 // ... Rest of task code.
\r
546 // Task to peek the data from the queue.
\r
547 void vADifferentTask( void *pvParameters )
\r
549 struct AMessage *pxRxedMessage;
\r
553 // Peek a message on the created queue. Block for 10 ticks if a
\r
554 // message is not immediately available.
\r
555 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
557 // pcRxedMessage now points to the struct AMessage variable posted
\r
558 // by vATask, but the item still remains on the queue.
\r
562 // ... Rest of task code.
\r
565 * \defgroup xQueueReceive xQueueReceive
\r
566 * \ingroup QueueManagement
\r
568 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
\r
573 portBASE_TYPE xQueueReceive(
\r
574 xQueueHandle xQueue,
\r
576 portTickType xTicksToWait
\r
579 * This is a macro that calls the xQueueGenericReceive() function.
\r
581 * Receive an item from a queue. The item is received by copy so a buffer of
\r
582 * adequate size must be provided. The number of bytes copied into the buffer
\r
583 * was defined when the queue was created.
\r
585 * Successfully received items are removed from the queue.
\r
587 * This function must not be used in an interrupt service routine. See
\r
588 * xQueueReceiveFromISR for an alternative that can.
\r
590 * @param pxQueue The handle to the queue from which the item is to be
\r
593 * @param pvBuffer Pointer to the buffer into which the received item will
\r
596 * @param xTicksToWait The maximum amount of time the task should block
\r
597 * waiting for an item to receive should the queue be empty at the time
\r
598 * of the call. xQueueReceive() will return immediately if xTicksToWait
\r
599 * is zero and the queue is empty. The time is defined in tick periods so the
\r
600 * constant portTICK_RATE_MS should be used to convert to real time if this is
\r
603 * @return pdTRUE if an item was successfully received from the queue,
\r
604 * otherwise pdFALSE.
\r
614 xQueueHandle xQueue;
\r
616 // Task to create a queue and post a value.
\r
617 void vATask( void *pvParameters )
\r
619 struct AMessage *pxMessage;
\r
621 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
622 // These should be passed by pointer as they contain a lot of data.
\r
623 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
626 // Failed to create the queue.
\r
631 // Send a pointer to a struct AMessage object. Don't block if the
\r
632 // queue is already full.
\r
633 pxMessage = & xMessage;
\r
634 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
636 // ... Rest of task code.
\r
639 // Task to receive from the queue.
\r
640 void vADifferentTask( void *pvParameters )
\r
642 struct AMessage *pxRxedMessage;
\r
646 // Receive a message on the created queue. Block for 10 ticks if a
\r
647 // message is not immediately available.
\r
648 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
650 // pcRxedMessage now points to the struct AMessage variable posted
\r
655 // ... Rest of task code.
\r
658 * \defgroup xQueueReceive xQueueReceive
\r
659 * \ingroup QueueManagement
\r
661 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
\r
667 portBASE_TYPE xQueueGenericReceive(
\r
668 xQueueHandle xQueue,
\r
670 portTickType xTicksToWait
\r
671 portBASE_TYPE xJustPeek
\r
674 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
675 * this function directly.
\r
677 * Receive an item from a queue. The item is received by copy so a buffer of
\r
678 * adequate size must be provided. The number of bytes copied into the buffer
\r
679 * was defined when the queue was created.
\r
681 * This function must not be used in an interrupt service routine. See
\r
682 * xQueueReceiveFromISR for an alternative that can.
\r
684 * @param pxQueue The handle to the queue from which the item is to be
\r
687 * @param pvBuffer Pointer to the buffer into which the received item will
\r
690 * @param xTicksToWait The maximum amount of time the task should block
\r
691 * waiting for an item to receive should the queue be empty at the time
\r
692 * of the call. The time is defined in tick periods so the constant
\r
693 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
694 * xQueueGenericReceive() will return immediately if the queue is empty and
\r
695 * xTicksToWait is 0.
\r
697 * @param xJustPeek When set to true, the item received from the queue is not
\r
698 * actually removed from the queue - meaning a subsequent call to
\r
699 * xQueueReceive() will return the same item. When set to false, the item
\r
700 * being received from the queue is also removed from the queue.
\r
702 * @return pdTRUE if an item was successfully received from the queue,
\r
703 * otherwise pdFALSE.
\r
713 xQueueHandle xQueue;
\r
715 // Task to create a queue and post a value.
\r
716 void vATask( void *pvParameters )
\r
718 struct AMessage *pxMessage;
\r
720 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
721 // These should be passed by pointer as they contain a lot of data.
\r
722 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
725 // Failed to create the queue.
\r
730 // Send a pointer to a struct AMessage object. Don't block if the
\r
731 // queue is already full.
\r
732 pxMessage = & xMessage;
\r
733 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
735 // ... Rest of task code.
\r
738 // Task to receive from the queue.
\r
739 void vADifferentTask( void *pvParameters )
\r
741 struct AMessage *pxRxedMessage;
\r
745 // Receive a message on the created queue. Block for 10 ticks if a
\r
746 // message is not immediately available.
\r
747 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
749 // pcRxedMessage now points to the struct AMessage variable posted
\r
754 // ... Rest of task code.
\r
757 * \defgroup xQueueReceive xQueueReceive
\r
758 * \ingroup QueueManagement
\r
760 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
764 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
766 * Return the number of messages stored in a queue.
\r
768 * @param xQueue A handle to the queue being queried.
\r
770 * @return The number of messages available in the queue.
\r
772 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
773 * \ingroup QueueManagement
\r
775 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
779 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
781 * Delete a queue - freeing all the memory allocated for storing of items
\r
782 * placed on the queue.
\r
784 * @param xQueue A handle to the queue to be deleted.
\r
786 * \page vQueueDelete vQueueDelete
\r
787 * \ingroup QueueManagement
\r
789 void vQueueDelete( xQueueHandle pxQueue );
\r
794 portBASE_TYPE xQueueSendToFrontFromISR(
\r
795 xQueueHandle pxQueue,
\r
796 const void *pvItemToQueue,
\r
797 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
801 * This is a macro that calls xQueueGenericSendFromISR().
\r
803 * Post an item to the front of a queue. It is safe to use this macro from
\r
804 * within an interrupt service routine.
\r
806 * Items are queued by copy not reference so it is preferable to only
\r
807 * queue small items, especially when called from an ISR. In most cases
\r
808 * it would be preferable to store a pointer to the item being queued.
\r
810 * @param xQueue The handle to the queue on which the item is to be posted.
\r
812 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
813 * queue. The size of the items the queue will hold was defined when the
\r
814 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
815 * into the queue storage area.
\r
817 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
\r
818 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
819 * to unblock, and the unblocked task has a priority higher than the currently
\r
820 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
\r
821 * a context switch should be requested before the interrupt is exited.
\r
823 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
826 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
829 void vBufferISR( void )
\r
832 portBASE_TYPE xHigherPrioritTaskWoken;
\r
834 // We have not woken a task at the start of the ISR.
\r
835 xHigherPriorityTaskWoken = pdFALSE;
\r
837 // Loop until the buffer is empty.
\r
840 // Obtain a byte from the buffer.
\r
841 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
844 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
846 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
848 // Now the buffer is empty we can switch context if necessary.
\r
849 if( xHigherPriorityTaskWoken )
\r
856 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
857 * \ingroup QueueManagement
\r
859 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
\r
865 portBASE_TYPE xQueueSendToBackFromISR(
\r
866 xQueueHandle pxQueue,
\r
867 const void *pvItemToQueue,
\r
868 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
872 * This is a macro that calls xQueueGenericSendFromISR().
\r
874 * Post an item to the back of a queue. It is safe to use this macro from
\r
875 * within an interrupt service routine.
\r
877 * Items are queued by copy not reference so it is preferable to only
\r
878 * queue small items, especially when called from an ISR. In most cases
\r
879 * it would be preferable to store a pointer to the item being queued.
\r
881 * @param xQueue The handle to the queue on which the item is to be posted.
\r
883 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
884 * queue. The size of the items the queue will hold was defined when the
\r
885 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
886 * into the queue storage area.
\r
888 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
\r
889 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
890 * to unblock, and the unblocked task has a priority higher than the currently
\r
891 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
\r
892 * a context switch should be requested before the interrupt is exited.
\r
894 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
897 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
900 void vBufferISR( void )
\r
903 portBASE_TYPE xHigherPriorityTaskWoken;
\r
905 // We have not woken a task at the start of the ISR.
\r
906 xHigherPriorityTaskWoken = pdFALSE;
\r
908 // Loop until the buffer is empty.
\r
911 // Obtain a byte from the buffer.
\r
912 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
915 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
917 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
919 // Now the buffer is empty we can switch context if necessary.
\r
920 if( xHigherPriorityTaskWoken )
\r
927 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
928 * \ingroup QueueManagement
\r
930 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
\r
935 portBASE_TYPE xQueueSendFromISR(
\r
936 xQueueHandle pxQueue,
\r
937 const void *pvItemToQueue,
\r
938 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
942 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
943 * for backward compatibility with versions of FreeRTOS.org that did not
\r
944 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
947 * Post an item to the back of a queue. It is safe to use this function from
\r
948 * within an interrupt service routine.
\r
950 * Items are queued by copy not reference so it is preferable to only
\r
951 * queue small items, especially when called from an ISR. In most cases
\r
952 * it would be preferable to store a pointer to the item being queued.
\r
954 * @param xQueue The handle to the queue on which the item is to be posted.
\r
956 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
957 * queue. The size of the items the queue will hold was defined when the
\r
958 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
959 * into the queue storage area.
\r
961 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
\r
962 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
963 * to unblock, and the unblocked task has a priority higher than the currently
\r
964 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
965 * a context switch should be requested before the interrupt is exited.
\r
967 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
970 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
973 void vBufferISR( void )
\r
976 portBASE_TYPE xHigherPriorityTaskWoken;
\r
978 // We have not woken a task at the start of the ISR.
\r
979 xHigherPriorityTaskWoken = pdFALSE;
\r
981 // Loop until the buffer is empty.
\r
984 // Obtain a byte from the buffer.
\r
985 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
988 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
990 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
992 // Now the buffer is empty we can switch context if necessary.
\r
993 if( xHigherPriorityTaskWoken )
\r
995 // Actual macro used here is port specific.
\r
996 taskYIELD_FROM_ISR ();
\r
1001 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1002 * \ingroup QueueManagement
\r
1004 #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
\r
1009 portBASE_TYPE xQueueGenericSendFromISR(
\r
1010 xQueueHandle pxQueue,
\r
1011 const void *pvItemToQueue,
\r
1012 portBASE_TYPE *pxHigherPriorityTaskWoken,
\r
1013 portBASE_TYPE xCopyPosition
\r
1017 * It is preferred that the macros xQueueSendFromISR(),
\r
1018 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1019 * of calling this function directly.
\r
1021 * Post an item on a queue. It is safe to use this function from within an
\r
1022 * interrupt service routine.
\r
1024 * Items are queued by copy not reference so it is preferable to only
\r
1025 * queue small items, especially when called from an ISR. In most cases
\r
1026 * it would be preferable to store a pointer to the item being queued.
\r
1028 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1030 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1031 * queue. The size of the items the queue will hold was defined when the
\r
1032 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1033 * into the queue storage area.
\r
1035 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
\r
1036 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1037 * to unblock, and the unblocked task has a priority higher than the currently
\r
1038 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
\r
1039 * a context switch should be requested before the interrupt is exited.
\r
1041 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1042 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1043 * at the front of the queue (for high priority messages).
\r
1045 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1048 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1051 void vBufferISR( void )
\r
1054 portBASE_TYPE xHigherPriorityTaskWokenByPost;
\r
1056 // We have not woken a task at the start of the ISR.
\r
1057 xHigherPriorityTaskWokenByPost = pdFALSE;
\r
1059 // Loop until the buffer is empty.
\r
1062 // Obtain a byte from the buffer.
\r
1063 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1065 // Post each byte.
\r
1066 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
\r
1068 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1070 // Now the buffer is empty we can switch context if necessary. Note that the
\r
1071 // name of the yield function required is port specific.
\r
1072 if( xHigherPriorityTaskWokenByPost )
\r
1074 taskYIELD_YIELD_FROM_ISR();
\r
1079 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1080 * \ingroup QueueManagement
\r
1082 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
\r
1087 portBASE_TYPE xQueueReceiveFromISR(
\r
1088 xQueueHandle pxQueue,
\r
1090 portBASE_TYPE *pxTaskWoken
\r
1094 * Receive an item from a queue. It is safe to use this function from within an
\r
1095 * interrupt service routine.
\r
1097 * @param pxQueue The handle to the queue from which the item is to be
\r
1100 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1103 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1104 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1105 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1106 * remain unchanged.
\r
1108 * @return pdTRUE if an item was successfully received from the queue,
\r
1109 * otherwise pdFALSE.
\r
1114 xQueueHandle xQueue;
\r
1116 // Function to create a queue and post some values.
\r
1117 void vAFunction( void *pvParameters )
\r
1119 char cValueToPost;
\r
1120 const portTickType xBlockTime = ( portTickType )0xff;
\r
1122 // Create a queue capable of containing 10 characters.
\r
1123 xQueue = xQueueCreate( 10, sizeof( char ) );
\r
1126 // Failed to create the queue.
\r
1131 // Post some characters that will be used within an ISR. If the queue
\r
1132 // is full then this task will block for xBlockTime ticks.
\r
1133 cValueToPost = 'a';
\r
1134 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1135 cValueToPost = 'b';
\r
1136 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1138 // ... keep posting characters ... this task may block when the queue
\r
1141 cValueToPost = 'c';
\r
1142 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1145 // ISR that outputs all the characters received on the queue.
\r
1146 void vISR_Routine( void )
\r
1148 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1151 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1153 // A character was received. Output the character now.
\r
1154 vOutputCharacter( cRxedChar );
\r
1156 // If removing the character from the queue woke the task that was
\r
1157 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1158 // pdTRUE. No matter how many times this loop iterates only one
\r
1159 // task will be woken.
\r
1162 if( cTaskWokenByPost != ( char ) pdFALSE;
\r
1168 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1169 * \ingroup QueueManagement
\r
1171 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1174 * Utilities to query queue that are safe to use from an ISR. These utilities
\r
1175 * should be used only from witin an ISR, or within a critical section.
\r
1177 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
\r
1178 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
\r
1179 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
\r
1183 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1184 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1185 * xQueueGenericReceive().
\r
1187 * The source code that implements the alternative (Alt) API is much
\r
1188 * simpler because it executes everything from within a critical section.
\r
1189 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1190 * preferred fully featured API too. The fully featured API has more
\r
1191 * complex code that takes longer to execute, but makes much less use of
\r
1192 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1193 * responsiveness to gain execution speed, whereas the fully featured API
\r
1194 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1196 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1197 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1198 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
\r
1199 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
\r
1200 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )
\r
1201 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )
\r
1204 * The functions defined above are for passing data to and from tasks. The
\r
1205 * functions below are the equivalents for passing data to and from
\r
1208 * These functions are called from the co-routine macro implementation and
\r
1209 * should not be called directly from application code. Instead use the macro
\r
1210 * wrappers defined within croutine.h.
\r
1212 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1213 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1214 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1215 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1218 * For internal use only. Use xSemaphoreCreateMutex() or
\r
1219 * xSemaphoreCreateCounting() instead of calling these functions directly.
\r
1221 xQueueHandle xQueueCreateMutex( void );
\r
1222 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1225 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1226 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1228 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime );
\r
1229 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex );
\r
1232 * The registry is provided as a means for kernel aware debuggers to
\r
1233 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
\r
1234 * a queue, semaphore or mutex handle to the registry if you want the handle
\r
1235 * to be available to a kernel aware debugger. If you are not using a kernel
\r
1236 * aware debugger then this function can be ignored.
\r
1238 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
\r
1239 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
\r
1240 * within FreeRTOSConfig.h for the registry to be available. Its value
\r
1241 * does not effect the number of queues, semaphores and mutexes that can be
\r
1242 * created - just the number that the registry can hold.
\r
1244 * @param xQueue The handle of the queue being added to the registry. This
\r
1245 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
\r
1246 * handles can also be passed in here.
\r
1248 * @param pcName The name to be associated with the handle. This is the
\r
1249 * name that the kernel aware debugger will display.
\r
1251 #if configQUEUE_REGISTRY_SIZE > 0U
\r
1252 void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcName );
\r
1255 /* Not a public API function, hence the 'Restricted' in the name. */
\r
1256 void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait );
\r
1259 #ifdef __cplusplus
\r
1263 #endif /* QUEUE_H */
\r