2 FreeRTOS V6.1.0 - Copyright (C) 2010 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 typedef void * xQueueHandle;
\r
75 /* For internal use only. */
\r
76 #define queueSEND_TO_BACK ( 0 )
\r
77 #define queueSEND_TO_FRONT ( 1 )
\r
83 xQueueHandle xQueueCreate(
\r
84 unsigned portBASE_TYPE uxQueueLength,
\r
85 unsigned portBASE_TYPE uxItemSize
\r
89 * Creates a new queue instance. This allocates the storage required by the
\r
90 * new queue and returns a handle for the queue.
\r
92 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
94 * @param uxItemSize The number of bytes each item in the queue will require.
\r
95 * Items are queued by copy, not by reference, so this is the number of bytes
\r
96 * that will be copied for each posted item. Each item on the queue must be
\r
99 * @return If the queue is successfully create then a handle to the newly
\r
100 * created queue is returned. If the queue cannot be created then 0 is
\r
111 void vATask( void *pvParameters )
\r
113 xQueueHandle xQueue1, xQueue2;
\r
115 // Create a queue capable of containing 10 unsigned long values.
\r
116 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
119 // Queue was not created and must not be used.
\r
122 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
123 // These should be passed by pointer as they contain a lot of data.
\r
124 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
127 // Queue was not created and must not be used.
\r
130 // ... Rest of task code.
\r
133 * \defgroup xQueueCreate xQueueCreate
\r
134 * \ingroup QueueManagement
\r
136 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
141 portBASE_TYPE xQueueSendToToFront(
\r
142 xQueueHandle xQueue,
\r
143 const void * pvItemToQueue,
\r
144 portTickType xTicksToWait
\r
148 * This is a macro that calls xQueueGenericSend().
\r
150 * Post an item to the front of a queue. The item is queued by copy, not by
\r
151 * reference. This function must not be called from an interrupt service
\r
152 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
155 * @param xQueue The handle to the queue on which the item is to be posted.
\r
157 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
158 * queue. The size of the items the queue will hold was defined when the
\r
159 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
160 * into the queue storage area.
\r
162 * @param xTicksToWait The maximum amount of time the task should block
\r
163 * waiting for space to become available on the queue, should it already
\r
164 * be full. The call will return immediately if this is set to 0 and the
\r
165 * queue is full. The time is defined in tick periods so the constant
\r
166 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
168 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
178 unsigned long ulVar = 10UL;
\r
180 void vATask( void *pvParameters )
\r
182 xQueueHandle xQueue1, xQueue2;
\r
183 struct AMessage *pxMessage;
\r
185 // Create a queue capable of containing 10 unsigned long values.
\r
186 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
188 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
189 // These should be passed by pointer as they contain a lot of data.
\r
190 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
196 // Send an unsigned long. Wait for 10 ticks for space to become
\r
197 // available if necessary.
\r
198 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
200 // Failed to post the message, even after 10 ticks.
\r
206 // Send a pointer to a struct AMessage object. Don't block if the
\r
207 // queue is already full.
\r
208 pxMessage = & xMessage;
\r
209 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
212 // ... Rest of task code.
\r
215 * \defgroup xQueueSend xQueueSend
\r
216 * \ingroup QueueManagement
\r
218 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
223 portBASE_TYPE xQueueSendToBack(
\r
224 xQueueHandle xQueue,
\r
225 const void * pvItemToQueue,
\r
226 portTickType xTicksToWait
\r
230 * This is a macro that calls xQueueGenericSend().
\r
232 * Post an item to the back of a queue. The item is queued by copy, not by
\r
233 * reference. This function must not be called from an interrupt service
\r
234 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
237 * @param xQueue The handle to the queue on which the item is to be posted.
\r
239 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
240 * queue. The size of the items the queue will hold was defined when the
\r
241 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
242 * into the queue storage area.
\r
244 * @param xTicksToWait The maximum amount of time the task should block
\r
245 * waiting for space to become available on the queue, should it already
\r
246 * be full. The call will return immediately if this is set to 0 and the queue
\r
247 * is full. The time is defined in tick periods so the constant
\r
248 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
250 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
260 unsigned long ulVar = 10UL;
\r
262 void vATask( void *pvParameters )
\r
264 xQueueHandle xQueue1, xQueue2;
\r
265 struct AMessage *pxMessage;
\r
267 // Create a queue capable of containing 10 unsigned long values.
\r
268 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
270 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
271 // These should be passed by pointer as they contain a lot of data.
\r
272 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
278 // Send an unsigned long. Wait for 10 ticks for space to become
\r
279 // available if necessary.
\r
280 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
282 // Failed to post the message, even after 10 ticks.
\r
288 // Send a pointer to a struct AMessage object. Don't block if the
\r
289 // queue is already full.
\r
290 pxMessage = & xMessage;
\r
291 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
294 // ... Rest of task code.
\r
297 * \defgroup xQueueSend xQueueSend
\r
298 * \ingroup QueueManagement
\r
300 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
305 portBASE_TYPE xQueueSend(
\r
306 xQueueHandle xQueue,
\r
307 const void * pvItemToQueue,
\r
308 portTickType xTicksToWait
\r
312 * This is a macro that calls xQueueGenericSend(). It is included for
\r
313 * backward compatibility with versions of FreeRTOS.org that did not
\r
314 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
315 * equivalent to xQueueSendToBack().
\r
317 * Post an item on a queue. The item is queued by copy, not by reference.
\r
318 * This function must not be called from an interrupt service routine.
\r
319 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
321 * @param xQueue The handle to the queue on which the item is to be posted.
\r
323 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
324 * queue. The size of the items the queue will hold was defined when the
\r
325 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
326 * into the queue storage area.
\r
328 * @param xTicksToWait The maximum amount of time the task should block
\r
329 * waiting for space to become available on the queue, should it already
\r
330 * be full. The call will return immediately if this is set to 0 and the
\r
331 * queue is full. The time is defined in tick periods so the constant
\r
332 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
334 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
344 unsigned long ulVar = 10UL;
\r
346 void vATask( void *pvParameters )
\r
348 xQueueHandle xQueue1, xQueue2;
\r
349 struct AMessage *pxMessage;
\r
351 // Create a queue capable of containing 10 unsigned long values.
\r
352 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
354 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
355 // These should be passed by pointer as they contain a lot of data.
\r
356 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
362 // Send an unsigned long. Wait for 10 ticks for space to become
\r
363 // available if necessary.
\r
364 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
366 // Failed to post the message, even after 10 ticks.
\r
372 // Send a pointer to a struct AMessage object. Don't block if the
\r
373 // queue is already full.
\r
374 pxMessage = & xMessage;
\r
375 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
378 // ... Rest of task code.
\r
381 * \defgroup xQueueSend xQueueSend
\r
382 * \ingroup QueueManagement
\r
384 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
390 portBASE_TYPE xQueueGenericSend(
\r
391 xQueueHandle xQueue,
\r
392 const void * pvItemToQueue,
\r
393 portTickType xTicksToWait
\r
394 portBASE_TYPE xCopyPosition
\r
398 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
399 * xQueueSendToBack() are used in place of calling this function directly.
\r
401 * Post an item on a queue. The item is queued by copy, not by reference.
\r
402 * This function must not be called from an interrupt service routine.
\r
403 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
405 * @param xQueue The handle to the queue on which the item is to be posted.
\r
407 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
408 * queue. The size of the items the queue will hold was defined when the
\r
409 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
410 * into the queue storage area.
\r
412 * @param xTicksToWait The maximum amount of time the task should block
\r
413 * waiting for space to become available on the queue, should it already
\r
414 * be full. The call will return immediately if this is set to 0 and the
\r
415 * queue is full. The time is defined in tick periods so the constant
\r
416 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
418 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
419 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
420 * at the front of the queue (for high priority messages).
\r
422 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
432 unsigned long ulVar = 10UL;
\r
434 void vATask( void *pvParameters )
\r
436 xQueueHandle xQueue1, xQueue2;
\r
437 struct AMessage *pxMessage;
\r
439 // Create a queue capable of containing 10 unsigned long values.
\r
440 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
442 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
443 // These should be passed by pointer as they contain a lot of data.
\r
444 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
450 // Send an unsigned long. Wait for 10 ticks for space to become
\r
451 // available if necessary.
\r
452 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
454 // Failed to post the message, even after 10 ticks.
\r
460 // Send a pointer to a struct AMessage object. Don't block if the
\r
461 // queue is already full.
\r
462 pxMessage = & xMessage;
\r
463 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
466 // ... Rest of task code.
\r
469 * \defgroup xQueueSend xQueueSend
\r
470 * \ingroup QueueManagement
\r
472 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
477 portBASE_TYPE xQueuePeek(
\r
478 xQueueHandle xQueue,
\r
480 portTickType xTicksToWait
\r
483 * This is a macro that calls the xQueueGenericReceive() function.
\r
485 * Receive an item from a queue without removing the item from the queue.
\r
486 * The item is received by copy so a buffer of adequate size must be
\r
487 * provided. The number of bytes copied into the buffer was defined when
\r
488 * the queue was created.
\r
490 * Successfully received items remain on the queue so will be returned again
\r
491 * by the next call, or a call to xQueueReceive().
\r
493 * This macro must not be used in an interrupt service routine.
\r
495 * @param pxQueue The handle to the queue from which the item is to be
\r
498 * @param pvBuffer Pointer to the buffer into which the received item will
\r
501 * @param xTicksToWait The maximum amount of time the task should block
\r
502 * waiting for an item to receive should the queue be empty at the time
\r
503 * of the call. The time is defined in tick periods so the constant
\r
504 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
505 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
\r
508 * @return pdTRUE if an item was successfully received from the queue,
\r
509 * otherwise pdFALSE.
\r
519 xQueueHandle xQueue;
\r
521 // Task to create a queue and post a value.
\r
522 void vATask( void *pvParameters )
\r
524 struct AMessage *pxMessage;
\r
526 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
527 // These should be passed by pointer as they contain a lot of data.
\r
528 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
531 // Failed to create the queue.
\r
536 // Send a pointer to a struct AMessage object. Don't block if the
\r
537 // queue is already full.
\r
538 pxMessage = & xMessage;
\r
539 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
541 // ... Rest of task code.
\r
544 // Task to peek the data from the queue.
\r
545 void vADifferentTask( void *pvParameters )
\r
547 struct AMessage *pxRxedMessage;
\r
551 // Peek a message on the created queue. Block for 10 ticks if a
\r
552 // message is not immediately available.
\r
553 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
555 // pcRxedMessage now points to the struct AMessage variable posted
\r
556 // by vATask, but the item still remains on the queue.
\r
560 // ... Rest of task code.
\r
563 * \defgroup xQueueReceive xQueueReceive
\r
564 * \ingroup QueueManagement
\r
566 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
571 portBASE_TYPE xQueueReceive(
\r
572 xQueueHandle xQueue,
\r
574 portTickType xTicksToWait
\r
577 * This is a macro that calls the xQueueGenericReceive() function.
\r
579 * Receive an item from a queue. The item is received by copy so a buffer of
\r
580 * adequate size must be provided. The number of bytes copied into the buffer
\r
581 * was defined when the queue was created.
\r
583 * Successfully received items are removed from the queue.
\r
585 * This function must not be used in an interrupt service routine. See
\r
586 * xQueueReceiveFromISR for an alternative that can.
\r
588 * @param pxQueue The handle to the queue from which the item is to be
\r
591 * @param pvBuffer Pointer to the buffer into which the received item will
\r
594 * @param xTicksToWait The maximum amount of time the task should block
\r
595 * waiting for an item to receive should the queue be empty at the time
\r
596 * of the call. xQueueReceive() will return immediately if xTicksToWait
\r
597 * is zero and the queue is empty. The time is defined in tick periods so the
\r
598 * constant portTICK_RATE_MS should be used to convert to real time if this is
\r
601 * @return pdTRUE if an item was successfully received from the queue,
\r
602 * otherwise pdFALSE.
\r
612 xQueueHandle xQueue;
\r
614 // Task to create a queue and post a value.
\r
615 void vATask( void *pvParameters )
\r
617 struct AMessage *pxMessage;
\r
619 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
620 // These should be passed by pointer as they contain a lot of data.
\r
621 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
624 // Failed to create the queue.
\r
629 // Send a pointer to a struct AMessage object. Don't block if the
\r
630 // queue is already full.
\r
631 pxMessage = & xMessage;
\r
632 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
634 // ... Rest of task code.
\r
637 // Task to receive from the queue.
\r
638 void vADifferentTask( void *pvParameters )
\r
640 struct AMessage *pxRxedMessage;
\r
644 // Receive a message on the created queue. Block for 10 ticks if a
\r
645 // message is not immediately available.
\r
646 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
648 // pcRxedMessage now points to the struct AMessage variable posted
\r
653 // ... Rest of task code.
\r
656 * \defgroup xQueueReceive xQueueReceive
\r
657 * \ingroup QueueManagement
\r
659 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
665 portBASE_TYPE xQueueGenericReceive(
\r
666 xQueueHandle xQueue,
\r
668 portTickType xTicksToWait
\r
669 portBASE_TYPE xJustPeek
\r
672 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
673 * this function directly.
\r
675 * Receive an item from a queue. The item is received by copy so a buffer of
\r
676 * adequate size must be provided. The number of bytes copied into the buffer
\r
677 * was defined when the queue was created.
\r
679 * This function must not be used in an interrupt service routine. See
\r
680 * xQueueReceiveFromISR for an alternative that can.
\r
682 * @param pxQueue The handle to the queue from which the item is to be
\r
685 * @param pvBuffer Pointer to the buffer into which the received item will
\r
688 * @param xTicksToWait The maximum amount of time the task should block
\r
689 * waiting for an item to receive should the queue be empty at the time
\r
690 * of the call. The time is defined in tick periods so the constant
\r
691 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
692 * xQueueGenericReceive() will return immediately if the queue is empty and
\r
693 * xTicksToWait is 0.
\r
695 * @param xJustPeek When set to true, the item received from the queue is not
\r
696 * actually removed from the queue - meaning a subsequent call to
\r
697 * xQueueReceive() will return the same item. When set to false, the item
\r
698 * being received from the queue is also removed from the queue.
\r
700 * @return pdTRUE if an item was successfully received from the queue,
\r
701 * otherwise pdFALSE.
\r
711 xQueueHandle xQueue;
\r
713 // Task to create a queue and post a value.
\r
714 void vATask( void *pvParameters )
\r
716 struct AMessage *pxMessage;
\r
718 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
719 // These should be passed by pointer as they contain a lot of data.
\r
720 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
723 // Failed to create the queue.
\r
728 // Send a pointer to a struct AMessage object. Don't block if the
\r
729 // queue is already full.
\r
730 pxMessage = & xMessage;
\r
731 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
733 // ... Rest of task code.
\r
736 // Task to receive from the queue.
\r
737 void vADifferentTask( void *pvParameters )
\r
739 struct AMessage *pxRxedMessage;
\r
743 // Receive a message on the created queue. Block for 10 ticks if a
\r
744 // message is not immediately available.
\r
745 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
747 // pcRxedMessage now points to the struct AMessage variable posted
\r
752 // ... Rest of task code.
\r
755 * \defgroup xQueueReceive xQueueReceive
\r
756 * \ingroup QueueManagement
\r
758 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
762 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
764 * Return the number of messages stored in a queue.
\r
766 * @param xQueue A handle to the queue being queried.
\r
768 * @return The number of messages available in the queue.
\r
770 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
771 * \ingroup QueueManagement
\r
773 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
777 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
779 * Delete a queue - freeing all the memory allocated for storing of items
\r
780 * placed on the queue.
\r
782 * @param xQueue A handle to the queue to be deleted.
\r
784 * \page vQueueDelete vQueueDelete
\r
785 * \ingroup QueueManagement
\r
787 void vQueueDelete( xQueueHandle xQueue );
\r
792 portBASE_TYPE xQueueSendToFrontFromISR(
\r
793 xQueueHandle pxQueue,
\r
794 const void *pvItemToQueue,
\r
795 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
799 * This is a macro that calls xQueueGenericSendFromISR().
\r
801 * Post an item to the front of a queue. It is safe to use this macro from
\r
802 * within an interrupt service routine.
\r
804 * Items are queued by copy not reference so it is preferable to only
\r
805 * queue small items, especially when called from an ISR. In most cases
\r
806 * it would be preferable to store a pointer to the item being queued.
\r
808 * @param xQueue The handle to the queue on which the item is to be posted.
\r
810 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
811 * queue. The size of the items the queue will hold was defined when the
\r
812 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
813 * into the queue storage area.
\r
815 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
\r
816 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
817 * to unblock, and the unblocked task has a priority higher than the currently
\r
818 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
\r
819 * a context switch should be requested before the interrupt is exited.
\r
821 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
824 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
827 void vBufferISR( void )
\r
830 portBASE_TYPE xHigherPrioritTaskWoken;
\r
832 // We have not woken a task at the start of the ISR.
\r
833 xHigherPriorityTaskWoken = pdFALSE;
\r
835 // Loop until the buffer is empty.
\r
838 // Obtain a byte from the buffer.
\r
839 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
842 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
844 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
846 // Now the buffer is empty we can switch context if necessary.
\r
847 if( xHigherPriorityTaskWoken )
\r
854 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
855 * \ingroup QueueManagement
\r
857 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_FRONT )
\r
863 portBASE_TYPE xQueueSendToBackFromISR(
\r
864 xQueueHandle pxQueue,
\r
865 const void *pvItemToQueue,
\r
866 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
870 * This is a macro that calls xQueueGenericSendFromISR().
\r
872 * Post an item to the back of a queue. It is safe to use this macro from
\r
873 * within an interrupt service routine.
\r
875 * Items are queued by copy not reference so it is preferable to only
\r
876 * queue small items, especially when called from an ISR. In most cases
\r
877 * it would be preferable to store a pointer to the item being queued.
\r
879 * @param xQueue The handle to the queue on which the item is to be posted.
\r
881 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
882 * queue. The size of the items the queue will hold was defined when the
\r
883 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
884 * into the queue storage area.
\r
886 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
\r
887 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
888 * to unblock, and the unblocked task has a priority higher than the currently
\r
889 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
\r
890 * a context switch should be requested before the interrupt is exited.
\r
892 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
895 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
898 void vBufferISR( void )
\r
901 portBASE_TYPE xHigherPriorityTaskWoken;
\r
903 // We have not woken a task at the start of the ISR.
\r
904 xHigherPriorityTaskWoken = pdFALSE;
\r
906 // Loop until the buffer is empty.
\r
909 // Obtain a byte from the buffer.
\r
910 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
913 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
915 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
917 // Now the buffer is empty we can switch context if necessary.
\r
918 if( xHigherPriorityTaskWoken )
\r
925 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
926 * \ingroup QueueManagement
\r
928 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
933 portBASE_TYPE xQueueSendFromISR(
\r
934 xQueueHandle pxQueue,
\r
935 const void *pvItemToQueue,
\r
936 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
940 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
941 * for backward compatibility with versions of FreeRTOS.org that did not
\r
942 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
945 * Post an item to the back of a queue. It is safe to use this function from
\r
946 * within an interrupt service routine.
\r
948 * Items are queued by copy not reference so it is preferable to only
\r
949 * queue small items, especially when called from an ISR. In most cases
\r
950 * it would be preferable to store a pointer to the item being queued.
\r
952 * @param xQueue The handle to the queue on which the item is to be posted.
\r
954 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
955 * queue. The size of the items the queue will hold was defined when the
\r
956 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
957 * into the queue storage area.
\r
959 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
\r
960 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
961 * to unblock, and the unblocked task has a priority higher than the currently
\r
962 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
963 * a context switch should be requested before the interrupt is exited.
\r
965 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
968 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
971 void vBufferISR( void )
\r
974 portBASE_TYPE xHigherPriorityTaskWoken;
\r
976 // We have not woken a task at the start of the ISR.
\r
977 xHigherPriorityTaskWoken = pdFALSE;
\r
979 // Loop until the buffer is empty.
\r
982 // Obtain a byte from the buffer.
\r
983 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
986 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
988 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
990 // Now the buffer is empty we can switch context if necessary.
\r
991 if( xHigherPriorityTaskWoken )
\r
993 // Actual macro used here is port specific.
\r
994 taskYIELD_FROM_ISR ();
\r
999 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1000 * \ingroup QueueManagement
\r
1002 #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
1007 portBASE_TYPE xQueueGenericSendFromISR(
\r
1008 xQueueHandle pxQueue,
\r
1009 const void *pvItemToQueue,
\r
1010 portBASE_TYPE *pxHigherPriorityTaskWoken,
\r
1011 portBASE_TYPE xCopyPosition
\r
1015 * It is preferred that the macros xQueueSendFromISR(),
\r
1016 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1017 * of calling this function directly.
\r
1019 * Post an item on a queue. It is safe to use this function from within an
\r
1020 * interrupt service routine.
\r
1022 * Items are queued by copy not reference so it is preferable to only
\r
1023 * queue small items, especially when called from an ISR. In most cases
\r
1024 * it would be preferable to store a pointer to the item being queued.
\r
1026 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1028 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1029 * queue. The size of the items the queue will hold was defined when the
\r
1030 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1031 * into the queue storage area.
\r
1033 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
\r
1034 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1035 * to unblock, and the unblocked task has a priority higher than the currently
\r
1036 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
\r
1037 * a context switch should be requested before the interrupt is exited.
\r
1039 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1040 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1041 * at the front of the queue (for high priority messages).
\r
1043 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1046 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1049 void vBufferISR( void )
\r
1052 portBASE_TYPE xHigherPriorityTaskWokenByPost;
\r
1054 // We have not woken a task at the start of the ISR.
\r
1055 xHigherPriorityTaskWokenByPost = pdFALSE;
\r
1057 // Loop until the buffer is empty.
\r
1060 // Obtain a byte from the buffer.
\r
1061 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1063 // Post each byte.
\r
1064 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
\r
1066 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1068 // Now the buffer is empty we can switch context if necessary. Note that the
\r
1069 // name of the yield function required is port specific.
\r
1070 if( xHigherPriorityTaskWokenByPost )
\r
1072 taskYIELD_YIELD_FROM_ISR();
\r
1077 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1078 * \ingroup QueueManagement
\r
1080 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
\r
1085 portBASE_TYPE xQueueReceiveFromISR(
\r
1086 xQueueHandle pxQueue,
\r
1088 portBASE_TYPE *pxTaskWoken
\r
1092 * Receive an item from a queue. It is safe to use this function from within an
\r
1093 * interrupt service routine.
\r
1095 * @param pxQueue The handle to the queue from which the item is to be
\r
1098 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1101 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1102 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1103 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1104 * remain unchanged.
\r
1106 * @return pdTRUE if an item was successfully received from the queue,
\r
1107 * otherwise pdFALSE.
\r
1112 xQueueHandle xQueue;
\r
1114 // Function to create a queue and post some values.
\r
1115 void vAFunction( void *pvParameters )
\r
1117 char cValueToPost;
\r
1118 const portTickType xBlockTime = ( portTickType )0xff;
\r
1120 // Create a queue capable of containing 10 characters.
\r
1121 xQueue = xQueueCreate( 10, sizeof( char ) );
\r
1124 // Failed to create the queue.
\r
1129 // Post some characters that will be used within an ISR. If the queue
\r
1130 // is full then this task will block for xBlockTime ticks.
\r
1131 cValueToPost = 'a';
\r
1132 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1133 cValueToPost = 'b';
\r
1134 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1136 // ... keep posting characters ... this task may block when the queue
\r
1139 cValueToPost = 'c';
\r
1140 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1143 // ISR that outputs all the characters received on the queue.
\r
1144 void vISR_Routine( void )
\r
1146 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1149 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1151 // A character was received. Output the character now.
\r
1152 vOutputCharacter( cRxedChar );
\r
1154 // If removing the character from the queue woke the task that was
\r
1155 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1156 // pdTRUE. No matter how many times this loop iterates only one
\r
1157 // task will be woken.
\r
1160 if( cTaskWokenByPost != ( char ) pdFALSE;
\r
1166 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1167 * \ingroup QueueManagement
\r
1169 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1172 * Utilities to query queue that are safe to use from an ISR. These utilities
\r
1173 * should be used only from witin an ISR, or within a critical section.
\r
1175 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
\r
1176 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
\r
1177 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
\r
1181 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1182 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1183 * xQueueGenericReceive().
\r
1185 * The source code that implements the alternative (Alt) API is much
\r
1186 * simpler because it executes everything from within a critical section.
\r
1187 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1188 * preferred fully featured API too. The fully featured API has more
\r
1189 * complex code that takes longer to execute, but makes much less use of
\r
1190 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1191 * responsiveness to gain execution speed, whereas the fully featured API
\r
1192 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1194 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1195 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1196 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
1197 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
1198 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
1199 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
1202 * The functions defined above are for passing data to and from tasks. The
\r
1203 * functions below are the equivalents for passing data to and from
\r
1206 * These functions are called from the co-routine macro implementation and
\r
1207 * should not be called directly from application code. Instead use the macro
\r
1208 * wrappers defined within croutine.h.
\r
1210 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1211 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1212 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1213 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1216 * For internal use only. Use xSemaphoreCreateMutex() or
\r
1217 * xSemaphoreCreateCounting() instead of calling these functions directly.
\r
1219 xQueueHandle xQueueCreateMutex( void );
\r
1220 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1223 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1224 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1226 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
\r
1227 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex );
\r
1230 * The registry is provided as a means for kernel aware debuggers to
\r
1231 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
\r
1232 * a queue, semaphore or mutex handle to the registry if you want the handle
\r
1233 * to be available to a kernel aware debugger. If you are not using a kernel
\r
1234 * aware debugger then this function can be ignored.
\r
1236 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
\r
1237 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
\r
1238 * within FreeRTOSConfig.h for the registry to be available. Its value
\r
1239 * does not effect the number of queues, semaphores and mutexes that can be
\r
1240 * created - just the number that the registry can hold.
\r
1242 * @param xQueue The handle of the queue being added to the registry. This
\r
1243 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
\r
1244 * handles can also be passed in here.
\r
1246 * @param pcName The name to be associated with the handle. This is the
\r
1247 * name that the kernel aware debugger will display.
\r
1249 #if configQUEUE_REGISTRY_SIZE > 0
\r
1250 void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcName );
\r
1256 #ifdef __cplusplus
\r
1260 #endif /* QUEUE_H */
\r