2 FreeRTOS.org V4.6.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 for an IEC 61508 compliant version along
\r
32 with commercial development and support options.
\r
33 ***************************************************************************
\r
39 typedef void * xQueueHandle;
\r
41 /* For internal use only. */
\r
42 #define queueSEND_TO_BACK ( 0 )
\r
43 #define queueSEND_TO_FRONT ( 1 )
\r
49 xQueueHandle xQueueCreate(
\r
50 unsigned portBASE_TYPE uxQueueLength,
\r
51 unsigned portBASE_TYPE uxItemSize
\r
55 * Creates a new queue instance. This allocates the storage required by the
\r
56 * new queue and returns a handle for the queue.
\r
58 * @param uxQueueLength The maximum number of items that the queue can contain.
\r
60 * @param uxItemSize The number of bytes each item in the queue will require.
\r
61 * Items are queued by copy, not by reference, so this is the number of bytes
\r
62 * that will be copied for each posted item. Each item on the queue must be
\r
65 * @return If the queue is successfully create then a handle to the newly
\r
66 * created queue is returned. If the queue cannot be created then 0 is
\r
73 portCHAR ucMessageID;
\r
74 portCHAR ucData[ 20 ];
\r
77 void vATask( void *pvParameters )
\r
79 xQueueHandle xQueue1, xQueue2;
\r
81 // Create a queue capable of containing 10 unsigned long values.
\r
82 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
85 // Queue was not created and must not be used.
\r
88 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
89 // These should be passed by pointer as they contain a lot of data.
\r
90 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
93 // Queue was not created and must not be used.
\r
96 // ... Rest of task code.
\r
99 * \defgroup xQueueCreate xQueueCreate
\r
100 * \ingroup QueueManagement
\r
102 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
\r
107 portBASE_TYPE xQueueSendToToFront(
\r
108 xQueueHandle xQueue,
\r
109 const void * pvItemToQueue,
\r
110 portTickType xTicksToWait
\r
114 * This is a macro that calls xQueueGenericSend().
\r
116 * Post an item to the front of a queue. The item is queued by copy, not by
\r
117 * reference. This function must not be called from an interrupt service
\r
118 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
121 * @param xQueue The handle to the queue on which the item is to be posted.
\r
123 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
124 * queue. The size of the items the queue will hold was defined when the
\r
125 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
126 * into the queue storage area.
\r
128 * @param xTicksToWait The maximum amount of time the task should block
\r
129 * waiting for space to become available on the queue, should it already
\r
130 * be full. The call will return immediately if this is set to 0. The
\r
131 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
132 * should be used to convert to real time if this is required.
\r
134 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
140 portCHAR ucMessageID;
\r
141 portCHAR ucData[ 20 ];
\r
144 unsigned portLONG ulVar = 10UL;
\r
146 void vATask( void *pvParameters )
\r
148 xQueueHandle xQueue1, xQueue2;
\r
149 struct AMessage *pxMessage;
\r
151 // Create a queue capable of containing 10 unsigned long values.
\r
152 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
154 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
155 // These should be passed by pointer as they contain a lot of data.
\r
156 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
162 // Send an unsigned long. Wait for 10 ticks for space to become
\r
163 // available if necessary.
\r
164 if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
166 // Failed to post the message, even after 10 ticks.
\r
172 // Send a pointer to a struct AMessage object. Don't block if the
\r
173 // queue is already full.
\r
174 pxMessage = & xMessage;
\r
175 xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
178 // ... Rest of task code.
\r
181 * \defgroup xQueueSend xQueueSend
\r
182 * \ingroup QueueManagement
\r
184 #define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_FRONT )
\r
189 portBASE_TYPE xQueueSendToBack(
\r
190 xQueueHandle xQueue,
\r
191 const void * pvItemToQueue,
\r
192 portTickType xTicksToWait
\r
196 * This is a macro that calls xQueueGenericSend().
\r
198 * Post an item to the back of a queue. The item is queued by copy, not by
\r
199 * reference. This function must not be called from an interrupt service
\r
200 * routine. See xQueueSendFromISR () for an alternative which may be used
\r
203 * @param xQueue The handle to the queue on which the item is to be posted.
\r
205 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
206 * queue. The size of the items the queue will hold was defined when the
\r
207 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
208 * into the queue storage area.
\r
210 * @param xTicksToWait The maximum amount of time the task should block
\r
211 * waiting for space to become available on the queue, should it already
\r
212 * be full. The call will return immediately if this is set to 0. The
\r
213 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
214 * should be used to convert to real time if this is required.
\r
216 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
222 portCHAR ucMessageID;
\r
223 portCHAR ucData[ 20 ];
\r
226 unsigned portLONG ulVar = 10UL;
\r
228 void vATask( void *pvParameters )
\r
230 xQueueHandle xQueue1, xQueue2;
\r
231 struct AMessage *pxMessage;
\r
233 // Create a queue capable of containing 10 unsigned long values.
\r
234 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
236 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
237 // These should be passed by pointer as they contain a lot of data.
\r
238 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
244 // Send an unsigned long. Wait for 10 ticks for space to become
\r
245 // available if necessary.
\r
246 if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
248 // Failed to post the message, even after 10 ticks.
\r
254 // Send a pointer to a struct AMessage object. Don't block if the
\r
255 // queue is already full.
\r
256 pxMessage = & xMessage;
\r
257 xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
260 // ... Rest of task code.
\r
263 * \defgroup xQueueSend xQueueSend
\r
264 * \ingroup QueueManagement
\r
266 #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
271 portBASE_TYPE xQueueSend(
\r
272 xQueueHandle xQueue,
\r
273 const void * pvItemToQueue,
\r
274 portTickType xTicksToWait
\r
278 * This is a macro that calls xQueueGenericSend(). It is included for
\r
279 * backward compatibility with versions of FreeRTOS.org that did not
\r
280 * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
\r
281 * equivalent to xQueueSendToBack().
\r
283 * Post an item on a queue. The item is queued by copy, not by reference.
\r
284 * This function must not be called from an interrupt service routine.
\r
285 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
287 * @param xQueue The handle to the queue on which the item is to be posted.
\r
289 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
290 * queue. The size of the items the queue will hold was defined when the
\r
291 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
292 * into the queue storage area.
\r
294 * @param xTicksToWait The maximum amount of time the task should block
\r
295 * waiting for space to become available on the queue, should it already
\r
296 * be full. The call will return immediately if this is set to 0. The
\r
297 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
298 * should be used to convert to real time if this is required.
\r
300 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
306 portCHAR ucMessageID;
\r
307 portCHAR ucData[ 20 ];
\r
310 unsigned portLONG ulVar = 10UL;
\r
312 void vATask( void *pvParameters )
\r
314 xQueueHandle xQueue1, xQueue2;
\r
315 struct AMessage *pxMessage;
\r
317 // Create a queue capable of containing 10 unsigned long values.
\r
318 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
320 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
321 // These should be passed by pointer as they contain a lot of data.
\r
322 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
328 // Send an unsigned long. Wait for 10 ticks for space to become
\r
329 // available if necessary.
\r
330 if( xQueueSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS )
\r
332 // Failed to post the message, even after 10 ticks.
\r
338 // Send a pointer to a struct AMessage object. Don't block if the
\r
339 // queue is already full.
\r
340 pxMessage = & xMessage;
\r
341 xQueueSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
344 // ... Rest of task code.
\r
347 * \defgroup xQueueSend xQueueSend
\r
348 * \ingroup QueueManagement
\r
350 #define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
\r
356 portBASE_TYPE xQueueGenericSend(
\r
357 xQueueHandle xQueue,
\r
358 const void * pvItemToQueue,
\r
359 portTickType xTicksToWait
\r
360 portBASE_TYPE xCopyPosition
\r
364 * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
\r
365 * xQueueSendToBack() are used in place of calling this function directly.
\r
367 * Post an item on a queue. The item is queued by copy, not by reference.
\r
368 * This function must not be called from an interrupt service routine.
\r
369 * See xQueueSendFromISR () for an alternative which may be used in an ISR.
\r
371 * @param xQueue The handle to the queue on which the item is to be posted.
\r
373 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
374 * queue. The size of the items the queue will hold was defined when the
\r
375 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
376 * into the queue storage area.
\r
378 * @param xTicksToWait The maximum amount of time the task should block
\r
379 * waiting for space to become available on the queue, should it already
\r
380 * be full. The call will return immediately if this is set to 0. The
\r
381 * time is defined in tick periods so the constant portTICK_RATE_MS
\r
382 * should be used to convert to real time if this is required.
\r
384 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
385 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
386 * at the front of the queue (for high priority messages).
\r
388 * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
\r
394 portCHAR ucMessageID;
\r
395 portCHAR ucData[ 20 ];
\r
398 unsigned portLONG ulVar = 10UL;
\r
400 void vATask( void *pvParameters )
\r
402 xQueueHandle xQueue1, xQueue2;
\r
403 struct AMessage *pxMessage;
\r
405 // Create a queue capable of containing 10 unsigned long values.
\r
406 xQueue1 = xQueueCreate( 10, sizeof( unsigned portLONG ) );
\r
408 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
409 // These should be passed by pointer as they contain a lot of data.
\r
410 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
416 // Send an unsigned long. Wait for 10 ticks for space to become
\r
417 // available if necessary.
\r
418 if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( portTickType ) 10, queueSEND_TO_BACK ) != pdPASS )
\r
420 // Failed to post the message, even after 10 ticks.
\r
426 // Send a pointer to a struct AMessage object. Don't block if the
\r
427 // queue is already full.
\r
428 pxMessage = & xMessage;
\r
429 xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
\r
432 // ... Rest of task code.
\r
435 * \defgroup xQueueSend xQueueSend
\r
436 * \ingroup QueueManagement
\r
438 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
\r
443 portBASE_TYPE xQueuePeek(
\r
444 xQueueHandle xQueue,
\r
446 portTickType xTicksToWait
\r
449 * This is a macro that calls the xQueueGenericReceive() function.
\r
451 * Receive an item from a queue without removing the item from the queue.
\r
452 * The item is received by copy so a buffer of adequate size must be
\r
453 * provided. The number of bytes copied into the buffer was defined when
\r
454 * the queue was created.
\r
456 * Successfully received items remain on the queue so will be returned again
\r
457 * by the next call, or a call to xQueueReceive().
\r
459 * This macro must not be used in an interrupt service routine.
\r
461 * @param pxQueue The handle to the queue from which the item is to be
\r
464 * @param pvBuffer Pointer to the buffer into which the received item will
\r
467 * @param xTicksToWait The maximum amount of time the task should block
\r
468 * waiting for an item to receive should the queue be empty at the time
\r
469 * of the call. The time is defined in tick periods so the constant
\r
470 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
472 * @return pdTRUE if an item was successfully received from the queue,
\r
473 * otherwise pdFALSE.
\r
479 portCHAR ucMessageID;
\r
480 portCHAR ucData[ 20 ];
\r
483 xQueueHandle xQueue;
\r
485 // Task to create a queue and post a value.
\r
486 void vATask( void *pvParameters )
\r
488 struct AMessage *pxMessage;
\r
490 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
491 // These should be passed by pointer as they contain a lot of data.
\r
492 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
495 // Failed to create the queue.
\r
500 // Send a pointer to a struct AMessage object. Don't block if the
\r
501 // queue is already full.
\r
502 pxMessage = & xMessage;
\r
503 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
505 // ... Rest of task code.
\r
508 // Task to peek the data from the queue.
\r
509 void vADifferentTask( void *pvParameters )
\r
511 struct AMessage *pxRxedMessage;
\r
515 // Peek a message on the created queue. Block for 10 ticks if a
\r
516 // message is not immediately available.
\r
517 if( xQueuePeek( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
519 // pcRxedMessage now points to the struct AMessage variable posted
\r
520 // by vATask, but the item still remains on the queue.
\r
524 // ... Rest of task code.
\r
527 * \defgroup xQueueReceive xQueueReceive
\r
528 * \ingroup QueueManagement
\r
530 #define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdTRUE )
\r
535 portBASE_TYPE xQueueReceive(
\r
536 xQueueHandle xQueue,
\r
538 portTickType xTicksToWait
\r
541 * This is a macro that calls the xQueueGenericReceive() function.
\r
543 * Receive an item from a queue. The item is received by copy so a buffer of
\r
544 * adequate size must be provided. The number of bytes copied into the buffer
\r
545 * was defined when the queue was created.
\r
547 * Successfully received items are removed from the queue.
\r
549 * This function must not be used in an interrupt service routine. See
\r
550 * xQueueReceiveFromISR for an alternative that can.
\r
552 * @param pxQueue The handle to the queue from which the item is to be
\r
555 * @param pvBuffer Pointer to the buffer into which the received item will
\r
558 * @param xTicksToWait The maximum amount of time the task should block
\r
559 * waiting for an item to receive should the queue be empty at the time
\r
560 * of the call. The time is defined in tick periods so the constant
\r
561 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
563 * @return pdTRUE if an item was successfully received from the queue,
\r
564 * otherwise pdFALSE.
\r
570 portCHAR ucMessageID;
\r
571 portCHAR ucData[ 20 ];
\r
574 xQueueHandle xQueue;
\r
576 // Task to create a queue and post a value.
\r
577 void vATask( void *pvParameters )
\r
579 struct AMessage *pxMessage;
\r
581 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
582 // These should be passed by pointer as they contain a lot of data.
\r
583 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
586 // Failed to create the queue.
\r
591 // Send a pointer to a struct AMessage object. Don't block if the
\r
592 // queue is already full.
\r
593 pxMessage = & xMessage;
\r
594 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
596 // ... Rest of task code.
\r
599 // Task to receive from the queue.
\r
600 void vADifferentTask( void *pvParameters )
\r
602 struct AMessage *pxRxedMessage;
\r
606 // Receive a message on the created queue. Block for 10 ticks if a
\r
607 // message is not immediately available.
\r
608 if( xQueueReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
610 // pcRxedMessage now points to the struct AMessage variable posted
\r
615 // ... Rest of task code.
\r
618 * \defgroup xQueueReceive xQueueReceive
\r
619 * \ingroup QueueManagement
\r
621 #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
\r
627 portBASE_TYPE xQueueGenericReceive(
\r
628 xQueueHandle xQueue,
\r
630 portTickType xTicksToWait
\r
631 portBASE_TYPE xJustPeek
\r
634 * It is preferred that the macro xQueueReceive() be used rather than calling
\r
635 * this function directly.
\r
637 * Receive an item from a queue. The item is received by copy so a buffer of
\r
638 * adequate size must be provided. The number of bytes copied into the buffer
\r
639 * was defined when the queue was created.
\r
641 * This function must not be used in an interrupt service routine. See
\r
642 * xQueueReceiveFromISR for an alternative that can.
\r
644 * @param pxQueue The handle to the queue from which the item is to be
\r
647 * @param pvBuffer Pointer to the buffer into which the received item will
\r
650 * @param xTicksToWait The maximum amount of time the task should block
\r
651 * waiting for an item to receive should the queue be empty at the time
\r
652 * of the call. The time is defined in tick periods so the constant
\r
653 * portTICK_RATE_MS should be used to convert to real time if this is required.
\r
655 * @param xJustPeek When set to true, the item received from the queue is not
\r
656 * actually removed from the queue - meaning a subsequent call to
\r
657 * xQueueReceive() will return the same item. When set to false, the item
\r
658 * being received from the queue is also removed from the queue.
\r
660 * @return pdTRUE if an item was successfully received from the queue,
\r
661 * otherwise pdFALSE.
\r
667 portCHAR ucMessageID;
\r
668 portCHAR ucData[ 20 ];
\r
671 xQueueHandle xQueue;
\r
673 // Task to create a queue and post a value.
\r
674 void vATask( void *pvParameters )
\r
676 struct AMessage *pxMessage;
\r
678 // Create a queue capable of containing 10 pointers to AMessage structures.
\r
679 // These should be passed by pointer as they contain a lot of data.
\r
680 xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
\r
683 // Failed to create the queue.
\r
688 // Send a pointer to a struct AMessage object. Don't block if the
\r
689 // queue is already full.
\r
690 pxMessage = & xMessage;
\r
691 xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
\r
693 // ... Rest of task code.
\r
696 // Task to receive from the queue.
\r
697 void vADifferentTask( void *pvParameters )
\r
699 struct AMessage *pxRxedMessage;
\r
703 // Receive a message on the created queue. Block for 10 ticks if a
\r
704 // message is not immediately available.
\r
705 if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( portTickType ) 10 ) )
\r
707 // pcRxedMessage now points to the struct AMessage variable posted
\r
712 // ... Rest of task code.
\r
715 * \defgroup xQueueReceive xQueueReceive
\r
716 * \ingroup QueueManagement
\r
718 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
\r
722 * <pre>unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );</pre>
\r
724 * Return the number of messages stored in a queue.
\r
726 * @param xQueue A handle to the queue being queried.
\r
728 * @return The number of messages available in the queue.
\r
730 * \page uxQueueMessagesWaiting uxQueueMessagesWaiting
\r
731 * \ingroup QueueManagement
\r
733 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue );
\r
737 * <pre>void vQueueDelete( xQueueHandle xQueue );</pre>
\r
739 * Delete a queue - freeing all the memory allocated for storing of items
\r
740 * placed on the queue.
\r
742 * @param xQueue A handle to the queue to be deleted.
\r
744 * \page vQueueDelete vQueueDelete
\r
745 * \ingroup QueueManagement
\r
747 void vQueueDelete( xQueueHandle xQueue );
\r
752 portBASE_TYPE xQueueSendToFrontFromISR(
\r
753 xQueueHandle pxQueue,
\r
754 const void *pvItemToQueue,
\r
755 portBASE_TYPE xTaskPreviouslyWoken
\r
759 * This is a macro that calls xQueueGenericSendFromISR().
\r
761 * Post an item to the front of a queue. It is safe to use this macro from
\r
762 * within an interrupt service routine.
\r
764 * Items are queued by copy not reference so it is preferable to only
\r
765 * queue small items, especially when called from an ISR. In most cases
\r
766 * it would be preferable to store a pointer to the item being queued.
\r
768 * @param xQueue The handle to the queue on which the item is to be posted.
\r
770 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
771 * queue. The size of the items the queue will hold was defined when the
\r
772 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
773 * into the queue storage area.
\r
775 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
776 * the same queue multiple times from a single interrupt. The first call
\r
777 * should always pass in pdFALSE. Subsequent calls should pass in
\r
778 * the value returned from the previous call. See the file serial .c in the
\r
779 * PC port for a good example of this mechanism.
\r
781 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
782 * used by the ISR to determine if a context switch may be required following
\r
785 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
788 void vBufferISR( void )
\r
791 portBASE_TYPE xTaskWokenByPost;
\r
793 // We have not woken a task at the start of the ISR.
\r
794 cTaskWokenByPost = pdFALSE;
\r
796 // Loop until the buffer is empty.
\r
799 // Obtain a byte from the buffer.
\r
800 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
802 // Post the byte. The first time round the loop cTaskWokenByPost
\r
803 // will be pdFALSE. If the queue send causes a task to wake we do
\r
804 // not want the task to run until we have finished the ISR, so
\r
805 // xQueueSendFromISR does not cause a context switch. Also we
\r
806 // don't want subsequent posts to wake any other tasks, so we store
\r
807 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
808 // knows not to wake any task the next iteration of the loop.
\r
809 xTaskWokenByPost = xQueueSendToFrontFromISR( xRxQueue, &cIn, cTaskWokenByPost );
\r
811 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
813 // Now the buffer is empty we can switch context if necessary.
\r
814 if( cTaskWokenByPost )
\r
821 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
822 * \ingroup QueueManagement
\r
824 #define xQueueSendToFrontFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken, queueSEND_TO_FRONT )
\r
830 portBASE_TYPE xQueueSendToBackFromISR(
\r
831 xQueueHandle pxQueue,
\r
832 const void *pvItemToQueue,
\r
833 portBASE_TYPE xTaskPreviouslyWoken
\r
837 * This is a macro that calls xQueueGenericSendFromISR().
\r
839 * Post an item to the back of a queue. It is safe to use this macro from
\r
840 * within an interrupt service routine.
\r
842 * Items are queued by copy not reference so it is preferable to only
\r
843 * queue small items, especially when called from an ISR. In most cases
\r
844 * it would be preferable to store a pointer to the item being queued.
\r
846 * @param xQueue The handle to the queue on which the item is to be posted.
\r
848 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
849 * queue. The size of the items the queue will hold was defined when the
\r
850 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
851 * into the queue storage area.
\r
853 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
854 * the same queue multiple times from a single interrupt. The first call
\r
855 * should always pass in pdFALSE. Subsequent calls should pass in
\r
856 * the value returned from the previous call. See the file serial .c in the
\r
857 * PC port for a good example of this mechanism.
\r
859 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
860 * used by the ISR to determine if a context switch may be required following
\r
863 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
866 void vBufferISR( void )
\r
869 portBASE_TYPE xTaskWokenByPost;
\r
871 // We have not woken a task at the start of the ISR.
\r
872 cTaskWokenByPost = pdFALSE;
\r
874 // Loop until the buffer is empty.
\r
877 // Obtain a byte from the buffer.
\r
878 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
880 // Post the byte. The first time round the loop cTaskWokenByPost
\r
881 // will be pdFALSE. If the queue send causes a task to wake we do
\r
882 // not want the task to run until we have finished the ISR, so
\r
883 // xQueueSendFromISR does not cause a context switch. Also we
\r
884 // don't want subsequent posts to wake any other tasks, so we store
\r
885 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
886 // knows not to wake any task the next iteration of the loop.
\r
887 xTaskWokenByPost = xQueueSendToBackFromISR( xRxQueue, &cIn, cTaskWokenByPost );
\r
889 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
891 // Now the buffer is empty we can switch context if necessary.
\r
892 if( cTaskWokenByPost )
\r
899 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
900 * \ingroup QueueManagement
\r
902 #define xQueueSendToBackFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken, queueSEND_TO_BACK )
\r
908 portBASE_TYPE xQueueSendFromISR(
\r
909 xQueueHandle pxQueue,
\r
910 const void *pvItemToQueue,
\r
911 portBASE_TYPE xTaskPreviouslyWoken
\r
915 * This is a macro that calls xQueueGenericSendFromISR(). It is included
\r
916 * for backward compatibility with versions of FreeRTOS.org that did not
\r
917 * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
\r
920 * Post an item to the back of a queue. It is safe to use this function from
\r
921 * within an interrupt service routine.
\r
923 * Items are queued by copy not reference so it is preferable to only
\r
924 * queue small items, especially when called from an ISR. In most cases
\r
925 * it would be preferable to store a pointer to the item being queued.
\r
927 * @param xQueue The handle to the queue on which the item is to be posted.
\r
929 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
930 * queue. The size of the items the queue will hold was defined when the
\r
931 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
932 * into the queue storage area.
\r
934 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
935 * the same queue multiple times from a single interrupt. The first call
\r
936 * should always pass in pdFALSE. Subsequent calls should pass in
\r
937 * the value returned from the previous call. See the file serial .c in the
\r
938 * PC port for a good example of this mechanism.
\r
940 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
941 * used by the ISR to determine if a context switch may be required following
\r
944 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
947 void vBufferISR( void )
\r
950 portBASE_TYPE xTaskWokenByPost;
\r
952 // We have not woken a task at the start of the ISR.
\r
953 cTaskWokenByPost = pdFALSE;
\r
955 // Loop until the buffer is empty.
\r
958 // Obtain a byte from the buffer.
\r
959 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
961 // Post the byte. The first time round the loop cTaskWokenByPost
\r
962 // will be pdFALSE. If the queue send causes a task to wake we do
\r
963 // not want the task to run until we have finished the ISR, so
\r
964 // xQueueSendFromISR does not cause a context switch. Also we
\r
965 // don't want subsequent posts to wake any other tasks, so we store
\r
966 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
967 // knows not to wake any task the next iteration of the loop.
\r
968 xTaskWokenByPost = xQueueSendFromISR( xRxQueue, &cIn, cTaskWokenByPost );
\r
970 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
972 // Now the buffer is empty we can switch context if necessary.
\r
973 if( cTaskWokenByPost )
\r
980 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
981 * \ingroup QueueManagement
\r
983 #define xQueueSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken ) xQueueGenericSendFromISR( pxQueue, pvItemToQueue, xTaskPreviouslyWoken, queueSEND_TO_BACK )
\r
988 portBASE_TYPE xQueueGenericSendFromISR(
\r
989 xQueueHandle pxQueue,
\r
990 const void *pvItemToQueue,
\r
991 portBASE_TYPE xTaskPreviouslyWoken
\r
992 portBASE_TYPE xCopyPosition
\r
996 * It is preferred that the macros xQueueSendFromISR(),
\r
997 * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
\r
998 * of calling this function directly.
\r
1000 * Post an item on a queue. It is safe to use this function from within an
\r
1001 * interrupt service routine.
\r
1003 * Items are queued by copy not reference so it is preferable to only
\r
1004 * queue small items, especially when called from an ISR. In most cases
\r
1005 * it would be preferable to store a pointer to the item being queued.
\r
1007 * @param xQueue The handle to the queue on which the item is to be posted.
\r
1009 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
1010 * queue. The size of the items the queue will hold was defined when the
\r
1011 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
1012 * into the queue storage area.
\r
1014 * @param cTaskPreviouslyWoken This is included so an ISR can post onto
\r
1015 * the same queue multiple times from a single interrupt. The first call
\r
1016 * should always pass in pdFALSE. Subsequent calls should pass in
\r
1017 * the value returned from the previous call. See the file serial .c in the
\r
1018 * PC port for a good example of this mechanism.
\r
1020 * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
\r
1021 * item at the back of the queue, or queueSEND_TO_FRONT to place the item
\r
1022 * at the front of the queue (for high priority messages).
\r
1024 * @return pdTRUE if a task was woken by posting onto the queue. This is
\r
1025 * used by the ISR to determine if a context switch may be required following
\r
1028 * Example usage for buffered IO (where the ISR can obtain more than one value
\r
1031 void vBufferISR( void )
\r
1034 portBASE_TYPE xTaskWokenByPost;
\r
1036 // We have not woken a task at the start of the ISR.
\r
1037 cTaskWokenByPost = pdFALSE;
\r
1039 // Loop until the buffer is empty.
\r
1042 // Obtain a byte from the buffer.
\r
1043 cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
\r
1045 // Post the byte. The first time round the loop cTaskWokenByPost
\r
1046 // will be pdFALSE. If the queue send causes a task to wake we do
\r
1047 // not want the task to run until we have finished the ISR, so
\r
1048 // xQueueSendFromISR does not cause a context switch. Also we
\r
1049 // don't want subsequent posts to wake any other tasks, so we store
\r
1050 // the return value back into cTaskWokenByPost so xQueueSendFromISR
\r
1051 // knows not to wake any task the next iteration of the loop.
\r
1052 xTaskWokenByPost = xQueueGenericSendFromISR( xRxQueue, &cIn, cTaskWokenByPost, queueSEND_TO_BACK );
\r
1054 } while( portINPUT_BYTE( BUFFER_COUNT ) );
\r
1056 // Now the buffer is empty we can switch context if necessary.
\r
1057 if( cTaskWokenByPost )
\r
1064 * \defgroup xQueueSendFromISR xQueueSendFromISR
\r
1065 * \ingroup QueueManagement
\r
1067 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE xTaskPreviouslyWoken, portBASE_TYPE xCopyPosition );
\r
1072 portBASE_TYPE xQueueReceiveFromISR(
\r
1073 xQueueHandle pxQueue,
\r
1075 portBASE_TYPE *pxTaskWoken
\r
1079 * Receive an item from a queue. It is safe to use this function from within an
\r
1080 * interrupt service routine.
\r
1082 * @param pxQueue The handle to the queue from which the item is to be
\r
1085 * @param pvBuffer Pointer to the buffer into which the received item will
\r
1088 * @param pxTaskWoken A task may be blocked waiting for space to become
\r
1089 * available on the queue. If xQueueReceiveFromISR causes such a task to
\r
1090 * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
\r
1091 * remain unchanged.
\r
1093 * @return pdTRUE if an item was successfully received from the queue,
\r
1094 * otherwise pdFALSE.
\r
1099 xQueueHandle xQueue;
\r
1101 // Function to create a queue and post some values.
\r
1102 void vAFunction( void *pvParameters )
\r
1104 portCHAR cValueToPost;
\r
1105 const portTickType xBlockTime = ( portTickType )0xff;
\r
1107 // Create a queue capable of containing 10 characters.
\r
1108 xQueue = xQueueCreate( 10, sizeof( portCHAR ) );
\r
1111 // Failed to create the queue.
\r
1116 // Post some characters that will be used within an ISR. If the queue
\r
1117 // is full then this task will block for xBlockTime ticks.
\r
1118 cValueToPost = 'a';
\r
1119 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1120 cValueToPost = 'b';
\r
1121 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1123 // ... keep posting characters ... this task may block when the queue
\r
1126 cValueToPost = 'c';
\r
1127 xQueueSend( xQueue, ( void * ) &cValueToPost, xBlockTime );
\r
1130 // ISR that outputs all the characters received on the queue.
\r
1131 void vISR_Routine( void )
\r
1133 portBASE_TYPE xTaskWokenByReceive = pdFALSE;
\r
1134 portCHAR cRxedChar;
\r
1136 while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
\r
1138 // A character was received. Output the character now.
\r
1139 vOutputCharacter( cRxedChar );
\r
1141 // If removing the character from the queue woke the task that was
\r
1142 // posting onto the queue cTaskWokenByReceive will have been set to
\r
1143 // pdTRUE. No matter how many times this loop iterates only one
\r
1144 // task will be woken.
\r
1147 if( cTaskWokenByPost != ( portCHAR ) pdFALSE;
\r
1153 * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
\r
1154 * \ingroup QueueManagement
\r
1156 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, const void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1160 * The functions defined above are for passing data to and from tasks. The
\r
1161 * functions below are the equivalents for passing data to and from
\r
1164 * These functions are called from the co-routine macro implementation and
\r
1165 * should not be called directly from application code. Instead use the macro
\r
1166 * wrappers defined within croutine.h.
\r
1168 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );
\r
1169 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken );
\r
1170 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait );
\r
1171 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );
\r
1174 * For internal use only. Use xSemaphoreCreateMutex() instead of calling
\r
1175 * this function directly.
\r
1177 xQueueHandle xQueueCreateMutex( void );
\r
1179 #endif /* QUEUE_H */
\r