2 FreeRTOS.org V4.8.0 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! Why not get us to quote to get FreeRTOS.org *
\r
30 * running on your hardware - or even write all or part of your application*
\r
31 * for you? See http://www.OpenRTOS.com for details. *
\r
33 ***************************************************************************
\r
34 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
55 typedef void * xQueueHandle;
\r
57 /* For internal use only. */
\r
58 #define queueSEND_TO_BACK ( 0 )
\r
59 #define queueSEND_TO_FRONT ( 1 )
\r
65 xQueueHandle xQueueCreate(
\r
66 unsigned portBASE_TYPE uxQueueLength,
\r
67 unsigned portBASE_TYPE uxItemSize
\r
71 * Creates a new queue instance. This allocates the storage required by the
\r
72 * new queue and returns a handle for the queue.
\r
74 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
76 * @param uxItemSize The number of bytes each item in the queue will require.
\r
77 * Items are queued by copy, not by reference, so this is the number of bytes
\r
78 * that will be copied for each posted item. Each item on the queue must be
\r
81 * @return If the queue is successfully create then a handle to the newly
\r
82 * created queue is returned. If the queue cannot be created then 0 is
\r
89 portCHAR ucMessageID;
\r
90 portCHAR ucData[ 20 ];
\r
93 void vATask( void *pvParameters )
\r
95 xQueueHandle xQueue1, xQueue2;
\r
97 // Create a queue capable of containing 10 unsigned long values.
\r
98 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
101 // Queue was not created and must not be used.
\r
104 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
105 // These should be passed by pointer as they contain a lot of data.
\r
106 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
109 // Queue was not created and must not be used.
\r
112 // ... Rest of task code.
\r
115 * \defgroup xQueueCreate xQueueCreate
\r
116 * \ingroup QueueManagement
\r
118 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
123 portBASE_TYPE xQueueSendToToFront(
\r
124 xQueueHandle xQueue,
\r
125 const void * pvItemToQueue,
\r
126 portTickType xTicksToWait
\r
130 * This is a macro that calls xQueueGenericSend().
\r
132 * Post an item to the front of a queue. The item is queued by copy, not by
\r
133 * reference. This function must not be called from an interrupt service
\r
134 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
137 * @param xQueue The handle to the queue on which the item is to be posted.
\r
139 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
140 * queue. The size of the items the queue will hold was defined when the
\r
141 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
142 * into the queue storage area.
\r
144 * @param xTicksToWait The maximum amount of time the task should block
\r
145 * waiting for space to become available on the queue, should it already
\r
146 * be full. The call will return immediately if this is set to 0. The
\r
147 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
148 * should be used to convert to real time if this is required.
\r
150 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
156 portCHAR ucMessageID;
\r
157 portCHAR ucData[ 20 ];
\r
160 unsigned portLONG ulVar = 10UL;
\r
162 void vATask( void *pvParameters )
\r
164 xQueueHandle xQueue1, xQueue2;
\r
165 struct AMessage *pxMessage;
\r
167 // Create a queue capable of containing 10 unsigned long values.
\r
168 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
170 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
171 // These should be passed by pointer as they contain a lot of data.
\r
172 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
178 // Send an unsigned long. Wait for 10 ticks for space to become
\r
179 // available if necessary.
\r
180 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
182 // Failed to post the message, even after 10 ticks.
\r
188 // Send a pointer to a struct AMessage object. Don't block if the
\r
189 // queue is already full.
\r
190 pxMessage = & xMessage;
\r
191 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
194 // ... Rest of task code.
\r
197 * \defgroup xQueueSend xQueueSend
\r
198 * \ingroup QueueManagement
\r
200 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
205 portBASE_TYPE xQueueSendToBack(
\r
206 xQueueHandle xQueue,
\r
207 const void * pvItemToQueue,
\r
208 portTickType xTicksToWait
\r
212 * This is a macro that calls xQueueGenericSend().
\r
214 * Post an item to the back of a queue. The item is queued by copy, not by
\r
215 * reference. This function must not be called from an interrupt service
\r
216 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
219 * @param xQueue The handle to the queue on which the item is to be posted.
\r
221 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
222 * queue. The size of the items the queue will hold was defined when the
\r
223 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
224 * into the queue storage area.
\r
226 * @param xTicksToWait The maximum amount of time the task should block
\r
227 * waiting for space to become available on the queue, should it already
\r
228 * be full. The call will return immediately if this is set to 0. The
\r
229 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
230 * should be used to convert to real time if this is required.
\r
232 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
238 portCHAR ucMessageID;
\r
239 portCHAR ucData[ 20 ];
\r
242 unsigned portLONG ulVar = 10UL;
\r
244 void vATask( void *pvParameters )
\r
246 xQueueHandle xQueue1, xQueue2;
\r
247 struct AMessage *pxMessage;
\r
249 // Create a queue capable of containing 10 unsigned long values.
\r
250 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
252 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
253 // These should be passed by pointer as they contain a lot of data.
\r
254 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
260 // Send an unsigned long. Wait for 10 ticks for space to become
\r
261 // available if necessary.
\r
262 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
264 // Failed to post the message, even after 10 ticks.
\r
270 // Send a pointer to a struct AMessage object. Don't block if the
\r
271 // queue is already full.
\r
272 pxMessage = & xMessage;
\r
273 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
276 // ... Rest of task code.
\r
279 * \defgroup xQueueSend xQueueSend
\r
280 * \ingroup QueueManagement
\r
282 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
287 portBASE_TYPE xQueueSend(
\r
288 xQueueHandle xQueue,
\r
289 const void * pvItemToQueue,
\r
290 portTickType xTicksToWait
\r
294 * This is a macro that calls xQueueGenericSend(). It is included for
\r
295 * backward compatibility with versions of FreeRTOS.org that did not
\r
296 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
297 * equivalent to xQueueSendToBack().
\r
299 * Post an item on a queue. The item is queued by copy, not by reference.
\r
300 * This function must not be called from an interrupt service routine.
\r
301 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
303 * @param xQueue The handle to the queue on which the item is to be posted.
\r
305 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
306 * queue. The size of the items the queue will hold was defined when the
\r
307 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
308 * into the queue storage area.
\r
310 * @param xTicksToWait The maximum amount of time the task should block
\r
311 * waiting for space to become available on the queue, should it already
\r
312 * be full. The call will return immediately if this is set to 0. The
\r
313 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
314 * should be used to convert to real time if this is required.
\r
316 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
322 portCHAR ucMessageID;
\r
323 portCHAR ucData[ 20 ];
\r
326 unsigned portLONG ulVar = 10UL;
\r
328 void vATask( void *pvParameters )
\r
330 xQueueHandle xQueue1, xQueue2;
\r
331 struct AMessage *pxMessage;
\r
333 // Create a queue capable of containing 10 unsigned long values.
\r
334 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
336 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
337 // These should be passed by pointer as they contain a lot of data.
\r
338 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
344 // Send an unsigned long. Wait for 10 ticks for space to become
\r
345 // available if necessary.
\r
346 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
348 // Failed to post the message, even after 10 ticks.
\r
354 // Send a pointer to a struct AMessage object. Don't block if the
\r
355 // queue is already full.
\r
356 pxMessage = & xMessage;
\r
357 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
360 // ... Rest of task code.
\r
363 * \defgroup xQueueSend xQueueSend
\r
364 * \ingroup QueueManagement
\r
366 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
372 portBASE_TYPE xQueueGenericSend(
\r
373 xQueueHandle xQueue,
\r
374 const void * pvItemToQueue,
\r
375 portTickType xTicksToWait
\r
376 portBASE_TYPE xCopyPosition
\r
380 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
381 * xQueueSendToBack() are used in place of calling this function directly.
\r
383 * Post an item on a queue. The item is queued by copy, not by reference.
\r
384 * This function must not be called from an interrupt service routine.
\r
385 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
387 * @param xQueue The handle to the queue on which the item is to be posted.
\r
389 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
390 * queue. The size of the items the queue will hold was defined when the
\r
391 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
392 * into the queue storage area.
\r
394 * @param xTicksToWait The maximum amount of time the task should block
\r
395 * waiting for space to become available on the queue, should it already
\r
396 * be full. The call will return immediately if this is set to 0. The
\r
397 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
398 * should be used to convert to real time if this is required.
\r
400 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
401 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
402 * at the front of the queue (for high priority messages).
\r
404 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
410 portCHAR ucMessageID;
\r
411 portCHAR ucData[ 20 ];
\r
414 unsigned portLONG ulVar = 10UL;
\r
416 void vATask( void *pvParameters )
\r
418 xQueueHandle xQueue1, xQueue2;
\r
419 struct AMessage *pxMessage;
\r
421 // Create a queue capable of containing 10 unsigned long values.
\r
422 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
424 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
425 // These should be passed by pointer as they contain a lot of data.
\r
426 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
432 // Send an unsigned long. Wait for 10 ticks for space to become
\r
433 // available if necessary.
\r
434 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
436 // Failed to post the message, even after 10 ticks.
\r
442 // Send a pointer to a struct AMessage object. Don't block if the
\r
443 // queue is already full.
\r
444 pxMessage = & xMessage;
\r
445 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
448 // ... Rest of task code.
\r
451 * \defgroup xQueueSend xQueueSend
\r
452 * \ingroup QueueManagement
\r
454 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
459 portBASE_TYPE xQueuePeek(
\r
460 xQueueHandle xQueue,
\r
462 portTickType xTicksToWait
\r
465 * This is a macro that calls the xQueueGenericReceive() function.
\r
467 * Receive an item from a queue without removing the item from the queue.
\r
468 * The item is received by copy so a buffer of adequate size must be
\r
469 * provided. The number of bytes copied into the buffer was defined when
\r
470 * the queue was created.
\r
472 * Successfully received items remain on the queue so will be returned again
\r
473 * by the next call, or a call to xQueueReceive().
\r
475 * This macro must not be used in an interrupt service routine.
\r
477 * @param pxQueue The handle to the queue from which the item is to be
\r
480 * @param pvBuffer Pointer to the buffer into which the received item will
\r
483 * @param xTicksToWait The maximum amount of time the task should block
\r
484 * waiting for an item to receive should the queue be empty at the time
\r
485 * of the call. The time is defined in tick periods so the constant
\r
486 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
488 * @return pdTRUE if an item was successfully received from the queue,
\r
489 * otherwise pdFALSE.
\r
495 portCHAR ucMessageID;
\r
496 portCHAR ucData[ 20 ];
\r
499 xQueueHandle xQueue;
\r
501 // Task to create a queue and post a value.
\r
502 void vATask( void *pvParameters )
\r
504 struct AMessage *pxMessage;
\r
506 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
507 // These should be passed by pointer as they contain a lot of data.
\r
508 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
511 // Failed to create the queue.
\r
516 // Send a pointer to a struct AMessage object. Don't block if the
\r
517 // queue is already full.
\r
518 pxMessage = & xMessage;
\r
519 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
521 // ... Rest of task code.
\r
524 // Task to peek the data from the queue.
\r
525 void vADifferentTask( void *pvParameters )
\r
527 struct AMessage *pxRxedMessage;
\r
531 // Peek a message on the created queue. Block for 10 ticks if a
\r
532 // message is not immediately available.
\r
533 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
535 // pcRxedMessage now points to the struct AMessage variable posted
\r
536 // by vATask, but the item still remains on the queue.
\r
540 // ... Rest of task code.
\r
543 * \defgroup xQueueReceive xQueueReceive
\r
544 * \ingroup QueueManagement
\r
546 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
551 portBASE_TYPE xQueueReceive(
\r
552 xQueueHandle xQueue,
\r
554 portTickType xTicksToWait
\r
557 * This is a macro that calls the xQueueGenericReceive() function.
\r
559 * Receive an item from a queue. The item is received by copy so a buffer of
\r
560 * adequate size must be provided. The number of bytes copied into the buffer
\r
561 * was defined when the queue was created.
\r
563 * Successfully received items are removed from the queue.
\r
565 * This function must not be used in an interrupt service routine. See
\r
566 * xQueueReceiveFromISR for an alternative that can.
\r
568 * @param pxQueue The handle to the queue from which the item is to be
\r
571 * @param pvBuffer Pointer to the buffer into which the received item will
\r
574 * @param xTicksToWait The maximum amount of time the task should block
\r
575 * waiting for an item to receive should the queue be empty at the time
\r
576 * of the call. The time is defined in tick periods so the constant
\r
577 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
579 * @return pdTRUE if an item was successfully received from the queue,
\r
580 * otherwise pdFALSE.
\r
586 portCHAR ucMessageID;
\r
587 portCHAR ucData[ 20 ];
\r
590 xQueueHandle xQueue;
\r
592 // Task to create a queue and post a value.
\r
593 void vATask( void *pvParameters )
\r
595 struct AMessage *pxMessage;
\r
597 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
598 // These should be passed by pointer as they contain a lot of data.
\r
599 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
602 // Failed to create the queue.
\r
607 // Send a pointer to a struct AMessage object. Don't block if the
\r
608 // queue is already full.
\r
609 pxMessage = & xMessage;
\r
610 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
612 // ... Rest of task code.
\r
615 // Task to receive from the queue.
\r
616 void vADifferentTask( void *pvParameters )
\r
618 struct AMessage *pxRxedMessage;
\r
622 // Receive a message on the created queue. Block for 10 ticks if a
\r
623 // message is not immediately available.
\r
624 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
626 // pcRxedMessage now points to the struct AMessage variable posted
\r
631 // ... Rest of task code.
\r
634 * \defgroup xQueueReceive xQueueReceive
\r
635 * \ingroup QueueManagement
\r
637 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
643 portBASE_TYPE xQueueGenericReceive(
\r
644 xQueueHandle xQueue,
\r
646 portTickType xTicksToWait
\r
647 portBASE_TYPE xJustPeek
\r
650 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
651 * this function directly.
\r
653 * Receive an item from a queue. The item is received by copy so a buffer of
\r
654 * adequate size must be provided. The number of bytes copied into the buffer
\r
655 * was defined when the queue was created.
\r
657 * This function must not be used in an interrupt service routine. See
\r
658 * xQueueReceiveFromISR for an alternative that can.
\r
660 * @param pxQueue The handle to the queue from which the item is to be
\r
663 * @param pvBuffer Pointer to the buffer into which the received item will
\r
666 * @param xTicksToWait The maximum amount of time the task should block
\r
667 * waiting for an item to receive should the queue be empty at the time
\r
668 * of the call. The time is defined in tick periods so the constant
\r
669 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
671 * @param xJustPeek When set to true, the item received from the queue is not
\r
672 * actually removed from the queue - meaning a subsequent call to
\r
673 * xQueueReceive() will return the same item. When set to false, the item
\r
674 * being received from the queue is also removed from the queue.
\r
676 * @return pdTRUE if an item was successfully received from the queue,
\r
677 * otherwise pdFALSE.
\r
683 portCHAR ucMessageID;
\r
684 portCHAR ucData[ 20 ];
\r
687 xQueueHandle xQueue;
\r
689 // Task to create a queue and post a value.
\r
690 void vATask( void *pvParameters )
\r
692 struct AMessage *pxMessage;
\r
694 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
695 // These should be passed by pointer as they contain a lot of data.
\r
696 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
699 // Failed to create the queue.
\r
704 // Send a pointer to a struct AMessage object. Don't block if the
\r
705 // queue is already full.
\r
706 pxMessage = & xMessage;
\r
707 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
709 // ... Rest of task code.
\r
712 // Task to receive from the queue.
\r
713 void vADifferentTask( void *pvParameters )
\r
715 struct AMessage *pxRxedMessage;
\r
719 // Receive a message on the created queue. Block for 10 ticks if a
\r
720 // message is not immediately available.
\r
721 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
723 // pcRxedMessage now points to the struct AMessage variable posted
\r
728 // ... Rest of task code.
\r
731 * \defgroup xQueueReceive xQueueReceive
\r
732 * \ingroup QueueManagement
\r
734 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
738 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle const xQueue );</pre>
\r
740 * Return the number of messages stored in a queue.
\r
742 * @param xQueue A handle to the queue being queried.
\r
744 * @return The number of messages available in the queue.
\r
746 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
747 * \ingroup QueueManagement
\r
749 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle const xQueue );
\r
753 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
755 * Delete a queue - freeing all the memory allocated for storing of items
\r
756 * placed on the queue.
\r
758 * @param xQueue A handle to the queue to be deleted.
\r
760 * \page vQueueDelete vQueueDelete
\r
761 * \ingroup QueueManagement
\r
763 void vQueueDelete( xQueueHandle xQueue );
\r
768 portBASE_TYPE xQueueSendToFrontFromISR(
\r
769 xQueueHandle pxQueue,
\r
770 const void *pvItemToQueue,
\r
771 portBASE_TYPE xTaskPreviouslyWoken
\r
775 * This is a macro that calls xQueueGenericSendFromISR().
\r
777 * Post an item to the front of a queue. It is safe to use this macro from
\r
778 * within an interrupt service routine.
\r
780 * Items are queued by copy not reference so it is preferable to only
\r
781 * queue small items, especially when called from an ISR. In most cases
\r
782 * it would be preferable to store a pointer to the item being queued.
\r
784 * @param xQueue The handle to the queue on which the item is to be posted.
\r
786 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
787 * queue. The size of the items the queue will hold was defined when the
\r
788 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
789 * into the queue storage area.
\r
791 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
792 * the same queue multiple times from a single interrupt. The first call
\r
793 * should always pass in pdFALSE. Subsequent calls should pass in
\r
794 * the value returned from the previous call. See the file serial .c in the
\r
795 * PC port for a good example of this mechanism.
\r
797 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
798 * used by the ISR to determine if a context switch may be required following
\r
801 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
804 void vBufferISR( void )
\r
807 portBASE_TYPE xTaskWokenByPost;
\r
809 // We have not woken a task at the start of the ISR.
\r
810 cTaskWokenByPost = pdFALSE;
\r
812 // Loop until the buffer is empty.
\r
815 // Obtain a byte from the buffer.
\r
816 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
818 // Post the byte. The first time round the loop cTaskWokenByPost
\r
819 // will be pdFALSE. If the queue send causes a task to wake we do
\r
820 // not want the task to run until we have finished the ISR, so
\r
821 // xQueueSendFromISR does not cause a context switch. Also we
\r
822 // don't want subsequent posts to wake any other tasks, so we store
\r
823 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
824 // knows not to wake any task the next iteration of the loop.
\r
825 xTaskWokenByPost = xQueueSendToFrontFromISR( xRxQueue, &cIn, cTaskWokenByPost );
\r
827 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
829 // Now the buffer is empty we can switch context if necessary.
\r
830 if( cTaskWokenByPost )
\r
837 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
838 * \ingroup QueueManagement
\r
840 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken, queueSEND_TO_FRONT )
\r
846 portBASE_TYPE xQueueSendToBackFromISR(
\r
847 xQueueHandle pxQueue,
\r
848 const void *pvItemToQueue,
\r
849 portBASE_TYPE xTaskPreviouslyWoken
\r
853 * This is a macro that calls xQueueGenericSendFromISR().
\r
855 * Post an item to the back of a queue. It is safe to use this macro from
\r
856 * within an interrupt service routine.
\r
858 * Items are queued by copy not reference so it is preferable to only
\r
859 * queue small items, especially when called from an ISR. In most cases
\r
860 * it would be preferable to store a pointer to the item being queued.
\r
862 * @param xQueue The handle to the queue on which the item is to be posted.
\r
864 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
865 * queue. The size of the items the queue will hold was defined when the
\r
866 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
867 * into the queue storage area.
\r
869 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
870 * the same queue multiple times from a single interrupt. The first call
\r
871 * should always pass in pdFALSE. Subsequent calls should pass in
\r
872 * the value returned from the previous call. See the file serial .c in the
\r
873 * PC port for a good example of this mechanism.
\r
875 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
876 * used by the ISR to determine if a context switch may be required following
\r
879 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
882 void vBufferISR( void )
\r
885 portBASE_TYPE xTaskWokenByPost;
\r
887 // We have not woken a task at the start of the ISR.
\r
888 cTaskWokenByPost = pdFALSE;
\r
890 // Loop until the buffer is empty.
\r
893 // Obtain a byte from the buffer.
\r
894 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
896 // Post the byte. The first time round the loop cTaskWokenByPost
\r
897 // will be pdFALSE. If the queue send causes a task to wake we do
\r
898 // not want the task to run until we have finished the ISR, so
\r
899 // xQueueSendFromISR does not cause a context switch. Also we
\r
900 // don't want subsequent posts to wake any other tasks, so we store
\r
901 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
902 // knows not to wake any task the next iteration of the loop.
\r
903 xTaskWokenByPost = xQueueSendToBackFromISR( xRxQueue, &cIn, cTaskWokenByPost );
\r
905 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
907 // Now the buffer is empty we can switch context if necessary.
\r
908 if( cTaskWokenByPost )
\r
915 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
916 * \ingroup QueueManagement
\r
918 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken, queueSEND_TO_BACK )
\r
923 portBASE_TYPE xQueueSendFromISR(
\r
924 xQueueHandle pxQueue,
\r
925 const void *pvItemToQueue,
\r
926 portBASE_TYPE xTaskPreviouslyWoken
\r
930 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
931 * for backward compatibility with versions of FreeRTOS.org that did not
\r
932 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
935 * Post an item to the back of a queue. It is safe to use this function from
\r
936 * within an interrupt service routine.
\r
938 * Items are queued by copy not reference so it is preferable to only
\r
939 * queue small items, especially when called from an ISR. In most cases
\r
940 * it would be preferable to store a pointer to the item being queued.
\r
942 * @param xQueue The handle to the queue on which the item is to be posted.
\r
944 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
945 * queue. The size of the items the queue will hold was defined when the
\r
946 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
947 * into the queue storage area.
\r
949 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
950 * the same queue multiple times from a single interrupt. The first call
\r
951 * should always pass in pdFALSE. Subsequent calls should pass in
\r
952 * the value returned from the previous call. See the file serial .c in the
\r
953 * PC port for a good example of this mechanism.
\r
955 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
956 * used by the ISR to determine if a context switch may be required following
\r
959 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
962 void vBufferISR( void )
\r
965 portBASE_TYPE xTaskWokenByPost;
\r
967 // We have not woken a task at the start of the ISR.
\r
968 cTaskWokenByPost = pdFALSE;
\r
970 // Loop until the buffer is empty.
\r
973 // Obtain a byte from the buffer.
\r
974 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
976 // Post the byte. The first time round the loop cTaskWokenByPost
\r
977 // will be pdFALSE. If the queue send causes a task to wake we do
\r
978 // not want the task to run until we have finished the ISR, so
\r
979 // xQueueSendFromISR does not cause a context switch. Also we
\r
980 // don't want subsequent posts to wake any other tasks, so we store
\r
981 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
982 // knows not to wake any task the next iteration of the loop.
\r
983 xTaskWokenByPost = xQueueSendFromISR( xRxQueue, &cIn, cTaskWokenByPost );
\r
985 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
987 // Now the buffer is empty we can switch context if necessary.
\r
988 if( cTaskWokenByPost )
\r
995 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
996 * \ingroup QueueManagement
\r
998 #define xQueueSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken, queueSEND_TO_BACK )
\r
1003 portBASE_TYPE xQueueGenericSendFromISR(
\r
1004 xQueueHandle pxQueue,
\r
1005 const void *pvItemToQueue,
\r
1006 portBASE_TYPE xTaskPreviouslyWoken
\r
1007 portBASE_TYPE xCopyPosition
\r
1011 * It is preferred that the macros xQueueSendFromISR(),
\r
1012 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1013 * of calling this function directly.
\r
1015 * Post an item on a queue. It is safe to use this function from within an
\r
1016 * interrupt service routine.
\r
1018 * Items are queued by copy not reference so it is preferable to only
\r
1019 * queue small items, especially when called from an ISR. In most cases
\r
1020 * it would be preferable to store a pointer to the item being queued.
\r
1022 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1024 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1025 * queue. The size of the items the queue will hold was defined when the
\r
1026 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1027 * into the queue storage area.
\r
1029 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
1030 * the same queue multiple times from a single interrupt. The first call
\r
1031 * should always pass in pdFALSE. Subsequent calls should pass in
\r
1032 * the value returned from the previous call. See the file serial .c in the
\r
1033 * PC port for a good example of this mechanism.
\r
1035 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1036 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1037 * at the front of the queue (for high priority messages).
\r
1039 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
1040 * used by the ISR to determine if a context switch may be required following
\r
1043 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1046 void vBufferISR( void )
\r
1049 portBASE_TYPE xTaskWokenByPost;
\r
1051 // We have not woken a task at the start of the ISR.
\r
1052 cTaskWokenByPost = pdFALSE;
\r
1054 // Loop until the buffer is empty.
\r
1057 // Obtain a byte from the buffer.
\r
1058 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1060 // Post the byte. The first time round the loop cTaskWokenByPost
\r
1061 // will be pdFALSE. If the queue send causes a task to wake we do
\r
1062 // not want the task to run until we have finished the ISR, so
\r
1063 // xQueueSendFromISR does not cause a context switch. Also we
\r
1064 // don't want subsequent posts to wake any other tasks, so we store
\r
1065 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
1066 // knows not to wake any task the next iteration of the loop.
\r
1067 xTaskWokenByPost = xQueueGenericSendFromISR( xRxQueue, &cIn, cTaskWokenByPost, queueSEND_TO_BACK );
\r
1069 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1071 // Now the buffer is empty we can switch context if necessary.
\r
1072 if( cTaskWokenByPost )
\r
1079 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1080 * \ingroup QueueManagement
\r
1082 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE xTaskPreviouslyWoken, 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 portCHAR cValueToPost;
\r
1120 const portTickType xBlockTime = ( portTickType )0xff;
\r
1122 // Create a queue capable of containing 10 characters.
\r
1123 xQueue = xQueueCreate( 10, sizeof( portCHAR ) );
\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
1149 portCHAR cRxedChar;
\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 != ( portCHAR ) pdFALSE;
\r
1168 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1169 * \ingroup QueueManagement
\r
1171 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, const 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 const pxQueue );
\r
1178 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle const pxQueue );
\r
1179 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle const 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, const 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 xMutex, portTickType xBlockTime );
\r
1229 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex );
\r
1232 #ifdef __cplusplus
\r
1236 #endif /* QUEUE_H */
\r