2 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * The FreeRTOS eBook and reference manual are available to purchase for a *
\r
29 * small fee. Help yourself get started quickly while also helping the *
\r
30 * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *
\r
32 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
49 #ifndef INC_FREERTOS_H
\r
50 #error "#include FreeRTOS.h" must appear in source files before "#include queue.h"
\r
64 #include "mpu_wrappers.h"
\r
67 typedef void * xQueueHandle;
\r
70 /* For internal use only. */
\r
71 #define queueSEND_TO_BACK ( 0 )
\r
72 #define queueSEND_TO_FRONT ( 1 )
\r
78 xQueueHandle xQueueCreate(
\r
79 unsigned portBASE_TYPE uxQueueLength,
\r
80 unsigned portBASE_TYPE uxItemSize
\r
84 * Creates a new queue instance. This allocates the storage required by the
\r
85 * new queue and returns a handle for the queue.
\r
87 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
89 * @param uxItemSize The number of bytes each item in the queue will require.
\r
90 * Items are queued by copy, not by reference, so this is the number of bytes
\r
91 * that will be copied for each posted item. Each item on the queue must be
\r
94 * @return If the queue is successfully create then a handle to the newly
\r
95 * created queue is returned. If the queue cannot be created then 0 is
\r
106 void vATask( void *pvParameters )
\r
108 xQueueHandle xQueue1, xQueue2;
\r
110 // Create a queue capable of containing 10 unsigned long values.
\r
111 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
114 // Queue was not created and must not be used.
\r
117 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
118 // These should be passed by pointer as they contain a lot of data.
\r
119 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
122 // Queue was not created and must not be used.
\r
125 // ... Rest of task code.
\r
128 * \defgroup xQueueCreate xQueueCreate
\r
129 * \ingroup QueueManagement
\r
131 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
136 portBASE_TYPE xQueueSendToToFront(
\r
137 xQueueHandle xQueue,
\r
138 const void * pvItemToQueue,
\r
139 portTickType xTicksToWait
\r
143 * This is a macro that calls xQueueGenericSend().
\r
145 * Post an item to the front of a queue. The item is queued by copy, not by
\r
146 * reference. This function must not be called from an interrupt service
\r
147 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
150 * @param xQueue The handle to the queue on which the item is to be posted.
\r
152 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
153 * queue. The size of the items the queue will hold was defined when the
\r
154 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
155 * into the queue storage area.
\r
157 * @param xTicksToWait The maximum amount of time the task should block
\r
158 * waiting for space to become available on the queue, should it already
\r
159 * be full. The call will return immediately if this is set to 0 and the
\r
160 * queue is full. The time is defined in tick periods so the constant
\r
161 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
163 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
173 unsigned long ulVar = 10UL;
\r
175 void vATask( void *pvParameters )
\r
177 xQueueHandle xQueue1, xQueue2;
\r
178 struct AMessage *pxMessage;
\r
180 // Create a queue capable of containing 10 unsigned long values.
\r
181 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
183 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
184 // These should be passed by pointer as they contain a lot of data.
\r
185 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
191 // Send an unsigned long. Wait for 10 ticks for space to become
\r
192 // available if necessary.
\r
193 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
195 // Failed to post the message, even after 10 ticks.
\r
201 // Send a pointer to a struct AMessage object. Don't block if the
\r
202 // queue is already full.
\r
203 pxMessage = & xMessage;
\r
204 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
207 // ... Rest of task code.
\r
210 * \defgroup xQueueSend xQueueSend
\r
211 * \ingroup QueueManagement
\r
213 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
218 portBASE_TYPE xQueueSendToBack(
\r
219 xQueueHandle xQueue,
\r
220 const void * pvItemToQueue,
\r
221 portTickType xTicksToWait
\r
225 * This is a macro that calls xQueueGenericSend().
\r
227 * Post an item to the back of a queue. The item is queued by copy, not by
\r
228 * reference. This function must not be called from an interrupt service
\r
229 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
232 * @param xQueue The handle to the queue on which the item is to be posted.
\r
234 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
235 * queue. The size of the items the queue will hold was defined when the
\r
236 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
237 * into the queue storage area.
\r
239 * @param xTicksToWait The maximum amount of time the task should block
\r
240 * waiting for space to become available on the queue, should it already
\r
241 * be full. The call will return immediately if this is set to 0 and the queue
\r
242 * is full. The time is defined in tick periods so the constant
\r
243 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
245 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
255 unsigned long ulVar = 10UL;
\r
257 void vATask( void *pvParameters )
\r
259 xQueueHandle xQueue1, xQueue2;
\r
260 struct AMessage *pxMessage;
\r
262 // Create a queue capable of containing 10 unsigned long values.
\r
263 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
265 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
266 // These should be passed by pointer as they contain a lot of data.
\r
267 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
273 // Send an unsigned long. Wait for 10 ticks for space to become
\r
274 // available if necessary.
\r
275 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
277 // Failed to post the message, even after 10 ticks.
\r
283 // Send a pointer to a struct AMessage object. Don't block if the
\r
284 // queue is already full.
\r
285 pxMessage = & xMessage;
\r
286 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
289 // ... Rest of task code.
\r
292 * \defgroup xQueueSend xQueueSend
\r
293 * \ingroup QueueManagement
\r
295 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
300 portBASE_TYPE xQueueSend(
\r
301 xQueueHandle xQueue,
\r
302 const void * pvItemToQueue,
\r
303 portTickType xTicksToWait
\r
307 * This is a macro that calls xQueueGenericSend(). It is included for
\r
308 * backward compatibility with versions of FreeRTOS.org that did not
\r
309 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
310 * equivalent to xQueueSendToBack().
\r
312 * Post an item on a queue. The item is queued by copy, not by reference.
\r
313 * This function must not be called from an interrupt service routine.
\r
314 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
316 * @param xQueue The handle to the queue on which the item is to be posted.
\r
318 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
319 * queue. The size of the items the queue will hold was defined when the
\r
320 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
321 * into the queue storage area.
\r
323 * @param xTicksToWait The maximum amount of time the task should block
\r
324 * waiting for space to become available on the queue, should it already
\r
325 * be full. The call will return immediately if this is set to 0 and the
\r
326 * queue is full. The time is defined in tick periods so the constant
\r
327 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
329 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
339 unsigned long ulVar = 10UL;
\r
341 void vATask( void *pvParameters )
\r
343 xQueueHandle xQueue1, xQueue2;
\r
344 struct AMessage *pxMessage;
\r
346 // Create a queue capable of containing 10 unsigned long values.
\r
347 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
349 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
350 // These should be passed by pointer as they contain a lot of data.
\r
351 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
357 // Send an unsigned long. Wait for 10 ticks for space to become
\r
358 // available if necessary.
\r
359 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
361 // Failed to post the message, even after 10 ticks.
\r
367 // Send a pointer to a struct AMessage object. Don't block if the
\r
368 // queue is already full.
\r
369 pxMessage = & xMessage;
\r
370 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
373 // ... Rest of task code.
\r
376 * \defgroup xQueueSend xQueueSend
\r
377 * \ingroup QueueManagement
\r
379 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
385 portBASE_TYPE xQueueGenericSend(
\r
386 xQueueHandle xQueue,
\r
387 const void * pvItemToQueue,
\r
388 portTickType xTicksToWait
\r
389 portBASE_TYPE xCopyPosition
\r
393 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
394 * xQueueSendToBack() are used in place of calling this function directly.
\r
396 * Post an item on a queue. The item is queued by copy, not by reference.
\r
397 * This function must not be called from an interrupt service routine.
\r
398 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
400 * @param xQueue The handle to the queue on which the item is to be posted.
\r
402 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
403 * queue. The size of the items the queue will hold was defined when the
\r
404 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
405 * into the queue storage area.
\r
407 * @param xTicksToWait The maximum amount of time the task should block
\r
408 * waiting for space to become available on the queue, should it already
\r
409 * be full. The call will return immediately if this is set to 0 and the
\r
410 * queue is full. The time is defined in tick periods so the constant
\r
411 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
413 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
414 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
415 * at the front of the queue (for high priority messages).
\r
417 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
427 unsigned long ulVar = 10UL;
\r
429 void vATask( void *pvParameters )
\r
431 xQueueHandle xQueue1, xQueue2;
\r
432 struct AMessage *pxMessage;
\r
434 // Create a queue capable of containing 10 unsigned long values.
\r
435 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
\r
437 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
438 // These should be passed by pointer as they contain a lot of data.
\r
439 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
445 // Send an unsigned long. Wait for 10 ticks for space to become
\r
446 // available if necessary.
\r
447 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
449 // Failed to post the message, even after 10 ticks.
\r
455 // Send a pointer to a struct AMessage object. Don't block if the
\r
456 // queue is already full.
\r
457 pxMessage = & xMessage;
\r
458 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
461 // ... Rest of task code.
\r
464 * \defgroup xQueueSend xQueueSend
\r
465 * \ingroup QueueManagement
\r
467 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
472 portBASE_TYPE xQueuePeek(
\r
473 xQueueHandle xQueue,
\r
475 portTickType xTicksToWait
\r
478 * This is a macro that calls the xQueueGenericReceive() function.
\r
480 * Receive an item from a queue without removing the item from the queue.
\r
481 * The item is received by copy so a buffer of adequate size must be
\r
482 * provided. The number of bytes copied into the buffer was defined when
\r
483 * the queue was created.
\r
485 * Successfully received items remain on the queue so will be returned again
\r
486 * by the next call, or a call to xQueueReceive().
\r
488 * This macro must not be used in an interrupt service routine.
\r
490 * @param pxQueue The handle to the queue from which the item is to be
\r
493 * @param pvBuffer Pointer to the buffer into which the received item will
\r
496 * @param xTicksToWait The maximum amount of time the task should block
\r
497 * waiting for an item to receive should the queue be empty at the time
\r
498 * of the call. The time is defined in tick periods so the constant
\r
499 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
500 * xQueuePeek() will return immediately if xTicksToWait is 0 and the queue
\r
503 * @return pdTRUE if an item was successfully received from the queue,
\r
504 * otherwise pdFALSE.
\r
514 xQueueHandle xQueue;
\r
516 // Task to create a queue and post a value.
\r
517 void vATask( void *pvParameters )
\r
519 struct AMessage *pxMessage;
\r
521 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
522 // These should be passed by pointer as they contain a lot of data.
\r
523 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
526 // Failed to create the queue.
\r
531 // Send a pointer to a struct AMessage object. Don't block if the
\r
532 // queue is already full.
\r
533 pxMessage = & xMessage;
\r
534 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
536 // ... Rest of task code.
\r
539 // Task to peek the data from the queue.
\r
540 void vADifferentTask( void *pvParameters )
\r
542 struct AMessage *pxRxedMessage;
\r
546 // Peek a message on the created queue. Block for 10 ticks if a
\r
547 // message is not immediately available.
\r
548 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
550 // pcRxedMessage now points to the struct AMessage variable posted
\r
551 // by vATask, but the item still remains on the queue.
\r
555 // ... Rest of task code.
\r
558 * \defgroup xQueueReceive xQueueReceive
\r
559 * \ingroup QueueManagement
\r
561 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
566 portBASE_TYPE xQueueReceive(
\r
567 xQueueHandle xQueue,
\r
569 portTickType xTicksToWait
\r
572 * This is a macro that calls the xQueueGenericReceive() function.
\r
574 * Receive an item from a queue. The item is received by copy so a buffer of
\r
575 * adequate size must be provided. The number of bytes copied into the buffer
\r
576 * was defined when the queue was created.
\r
578 * Successfully received items are removed from the queue.
\r
580 * This function must not be used in an interrupt service routine. See
\r
581 * xQueueReceiveFromISR for an alternative that can.
\r
583 * @param pxQueue The handle to the queue from which the item is to be
\r
586 * @param pvBuffer Pointer to the buffer into which the received item will
\r
589 * @param xTicksToWait The maximum amount of time the task should block
\r
590 * waiting for an item to receive should the queue be empty at the time
\r
591 * of the call. xQueueReceive() will return immediately if xTicksToWait
\r
592 * is zero and the queue is empty. The time is defined in tick periods so the
\r
593 * constant portTICK_RATE_MS should be used to convert to real time if this is
\r
596 * @return pdTRUE if an item was successfully received from the queue,
\r
597 * otherwise pdFALSE.
\r
607 xQueueHandle xQueue;
\r
609 // Task to create a queue and post a value.
\r
610 void vATask( void *pvParameters )
\r
612 struct AMessage *pxMessage;
\r
614 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
615 // These should be passed by pointer as they contain a lot of data.
\r
616 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
619 // Failed to create the queue.
\r
624 // Send a pointer to a struct AMessage object. Don't block if the
\r
625 // queue is already full.
\r
626 pxMessage = & xMessage;
\r
627 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
629 // ... Rest of task code.
\r
632 // Task to receive from the queue.
\r
633 void vADifferentTask( void *pvParameters )
\r
635 struct AMessage *pxRxedMessage;
\r
639 // Receive a message on the created queue. Block for 10 ticks if a
\r
640 // message is not immediately available.
\r
641 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
643 // pcRxedMessage now points to the struct AMessage variable posted
\r
648 // ... Rest of task code.
\r
651 * \defgroup xQueueReceive xQueueReceive
\r
652 * \ingroup QueueManagement
\r
654 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
660 portBASE_TYPE xQueueGenericReceive(
\r
661 xQueueHandle xQueue,
\r
663 portTickType xTicksToWait
\r
664 portBASE_TYPE xJustPeek
\r
667 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
668 * this function directly.
\r
670 * Receive an item from a queue. The item is received by copy so a buffer of
\r
671 * adequate size must be provided. The number of bytes copied into the buffer
\r
672 * was defined when the queue was created.
\r
674 * This function must not be used in an interrupt service routine. See
\r
675 * xQueueReceiveFromISR for an alternative that can.
\r
677 * @param pxQueue The handle to the queue from which the item is to be
\r
680 * @param pvBuffer Pointer to the buffer into which the received item will
\r
683 * @param xTicksToWait The maximum amount of time the task should block
\r
684 * waiting for an item to receive should the queue be empty at the time
\r
685 * of the call. The time is defined in tick periods so the constant
\r
686 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
687 * xQueueGenericReceive() will return immediately if the queue is empty and
\r
688 * xTicksToWait is 0.
\r
690 * @param xJustPeek When set to true, the item received from the queue is not
\r
691 * actually removed from the queue - meaning a subsequent call to
\r
692 * xQueueReceive() will return the same item. When set to false, the item
\r
693 * being received from the queue is also removed from the queue.
\r
695 * @return pdTRUE if an item was successfully received from the queue,
\r
696 * otherwise pdFALSE.
\r
706 xQueueHandle xQueue;
\r
708 // Task to create a queue and post a value.
\r
709 void vATask( void *pvParameters )
\r
711 struct AMessage *pxMessage;
\r
713 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
714 // These should be passed by pointer as they contain a lot of data.
\r
715 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
718 // Failed to create the queue.
\r
723 // Send a pointer to a struct AMessage object. Don't block if the
\r
724 // queue is already full.
\r
725 pxMessage = & xMessage;
\r
726 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
728 // ... Rest of task code.
\r
731 // Task to receive from the queue.
\r
732 void vADifferentTask( void *pvParameters )
\r
734 struct AMessage *pxRxedMessage;
\r
738 // Receive a message on the created queue. Block for 10 ticks if a
\r
739 // message is not immediately available.
\r
740 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
742 // pcRxedMessage now points to the struct AMessage variable posted
\r
747 // ... Rest of task code.
\r
750 * \defgroup xQueueReceive xQueueReceive
\r
751 * \ingroup QueueManagement
\r
753 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
757 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
759 * Return the number of messages stored in a queue.
\r
761 * @param xQueue A handle to the queue being queried.
\r
763 * @return The number of messages available in the queue.
\r
765 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
766 * \ingroup QueueManagement
\r
768 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
772 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
774 * Delete a queue - freeing all the memory allocated for storing of items
\r
775 * placed on the queue.
\r
777 * @param xQueue A handle to the queue to be deleted.
\r
779 * \page vQueueDelete vQueueDelete
\r
780 * \ingroup QueueManagement
\r
782 void vQueueDelete( xQueueHandle xQueue );
\r
787 portBASE_TYPE xQueueSendToFrontFromISR(
\r
788 xQueueHandle pxQueue,
\r
789 const void *pvItemToQueue,
\r
790 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
794 * This is a macro that calls xQueueGenericSendFromISR().
\r
796 * Post an item to the front of a queue. It is safe to use this macro from
\r
797 * within an interrupt service routine.
\r
799 * Items are queued by copy not reference so it is preferable to only
\r
800 * queue small items, especially when called from an ISR. In most cases
\r
801 * it would be preferable to store a pointer to the item being queued.
\r
803 * @param xQueue The handle to the queue on which the item is to be posted.
\r
805 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
806 * queue. The size of the items the queue will hold was defined when the
\r
807 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
808 * into the queue storage area.
\r
810 * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
\r
811 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
812 * to unblock, and the unblocked task has a priority higher than the currently
\r
813 * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
\r
814 * a context switch should be requested before the interrupt is exited.
\r
816 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
819 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
822 void vBufferISR( void )
\r
825 portBASE_TYPE xHigherPrioritTaskWoken;
\r
827 // We have not woken a task at the start of the ISR.
\r
828 xHigherPriorityTaskWoken = pdFALSE;
\r
830 // Loop until the buffer is empty.
\r
833 // Obtain a byte from the buffer.
\r
834 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
837 xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
839 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
841 // Now the buffer is empty we can switch context if necessary.
\r
842 if( xHigherPriorityTaskWoken )
\r
849 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
850 * \ingroup QueueManagement
\r
852 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_FRONT )
\r
858 portBASE_TYPE xQueueSendToBackFromISR(
\r
859 xQueueHandle pxQueue,
\r
860 const void *pvItemToQueue,
\r
861 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
865 * This is a macro that calls xQueueGenericSendFromISR().
\r
867 * Post an item to the back of a queue. It is safe to use this macro from
\r
868 * within an interrupt service routine.
\r
870 * Items are queued by copy not reference so it is preferable to only
\r
871 * queue small items, especially when called from an ISR. In most cases
\r
872 * it would be preferable to store a pointer to the item being queued.
\r
874 * @param xQueue The handle to the queue on which the item is to be posted.
\r
876 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
877 * queue. The size of the items the queue will hold was defined when the
\r
878 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
879 * into the queue storage area.
\r
881 * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
\r
882 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
883 * to unblock, and the unblocked task has a priority higher than the currently
\r
884 * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
\r
885 * a context switch should be requested before the interrupt is exited.
\r
887 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
890 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
893 void vBufferISR( void )
\r
896 portBASE_TYPE xHigherPriorityTaskWoken;
\r
898 // We have not woken a task at the start of the ISR.
\r
899 xHigherPriorityTaskWoken = pdFALSE;
\r
901 // Loop until the buffer is empty.
\r
904 // Obtain a byte from the buffer.
\r
905 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
908 xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
910 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
912 // Now the buffer is empty we can switch context if necessary.
\r
913 if( xHigherPriorityTaskWoken )
\r
920 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
921 * \ingroup QueueManagement
\r
923 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
928 portBASE_TYPE xQueueSendFromISR(
\r
929 xQueueHandle pxQueue,
\r
930 const void *pvItemToQueue,
\r
931 portBASE_TYPE *pxHigherPriorityTaskWoken
\r
935 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
936 * for backward compatibility with versions of FreeRTOS.org that did not
\r
937 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
940 * Post an item to the back of a queue. It is safe to use this function from
\r
941 * within an interrupt service routine.
\r
943 * Items are queued by copy not reference so it is preferable to only
\r
944 * queue small items, especially when called from an ISR. In most cases
\r
945 * it would be preferable to store a pointer to the item being queued.
\r
947 * @param xQueue The handle to the queue on which the item is to be posted.
\r
949 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
950 * queue. The size of the items the queue will hold was defined when the
\r
951 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
952 * into the queue storage area.
\r
954 * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
\r
955 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
956 * to unblock, and the unblocked task has a priority higher than the currently
\r
957 * running task. If xQueueSendFromISR() sets this value to pdTRUE then
\r
958 * a context switch should be requested before the interrupt is exited.
\r
960 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
963 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
966 void vBufferISR( void )
\r
969 portBASE_TYPE xHigherPriorityTaskWoken;
\r
971 // We have not woken a task at the start of the ISR.
\r
972 xHigherPriorityTaskWoken = pdFALSE;
\r
974 // Loop until the buffer is empty.
\r
977 // Obtain a byte from the buffer.
\r
978 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
981 xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
\r
983 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
985 // Now the buffer is empty we can switch context if necessary.
\r
986 if( xHigherPriorityTaskWoken )
\r
988 // Actual macro used here is port specific.
\r
989 taskYIELD_FROM_ISR ();
\r
994 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
995 * \ingroup QueueManagement
\r
997 #define xQueueSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, pxHigherPriorityTaskWoken, queueSEND_TO_BACK )
\r
1002 portBASE_TYPE xQueueGenericSendFromISR(
\r
1003 xQueueHandle pxQueue,
\r
1004 const void *pvItemToQueue,
\r
1005 portBASE_TYPE *pxHigherPriorityTaskWoken,
\r
1006 portBASE_TYPE xCopyPosition
\r
1010 * It is preferred that the macros xQueueSendFromISR(),
\r
1011 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1012 * of calling this function directly.
\r
1014 * Post an item on a queue. It is safe to use this function from within an
\r
1015 * interrupt service routine.
\r
1017 * Items are queued by copy not reference so it is preferable to only
\r
1018 * queue small items, especially when called from an ISR. In most cases
\r
1019 * it would be preferable to store a pointer to the item being queued.
\r
1021 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1023 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1024 * queue. The size of the items the queue will hold was defined when the
\r
1025 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1026 * into the queue storage area.
\r
1028 * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
\r
1029 * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
\r
1030 * to unblock, and the unblocked task has a priority higher than the currently
\r
1031 * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
\r
1032 * a context switch should be requested before the interrupt is exited.
\r
1034 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1035 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1036 * at the front of the queue (for high priority messages).
\r
1038 * @return pdTRUE if the data was successfully sent to the queue, otherwise
\r
1041 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1044 void vBufferISR( void )
\r
1047 portBASE_TYPE xHigherPriorityTaskWokenByPost;
\r
1049 // We have not woken a task at the start of the ISR.
\r
1050 xHigherPriorityTaskWokenByPost = pdFALSE;
\r
1052 // Loop until the buffer is empty.
\r
1055 // Obtain a byte from the buffer.
\r
1056 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1058 // Post each byte.
\r
1059 xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
\r
1061 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1063 // Now the buffer is empty we can switch context if necessary. Note that the
\r
1064 // name of the yield function required is port specific.
\r
1065 if( xHigherPriorityTaskWokenByPost )
\r
1067 taskYIELD_YIELD_FROM_ISR();
\r
1072 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1073 * \ingroup QueueManagement
\r
1075 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition );
\r
1080 portBASE_TYPE xQueueReceiveFromISR(
\r
1081 xQueueHandle pxQueue,
\r
1083 portBASE_TYPE *pxTaskWoken
\r
1087 * Receive an item from a queue. It is safe to use this function from within an
\r
1088 * interrupt service routine.
\r
1090 * @param pxQueue The handle to the queue from which the item is to be
\r
1093 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1096 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1097 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1098 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1099 * remain unchanged.
\r
1101 * @return pdTRUE if an item was successfully received from the queue,
\r
1102 * otherwise pdFALSE.
\r
1107 xQueueHandle xQueue;
\r
1109 // Function to create a queue and post some values.
\r
1110 void vAFunction( void *pvParameters )
\r
1112 char cValueToPost;
\r
1113 const portTickType xBlockTime = ( portTickType )0xff;
\r
1115 // Create a queue capable of containing 10 characters.
\r
1116 xQueue = xQueueCreate( 10, sizeof( char ) );
\r
1119 // Failed to create the queue.
\r
1124 // Post some characters that will be used within an ISR. If the queue
\r
1125 // is full then this task will block for xBlockTime ticks.
\r
1126 cValueToPost = 'a';
\r
1127 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1128 cValueToPost = 'b';
\r
1129 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1131 // ... keep posting characters ... this task may block when the queue
\r
1134 cValueToPost = 'c';
\r
1135 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1138 // ISR that outputs all the characters received on the queue.
\r
1139 void vISR_Routine( void )
\r
1141 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1144 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1146 // A character was received. Output the character now.
\r
1147 vOutputCharacter( cRxedChar );
\r
1149 // If removing the character from the queue woke the task that was
\r
1150 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1151 // pdTRUE. No matter how many times this loop iterates only one
\r
1152 // task will be woken.
\r
1155 if( cTaskWokenByPost != ( char ) pdFALSE;
\r
1161 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1162 * \ingroup QueueManagement
\r
1164 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1167 * Utilities to query queue that are safe to use from an ISR. These utilities
\r
1168 * should be used only from witin an ISR, or within a critical section.
\r
1170 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue );
\r
1171 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue );
\r
1172 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue );
\r
1176 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1177 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1178 * xQueueGenericReceive().
\r
1180 * The source code that implements the alternative (Alt) API is much
\r
1181 * simpler because it executes everything from within a critical section.
\r
1182 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1183 * preferred fully featured API too. The fully featured API has more
\r
1184 * complex code that takes longer to execute, but makes much less use of
\r
1185 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1186 * responsiveness to gain execution speed, whereas the fully featured API
\r
1187 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1189 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1190 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1191 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
1192 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
1193 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
1194 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
1197 * The functions defined above are for passing data to and from tasks. The
\r
1198 * functions below are the equivalents for passing data to and from
\r
1201 * These functions are called from the co-routine macro implementation and
\r
1202 * should not be called directly from application code. Instead use the macro
\r
1203 * wrappers defined within croutine.h.
\r
1205 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1206 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1207 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1208 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1211 * For internal use only. Use xSemaphoreCreateMutex() or
\r
1212 * xSemaphoreCreateCounting() instead of calling these functions directly.
\r
1214 xQueueHandle xQueueCreateMutex( void );
\r
1215 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1218 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1219 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1221 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
\r
1222 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex );
\r
1225 * The registry is provided as a means for kernel aware debuggers to
\r
1226 * locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
\r
1227 * a queue, semaphore or mutex handle to the registry if you want the handle
\r
1228 * to be available to a kernel aware debugger. If you are not using a kernel
\r
1229 * aware debugger then this function can be ignored.
\r
1231 * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the
\r
1232 * registry can hold. configQUEUE_REGISTRY_SIZE must be greater than 0
\r
1233 * within FreeRTOSConfig.h for the registry to be available. Its value
\r
1234 * does not effect the number of queues, semaphores and mutexes that can be
\r
1235 * created - just the number that the registry can hold.
\r
1237 * @param xQueue The handle of the queue being added to the registry. This
\r
1238 * is the handle returned by a call to xQueueCreate(). Semaphore and mutex
\r
1239 * handles can also be passed in here.
\r
1241 * @param pcName The name to be associated with the handle. This is the
\r
1242 * name that the kernel aware debugger will display.
\r
1244 #if configQUEUE_REGISTRY_SIZE > 0
\r
1245 void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcName );
\r
1251 #ifdef __cplusplus
\r
1255 #endif /* QUEUE_H */
\r