2 FreeRTOS.org V4.7.2 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
28 Please ensure to read the configuration and relevant port sections of the
\r
29 online documentation.
\r
31 +++ http://www.FreeRTOS.org +++
\r
32 Documentation, latest information, license and contact details.
\r
34 +++ http://www.SafeRTOS.com +++
\r
35 A version that is certified for use in safety critical systems.
\r
37 +++ http://www.OpenRTOS.com +++
\r
38 Commercial support, development, porting, licensing and training services.
\r
40 ***************************************************************************
\r
49 typedef void * xQueueHandle;
\r
51 /* For internal use only. */
\r
52 #define queueSEND_TO_BACK ( 0 )
\r
53 #define queueSEND_TO_FRONT ( 1 )
\r
59 xQueueHandle xQueueCreate(
\r
60 unsigned portBASE_TYPE uxQueueLength,
\r
61 unsigned portBASE_TYPE uxItemSize
\r
65 * Creates a new queue instance. This allocates the storage required by the
\r
66 * new queue and returns a handle for the queue.
\r
68 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
70 * @param uxItemSize The number of bytes each item in the queue will require.
\r
71 * Items are queued by copy, not by reference, so this is the number of bytes
\r
72 * that will be copied for each posted item. Each item on the queue must be
\r
75 * @return If the queue is successfully create then a handle to the newly
\r
76 * created queue is returned. If the queue cannot be created then 0 is
\r
83 portCHAR ucMessageID;
\r
84 portCHAR ucData[ 20 ];
\r
87 void vATask( void *pvParameters )
\r
89 xQueueHandle xQueue1, xQueue2;
\r
91 // Create a queue capable of containing 10 unsigned long values.
\r
92 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
95 // Queue was not created and must not be used.
\r
98 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
99 // These should be passed by pointer as they contain a lot of data.
\r
100 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
103 // Queue was not created and must not be used.
\r
106 // ... Rest of task code.
\r
109 * \defgroup xQueueCreate xQueueCreate
\r
110 * \ingroup QueueManagement
\r
112 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
117 portBASE_TYPE xQueueSendToToFront(
\r
118 xQueueHandle xQueue,
\r
119 const void * pvItemToQueue,
\r
120 portTickType xTicksToWait
\r
124 * This is a macro that calls xQueueGenericSend().
\r
126 * Post an item to the front of a queue. The item is queued by copy, not by
\r
127 * reference. This function must not be called from an interrupt service
\r
128 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
131 * @param xQueue The handle to the queue on which the item is to be posted.
\r
133 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
134 * queue. The size of the items the queue will hold was defined when the
\r
135 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
136 * into the queue storage area.
\r
138 * @param xTicksToWait The maximum amount of time the task should block
\r
139 * waiting for space to become available on the queue, should it already
\r
140 * be full. The call will return immediately if this is set to 0. The
\r
141 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
142 * should be used to convert to real time if this is required.
\r
144 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
150 portCHAR ucMessageID;
\r
151 portCHAR ucData[ 20 ];
\r
154 unsigned portLONG ulVar = 10UL;
\r
156 void vATask( void *pvParameters )
\r
158 xQueueHandle xQueue1, xQueue2;
\r
159 struct AMessage *pxMessage;
\r
161 // Create a queue capable of containing 10 unsigned long values.
\r
162 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
164 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
165 // These should be passed by pointer as they contain a lot of data.
\r
166 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
172 // Send an unsigned long. Wait for 10 ticks for space to become
\r
173 // available if necessary.
\r
174 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
176 // Failed to post the message, even after 10 ticks.
\r
182 // Send a pointer to a struct AMessage object. Don't block if the
\r
183 // queue is already full.
\r
184 pxMessage = & xMessage;
\r
185 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
188 // ... Rest of task code.
\r
191 * \defgroup xQueueSend xQueueSend
\r
192 * \ingroup QueueManagement
\r
194 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
199 portBASE_TYPE xQueueSendToBack(
\r
200 xQueueHandle xQueue,
\r
201 const void * pvItemToQueue,
\r
202 portTickType xTicksToWait
\r
206 * This is a macro that calls xQueueGenericSend().
\r
208 * Post an item to the back of a queue. The item is queued by copy, not by
\r
209 * reference. This function must not be called from an interrupt service
\r
210 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
213 * @param xQueue The handle to the queue on which the item is to be posted.
\r
215 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
216 * queue. The size of the items the queue will hold was defined when the
\r
217 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
218 * into the queue storage area.
\r
220 * @param xTicksToWait The maximum amount of time the task should block
\r
221 * waiting for space to become available on the queue, should it already
\r
222 * be full. The call will return immediately if this is set to 0. The
\r
223 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
224 * should be used to convert to real time if this is required.
\r
226 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
232 portCHAR ucMessageID;
\r
233 portCHAR ucData[ 20 ];
\r
236 unsigned portLONG ulVar = 10UL;
\r
238 void vATask( void *pvParameters )
\r
240 xQueueHandle xQueue1, xQueue2;
\r
241 struct AMessage *pxMessage;
\r
243 // Create a queue capable of containing 10 unsigned long values.
\r
244 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
246 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
247 // These should be passed by pointer as they contain a lot of data.
\r
248 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
254 // Send an unsigned long. Wait for 10 ticks for space to become
\r
255 // available if necessary.
\r
256 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
258 // Failed to post the message, even after 10 ticks.
\r
264 // Send a pointer to a struct AMessage object. Don't block if the
\r
265 // queue is already full.
\r
266 pxMessage = & xMessage;
\r
267 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
270 // ... Rest of task code.
\r
273 * \defgroup xQueueSend xQueueSend
\r
274 * \ingroup QueueManagement
\r
276 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
281 portBASE_TYPE xQueueSend(
\r
282 xQueueHandle xQueue,
\r
283 const void * pvItemToQueue,
\r
284 portTickType xTicksToWait
\r
288 * This is a macro that calls xQueueGenericSend(). It is included for
\r
289 * backward compatibility with versions of FreeRTOS.org that did not
\r
290 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
291 * equivalent to xQueueSendToBack().
\r
293 * Post an item on a queue. The item is queued by copy, not by reference.
\r
294 * This function must not be called from an interrupt service routine.
\r
295 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
297 * @param xQueue The handle to the queue on which the item is to be posted.
\r
299 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
300 * queue. The size of the items the queue will hold was defined when the
\r
301 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
302 * into the queue storage area.
\r
304 * @param xTicksToWait The maximum amount of time the task should block
\r
305 * waiting for space to become available on the queue, should it already
\r
306 * be full. The call will return immediately if this is set to 0. The
\r
307 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
308 * should be used to convert to real time if this is required.
\r
310 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
316 portCHAR ucMessageID;
\r
317 portCHAR ucData[ 20 ];
\r
320 unsigned portLONG ulVar = 10UL;
\r
322 void vATask( void *pvParameters )
\r
324 xQueueHandle xQueue1, xQueue2;
\r
325 struct AMessage *pxMessage;
\r
327 // Create a queue capable of containing 10 unsigned long values.
\r
328 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
330 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
331 // These should be passed by pointer as they contain a lot of data.
\r
332 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
338 // Send an unsigned long. Wait for 10 ticks for space to become
\r
339 // available if necessary.
\r
340 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
342 // Failed to post the message, even after 10 ticks.
\r
348 // Send a pointer to a struct AMessage object. Don't block if the
\r
349 // queue is already full.
\r
350 pxMessage = & xMessage;
\r
351 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
354 // ... Rest of task code.
\r
357 * \defgroup xQueueSend xQueueSend
\r
358 * \ingroup QueueManagement
\r
360 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
366 portBASE_TYPE xQueueGenericSend(
\r
367 xQueueHandle xQueue,
\r
368 const void * pvItemToQueue,
\r
369 portTickType xTicksToWait
\r
370 portBASE_TYPE xCopyPosition
\r
374 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
375 * xQueueSendToBack() are used in place of calling this function directly.
\r
377 * Post an item on a queue. The item is queued by copy, not by reference.
\r
378 * This function must not be called from an interrupt service routine.
\r
379 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
381 * @param xQueue The handle to the queue on which the item is to be posted.
\r
383 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
384 * queue. The size of the items the queue will hold was defined when the
\r
385 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
386 * into the queue storage area.
\r
388 * @param xTicksToWait The maximum amount of time the task should block
\r
389 * waiting for space to become available on the queue, should it already
\r
390 * be full. The call will return immediately if this is set to 0. The
\r
391 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
392 * should be used to convert to real time if this is required.
\r
394 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
395 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
396 * at the front of the queue (for high priority messages).
\r
398 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
404 portCHAR ucMessageID;
\r
405 portCHAR ucData[ 20 ];
\r
408 unsigned portLONG ulVar = 10UL;
\r
410 void vATask( void *pvParameters )
\r
412 xQueueHandle xQueue1, xQueue2;
\r
413 struct AMessage *pxMessage;
\r
415 // Create a queue capable of containing 10 unsigned long values.
\r
416 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
418 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
419 // These should be passed by pointer as they contain a lot of data.
\r
420 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
426 // Send an unsigned long. Wait for 10 ticks for space to become
\r
427 // available if necessary.
\r
428 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
430 // Failed to post the message, even after 10 ticks.
\r
436 // Send a pointer to a struct AMessage object. Don't block if the
\r
437 // queue is already full.
\r
438 pxMessage = & xMessage;
\r
439 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
442 // ... Rest of task code.
\r
445 * \defgroup xQueueSend xQueueSend
\r
446 * \ingroup QueueManagement
\r
448 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
453 portBASE_TYPE xQueuePeek(
\r
454 xQueueHandle xQueue,
\r
456 portTickType xTicksToWait
\r
459 * This is a macro that calls the xQueueGenericReceive() function.
\r
461 * Receive an item from a queue without removing the item from the queue.
\r
462 * The item is received by copy so a buffer of adequate size must be
\r
463 * provided. The number of bytes copied into the buffer was defined when
\r
464 * the queue was created.
\r
466 * Successfully received items remain on the queue so will be returned again
\r
467 * by the next call, or a call to xQueueReceive().
\r
469 * This macro must not be used in an interrupt service routine.
\r
471 * @param pxQueue The handle to the queue from which the item is to be
\r
474 * @param pvBuffer Pointer to the buffer into which the received item will
\r
477 * @param xTicksToWait The maximum amount of time the task should block
\r
478 * waiting for an item to receive should the queue be empty at the time
\r
479 * of the call. The time is defined in tick periods so the constant
\r
480 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
482 * @return pdTRUE if an item was successfully received from the queue,
\r
483 * otherwise pdFALSE.
\r
489 portCHAR ucMessageID;
\r
490 portCHAR ucData[ 20 ];
\r
493 xQueueHandle xQueue;
\r
495 // Task to create a queue and post a value.
\r
496 void vATask( void *pvParameters )
\r
498 struct AMessage *pxMessage;
\r
500 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
501 // These should be passed by pointer as they contain a lot of data.
\r
502 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
505 // Failed to create the queue.
\r
510 // Send a pointer to a struct AMessage object. Don't block if the
\r
511 // queue is already full.
\r
512 pxMessage = & xMessage;
\r
513 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
515 // ... Rest of task code.
\r
518 // Task to peek the data from the queue.
\r
519 void vADifferentTask( void *pvParameters )
\r
521 struct AMessage *pxRxedMessage;
\r
525 // Peek a message on the created queue. Block for 10 ticks if a
\r
526 // message is not immediately available.
\r
527 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
529 // pcRxedMessage now points to the struct AMessage variable posted
\r
530 // by vATask, but the item still remains on the queue.
\r
534 // ... Rest of task code.
\r
537 * \defgroup xQueueReceive xQueueReceive
\r
538 * \ingroup QueueManagement
\r
540 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
545 portBASE_TYPE xQueueReceive(
\r
546 xQueueHandle xQueue,
\r
548 portTickType xTicksToWait
\r
551 * This is a macro that calls the xQueueGenericReceive() function.
\r
553 * Receive an item from a queue. The item is received by copy so a buffer of
\r
554 * adequate size must be provided. The number of bytes copied into the buffer
\r
555 * was defined when the queue was created.
\r
557 * Successfully received items are removed from the queue.
\r
559 * This function must not be used in an interrupt service routine. See
\r
560 * xQueueReceiveFromISR for an alternative that can.
\r
562 * @param pxQueue The handle to the queue from which the item is to be
\r
565 * @param pvBuffer Pointer to the buffer into which the received item will
\r
568 * @param xTicksToWait The maximum amount of time the task should block
\r
569 * waiting for an item to receive should the queue be empty at the time
\r
570 * of the call. The time is defined in tick periods so the constant
\r
571 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
573 * @return pdTRUE if an item was successfully received from the queue,
\r
574 * otherwise pdFALSE.
\r
580 portCHAR ucMessageID;
\r
581 portCHAR ucData[ 20 ];
\r
584 xQueueHandle xQueue;
\r
586 // Task to create a queue and post a value.
\r
587 void vATask( void *pvParameters )
\r
589 struct AMessage *pxMessage;
\r
591 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
592 // These should be passed by pointer as they contain a lot of data.
\r
593 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
596 // Failed to create the queue.
\r
601 // Send a pointer to a struct AMessage object. Don't block if the
\r
602 // queue is already full.
\r
603 pxMessage = & xMessage;
\r
604 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
606 // ... Rest of task code.
\r
609 // Task to receive from the queue.
\r
610 void vADifferentTask( void *pvParameters )
\r
612 struct AMessage *pxRxedMessage;
\r
616 // Receive a message on the created queue. Block for 10 ticks if a
\r
617 // message is not immediately available.
\r
618 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
620 // pcRxedMessage now points to the struct AMessage variable posted
\r
625 // ... Rest of task code.
\r
628 * \defgroup xQueueReceive xQueueReceive
\r
629 * \ingroup QueueManagement
\r
631 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
637 portBASE_TYPE xQueueGenericReceive(
\r
638 xQueueHandle xQueue,
\r
640 portTickType xTicksToWait
\r
641 portBASE_TYPE xJustPeek
\r
644 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
645 * this function directly.
\r
647 * Receive an item from a queue. The item is received by copy so a buffer of
\r
648 * adequate size must be provided. The number of bytes copied into the buffer
\r
649 * was defined when the queue was created.
\r
651 * This function must not be used in an interrupt service routine. See
\r
652 * xQueueReceiveFromISR for an alternative that can.
\r
654 * @param pxQueue The handle to the queue from which the item is to be
\r
657 * @param pvBuffer Pointer to the buffer into which the received item will
\r
660 * @param xTicksToWait The maximum amount of time the task should block
\r
661 * waiting for an item to receive should the queue be empty at the time
\r
662 * of the call. The time is defined in tick periods so the constant
\r
663 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
665 * @param xJustPeek When set to true, the item received from the queue is not
\r
666 * actually removed from the queue - meaning a subsequent call to
\r
667 * xQueueReceive() will return the same item. When set to false, the item
\r
668 * being received from the queue is also removed from the queue.
\r
670 * @return pdTRUE if an item was successfully received from the queue,
\r
671 * otherwise pdFALSE.
\r
677 portCHAR ucMessageID;
\r
678 portCHAR ucData[ 20 ];
\r
681 xQueueHandle xQueue;
\r
683 // Task to create a queue and post a value.
\r
684 void vATask( void *pvParameters )
\r
686 struct AMessage *pxMessage;
\r
688 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
689 // These should be passed by pointer as they contain a lot of data.
\r
690 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
693 // Failed to create the queue.
\r
698 // Send a pointer to a struct AMessage object. Don't block if the
\r
699 // queue is already full.
\r
700 pxMessage = & xMessage;
\r
701 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
703 // ... Rest of task code.
\r
706 // Task to receive from the queue.
\r
707 void vADifferentTask( void *pvParameters )
\r
709 struct AMessage *pxRxedMessage;
\r
713 // Receive a message on the created queue. Block for 10 ticks if a
\r
714 // message is not immediately available.
\r
715 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
717 // pcRxedMessage now points to the struct AMessage variable posted
\r
722 // ... Rest of task code.
\r
725 * \defgroup xQueueReceive xQueueReceive
\r
726 * \ingroup QueueManagement
\r
728 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
732 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle const xQueue );</pre>
\r
734 * Return the number of messages stored in a queue.
\r
736 * @param xQueue A handle to the queue being queried.
\r
738 * @return The number of messages available in the queue.
\r
740 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
741 * \ingroup QueueManagement
\r
743 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle const xQueue );
\r
747 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
749 * Delete a queue - freeing all the memory allocated for storing of items
\r
750 * placed on the queue.
\r
752 * @param xQueue A handle to the queue to be deleted.
\r
754 * \page vQueueDelete vQueueDelete
\r
755 * \ingroup QueueManagement
\r
757 void vQueueDelete( xQueueHandle xQueue );
\r
762 portBASE_TYPE xQueueSendToFrontFromISR(
\r
763 xQueueHandle pxQueue,
\r
764 const void *pvItemToQueue,
\r
765 portBASE_TYPE xTaskPreviouslyWoken
\r
769 * This is a macro that calls xQueueGenericSendFromISR().
\r
771 * Post an item to the front of a queue. It is safe to use this macro from
\r
772 * within an interrupt service routine.
\r
774 * Items are queued by copy not reference so it is preferable to only
\r
775 * queue small items, especially when called from an ISR. In most cases
\r
776 * it would be preferable to store a pointer to the item being queued.
\r
778 * @param xQueue The handle to the queue on which the item is to be posted.
\r
780 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
781 * queue. The size of the items the queue will hold was defined when the
\r
782 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
783 * into the queue storage area.
\r
785 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
786 * the same queue multiple times from a single interrupt. The first call
\r
787 * should always pass in pdFALSE. Subsequent calls should pass in
\r
788 * the value returned from the previous call. See the file serial .c in the
\r
789 * PC port for a good example of this mechanism.
\r
791 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
792 * used by the ISR to determine if a context switch may be required following
\r
795 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
798 void vBufferISR( void )
\r
801 portBASE_TYPE xTaskWokenByPost;
\r
803 // We have not woken a task at the start of the ISR.
\r
804 cTaskWokenByPost = pdFALSE;
\r
806 // Loop until the buffer is empty.
\r
809 // Obtain a byte from the buffer.
\r
810 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
812 // Post the byte. The first time round the loop cTaskWokenByPost
\r
813 // will be pdFALSE. If the queue send causes a task to wake we do
\r
814 // not want the task to run until we have finished the ISR, so
\r
815 // xQueueSendFromISR does not cause a context switch. Also we
\r
816 // don't want subsequent posts to wake any other tasks, so we store
\r
817 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
818 // knows not to wake any task the next iteration of the loop.
\r
819 xTaskWokenByPost = xQueueSendToFrontFromISR( xRxQueue, &cIn, cTaskWokenByPost );
\r
821 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
823 // Now the buffer is empty we can switch context if necessary.
\r
824 if( cTaskWokenByPost )
\r
831 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
832 * \ingroup QueueManagement
\r
834 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken, queueSEND_TO_FRONT )
\r
840 portBASE_TYPE xQueueSendToBackFromISR(
\r
841 xQueueHandle pxQueue,
\r
842 const void *pvItemToQueue,
\r
843 portBASE_TYPE xTaskPreviouslyWoken
\r
847 * This is a macro that calls xQueueGenericSendFromISR().
\r
849 * Post an item to the back of a queue. It is safe to use this macro from
\r
850 * within an interrupt service routine.
\r
852 * Items are queued by copy not reference so it is preferable to only
\r
853 * queue small items, especially when called from an ISR. In most cases
\r
854 * it would be preferable to store a pointer to the item being queued.
\r
856 * @param xQueue The handle to the queue on which the item is to be posted.
\r
858 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
859 * queue. The size of the items the queue will hold was defined when the
\r
860 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
861 * into the queue storage area.
\r
863 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
864 * the same queue multiple times from a single interrupt. The first call
\r
865 * should always pass in pdFALSE. Subsequent calls should pass in
\r
866 * the value returned from the previous call. See the file serial .c in the
\r
867 * PC port for a good example of this mechanism.
\r
869 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
870 * used by the ISR to determine if a context switch may be required following
\r
873 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
876 void vBufferISR( void )
\r
879 portBASE_TYPE xTaskWokenByPost;
\r
881 // We have not woken a task at the start of the ISR.
\r
882 cTaskWokenByPost = pdFALSE;
\r
884 // Loop until the buffer is empty.
\r
887 // Obtain a byte from the buffer.
\r
888 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
890 // Post the byte. The first time round the loop cTaskWokenByPost
\r
891 // will be pdFALSE. If the queue send causes a task to wake we do
\r
892 // not want the task to run until we have finished the ISR, so
\r
893 // xQueueSendFromISR does not cause a context switch. Also we
\r
894 // don't want subsequent posts to wake any other tasks, so we store
\r
895 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
896 // knows not to wake any task the next iteration of the loop.
\r
897 xTaskWokenByPost = xQueueSendToBackFromISR( xRxQueue, &cIn, cTaskWokenByPost );
\r
899 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
901 // Now the buffer is empty we can switch context if necessary.
\r
902 if( cTaskWokenByPost )
\r
909 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
910 * \ingroup QueueManagement
\r
912 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken, queueSEND_TO_BACK )
\r
917 portBASE_TYPE xQueueSendFromISR(
\r
918 xQueueHandle pxQueue,
\r
919 const void *pvItemToQueue,
\r
920 portBASE_TYPE xTaskPreviouslyWoken
\r
924 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
925 * for backward compatibility with versions of FreeRTOS.org that did not
\r
926 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
929 * Post an item to the back of a queue. It is safe to use this function from
\r
930 * within an interrupt service routine.
\r
932 * Items are queued by copy not reference so it is preferable to only
\r
933 * queue small items, especially when called from an ISR. In most cases
\r
934 * it would be preferable to store a pointer to the item being queued.
\r
936 * @param xQueue The handle to the queue on which the item is to be posted.
\r
938 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
939 * queue. The size of the items the queue will hold was defined when the
\r
940 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
941 * into the queue storage area.
\r
943 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
944 * the same queue multiple times from a single interrupt. The first call
\r
945 * should always pass in pdFALSE. Subsequent calls should pass in
\r
946 * the value returned from the previous call. See the file serial .c in the
\r
947 * PC port for a good example of this mechanism.
\r
949 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
950 * used by the ISR to determine if a context switch may be required following
\r
953 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
956 void vBufferISR( void )
\r
959 portBASE_TYPE xTaskWokenByPost;
\r
961 // We have not woken a task at the start of the ISR.
\r
962 cTaskWokenByPost = pdFALSE;
\r
964 // Loop until the buffer is empty.
\r
967 // Obtain a byte from the buffer.
\r
968 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
970 // Post the byte. The first time round the loop cTaskWokenByPost
\r
971 // will be pdFALSE. If the queue send causes a task to wake we do
\r
972 // not want the task to run until we have finished the ISR, so
\r
973 // xQueueSendFromISR does not cause a context switch. Also we
\r
974 // don't want subsequent posts to wake any other tasks, so we store
\r
975 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
976 // knows not to wake any task the next iteration of the loop.
\r
977 xTaskWokenByPost = xQueueSendFromISR( xRxQueue, &cIn, cTaskWokenByPost );
\r
979 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
981 // Now the buffer is empty we can switch context if necessary.
\r
982 if( cTaskWokenByPost )
\r
989 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
990 * \ingroup QueueManagement
\r
992 #define xQueueSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken, queueSEND_TO_BACK )
\r
997 portBASE_TYPE xQueueGenericSendFromISR(
\r
998 xQueueHandle pxQueue,
\r
999 const void *pvItemToQueue,
\r
1000 portBASE_TYPE xTaskPreviouslyWoken
\r
1001 portBASE_TYPE xCopyPosition
\r
1005 * It is preferred that the macros xQueueSendFromISR(),
\r
1006 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1007 * of calling this function directly.
\r
1009 * Post an item on a queue. It is safe to use this function from within an
\r
1010 * interrupt service routine.
\r
1012 * Items are queued by copy not reference so it is preferable to only
\r
1013 * queue small items, especially when called from an ISR. In most cases
\r
1014 * it would be preferable to store a pointer to the item being queued.
\r
1016 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1018 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1019 * queue. The size of the items the queue will hold was defined when the
\r
1020 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1021 * into the queue storage area.
\r
1023 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
1024 * the same queue multiple times from a single interrupt. The first call
\r
1025 * should always pass in pdFALSE. Subsequent calls should pass in
\r
1026 * the value returned from the previous call. See the file serial .c in the
\r
1027 * PC port for a good example of this mechanism.
\r
1029 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1030 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1031 * at the front of the queue (for high priority messages).
\r
1033 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
1034 * used by the ISR to determine if a context switch may be required following
\r
1037 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1040 void vBufferISR( void )
\r
1043 portBASE_TYPE xTaskWokenByPost;
\r
1045 // We have not woken a task at the start of the ISR.
\r
1046 cTaskWokenByPost = pdFALSE;
\r
1048 // Loop until the buffer is empty.
\r
1051 // Obtain a byte from the buffer.
\r
1052 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1054 // Post the byte. The first time round the loop cTaskWokenByPost
\r
1055 // will be pdFALSE. If the queue send causes a task to wake we do
\r
1056 // not want the task to run until we have finished the ISR, so
\r
1057 // xQueueSendFromISR does not cause a context switch. Also we
\r
1058 // don't want subsequent posts to wake any other tasks, so we store
\r
1059 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
1060 // knows not to wake any task the next iteration of the loop.
\r
1061 xTaskWokenByPost = xQueueGenericSendFromISR( xRxQueue, &cIn, cTaskWokenByPost, queueSEND_TO_BACK );
\r
1063 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1065 // Now the buffer is empty we can switch context if necessary.
\r
1066 if( cTaskWokenByPost )
\r
1073 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1074 * \ingroup QueueManagement
\r
1076 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE xTaskPreviouslyWoken, portBASE_TYPE xCopyPosition );
\r
1081 portBASE_TYPE xQueueReceiveFromISR(
\r
1082 xQueueHandle pxQueue,
\r
1084 portBASE_TYPE *pxTaskWoken
\r
1088 * Receive an item from a queue. It is safe to use this function from within an
\r
1089 * interrupt service routine.
\r
1091 * @param pxQueue The handle to the queue from which the item is to be
\r
1094 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1097 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1098 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1099 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1100 * remain unchanged.
\r
1102 * @return pdTRUE if an item was successfully received from the queue,
\r
1103 * otherwise pdFALSE.
\r
1108 xQueueHandle xQueue;
\r
1110 // Function to create a queue and post some values.
\r
1111 void vAFunction( void *pvParameters )
\r
1113 portCHAR cValueToPost;
\r
1114 const portTickType xBlockTime = ( portTickType )0xff;
\r
1116 // Create a queue capable of containing 10 characters.
\r
1117 xQueue = xQueueCreate( 10, sizeof( portCHAR ) );
\r
1120 // Failed to create the queue.
\r
1125 // Post some characters that will be used within an ISR. If the queue
\r
1126 // is full then this task will block for xBlockTime ticks.
\r
1127 cValueToPost = 'a';
\r
1128 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1129 cValueToPost = 'b';
\r
1130 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1132 // ... keep posting characters ... this task may block when the queue
\r
1135 cValueToPost = 'c';
\r
1136 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1139 // ISR that outputs all the characters received on the queue.
\r
1140 void vISR_Routine( void )
\r
1142 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1143 portCHAR cRxedChar;
\r
1145 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1147 // A character was received. Output the character now.
\r
1148 vOutputCharacter( cRxedChar );
\r
1150 // If removing the character from the queue woke the task that was
\r
1151 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1152 // pdTRUE. No matter how many times this loop iterates only one
\r
1153 // task will be woken.
\r
1156 if( cTaskWokenByPost != ( portCHAR ) pdFALSE;
\r
1162 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1163 * \ingroup QueueManagement
\r
1165 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, const void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1168 * Utilities to query queue that are safe to use from an ISR. These utilities
\r
1169 * should be used only from witin an ISR, or within a critical section.
\r
1171 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle const pxQueue );
\r
1172 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle const pxQueue );
\r
1173 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle const pxQueue );
\r
1177 * xQueueAltGenericSend() is an alternative version of xQueueGenericSend().
\r
1178 * Likewise xQueueAltGenericReceive() is an alternative version of
\r
1179 * xQueueGenericReceive().
\r
1181 * The source code that implements the alternative (Alt) API is much
\r
1182 * simpler because it executes everything from within a critical section.
\r
1183 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1184 * preferred fully featured API too. The fully featured API has more
\r
1185 * complex code that takes longer to execute, but makes much less use of
\r
1186 * critical sections. Therefore the alternative API sacrifices interrupt
\r
1187 * responsiveness to gain execution speed, whereas the fully featured API
\r
1188 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1190 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1191 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1192 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
1193 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
1194 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
1195 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
1198 * The functions defined above are for passing data to and from tasks. The
\r
1199 * functions below are the equivalents for passing data to and from
\r
1202 * These functions are called from the co-routine macro implementation and
\r
1203 * should not be called directly from application code. Instead use the macro
\r
1204 * wrappers defined within croutine.h.
\r
1206 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1207 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1208 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1209 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1212 * For internal use only. Use xSemaphoreCreateMutex() or
\r
1213 * xSemaphoreCreateCounting() instead of calling these functions directly.
\r
1215 xQueueHandle xQueueCreateMutex( void );
\r
1216 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1219 * For internal use only. Use xSemaphoreTakeMutexRecursive() or
\r
1220 * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
\r
1222 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
\r
1223 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex );
\r
1226 #ifdef __cplusplus
\r
1230 #endif /* QUEUE_H */
\r