FreeRTOS
[armadillo_firmware.git] / FreeRTOS / Source / include / queue.h
blob4d357169179c7552d99e094ec2157dc906197baf
1 /*
2 FreeRTOS V6.0.5 - Copyright (C) 2010 Real Time Engineers Ltd.
4 ***************************************************************************
5 * *
6 * If you are: *
7 * *
8 * + New to FreeRTOS, *
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
10 * + Looking for basic training, *
11 * + Wanting to improve your FreeRTOS skills and productivity *
12 * *
13 * then take a look at the FreeRTOS eBook *
14 * *
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
16 * http://www.FreeRTOS.org/Documentation *
17 * *
18 * A pdf reference manual is also available. Both are usually delivered *
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
20 * and 8pm GMT (although please allow up to 24 hours in case of *
21 * exceptional circumstances). Thank you for your support! *
22 * *
23 ***************************************************************************
25 This file is part of the FreeRTOS distribution.
27 FreeRTOS is free software; you can redistribute it and/or modify it under
28 the terms of the GNU General Public License (version 2) as published by the
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30 ***NOTE*** The exception to the GPL is included to allow you to distribute
31 a combined work that includes FreeRTOS without being obliged to provide the
32 source code for proprietary components outside of the FreeRTOS kernel.
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
36 more details. You should have received a copy of the GNU General Public
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
39 by writing to Richard Barry, contact details for whom are available on the
40 FreeRTOS WEB site.
42 1 tab == 4 spaces!
44 http://www.FreeRTOS.org - Documentation, latest information, license and
45 contact details.
47 http://www.SafeRTOS.com - A version that is certified for use in safety
48 critical systems.
50 http://www.OpenRTOS.com - Commercial support, development, porting,
51 licensing and training services.
54 #ifndef INC_FREERTOS_H
55 #error "#include FreeRTOS.h" must appear in source files before "#include queue.h"
56 #endif
61 #ifndef QUEUE_H
62 #define QUEUE_H
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
69 #include "mpu_wrappers.h"
72 typedef void * xQueueHandle;
75 /* For internal use only. */
76 #define queueSEND_TO_BACK ( 0 )
77 #define queueSEND_TO_FRONT ( 1 )
80 /**
81 * queue. h
82 * <pre>
83 xQueueHandle xQueueCreate(
84 unsigned portBASE_TYPE uxQueueLength,
85 unsigned portBASE_TYPE uxItemSize
87 * </pre>
89 * Creates a new queue instance. This allocates the storage required by the
90 * new queue and returns a handle for the queue.
92 * @param uxQueueLength The maximum number of items that the queue can contain.
94 * @param uxItemSize The number of bytes each item in the queue will require.
95 * Items are queued by copy, not by reference, so this is the number of bytes
96 * that will be copied for each posted item. Each item on the queue must be
97 * the same size.
99 * @return If the queue is successfully create then a handle to the newly
100 * created queue is returned. If the queue cannot be created then 0 is
101 * returned.
103 * Example usage:
104 <pre>
105 struct AMessage
107 char ucMessageID;
108 char ucData[ 20 ];
111 void vATask( void *pvParameters )
113 xQueueHandle xQueue1, xQueue2;
115 // Create a queue capable of containing 10 unsigned long values.
116 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
117 if( xQueue1 == 0 )
119 // Queue was not created and must not be used.
122 // Create a queue capable of containing 10 pointers to AMessage structures.
123 // These should be passed by pointer as they contain a lot of data.
124 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
125 if( xQueue2 == 0 )
127 // Queue was not created and must not be used.
130 // ... Rest of task code.
132 </pre>
133 * \defgroup xQueueCreate xQueueCreate
134 * \ingroup QueueManagement
136 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
139 * queue. h
140 * <pre>
141 portBASE_TYPE xQueueSendToToFront(
142 xQueueHandle xQueue,
143 const void * pvItemToQueue,
144 portTickType xTicksToWait
146 * </pre>
148 * This is a macro that calls xQueueGenericSend().
150 * Post an item to the front of a queue. The item is queued by copy, not by
151 * reference. This function must not be called from an interrupt service
152 * routine. See xQueueSendFromISR () for an alternative which may be used
153 * in an ISR.
155 * @param xQueue The handle to the queue on which the item is to be posted.
157 * @param pvItemToQueue A pointer to the item that is to be placed on the
158 * queue. The size of the items the queue will hold was defined when the
159 * queue was created, so this many bytes will be copied from pvItemToQueue
160 * into the queue storage area.
162 * @param xTicksToWait The maximum amount of time the task should block
163 * waiting for space to become available on the queue, should it already
164 * be full. The call will return immediately if this is set to 0 and the
165 * queue is full. The time is defined in tick periods so the constant
166 * portTICK_RATE_MS should be used to convert to real time if this is required.
168 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
170 * Example usage:
171 <pre>
172 struct AMessage
174 char ucMessageID;
175 char ucData[ 20 ];
176 } xMessage;
178 unsigned long ulVar = 10UL;
180 void vATask( void *pvParameters )
182 xQueueHandle xQueue1, xQueue2;
183 struct AMessage *pxMessage;
185 // Create a queue capable of containing 10 unsigned long values.
186 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
188 // Create a queue capable of containing 10 pointers to AMessage structures.
189 // These should be passed by pointer as they contain a lot of data.
190 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
192 // ...
194 if( xQueue1 != 0 )
196 // Send an unsigned long. Wait for 10 ticks for space to become
197 // available if necessary.
198 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
200 // Failed to post the message, even after 10 ticks.
204 if( xQueue2 != 0 )
206 // Send a pointer to a struct AMessage object. Don't block if the
207 // queue is already full.
208 pxMessage = & xMessage;
209 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
212 // ... Rest of task code.
214 </pre>
215 * \defgroup xQueueSend xQueueSend
216 * \ingroup QueueManagement
218 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
221 * queue. h
222 * <pre>
223 portBASE_TYPE xQueueSendToBack(
224 xQueueHandle xQueue,
225 const void * pvItemToQueue,
226 portTickType xTicksToWait
228 * </pre>
230 * This is a macro that calls xQueueGenericSend().
232 * Post an item to the back of a queue. The item is queued by copy, not by
233 * reference. This function must not be called from an interrupt service
234 * routine. See xQueueSendFromISR () for an alternative which may be used
235 * in an ISR.
237 * @param xQueue The handle to the queue on which the item is to be posted.
239 * @param pvItemToQueue A pointer to the item that is to be placed on the
240 * queue. The size of the items the queue will hold was defined when the
241 * queue was created, so this many bytes will be copied from pvItemToQueue
242 * into the queue storage area.
244 * @param xTicksToWait The maximum amount of time the task should block
245 * waiting for space to become available on the queue, should it already
246 * be full. The call will return immediately if this is set to 0 and the queue
247 * is full. The time is defined in tick periods so the constant
248 * portTICK_RATE_MS should be used to convert to real time if this is required.
250 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
252 * Example usage:
253 <pre>
254 struct AMessage
256 char ucMessageID;
257 char ucData[ 20 ];
258 } xMessage;
260 unsigned long ulVar = 10UL;
262 void vATask( void *pvParameters )
264 xQueueHandle xQueue1, xQueue2;
265 struct AMessage *pxMessage;
267 // Create a queue capable of containing 10 unsigned long values.
268 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
270 // Create a queue capable of containing 10 pointers to AMessage structures.
271 // These should be passed by pointer as they contain a lot of data.
272 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
274 // ...
276 if( xQueue1 != 0 )
278 // Send an unsigned long. Wait for 10 ticks for space to become
279 // available if necessary.
280 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
282 // Failed to post the message, even after 10 ticks.
286 if( xQueue2 != 0 )
288 // Send a pointer to a struct AMessage object. Don't block if the
289 // queue is already full.
290 pxMessage = & xMessage;
291 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
294 // ... Rest of task code.
296 </pre>
297 * \defgroup xQueueSend xQueueSend
298 * \ingroup QueueManagement
300 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
303 * queue. h
304 * <pre>
305 portBASE_TYPE xQueueSend(
306 xQueueHandle xQueue,
307 const void * pvItemToQueue,
308 portTickType xTicksToWait
310 * </pre>
312 * This is a macro that calls xQueueGenericSend(). It is included for
313 * backward compatibility with versions of FreeRTOS.org that did not
314 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
315 * equivalent to xQueueSendToBack().
317 * Post an item on a queue. The item is queued by copy, not by reference.
318 * This function must not be called from an interrupt service routine.
319 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
321 * @param xQueue The handle to the queue on which the item is to be posted.
323 * @param pvItemToQueue A pointer to the item that is to be placed on the
324 * queue. The size of the items the queue will hold was defined when the
325 * queue was created, so this many bytes will be copied from pvItemToQueue
326 * into the queue storage area.
328 * @param xTicksToWait The maximum amount of time the task should block
329 * waiting for space to become available on the queue, should it already
330 * be full. The call will return immediately if this is set to 0 and the
331 * queue is full. The time is defined in tick periods so the constant
332 * portTICK_RATE_MS should be used to convert to real time if this is required.
334 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
336 * Example usage:
337 <pre>
338 struct AMessage
340 char ucMessageID;
341 char ucData[ 20 ];
342 } xMessage;
344 unsigned long ulVar = 10UL;
346 void vATask( void *pvParameters )
348 xQueueHandle xQueue1, xQueue2;
349 struct AMessage *pxMessage;
351 // Create a queue capable of containing 10 unsigned long values.
352 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
354 // Create a queue capable of containing 10 pointers to AMessage structures.
355 // These should be passed by pointer as they contain a lot of data.
356 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
358 // ...
360 if( xQueue1 != 0 )
362 // Send an unsigned long. Wait for 10 ticks for space to become
363 // available if necessary.
364 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
366 // Failed to post the message, even after 10 ticks.
370 if( xQueue2 != 0 )
372 // Send a pointer to a struct AMessage object. Don't block if the
373 // queue is already full.
374 pxMessage = & xMessage;
375 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
378 // ... Rest of task code.
380 </pre>
381 * \defgroup xQueueSend xQueueSend
382 * \ingroup QueueManagement
384 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
388 * queue. h
389 * <pre>
390 portBASE_TYPE xQueueGenericSend(
391 xQueueHandle xQueue,
392 const void * pvItemToQueue,
393 portTickType xTicksToWait
394 portBASE_TYPE xCopyPosition
396 * </pre>
398 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
399 * xQueueSendToBack() are used in place of calling this function directly.
401 * Post an item on a queue. The item is queued by copy, not by reference.
402 * This function must not be called from an interrupt service routine.
403 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
405 * @param xQueue The handle to the queue on which the item is to be posted.
407 * @param pvItemToQueue A pointer to the item that is to be placed on the
408 * queue. The size of the items the queue will hold was defined when the
409 * queue was created, so this many bytes will be copied from pvItemToQueue
410 * into the queue storage area.
412 * @param xTicksToWait The maximum amount of time the task should block
413 * waiting for space to become available on the queue, should it already
414 * be full. The call will return immediately if this is set to 0 and the
415 * queue is full. The time is defined in tick periods so the constant
416 * portTICK_RATE_MS should be used to convert to real time if this is required.
418 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
419 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
420 * at the front of the queue (for high priority messages).
422 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
424 * Example usage:
425 <pre>
426 struct AMessage
428 char ucMessageID;
429 char ucData[ 20 ];
430 } xMessage;
432 unsigned long ulVar = 10UL;
434 void vATask( void *pvParameters )
436 xQueueHandle xQueue1, xQueue2;
437 struct AMessage *pxMessage;
439 // Create a queue capable of containing 10 unsigned long values.
440 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
442 // Create a queue capable of containing 10 pointers to AMessage structures.
443 // These should be passed by pointer as they contain a lot of data.
444 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
446 // ...
448 if( xQueue1 != 0 )
450 // Send an unsigned long. Wait for 10 ticks for space to become
451 // available if necessary.
452 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
454 // Failed to post the message, even after 10 ticks.
458 if( xQueue2 != 0 )
460 // Send a pointer to a struct AMessage object. Don't block if the
461 // queue is already full.
462 pxMessage = & xMessage;
463 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
466 // ... Rest of task code.
468 </pre>
469 * \defgroup xQueueSend xQueueSend
470 * \ingroup QueueManagement
472 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
475 * queue. h
476 * <pre>
477 portBASE_TYPE xQueuePeek(
478 xQueueHandle xQueue,
479 void *pvBuffer,
480 portTickType xTicksToWait
481 );</pre>
483 * This is a macro that calls the xQueueGenericReceive() function.
485 * Receive an item from a queue without removing the item from the queue.
486 * The item is received by copy so a buffer of adequate size must be
487 * provided. The number of bytes copied into the buffer was defined when
488 * the queue was created.
490 * Successfully received items remain on the queue so will be returned again
491 * by the next call, or a call to xQueueReceive().
493 * This macro must not be used in an interrupt service routine.
495 * @param pxQueue The handle to the queue from which the item is to be
496 * received.
498 * @param pvBuffer Pointer to the buffer into which the received item will
499 * be copied.
501 * @param xTicksToWait The maximum amount of time the task should block
502 * waiting for an item to receive should the queue be empty at the time
503 * of the call. The time is defined in tick periods so the constant
504 * portTICK_RATE_MS should be used to convert to real time if this is required.
505 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
506 * is empty.
508 * @return pdTRUE if an item was successfully received from the queue,
509 * otherwise pdFALSE.
511 * Example usage:
512 <pre>
513 struct AMessage
515 char ucMessageID;
516 char ucData[ 20 ];
517 } xMessage;
519 xQueueHandle xQueue;
521 // Task to create a queue and post a value.
522 void vATask( void *pvParameters )
524 struct AMessage *pxMessage;
526 // Create a queue capable of containing 10 pointers to AMessage structures.
527 // These should be passed by pointer as they contain a lot of data.
528 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
529 if( xQueue == 0 )
531 // Failed to create the queue.
534 // ...
536 // Send a pointer to a struct AMessage object. Don't block if the
537 // queue is already full.
538 pxMessage = & xMessage;
539 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
541 // ... Rest of task code.
544 // Task to peek the data from the queue.
545 void vADifferentTask( void *pvParameters )
547 struct AMessage *pxRxedMessage;
549 if( xQueue != 0 )
551 // Peek a message on the created queue. Block for 10 ticks if a
552 // message is not immediately available.
553 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
555 // pcRxedMessage now points to the struct AMessage variable posted
556 // by vATask, but the item still remains on the queue.
560 // ... Rest of task code.
562 </pre>
563 * \defgroup xQueueReceive xQueueReceive
564 * \ingroup QueueManagement
566 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
569 * queue. h
570 * <pre>
571 portBASE_TYPE xQueueReceive(
572 xQueueHandle xQueue,
573 void *pvBuffer,
574 portTickType xTicksToWait
575 );</pre>
577 * This is a macro that calls the xQueueGenericReceive() function.
579 * Receive an item from a queue. The item is received by copy so a buffer of
580 * adequate size must be provided. The number of bytes copied into the buffer
581 * was defined when the queue was created.
583 * Successfully received items are removed from the queue.
585 * This function must not be used in an interrupt service routine. See
586 * xQueueReceiveFromISR for an alternative that can.
588 * @param pxQueue The handle to the queue from which the item is to be
589 * received.
591 * @param pvBuffer Pointer to the buffer into which the received item will
592 * be copied.
594 * @param xTicksToWait The maximum amount of time the task should block
595 * waiting for an item to receive should the queue be empty at the time
596 * of the call. xQueueReceive() will return immediately if xTicksToWait
597 * is zero and the queue is empty. The time is defined in tick periods so the
598 * constant portTICK_RATE_MS should be used to convert to real time if this is
599 * required.
601 * @return pdTRUE if an item was successfully received from the queue,
602 * otherwise pdFALSE.
604 * Example usage:
605 <pre>
606 struct AMessage
608 char ucMessageID;
609 char ucData[ 20 ];
610 } xMessage;
612 xQueueHandle xQueue;
614 // Task to create a queue and post a value.
615 void vATask( void *pvParameters )
617 struct AMessage *pxMessage;
619 // Create a queue capable of containing 10 pointers to AMessage structures.
620 // These should be passed by pointer as they contain a lot of data.
621 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
622 if( xQueue == 0 )
624 // Failed to create the queue.
627 // ...
629 // Send a pointer to a struct AMessage object. Don't block if the
630 // queue is already full.
631 pxMessage = & xMessage;
632 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
634 // ... Rest of task code.
637 // Task to receive from the queue.
638 void vADifferentTask( void *pvParameters )
640 struct AMessage *pxRxedMessage;
642 if( xQueue != 0 )
644 // Receive a message on the created queue. Block for 10 ticks if a
645 // message is not immediately available.
646 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
648 // pcRxedMessage now points to the struct AMessage variable posted
649 // by vATask.
653 // ... Rest of task code.
655 </pre>
656 * \defgroup xQueueReceive xQueueReceive
657 * \ingroup QueueManagement
659 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
663 * queue. h
664 * <pre>
665 portBASE_TYPE xQueueGenericReceive(
666 xQueueHandle xQueue,
667 void *pvBuffer,
668 portTickType xTicksToWait
669 portBASE_TYPE xJustPeek
670 );</pre>
672 * It is preferred that the macro xQueueReceive() be used rather than calling
673 * this function directly.
675 * Receive an item from a queue. The item is received by copy so a buffer of
676 * adequate size must be provided. The number of bytes copied into the buffer
677 * was defined when the queue was created.
679 * This function must not be used in an interrupt service routine. See
680 * xQueueReceiveFromISR for an alternative that can.
682 * @param pxQueue The handle to the queue from which the item is to be
683 * received.
685 * @param pvBuffer Pointer to the buffer into which the received item will
686 * be copied.
688 * @param xTicksToWait The maximum amount of time the task should block
689 * waiting for an item to receive should the queue be empty at the time
690 * of the call. The time is defined in tick periods so the constant
691 * portTICK_RATE_MS should be used to convert to real time if this is required.
692 * xQueueGenericReceive() will return immediately if the queue is empty and
693 * xTicksToWait is 0.
695 * @param xJustPeek When set to true, the item received from the queue is not
696 * actually removed from the queue - meaning a subsequent call to
697 * xQueueReceive() will return the same item. When set to false, the item
698 * being received from the queue is also removed from the queue.
700 * @return pdTRUE if an item was successfully received from the queue,
701 * otherwise pdFALSE.
703 * Example usage:
704 <pre>
705 struct AMessage
707 char ucMessageID;
708 char ucData[ 20 ];
709 } xMessage;
711 xQueueHandle xQueue;
713 // Task to create a queue and post a value.
714 void vATask( void *pvParameters )
716 struct AMessage *pxMessage;
718 // Create a queue capable of containing 10 pointers to AMessage structures.
719 // These should be passed by pointer as they contain a lot of data.
720 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
721 if( xQueue == 0 )
723 // Failed to create the queue.
726 // ...
728 // Send a pointer to a struct AMessage object. Don't block if the
729 // queue is already full.
730 pxMessage = & xMessage;
731 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
733 // ... Rest of task code.
736 // Task to receive from the queue.
737 void vADifferentTask( void *pvParameters )
739 struct AMessage *pxRxedMessage;
741 if( xQueue != 0 )
743 // Receive a message on the created queue. Block for 10 ticks if a
744 // message is not immediately available.
745 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
747 // pcRxedMessage now points to the struct AMessage variable posted
748 // by vATask.
752 // ... Rest of task code.
754 </pre>
755 * \defgroup xQueueReceive xQueueReceive
756 * \ingroup QueueManagement
758 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
761 * queue. h
762 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
764 * Return the number of messages stored in a queue.
766 * @param xQueue A handle to the queue being queried.
768 * @return The number of messages available in the queue.
770 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
771 * \ingroup QueueManagement
773 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
776 * queue. h
777 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
779 * Delete a queue - freeing all the memory allocated for storing of items
780 * placed on the queue.
782 * @param xQueue A handle to the queue to be deleted.
784 * \page vQueueDelete vQueueDelete
785 * \ingroup QueueManagement
787 void vQueueDelete( xQueueHandle xQueue );
790 * queue. h
791 * <pre>
792 portBASE_TYPE xQueueSendToFrontFromISR(
793 xQueueHandle pxQueue,
794 const void *pvItemToQueue,
795 portBASE_TYPE *pxHigherPriorityTaskWoken
797 </pre>
799 * This is a macro that calls xQueueGenericSendFromISR().
801 * Post an item to the front of a queue. It is safe to use this macro from
802 * within an interrupt service routine.
804 * Items are queued by copy not reference so it is preferable to only
805 * queue small items, especially when called from an ISR. In most cases
806 * it would be preferable to store a pointer to the item being queued.
808 * @param xQueue The handle to the queue on which the item is to be posted.
810 * @param pvItemToQueue A pointer to the item that is to be placed on the
811 * queue. The size of the items the queue will hold was defined when the
812 * queue was created, so this many bytes will be copied from pvItemToQueue
813 * into the queue storage area.
815 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
816 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
817 * to unblock, and the unblocked task has a priority higher than the currently
818 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
819 * a context switch should be requested before the interrupt is exited.
821 * @return pdTRUE if the data was successfully sent to the queue, otherwise
822 * errQUEUE_FULL.
824 * Example usage for buffered IO (where the ISR can obtain more than one value
825 * per call):
826 <pre>
827 void vBufferISR( void )
829 char cIn;
830 portBASE_TYPE xHigherPrioritTaskWoken;
832 // We have not woken a task at the start of the ISR.
833 xHigherPriorityTaskWoken = pdFALSE;
835 // Loop until the buffer is empty.
838 // Obtain a byte from the buffer.
839 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
841 // Post the byte.
842 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
844 } while( portINPUT_BYTE( BUFFER_COUNT ) );
846 // Now the buffer is empty we can switch context if necessary.
847 if( xHigherPriorityTaskWoken )
849 taskYIELD ();
852 </pre>
854 * \defgroup xQueueSendFromISR xQueueSendFromISR
855 * \ingroup QueueManagement
857 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_FRONT )
861 * queue. h
862 * <pre>
863 portBASE_TYPE xQueueSendToBackFromISR(
864 xQueueHandle pxQueue,
865 const void *pvItemToQueue,
866 portBASE_TYPE *pxHigherPriorityTaskWoken
868 </pre>
870 * This is a macro that calls xQueueGenericSendFromISR().
872 * Post an item to the back of a queue. It is safe to use this macro from
873 * within an interrupt service routine.
875 * Items are queued by copy not reference so it is preferable to only
876 * queue small items, especially when called from an ISR. In most cases
877 * it would be preferable to store a pointer to the item being queued.
879 * @param xQueue The handle to the queue on which the item is to be posted.
881 * @param pvItemToQueue A pointer to the item that is to be placed on the
882 * queue. The size of the items the queue will hold was defined when the
883 * queue was created, so this many bytes will be copied from pvItemToQueue
884 * into the queue storage area.
886 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
887 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
888 * to unblock, and the unblocked task has a priority higher than the currently
889 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
890 * a context switch should be requested before the interrupt is exited.
892 * @return pdTRUE if the data was successfully sent to the queue, otherwise
893 * errQUEUE_FULL.
895 * Example usage for buffered IO (where the ISR can obtain more than one value
896 * per call):
897 <pre>
898 void vBufferISR( void )
900 char cIn;
901 portBASE_TYPE xHigherPriorityTaskWoken;
903 // We have not woken a task at the start of the ISR.
904 xHigherPriorityTaskWoken = pdFALSE;
906 // Loop until the buffer is empty.
909 // Obtain a byte from the buffer.
910 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
912 // Post the byte.
913 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
915 } while( portINPUT_BYTE( BUFFER_COUNT ) );
917 // Now the buffer is empty we can switch context if necessary.
918 if( xHigherPriorityTaskWoken )
920 taskYIELD ();
923 </pre>
925 * \defgroup xQueueSendFromISR xQueueSendFromISR
926 * \ingroup QueueManagement
928 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
931 * queue. h
932 * <pre>
933 portBASE_TYPE xQueueSendFromISR(
934 xQueueHandle pxQueue,
935 const void *pvItemToQueue,
936 portBASE_TYPE *pxHigherPriorityTaskWoken
938 </pre>
940 * This is a macro that calls xQueueGenericSendFromISR(). It is included
941 * for backward compatibility with versions of FreeRTOS.org that did not
942 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
943 * macros.
945 * Post an item to the back of a queue. It is safe to use this function from
946 * within an interrupt service routine.
948 * Items are queued by copy not reference so it is preferable to only
949 * queue small items, especially when called from an ISR. In most cases
950 * it would be preferable to store a pointer to the item being queued.
952 * @param xQueue The handle to the queue on which the item is to be posted.
954 * @param pvItemToQueue A pointer to the item that is to be placed on the
955 * queue. The size of the items the queue will hold was defined when the
956 * queue was created, so this many bytes will be copied from pvItemToQueue
957 * into the queue storage area.
959 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
960 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
961 * to unblock, and the unblocked task has a priority higher than the currently
962 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
963 * a context switch should be requested before the interrupt is exited.
965 * @return pdTRUE if the data was successfully sent to the queue, otherwise
966 * errQUEUE_FULL.
968 * Example usage for buffered IO (where the ISR can obtain more than one value
969 * per call):
970 <pre>
971 void vBufferISR( void )
973 char cIn;
974 portBASE_TYPE xHigherPriorityTaskWoken;
976 // We have not woken a task at the start of the ISR.
977 xHigherPriorityTaskWoken = pdFALSE;
979 // Loop until the buffer is empty.
982 // Obtain a byte from the buffer.
983 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
985 // Post the byte.
986 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
988 } while( portINPUT_BYTE( BUFFER_COUNT ) );
990 // Now the buffer is empty we can switch context if necessary.
991 if( xHigherPriorityTaskWoken )
993 // Actual macro used here is port specific.
994 taskYIELD_FROM_ISR ();
997 </pre>
999 * \defgroup xQueueSendFromISR xQueueSendFromISR
1000 * \ingroup QueueManagement
1002 #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
1005 * queue. h
1006 * <pre>
1007 portBASE_TYPE xQueueGenericSendFromISR(
1008 xQueueHandle pxQueue,
1009 const void *pvItemToQueue,
1010 portBASE_TYPE *pxHigherPriorityTaskWoken,
1011 portBASE_TYPE xCopyPosition
1013 </pre>
1015 * It is preferred that the macros xQueueSendFromISR(),
1016 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
1017 * of calling this function directly.
1019 * Post an item on a queue. It is safe to use this function from within an
1020 * interrupt service routine.
1022 * Items are queued by copy not reference so it is preferable to only
1023 * queue small items, especially when called from an ISR. In most cases
1024 * it would be preferable to store a pointer to the item being queued.
1026 * @param xQueue The handle to the queue on which the item is to be posted.
1028 * @param pvItemToQueue A pointer to the item that is to be placed on the
1029 * queue. The size of the items the queue will hold was defined when the
1030 * queue was created, so this many bytes will be copied from pvItemToQueue
1031 * into the queue storage area.
1033 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
1034 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
1035 * to unblock, and the unblocked task has a priority higher than the currently
1036 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
1037 * a context switch should be requested before the interrupt is exited.
1039 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
1040 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
1041 * at the front of the queue (for high priority messages).
1043 * @return pdTRUE if the data was successfully sent to the queue, otherwise
1044 * errQUEUE_FULL.
1046 * Example usage for buffered IO (where the ISR can obtain more than one value
1047 * per call):
1048 <pre>
1049 void vBufferISR( void )
1051 char cIn;
1052 portBASE_TYPE xHigherPriorityTaskWokenByPost;
1054 // We have not woken a task at the start of the ISR.
1055 xHigherPriorityTaskWokenByPost = pdFALSE;
1057 // Loop until the buffer is empty.
1060 // Obtain a byte from the buffer.
1061 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
1063 // Post each byte.
1064 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
1066 } while( portINPUT_BYTE( BUFFER_COUNT ) );
1068 // Now the buffer is empty we can switch context if necessary. Note that the
1069 // name of the yield function required is port specific.
1070 if( xHigherPriorityTaskWokenByPost )
1072 taskYIELD_YIELD_FROM_ISR();
1075 </pre>
1077 * \defgroup xQueueSendFromISR xQueueSendFromISR
1078 * \ingroup QueueManagement
1080 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
1083 * queue. h
1084 * <pre>
1085 portBASE_TYPE xQueueReceiveFromISR(
1086 xQueueHandle pxQueue,
1087 void *pvBuffer,
1088 portBASE_TYPE *pxTaskWoken
1090 * </pre>
1092 * Receive an item from a queue. It is safe to use this function from within an
1093 * interrupt service routine.
1095 * @param pxQueue The handle to the queue from which the item is to be
1096 * received.
1098 * @param pvBuffer Pointer to the buffer into which the received item will
1099 * be copied.
1101 * @param pxTaskWoken A task may be blocked waiting for space to become
1102 * available on the queue. If xQueueReceiveFromISR causes such a task to
1103 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
1104 * remain unchanged.
1106 * @return pdTRUE if an item was successfully received from the queue,
1107 * otherwise pdFALSE.
1109 * Example usage:
1110 <pre>
1112 xQueueHandle xQueue;
1114 // Function to create a queue and post some values.
1115 void vAFunction( void *pvParameters )
1117 char cValueToPost;
1118 const portTickType xBlockTime = ( portTickType )0xff;
1120 // Create a queue capable of containing 10 characters.
1121 xQueue = xQueueCreate( 10, sizeof( char ) );
1122 if( xQueue == 0 )
1124 // Failed to create the queue.
1127 // ...
1129 // Post some characters that will be used within an ISR. If the queue
1130 // is full then this task will block for xBlockTime ticks.
1131 cValueToPost = 'a';
1132 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
1133 cValueToPost = 'b';
1134 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
1136 // ... keep posting characters ... this task may block when the queue
1137 // becomes full.
1139 cValueToPost = 'c';
1140 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
1143 // ISR that outputs all the characters received on the queue.
1144 void vISR_Routine( void )
1146 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
1147 char cRxedChar;
1149 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
1151 // A character was received. Output the character now.
1152 vOutputCharacter( cRxedChar );
1154 // If removing the character from the queue woke the task that was
1155 // posting onto the queue cTaskWokenByReceive will have been set to
1156 // pdTRUE. No matter how many times this loop iterates only one
1157 // task will be woken.
1160 if( cTaskWokenByPost != ( char ) pdFALSE;
1162 taskYIELD ();
1165 </pre>
1166 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
1167 * \ingroup QueueManagement
1169 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
1172 * Utilities to query queue that are safe to use from an ISR. These utilities
1173 * should be used only from witin an ISR, or within a critical section.
1175 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
1176 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
1177 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
1181 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
1182 * Likewise xQueueAltGenericReceive() is an alternative version of
1183 * xQueueGenericReceive().
1185 * The source code that implements the alternative (Alt) API is much
1186 * simpler because it executes everything from within a critical section.
1187 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
1188 * preferred fully featured API too. The fully featured API has more
1189 * complex code that takes longer to execute, but makes much less use of
1190 * critical sections. Therefore the alternative API sacrifices interrupt
1191 * responsiveness to gain execution speed, whereas the fully featured API
1192 * sacrifices execution speed to ensure better interrupt responsiveness.
1194 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
1195 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
1196 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
1197 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
1198 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
1199 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
1202 * The functions defined above are for passing data to and from tasks. The
1203 * functions below are the equivalents for passing data to and from
1204 * co-routines.
1206 * These functions are called from the co-routine macro implementation and
1207 * should not be called directly from application code. Instead use the macro
1208 * wrappers defined within croutine.h.
1210 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
1211 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
1212 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
1213 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
1216 * For internal use only. Use xSemaphoreCreateMutex() or
1217 * xSemaphoreCreateCounting() instead of calling these functions directly.
1219 xQueueHandle xQueueCreateMutex( void );
1220 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
1223 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
1224 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
1226 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
1227 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex );
1230 * The registry is provided as a means for kernel aware debuggers to
1231 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
1232 * a queue, semaphore or mutex handle to the registry if you want the handle
1233 * to be available to a kernel aware debugger. If you are not using a kernel
1234 * aware debugger then this function can be ignored.
1236 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
1237 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
1238 * within FreeRTOSConfig.h for the registry to be available. Its value
1239 * does not effect the number of queues, semaphores and mutexes that can be
1240 * created - just the number that the registry can hold.
1242 * @param xQueue The handle of the queue being added to the registry. This
1243 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
1244 * handles can also be passed in here.
1246 * @param pcName The name to be associated with the handle. This is the
1247 * name that the kernel aware debugger will display.
1249 #if configQUEUE_REGISTRY_SIZE > 0
1250 void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcName );
1251 #endif
1256 #ifdef __cplusplus
1258 #endif
1260 #endif /* QUEUE_H */