2 FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not it can be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
78 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
\r
79 all the API functions to use the MPU wrappers. That should only be done when
\r
80 task.h is included from an application file. */
\r
81 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
\r
83 #include "FreeRTOS.h"
\r
87 #if ( configUSE_CO_ROUTINES == 1 )
\r
88 #include "croutine.h"
\r
91 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
\r
93 /* Constants used with the cRxLock and xTxLock structure members. */
\r
94 #define queueUNLOCKED ( ( signed portBASE_TYPE ) -1 )
\r
95 #define queueLOCKED_UNMODIFIED ( ( signed portBASE_TYPE ) 0 )
\r
97 #define queueERRONEOUS_UNBLOCK ( -1 )
\r
99 /* When the xQUEUE structure is used to represent a base queue its pcHead and
\r
100 pcTail members are used as pointers into the queue storage area. When the
\r
101 xQUEUE structure is used to represent a mutex pcHead and pcTail pointers are
\r
102 not necessary, and the pcHead pointer is set to NULL to indicate that the
\r
103 pcTail pointer actually points to the mutex holder (if any). Map alternative
\r
104 names to the pcHead and pcTail structure members to ensure the readability of
\r
105 the code is maintained despite this dual use of two structure members. An
\r
106 alternative implementation would be to use a union, but use of a union is
\r
107 against the coding standard (although an exception to the standard has been
\r
108 permitted where the dual use also significantly changes the type of the
\r
109 structure member). */
\r
110 #define pxMutexHolder pcTail
\r
111 #define uxQueueType pcHead
\r
112 #define queueQUEUE_IS_MUTEX NULL
\r
114 /* Semaphores do not actually store or copy data, so have an item size of
\r
116 #define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( unsigned portBASE_TYPE ) 0 )
\r
117 #define queueDONT_BLOCK ( ( portTickType ) 0U )
\r
118 #define queueMUTEX_GIVE_BLOCK_TIME ( ( portTickType ) 0U )
\r
122 * Definition of the queue used by the scheduler.
\r
123 * Items are queued by copy, not reference.
\r
125 typedef struct QueueDefinition
\r
127 signed char *pcHead; /*< Points to the beginning of the queue storage area. */
\r
128 signed char *pcTail; /*< Points to the byte at the end of the queue storage area. Once more byte is allocated than necessary to store the queue items, this is used as a marker. */
\r
130 signed char *pcWriteTo; /*< Points to the free next place in the storage area. */
\r
132 union /* Use of a union is an exception to the coding standard to ensure two mutually exclusive structure members don't appear simultaneously (wasting RAM). */
\r
134 signed char *pcReadFrom; /*< Points to the last place that a queued item was read from when the structure is used as a queue. */
\r
135 unsigned portBASE_TYPE uxRecursiveCallCount;/*< Maintains a count of the numebr of times a recursive mutex has been recursively 'taken' when the structure is used as a mutex. */
\r
138 xList xTasksWaitingToSend; /*< List of tasks that are blocked waiting to post onto this queue. Stored in priority order. */
\r
139 xList xTasksWaitingToReceive; /*< List of tasks that are blocked waiting to read from this queue. Stored in priority order. */
\r
141 volatile unsigned portBASE_TYPE uxMessagesWaiting;/*< The number of items currently in the queue. */
\r
142 unsigned portBASE_TYPE uxLength; /*< The length of the queue defined as the number of items it will hold, not the number of bytes. */
\r
143 unsigned portBASE_TYPE uxItemSize; /*< The size of each items that the queue will hold. */
\r
145 volatile signed portBASE_TYPE xRxLock; /*< Stores the number of items received from the queue (removed from the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */
\r
146 volatile signed portBASE_TYPE xTxLock; /*< Stores the number of items transmitted to the queue (added to the queue) while the queue was locked. Set to queueUNLOCKED when the queue is not locked. */
\r
148 #if ( configUSE_TRACE_FACILITY == 1 )
\r
149 unsigned char ucQueueNumber;
\r
150 unsigned char ucQueueType;
\r
153 #if ( configUSE_QUEUE_SETS == 1 )
\r
154 struct QueueDefinition *pxQueueSetContainer;
\r
158 /*-----------------------------------------------------------*/
\r
161 * The queue registry is just a means for kernel aware debuggers to locate
\r
162 * queue structures. It has no other purpose so is an optional component.
\r
164 #if ( configQUEUE_REGISTRY_SIZE > 0 )
\r
166 /* The type stored within the queue registry array. This allows a name
\r
167 to be assigned to each queue making kernel aware debugging a little
\r
168 more user friendly. */
\r
169 typedef struct QUEUE_REGISTRY_ITEM
\r
171 signed char *pcQueueName;
\r
172 xQueueHandle xHandle;
\r
173 } xQueueRegistryItem;
\r
175 /* The queue registry is simply an array of xQueueRegistryItem structures.
\r
176 The pcQueueName member of a structure being NULL is indicative of the
\r
177 array position being vacant. */
\r
178 xQueueRegistryItem xQueueRegistry[ configQUEUE_REGISTRY_SIZE ];
\r
180 #endif /* configQUEUE_REGISTRY_SIZE */
\r
183 * Unlocks a queue locked by a call to prvLockQueue. Locking a queue does not
\r
184 * prevent an ISR from adding or removing items to the queue, but does prevent
\r
185 * an ISR from removing tasks from the queue event lists. If an ISR finds a
\r
186 * queue is locked it will instead increment the appropriate queue lock count
\r
187 * to indicate that a task may require unblocking. When the queue in unlocked
\r
188 * these lock counts are inspected, and the appropriate action taken.
\r
190 static void prvUnlockQueue( xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;
\r
193 * Uses a critical section to determine if there is any data in a queue.
\r
195 * @return pdTRUE if the queue contains no items, otherwise pdFALSE.
\r
197 static signed portBASE_TYPE prvIsQueueEmpty( const xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;
\r
200 * Uses a critical section to determine if there is any space in a queue.
\r
202 * @return pdTRUE if there is no space, otherwise pdFALSE;
\r
204 static signed portBASE_TYPE prvIsQueueFull( const xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;
\r
207 * Copies an item into the queue, either at the front of the queue or the
\r
208 * back of the queue.
\r
210 static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition ) PRIVILEGED_FUNCTION;
\r
213 * Copies an item out of a queue.
\r
215 static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer ) PRIVILEGED_FUNCTION;
\r
217 #if ( configUSE_QUEUE_SETS == 1 )
\r
219 * Checks to see if a queue is a member of a queue set, and if so, notifies
\r
220 * the queue set that the queue contains data.
\r
222 static portBASE_TYPE prvNotifyQueueSetContainer( xQUEUE *pxQueue, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;
\r
225 /*-----------------------------------------------------------*/
\r
228 * Macro to mark a queue as locked. Locking a queue prevents an ISR from
\r
229 * accessing the queue event lists.
\r
231 #define prvLockQueue( pxQueue ) \
\r
232 taskENTER_CRITICAL(); \
\r
234 if( ( pxQueue )->xRxLock == queueUNLOCKED ) \
\r
236 ( pxQueue )->xRxLock = queueLOCKED_UNMODIFIED; \
\r
238 if( ( pxQueue )->xTxLock == queueUNLOCKED ) \
\r
240 ( pxQueue )->xTxLock = queueLOCKED_UNMODIFIED; \
\r
243 taskEXIT_CRITICAL()
\r
244 /*-----------------------------------------------------------*/
\r
246 portBASE_TYPE xQueueGenericReset( xQueueHandle xQueue, portBASE_TYPE xNewQueue )
\r
250 pxQueue = ( xQUEUE * ) xQueue;
\r
251 configASSERT( pxQueue );
\r
253 taskENTER_CRITICAL();
\r
255 pxQueue->pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize );
\r
256 pxQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U;
\r
257 pxQueue->pcWriteTo = pxQueue->pcHead;
\r
258 pxQueue->u.pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - ( unsigned portBASE_TYPE ) 1U ) * pxQueue->uxItemSize );
\r
259 pxQueue->xRxLock = queueUNLOCKED;
\r
260 pxQueue->xTxLock = queueUNLOCKED;
\r
262 if( xNewQueue == pdFALSE )
\r
264 /* If there are tasks blocked waiting to read from the queue, then
\r
265 the tasks will remain blocked as after this function exits the queue
\r
266 will still be empty. If there are tasks blocked waiting to write to
\r
267 the queue, then one should be unblocked as after this function exits
\r
268 it will be possible to write to it. */
\r
269 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
271 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )
\r
273 portYIELD_WITHIN_API();
\r
279 /* Ensure the event queues start in the correct state. */
\r
280 vListInitialise( &( pxQueue->xTasksWaitingToSend ) );
\r
281 vListInitialise( &( pxQueue->xTasksWaitingToReceive ) );
\r
284 taskEXIT_CRITICAL();
\r
286 /* A value is returned for calling semantic consistency with previous
\r
290 /*-----------------------------------------------------------*/
\r
292 xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType )
\r
294 xQUEUE *pxNewQueue;
\r
295 size_t xQueueSizeInBytes;
\r
296 xQueueHandle xReturn = NULL;
\r
298 /* Remove compiler warnings about unused parameters should
\r
299 configUSE_TRACE_FACILITY not be set to 1. */
\r
300 ( void ) ucQueueType;
\r
302 /* Allocate the new queue structure. */
\r
303 if( uxQueueLength > ( unsigned portBASE_TYPE ) 0 )
\r
305 pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );
\r
306 if( pxNewQueue != NULL )
\r
308 /* Create the list of pointers to queue items. The queue is one byte
\r
309 longer than asked for to make wrap checking easier/faster. */
\r
310 xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ) + ( size_t ) 1;
\r
312 pxNewQueue->pcHead = ( signed char * ) pvPortMalloc( xQueueSizeInBytes );
\r
313 if( pxNewQueue->pcHead != NULL )
\r
315 /* Initialise the queue members as described above where the
\r
316 queue type is defined. */
\r
317 pxNewQueue->uxLength = uxQueueLength;
\r
318 pxNewQueue->uxItemSize = uxItemSize;
\r
319 xQueueGenericReset( pxNewQueue, pdTRUE );
\r
321 #if ( configUSE_TRACE_FACILITY == 1 )
\r
323 pxNewQueue->ucQueueType = ucQueueType;
\r
325 #endif /* configUSE_TRACE_FACILITY */
\r
327 #if( configUSE_QUEUE_SETS == 1 )
\r
329 pxNewQueue->pxQueueSetContainer = NULL;
\r
331 #endif /* configUSE_QUEUE_SETS */
\r
333 traceQUEUE_CREATE( pxNewQueue );
\r
334 xReturn = pxNewQueue;
\r
338 traceQUEUE_CREATE_FAILED( ucQueueType );
\r
339 vPortFree( pxNewQueue );
\r
344 configASSERT( xReturn );
\r
348 /*-----------------------------------------------------------*/
\r
350 #if ( configUSE_MUTEXES == 1 )
\r
352 xQueueHandle xQueueCreateMutex( unsigned char ucQueueType )
\r
354 xQUEUE *pxNewQueue;
\r
356 /* Prevent compiler warnings about unused parameters if
\r
357 configUSE_TRACE_FACILITY does not equal 1. */
\r
358 ( void ) ucQueueType;
\r
360 /* Allocate the new queue structure. */
\r
361 pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );
\r
362 if( pxNewQueue != NULL )
\r
364 /* Information required for priority inheritance. */
\r
365 pxNewQueue->pxMutexHolder = NULL;
\r
366 pxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX;
\r
368 /* Queues used as a mutex no data is actually copied into or out
\r
370 pxNewQueue->pcWriteTo = NULL;
\r
371 pxNewQueue->u.pcReadFrom = NULL;
\r
373 /* Each mutex has a length of 1 (like a binary semaphore) and
\r
374 an item size of 0 as nothing is actually copied into or out
\r
376 pxNewQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U;
\r
377 pxNewQueue->uxLength = ( unsigned portBASE_TYPE ) 1U;
\r
378 pxNewQueue->uxItemSize = ( unsigned portBASE_TYPE ) 0U;
\r
379 pxNewQueue->xRxLock = queueUNLOCKED;
\r
380 pxNewQueue->xTxLock = queueUNLOCKED;
\r
382 #if ( configUSE_TRACE_FACILITY == 1 )
\r
384 pxNewQueue->ucQueueType = ucQueueType;
\r
388 #if ( configUSE_QUEUE_SETS == 1 )
\r
390 pxNewQueue->pxQueueSetContainer = NULL;
\r
394 /* Ensure the event queues start with the correct state. */
\r
395 vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) );
\r
396 vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );
\r
398 traceCREATE_MUTEX( pxNewQueue );
\r
400 /* Start with the semaphore in the expected state. */
\r
401 xQueueGenericSend( pxNewQueue, NULL, ( portTickType ) 0U, queueSEND_TO_BACK );
\r
405 traceCREATE_MUTEX_FAILED();
\r
408 configASSERT( pxNewQueue );
\r
412 #endif /* configUSE_MUTEXES */
\r
413 /*-----------------------------------------------------------*/
\r
415 #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
\r
417 void* xQueueGetMutexHolder( xQueueHandle xSemaphore )
\r
421 /* This function is called by xSemaphoreGetMutexHolder(), and should not
\r
422 be called directly. Note: This is is a good way of determining if the
\r
423 calling task is the mutex holder, but not a good way of determining the
\r
424 identity of the mutex holder, as the holder may change between the
\r
425 following critical section exiting and the function returning. */
\r
426 taskENTER_CRITICAL();
\r
428 if( ( ( xQUEUE * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX )
\r
430 pxReturn = ( void * ) ( ( xQUEUE * ) xSemaphore )->pxMutexHolder;
\r
437 taskEXIT_CRITICAL();
\r
443 /*-----------------------------------------------------------*/
\r
445 #if ( configUSE_RECURSIVE_MUTEXES == 1 )
\r
447 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex )
\r
449 portBASE_TYPE xReturn;
\r
452 pxMutex = ( xQUEUE * ) xMutex;
\r
453 configASSERT( pxMutex );
\r
455 /* If this is the task that holds the mutex then pxMutexHolder will not
\r
456 change outside of this task. If this task does not hold the mutex then
\r
457 pxMutexHolder can never coincidentally equal the tasks handle, and as
\r
458 this is the only condition we are interested in it does not matter if
\r
459 pxMutexHolder is accessed simultaneously by another task. Therefore no
\r
460 mutual exclusion is required to test the pxMutexHolder variable. */
\r
461 if( pxMutex->pxMutexHolder == ( void * ) xTaskGetCurrentTaskHandle() )
\r
463 traceGIVE_MUTEX_RECURSIVE( pxMutex );
\r
465 /* uxRecursiveCallCount cannot be zero if pxMutexHolder is equal to
\r
466 the task handle, therefore no underflow check is required. Also,
\r
467 uxRecursiveCallCount is only modified by the mutex holder, and as
\r
468 there can only be one, no mutual exclusion is required to modify the
\r
469 uxRecursiveCallCount member. */
\r
470 ( pxMutex->u.uxRecursiveCallCount )--;
\r
472 /* Have we unwound the call count? */
\r
473 if( pxMutex->u.uxRecursiveCallCount == 0 )
\r
475 /* Return the mutex. This will automatically unblock any other
\r
476 task that might be waiting to access the mutex. */
\r
477 xQueueGenericSend( pxMutex, NULL, queueMUTEX_GIVE_BLOCK_TIME, queueSEND_TO_BACK );
\r
484 /* We cannot give the mutex because we are not the holder. */
\r
487 traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex );
\r
493 #endif /* configUSE_RECURSIVE_MUTEXES */
\r
494 /*-----------------------------------------------------------*/
\r
496 #if ( configUSE_RECURSIVE_MUTEXES == 1 )
\r
498 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime )
\r
500 portBASE_TYPE xReturn;
\r
503 pxMutex = ( xQUEUE * ) xMutex;
\r
504 configASSERT( pxMutex );
\r
506 /* Comments regarding mutual exclusion as per those within
\r
507 xQueueGiveMutexRecursive(). */
\r
509 traceTAKE_MUTEX_RECURSIVE( pxMutex );
\r
511 if( pxMutex->pxMutexHolder == ( void * ) xTaskGetCurrentTaskHandle() )
\r
513 ( pxMutex->u.uxRecursiveCallCount )++;
\r
518 xReturn = xQueueGenericReceive( pxMutex, NULL, xBlockTime, pdFALSE );
\r
520 /* pdPASS will only be returned if we successfully obtained the mutex,
\r
521 we may have blocked to reach here. */
\r
522 if( xReturn == pdPASS )
\r
524 ( pxMutex->u.uxRecursiveCallCount )++;
\r
528 traceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex );
\r
535 #endif /* configUSE_RECURSIVE_MUTEXES */
\r
536 /*-----------------------------------------------------------*/
\r
538 #if ( configUSE_COUNTING_SEMAPHORES == 1 )
\r
540 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount )
\r
542 xQueueHandle xHandle;
\r
544 xHandle = xQueueGenericCreate( ( unsigned portBASE_TYPE ) uxCountValue, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE );
\r
546 if( xHandle != NULL )
\r
548 ( ( xQUEUE * ) xHandle )->uxMessagesWaiting = uxInitialCount;
\r
550 traceCREATE_COUNTING_SEMAPHORE();
\r
554 traceCREATE_COUNTING_SEMAPHORE_FAILED();
\r
557 configASSERT( xHandle );
\r
561 #endif /* configUSE_COUNTING_SEMAPHORES */
\r
562 /*-----------------------------------------------------------*/
\r
564 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )
\r
566 signed portBASE_TYPE xEntryTimeSet = pdFALSE;
\r
567 xTimeOutType xTimeOut;
\r
570 pxQueue = ( xQUEUE * ) xQueue;
\r
571 configASSERT( pxQueue );
\r
572 configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );
\r
573 configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
\r
575 /* This function relaxes the coding standard somewhat to allow return
\r
576 statements within the function itself. This is done in the interest
\r
577 of execution time efficiency. */
\r
580 taskENTER_CRITICAL();
\r
582 /* Is there room on the queue now? The running task must be
\r
583 the highest priority task wanting to access the queue. If
\r
584 the head item in the queue is to be overwritten then it does
\r
585 not matter if the queue is full. */
\r
586 if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
\r
588 traceQUEUE_SEND( pxQueue );
\r
589 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
\r
591 #if ( configUSE_QUEUE_SETS == 1 )
\r
593 if( pxQueue->pxQueueSetContainer != NULL )
\r
595 if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE )
\r
597 /* The queue is a member of a queue set, and posting
\r
598 to the queue set caused a higher priority task to
\r
599 unblock. A context switch is required. */
\r
600 portYIELD_WITHIN_API();
\r
605 /* If there was a task waiting for data to arrive on the
\r
606 queue then unblock it now. */
\r
607 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
609 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )
\r
611 /* The unblocked task has a priority higher than
\r
612 our own so yield immediately. Yes it is ok to
\r
613 do this from within the critical section - the
\r
614 kernel takes care of that. */
\r
615 portYIELD_WITHIN_API();
\r
620 #else /* configUSE_QUEUE_SETS */
\r
622 /* If there was a task waiting for data to arrive on the
\r
623 queue then unblock it now. */
\r
624 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
626 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )
\r
628 /* The unblocked task has a priority higher than
\r
629 our own so yield immediately. Yes it is ok to do
\r
630 this from within the critical section - the kernel
\r
631 takes care of that. */
\r
632 portYIELD_WITHIN_API();
\r
636 #endif /* configUSE_QUEUE_SETS */
\r
638 taskEXIT_CRITICAL();
\r
640 /* Return to the original privilege level before exiting the
\r
646 if( xTicksToWait == ( portTickType ) 0 )
\r
648 /* The queue was full and no block time is specified (or
\r
649 the block time has expired) so leave now. */
\r
650 taskEXIT_CRITICAL();
\r
652 /* Return to the original privilege level before exiting
\r
654 traceQUEUE_SEND_FAILED( pxQueue );
\r
655 return errQUEUE_FULL;
\r
657 else if( xEntryTimeSet == pdFALSE )
\r
659 /* The queue was full and a block time was specified so
\r
660 configure the timeout structure. */
\r
661 vTaskSetTimeOutState( &xTimeOut );
\r
662 xEntryTimeSet = pdTRUE;
\r
666 taskEXIT_CRITICAL();
\r
668 /* Interrupts and other tasks can send to and receive from the queue
\r
669 now the critical section has been exited. */
\r
672 prvLockQueue( pxQueue );
\r
674 /* Update the timeout state to see if it has expired yet. */
\r
675 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
677 if( prvIsQueueFull( pxQueue ) != pdFALSE )
\r
679 traceBLOCKING_ON_QUEUE_SEND( pxQueue );
\r
680 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );
\r
682 /* Unlocking the queue means queue events can effect the
\r
683 event list. It is possible that interrupts occurring now
\r
684 remove this task from the event list again - but as the
\r
685 scheduler is suspended the task will go onto the pending
\r
686 ready last instead of the actual ready list. */
\r
687 prvUnlockQueue( pxQueue );
\r
689 /* Resuming the scheduler will move tasks from the pending
\r
690 ready list into the ready list - so it is feasible that this
\r
691 task is already in a ready list before it yields - in which
\r
692 case the yield will not cause a context switch unless there
\r
693 is also a higher priority task in the pending ready list. */
\r
694 if( xTaskResumeAll() == pdFALSE )
\r
696 portYIELD_WITHIN_API();
\r
702 prvUnlockQueue( pxQueue );
\r
703 ( void ) xTaskResumeAll();
\r
708 /* The timeout has expired. */
\r
709 prvUnlockQueue( pxQueue );
\r
710 ( void ) xTaskResumeAll();
\r
712 /* Return to the original privilege level before exiting the
\r
714 traceQUEUE_SEND_FAILED( pxQueue );
\r
715 return errQUEUE_FULL;
\r
719 /*-----------------------------------------------------------*/
\r
721 #if ( configUSE_ALTERNATIVE_API == 1 )
\r
723 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )
\r
725 signed portBASE_TYPE xEntryTimeSet = pdFALSE;
\r
726 xTimeOutType xTimeOut;
\r
729 pxQueue = ( xQUEUE * ) xQueue;
\r
730 configASSERT( pxQueue );
\r
731 configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );
\r
735 taskENTER_CRITICAL();
\r
737 /* Is there room on the queue now? To be running we must be
\r
738 the highest priority task wanting to access the queue. */
\r
739 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
741 traceQUEUE_SEND( pxQueue );
\r
742 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
\r
744 /* If there was a task waiting for data to arrive on the
\r
745 queue then unblock it now. */
\r
746 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
748 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )
\r
750 /* The unblocked task has a priority higher than
\r
751 our own so yield immediately. */
\r
752 portYIELD_WITHIN_API();
\r
756 taskEXIT_CRITICAL();
\r
761 if( xTicksToWait == ( portTickType ) 0 )
\r
763 taskEXIT_CRITICAL();
\r
764 return errQUEUE_FULL;
\r
766 else if( xEntryTimeSet == pdFALSE )
\r
768 vTaskSetTimeOutState( &xTimeOut );
\r
769 xEntryTimeSet = pdTRUE;
\r
773 taskEXIT_CRITICAL();
\r
775 taskENTER_CRITICAL();
\r
777 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
779 if( prvIsQueueFull( pxQueue ) != pdFALSE )
\r
781 traceBLOCKING_ON_QUEUE_SEND( pxQueue );
\r
782 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );
\r
783 portYIELD_WITHIN_API();
\r
788 taskEXIT_CRITICAL();
\r
789 traceQUEUE_SEND_FAILED( pxQueue );
\r
790 return errQUEUE_FULL;
\r
793 taskEXIT_CRITICAL();
\r
797 #endif /* configUSE_ALTERNATIVE_API */
\r
798 /*-----------------------------------------------------------*/
\r
800 #if ( configUSE_ALTERNATIVE_API == 1 )
\r
802 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )
\r
804 signed portBASE_TYPE xEntryTimeSet = pdFALSE;
\r
805 xTimeOutType xTimeOut;
\r
806 signed char *pcOriginalReadPosition;
\r
809 pxQueue = ( xQUEUE * ) xQueue;
\r
810 configASSERT( pxQueue );
\r
811 configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );
\r
815 taskENTER_CRITICAL();
\r
817 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
819 /* Remember our read position in case we are just peeking. */
\r
820 pcOriginalReadPosition = pxQueue->u.pcReadFrom;
\r
822 prvCopyDataFromQueue( pxQueue, pvBuffer );
\r
824 if( xJustPeeking == pdFALSE )
\r
826 traceQUEUE_RECEIVE( pxQueue );
\r
828 /* We are actually removing data. */
\r
829 --( pxQueue->uxMessagesWaiting );
\r
831 #if ( configUSE_MUTEXES == 1 )
\r
833 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
835 /* Record the information required to implement
\r
836 priority inheritance should it become necessary. */
\r
837 pxQueue->pxMutexHolder = ( void * ) xTaskGetCurrentTaskHandle();
\r
842 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
844 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )
\r
846 portYIELD_WITHIN_API();
\r
852 traceQUEUE_PEEK( pxQueue );
\r
854 /* We are not removing the data, so reset our read
\r
856 pxQueue->u.pcReadFrom = pcOriginalReadPosition;
\r
858 /* The data is being left in the queue, so see if there are
\r
859 any other tasks waiting for the data. */
\r
860 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
862 /* Tasks that are removed from the event list will get added to
\r
863 the pending ready list as the scheduler is still suspended. */
\r
864 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
866 /* The task waiting has a higher priority than this task. */
\r
867 portYIELD_WITHIN_API();
\r
873 taskEXIT_CRITICAL();
\r
878 if( xTicksToWait == ( portTickType ) 0 )
\r
880 taskEXIT_CRITICAL();
\r
881 traceQUEUE_RECEIVE_FAILED( pxQueue );
\r
882 return errQUEUE_EMPTY;
\r
884 else if( xEntryTimeSet == pdFALSE )
\r
886 vTaskSetTimeOutState( &xTimeOut );
\r
887 xEntryTimeSet = pdTRUE;
\r
891 taskEXIT_CRITICAL();
\r
893 taskENTER_CRITICAL();
\r
895 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
897 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
\r
899 traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );
\r
901 #if ( configUSE_MUTEXES == 1 )
\r
903 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
905 portENTER_CRITICAL();
\r
907 vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );
\r
909 portEXIT_CRITICAL();
\r
914 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
\r
915 portYIELD_WITHIN_API();
\r
920 taskEXIT_CRITICAL();
\r
921 traceQUEUE_RECEIVE_FAILED( pxQueue );
\r
922 return errQUEUE_EMPTY;
\r
925 taskEXIT_CRITICAL();
\r
930 #endif /* configUSE_ALTERNATIVE_API */
\r
931 /*-----------------------------------------------------------*/
\r
933 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle xQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition )
\r
935 signed portBASE_TYPE xReturn;
\r
936 unsigned portBASE_TYPE uxSavedInterruptStatus;
\r
939 pxQueue = ( xQUEUE * ) xQueue;
\r
940 configASSERT( pxQueue );
\r
941 configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );
\r
942 configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
\r
944 /* RTOS ports that support interrupt nesting have the concept of a maximum
\r
945 system call (or maximum API call) interrupt priority. Interrupts that are
\r
946 above the maximum system call priority are keep permanently enabled, even
\r
947 when the RTOS kernel is in a critical section, but cannot make any calls to
\r
948 FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
\r
949 then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
\r
950 failure if a FreeRTOS API function is called from an interrupt that has been
\r
951 assigned a priority above the configured maximum system call priority.
\r
952 Only FreeRTOS functions that end in FromISR can be called from interrupts
\r
953 that have been assigned a priority at or (logically) below the maximum
\r
954 system call interrupt priority. FreeRTOS maintains a separate interrupt
\r
955 safe API to ensure interrupt entry is as fast and as simple as possible.
\r
956 More information (albeit Cortex-M specific) is provided on the following
\r
957 link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */
\r
958 portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
\r
960 /* Similar to xQueueGenericSend, except we don't block if there is no room
\r
961 in the queue. Also we don't directly wake a task that was blocked on a
\r
962 queue read, instead we return a flag to say whether a context switch is
\r
963 required or not (i.e. has a task with a higher priority than us been woken
\r
965 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
\r
967 if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
\r
969 traceQUEUE_SEND_FROM_ISR( pxQueue );
\r
971 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
\r
973 /* If the queue is locked we do not alter the event list. This will
\r
974 be done when the queue is unlocked later. */
\r
975 if( pxQueue->xTxLock == queueUNLOCKED )
\r
977 #if ( configUSE_QUEUE_SETS == 1 )
\r
979 if( pxQueue->pxQueueSetContainer != NULL )
\r
981 if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE )
\r
983 /* The queue is a member of a queue set, and posting
\r
984 to the queue set caused a higher priority task to
\r
985 unblock. A context switch is required. */
\r
986 if( pxHigherPriorityTaskWoken != NULL )
\r
988 *pxHigherPriorityTaskWoken = pdTRUE;
\r
994 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
996 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
998 /* The task waiting has a higher priority so record that a
\r
999 context switch is required. */
\r
1000 if( pxHigherPriorityTaskWoken != NULL )
\r
1002 *pxHigherPriorityTaskWoken = pdTRUE;
\r
1008 #else /* configUSE_QUEUE_SETS */
\r
1010 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
1012 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1014 /* The task waiting has a higher priority so record that a
\r
1015 context switch is required. */
\r
1016 if( pxHigherPriorityTaskWoken != NULL )
\r
1018 *pxHigherPriorityTaskWoken = pdTRUE;
\r
1023 #endif /* configUSE_QUEUE_SETS */
\r
1027 /* Increment the lock count so the task that unlocks the queue
\r
1028 knows that data was posted while it was locked. */
\r
1029 ++( pxQueue->xTxLock );
\r
1036 traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );
\r
1037 xReturn = errQUEUE_FULL;
\r
1040 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
\r
1044 /*-----------------------------------------------------------*/
\r
1046 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )
\r
1048 signed portBASE_TYPE xEntryTimeSet = pdFALSE;
\r
1049 xTimeOutType xTimeOut;
\r
1050 signed char *pcOriginalReadPosition;
\r
1053 pxQueue = ( xQUEUE * ) xQueue;
\r
1054 configASSERT( pxQueue );
\r
1055 configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );
\r
1057 /* This function relaxes the coding standard somewhat to allow return
\r
1058 statements within the function itself. This is done in the interest
\r
1059 of execution time efficiency. */
\r
1063 taskENTER_CRITICAL();
\r
1065 /* Is there data in the queue now? To be running we must be
\r
1066 the highest priority task wanting to access the queue. */
\r
1067 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
1069 /* Remember the read position in case the queue is only being
\r
1071 pcOriginalReadPosition = pxQueue->u.pcReadFrom;
\r
1073 prvCopyDataFromQueue( pxQueue, pvBuffer );
\r
1075 if( xJustPeeking == pdFALSE )
\r
1077 traceQUEUE_RECEIVE( pxQueue );
\r
1079 /* Actually removing data, not just peeking. */
\r
1080 --( pxQueue->uxMessagesWaiting );
\r
1082 #if ( configUSE_MUTEXES == 1 )
\r
1084 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
1086 /* Record the information required to implement
\r
1087 priority inheritance should it become necessary. */
\r
1088 pxQueue->pxMutexHolder = ( void * ) xTaskGetCurrentTaskHandle();
\r
1093 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
1095 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )
\r
1097 portYIELD_WITHIN_API();
\r
1103 traceQUEUE_PEEK( pxQueue );
\r
1105 /* The data is not being removed, so reset the read
\r
1107 pxQueue->u.pcReadFrom = pcOriginalReadPosition;
\r
1109 /* The data is being left in the queue, so see if there are
\r
1110 any other tasks waiting for the data. */
\r
1111 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
1113 /* Tasks that are removed from the event list will get added to
\r
1114 the pending ready list as the scheduler is still suspended. */
\r
1115 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1117 /* The task waiting has a higher priority than this task. */
\r
1118 portYIELD_WITHIN_API();
\r
1123 taskEXIT_CRITICAL();
\r
1128 if( xTicksToWait == ( portTickType ) 0 )
\r
1130 /* The queue was empty and no block time is specified (or
\r
1131 the block time has expired) so leave now. */
\r
1132 taskEXIT_CRITICAL();
\r
1133 traceQUEUE_RECEIVE_FAILED( pxQueue );
\r
1134 return errQUEUE_EMPTY;
\r
1136 else if( xEntryTimeSet == pdFALSE )
\r
1138 /* The queue was empty and a block time was specified so
\r
1139 configure the timeout structure. */
\r
1140 vTaskSetTimeOutState( &xTimeOut );
\r
1141 xEntryTimeSet = pdTRUE;
\r
1145 taskEXIT_CRITICAL();
\r
1147 /* Interrupts and other tasks can send to and receive from the queue
\r
1148 now the critical section has been exited. */
\r
1150 vTaskSuspendAll();
\r
1151 prvLockQueue( pxQueue );
\r
1153 /* Update the timeout state to see if it has expired yet. */
\r
1154 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
1156 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
\r
1158 traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );
\r
1160 #if ( configUSE_MUTEXES == 1 )
\r
1162 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
1164 portENTER_CRITICAL();
\r
1166 vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );
\r
1168 portEXIT_CRITICAL();
\r
1173 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
\r
1174 prvUnlockQueue( pxQueue );
\r
1175 if( xTaskResumeAll() == pdFALSE )
\r
1177 portYIELD_WITHIN_API();
\r
1183 prvUnlockQueue( pxQueue );
\r
1184 ( void ) xTaskResumeAll();
\r
1189 prvUnlockQueue( pxQueue );
\r
1190 ( void ) xTaskResumeAll();
\r
1191 traceQUEUE_RECEIVE_FAILED( pxQueue );
\r
1192 return errQUEUE_EMPTY;
\r
1196 /*-----------------------------------------------------------*/
\r
1198 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken )
\r
1200 signed portBASE_TYPE xReturn;
\r
1201 unsigned portBASE_TYPE uxSavedInterruptStatus;
\r
1204 pxQueue = ( xQUEUE * ) xQueue;
\r
1205 configASSERT( pxQueue );
\r
1206 configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );
\r
1208 /* RTOS ports that support interrupt nesting have the concept of a maximum
\r
1209 system call (or maximum API call) interrupt priority. Interrupts that are
\r
1210 above the maximum system call priority are keep permanently enabled, even
\r
1211 when the RTOS kernel is in a critical section, but cannot make any calls to
\r
1212 FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
\r
1213 then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
\r
1214 failure if a FreeRTOS API function is called from an interrupt that has been
\r
1215 assigned a priority above the configured maximum system call priority.
\r
1216 Only FreeRTOS functions that end in FromISR can be called from interrupts
\r
1217 that have been assigned a priority at or (logically) below the maximum
\r
1218 system call interrupt priority. FreeRTOS maintains a separate interrupt
\r
1219 safe API to ensure interrupt entry is as fast and as simple as possible.
\r
1220 More information (albeit Cortex-M specific) is provided on the following
\r
1221 link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */
\r
1222 portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
\r
1224 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
\r
1226 /* Cannot block in an ISR, so check there is data available. */
\r
1227 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
1229 traceQUEUE_RECEIVE_FROM_ISR( pxQueue );
\r
1231 prvCopyDataFromQueue( pxQueue, pvBuffer );
\r
1232 --( pxQueue->uxMessagesWaiting );
\r
1234 /* If the queue is locked the event list will not be modified.
\r
1235 Instead update the lock count so the task that unlocks the queue
\r
1236 will know that an ISR has removed data while the queue was
\r
1238 if( pxQueue->xRxLock == queueUNLOCKED )
\r
1240 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
1242 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
1244 /* The task waiting has a higher priority than us so
\r
1245 force a context switch. */
\r
1246 if( pxHigherPriorityTaskWoken != NULL )
\r
1248 *pxHigherPriorityTaskWoken = pdTRUE;
\r
1255 /* Increment the lock count so the task that unlocks the queue
\r
1256 knows that data was removed while it was locked. */
\r
1257 ++( pxQueue->xRxLock );
\r
1265 traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue );
\r
1268 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
\r
1272 /*-----------------------------------------------------------*/
\r
1274 signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, void * const pvBuffer )
\r
1276 signed portBASE_TYPE xReturn;
\r
1277 unsigned portBASE_TYPE uxSavedInterruptStatus;
\r
1278 signed char *pcOriginalReadPosition;
\r
1281 pxQueue = ( xQUEUE * ) xQueue;
\r
1282 configASSERT( pxQueue );
\r
1283 configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );
\r
1285 /* RTOS ports that support interrupt nesting have the concept of a maximum
\r
1286 system call (or maximum API call) interrupt priority. Interrupts that are
\r
1287 above the maximum system call priority are keep permanently enabled, even
\r
1288 when the RTOS kernel is in a critical section, but cannot make any calls to
\r
1289 FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
\r
1290 then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
\r
1291 failure if a FreeRTOS API function is called from an interrupt that has been
\r
1292 assigned a priority above the configured maximum system call priority.
\r
1293 Only FreeRTOS functions that end in FromISR can be called from interrupts
\r
1294 that have been assigned a priority at or (logically) below the maximum
\r
1295 system call interrupt priority. FreeRTOS maintains a separate interrupt
\r
1296 safe API to ensure interrupt entry is as fast and as simple as possible.
\r
1297 More information (albeit Cortex-M specific) is provided on the following
\r
1298 link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */
\r
1299 portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
\r
1301 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
\r
1303 /* Cannot block in an ISR, so check there is data available. */
\r
1304 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
1306 traceQUEUE_PEEK_FROM_ISR( pxQueue );
\r
1308 /* Remember the read position so it can be reset as nothing is
\r
1309 actually being removed from the queue. */
\r
1310 pcOriginalReadPosition = pxQueue->u.pcReadFrom;
\r
1311 prvCopyDataFromQueue( pxQueue, pvBuffer );
\r
1312 pxQueue->u.pcReadFrom = pcOriginalReadPosition;
\r
1319 traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue );
\r
1322 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
\r
1326 /*-----------------------------------------------------------*/
\r
1328 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue )
\r
1330 unsigned portBASE_TYPE uxReturn;
\r
1332 configASSERT( xQueue );
\r
1334 taskENTER_CRITICAL();
\r
1335 uxReturn = ( ( xQUEUE * ) xQueue )->uxMessagesWaiting;
\r
1336 taskEXIT_CRITICAL();
\r
1340 /*-----------------------------------------------------------*/
\r
1342 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle xQueue )
\r
1344 unsigned portBASE_TYPE uxReturn;
\r
1346 configASSERT( xQueue );
\r
1348 uxReturn = ( ( xQUEUE * ) xQueue )->uxMessagesWaiting;
\r
1352 /*-----------------------------------------------------------*/
\r
1354 void vQueueDelete( xQueueHandle xQueue )
\r
1358 pxQueue = ( xQUEUE * ) xQueue;
\r
1359 configASSERT( pxQueue );
\r
1361 traceQUEUE_DELETE( pxQueue );
\r
1362 #if ( configQUEUE_REGISTRY_SIZE > 0 )
\r
1364 vQueueUnregisterQueue( pxQueue );
\r
1367 vPortFree( pxQueue->pcHead );
\r
1368 vPortFree( pxQueue );
\r
1370 /*-----------------------------------------------------------*/
\r
1372 #if ( configUSE_TRACE_FACILITY == 1 )
\r
1374 unsigned char ucQueueGetQueueNumber( xQueueHandle xQueue )
\r
1376 return ( ( xQUEUE * ) xQueue )->ucQueueNumber;
\r
1379 #endif /* configUSE_TRACE_FACILITY */
\r
1380 /*-----------------------------------------------------------*/
\r
1382 #if ( configUSE_TRACE_FACILITY == 1 )
\r
1384 void vQueueSetQueueNumber( xQueueHandle xQueue, unsigned char ucQueueNumber )
\r
1386 ( ( xQUEUE * ) xQueue )->ucQueueNumber = ucQueueNumber;
\r
1389 #endif /* configUSE_TRACE_FACILITY */
\r
1390 /*-----------------------------------------------------------*/
\r
1392 #if ( configUSE_TRACE_FACILITY == 1 )
\r
1394 unsigned char ucQueueGetQueueType( xQueueHandle xQueue )
\r
1396 return ( ( xQUEUE * ) xQueue )->ucQueueType;
\r
1399 #endif /* configUSE_TRACE_FACILITY */
\r
1400 /*-----------------------------------------------------------*/
\r
1402 static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition )
\r
1404 if( pxQueue->uxItemSize == ( unsigned portBASE_TYPE ) 0 )
\r
1406 #if ( configUSE_MUTEXES == 1 )
\r
1408 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
1410 /* The mutex is no longer being held. */
\r
1411 vTaskPriorityDisinherit( ( void * ) pxQueue->pxMutexHolder );
\r
1412 pxQueue->pxMutexHolder = NULL;
\r
1415 #endif /* configUSE_MUTEXES */
\r
1417 else if( xPosition == queueSEND_TO_BACK )
\r
1419 memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize );
\r
1420 pxQueue->pcWriteTo += pxQueue->uxItemSize;
\r
1421 if( pxQueue->pcWriteTo >= pxQueue->pcTail )
\r
1423 pxQueue->pcWriteTo = pxQueue->pcHead;
\r
1428 memcpy( ( void * ) pxQueue->u.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize );
\r
1429 pxQueue->u.pcReadFrom -= pxQueue->uxItemSize;
\r
1430 if( pxQueue->u.pcReadFrom < pxQueue->pcHead )
\r
1432 pxQueue->u.pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );
\r
1435 if( xPosition == queueOVERWRITE )
\r
1437 if( pxQueue->uxMessagesWaiting > 0 )
\r
1439 /* An item is not being added but overwritten, so subtract
\r
1440 one from the recorded number of items in the queue so when
\r
1441 one is added again below the number of recorded items remains
\r
1443 --( pxQueue->uxMessagesWaiting );
\r
1448 ++( pxQueue->uxMessagesWaiting );
\r
1450 /*-----------------------------------------------------------*/
\r
1452 static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer )
\r
1454 if( pxQueue->uxQueueType != queueQUEUE_IS_MUTEX )
\r
1456 pxQueue->u.pcReadFrom += pxQueue->uxItemSize;
\r
1457 if( pxQueue->u.pcReadFrom >= pxQueue->pcTail )
\r
1459 pxQueue->u.pcReadFrom = pxQueue->pcHead;
\r
1461 memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( size_t ) pxQueue->uxItemSize );
\r
1464 /*-----------------------------------------------------------*/
\r
1466 static void prvUnlockQueue( xQUEUE *pxQueue )
\r
1468 /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */
\r
1470 /* The lock counts contains the number of extra data items placed or
\r
1471 removed from the queue while the queue was locked. When a queue is
\r
1472 locked items can be added or removed, but the event lists cannot be
\r
1474 taskENTER_CRITICAL();
\r
1476 /* See if data was added to the queue while it was locked. */
\r
1477 while( pxQueue->xTxLock > queueLOCKED_UNMODIFIED )
\r
1479 /* Data was posted while the queue was locked. Are any tasks
\r
1480 blocked waiting for data to become available? */
\r
1481 #if ( configUSE_QUEUE_SETS == 1 )
\r
1483 if( pxQueue->pxQueueSetContainer != NULL )
\r
1485 if( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) == pdTRUE )
\r
1487 /* The queue is a member of a queue set, and posting to
\r
1488 the queue set caused a higher priority task to unblock.
\r
1489 A context switch is required. */
\r
1490 vTaskMissedYield();
\r
1495 /* Tasks that are removed from the event list will get added to
\r
1496 the pending ready list as the scheduler is still suspended. */
\r
1497 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
1499 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1501 /* The task waiting has a higher priority so record that a
\r
1502 context switch is required. */
\r
1503 vTaskMissedYield();
\r
1512 #else /* configUSE_QUEUE_SETS */
\r
1514 /* Tasks that are removed from the event list will get added to
\r
1515 the pending ready list as the scheduler is still suspended. */
\r
1516 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
1518 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1520 /* The task waiting has a higher priority so record that a
\r
1521 context switch is required. */
\r
1522 vTaskMissedYield();
\r
1530 #endif /* configUSE_QUEUE_SETS */
\r
1532 --( pxQueue->xTxLock );
\r
1535 pxQueue->xTxLock = queueUNLOCKED;
\r
1537 taskEXIT_CRITICAL();
\r
1539 /* Do the same for the Rx lock. */
\r
1540 taskENTER_CRITICAL();
\r
1542 while( pxQueue->xRxLock > queueLOCKED_UNMODIFIED )
\r
1544 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
1546 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
1548 vTaskMissedYield();
\r
1551 --( pxQueue->xRxLock );
\r
1559 pxQueue->xRxLock = queueUNLOCKED;
\r
1561 taskEXIT_CRITICAL();
\r
1563 /*-----------------------------------------------------------*/
\r
1565 static signed portBASE_TYPE prvIsQueueEmpty( const xQUEUE *pxQueue )
\r
1567 signed portBASE_TYPE xReturn;
\r
1569 taskENTER_CRITICAL();
\r
1571 if( pxQueue->uxMessagesWaiting == 0 )
\r
1577 xReturn = pdFALSE;
\r
1580 taskEXIT_CRITICAL();
\r
1584 /*-----------------------------------------------------------*/
\r
1586 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle xQueue )
\r
1588 signed portBASE_TYPE xReturn;
\r
1590 configASSERT( xQueue );
\r
1591 if( ( ( xQUEUE * ) xQueue )->uxMessagesWaiting == 0 )
\r
1597 xReturn = pdFALSE;
\r
1602 /*-----------------------------------------------------------*/
\r
1604 static signed portBASE_TYPE prvIsQueueFull( const xQUEUE *pxQueue )
\r
1606 signed portBASE_TYPE xReturn;
\r
1608 taskENTER_CRITICAL();
\r
1610 if( pxQueue->uxMessagesWaiting == pxQueue->uxLength )
\r
1616 xReturn = pdFALSE;
\r
1619 taskEXIT_CRITICAL();
\r
1623 /*-----------------------------------------------------------*/
\r
1625 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle xQueue )
\r
1627 signed portBASE_TYPE xReturn;
\r
1629 configASSERT( xQueue );
\r
1630 if( ( ( xQUEUE * ) xQueue )->uxMessagesWaiting == ( ( xQUEUE * ) xQueue )->uxLength )
\r
1636 xReturn = pdFALSE;
\r
1641 /*-----------------------------------------------------------*/
\r
1643 #if ( configUSE_CO_ROUTINES == 1 )
\r
1645 signed portBASE_TYPE xQueueCRSend( xQueueHandle xQueue, const void *pvItemToQueue, portTickType xTicksToWait )
\r
1647 signed portBASE_TYPE xReturn;
\r
1650 pxQueue = ( xQUEUE * ) xQueue;
\r
1652 /* If the queue is already full we may have to block. A critical section
\r
1653 is required to prevent an interrupt removing something from the queue
\r
1654 between the check to see if the queue is full and blocking on the queue. */
\r
1655 portDISABLE_INTERRUPTS();
\r
1657 if( prvIsQueueFull( pxQueue ) != pdFALSE )
\r
1659 /* The queue is full - do we want to block or just leave without
\r
1661 if( xTicksToWait > ( portTickType ) 0 )
\r
1663 /* As this is called from a coroutine we cannot block directly, but
\r
1664 return indicating that we need to block. */
\r
1665 vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToSend ) );
\r
1666 portENABLE_INTERRUPTS();
\r
1667 return errQUEUE_BLOCKED;
\r
1671 portENABLE_INTERRUPTS();
\r
1672 return errQUEUE_FULL;
\r
1676 portENABLE_INTERRUPTS();
\r
1678 portDISABLE_INTERRUPTS();
\r
1680 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
1682 /* There is room in the queue, copy the data into the queue. */
\r
1683 prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );
\r
1686 /* Were any co-routines waiting for data to become available? */
\r
1687 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
1689 /* In this instance the co-routine could be placed directly
\r
1690 into the ready list as we are within a critical section.
\r
1691 Instead the same pending ready list mechanism is used as if
\r
1692 the event were caused from within an interrupt. */
\r
1693 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1695 /* The co-routine waiting has a higher priority so record
\r
1696 that a yield might be appropriate. */
\r
1697 xReturn = errQUEUE_YIELD;
\r
1703 xReturn = errQUEUE_FULL;
\r
1706 portENABLE_INTERRUPTS();
\r
1711 #endif /* configUSE_CO_ROUTINES */
\r
1712 /*-----------------------------------------------------------*/
\r
1714 #if ( configUSE_CO_ROUTINES == 1 )
\r
1716 signed portBASE_TYPE xQueueCRReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait )
\r
1718 signed portBASE_TYPE xReturn;
\r
1721 pxQueue = ( xQUEUE * ) xQueue;
\r
1723 /* If the queue is already empty we may have to block. A critical section
\r
1724 is required to prevent an interrupt adding something to the queue
\r
1725 between the check to see if the queue is empty and blocking on the queue. */
\r
1726 portDISABLE_INTERRUPTS();
\r
1728 if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )
\r
1730 /* There are no messages in the queue, do we want to block or just
\r
1731 leave with nothing? */
\r
1732 if( xTicksToWait > ( portTickType ) 0 )
\r
1734 /* As this is a co-routine we cannot block directly, but return
\r
1735 indicating that we need to block. */
\r
1736 vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToReceive ) );
\r
1737 portENABLE_INTERRUPTS();
\r
1738 return errQUEUE_BLOCKED;
\r
1742 portENABLE_INTERRUPTS();
\r
1743 return errQUEUE_FULL;
\r
1747 portENABLE_INTERRUPTS();
\r
1749 portDISABLE_INTERRUPTS();
\r
1751 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
1753 /* Data is available from the queue. */
\r
1754 pxQueue->u.pcReadFrom += pxQueue->uxItemSize;
\r
1755 if( pxQueue->u.pcReadFrom >= pxQueue->pcTail )
\r
1757 pxQueue->u.pcReadFrom = pxQueue->pcHead;
\r
1759 --( pxQueue->uxMessagesWaiting );
\r
1760 memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );
\r
1764 /* Were any co-routines waiting for space to become available? */
\r
1765 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
1767 /* In this instance the co-routine could be placed directly
\r
1768 into the ready list as we are within a critical section.
\r
1769 Instead the same pending ready list mechanism is used as if
\r
1770 the event were caused from within an interrupt. */
\r
1771 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
1773 xReturn = errQUEUE_YIELD;
\r
1782 portENABLE_INTERRUPTS();
\r
1787 #endif /* configUSE_CO_ROUTINES */
\r
1788 /*-----------------------------------------------------------*/
\r
1790 #if ( configUSE_CO_ROUTINES == 1 )
\r
1792 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle xQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken )
\r
1796 pxQueue = ( xQUEUE * ) xQueue;
\r
1798 /* Cannot block within an ISR so if there is no space on the queue then
\r
1799 exit without doing anything. */
\r
1800 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
1802 prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );
\r
1804 /* We only want to wake one co-routine per ISR, so check that a
\r
1805 co-routine has not already been woken. */
\r
1806 if( xCoRoutinePreviouslyWoken == pdFALSE )
\r
1808 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
1810 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1818 return xCoRoutinePreviouslyWoken;
\r
1821 #endif /* configUSE_CO_ROUTINES */
\r
1822 /*-----------------------------------------------------------*/
\r
1824 #if ( configUSE_CO_ROUTINES == 1 )
\r
1826 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle xQueue, void *pvBuffer, signed portBASE_TYPE *pxCoRoutineWoken )
\r
1828 signed portBASE_TYPE xReturn;
\r
1831 pxQueue = ( xQUEUE * ) xQueue;
\r
1833 /* We cannot block from an ISR, so check there is data available. If
\r
1834 not then just leave without doing anything. */
\r
1835 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
1837 /* Copy the data from the queue. */
\r
1838 pxQueue->u.pcReadFrom += pxQueue->uxItemSize;
\r
1839 if( pxQueue->u.pcReadFrom >= pxQueue->pcTail )
\r
1841 pxQueue->u.pcReadFrom = pxQueue->pcHead;
\r
1843 --( pxQueue->uxMessagesWaiting );
\r
1844 memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );
\r
1846 if( ( *pxCoRoutineWoken ) == pdFALSE )
\r
1848 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
1850 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
1852 *pxCoRoutineWoken = pdTRUE;
\r
1867 #endif /* configUSE_CO_ROUTINES */
\r
1868 /*-----------------------------------------------------------*/
\r
1870 #if ( configQUEUE_REGISTRY_SIZE > 0 )
\r
1872 void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcQueueName )
\r
1874 unsigned portBASE_TYPE ux;
\r
1876 /* See if there is an empty space in the registry. A NULL name denotes
\r
1878 for( ux = ( unsigned portBASE_TYPE ) 0U; ux < ( unsigned portBASE_TYPE ) configQUEUE_REGISTRY_SIZE; ux++ )
\r
1880 if( xQueueRegistry[ ux ].pcQueueName == NULL )
\r
1882 /* Store the information on this queue. */
\r
1883 xQueueRegistry[ ux ].pcQueueName = pcQueueName;
\r
1884 xQueueRegistry[ ux ].xHandle = xQueue;
\r
1890 #endif /* configQUEUE_REGISTRY_SIZE */
\r
1891 /*-----------------------------------------------------------*/
\r
1893 #if ( configQUEUE_REGISTRY_SIZE > 0 )
\r
1895 void vQueueUnregisterQueue( xQueueHandle xQueue )
\r
1897 unsigned portBASE_TYPE ux;
\r
1899 /* See if the handle of the queue being unregistered in actually in the
\r
1901 for( ux = ( unsigned portBASE_TYPE ) 0U; ux < ( unsigned portBASE_TYPE ) configQUEUE_REGISTRY_SIZE; ux++ )
\r
1903 if( xQueueRegistry[ ux ].xHandle == xQueue )
\r
1905 /* Set the name to NULL to show that this slot if free again. */
\r
1906 xQueueRegistry[ ux ].pcQueueName = NULL;
\r
1913 #endif /* configQUEUE_REGISTRY_SIZE */
\r
1914 /*-----------------------------------------------------------*/
\r
1916 #if ( configUSE_TIMERS == 1 )
\r
1918 void vQueueWaitForMessageRestricted( xQueueHandle xQueue, portTickType xTicksToWait )
\r
1922 pxQueue = ( xQUEUE * ) xQueue;
\r
1924 /* This function should not be called by application code hence the
\r
1925 'Restricted' in its name. It is not part of the public API. It is
\r
1926 designed for use by kernel code, and has special calling requirements.
\r
1927 It can result in vListInsert() being called on a list that can only
\r
1928 possibly ever have one item in it, so the list will be fast, but even
\r
1929 so it should be called with the scheduler locked and not from a critical
\r
1932 /* Only do anything if there are no messages in the queue. This function
\r
1933 will not actually cause the task to block, just place it on a blocked
\r
1934 list. It will not block until the scheduler is unlocked - at which
\r
1935 time a yield will be performed. If an item is added to the queue while
\r
1936 the queue is locked, and the calling task blocks on the queue, then the
\r
1937 calling task will be immediately unblocked when the queue is unlocked. */
\r
1938 prvLockQueue( pxQueue );
\r
1939 if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0U )
\r
1941 /* There is nothing in the queue, block for the specified period. */
\r
1942 vTaskPlaceOnEventListRestricted( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
\r
1944 prvUnlockQueue( pxQueue );
\r
1947 #endif /* configUSE_TIMERS */
\r
1948 /*-----------------------------------------------------------*/
\r
1950 #if ( configUSE_QUEUE_SETS == 1 )
\r
1952 xQueueSetHandle xQueueCreateSet( unsigned portBASE_TYPE uxEventQueueLength )
\r
1954 xQueueSetHandle pxQueue;
\r
1956 pxQueue = xQueueGenericCreate( uxEventQueueLength, sizeof( xQUEUE * ), queueQUEUE_TYPE_SET );
\r
1961 #endif /* configUSE_QUEUE_SETS */
\r
1962 /*-----------------------------------------------------------*/
\r
1964 #if ( configUSE_QUEUE_SETS == 1 )
\r
1966 portBASE_TYPE xQueueAddToSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet )
\r
1968 portBASE_TYPE xReturn;
\r
1970 if( ( ( xQUEUE * ) xQueueOrSemaphore )->pxQueueSetContainer != NULL )
\r
1972 /* Cannot add a queue/semaphore to more than one queue set. */
\r
1975 else if( ( ( xQUEUE * ) xQueueOrSemaphore )->uxMessagesWaiting != 0 )
\r
1977 /* Cannot add a queue/semaphore to a queue set if there are already
\r
1978 items in the queue/semaphore. */
\r
1983 taskENTER_CRITICAL();
\r
1985 ( ( xQUEUE * ) xQueueOrSemaphore )->pxQueueSetContainer = xQueueSet;
\r
1987 taskEXIT_CRITICAL();
\r
1994 #endif /* configUSE_QUEUE_SETS */
\r
1995 /*-----------------------------------------------------------*/
\r
1997 #if ( configUSE_QUEUE_SETS == 1 )
\r
1999 portBASE_TYPE xQueueRemoveFromSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet )
\r
2001 portBASE_TYPE xReturn;
\r
2002 xQUEUE *pxQueueOrSemaphore;
\r
2004 pxQueueOrSemaphore = ( xQUEUE * ) xQueueOrSemaphore;
\r
2006 if( pxQueueOrSemaphore->pxQueueSetContainer != xQueueSet )
\r
2008 /* The queue was not a member of the set. */
\r
2011 else if( pxQueueOrSemaphore->uxMessagesWaiting != 0 )
\r
2013 /* It is dangerous to remove a queue from a set when the queue is
\r
2014 not empty because the queue set will still hold pending events for
\r
2020 taskENTER_CRITICAL();
\r
2022 /* The queue is no longer contained in the set. */
\r
2023 pxQueueOrSemaphore->pxQueueSetContainer = NULL;
\r
2025 taskEXIT_CRITICAL();
\r
2032 #endif /* configUSE_QUEUE_SETS */
\r
2033 /*-----------------------------------------------------------*/
\r
2035 #if ( configUSE_QUEUE_SETS == 1 )
\r
2037 xQueueSetMemberHandle xQueueSelectFromSet( xQueueSetHandle xQueueSet, portTickType xBlockTimeTicks )
\r
2039 xQueueSetMemberHandle xReturn = NULL;
\r
2041 xQueueGenericReceive( ( xQueueHandle ) xQueueSet, &xReturn, xBlockTimeTicks, pdFALSE );
\r
2045 #endif /* configUSE_QUEUE_SETS */
\r
2046 /*-----------------------------------------------------------*/
\r
2048 #if ( configUSE_QUEUE_SETS == 1 )
\r
2050 xQueueSetMemberHandle xQueueSelectFromSetFromISR( xQueueSetHandle xQueueSet )
\r
2052 xQueueSetMemberHandle xReturn = NULL;
\r
2054 xQueueReceiveFromISR( ( xQueueHandle ) xQueueSet, &xReturn, NULL );
\r
2058 #endif /* configUSE_QUEUE_SETS */
\r
2059 /*-----------------------------------------------------------*/
\r
2061 #if ( configUSE_QUEUE_SETS == 1 )
\r
2063 static portBASE_TYPE prvNotifyQueueSetContainer( xQUEUE *pxQueue, portBASE_TYPE xCopyPosition )
\r
2065 xQUEUE *pxQueueSetContainer = pxQueue->pxQueueSetContainer;
\r
2066 portBASE_TYPE xReturn = pdFALSE;
\r
2068 configASSERT( pxQueueSetContainer );
\r
2069 configASSERT( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength );
\r
2071 if( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength )
\r
2073 traceQUEUE_SEND( pxQueueSetContainer );
\r
2074 /* The data copies is the handle of the queue that contains data. */
\r
2075 prvCopyDataToQueue( pxQueueSetContainer, &pxQueue, xCopyPosition );
\r
2076 if( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE )
\r
2078 if( xTaskRemoveFromEventList( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) != pdFALSE )
\r
2080 /* The task waiting has a higher priority */
\r
2089 #endif /* configUSE_QUEUE_SETS */
\r