2 FreeRTOS V5.4.0 - Copyright (C) 2003-2009 Richard Barry.
\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
61 typedef void * xQueueHandle;
\r
63 /* For internal use only. */
\r
64 #define queueSEND_TO_BACK ( 0 )
\r
65 #define queueSEND_TO_FRONT ( 1 )
\r
71 xQueueHandle xQueueCreate(
\r
72 unsigned portBASE_TYPE uxQueueLength,
\r
73 unsigned portBASE_TYPE uxItemSize
\r
77 * Creates a new queue instance. This allocates the storage required by the
\r
78 * new queue and returns a handle for the queue.
\r
80 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
82 * @param uxItemSize The number of bytes each item in the queue will require.
\r
83 * Items are queued by copy, not by reference, so this is the number of bytes
\r
84 * that will be copied for each posted item. Each item on the queue must be
\r
87 * @return If the queue is successfully create then a handle to the newly
\r
88 * created queue is returned. If the queue cannot be created then 0 is
\r
95 portCHAR ucMessageID;
\r
96 portCHAR ucData[ 20 ];
\r
99 void vATask( void *pvParameters )
\r
101 xQueueHandle xQueue1, xQueue2;
\r
103 // Create a queue capable of containing 10 unsigned long values.
\r
104 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
107 // Queue was not created and must not be used.
\r
110 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
111 // These should be passed by pointer as they contain a lot of data.
\r
112 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
115 // Queue was not created and must not be used.
\r
118 // ... Rest of task code.
\r
121 * \defgroup xQueueCreate xQueueCreate
\r
122 * \ingroup QueueManagement
\r
124 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
129 portBASE_TYPE xQueueSendToToFront(
\r
130 xQueueHandle xQueue,
\r
131 const void * pvItemToQueue,
\r
132 portTickType xTicksToWait
\r
136 * This is a macro that calls xQueueGenericSend().
\r
138 * Post an item to the front of a queue. The item is queued by copy, not by
\r
139 * reference. This function must not be called from an interrupt service
\r
140 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
143 * @param xQueue The handle to the queue on which the item is to be posted.
\r
145 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
146 * queue. The size of the items the queue will hold was defined when the
\r
147 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
148 * into the queue storage area.
\r
150 * @param xTicksToWait The maximum amount of time the task should block
\r
151 * waiting for space to become available on the queue, should it already
\r
152 * be full. The call will return immediately if this is set to 0 and the
\r
153 * queue is full. The time is defined in tick periods so the constant
\r
154 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
156 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
162 portCHAR ucMessageID;
\r
163 portCHAR ucData[ 20 ];
\r
166 unsigned portLONG ulVar = 10UL;
\r
168 void vATask( void *pvParameters )
\r
170 xQueueHandle xQueue1, xQueue2;
\r
171 struct AMessage *pxMessage;
\r
173 // Create a queue capable of containing 10 unsigned long values.
\r
174 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
176 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
177 // These should be passed by pointer as they contain a lot of data.
\r
178 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
184 // Send an unsigned long. Wait for 10 ticks for space to become
\r
185 // available if necessary.
\r
186 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
188 // Failed to post the message, even after 10 ticks.
\r
194 // Send a pointer to a struct AMessage object. Don't block if the
\r
195 // queue is already full.
\r
196 pxMessage = & xMessage;
\r
197 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
200 // ... Rest of task code.
\r
203 * \defgroup xQueueSend xQueueSend
\r
204 * \ingroup QueueManagement
\r
206 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
211 portBASE_TYPE xQueueSendToBack(
\r
212 xQueueHandle xQueue,
\r
213 const void * pvItemToQueue,
\r
214 portTickType xTicksToWait
\r
218 * This is a macro that calls xQueueGenericSend().
\r
220 * Post an item to the back of a queue. The item is queued by copy, not by
\r
221 * reference. This function must not be called from an interrupt service
\r
222 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
225 * @param xQueue The handle to the queue on which the item is to be posted.
\r
227 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
228 * queue. The size of the items the queue will hold was defined when the
\r
229 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
230 * into the queue storage area.
\r
232 * @param xTicksToWait The maximum amount of time the task should block
\r
233 * waiting for space to become available on the queue, should it already
\r
234 * be full. The call will return immediately if this is set to 0 and the queue
\r
235 * is full. The time is defined in tick periods so the constant
\r
236 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
238 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
244 portCHAR ucMessageID;
\r
245 portCHAR ucData[ 20 ];
\r
248 unsigned portLONG ulVar = 10UL;
\r
250 void vATask( void *pvParameters )
\r
252 xQueueHandle xQueue1, xQueue2;
\r
253 struct AMessage *pxMessage;
\r
255 // Create a queue capable of containing 10 unsigned long values.
\r
256 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
258 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
259 // These should be passed by pointer as they contain a lot of data.
\r
260 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
266 // Send an unsigned long. Wait for 10 ticks for space to become
\r
267 // available if necessary.
\r
268 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
270 // Failed to post the message, even after 10 ticks.
\r
276 // Send a pointer to a struct AMessage object. Don't block if the
\r
277 // queue is already full.
\r
278 pxMessage = & xMessage;
\r
279 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
282 // ... Rest of task code.
\r
285 * \defgroup xQueueSend xQueueSend
\r
286 * \ingroup QueueManagement
\r
288 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
293 portBASE_TYPE xQueueSend(
\r
294 xQueueHandle xQueue,
\r
295 const void * pvItemToQueue,
\r
296 portTickType xTicksToWait
\r
300 * This is a macro that calls xQueueGenericSend(). It is included for
\r
301 * backward compatibility with versions of FreeRTOS.org that did not
\r
302 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
303 * equivalent to xQueueSendToBack().
\r
305 * Post an item on a queue. The item is queued by copy, not by reference.
\r
306 * This function must not be called from an interrupt service routine.
\r
307 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
309 * @param xQueue The handle to the queue on which the item is to be posted.
\r
311 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
312 * queue. The size of the items the queue will hold was defined when the
\r
313 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
314 * into the queue storage area.
\r
316 * @param xTicksToWait The maximum amount of time the task should block
\r
317 * waiting for space to become available on the queue, should it already
\r
318 * be full. The call will return immediately if this is set to 0 and the
\r
319 * queue is full. The time is defined in tick periods so the constant
\r
320 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
322 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
328 portCHAR ucMessageID;
\r
329 portCHAR ucData[ 20 ];
\r
332 unsigned portLONG ulVar = 10UL;
\r
334 void vATask( void *pvParameters )
\r
336 xQueueHandle xQueue1, xQueue2;
\r
337 struct AMessage *pxMessage;
\r
339 // Create a queue capable of containing 10 unsigned long values.
\r
340 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
342 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
343 // These should be passed by pointer as they contain a lot of data.
\r
344 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
350 // Send an unsigned long. Wait for 10 ticks for space to become
\r
351 // available if necessary.
\r
352 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
354 // Failed to post the message, even after 10 ticks.
\r
360 // Send a pointer to a struct AMessage object. Don't block if the
\r
361 // queue is already full.
\r
362 pxMessage = & xMessage;
\r
363 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
366 // ... Rest of task code.
\r
369 * \defgroup xQueueSend xQueueSend
\r
370 * \ingroup QueueManagement
\r
372 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
378 portBASE_TYPE xQueueGenericSend(
\r
379 xQueueHandle xQueue,
\r
380 const void * pvItemToQueue,
\r
381 portTickType xTicksToWait
\r
382 portBASE_TYPE xCopyPosition
\r
386 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
387 * xQueueSendToBack() are used in place of calling this function directly.
\r
389 * Post an item on a queue. The item is queued by copy, not by reference.
\r
390 * This function must not be called from an interrupt service routine.
\r
391 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
393 * @param xQueue The handle to the queue on which the item is to be posted.
\r
395 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
396 * queue. The size of the items the queue will hold was defined when the
\r
397 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
398 * into the queue storage area.
\r
400 * @param xTicksToWait The maximum amount of time the task should block
\r
401 * waiting for space to become available on the queue, should it already
\r
402 * be full. The call will return immediately if this is set to 0 and the
\r
403 * queue is full. The time is defined in tick periods so the constant
\r
404 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
406 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
407 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
408 * at the front of the queue (for high priority messages).
\r
410 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
416 portCHAR ucMessageID;
\r
417 portCHAR ucData[ 20 ];
\r
420 unsigned portLONG ulVar = 10UL;
\r
422 void vATask( void *pvParameters )
\r
424 xQueueHandle xQueue1, xQueue2;
\r
425 struct AMessage *pxMessage;
\r
427 // Create a queue capable of containing 10 unsigned long values.
\r
428 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
430 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
431 // These should be passed by pointer as they contain a lot of data.
\r
432 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
438 // Send an unsigned long. Wait for 10 ticks for space to become
\r
439 // available if necessary.
\r
440 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
442 // Failed to post the message, even after 10 ticks.
\r
448 // Send a pointer to a struct AMessage object. Don't block if the
\r
449 // queue is already full.
\r
450 pxMessage = & xMessage;
\r
451 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
454 // ... Rest of task code.
\r
457 * \defgroup xQueueSend xQueueSend
\r
458 * \ingroup QueueManagement
\r
460 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
465 portBASE_TYPE xQueuePeek(
\r
466 xQueueHandle xQueue,
\r
468 portTickType xTicksToWait
\r
471 * This is a macro that calls the xQueueGenericReceive() function.
\r
473 * Receive an item from a queue without removing the item from the queue.
\r
474 * The item is received by copy so a buffer of adequate size must be
\r
475 * provided. The number of bytes copied into the buffer was defined when
\r
476 * the queue was created.
\r
478 * Successfully received items remain on the queue so will be returned again
\r
479 * by the next call, or a call to xQueueReceive().
\r
481 * This macro must not be used in an interrupt service routine.
\r
483 * @param pxQueue The handle to the queue from which the item is to be
\r
486 * @param pvBuffer Pointer to the buffer into which the received item will
\r
489 * @param xTicksToWait The maximum amount of time the task should block
\r
490 * waiting for an item to receive should the queue be empty at the time
\r
491 * of the call. The time is defined in tick periods so the constant
\r
492 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
493 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
\r
496 * @return pdTRUE if an item was successfully received from the queue,
\r
497 * otherwise pdFALSE.
\r
503 portCHAR ucMessageID;
\r
504 portCHAR ucData[ 20 ];
\r
507 xQueueHandle xQueue;
\r
509 // Task to create a queue and post a value.
\r
510 void vATask( void *pvParameters )
\r
512 struct AMessage *pxMessage;
\r
514 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
515 // These should be passed by pointer as they contain a lot of data.
\r
516 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
519 // Failed to create the queue.
\r
524 // Send a pointer to a struct AMessage object. Don't block if the
\r
525 // queue is already full.
\r
526 pxMessage = & xMessage;
\r
527 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
529 // ... Rest of task code.
\r
532 // Task to peek the data from the queue.
\r
533 void vADifferentTask( void *pvParameters )
\r
535 struct AMessage *pxRxedMessage;
\r
539 // Peek a message on the created queue. Block for 10 ticks if a
\r
540 // message is not immediately available.
\r
541 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
543 // pcRxedMessage now points to the struct AMessage variable posted
\r
544 // by vATask, but the item still remains on the queue.
\r
548 // ... Rest of task code.
\r
551 * \defgroup xQueueReceive xQueueReceive
\r
552 * \ingroup QueueManagement
\r
554 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
559 portBASE_TYPE xQueueReceive(
\r
560 xQueueHandle xQueue,
\r
562 portTickType xTicksToWait
\r
565 * This is a macro that calls the xQueueGenericReceive() function.
\r
567 * Receive an item from a queue. The item is received by copy so a buffer of
\r
568 * adequate size must be provided. The number of bytes copied into the buffer
\r
569 * was defined when the queue was created.
\r
571 * Successfully received items are removed from the queue.
\r
573 * This function must not be used in an interrupt service routine. See
\r
574 * xQueueReceiveFromISR for an alternative that can.
\r
576 * @param pxQueue The handle to the queue from which the item is to be
\r
579 * @param pvBuffer Pointer to the buffer into which the received item will
\r
582 * @param xTicksToWait The maximum amount of time the task should block
\r
583 * waiting for an item to receive should the queue be empty at the time
\r
584 * of the call. xQueueReceive() will return immediately if xTicksToWait
\r
585 * is zero and the queue is empty. The time is defined in tick periods so the
\r
586 * constant portTICK_RATE_MS should be used to convert to real time if this is
\r
589 * @return pdTRUE if an item was successfully received from the queue,
\r
590 * otherwise pdFALSE.
\r
596 portCHAR ucMessageID;
\r
597 portCHAR ucData[ 20 ];
\r
600 xQueueHandle xQueue;
\r
602 // Task to create a queue and post a value.
\r
603 void vATask( void *pvParameters )
\r
605 struct AMessage *pxMessage;
\r
607 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
608 // These should be passed by pointer as they contain a lot of data.
\r
609 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
612 // Failed to create the queue.
\r
617 // Send a pointer to a struct AMessage object. Don't block if the
\r
618 // queue is already full.
\r
619 pxMessage = & xMessage;
\r
620 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
622 // ... Rest of task code.
\r
625 // Task to receive from the queue.
\r
626 void vADifferentTask( void *pvParameters )
\r
628 struct AMessage *pxRxedMessage;
\r
632 // Receive a message on the created queue. Block for 10 ticks if a
\r
633 // message is not immediately available.
\r
634 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
636 // pcRxedMessage now points to the struct AMessage variable posted
\r
641 // ... Rest of task code.
\r
644 * \defgroup xQueueReceive xQueueReceive
\r
645 * \ingroup QueueManagement
\r
647 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
653 portBASE_TYPE xQueueGenericReceive(
\r
654 xQueueHandle xQueue,
\r
656 portTickType xTicksToWait
\r
657 portBASE_TYPE xJustPeek
\r
660 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
661 * this function directly.
\r
663 * Receive an item from a queue. The item is received by copy so a buffer of
\r
664 * adequate size must be provided. The number of bytes copied into the buffer
\r
665 * was defined when the queue was created.
\r
667 * This function must not be used in an interrupt service routine. See
\r
668 * xQueueReceiveFromISR for an alternative that can.
\r
670 * @param pxQueue The handle to the queue from which the item is to be
\r
673 * @param pvBuffer Pointer to the buffer into which the received item will
\r
676 * @param xTicksToWait The maximum amount of time the task should block
\r
677 * waiting for an item to receive should the queue be empty at the time
\r
678 * of the call. The time is defined in tick periods so the constant
\r
679 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
680 * xQueueGenericReceive() will return immediately if the queue is empty and
\r
681 * xTicksToWait is 0.
\r
683 * @param xJustPeek When set to true, the item received from the queue is not
\r
684 * actually removed from the queue - meaning a subsequent call to
\r
685 * xQueueReceive() will return the same item. When set to false, the item
\r
686 * being received from the queue is also removed from the queue.
\r
688 * @return pdTRUE if an item was successfully received from the queue,
\r
689 * otherwise pdFALSE.
\r
695 portCHAR ucMessageID;
\r
696 portCHAR ucData[ 20 ];
\r
699 xQueueHandle xQueue;
\r
701 // Task to create a queue and post a value.
\r
702 void vATask( void *pvParameters )
\r
704 struct AMessage *pxMessage;
\r
706 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
707 // These should be passed by pointer as they contain a lot of data.
\r
708 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
711 // Failed to create the queue.
\r
716 // Send a pointer to a struct AMessage object. Don't block if the
\r
717 // queue is already full.
\r
718 pxMessage = & xMessage;
\r
719 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
721 // ... Rest of task code.
\r
724 // Task to receive from the queue.
\r
725 void vADifferentTask( void *pvParameters )
\r
727 struct AMessage *pxRxedMessage;
\r
731 // Receive a message on the created queue. Block for 10 ticks if a
\r
732 // message is not immediately available.
\r
733 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
735 // pcRxedMessage now points to the struct AMessage variable posted
\r
740 // ... Rest of task code.
\r
743 * \defgroup xQueueReceive xQueueReceive
\r
744 * \ingroup QueueManagement
\r
746 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
750 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
752 * Return the number of messages stored in a queue.
\r
754 * @param xQueue A handle to the queue being queried.
\r
756 * @return The number of messages available in the queue.
\r
758 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
759 * \ingroup QueueManagement
\r
761 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
765 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
767 * Delete a queue - freeing all the memory allocated for storing of items
\r
768 * placed on the queue.
\r
770 * @param xQueue A handle to the queue to be deleted.
\r
772 * \page vQueueDelete vQueueDelete
\r
773 * \ingroup QueueManagement
\r
775 void vQueueDelete( xQueueHandle xQueue );
\r
780 portBASE_TYPE xQueueSendToFrontFromISR(
\r
781 xQueueHandle pxQueue,
\r
782 const void *pvItemToQueue,
\r
783 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
787 * This is a macro that calls xQueueGenericSendFromISR().
\r
789 * Post an item to the front of a queue. It is safe to use this macro from
\r
790 * within an interrupt service routine.
\r
792 * Items are queued by copy not reference so it is preferable to only
\r
793 * queue small items, especially when called from an ISR. In most cases
\r
794 * it would be preferable to store a pointer to the item being queued.
\r
796 * @param xQueue The handle to the queue on which the item is to be posted.
\r
798 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
799 * queue. The size of the items the queue will hold was defined when the
\r
800 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
801 * into the queue storage area.
\r
803 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
\r
804 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
805 * to unblock, and the unblocked task has a priority higher than the currently
\r
806 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
\r
807 * a context switch should be requested before the interrupt is exited.
\r
809 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
812 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
815 void vBufferISR( void )
\r
818 portBASE_TYPE xHigherPrioritTaskWoken;
\r
820 // We have not woken a task at the start of the ISR.
\r
821 xHigherPriorityTaskWoken = pdFALSE;
\r
823 // Loop until the buffer is empty.
\r
826 // Obtain a byte from the buffer.
\r
827 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
830 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
832 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
834 // Now the buffer is empty we can switch context if necessary.
\r
835 if( xHigherPriorityTaskWoken )
\r
842 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
843 * \ingroup QueueManagement
\r
845 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_FRONT )
\r
851 portBASE_TYPE xQueueSendToBackFromISR(
\r
852 xQueueHandle pxQueue,
\r
853 const void *pvItemToQueue,
\r
854 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
858 * This is a macro that calls xQueueGenericSendFromISR().
\r
860 * Post an item to the back of a queue. It is safe to use this macro from
\r
861 * within an interrupt service routine.
\r
863 * Items are queued by copy not reference so it is preferable to only
\r
864 * queue small items, especially when called from an ISR. In most cases
\r
865 * it would be preferable to store a pointer to the item being queued.
\r
867 * @param xQueue The handle to the queue on which the item is to be posted.
\r
869 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
870 * queue. The size of the items the queue will hold was defined when the
\r
871 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
872 * into the queue storage area.
\r
874 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
\r
875 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
876 * to unblock, and the unblocked task has a priority higher than the currently
\r
877 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
\r
878 * a context switch should be requested before the interrupt is exited.
\r
880 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
883 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
886 void vBufferISR( void )
\r
889 portBASE_TYPE xHigherPriorityTaskWoken;
\r
891 // We have not woken a task at the start of the ISR.
\r
892 xHigherPriorityTaskWoken = pdFALSE;
\r
894 // Loop until the buffer is empty.
\r
897 // Obtain a byte from the buffer.
\r
898 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
901 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
903 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
905 // Now the buffer is empty we can switch context if necessary.
\r
906 if( xHigherPriorityTaskWoken )
\r
913 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
914 * \ingroup QueueManagement
\r
916 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
921 portBASE_TYPE xQueueSendFromISR(
\r
922 xQueueHandle pxQueue,
\r
923 const void *pvItemToQueue,
\r
924 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
928 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
929 * for backward compatibility with versions of FreeRTOS.org that did not
\r
930 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
933 * Post an item to the back of a queue. It is safe to use this function from
\r
934 * within an interrupt service routine.
\r
936 * Items are queued by copy not reference so it is preferable to only
\r
937 * queue small items, especially when called from an ISR. In most cases
\r
938 * it would be preferable to store a pointer to the item being queued.
\r
940 * @param xQueue The handle to the queue on which the item is to be posted.
\r
942 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
943 * queue. The size of the items the queue will hold was defined when the
\r
944 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
945 * into the queue storage area.
\r
947 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
\r
948 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
949 * to unblock, and the unblocked task has a priority higher than the currently
\r
950 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
951 * a context switch should be requested before the interrupt is exited.
\r
953 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
956 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
959 void vBufferISR( void )
\r
962 portBASE_TYPE xHigherPriorityTaskWoken;
\r
964 // We have not woken a task at the start of the ISR.
\r
965 xHigherPriorityTaskWoken = pdFALSE;
\r
967 // Loop until the buffer is empty.
\r
970 // Obtain a byte from the buffer.
\r
971 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
974 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
976 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
978 // Now the buffer is empty we can switch context if necessary.
\r
979 if( xHigherPriorityTaskWoken )
\r
981 // Actual macro used here is port specific.
\r
982 taskYIELD_FROM_ISR ();
\r
987 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
988 * \ingroup QueueManagement
\r
990 #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
995 portBASE_TYPE xQueueGenericSendFromISR(
\r
996 xQueueHandle pxQueue,
\r
997 const void *pvItemToQueue,
\r
998 portBASE_TYPE *pxHigherPriorityTaskWoken,
\r
999 portBASE_TYPE xCopyPosition
\r
1003 * It is preferred that the macros xQueueSendFromISR(),
\r
1004 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1005 * of calling this function directly.
\r
1007 * Post an item on a queue. It is safe to use this function from within an
\r
1008 * interrupt service routine.
\r
1010 * Items are queued by copy not reference so it is preferable to only
\r
1011 * queue small items, especially when called from an ISR. In most cases
\r
1012 * it would be preferable to store a pointer to the item being queued.
\r
1014 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1016 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1017 * queue. The size of the items the queue will hold was defined when the
\r
1018 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1019 * into the queue storage area.
\r
1021 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
\r
1022 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1023 * to unblock, and the unblocked task has a priority higher than the currently
\r
1024 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
\r
1025 * a context switch should be requested before the interrupt is exited.
\r
1027 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1028 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1029 * at the front of the queue (for high priority messages).
\r
1031 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1034 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1037 void vBufferISR( void )
\r
1040 portBASE_TYPE xHigherPriorityTaskWokenByPost;
\r
1042 // We have not woken a task at the start of the ISR.
\r
1043 xHigherPriorityTaskWokenByPost = pdFALSE;
\r
1045 // Loop until the buffer is empty.
\r
1048 // Obtain a byte from the buffer.
\r
1049 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1051 // Post each byte.
\r
1052 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
\r
1054 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1056 // Now the buffer is empty we can switch context if necessary. Note that the
\r
1057 // name of the yield function required is port specific.
\r
1058 if( xHigherPriorityTaskWokenByPost )
\r
1060 taskYIELD_YIELD_FROM_ISR();
\r
1065 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1066 * \ingroup QueueManagement
\r
1068 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
\r
1073 portBASE_TYPE xQueueReceiveFromISR(
\r
1074 xQueueHandle pxQueue,
\r
1076 portBASE_TYPE *pxTaskWoken
\r
1080 * Receive an item from a queue. It is safe to use this function from within an
\r
1081 * interrupt service routine.
\r
1083 * @param pxQueue The handle to the queue from which the item is to be
\r
1086 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1089 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1090 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1091 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1092 * remain unchanged.
\r
1094 * @return pdTRUE if an item was successfully received from the queue,
\r
1095 * otherwise pdFALSE.
\r
1100 xQueueHandle xQueue;
\r
1102 // Function to create a queue and post some values.
\r
1103 void vAFunction( void *pvParameters )
\r
1105 portCHAR cValueToPost;
\r
1106 const portTickType xBlockTime = ( portTickType )0xff;
\r
1108 // Create a queue capable of containing 10 characters.
\r
1109 xQueue = xQueueCreate( 10, sizeof( portCHAR ) );
\r
1112 // Failed to create the queue.
\r
1117 // Post some characters that will be used within an ISR. If the queue
\r
1118 // is full then this task will block for xBlockTime ticks.
\r
1119 cValueToPost = 'a';
\r
1120 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1121 cValueToPost = 'b';
\r
1122 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1124 // ... keep posting characters ... this task may block when the queue
\r
1127 cValueToPost = 'c';
\r
1128 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1131 // ISR that outputs all the characters received on the queue.
\r
1132 void vISR_Routine( void )
\r
1134 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1135 portCHAR cRxedChar;
\r
1137 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1139 // A character was received. Output the character now.
\r
1140 vOutputCharacter( cRxedChar );
\r
1142 // If removing the character from the queue woke the task that was
\r
1143 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1144 // pdTRUE. No matter how many times this loop iterates only one
\r
1145 // task will be woken.
\r
1148 if( cTaskWokenByPost != ( portCHAR ) pdFALSE;
\r
1154 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1155 * \ingroup QueueManagement
\r
1157 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1160 * Utilities to query queue that are safe to use from an ISR. These utilities
\r
1161 * should be used only from witin an ISR, or within a critical section.
\r
1163 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
\r
1164 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
\r
1165 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
\r
1169 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1170 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1171 * xQueueGenericReceive().
\r
1173 * The source code that implements the alternative (Alt) API is much
\r
1174 * simpler because it executes everything from within a critical section.
\r
1175 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1176 * preferred fully featured API too. The fully featured API has more
\r
1177 * complex code that takes longer to execute, but makes much less use of
\r
1178 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1179 * responsiveness to gain execution speed, whereas the fully featured API
\r
1180 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1182 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1183 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1184 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
1185 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
1186 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
1187 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
1190 * The functions defined above are for passing data to and from tasks. The
\r
1191 * functions below are the equivalents for passing data to and from
\r
1194 * These functions are called from the co-routine macro implementation and
\r
1195 * should not be called directly from application code. Instead use the macro
\r
1196 * wrappers defined within croutine.h.
\r
1198 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1199 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1200 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1201 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1204 * For internal use only. Use xSemaphoreCreateMutex() or
\r
1205 * xSemaphoreCreateCounting() instead of calling these functions directly.
\r
1207 xQueueHandle xQueueCreateMutex( void );
\r
1208 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1211 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1212 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1214 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
\r
1215 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex );
\r
1218 * The registry is provided as a means for kernel aware debuggers to
\r
1219 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
\r
1220 * a queue, semaphore or mutex handle to the registry if you want the handle
\r
1221 * to be available to a kernel aware debugger. If you are not using a kernel
\r
1222 * aware debugger then this function can be ignored.
\r
1224 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
\r
1225 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
\r
1226 * within FreeRTOSConfig.h for the registry to be available. Its value
\r
1227 * does not effect the number of queues, semaphores and mutexes that can be
\r
1228 * created - just the number that the registry can hold.
\r
1230 * @param xQueue The handle of the queue being added to the registry. This
\r
1231 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
\r
1232 * handles can also be passed in here.
\r
1234 * @param pcName The name to be associated with the handle. This is the
\r
1235 * name that the kernel aware debugger will display.
\r
1237 #if configQUEUE_REGISTRY_SIZE > 0
\r
1238 void vQueueAddToRegistry( xQueueHandle xQueue, signed portCHAR *pcName );
\r
1244 #ifdef __cplusplus
\r
1248 #endif /* QUEUE_H */
\r