2 FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS books - available as PDF or paperback *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 ***NOTE*** The exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
54 #ifndef INC_FREERTOS_H
\r
55 #error "#include FreeRTOS.h" must appear in source files before "#include queue.h"
\r
69 #include "mpu_wrappers.h"
\r
72 * Type by which queues are referenced. For example, a call to xQueueCreate
\r
73 * returns (via a pointer parameter) an xQueueHandle variable that can then
\r
74 * be used as a parameter to xQueueSend(), xQueueReceive(), etc.
\r
76 typedef void * xQueueHandle;
\r
79 /* For internal use only. */
\r
80 #define queueSEND_TO_BACK ( 0 )
\r
81 #define queueSEND_TO_FRONT ( 1 )
\r
87 xQueueHandle xQueueCreate(
\r
88 unsigned portBASE_TYPE uxQueueLength,
\r
89 unsigned portBASE_TYPE uxItemSize
\r
93 * Creates a new queue instance. This allocates the storage required by the
\r
94 * new queue and returns a handle for the queue.
\r
96 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
98 * @param uxItemSize The number of bytes each item in the queue will require.
\r
99 * Items are queued by copy, not by reference, so this is the number of bytes
\r
100 * that will be copied for each posted item. Each item on the queue must be
\r
103 * @return If the queue is successfully create then a handle to the newly
\r
104 * created queue is returned. If the queue cannot be created then 0 is
\r
115 void vATask( void *pvParameters )
\r
117 xQueueHandle xQueue1, xQueue2;
\r
119 // Create a queue capable of containing 10 unsigned long values.
\r
120 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
123 // Queue was not created and must not be used.
\r
126 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
127 // These should be passed by pointer as they contain a lot of data.
\r
128 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
131 // Queue was not created and must not be used.
\r
134 // ... Rest of task code.
\r
137 * \defgroup xQueueCreate xQueueCreate
\r
138 * \ingroup QueueManagement
\r
140 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
145 portBASE_TYPE xQueueSendToToFront(
\r
146 xQueueHandle xQueue,
\r
147 const void * pvItemToQueue,
\r
148 portTickType xTicksToWait
\r
152 * This is a macro that calls xQueueGenericSend().
\r
154 * Post an item to the front of a queue. The item is queued by copy, not by
\r
155 * reference. This function must not be called from an interrupt service
\r
156 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
159 * @param xQueue The handle to the queue on which the item is to be posted.
\r
161 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
162 * queue. The size of the items the queue will hold was defined when the
\r
163 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
164 * into the queue storage area.
\r
166 * @param xTicksToWait The maximum amount of time the task should block
\r
167 * waiting for space to become available on the queue, should it already
\r
168 * be full. The call will return immediately if this is set to 0 and the
\r
169 * queue is full. The time is defined in tick periods so the constant
\r
170 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
172 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
182 unsigned long ulVar = 10UL;
\r
184 void vATask( void *pvParameters )
\r
186 xQueueHandle xQueue1, xQueue2;
\r
187 struct AMessage *pxMessage;
\r
189 // Create a queue capable of containing 10 unsigned long values.
\r
190 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
192 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
193 // These should be passed by pointer as they contain a lot of data.
\r
194 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
200 // Send an unsigned long. Wait for 10 ticks for space to become
\r
201 // available if necessary.
\r
202 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
204 // Failed to post the message, even after 10 ticks.
\r
210 // Send a pointer to a struct AMessage object. Don't block if the
\r
211 // queue is already full.
\r
212 pxMessage = & xMessage;
\r
213 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
216 // ... Rest of task code.
\r
219 * \defgroup xQueueSend xQueueSend
\r
220 * \ingroup QueueManagement
\r
222 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
227 portBASE_TYPE xQueueSendToBack(
\r
228 xQueueHandle xQueue,
\r
229 const void * pvItemToQueue,
\r
230 portTickType xTicksToWait
\r
234 * This is a macro that calls xQueueGenericSend().
\r
236 * Post an item to the back of a queue. The item is queued by copy, not by
\r
237 * reference. This function must not be called from an interrupt service
\r
238 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
241 * @param xQueue The handle to the queue on which the item is to be posted.
\r
243 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
244 * queue. The size of the items the queue will hold was defined when the
\r
245 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
246 * into the queue storage area.
\r
248 * @param xTicksToWait The maximum amount of time the task should block
\r
249 * waiting for space to become available on the queue, should it already
\r
250 * be full. The call will return immediately if this is set to 0 and the queue
\r
251 * is full. The time is defined in tick periods so the constant
\r
252 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
254 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
264 unsigned long ulVar = 10UL;
\r
266 void vATask( void *pvParameters )
\r
268 xQueueHandle xQueue1, xQueue2;
\r
269 struct AMessage *pxMessage;
\r
271 // Create a queue capable of containing 10 unsigned long values.
\r
272 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
274 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
275 // These should be passed by pointer as they contain a lot of data.
\r
276 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
282 // Send an unsigned long. Wait for 10 ticks for space to become
\r
283 // available if necessary.
\r
284 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
286 // Failed to post the message, even after 10 ticks.
\r
292 // Send a pointer to a struct AMessage object. Don't block if the
\r
293 // queue is already full.
\r
294 pxMessage = & xMessage;
\r
295 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
298 // ... Rest of task code.
\r
301 * \defgroup xQueueSend xQueueSend
\r
302 * \ingroup QueueManagement
\r
304 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
309 portBASE_TYPE xQueueSend(
\r
310 xQueueHandle xQueue,
\r
311 const void * pvItemToQueue,
\r
312 portTickType xTicksToWait
\r
316 * This is a macro that calls xQueueGenericSend(). It is included for
\r
317 * backward compatibility with versions of FreeRTOS.org that did not
\r
318 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
319 * equivalent to xQueueSendToBack().
\r
321 * Post an item on a queue. The item is queued by copy, not by reference.
\r
322 * This function must not be called from an interrupt service routine.
\r
323 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
325 * @param xQueue The handle to the queue on which the item is to be posted.
\r
327 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
328 * queue. The size of the items the queue will hold was defined when the
\r
329 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
330 * into the queue storage area.
\r
332 * @param xTicksToWait The maximum amount of time the task should block
\r
333 * waiting for space to become available on the queue, should it already
\r
334 * be full. The call will return immediately if this is set to 0 and the
\r
335 * queue is full. The time is defined in tick periods so the constant
\r
336 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
338 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
348 unsigned long ulVar = 10UL;
\r
350 void vATask( void *pvParameters )
\r
352 xQueueHandle xQueue1, xQueue2;
\r
353 struct AMessage *pxMessage;
\r
355 // Create a queue capable of containing 10 unsigned long values.
\r
356 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
358 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
359 // These should be passed by pointer as they contain a lot of data.
\r
360 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
366 // Send an unsigned long. Wait for 10 ticks for space to become
\r
367 // available if necessary.
\r
368 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
370 // Failed to post the message, even after 10 ticks.
\r
376 // Send a pointer to a struct AMessage object. Don't block if the
\r
377 // queue is already full.
\r
378 pxMessage = & xMessage;
\r
379 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
382 // ... Rest of task code.
\r
385 * \defgroup xQueueSend xQueueSend
\r
386 * \ingroup QueueManagement
\r
388 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
394 portBASE_TYPE xQueueGenericSend(
\r
395 xQueueHandle xQueue,
\r
396 const void * pvItemToQueue,
\r
397 portTickType xTicksToWait
\r
398 portBASE_TYPE xCopyPosition
\r
402 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
403 * xQueueSendToBack() are used in place of calling this function directly.
\r
405 * Post an item on a queue. The item is queued by copy, not by reference.
\r
406 * This function must not be called from an interrupt service routine.
\r
407 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
409 * @param xQueue The handle to the queue on which the item is to be posted.
\r
411 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
412 * queue. The size of the items the queue will hold was defined when the
\r
413 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
414 * into the queue storage area.
\r
416 * @param xTicksToWait The maximum amount of time the task should block
\r
417 * waiting for space to become available on the queue, should it already
\r
418 * be full. The call will return immediately if this is set to 0 and the
\r
419 * queue is full. The time is defined in tick periods so the constant
\r
420 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
422 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
423 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
424 * at the front of the queue (for high priority messages).
\r
426 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
436 unsigned long ulVar = 10UL;
\r
438 void vATask( void *pvParameters )
\r
440 xQueueHandle xQueue1, xQueue2;
\r
441 struct AMessage *pxMessage;
\r
443 // Create a queue capable of containing 10 unsigned long values.
\r
444 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
446 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
447 // These should be passed by pointer as they contain a lot of data.
\r
448 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
454 // Send an unsigned long. Wait for 10 ticks for space to become
\r
455 // available if necessary.
\r
456 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
458 // Failed to post the message, even after 10 ticks.
\r
464 // Send a pointer to a struct AMessage object. Don't block if the
\r
465 // queue is already full.
\r
466 pxMessage = & xMessage;
\r
467 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
470 // ... Rest of task code.
\r
473 * \defgroup xQueueSend xQueueSend
\r
474 * \ingroup QueueManagement
\r
476 signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
481 portBASE_TYPE xQueuePeek(
\r
482 xQueueHandle xQueue,
\r
484 portTickType xTicksToWait
\r
487 * This is a macro that calls the xQueueGenericReceive() function.
\r
489 * Receive an item from a queue without removing the item from the queue.
\r
490 * The item is received by copy so a buffer of adequate size must be
\r
491 * provided. The number of bytes copied into the buffer was defined when
\r
492 * the queue was created.
\r
494 * Successfully received items remain on the queue so will be returned again
\r
495 * by the next call, or a call to xQueueReceive().
\r
497 * This macro must not be used in an interrupt service routine.
\r
499 * @param pxQueue The handle to the queue from which the item is to be
\r
502 * @param pvBuffer Pointer to the buffer into which the received item will
\r
505 * @param xTicksToWait The maximum amount of time the task should block
\r
506 * waiting for an item to receive should the queue be empty at the time
\r
507 * of the call. The time is defined in tick periods so the constant
\r
508 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
509 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
\r
512 * @return pdTRUE if an item was successfully received from the queue,
\r
513 * otherwise pdFALSE.
\r
523 xQueueHandle xQueue;
\r
525 // Task to create a queue and post a value.
\r
526 void vATask( void *pvParameters )
\r
528 struct AMessage *pxMessage;
\r
530 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
531 // These should be passed by pointer as they contain a lot of data.
\r
532 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
535 // Failed to create the queue.
\r
540 // Send a pointer to a struct AMessage object. Don't block if the
\r
541 // queue is already full.
\r
542 pxMessage = & xMessage;
\r
543 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
545 // ... Rest of task code.
\r
548 // Task to peek the data from the queue.
\r
549 void vADifferentTask( void *pvParameters )
\r
551 struct AMessage *pxRxedMessage;
\r
555 // Peek a message on the created queue. Block for 10 ticks if a
\r
556 // message is not immediately available.
\r
557 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
559 // pcRxedMessage now points to the struct AMessage variable posted
\r
560 // by vATask, but the item still remains on the queue.
\r
564 // ... Rest of task code.
\r
567 * \defgroup xQueueReceive xQueueReceive
\r
568 * \ingroup QueueManagement
\r
570 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
575 portBASE_TYPE xQueueReceive(
\r
576 xQueueHandle xQueue,
\r
578 portTickType xTicksToWait
\r
581 * This is a macro that calls the xQueueGenericReceive() function.
\r
583 * Receive an item from a queue. The item is received by copy so a buffer of
\r
584 * adequate size must be provided. The number of bytes copied into the buffer
\r
585 * was defined when the queue was created.
\r
587 * Successfully received items are removed from the queue.
\r
589 * This function must not be used in an interrupt service routine. See
\r
590 * xQueueReceiveFromISR for an alternative that can.
\r
592 * @param pxQueue The handle to the queue from which the item is to be
\r
595 * @param pvBuffer Pointer to the buffer into which the received item will
\r
598 * @param xTicksToWait The maximum amount of time the task should block
\r
599 * waiting for an item to receive should the queue be empty at the time
\r
600 * of the call. xQueueReceive() will return immediately if xTicksToWait
\r
601 * is zero and the queue is empty. The time is defined in tick periods so the
\r
602 * constant portTICK_RATE_MS should be used to convert to real time if this is
\r
605 * @return pdTRUE if an item was successfully received from the queue,
\r
606 * otherwise pdFALSE.
\r
616 xQueueHandle xQueue;
\r
618 // Task to create a queue and post a value.
\r
619 void vATask( void *pvParameters )
\r
621 struct AMessage *pxMessage;
\r
623 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
624 // These should be passed by pointer as they contain a lot of data.
\r
625 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
628 // Failed to create the queue.
\r
633 // Send a pointer to a struct AMessage object. Don't block if the
\r
634 // queue is already full.
\r
635 pxMessage = & xMessage;
\r
636 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
638 // ... Rest of task code.
\r
641 // Task to receive from the queue.
\r
642 void vADifferentTask( void *pvParameters )
\r
644 struct AMessage *pxRxedMessage;
\r
648 // Receive a message on the created queue. Block for 10 ticks if a
\r
649 // message is not immediately available.
\r
650 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
652 // pcRxedMessage now points to the struct AMessage variable posted
\r
657 // ... Rest of task code.
\r
660 * \defgroup xQueueReceive xQueueReceive
\r
661 * \ingroup QueueManagement
\r
663 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
669 portBASE_TYPE xQueueGenericReceive(
\r
670 xQueueHandle xQueue,
\r
672 portTickType xTicksToWait
\r
673 portBASE_TYPE xJustPeek
\r
676 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
677 * this function directly.
\r
679 * Receive an item from a queue. The item is received by copy so a buffer of
\r
680 * adequate size must be provided. The number of bytes copied into the buffer
\r
681 * was defined when the queue was created.
\r
683 * This function must not be used in an interrupt service routine. See
\r
684 * xQueueReceiveFromISR for an alternative that can.
\r
686 * @param pxQueue The handle to the queue from which the item is to be
\r
689 * @param pvBuffer Pointer to the buffer into which the received item will
\r
692 * @param xTicksToWait The maximum amount of time the task should block
\r
693 * waiting for an item to receive should the queue be empty at the time
\r
694 * of the call. The time is defined in tick periods so the constant
\r
695 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
696 * xQueueGenericReceive() will return immediately if the queue is empty and
\r
697 * xTicksToWait is 0.
\r
699 * @param xJustPeek When set to true, the item received from the queue is not
\r
700 * actually removed from the queue - meaning a subsequent call to
\r
701 * xQueueReceive() will return the same item. When set to false, the item
\r
702 * being received from the queue is also removed from the queue.
\r
704 * @return pdTRUE if an item was successfully received from the queue,
\r
705 * otherwise pdFALSE.
\r
715 xQueueHandle xQueue;
\r
717 // Task to create a queue and post a value.
\r
718 void vATask( void *pvParameters )
\r
720 struct AMessage *pxMessage;
\r
722 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
723 // These should be passed by pointer as they contain a lot of data.
\r
724 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
727 // Failed to create the queue.
\r
732 // Send a pointer to a struct AMessage object. Don't block if the
\r
733 // queue is already full.
\r
734 pxMessage = & xMessage;
\r
735 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
737 // ... Rest of task code.
\r
740 // Task to receive from the queue.
\r
741 void vADifferentTask( void *pvParameters )
\r
743 struct AMessage *pxRxedMessage;
\r
747 // Receive a message on the created queue. Block for 10 ticks if a
\r
748 // message is not immediately available.
\r
749 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
751 // pcRxedMessage now points to the struct AMessage variable posted
\r
756 // ... Rest of task code.
\r
759 * \defgroup xQueueReceive xQueueReceive
\r
760 * \ingroup QueueManagement
\r
762 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
766 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
768 * Return the number of messages stored in a queue.
\r
770 * @param xQueue A handle to the queue being queried.
\r
772 * @return The number of messages available in the queue.
\r
774 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
775 * \ingroup QueueManagement
\r
777 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
781 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
783 * Delete a queue - freeing all the memory allocated for storing of items
\r
784 * placed on the queue.
\r
786 * @param xQueue A handle to the queue to be deleted.
\r
788 * \page vQueueDelete vQueueDelete
\r
789 * \ingroup QueueManagement
\r
791 void vQueueDelete( xQueueHandle pxQueue );
\r
796 portBASE_TYPE xQueueSendToFrontFromISR(
\r
797 xQueueHandle pxQueue,
\r
798 const void *pvItemToQueue,
\r
799 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
803 * This is a macro that calls xQueueGenericSendFromISR().
\r
805 * Post an item to the front of a queue. It is safe to use this macro from
\r
806 * within an interrupt service routine.
\r
808 * Items are queued by copy not reference so it is preferable to only
\r
809 * queue small items, especially when called from an ISR. In most cases
\r
810 * it would be preferable to store a pointer to the item being queued.
\r
812 * @param xQueue The handle to the queue on which the item is to be posted.
\r
814 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
815 * queue. The size of the items the queue will hold was defined when the
\r
816 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
817 * into the queue storage area.
\r
819 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
\r
820 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
821 * to unblock, and the unblocked task has a priority higher than the currently
\r
822 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
\r
823 * a context switch should be requested before the interrupt is exited.
\r
825 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
828 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
831 void vBufferISR( void )
\r
834 portBASE_TYPE xHigherPrioritTaskWoken;
\r
836 // We have not woken a task at the start of the ISR.
\r
837 xHigherPriorityTaskWoken = pdFALSE;
\r
839 // Loop until the buffer is empty.
\r
842 // Obtain a byte from the buffer.
\r
843 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
846 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
848 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
850 // Now the buffer is empty we can switch context if necessary.
\r
851 if( xHigherPriorityTaskWoken )
\r
858 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
859 * \ingroup QueueManagement
\r
861 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_FRONT )
\r
867 portBASE_TYPE xQueueSendToBackFromISR(
\r
868 xQueueHandle pxQueue,
\r
869 const void *pvItemToQueue,
\r
870 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
874 * This is a macro that calls xQueueGenericSendFromISR().
\r
876 * Post an item to the back of a queue. It is safe to use this macro from
\r
877 * within an interrupt service routine.
\r
879 * Items are queued by copy not reference so it is preferable to only
\r
880 * queue small items, especially when called from an ISR. In most cases
\r
881 * it would be preferable to store a pointer to the item being queued.
\r
883 * @param xQueue The handle to the queue on which the item is to be posted.
\r
885 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
886 * queue. The size of the items the queue will hold was defined when the
\r
887 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
888 * into the queue storage area.
\r
890 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
\r
891 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
892 * to unblock, and the unblocked task has a priority higher than the currently
\r
893 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
\r
894 * a context switch should be requested before the interrupt is exited.
\r
896 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
899 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
902 void vBufferISR( void )
\r
905 portBASE_TYPE xHigherPriorityTaskWoken;
\r
907 // We have not woken a task at the start of the ISR.
\r
908 xHigherPriorityTaskWoken = pdFALSE;
\r
910 // Loop until the buffer is empty.
\r
913 // Obtain a byte from the buffer.
\r
914 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
917 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
919 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
921 // Now the buffer is empty we can switch context if necessary.
\r
922 if( xHigherPriorityTaskWoken )
\r
929 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
930 * \ingroup QueueManagement
\r
932 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
937 portBASE_TYPE xQueueSendFromISR(
\r
938 xQueueHandle pxQueue,
\r
939 const void *pvItemToQueue,
\r
940 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
944 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
945 * for backward compatibility with versions of FreeRTOS.org that did not
\r
946 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
949 * Post an item to the back of a queue. It is safe to use this function from
\r
950 * within an interrupt service routine.
\r
952 * Items are queued by copy not reference so it is preferable to only
\r
953 * queue small items, especially when called from an ISR. In most cases
\r
954 * it would be preferable to store a pointer to the item being queued.
\r
956 * @param xQueue The handle to the queue on which the item is to be posted.
\r
958 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
959 * queue. The size of the items the queue will hold was defined when the
\r
960 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
961 * into the queue storage area.
\r
963 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
\r
964 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
965 * to unblock, and the unblocked task has a priority higher than the currently
\r
966 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
967 * a context switch should be requested before the interrupt is exited.
\r
969 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
972 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
975 void vBufferISR( void )
\r
978 portBASE_TYPE xHigherPriorityTaskWoken;
\r
980 // We have not woken a task at the start of the ISR.
\r
981 xHigherPriorityTaskWoken = pdFALSE;
\r
983 // Loop until the buffer is empty.
\r
986 // Obtain a byte from the buffer.
\r
987 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
990 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
992 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
994 // Now the buffer is empty we can switch context if necessary.
\r
995 if( xHigherPriorityTaskWoken )
\r
997 // Actual macro used here is port specific.
\r
998 taskYIELD_FROM_ISR ();
\r
1003 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1004 * \ingroup QueueManagement
\r
1006 #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
1011 portBASE_TYPE xQueueGenericSendFromISR(
\r
1012 xQueueHandle pxQueue,
\r
1013 const void *pvItemToQueue,
\r
1014 portBASE_TYPE *pxHigherPriorityTaskWoken,
\r
1015 portBASE_TYPE xCopyPosition
\r
1019 * It is preferred that the macros xQueueSendFromISR(),
\r
1020 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1021 * of calling this function directly.
\r
1023 * Post an item on a queue. It is safe to use this function from within an
\r
1024 * interrupt service routine.
\r
1026 * Items are queued by copy not reference so it is preferable to only
\r
1027 * queue small items, especially when called from an ISR. In most cases
\r
1028 * it would be preferable to store a pointer to the item being queued.
\r
1030 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1032 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1033 * queue. The size of the items the queue will hold was defined when the
\r
1034 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1035 * into the queue storage area.
\r
1037 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
\r
1038 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1039 * to unblock, and the unblocked task has a priority higher than the currently
\r
1040 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
\r
1041 * a context switch should be requested before the interrupt is exited.
\r
1043 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1044 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1045 * at the front of the queue (for high priority messages).
\r
1047 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1050 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1053 void vBufferISR( void )
\r
1056 portBASE_TYPE xHigherPriorityTaskWokenByPost;
\r
1058 // We have not woken a task at the start of the ISR.
\r
1059 xHigherPriorityTaskWokenByPost = pdFALSE;
\r
1061 // Loop until the buffer is empty.
\r
1064 // Obtain a byte from the buffer.
\r
1065 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1067 // Post each byte.
\r
1068 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
\r
1070 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1072 // Now the buffer is empty we can switch context if necessary. Note that the
\r
1073 // name of the yield function required is port specific.
\r
1074 if( xHigherPriorityTaskWokenByPost )
\r
1076 taskYIELD_YIELD_FROM_ISR();
\r
1081 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1082 * \ingroup QueueManagement
\r
1084 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
\r
1089 portBASE_TYPE xQueueReceiveFromISR(
\r
1090 xQueueHandle pxQueue,
\r
1092 portBASE_TYPE *pxTaskWoken
\r
1096 * Receive an item from a queue. It is safe to use this function from within an
\r
1097 * interrupt service routine.
\r
1099 * @param pxQueue The handle to the queue from which the item is to be
\r
1102 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1105 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1106 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1107 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1108 * remain unchanged.
\r
1110 * @return pdTRUE if an item was successfully received from the queue,
\r
1111 * otherwise pdFALSE.
\r
1116 xQueueHandle xQueue;
\r
1118 // Function to create a queue and post some values.
\r
1119 void vAFunction( void *pvParameters )
\r
1121 char cValueToPost;
\r
1122 const portTickType xBlockTime = ( portTickType )0xff;
\r
1124 // Create a queue capable of containing 10 characters.
\r
1125 xQueue = xQueueCreate( 10, sizeof( char ) );
\r
1128 // Failed to create the queue.
\r
1133 // Post some characters that will be used within an ISR. If the queue
\r
1134 // is full then this task will block for xBlockTime ticks.
\r
1135 cValueToPost = 'a';
\r
1136 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1137 cValueToPost = 'b';
\r
1138 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1140 // ... keep posting characters ... this task may block when the queue
\r
1143 cValueToPost = 'c';
\r
1144 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1147 // ISR that outputs all the characters received on the queue.
\r
1148 void vISR_Routine( void )
\r
1150 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1153 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1155 // A character was received. Output the character now.
\r
1156 vOutputCharacter( cRxedChar );
\r
1158 // If removing the character from the queue woke the task that was
\r
1159 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1160 // pdTRUE. No matter how many times this loop iterates only one
\r
1161 // task will be woken.
\r
1164 if( cTaskWokenByPost != ( char ) pdFALSE;
\r
1170 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1171 * \ingroup QueueManagement
\r
1173 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1176 * Utilities to query queue that are safe to use from an ISR. These utilities
\r
1177 * should be used only from witin an ISR, or within a critical section.
\r
1179 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
\r
1180 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
\r
1181 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
\r
1185 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1186 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1187 * xQueueGenericReceive().
\r
1189 * The source code that implements the alternative (Alt) API is much
\r
1190 * simpler because it executes everything from within a critical section.
\r
1191 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1192 * preferred fully featured API too. The fully featured API has more
\r
1193 * complex code that takes longer to execute, but makes much less use of
\r
1194 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1195 * responsiveness to gain execution speed, whereas the fully featured API
\r
1196 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1198 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1199 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1200 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
1201 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
1202 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
1203 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
1206 * The functions defined above are for passing data to and from tasks. The
\r
1207 * functions below are the equivalents for passing data to and from
\r
1210 * These functions are called from the co-routine macro implementation and
\r
1211 * should not be called directly from application code. Instead use the macro
\r
1212 * wrappers defined within croutine.h.
\r
1214 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1215 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1216 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1217 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1220 * For internal use only. Use xSemaphoreCreateMutex() or
\r
1221 * xSemaphoreCreateCounting() instead of calling these functions directly.
\r
1223 xQueueHandle xQueueCreateMutex( void );
\r
1224 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1227 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1228 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1230 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime );
\r
1231 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex );
\r
1234 * The registry is provided as a means for kernel aware debuggers to
\r
1235 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
\r
1236 * a queue, semaphore or mutex handle to the registry if you want the handle
\r
1237 * to be available to a kernel aware debugger. If you are not using a kernel
\r
1238 * aware debugger then this function can be ignored.
\r
1240 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
\r
1241 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
\r
1242 * within FreeRTOSConfig.h for the registry to be available. Its value
\r
1243 * does not effect the number of queues, semaphores and mutexes that can be
\r
1244 * created - just the number that the registry can hold.
\r
1246 * @param xQueue The handle of the queue being added to the registry. This
\r
1247 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
\r
1248 * handles can also be passed in here.
\r
1250 * @param pcName The name to be associated with the handle. This is the
\r
1251 * name that the kernel aware debugger will display.
\r
1253 #if configQUEUE_REGISTRY_SIZE > 0
\r
1254 void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcName );
\r
1257 /* Not a public API function, hence the 'Restricted' in the name. */
\r
1258 void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait );
\r
1261 #ifdef __cplusplus
\r
1265 #endif /* QUEUE_H */
\r