2 FreeRTOS.org V5.0.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! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
56 typedef void * xQueueHandle;
\r
58 /* For internal use only. */
\r
59 #define queueSEND_TO_BACK ( 0 )
\r
60 #define queueSEND_TO_FRONT ( 1 )
\r
66 xQueueHandle xQueueCreate(
\r
67 unsigned portBASE_TYPE uxQueueLength,
\r
68 unsigned portBASE_TYPE uxItemSize
\r
72 * Creates a new queue instance. This allocates the storage required by the
\r
73 * new queue and returns a handle for the queue.
\r
75 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
77 * @param uxItemSize The number of bytes each item in the queue will require.
\r
78 * Items are queued by copy, not by reference, so this is the number of bytes
\r
79 * that will be copied for each posted item. Each item on the queue must be
\r
82 * @return If the queue is successfully create then a handle to the newly
\r
83 * created queue is returned. If the queue cannot be created then 0 is
\r
90 portCHAR ucMessageID;
\r
91 portCHAR ucData[ 20 ];
\r
94 void vATask( void *pvParameters )
\r
96 xQueueHandle xQueue1, xQueue2;
\r
98 // Create a queue capable of containing 10 unsigned long values.
\r
99 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
102 // Queue was not created and must not be used.
\r
105 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
106 // These should be passed by pointer as they contain a lot of data.
\r
107 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
110 // Queue was not created and must not be used.
\r
113 // ... Rest of task code.
\r
116 * \defgroup xQueueCreate xQueueCreate
\r
117 * \ingroup QueueManagement
\r
119 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
124 portBASE_TYPE xQueueSendToToFront(
\r
125 xQueueHandle xQueue,
\r
126 const void * pvItemToQueue,
\r
127 portTickType xTicksToWait
\r
131 * This is a macro that calls xQueueGenericSend().
\r
133 * Post an item to the front of a queue. The item is queued by copy, not by
\r
134 * reference. This function must not be called from an interrupt service
\r
135 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
138 * @param xQueue The handle to the queue on which the item is to be posted.
\r
140 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
141 * queue. The size of the items the queue will hold was defined when the
\r
142 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
143 * into the queue storage area.
\r
145 * @param xTicksToWait The maximum amount of time the task should block
\r
146 * waiting for space to become available on the queue, should it already
\r
147 * be full. The call will return immediately if this is set to 0. The
\r
148 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
149 * should be used to convert to real time if this is required.
\r
151 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
157 portCHAR ucMessageID;
\r
158 portCHAR ucData[ 20 ];
\r
161 unsigned portLONG ulVar = 10UL;
\r
163 void vATask( void *pvParameters )
\r
165 xQueueHandle xQueue1, xQueue2;
\r
166 struct AMessage *pxMessage;
\r
168 // Create a queue capable of containing 10 unsigned long values.
\r
169 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
171 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
172 // These should be passed by pointer as they contain a lot of data.
\r
173 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
179 // Send an unsigned long. Wait for 10 ticks for space to become
\r
180 // available if necessary.
\r
181 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
183 // Failed to post the message, even after 10 ticks.
\r
189 // Send a pointer to a struct AMessage object. Don't block if the
\r
190 // queue is already full.
\r
191 pxMessage = & xMessage;
\r
192 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
195 // ... Rest of task code.
\r
198 * \defgroup xQueueSend xQueueSend
\r
199 * \ingroup QueueManagement
\r
201 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
206 portBASE_TYPE xQueueSendToBack(
\r
207 xQueueHandle xQueue,
\r
208 const void * pvItemToQueue,
\r
209 portTickType xTicksToWait
\r
213 * This is a macro that calls xQueueGenericSend().
\r
215 * Post an item to the back of a queue. The item is queued by copy, not by
\r
216 * reference. This function must not be called from an interrupt service
\r
217 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
220 * @param xQueue The handle to the queue on which the item is to be posted.
\r
222 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
223 * queue. The size of the items the queue will hold was defined when the
\r
224 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
225 * into the queue storage area.
\r
227 * @param xTicksToWait The maximum amount of time the task should block
\r
228 * waiting for space to become available on the queue, should it already
\r
229 * be full. The call will return immediately if this is set to 0. The
\r
230 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
231 * should be used to convert to real time if this is required.
\r
233 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
239 portCHAR ucMessageID;
\r
240 portCHAR ucData[ 20 ];
\r
243 unsigned portLONG ulVar = 10UL;
\r
245 void vATask( void *pvParameters )
\r
247 xQueueHandle xQueue1, xQueue2;
\r
248 struct AMessage *pxMessage;
\r
250 // Create a queue capable of containing 10 unsigned long values.
\r
251 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
253 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
254 // These should be passed by pointer as they contain a lot of data.
\r
255 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
261 // Send an unsigned long. Wait for 10 ticks for space to become
\r
262 // available if necessary.
\r
263 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
265 // Failed to post the message, even after 10 ticks.
\r
271 // Send a pointer to a struct AMessage object. Don't block if the
\r
272 // queue is already full.
\r
273 pxMessage = & xMessage;
\r
274 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
277 // ... Rest of task code.
\r
280 * \defgroup xQueueSend xQueueSend
\r
281 * \ingroup QueueManagement
\r
283 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
288 portBASE_TYPE xQueueSend(
\r
289 xQueueHandle xQueue,
\r
290 const void * pvItemToQueue,
\r
291 portTickType xTicksToWait
\r
295 * This is a macro that calls xQueueGenericSend(). It is included for
\r
296 * backward compatibility with versions of FreeRTOS.org that did not
\r
297 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
298 * equivalent to xQueueSendToBack().
\r
300 * Post an item on a queue. The item is queued by copy, not by reference.
\r
301 * This function must not be called from an interrupt service routine.
\r
302 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
304 * @param xQueue The handle to the queue on which the item is to be posted.
\r
306 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
307 * queue. The size of the items the queue will hold was defined when the
\r
308 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
309 * into the queue storage area.
\r
311 * @param xTicksToWait The maximum amount of time the task should block
\r
312 * waiting for space to become available on the queue, should it already
\r
313 * be full. The call will return immediately if this is set to 0. The
\r
314 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
315 * should be used to convert to real time if this is required.
\r
317 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
323 portCHAR ucMessageID;
\r
324 portCHAR ucData[ 20 ];
\r
327 unsigned portLONG ulVar = 10UL;
\r
329 void vATask( void *pvParameters )
\r
331 xQueueHandle xQueue1, xQueue2;
\r
332 struct AMessage *pxMessage;
\r
334 // Create a queue capable of containing 10 unsigned long values.
\r
335 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
337 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
338 // These should be passed by pointer as they contain a lot of data.
\r
339 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
345 // Send an unsigned long. Wait for 10 ticks for space to become
\r
346 // available if necessary.
\r
347 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
349 // Failed to post the message, even after 10 ticks.
\r
355 // Send a pointer to a struct AMessage object. Don't block if the
\r
356 // queue is already full.
\r
357 pxMessage = & xMessage;
\r
358 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
361 // ... Rest of task code.
\r
364 * \defgroup xQueueSend xQueueSend
\r
365 * \ingroup QueueManagement
\r
367 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
373 portBASE_TYPE xQueueGenericSend(
\r
374 xQueueHandle xQueue,
\r
375 const void * pvItemToQueue,
\r
376 portTickType xTicksToWait
\r
377 portBASE_TYPE xCopyPosition
\r
381 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
382 * xQueueSendToBack() are used in place of calling this function directly.
\r
384 * Post an item on a queue. The item is queued by copy, not by reference.
\r
385 * This function must not be called from an interrupt service routine.
\r
386 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
388 * @param xQueue The handle to the queue on which the item is to be posted.
\r
390 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
391 * queue. The size of the items the queue will hold was defined when the
\r
392 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
393 * into the queue storage area.
\r
395 * @param xTicksToWait The maximum amount of time the task should block
\r
396 * waiting for space to become available on the queue, should it already
\r
397 * be full. The call will return immediately if this is set to 0. The
\r
398 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
399 * should be used to convert to real time if this is required.
\r
401 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
402 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
403 * at the front of the queue (for high priority messages).
\r
405 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
411 portCHAR ucMessageID;
\r
412 portCHAR ucData[ 20 ];
\r
415 unsigned portLONG ulVar = 10UL;
\r
417 void vATask( void *pvParameters )
\r
419 xQueueHandle xQueue1, xQueue2;
\r
420 struct AMessage *pxMessage;
\r
422 // Create a queue capable of containing 10 unsigned long values.
\r
423 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
425 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
426 // These should be passed by pointer as they contain a lot of data.
\r
427 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
433 // Send an unsigned long. Wait for 10 ticks for space to become
\r
434 // available if necessary.
\r
435 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
437 // Failed to post the message, even after 10 ticks.
\r
443 // Send a pointer to a struct AMessage object. Don't block if the
\r
444 // queue is already full.
\r
445 pxMessage = & xMessage;
\r
446 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
449 // ... Rest of task code.
\r
452 * \defgroup xQueueSend xQueueSend
\r
453 * \ingroup QueueManagement
\r
455 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
460 portBASE_TYPE xQueuePeek(
\r
461 xQueueHandle xQueue,
\r
463 portTickType xTicksToWait
\r
466 * This is a macro that calls the xQueueGenericReceive() function.
\r
468 * Receive an item from a queue without removing the item from the queue.
\r
469 * The item is received by copy so a buffer of adequate size must be
\r
470 * provided. The number of bytes copied into the buffer was defined when
\r
471 * the queue was created.
\r
473 * Successfully received items remain on the queue so will be returned again
\r
474 * by the next call, or a call to xQueueReceive().
\r
476 * This macro must not be used in an interrupt service routine.
\r
478 * @param pxQueue The handle to the queue from which the item is to be
\r
481 * @param pvBuffer Pointer to the buffer into which the received item will
\r
484 * @param xTicksToWait The maximum amount of time the task should block
\r
485 * waiting for an item to receive should the queue be empty at the time
\r
486 * of the call. The time is defined in tick periods so the constant
\r
487 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
489 * @return pdTRUE if an item was successfully received from the queue,
\r
490 * otherwise pdFALSE.
\r
496 portCHAR ucMessageID;
\r
497 portCHAR ucData[ 20 ];
\r
500 xQueueHandle xQueue;
\r
502 // Task to create a queue and post a value.
\r
503 void vATask( void *pvParameters )
\r
505 struct AMessage *pxMessage;
\r
507 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
508 // These should be passed by pointer as they contain a lot of data.
\r
509 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
512 // Failed to create the queue.
\r
517 // Send a pointer to a struct AMessage object. Don't block if the
\r
518 // queue is already full.
\r
519 pxMessage = & xMessage;
\r
520 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
522 // ... Rest of task code.
\r
525 // Task to peek the data from the queue.
\r
526 void vADifferentTask( void *pvParameters )
\r
528 struct AMessage *pxRxedMessage;
\r
532 // Peek a message on the created queue. Block for 10 ticks if a
\r
533 // message is not immediately available.
\r
534 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
536 // pcRxedMessage now points to the struct AMessage variable posted
\r
537 // by vATask, but the item still remains on the queue.
\r
541 // ... Rest of task code.
\r
544 * \defgroup xQueueReceive xQueueReceive
\r
545 * \ingroup QueueManagement
\r
547 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
552 portBASE_TYPE xQueueReceive(
\r
553 xQueueHandle xQueue,
\r
555 portTickType xTicksToWait
\r
558 * This is a macro that calls the xQueueGenericReceive() function.
\r
560 * Receive an item from a queue. The item is received by copy so a buffer of
\r
561 * adequate size must be provided. The number of bytes copied into the buffer
\r
562 * was defined when the queue was created.
\r
564 * Successfully received items are removed from the queue.
\r
566 * This function must not be used in an interrupt service routine. See
\r
567 * xQueueReceiveFromISR for an alternative that can.
\r
569 * @param pxQueue The handle to the queue from which the item is to be
\r
572 * @param pvBuffer Pointer to the buffer into which the received item will
\r
575 * @param xTicksToWait The maximum amount of time the task should block
\r
576 * waiting for an item to receive should the queue be empty at the time
\r
577 * of the call. The time is defined in tick periods so the constant
\r
578 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
580 * @return pdTRUE if an item was successfully received from the queue,
\r
581 * otherwise pdFALSE.
\r
587 portCHAR ucMessageID;
\r
588 portCHAR ucData[ 20 ];
\r
591 xQueueHandle xQueue;
\r
593 // Task to create a queue and post a value.
\r
594 void vATask( void *pvParameters )
\r
596 struct AMessage *pxMessage;
\r
598 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
599 // These should be passed by pointer as they contain a lot of data.
\r
600 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
603 // Failed to create the queue.
\r
608 // Send a pointer to a struct AMessage object. Don't block if the
\r
609 // queue is already full.
\r
610 pxMessage = & xMessage;
\r
611 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
613 // ... Rest of task code.
\r
616 // Task to receive from the queue.
\r
617 void vADifferentTask( void *pvParameters )
\r
619 struct AMessage *pxRxedMessage;
\r
623 // Receive a message on the created queue. Block for 10 ticks if a
\r
624 // message is not immediately available.
\r
625 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
627 // pcRxedMessage now points to the struct AMessage variable posted
\r
632 // ... Rest of task code.
\r
635 * \defgroup xQueueReceive xQueueReceive
\r
636 * \ingroup QueueManagement
\r
638 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
644 portBASE_TYPE xQueueGenericReceive(
\r
645 xQueueHandle xQueue,
\r
647 portTickType xTicksToWait
\r
648 portBASE_TYPE xJustPeek
\r
651 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
652 * this function directly.
\r
654 * Receive an item from a queue. The item is received by copy so a buffer of
\r
655 * adequate size must be provided. The number of bytes copied into the buffer
\r
656 * was defined when the queue was created.
\r
658 * This function must not be used in an interrupt service routine. See
\r
659 * xQueueReceiveFromISR for an alternative that can.
\r
661 * @param pxQueue The handle to the queue from which the item is to be
\r
664 * @param pvBuffer Pointer to the buffer into which the received item will
\r
667 * @param xTicksToWait The maximum amount of time the task should block
\r
668 * waiting for an item to receive should the queue be empty at the time
\r
669 * of the call. The time is defined in tick periods so the constant
\r
670 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
672 * @param xJustPeek When set to true, the item received from the queue is not
\r
673 * actually removed from the queue - meaning a subsequent call to
\r
674 * xQueueReceive() will return the same item. When set to false, the item
\r
675 * being received from the queue is also removed from the queue.
\r
677 * @return pdTRUE if an item was successfully received from the queue,
\r
678 * otherwise pdFALSE.
\r
684 portCHAR ucMessageID;
\r
685 portCHAR ucData[ 20 ];
\r
688 xQueueHandle xQueue;
\r
690 // Task to create a queue and post a value.
\r
691 void vATask( void *pvParameters )
\r
693 struct AMessage *pxMessage;
\r
695 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
696 // These should be passed by pointer as they contain a lot of data.
\r
697 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
700 // Failed to create the queue.
\r
705 // Send a pointer to a struct AMessage object. Don't block if the
\r
706 // queue is already full.
\r
707 pxMessage = & xMessage;
\r
708 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
710 // ... Rest of task code.
\r
713 // Task to receive from the queue.
\r
714 void vADifferentTask( void *pvParameters )
\r
716 struct AMessage *pxRxedMessage;
\r
720 // Receive a message on the created queue. Block for 10 ticks if a
\r
721 // message is not immediately available.
\r
722 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
724 // pcRxedMessage now points to the struct AMessage variable posted
\r
729 // ... Rest of task code.
\r
732 * \defgroup xQueueReceive xQueueReceive
\r
733 * \ingroup QueueManagement
\r
735 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
739 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
741 * Return the number of messages stored in a queue.
\r
743 * @param xQueue A handle to the queue being queried.
\r
745 * @return The number of messages available in the queue.
\r
747 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
748 * \ingroup QueueManagement
\r
750 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
754 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
756 * Delete a queue - freeing all the memory allocated for storing of items
\r
757 * placed on the queue.
\r
759 * @param xQueue A handle to the queue to be deleted.
\r
761 * \page vQueueDelete vQueueDelete
\r
762 * \ingroup QueueManagement
\r
764 void vQueueDelete( xQueueHandle xQueue );
\r
769 portBASE_TYPE xQueueSendToFrontFromISR(
\r
770 xQueueHandle pxQueue,
\r
771 const void *pvItemToQueue,
\r
772 portBASE_TYPE xTaskPreviouslyWoken
\r
776 * This is a macro that calls xQueueGenericSendFromISR().
\r
778 * Post an item to the front of a queue. It is safe to use this macro from
\r
779 * within an interrupt service routine.
\r
781 * Items are queued by copy not reference so it is preferable to only
\r
782 * queue small items, especially when called from an ISR. In most cases
\r
783 * it would be preferable to store a pointer to the item being queued.
\r
785 * @param xQueue The handle to the queue on which the item is to be posted.
\r
787 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
788 * queue. The size of the items the queue will hold was defined when the
\r
789 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
790 * into the queue storage area.
\r
792 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
\r
793 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
794 * to unblock, and the unblocked task has a priority higher than the currently
\r
795 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
\r
796 * a context switch should be requested before the interrupt is exited.
\r
798 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\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 xHigherPrioritTaskWoken;
\r
809 // We have not woken a task at the start of the ISR.
\r
810 xHigherPriorityTaskWoken = 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
819 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
821 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
823 // Now the buffer is empty we can switch context if necessary.
\r
824 if( xHigherPriorityTaskWoken )
\r
831 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
832 * \ingroup QueueManagement
\r
834 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_FRONT )
\r
840 portBASE_TYPE xQueueSendToBackFromISR(
\r
841 xQueueHandle pxQueue,
\r
842 const void *pvItemToQueue,
\r
843 portBASE_TYPE xTaskPreviouslyWoken
\r
847 * This is a macro that calls xQueueGenericSendFromISR().
\r
849 * Post an item to the back of a queue. It is safe to use this macro from
\r
850 * within an interrupt service routine.
\r
852 * Items are queued by copy not reference so it is preferable to only
\r
853 * queue small items, especially when called from an ISR. In most cases
\r
854 * it would be preferable to store a pointer to the item being queued.
\r
856 * @param xQueue The handle to the queue on which the item is to be posted.
\r
858 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
859 * queue. The size of the items the queue will hold was defined when the
\r
860 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
861 * into the queue storage area.
\r
863 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
\r
864 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
865 * to unblock, and the unblocked task has a priority higher than the currently
\r
866 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
\r
867 * a context switch should be requested before the interrupt is exited.
\r
869 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
872 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
875 void vBufferISR( void )
\r
878 portBASE_TYPE xHigherPriorityTaskWoken;
\r
880 // We have not woken a task at the start of the ISR.
\r
881 xHigherPriorityTaskWoken = pdFALSE;
\r
883 // Loop until the buffer is empty.
\r
886 // Obtain a byte from the buffer.
\r
887 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
890 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
892 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
894 // Now the buffer is empty we can switch context if necessary.
\r
895 if( xHigherPriorityTaskWoken )
\r
902 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
903 * \ingroup QueueManagement
\r
905 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
910 portBASE_TYPE xQueueSendFromISR(
\r
911 xQueueHandle pxQueue,
\r
912 const void *pvItemToQueue,
\r
913 portBASE_TYPE xTaskPreviouslyWoken
\r
917 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
918 * for backward compatibility with versions of FreeRTOS.org that did not
\r
919 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
922 * Post an item to the back of a queue. It is safe to use this function from
\r
923 * within an interrupt service routine.
\r
925 * Items are queued by copy not reference so it is preferable to only
\r
926 * queue small items, especially when called from an ISR. In most cases
\r
927 * it would be preferable to store a pointer to the item being queued.
\r
929 * @param xQueue The handle to the queue on which the item is to be posted.
\r
931 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
932 * queue. The size of the items the queue will hold was defined when the
\r
933 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
934 * into the queue storage area.
\r
936 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
\r
937 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
938 * to unblock, and the unblocked task has a priority higher than the currently
\r
939 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
940 * a context switch should be requested before the interrupt is exited.
\r
942 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
945 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
948 void vBufferISR( void )
\r
951 portBASE_TYPE xHigherPriorityTaskWoken;
\r
953 // We have not woken a task at the start of the ISR.
\r
954 xHigherPriorityTaskWoken = pdFALSE;
\r
956 // Loop until the buffer is empty.
\r
959 // Obtain a byte from the buffer.
\r
960 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
963 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
965 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
967 // Now the buffer is empty we can switch context if necessary.
\r
968 if( xHigherPriorityTaskWoken )
\r
970 // Actual macro used here is port specific.
\r
971 taskYIELD_FROM_ISR ();
\r
976 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
977 * \ingroup QueueManagement
\r
979 #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
984 portBASE_TYPE xQueueGenericSendFromISR(
\r
985 xQueueHandle pxQueue,
\r
986 const void *pvItemToQueue,
\r
987 portBASE_TYPE *pxHigherPriorityTaskWoken,
\r
988 portBASE_TYPE xCopyPosition
\r
992 * It is preferred that the macros xQueueSendFromISR(),
\r
993 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
994 * of calling this function directly.
\r
996 * Post an item on a queue. It is safe to use this function from within an
\r
997 * interrupt service routine.
\r
999 * Items are queued by copy not reference so it is preferable to only
\r
1000 * queue small items, especially when called from an ISR. In most cases
\r
1001 * it would be preferable to store a pointer to the item being queued.
\r
1003 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1005 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1006 * queue. The size of the items the queue will hold was defined when the
\r
1007 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1008 * into the queue storage area.
\r
1010 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
\r
1011 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1012 * to unblock, and the unblocked task has a priority higher than the currently
\r
1013 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
\r
1014 * a context switch should be requested before the interrupt is exited.
\r
1016 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1017 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1018 * at the front of the queue (for high priority messages).
\r
1020 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1023 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1026 void vBufferISR( void )
\r
1029 portBASE_TYPE xHigherPriorityTaskWokenByPost;
\r
1031 // We have not woken a task at the start of the ISR.
\r
1032 xHigherPriorityTaskWokenByPost = pdFALSE;
\r
1034 // Loop until the buffer is empty.
\r
1037 // Obtain a byte from the buffer.
\r
1038 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1040 // Post each byte.
\r
1041 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
\r
1043 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1045 // Now the buffer is empty we can switch context if necessary. Note that the
\r
1046 // name of the yield function required is port specific.
\r
1047 if( xHigherPriorityTaskWokenByPost )
\r
1049 taskYIELD_YIELD_FROM_ISR();
\r
1054 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1055 * \ingroup QueueManagement
\r
1057 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
\r
1062 portBASE_TYPE xQueueReceiveFromISR(
\r
1063 xQueueHandle pxQueue,
\r
1065 portBASE_TYPE *pxTaskWoken
\r
1069 * Receive an item from a queue. It is safe to use this function from within an
\r
1070 * interrupt service routine.
\r
1072 * @param pxQueue The handle to the queue from which the item is to be
\r
1075 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1078 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1079 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1080 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1081 * remain unchanged.
\r
1083 * @return pdTRUE if an item was successfully received from the queue,
\r
1084 * otherwise pdFALSE.
\r
1089 xQueueHandle xQueue;
\r
1091 // Function to create a queue and post some values.
\r
1092 void vAFunction( void *pvParameters )
\r
1094 portCHAR cValueToPost;
\r
1095 const portTickType xBlockTime = ( portTickType )0xff;
\r
1097 // Create a queue capable of containing 10 characters.
\r
1098 xQueue = xQueueCreate( 10, sizeof( portCHAR ) );
\r
1101 // Failed to create the queue.
\r
1106 // Post some characters that will be used within an ISR. If the queue
\r
1107 // is full then this task will block for xBlockTime ticks.
\r
1108 cValueToPost = 'a';
\r
1109 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1110 cValueToPost = 'b';
\r
1111 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1113 // ... keep posting characters ... this task may block when the queue
\r
1116 cValueToPost = 'c';
\r
1117 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1120 // ISR that outputs all the characters received on the queue.
\r
1121 void vISR_Routine( void )
\r
1123 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1124 portCHAR cRxedChar;
\r
1126 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1128 // A character was received. Output the character now.
\r
1129 vOutputCharacter( cRxedChar );
\r
1131 // If removing the character from the queue woke the task that was
\r
1132 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1133 // pdTRUE. No matter how many times this loop iterates only one
\r
1134 // task will be woken.
\r
1137 if( cTaskWokenByPost != ( portCHAR ) pdFALSE;
\r
1143 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1144 * \ingroup QueueManagement
\r
1146 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1149 * Utilities to query queue that are safe to use from an ISR. These utilities
\r
1150 * should be used only from witin an ISR, or within a critical section.
\r
1152 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
\r
1153 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
\r
1154 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
\r
1158 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1159 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1160 * xQueueGenericReceive().
\r
1162 * The source code that implements the alternative (Alt) API is much
\r
1163 * simpler because it executes everything from within a critical section.
\r
1164 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1165 * preferred fully featured API too. The fully featured API has more
\r
1166 * complex code that takes longer to execute, but makes much less use of
\r
1167 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1168 * responsiveness to gain execution speed, whereas the fully featured API
\r
1169 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1171 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1172 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1173 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
1174 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
1175 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
1176 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
1179 * The functions defined above are for passing data to and from tasks. The
\r
1180 * functions below are the equivalents for passing data to and from
\r
1183 * These functions are called from the co-routine macro implementation and
\r
1184 * should not be called directly from application code. Instead use the macro
\r
1185 * wrappers defined within croutine.h.
\r
1187 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1188 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1189 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1190 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1193 * For internal use only. Use xSemaphoreCreateMutex() or
\r
1194 * xSemaphoreCreateCounting() instead of calling these functions directly.
\r
1196 xQueueHandle xQueueCreateMutex( void );
\r
1197 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1200 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1201 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1203 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
\r
1204 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex );
\r
1207 #ifdef __cplusplus
\r
1211 #endif /* QUEUE_H */
\r