2 FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
48 #ifndef INC_FREERTOS_H
\r
49 #error "#include FreeRTOS.h" must appear in source files before "#include queue.h"
\r
63 #include "mpu_wrappers.h"
\r
66 typedef void * xQueueHandle;
\r
69 /* For internal use only. */
\r
70 #define queueSEND_TO_BACK ( 0 )
\r
71 #define queueSEND_TO_FRONT ( 1 )
\r
77 xQueueHandle xQueueCreate(
\r
78 unsigned portBASE_TYPE uxQueueLength,
\r
79 unsigned portBASE_TYPE uxItemSize
\r
83 * Creates a new queue instance. This allocates the storage required by the
\r
84 * new queue and returns a handle for the queue.
\r
86 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
88 * @param uxItemSize The number of bytes each item in the queue will require.
\r
89 * Items are queued by copy, not by reference, so this is the number of bytes
\r
90 * that will be copied for each posted item. Each item on the queue must be
\r
93 * @return If the queue is successfully create then a handle to the newly
\r
94 * created queue is returned. If the queue cannot be created then 0 is
\r
101 portCHAR ucMessageID;
\r
102 portCHAR ucData[ 20 ];
\r
105 void vATask( void *pvParameters )
\r
107 xQueueHandle xQueue1, xQueue2;
\r
109 // Create a queue capable of containing 10 unsigned long values.
\r
110 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
113 // Queue was not created and must not be used.
\r
116 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
117 // These should be passed by pointer as they contain a lot of data.
\r
118 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
121 // Queue was not created and must not be used.
\r
124 // ... Rest of task code.
\r
127 * \defgroup xQueueCreate xQueueCreate
\r
128 * \ingroup QueueManagement
\r
130 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
135 portBASE_TYPE xQueueSendToToFront(
\r
136 xQueueHandle xQueue,
\r
137 const void * pvItemToQueue,
\r
138 portTickType xTicksToWait
\r
142 * This is a macro that calls xQueueGenericSend().
\r
144 * Post an item to the front of a queue. The item is queued by copy, not by
\r
145 * reference. This function must not be called from an interrupt service
\r
146 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
149 * @param xQueue The handle to the queue on which the item is to be posted.
\r
151 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
152 * queue. The size of the items the queue will hold was defined when the
\r
153 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
154 * into the queue storage area.
\r
156 * @param xTicksToWait The maximum amount of time the task should block
\r
157 * waiting for space to become available on the queue, should it already
\r
158 * be full. The call will return immediately if this is set to 0 and the
\r
159 * queue is full. The time is defined in tick periods so the constant
\r
160 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
162 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
168 portCHAR ucMessageID;
\r
169 portCHAR ucData[ 20 ];
\r
172 unsigned portLONG ulVar = 10UL;
\r
174 void vATask( void *pvParameters )
\r
176 xQueueHandle xQueue1, xQueue2;
\r
177 struct AMessage *pxMessage;
\r
179 // Create a queue capable of containing 10 unsigned long values.
\r
180 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
182 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
183 // These should be passed by pointer as they contain a lot of data.
\r
184 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
190 // Send an unsigned long. Wait for 10 ticks for space to become
\r
191 // available if necessary.
\r
192 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
194 // Failed to post the message, even after 10 ticks.
\r
200 // Send a pointer to a struct AMessage object. Don't block if the
\r
201 // queue is already full.
\r
202 pxMessage = & xMessage;
\r
203 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
206 // ... Rest of task code.
\r
209 * \defgroup xQueueSend xQueueSend
\r
210 * \ingroup QueueManagement
\r
212 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
217 portBASE_TYPE xQueueSendToBack(
\r
218 xQueueHandle xQueue,
\r
219 const void * pvItemToQueue,
\r
220 portTickType xTicksToWait
\r
224 * This is a macro that calls xQueueGenericSend().
\r
226 * Post an item to the back of a queue. The item is queued by copy, not by
\r
227 * reference. This function must not be called from an interrupt service
\r
228 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
231 * @param xQueue The handle to the queue on which the item is to be posted.
\r
233 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
234 * queue. The size of the items the queue will hold was defined when the
\r
235 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
236 * into the queue storage area.
\r
238 * @param xTicksToWait The maximum amount of time the task should block
\r
239 * waiting for space to become available on the queue, should it already
\r
240 * be full. The call will return immediately if this is set to 0 and the queue
\r
241 * is full. The time is defined in tick periods so the constant
\r
242 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
244 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
250 portCHAR ucMessageID;
\r
251 portCHAR ucData[ 20 ];
\r
254 unsigned portLONG ulVar = 10UL;
\r
256 void vATask( void *pvParameters )
\r
258 xQueueHandle xQueue1, xQueue2;
\r
259 struct AMessage *pxMessage;
\r
261 // Create a queue capable of containing 10 unsigned long values.
\r
262 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
264 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
265 // These should be passed by pointer as they contain a lot of data.
\r
266 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
272 // Send an unsigned long. Wait for 10 ticks for space to become
\r
273 // available if necessary.
\r
274 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
276 // Failed to post the message, even after 10 ticks.
\r
282 // Send a pointer to a struct AMessage object. Don't block if the
\r
283 // queue is already full.
\r
284 pxMessage = & xMessage;
\r
285 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
288 // ... Rest of task code.
\r
291 * \defgroup xQueueSend xQueueSend
\r
292 * \ingroup QueueManagement
\r
294 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
299 portBASE_TYPE xQueueSend(
\r
300 xQueueHandle xQueue,
\r
301 const void * pvItemToQueue,
\r
302 portTickType xTicksToWait
\r
306 * This is a macro that calls xQueueGenericSend(). It is included for
\r
307 * backward compatibility with versions of FreeRTOS.org that did not
\r
308 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
309 * equivalent to xQueueSendToBack().
\r
311 * Post an item on a queue. The item is queued by copy, not by reference.
\r
312 * This function must not be called from an interrupt service routine.
\r
313 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
315 * @param xQueue The handle to the queue on which the item is to be posted.
\r
317 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
318 * queue. The size of the items the queue will hold was defined when the
\r
319 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
320 * into the queue storage area.
\r
322 * @param xTicksToWait The maximum amount of time the task should block
\r
323 * waiting for space to become available on the queue, should it already
\r
324 * be full. The call will return immediately if this is set to 0 and the
\r
325 * queue is full. The time is defined in tick periods so the constant
\r
326 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
328 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
334 portCHAR ucMessageID;
\r
335 portCHAR ucData[ 20 ];
\r
338 unsigned portLONG ulVar = 10UL;
\r
340 void vATask( void *pvParameters )
\r
342 xQueueHandle xQueue1, xQueue2;
\r
343 struct AMessage *pxMessage;
\r
345 // Create a queue capable of containing 10 unsigned long values.
\r
346 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
348 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
349 // These should be passed by pointer as they contain a lot of data.
\r
350 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
356 // Send an unsigned long. Wait for 10 ticks for space to become
\r
357 // available if necessary.
\r
358 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
360 // Failed to post the message, even after 10 ticks.
\r
366 // Send a pointer to a struct AMessage object. Don't block if the
\r
367 // queue is already full.
\r
368 pxMessage = & xMessage;
\r
369 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
372 // ... Rest of task code.
\r
375 * \defgroup xQueueSend xQueueSend
\r
376 * \ingroup QueueManagement
\r
378 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
384 portBASE_TYPE xQueueGenericSend(
\r
385 xQueueHandle xQueue,
\r
386 const void * pvItemToQueue,
\r
387 portTickType xTicksToWait
\r
388 portBASE_TYPE xCopyPosition
\r
392 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
393 * xQueueSendToBack() are used in place of calling this function directly.
\r
395 * Post an item on a queue. The item is queued by copy, not by reference.
\r
396 * This function must not be called from an interrupt service routine.
\r
397 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
399 * @param xQueue The handle to the queue on which the item is to be posted.
\r
401 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
402 * queue. The size of the items the queue will hold was defined when the
\r
403 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
404 * into the queue storage area.
\r
406 * @param xTicksToWait The maximum amount of time the task should block
\r
407 * waiting for space to become available on the queue, should it already
\r
408 * be full. The call will return immediately if this is set to 0 and the
\r
409 * queue is full. The time is defined in tick periods so the constant
\r
410 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
412 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
413 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
414 * at the front of the queue (for high priority messages).
\r
416 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
422 portCHAR ucMessageID;
\r
423 portCHAR ucData[ 20 ];
\r
426 unsigned portLONG ulVar = 10UL;
\r
428 void vATask( void *pvParameters )
\r
430 xQueueHandle xQueue1, xQueue2;
\r
431 struct AMessage *pxMessage;
\r
433 // Create a queue capable of containing 10 unsigned long values.
\r
434 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
436 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
437 // These should be passed by pointer as they contain a lot of data.
\r
438 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
444 // Send an unsigned long. Wait for 10 ticks for space to become
\r
445 // available if necessary.
\r
446 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
448 // Failed to post the message, even after 10 ticks.
\r
454 // Send a pointer to a struct AMessage object. Don't block if the
\r
455 // queue is already full.
\r
456 pxMessage = & xMessage;
\r
457 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
460 // ... Rest of task code.
\r
463 * \defgroup xQueueSend xQueueSend
\r
464 * \ingroup QueueManagement
\r
466 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
471 portBASE_TYPE xQueuePeek(
\r
472 xQueueHandle xQueue,
\r
474 portTickType xTicksToWait
\r
477 * This is a macro that calls the xQueueGenericReceive() function.
\r
479 * Receive an item from a queue without removing the item from the queue.
\r
480 * The item is received by copy so a buffer of adequate size must be
\r
481 * provided. The number of bytes copied into the buffer was defined when
\r
482 * the queue was created.
\r
484 * Successfully received items remain on the queue so will be returned again
\r
485 * by the next call, or a call to xQueueReceive().
\r
487 * This macro must not be used in an interrupt service routine.
\r
489 * @param pxQueue The handle to the queue from which the item is to be
\r
492 * @param pvBuffer Pointer to the buffer into which the received item will
\r
495 * @param xTicksToWait The maximum amount of time the task should block
\r
496 * waiting for an item to receive should the queue be empty at the time
\r
497 * of the call. The time is defined in tick periods so the constant
\r
498 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
499 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
\r
502 * @return pdTRUE if an item was successfully received from the queue,
\r
503 * otherwise pdFALSE.
\r
509 portCHAR ucMessageID;
\r
510 portCHAR ucData[ 20 ];
\r
513 xQueueHandle xQueue;
\r
515 // Task to create a queue and post a value.
\r
516 void vATask( void *pvParameters )
\r
518 struct AMessage *pxMessage;
\r
520 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
521 // These should be passed by pointer as they contain a lot of data.
\r
522 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
525 // Failed to create the queue.
\r
530 // Send a pointer to a struct AMessage object. Don't block if the
\r
531 // queue is already full.
\r
532 pxMessage = & xMessage;
\r
533 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
535 // ... Rest of task code.
\r
538 // Task to peek the data from the queue.
\r
539 void vADifferentTask( void *pvParameters )
\r
541 struct AMessage *pxRxedMessage;
\r
545 // Peek a message on the created queue. Block for 10 ticks if a
\r
546 // message is not immediately available.
\r
547 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
549 // pcRxedMessage now points to the struct AMessage variable posted
\r
550 // by vATask, but the item still remains on the queue.
\r
554 // ... Rest of task code.
\r
557 * \defgroup xQueueReceive xQueueReceive
\r
558 * \ingroup QueueManagement
\r
560 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
565 portBASE_TYPE xQueueReceive(
\r
566 xQueueHandle xQueue,
\r
568 portTickType xTicksToWait
\r
571 * This is a macro that calls the xQueueGenericReceive() function.
\r
573 * Receive an item from a queue. The item is received by copy so a buffer of
\r
574 * adequate size must be provided. The number of bytes copied into the buffer
\r
575 * was defined when the queue was created.
\r
577 * Successfully received items are removed from the queue.
\r
579 * This function must not be used in an interrupt service routine. See
\r
580 * xQueueReceiveFromISR for an alternative that can.
\r
582 * @param pxQueue The handle to the queue from which the item is to be
\r
585 * @param pvBuffer Pointer to the buffer into which the received item will
\r
588 * @param xTicksToWait The maximum amount of time the task should block
\r
589 * waiting for an item to receive should the queue be empty at the time
\r
590 * of the call. xQueueReceive() will return immediately if xTicksToWait
\r
591 * is zero and the queue is empty. The time is defined in tick periods so the
\r
592 * constant portTICK_RATE_MS should be used to convert to real time if this is
\r
595 * @return pdTRUE if an item was successfully received from the queue,
\r
596 * otherwise pdFALSE.
\r
602 portCHAR ucMessageID;
\r
603 portCHAR ucData[ 20 ];
\r
606 xQueueHandle xQueue;
\r
608 // Task to create a queue and post a value.
\r
609 void vATask( void *pvParameters )
\r
611 struct AMessage *pxMessage;
\r
613 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
614 // These should be passed by pointer as they contain a lot of data.
\r
615 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
618 // Failed to create the queue.
\r
623 // Send a pointer to a struct AMessage object. Don't block if the
\r
624 // queue is already full.
\r
625 pxMessage = & xMessage;
\r
626 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
628 // ... Rest of task code.
\r
631 // Task to receive from the queue.
\r
632 void vADifferentTask( void *pvParameters )
\r
634 struct AMessage *pxRxedMessage;
\r
638 // Receive a message on the created queue. Block for 10 ticks if a
\r
639 // message is not immediately available.
\r
640 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
642 // pcRxedMessage now points to the struct AMessage variable posted
\r
647 // ... Rest of task code.
\r
650 * \defgroup xQueueReceive xQueueReceive
\r
651 * \ingroup QueueManagement
\r
653 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
659 portBASE_TYPE xQueueGenericReceive(
\r
660 xQueueHandle xQueue,
\r
662 portTickType xTicksToWait
\r
663 portBASE_TYPE xJustPeek
\r
666 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
667 * this function directly.
\r
669 * Receive an item from a queue. The item is received by copy so a buffer of
\r
670 * adequate size must be provided. The number of bytes copied into the buffer
\r
671 * was defined when the queue was created.
\r
673 * This function must not be used in an interrupt service routine. See
\r
674 * xQueueReceiveFromISR for an alternative that can.
\r
676 * @param pxQueue The handle to the queue from which the item is to be
\r
679 * @param pvBuffer Pointer to the buffer into which the received item will
\r
682 * @param xTicksToWait The maximum amount of time the task should block
\r
683 * waiting for an item to receive should the queue be empty at the time
\r
684 * of the call. The time is defined in tick periods so the constant
\r
685 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
686 * xQueueGenericReceive() will return immediately if the queue is empty and
\r
687 * xTicksToWait is 0.
\r
689 * @param xJustPeek When set to true, the item received from the queue is not
\r
690 * actually removed from the queue - meaning a subsequent call to
\r
691 * xQueueReceive() will return the same item. When set to false, the item
\r
692 * being received from the queue is also removed from the queue.
\r
694 * @return pdTRUE if an item was successfully received from the queue,
\r
695 * otherwise pdFALSE.
\r
701 portCHAR ucMessageID;
\r
702 portCHAR ucData[ 20 ];
\r
705 xQueueHandle xQueue;
\r
707 // Task to create a queue and post a value.
\r
708 void vATask( void *pvParameters )
\r
710 struct AMessage *pxMessage;
\r
712 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
713 // These should be passed by pointer as they contain a lot of data.
\r
714 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
717 // Failed to create the queue.
\r
722 // Send a pointer to a struct AMessage object. Don't block if the
\r
723 // queue is already full.
\r
724 pxMessage = & xMessage;
\r
725 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
727 // ... Rest of task code.
\r
730 // Task to receive from the queue.
\r
731 void vADifferentTask( void *pvParameters )
\r
733 struct AMessage *pxRxedMessage;
\r
737 // Receive a message on the created queue. Block for 10 ticks if a
\r
738 // message is not immediately available.
\r
739 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
741 // pcRxedMessage now points to the struct AMessage variable posted
\r
746 // ... Rest of task code.
\r
749 * \defgroup xQueueReceive xQueueReceive
\r
750 * \ingroup QueueManagement
\r
752 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
756 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
758 * Return the number of messages stored in a queue.
\r
760 * @param xQueue A handle to the queue being queried.
\r
762 * @return The number of messages available in the queue.
\r
764 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
765 * \ingroup QueueManagement
\r
767 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
771 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
773 * Delete a queue - freeing all the memory allocated for storing of items
\r
774 * placed on the queue.
\r
776 * @param xQueue A handle to the queue to be deleted.
\r
778 * \page vQueueDelete vQueueDelete
\r
779 * \ingroup QueueManagement
\r
781 void vQueueDelete( xQueueHandle xQueue );
\r
786 portBASE_TYPE xQueueSendToFrontFromISR(
\r
787 xQueueHandle pxQueue,
\r
788 const void *pvItemToQueue,
\r
789 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
793 * This is a macro that calls xQueueGenericSendFromISR().
\r
795 * Post an item to the front of a queue. It is safe to use this macro from
\r
796 * within an interrupt service routine.
\r
798 * Items are queued by copy not reference so it is preferable to only
\r
799 * queue small items, especially when called from an ISR. In most cases
\r
800 * it would be preferable to store a pointer to the item being queued.
\r
802 * @param xQueue The handle to the queue on which the item is to be posted.
\r
804 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
805 * queue. The size of the items the queue will hold was defined when the
\r
806 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
807 * into the queue storage area.
\r
809 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
\r
810 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
811 * to unblock, and the unblocked task has a priority higher than the currently
\r
812 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
\r
813 * a context switch should be requested before the interrupt is exited.
\r
815 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
818 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
821 void vBufferISR( void )
\r
824 portBASE_TYPE xHigherPrioritTaskWoken;
\r
826 // We have not woken a task at the start of the ISR.
\r
827 xHigherPriorityTaskWoken = pdFALSE;
\r
829 // Loop until the buffer is empty.
\r
832 // Obtain a byte from the buffer.
\r
833 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
836 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
838 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
840 // Now the buffer is empty we can switch context if necessary.
\r
841 if( xHigherPriorityTaskWoken )
\r
848 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
849 * \ingroup QueueManagement
\r
851 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_FRONT )
\r
857 portBASE_TYPE xQueueSendToBackFromISR(
\r
858 xQueueHandle pxQueue,
\r
859 const void *pvItemToQueue,
\r
860 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
864 * This is a macro that calls xQueueGenericSendFromISR().
\r
866 * Post an item to the back of a queue. It is safe to use this macro from
\r
867 * within an interrupt service routine.
\r
869 * Items are queued by copy not reference so it is preferable to only
\r
870 * queue small items, especially when called from an ISR. In most cases
\r
871 * it would be preferable to store a pointer to the item being queued.
\r
873 * @param xQueue The handle to the queue on which the item is to be posted.
\r
875 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
876 * queue. The size of the items the queue will hold was defined when the
\r
877 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
878 * into the queue storage area.
\r
880 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
\r
881 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
882 * to unblock, and the unblocked task has a priority higher than the currently
\r
883 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
\r
884 * a context switch should be requested before the interrupt is exited.
\r
886 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
889 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
892 void vBufferISR( void )
\r
895 portBASE_TYPE xHigherPriorityTaskWoken;
\r
897 // We have not woken a task at the start of the ISR.
\r
898 xHigherPriorityTaskWoken = pdFALSE;
\r
900 // Loop until the buffer is empty.
\r
903 // Obtain a byte from the buffer.
\r
904 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
907 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
909 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
911 // Now the buffer is empty we can switch context if necessary.
\r
912 if( xHigherPriorityTaskWoken )
\r
919 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
920 * \ingroup QueueManagement
\r
922 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
927 portBASE_TYPE xQueueSendFromISR(
\r
928 xQueueHandle pxQueue,
\r
929 const void *pvItemToQueue,
\r
930 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
934 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
935 * for backward compatibility with versions of FreeRTOS.org that did not
\r
936 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
939 * Post an item to the back of a queue. It is safe to use this function from
\r
940 * within an interrupt service routine.
\r
942 * Items are queued by copy not reference so it is preferable to only
\r
943 * queue small items, especially when called from an ISR. In most cases
\r
944 * it would be preferable to store a pointer to the item being queued.
\r
946 * @param xQueue The handle to the queue on which the item is to be posted.
\r
948 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
949 * queue. The size of the items the queue will hold was defined when the
\r
950 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
951 * into the queue storage area.
\r
953 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
\r
954 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
955 * to unblock, and the unblocked task has a priority higher than the currently
\r
956 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
957 * a context switch should be requested before the interrupt is exited.
\r
959 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
962 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
965 void vBufferISR( void )
\r
968 portBASE_TYPE xHigherPriorityTaskWoken;
\r
970 // We have not woken a task at the start of the ISR.
\r
971 xHigherPriorityTaskWoken = pdFALSE;
\r
973 // Loop until the buffer is empty.
\r
976 // Obtain a byte from the buffer.
\r
977 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
980 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
982 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
984 // Now the buffer is empty we can switch context if necessary.
\r
985 if( xHigherPriorityTaskWoken )
\r
987 // Actual macro used here is port specific.
\r
988 taskYIELD_FROM_ISR ();
\r
993 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
994 * \ingroup QueueManagement
\r
996 #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
1001 portBASE_TYPE xQueueGenericSendFromISR(
\r
1002 xQueueHandle pxQueue,
\r
1003 const void *pvItemToQueue,
\r
1004 portBASE_TYPE *pxHigherPriorityTaskWoken,
\r
1005 portBASE_TYPE xCopyPosition
\r
1009 * It is preferred that the macros xQueueSendFromISR(),
\r
1010 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1011 * of calling this function directly.
\r
1013 * Post an item on a queue. It is safe to use this function from within an
\r
1014 * interrupt service routine.
\r
1016 * Items are queued by copy not reference so it is preferable to only
\r
1017 * queue small items, especially when called from an ISR. In most cases
\r
1018 * it would be preferable to store a pointer to the item being queued.
\r
1020 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1022 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1023 * queue. The size of the items the queue will hold was defined when the
\r
1024 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1025 * into the queue storage area.
\r
1027 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
\r
1028 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1029 * to unblock, and the unblocked task has a priority higher than the currently
\r
1030 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
\r
1031 * a context switch should be requested before the interrupt is exited.
\r
1033 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1034 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1035 * at the front of the queue (for high priority messages).
\r
1037 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1040 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1043 void vBufferISR( void )
\r
1046 portBASE_TYPE xHigherPriorityTaskWokenByPost;
\r
1048 // We have not woken a task at the start of the ISR.
\r
1049 xHigherPriorityTaskWokenByPost = pdFALSE;
\r
1051 // Loop until the buffer is empty.
\r
1054 // Obtain a byte from the buffer.
\r
1055 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1057 // Post each byte.
\r
1058 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
\r
1060 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1062 // Now the buffer is empty we can switch context if necessary. Note that the
\r
1063 // name of the yield function required is port specific.
\r
1064 if( xHigherPriorityTaskWokenByPost )
\r
1066 taskYIELD_YIELD_FROM_ISR();
\r
1071 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1072 * \ingroup QueueManagement
\r
1074 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
\r
1079 portBASE_TYPE xQueueReceiveFromISR(
\r
1080 xQueueHandle pxQueue,
\r
1082 portBASE_TYPE *pxTaskWoken
\r
1086 * Receive an item from a queue. It is safe to use this function from within an
\r
1087 * interrupt service routine.
\r
1089 * @param pxQueue The handle to the queue from which the item is to be
\r
1092 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1095 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1096 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1097 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1098 * remain unchanged.
\r
1100 * @return pdTRUE if an item was successfully received from the queue,
\r
1101 * otherwise pdFALSE.
\r
1106 xQueueHandle xQueue;
\r
1108 // Function to create a queue and post some values.
\r
1109 void vAFunction( void *pvParameters )
\r
1111 portCHAR cValueToPost;
\r
1112 const portTickType xBlockTime = ( portTickType )0xff;
\r
1114 // Create a queue capable of containing 10 characters.
\r
1115 xQueue = xQueueCreate( 10, sizeof( portCHAR ) );
\r
1118 // Failed to create the queue.
\r
1123 // Post some characters that will be used within an ISR. If the queue
\r
1124 // is full then this task will block for xBlockTime ticks.
\r
1125 cValueToPost = 'a';
\r
1126 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1127 cValueToPost = 'b';
\r
1128 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1130 // ... keep posting characters ... this task may block when the queue
\r
1133 cValueToPost = 'c';
\r
1134 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1137 // ISR that outputs all the characters received on the queue.
\r
1138 void vISR_Routine( void )
\r
1140 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1141 portCHAR cRxedChar;
\r
1143 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1145 // A character was received. Output the character now.
\r
1146 vOutputCharacter( cRxedChar );
\r
1148 // If removing the character from the queue woke the task that was
\r
1149 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1150 // pdTRUE. No matter how many times this loop iterates only one
\r
1151 // task will be woken.
\r
1154 if( cTaskWokenByPost != ( portCHAR ) pdFALSE;
\r
1160 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1161 * \ingroup QueueManagement
\r
1163 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1166 * Utilities to query queue that are safe to use from an ISR. These utilities
\r
1167 * should be used only from witin an ISR, or within a critical section.
\r
1169 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
\r
1170 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
\r
1171 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
\r
1175 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1176 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1177 * xQueueGenericReceive().
\r
1179 * The source code that implements the alternative (Alt) API is much
\r
1180 * simpler because it executes everything from within a critical section.
\r
1181 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1182 * preferred fully featured API too. The fully featured API has more
\r
1183 * complex code that takes longer to execute, but makes much less use of
\r
1184 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1185 * responsiveness to gain execution speed, whereas the fully featured API
\r
1186 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1188 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1189 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1190 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
1191 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
1192 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
1193 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
1196 * The functions defined above are for passing data to and from tasks. The
\r
1197 * functions below are the equivalents for passing data to and from
\r
1200 * These functions are called from the co-routine macro implementation and
\r
1201 * should not be called directly from application code. Instead use the macro
\r
1202 * wrappers defined within croutine.h.
\r
1204 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1205 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1206 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1207 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1210 * For internal use only. Use xSemaphoreCreateMutex() or
\r
1211 * xSemaphoreCreateCounting() instead of calling these functions directly.
\r
1213 xQueueHandle xQueueCreateMutex( void );
\r
1214 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1217 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1218 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1220 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
\r
1221 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex );
\r
1224 * The registry is provided as a means for kernel aware debuggers to
\r
1225 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
\r
1226 * a queue, semaphore or mutex handle to the registry if you want the handle
\r
1227 * to be available to a kernel aware debugger. If you are not using a kernel
\r
1228 * aware debugger then this function can be ignored.
\r
1230 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
\r
1231 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
\r
1232 * within FreeRTOSConfig.h for the registry to be available. Its value
\r
1233 * does not effect the number of queues, semaphores and mutexes that can be
\r
1234 * created - just the number that the registry can hold.
\r
1236 * @param xQueue The handle of the queue being added to the registry. This
\r
1237 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
\r
1238 * handles can also be passed in here.
\r
1240 * @param pcName The name to be associated with the handle. This is the
\r
1241 * name that the kernel aware debugger will display.
\r
1243 #if configQUEUE_REGISTRY_SIZE > 0
\r
1244 void vQueueAddToRegistry( xQueueHandle xQueue, signed portCHAR *pcName );
\r
1250 #ifdef __cplusplus
\r
1254 #endif /* QUEUE_H */
\r