2 FreeRTOS.org V4.7.0 - Copyright (C) 2003-2007 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
27 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
31 Also see http://www.SafeRTOS.com a version that has been certified for use
\r
32 in safety critical systems, plus commercial licensing, development and
\r
34 ***************************************************************************
\r
43 typedef void * xQueueHandle;
\r
45 /* For internal use only. */
\r
46 #define queueSEND_TO_BACK ( 0 )
\r
47 #define queueSEND_TO_FRONT ( 1 )
\r
53 xQueueHandle xQueueCreate(
\r
54 unsigned portBASE_TYPE uxQueueLength,
\r
55 unsigned portBASE_TYPE uxItemSize
\r
59 * Creates a new queue instance. This allocates the storage required by the
\r
60 * new queue and returns a handle for the queue.
\r
62 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
64 * @param uxItemSize The number of bytes each item in the queue will require.
\r
65 * Items are queued by copy, not by reference, so this is the number of bytes
\r
66 * that will be copied for each posted item. Each item on the queue must be
\r
69 * @return If the queue is successfully create then a handle to the newly
\r
70 * created queue is returned. If the queue cannot be created then 0 is
\r
77 portCHAR ucMessageID;
\r
78 portCHAR ucData[ 20 ];
\r
81 void vATask( void *pvParameters )
\r
83 xQueueHandle xQueue1, xQueue2;
\r
85 // Create a queue capable of containing 10 unsigned long values.
\r
86 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
89 // Queue was not created and must not be used.
\r
92 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
93 // These should be passed by pointer as they contain a lot of data.
\r
94 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
97 // Queue was not created and must not be used.
\r
100 // ... Rest of task code.
\r
103 * \defgroup xQueueCreate xQueueCreate
\r
104 * \ingroup QueueManagement
\r
106 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
111 portBASE_TYPE xQueueSendToToFront(
\r
112 xQueueHandle xQueue,
\r
113 const void * pvItemToQueue,
\r
114 portTickType xTicksToWait
\r
118 * This is a macro that calls xQueueGenericSend().
\r
120 * Post an item to the front of a queue. The item is queued by copy, not by
\r
121 * reference. This function must not be called from an interrupt service
\r
122 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
125 * @param xQueue The handle to the queue on which the item is to be posted.
\r
127 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
128 * queue. The size of the items the queue will hold was defined when the
\r
129 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
130 * into the queue storage area.
\r
132 * @param xTicksToWait The maximum amount of time the task should block
\r
133 * waiting for space to become available on the queue, should it already
\r
134 * be full. The call will return immediately if this is set to 0. The
\r
135 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
136 * should be used to convert to real time if this is required.
\r
138 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
144 portCHAR ucMessageID;
\r
145 portCHAR ucData[ 20 ];
\r
148 unsigned portLONG ulVar = 10UL;
\r
150 void vATask( void *pvParameters )
\r
152 xQueueHandle xQueue1, xQueue2;
\r
153 struct AMessage *pxMessage;
\r
155 // Create a queue capable of containing 10 unsigned long values.
\r
156 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
158 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
159 // These should be passed by pointer as they contain a lot of data.
\r
160 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
166 // Send an unsigned long. Wait for 10 ticks for space to become
\r
167 // available if necessary.
\r
168 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
170 // Failed to post the message, even after 10 ticks.
\r
176 // Send a pointer to a struct AMessage object. Don't block if the
\r
177 // queue is already full.
\r
178 pxMessage = & xMessage;
\r
179 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
182 // ... Rest of task code.
\r
185 * \defgroup xQueueSend xQueueSend
\r
186 * \ingroup QueueManagement
\r
188 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
193 portBASE_TYPE xQueueSendToBack(
\r
194 xQueueHandle xQueue,
\r
195 const void * pvItemToQueue,
\r
196 portTickType xTicksToWait
\r
200 * This is a macro that calls xQueueGenericSend().
\r
202 * Post an item to the back of a queue. The item is queued by copy, not by
\r
203 * reference. This function must not be called from an interrupt service
\r
204 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
207 * @param xQueue The handle to the queue on which the item is to be posted.
\r
209 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
210 * queue. The size of the items the queue will hold was defined when the
\r
211 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
212 * into the queue storage area.
\r
214 * @param xTicksToWait The maximum amount of time the task should block
\r
215 * waiting for space to become available on the queue, should it already
\r
216 * be full. The call will return immediately if this is set to 0. The
\r
217 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
218 * should be used to convert to real time if this is required.
\r
220 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
226 portCHAR ucMessageID;
\r
227 portCHAR ucData[ 20 ];
\r
230 unsigned portLONG ulVar = 10UL;
\r
232 void vATask( void *pvParameters )
\r
234 xQueueHandle xQueue1, xQueue2;
\r
235 struct AMessage *pxMessage;
\r
237 // Create a queue capable of containing 10 unsigned long values.
\r
238 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
240 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
241 // These should be passed by pointer as they contain a lot of data.
\r
242 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
248 // Send an unsigned long. Wait for 10 ticks for space to become
\r
249 // available if necessary.
\r
250 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
252 // Failed to post the message, even after 10 ticks.
\r
258 // Send a pointer to a struct AMessage object. Don't block if the
\r
259 // queue is already full.
\r
260 pxMessage = & xMessage;
\r
261 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
264 // ... Rest of task code.
\r
267 * \defgroup xQueueSend xQueueSend
\r
268 * \ingroup QueueManagement
\r
270 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
275 portBASE_TYPE xQueueSend(
\r
276 xQueueHandle xQueue,
\r
277 const void * pvItemToQueue,
\r
278 portTickType xTicksToWait
\r
282 * This is a macro that calls xQueueGenericSend(). It is included for
\r
283 * backward compatibility with versions of FreeRTOS.org that did not
\r
284 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
285 * equivalent to xQueueSendToBack().
\r
287 * Post an item on a queue. The item is queued by copy, not by reference.
\r
288 * This function must not be called from an interrupt service routine.
\r
289 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
291 * @param xQueue The handle to the queue on which the item is to be posted.
\r
293 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
294 * queue. The size of the items the queue will hold was defined when the
\r
295 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
296 * into the queue storage area.
\r
298 * @param xTicksToWait The maximum amount of time the task should block
\r
299 * waiting for space to become available on the queue, should it already
\r
300 * be full. The call will return immediately if this is set to 0. The
\r
301 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
302 * should be used to convert to real time if this is required.
\r
304 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
310 portCHAR ucMessageID;
\r
311 portCHAR ucData[ 20 ];
\r
314 unsigned portLONG ulVar = 10UL;
\r
316 void vATask( void *pvParameters )
\r
318 xQueueHandle xQueue1, xQueue2;
\r
319 struct AMessage *pxMessage;
\r
321 // Create a queue capable of containing 10 unsigned long values.
\r
322 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
324 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
325 // These should be passed by pointer as they contain a lot of data.
\r
326 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
332 // Send an unsigned long. Wait for 10 ticks for space to become
\r
333 // available if necessary.
\r
334 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
336 // Failed to post the message, even after 10 ticks.
\r
342 // Send a pointer to a struct AMessage object. Don't block if the
\r
343 // queue is already full.
\r
344 pxMessage = & xMessage;
\r
345 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
348 // ... Rest of task code.
\r
351 * \defgroup xQueueSend xQueueSend
\r
352 * \ingroup QueueManagement
\r
354 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
360 portBASE_TYPE xQueueGenericSend(
\r
361 xQueueHandle xQueue,
\r
362 const void * pvItemToQueue,
\r
363 portTickType xTicksToWait
\r
364 portBASE_TYPE xCopyPosition
\r
368 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
369 * xQueueSendToBack() are used in place of calling this function directly.
\r
371 * Post an item on a queue. The item is queued by copy, not by reference.
\r
372 * This function must not be called from an interrupt service routine.
\r
373 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
375 * @param xQueue The handle to the queue on which the item is to be posted.
\r
377 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
378 * queue. The size of the items the queue will hold was defined when the
\r
379 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
380 * into the queue storage area.
\r
382 * @param xTicksToWait The maximum amount of time the task should block
\r
383 * waiting for space to become available on the queue, should it already
\r
384 * be full. The call will return immediately if this is set to 0. The
\r
385 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
386 * should be used to convert to real time if this is required.
\r
388 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
389 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
390 * at the front of the queue (for high priority messages).
\r
392 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
398 portCHAR ucMessageID;
\r
399 portCHAR ucData[ 20 ];
\r
402 unsigned portLONG ulVar = 10UL;
\r
404 void vATask( void *pvParameters )
\r
406 xQueueHandle xQueue1, xQueue2;
\r
407 struct AMessage *pxMessage;
\r
409 // Create a queue capable of containing 10 unsigned long values.
\r
410 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
412 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
413 // These should be passed by pointer as they contain a lot of data.
\r
414 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
420 // Send an unsigned long. Wait for 10 ticks for space to become
\r
421 // available if necessary.
\r
422 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
424 // Failed to post the message, even after 10 ticks.
\r
430 // Send a pointer to a struct AMessage object. Don't block if the
\r
431 // queue is already full.
\r
432 pxMessage = & xMessage;
\r
433 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
436 // ... Rest of task code.
\r
439 * \defgroup xQueueSend xQueueSend
\r
440 * \ingroup QueueManagement
\r
442 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
447 portBASE_TYPE xQueuePeek(
\r
448 xQueueHandle xQueue,
\r
450 portTickType xTicksToWait
\r
453 * This is a macro that calls the xQueueGenericReceive() function.
\r
455 * Receive an item from a queue without removing the item from the queue.
\r
456 * The item is received by copy so a buffer of adequate size must be
\r
457 * provided. The number of bytes copied into the buffer was defined when
\r
458 * the queue was created.
\r
460 * Successfully received items remain on the queue so will be returned again
\r
461 * by the next call, or a call to xQueueReceive().
\r
463 * This macro must not be used in an interrupt service routine.
\r
465 * @param pxQueue The handle to the queue from which the item is to be
\r
468 * @param pvBuffer Pointer to the buffer into which the received item will
\r
471 * @param xTicksToWait The maximum amount of time the task should block
\r
472 * waiting for an item to receive should the queue be empty at the time
\r
473 * of the call. The time is defined in tick periods so the constant
\r
474 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
476 * @return pdTRUE if an item was successfully received from the queue,
\r
477 * otherwise pdFALSE.
\r
483 portCHAR ucMessageID;
\r
484 portCHAR ucData[ 20 ];
\r
487 xQueueHandle xQueue;
\r
489 // Task to create a queue and post a value.
\r
490 void vATask( void *pvParameters )
\r
492 struct AMessage *pxMessage;
\r
494 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
495 // These should be passed by pointer as they contain a lot of data.
\r
496 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
499 // Failed to create the queue.
\r
504 // Send a pointer to a struct AMessage object. Don't block if the
\r
505 // queue is already full.
\r
506 pxMessage = & xMessage;
\r
507 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
509 // ... Rest of task code.
\r
512 // Task to peek the data from the queue.
\r
513 void vADifferentTask( void *pvParameters )
\r
515 struct AMessage *pxRxedMessage;
\r
519 // Peek a message on the created queue. Block for 10 ticks if a
\r
520 // message is not immediately available.
\r
521 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
523 // pcRxedMessage now points to the struct AMessage variable posted
\r
524 // by vATask, but the item still remains on the queue.
\r
528 // ... Rest of task code.
\r
531 * \defgroup xQueueReceive xQueueReceive
\r
532 * \ingroup QueueManagement
\r
534 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
539 portBASE_TYPE xQueueReceive(
\r
540 xQueueHandle xQueue,
\r
542 portTickType xTicksToWait
\r
545 * This is a macro that calls the xQueueGenericReceive() function.
\r
547 * Receive an item from a queue. The item is received by copy so a buffer of
\r
548 * adequate size must be provided. The number of bytes copied into the buffer
\r
549 * was defined when the queue was created.
\r
551 * Successfully received items are removed from the queue.
\r
553 * This function must not be used in an interrupt service routine. See
\r
554 * xQueueReceiveFromISR for an alternative that can.
\r
556 * @param pxQueue The handle to the queue from which the item is to be
\r
559 * @param pvBuffer Pointer to the buffer into which the received item will
\r
562 * @param xTicksToWait The maximum amount of time the task should block
\r
563 * waiting for an item to receive should the queue be empty at the time
\r
564 * of the call. The time is defined in tick periods so the constant
\r
565 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
567 * @return pdTRUE if an item was successfully received from the queue,
\r
568 * otherwise pdFALSE.
\r
574 portCHAR ucMessageID;
\r
575 portCHAR ucData[ 20 ];
\r
578 xQueueHandle xQueue;
\r
580 // Task to create a queue and post a value.
\r
581 void vATask( void *pvParameters )
\r
583 struct AMessage *pxMessage;
\r
585 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
586 // These should be passed by pointer as they contain a lot of data.
\r
587 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
590 // Failed to create the queue.
\r
595 // Send a pointer to a struct AMessage object. Don't block if the
\r
596 // queue is already full.
\r
597 pxMessage = & xMessage;
\r
598 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
600 // ... Rest of task code.
\r
603 // Task to receive from the queue.
\r
604 void vADifferentTask( void *pvParameters )
\r
606 struct AMessage *pxRxedMessage;
\r
610 // Receive a message on the created queue. Block for 10 ticks if a
\r
611 // message is not immediately available.
\r
612 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
614 // pcRxedMessage now points to the struct AMessage variable posted
\r
619 // ... Rest of task code.
\r
622 * \defgroup xQueueReceive xQueueReceive
\r
623 * \ingroup QueueManagement
\r
625 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
631 portBASE_TYPE xQueueGenericReceive(
\r
632 xQueueHandle xQueue,
\r
634 portTickType xTicksToWait
\r
635 portBASE_TYPE xJustPeek
\r
638 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
639 * this function directly.
\r
641 * Receive an item from a queue. The item is received by copy so a buffer of
\r
642 * adequate size must be provided. The number of bytes copied into the buffer
\r
643 * was defined when the queue was created.
\r
645 * This function must not be used in an interrupt service routine. See
\r
646 * xQueueReceiveFromISR for an alternative that can.
\r
648 * @param pxQueue The handle to the queue from which the item is to be
\r
651 * @param pvBuffer Pointer to the buffer into which the received item will
\r
654 * @param xTicksToWait The maximum amount of time the task should block
\r
655 * waiting for an item to receive should the queue be empty at the time
\r
656 * of the call. The time is defined in tick periods so the constant
\r
657 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
659 * @param xJustPeek When set to true, the item received from the queue is not
\r
660 * actually removed from the queue - meaning a subsequent call to
\r
661 * xQueueReceive() will return the same item. When set to false, the item
\r
662 * being received from the queue is also removed from the queue.
\r
664 * @return pdTRUE if an item was successfully received from the queue,
\r
665 * otherwise pdFALSE.
\r
671 portCHAR ucMessageID;
\r
672 portCHAR ucData[ 20 ];
\r
675 xQueueHandle xQueue;
\r
677 // Task to create a queue and post a value.
\r
678 void vATask( void *pvParameters )
\r
680 struct AMessage *pxMessage;
\r
682 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
683 // These should be passed by pointer as they contain a lot of data.
\r
684 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
687 // Failed to create the queue.
\r
692 // Send a pointer to a struct AMessage object. Don't block if the
\r
693 // queue is already full.
\r
694 pxMessage = & xMessage;
\r
695 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
697 // ... Rest of task code.
\r
700 // Task to receive from the queue.
\r
701 void vADifferentTask( void *pvParameters )
\r
703 struct AMessage *pxRxedMessage;
\r
707 // Receive a message on the created queue. Block for 10 ticks if a
\r
708 // message is not immediately available.
\r
709 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
711 // pcRxedMessage now points to the struct AMessage variable posted
\r
716 // ... Rest of task code.
\r
719 * \defgroup xQueueReceive xQueueReceive
\r
720 * \ingroup QueueManagement
\r
722 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
726 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
728 * Return the number of messages stored in a queue.
\r
730 * @param xQueue A handle to the queue being queried.
\r
732 * @return The number of messages available in the queue.
\r
734 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
735 * \ingroup QueueManagement
\r
737 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
741 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
743 * Delete a queue - freeing all the memory allocated for storing of items
\r
744 * placed on the queue.
\r
746 * @param xQueue A handle to the queue to be deleted.
\r
748 * \page vQueueDelete vQueueDelete
\r
749 * \ingroup QueueManagement
\r
751 void vQueueDelete( xQueueHandle xQueue );
\r
756 portBASE_TYPE xQueueSendToFrontFromISR(
\r
757 xQueueHandle pxQueue,
\r
758 const void *pvItemToQueue,
\r
759 portBASE_TYPE xTaskPreviouslyWoken
\r
763 * This is a macro that calls xQueueGenericSendFromISR().
\r
765 * Post an item to the front of a queue. It is safe to use this macro from
\r
766 * within an interrupt service routine.
\r
768 * Items are queued by copy not reference so it is preferable to only
\r
769 * queue small items, especially when called from an ISR. In most cases
\r
770 * it would be preferable to store a pointer to the item being queued.
\r
772 * @param xQueue The handle to the queue on which the item is to be posted.
\r
774 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
775 * queue. The size of the items the queue will hold was defined when the
\r
776 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
777 * into the queue storage area.
\r
779 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
780 * the same queue multiple times from a single interrupt. The first call
\r
781 * should always pass in pdFALSE. Subsequent calls should pass in
\r
782 * the value returned from the previous call. See the file serial .c in the
\r
783 * PC port for a good example of this mechanism.
\r
785 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
786 * used by the ISR to determine if a context switch may be required following
\r
789 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
792 void vBufferISR( void )
\r
795 portBASE_TYPE xTaskWokenByPost;
\r
797 // We have not woken a task at the start of the ISR.
\r
798 cTaskWokenByPost = pdFALSE;
\r
800 // Loop until the buffer is empty.
\r
803 // Obtain a byte from the buffer.
\r
804 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
806 // Post the byte. The first time round the loop cTaskWokenByPost
\r
807 // will be pdFALSE. If the queue send causes a task to wake we do
\r
808 // not want the task to run until we have finished the ISR, so
\r
809 // xQueueSendFromISR does not cause a context switch. Also we
\r
810 // don't want subsequent posts to wake any other tasks, so we store
\r
811 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
812 // knows not to wake any task the next iteration of the loop.
\r
813 xTaskWokenByPost = xQueueSendToFrontFromISR( xRxQueue, &cIn, cTaskWokenByPost );
\r
815 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
817 // Now the buffer is empty we can switch context if necessary.
\r
818 if( cTaskWokenByPost )
\r
825 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
826 * \ingroup QueueManagement
\r
828 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken, queueSEND_TO_FRONT )
\r
834 portBASE_TYPE xQueueSendToBackFromISR(
\r
835 xQueueHandle pxQueue,
\r
836 const void *pvItemToQueue,
\r
837 portBASE_TYPE xTaskPreviouslyWoken
\r
841 * This is a macro that calls xQueueGenericSendFromISR().
\r
843 * Post an item to the back of a queue. It is safe to use this macro from
\r
844 * within an interrupt service routine.
\r
846 * Items are queued by copy not reference so it is preferable to only
\r
847 * queue small items, especially when called from an ISR. In most cases
\r
848 * it would be preferable to store a pointer to the item being queued.
\r
850 * @param xQueue The handle to the queue on which the item is to be posted.
\r
852 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
853 * queue. The size of the items the queue will hold was defined when the
\r
854 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
855 * into the queue storage area.
\r
857 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
858 * the same queue multiple times from a single interrupt. The first call
\r
859 * should always pass in pdFALSE. Subsequent calls should pass in
\r
860 * the value returned from the previous call. See the file serial .c in the
\r
861 * PC port for a good example of this mechanism.
\r
863 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
864 * used by the ISR to determine if a context switch may be required following
\r
867 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
870 void vBufferISR( void )
\r
873 portBASE_TYPE xTaskWokenByPost;
\r
875 // We have not woken a task at the start of the ISR.
\r
876 cTaskWokenByPost = pdFALSE;
\r
878 // Loop until the buffer is empty.
\r
881 // Obtain a byte from the buffer.
\r
882 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
884 // Post the byte. The first time round the loop cTaskWokenByPost
\r
885 // will be pdFALSE. If the queue send causes a task to wake we do
\r
886 // not want the task to run until we have finished the ISR, so
\r
887 // xQueueSendFromISR does not cause a context switch. Also we
\r
888 // don't want subsequent posts to wake any other tasks, so we store
\r
889 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
890 // knows not to wake any task the next iteration of the loop.
\r
891 xTaskWokenByPost = xQueueSendToBackFromISR( xRxQueue, &cIn, cTaskWokenByPost );
\r
893 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
895 // Now the buffer is empty we can switch context if necessary.
\r
896 if( cTaskWokenByPost )
\r
903 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
904 * \ingroup QueueManagement
\r
906 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken, queueSEND_TO_BACK )
\r
912 portBASE_TYPE xQueueSendFromISR(
\r
913 xQueueHandle pxQueue,
\r
914 const void *pvItemToQueue,
\r
915 portBASE_TYPE xTaskPreviouslyWoken
\r
919 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
920 * for backward compatibility with versions of FreeRTOS.org that did not
\r
921 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
924 * Post an item to the back of a queue. It is safe to use this function from
\r
925 * within an interrupt service routine.
\r
927 * Items are queued by copy not reference so it is preferable to only
\r
928 * queue small items, especially when called from an ISR. In most cases
\r
929 * it would be preferable to store a pointer to the item being queued.
\r
931 * @param xQueue The handle to the queue on which the item is to be posted.
\r
933 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
934 * queue. The size of the items the queue will hold was defined when the
\r
935 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
936 * into the queue storage area.
\r
938 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
939 * the same queue multiple times from a single interrupt. The first call
\r
940 * should always pass in pdFALSE. Subsequent calls should pass in
\r
941 * the value returned from the previous call. See the file serial .c in the
\r
942 * PC port for a good example of this mechanism.
\r
944 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
945 * used by the ISR to determine if a context switch may be required following
\r
948 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
951 void vBufferISR( void )
\r
954 portBASE_TYPE xTaskWokenByPost;
\r
956 // We have not woken a task at the start of the ISR.
\r
957 cTaskWokenByPost = pdFALSE;
\r
959 // Loop until the buffer is empty.
\r
962 // Obtain a byte from the buffer.
\r
963 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
965 // Post the byte. The first time round the loop cTaskWokenByPost
\r
966 // will be pdFALSE. If the queue send causes a task to wake we do
\r
967 // not want the task to run until we have finished the ISR, so
\r
968 // xQueueSendFromISR does not cause a context switch. Also we
\r
969 // don't want subsequent posts to wake any other tasks, so we store
\r
970 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
971 // knows not to wake any task the next iteration of the loop.
\r
972 xTaskWokenByPost = xQueueSendFromISR( xRxQueue, &cIn, cTaskWokenByPost );
\r
974 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
976 // Now the buffer is empty we can switch context if necessary.
\r
977 if( cTaskWokenByPost )
\r
984 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
985 * \ingroup QueueManagement
\r
987 #define xQueueSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken, queueSEND_TO_BACK )
\r
992 portBASE_TYPE xQueueGenericSendFromISR(
\r
993 xQueueHandle pxQueue,
\r
994 const void *pvItemToQueue,
\r
995 portBASE_TYPE xTaskPreviouslyWoken
\r
996 portBASE_TYPE xCopyPosition
\r
1000 * It is preferred that the macros xQueueSendFromISR(),
\r
1001 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
1002 * of calling this function directly.
\r
1004 * Post an item on a queue. It is safe to use this function from within an
\r
1005 * interrupt service routine.
\r
1007 * Items are queued by copy not reference so it is preferable to only
\r
1008 * queue small items, especially when called from an ISR. In most cases
\r
1009 * it would be preferable to store a pointer to the item being queued.
\r
1011 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1013 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1014 * queue. The size of the items the queue will hold was defined when the
\r
1015 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1016 * into the queue storage area.
\r
1018 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
1019 * the same queue multiple times from a single interrupt. The first call
\r
1020 * should always pass in pdFALSE. Subsequent calls should pass in
\r
1021 * the value returned from the previous call. See the file serial .c in the
\r
1022 * PC port for a good example of this mechanism.
\r
1024 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1025 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1026 * at the front of the queue (for high priority messages).
\r
1028 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
1029 * used by the ISR to determine if a context switch may be required following
\r
1032 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1035 void vBufferISR( void )
\r
1038 portBASE_TYPE xTaskWokenByPost;
\r
1040 // We have not woken a task at the start of the ISR.
\r
1041 cTaskWokenByPost = pdFALSE;
\r
1043 // Loop until the buffer is empty.
\r
1046 // Obtain a byte from the buffer.
\r
1047 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1049 // Post the byte. The first time round the loop cTaskWokenByPost
\r
1050 // will be pdFALSE. If the queue send causes a task to wake we do
\r
1051 // not want the task to run until we have finished the ISR, so
\r
1052 // xQueueSendFromISR does not cause a context switch. Also we
\r
1053 // don't want subsequent posts to wake any other tasks, so we store
\r
1054 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
1055 // knows not to wake any task the next iteration of the loop.
\r
1056 xTaskWokenByPost = xQueueGenericSendFromISR( xRxQueue, &cIn, cTaskWokenByPost, queueSEND_TO_BACK );
\r
1058 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1060 // Now the buffer is empty we can switch context if necessary.
\r
1061 if( cTaskWokenByPost )
\r
1068 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1069 * \ingroup QueueManagement
\r
1071 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE xTaskPreviouslyWoken, portBASE_TYPE xCopyPosition );
\r
1076 portBASE_TYPE xQueueReceiveFromISR(
\r
1077 xQueueHandle pxQueue,
\r
1079 portBASE_TYPE *pxTaskWoken
\r
1083 * Receive an item from a queue. It is safe to use this function from within an
\r
1084 * interrupt service routine.
\r
1086 * @param pxQueue The handle to the queue from which the item is to be
\r
1089 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1092 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1093 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1094 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1095 * remain unchanged.
\r
1097 * @return pdTRUE if an item was successfully received from the queue,
\r
1098 * otherwise pdFALSE.
\r
1103 xQueueHandle xQueue;
\r
1105 // Function to create a queue and post some values.
\r
1106 void vAFunction( void *pvParameters )
\r
1108 portCHAR cValueToPost;
\r
1109 const portTickType xBlockTime = ( portTickType )0xff;
\r
1111 // Create a queue capable of containing 10 characters.
\r
1112 xQueue = xQueueCreate( 10, sizeof( portCHAR ) );
\r
1115 // Failed to create the queue.
\r
1120 // Post some characters that will be used within an ISR. If the queue
\r
1121 // is full then this task will block for xBlockTime ticks.
\r
1122 cValueToPost = 'a';
\r
1123 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1124 cValueToPost = 'b';
\r
1125 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1127 // ... keep posting characters ... this task may block when the queue
\r
1130 cValueToPost = 'c';
\r
1131 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1134 // ISR that outputs all the characters received on the queue.
\r
1135 void vISR_Routine( void )
\r
1137 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1138 portCHAR cRxedChar;
\r
1140 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1142 // A character was received. Output the character now.
\r
1143 vOutputCharacter( cRxedChar );
\r
1145 // If removing the character from the queue woke the task that was
\r
1146 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1147 // pdTRUE. No matter how many times this loop iterates only one
\r
1148 // task will be woken.
\r
1151 if( cTaskWokenByPost != ( portCHAR ) pdFALSE;
\r
1157 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1158 * \ingroup QueueManagement
\r
1160 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, const void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1163 * xQueueAltGenericSend() is a light weight version of xQueueGenericSend().
\r
1164 * Likewise xQueueAltGenericReceive() is a light weight version of
\r
1165 * xQueueGenericReceive().
\r
1167 * The source code that implements the light weight (fast) API is much
\r
1168 * simpler because it executes everything from within a critical section.
\r
1169 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the
\r
1170 * fully featured API as an alternative. The fully featured API has more
\r
1171 * complex code that takes longer to execute, but makes much less use of
\r
1172 * critical sections. Therefore the light weight API sacrifices interrupt
\r
1173 * responsiveness to gain execution speed, whereas the fully featured API
\r
1174 * sacrifices execution speed to ensure better interrupt responsiveness.
\r
1176 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
1177 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );
\r
1180 * The light weight versions of the fully featured macros.
\r
1182 #define xQueueAltSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
1183 #define xQueueAltSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueAltGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
1184 #define xQueueAltReceive( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
1185 #define xQueueAltPeek( xQueue, pvBuffer, xTicksToWait ) xQueueAltGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
1188 * The functions defined above are for passing data to and from tasks. The
\r
1189 * functions below are the equivalents for passing data to and from
\r
1192 * These functions are called from the co-routine macro implementation and
\r
1193 * should not be called directly from application code. Instead use the macro
\r
1194 * wrappers defined within croutine.h.
\r
1196 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1197 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1198 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1199 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1202 * For internal use only. Use xSemaphoreCreateMutex() or
\r
1203 * xSemaphoreCreateCounting() instead of calling these functions directly.
\r
1205 xQueueHandle xQueueCreateMutex( void );
\r
1206 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );
\r
1208 #ifdef __cplusplus
\r
1212 #endif /* QUEUE_H */
\r