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 /* Lint e961 and e750 are suppressed as a MISRA exception justified because the
\r
92 MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the
\r
93 header files above, but not in this file, in order to generate the correct
\r
94 privileged Vs unprivileged linkage and placement. */
\r
95 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */
\r
98 /* Constants used with the cRxLock and xTxLock structure members. */
\r
99 #define queueUNLOCKED ( ( signed portBASE_TYPE ) -1 )
\r
100 #define queueLOCKED_UNMODIFIED ( ( signed portBASE_TYPE ) 0 )
\r
102 /* When the xQUEUE structure is used to represent a base queue its pcHead and
\r
103 pcTail members are used as pointers into the queue storage area. When the
\r
104 xQUEUE structure is used to represent a mutex pcHead and pcTail pointers are
\r
105 not necessary, and the pcHead pointer is set to NULL to indicate that the
\r
106 pcTail pointer actually points to the mutex holder (if any). Map alternative
\r
107 names to the pcHead and pcTail structure members to ensure the readability of
\r
108 the code is maintained despite this dual use of two structure members. An
\r
109 alternative implementation would be to use a union, but use of a union is
\r
110 against the coding standard (although an exception to the standard has been
\r
111 permitted where the dual use also significantly changes the type of the
\r
112 structure member). */
\r
113 #define pxMutexHolder pcTail
\r
114 #define uxQueueType pcHead
\r
115 #define queueQUEUE_IS_MUTEX NULL
\r
117 /* Semaphores do not actually store or copy data, so have an item size of
\r
119 #define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( unsigned portBASE_TYPE ) 0 )
\r
120 #define queueMUTEX_GIVE_BLOCK_TIME ( ( portTickType ) 0U )
\r
124 * Definition of the queue used by the scheduler.
\r
125 * Items are queued by copy, not reference.
\r
127 typedef struct QueueDefinition
\r
129 signed char *pcHead; /*< Points to the beginning of the queue storage area. */
\r
130 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
132 signed char *pcWriteTo; /*< Points to the free next place in the storage area. */
\r
134 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
136 signed char *pcReadFrom; /*< Points to the last place that a queued item was read from when the structure is used as a queue. */
\r
137 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
140 xList xTasksWaitingToSend; /*< List of tasks that are blocked waiting to post onto this queue. Stored in priority order. */
\r
141 xList xTasksWaitingToReceive; /*< List of tasks that are blocked waiting to read from this queue. Stored in priority order. */
\r
143 volatile unsigned portBASE_TYPE uxMessagesWaiting;/*< The number of items currently in the queue. */
\r
144 unsigned portBASE_TYPE uxLength; /*< The length of the queue defined as the number of items it will hold, not the number of bytes. */
\r
145 unsigned portBASE_TYPE uxItemSize; /*< The size of each items that the queue will hold. */
\r
147 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
148 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
150 #if ( configUSE_TRACE_FACILITY == 1 )
\r
151 unsigned char ucQueueNumber;
\r
152 unsigned char ucQueueType;
\r
155 #if ( configUSE_QUEUE_SETS == 1 )
\r
156 struct QueueDefinition *pxQueueSetContainer;
\r
160 /*-----------------------------------------------------------*/
\r
163 * The queue registry is just a means for kernel aware debuggers to locate
\r
164 * queue structures. It has no other purpose so is an optional component.
\r
166 #if ( configQUEUE_REGISTRY_SIZE > 0 )
\r
168 /* The type stored within the queue registry array. This allows a name
\r
169 to be assigned to each queue making kernel aware debugging a little
\r
170 more user friendly. */
\r
171 typedef struct QUEUE_REGISTRY_ITEM
\r
173 signed char *pcQueueName;
\r
174 xQueueHandle xHandle;
\r
175 } xQueueRegistryItem;
\r
177 /* The queue registry is simply an array of xQueueRegistryItem structures.
\r
178 The pcQueueName member of a structure being NULL is indicative of the
\r
179 array position being vacant. */
\r
180 xQueueRegistryItem xQueueRegistry[ configQUEUE_REGISTRY_SIZE ];
\r
182 #endif /* configQUEUE_REGISTRY_SIZE */
\r
185 * Unlocks a queue locked by a call to prvLockQueue. Locking a queue does not
\r
186 * prevent an ISR from adding or removing items to the queue, but does prevent
\r
187 * an ISR from removing tasks from the queue event lists. If an ISR finds a
\r
188 * queue is locked it will instead increment the appropriate queue lock count
\r
189 * to indicate that a task may require unblocking. When the queue in unlocked
\r
190 * these lock counts are inspected, and the appropriate action taken.
\r
192 static void prvUnlockQueue( xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;
\r
195 * Uses a critical section to determine if there is any data in a queue.
\r
197 * @return pdTRUE if the queue contains no items, otherwise pdFALSE.
\r
199 static signed portBASE_TYPE prvIsQueueEmpty( const xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;
\r
202 * Uses a critical section to determine if there is any space in a queue.
\r
204 * @return pdTRUE if there is no space, otherwise pdFALSE;
\r
206 static signed portBASE_TYPE prvIsQueueFull( const xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;
\r
209 * Copies an item into the queue, either at the front of the queue or the
\r
210 * back of the queue.
\r
212 static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition ) PRIVILEGED_FUNCTION;
\r
215 * Copies an item out of a queue.
\r
217 static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void * const pvBuffer ) PRIVILEGED_FUNCTION;
\r
219 #if ( configUSE_QUEUE_SETS == 1 )
\r
221 * Checks to see if a queue is a member of a queue set, and if so, notifies
\r
222 * the queue set that the queue contains data.
\r
224 static portBASE_TYPE prvNotifyQueueSetContainer( const xQUEUE * const pxQueue, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;
\r
227 /*-----------------------------------------------------------*/
\r
230 * Macro to mark a queue as locked. Locking a queue prevents an ISR from
\r
231 * accessing the queue event lists.
\r
233 #define prvLockQueue( pxQueue ) \
\r
234 taskENTER_CRITICAL(); \
\r
236 if( ( pxQueue )->xRxLock == queueUNLOCKED ) \
\r
238 ( pxQueue )->xRxLock = queueLOCKED_UNMODIFIED; \
\r
240 if( ( pxQueue )->xTxLock == queueUNLOCKED ) \
\r
242 ( pxQueue )->xTxLock = queueLOCKED_UNMODIFIED; \
\r
245 taskEXIT_CRITICAL()
\r
246 /*-----------------------------------------------------------*/
\r
248 portBASE_TYPE xQueueGenericReset( xQueueHandle xQueue, portBASE_TYPE xNewQueue )
\r
250 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
\r
252 configASSERT( pxQueue );
\r
254 taskENTER_CRITICAL();
\r
256 pxQueue->pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize );
\r
257 pxQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U;
\r
258 pxQueue->pcWriteTo = pxQueue->pcHead;
\r
259 pxQueue->u.pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - ( unsigned portBASE_TYPE ) 1U ) * pxQueue->uxItemSize );
\r
260 pxQueue->xRxLock = queueUNLOCKED;
\r
261 pxQueue->xTxLock = queueUNLOCKED;
\r
263 if( xNewQueue == pdFALSE )
\r
265 /* If there are tasks blocked waiting to read from the queue, then
\r
266 the tasks will remain blocked as after this function exits the queue
\r
267 will still be empty. If there are tasks blocked waiting to write to
\r
268 the queue, then one should be unblocked as after this function exits
\r
269 it will be possible to write to it. */
\r
270 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
272 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )
\r
274 portYIELD_WITHIN_API();
\r
280 /* Ensure the event queues start in the correct state. */
\r
281 vListInitialise( &( pxQueue->xTasksWaitingToSend ) );
\r
282 vListInitialise( &( pxQueue->xTasksWaitingToReceive ) );
\r
285 taskEXIT_CRITICAL();
\r
287 /* A value is returned for calling semantic consistency with previous
\r
291 /*-----------------------------------------------------------*/
\r
293 xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType )
\r
295 xQUEUE *pxNewQueue;
\r
296 size_t xQueueSizeInBytes;
\r
297 xQueueHandle xReturn = NULL;
\r
299 /* Remove compiler warnings about unused parameters should
\r
300 configUSE_TRACE_FACILITY not be set to 1. */
\r
301 ( void ) ucQueueType;
\r
303 /* Allocate the new queue structure. */
\r
304 if( uxQueueLength > ( unsigned portBASE_TYPE ) 0 )
\r
306 pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );
\r
307 if( pxNewQueue != NULL )
\r
309 /* Create the list of pointers to queue items. The queue is one byte
\r
310 longer than asked for to make wrap checking easier/faster. */
\r
311 xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ) + ( size_t ) 1; /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
\r
313 pxNewQueue->pcHead = ( signed char * ) pvPortMalloc( xQueueSizeInBytes );
\r
314 if( pxNewQueue->pcHead != NULL )
\r
316 /* Initialise the queue members as described above where the
\r
317 queue type is defined. */
\r
318 pxNewQueue->uxLength = uxQueueLength;
\r
319 pxNewQueue->uxItemSize = uxItemSize;
\r
320 ( void ) xQueueGenericReset( pxNewQueue, pdTRUE );
\r
322 #if ( configUSE_TRACE_FACILITY == 1 )
\r
324 pxNewQueue->ucQueueType = ucQueueType;
\r
326 #endif /* configUSE_TRACE_FACILITY */
\r
328 #if( configUSE_QUEUE_SETS == 1 )
\r
330 pxNewQueue->pxQueueSetContainer = NULL;
\r
332 #endif /* configUSE_QUEUE_SETS */
\r
334 traceQUEUE_CREATE( pxNewQueue );
\r
335 xReturn = pxNewQueue;
\r
339 traceQUEUE_CREATE_FAILED( ucQueueType );
\r
340 vPortFree( pxNewQueue );
\r
345 configASSERT( xReturn );
\r
349 /*-----------------------------------------------------------*/
\r
351 #if ( configUSE_MUTEXES == 1 )
\r
353 xQueueHandle xQueueCreateMutex( unsigned char ucQueueType )
\r
355 xQUEUE *pxNewQueue;
\r
357 /* Prevent compiler warnings about unused parameters if
\r
358 configUSE_TRACE_FACILITY does not equal 1. */
\r
359 ( void ) ucQueueType;
\r
361 /* Allocate the new queue structure. */
\r
362 pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );
\r
363 if( pxNewQueue != NULL )
\r
365 /* Information required for priority inheritance. */
\r
366 pxNewQueue->pxMutexHolder = NULL;
\r
367 pxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX;
\r
369 /* Queues used as a mutex no data is actually copied into or out
\r
371 pxNewQueue->pcWriteTo = NULL;
\r
372 pxNewQueue->u.pcReadFrom = NULL;
\r
374 /* Each mutex has a length of 1 (like a binary semaphore) and
\r
375 an item size of 0 as nothing is actually copied into or out
\r
377 pxNewQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U;
\r
378 pxNewQueue->uxLength = ( unsigned portBASE_TYPE ) 1U;
\r
379 pxNewQueue->uxItemSize = ( unsigned portBASE_TYPE ) 0U;
\r
380 pxNewQueue->xRxLock = queueUNLOCKED;
\r
381 pxNewQueue->xTxLock = queueUNLOCKED;
\r
383 #if ( configUSE_TRACE_FACILITY == 1 )
\r
385 pxNewQueue->ucQueueType = ucQueueType;
\r
389 #if ( configUSE_QUEUE_SETS == 1 )
\r
391 pxNewQueue->pxQueueSetContainer = NULL;
\r
395 /* Ensure the event queues start with the correct state. */
\r
396 vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) );
\r
397 vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );
\r
399 traceCREATE_MUTEX( pxNewQueue );
\r
401 /* Start with the semaphore in the expected state. */
\r
402 ( void ) xQueueGenericSend( pxNewQueue, NULL, ( portTickType ) 0U, queueSEND_TO_BACK );
\r
406 traceCREATE_MUTEX_FAILED();
\r
409 configASSERT( pxNewQueue );
\r
413 #endif /* configUSE_MUTEXES */
\r
414 /*-----------------------------------------------------------*/
\r
416 #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
\r
418 void* xQueueGetMutexHolder( xQueueHandle xSemaphore )
\r
422 /* This function is called by xSemaphoreGetMutexHolder(), and should not
\r
423 be called directly. Note: This is is a good way of determining if the
\r
424 calling task is the mutex holder, but not a good way of determining the
\r
425 identity of the mutex holder, as the holder may change between the
\r
426 following critical section exiting and the function returning. */
\r
427 taskENTER_CRITICAL();
\r
429 if( ( ( xQUEUE * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX )
\r
431 pxReturn = ( void * ) ( ( xQUEUE * ) xSemaphore )->pxMutexHolder;
\r
438 taskEXIT_CRITICAL();
\r
444 /*-----------------------------------------------------------*/
\r
446 #if ( configUSE_RECURSIVE_MUTEXES == 1 )
\r
448 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex )
\r
450 portBASE_TYPE xReturn;
\r
451 xQUEUE * const 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() ) /*lint !e961 Not a redundant cast as xTaskHandle is a typedef. */
\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 == ( unsigned portBASE_TYPE ) 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 ( void ) 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
501 xQUEUE * const pxMutex = ( xQUEUE * ) xMutex;
\r
503 configASSERT( pxMutex );
\r
505 /* Comments regarding mutual exclusion as per those within
\r
506 xQueueGiveMutexRecursive(). */
\r
508 traceTAKE_MUTEX_RECURSIVE( pxMutex );
\r
510 if( pxMutex->pxMutexHolder == ( void * ) xTaskGetCurrentTaskHandle() ) /*lint !e961 Cast is not redundant as xTaskHandle is a typedef. */
\r
512 ( pxMutex->u.uxRecursiveCallCount )++;
\r
517 xReturn = xQueueGenericReceive( pxMutex, NULL, xBlockTime, pdFALSE );
\r
519 /* pdPASS will only be returned if we successfully obtained the mutex,
\r
520 we may have blocked to reach here. */
\r
521 if( xReturn == pdPASS )
\r
523 ( pxMutex->u.uxRecursiveCallCount )++;
\r
527 traceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex );
\r
534 #endif /* configUSE_RECURSIVE_MUTEXES */
\r
535 /*-----------------------------------------------------------*/
\r
537 #if ( configUSE_COUNTING_SEMAPHORES == 1 )
\r
539 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount )
\r
541 xQueueHandle xHandle;
\r
543 xHandle = xQueueGenericCreate( uxCountValue, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE );
\r
545 if( xHandle != NULL )
\r
547 ( ( xQUEUE * ) xHandle )->uxMessagesWaiting = uxInitialCount;
\r
549 traceCREATE_COUNTING_SEMAPHORE();
\r
553 traceCREATE_COUNTING_SEMAPHORE_FAILED();
\r
556 configASSERT( xHandle );
\r
560 #endif /* configUSE_COUNTING_SEMAPHORES */
\r
561 /*-----------------------------------------------------------*/
\r
563 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )
\r
565 signed portBASE_TYPE xEntryTimeSet = pdFALSE;
\r
566 xTimeOutType xTimeOut;
\r
567 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
\r
569 configASSERT( pxQueue );
\r
570 configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );
\r
571 configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
\r
573 /* This function relaxes the coding standard somewhat to allow return
\r
574 statements within the function itself. This is done in the interest
\r
575 of execution time efficiency. */
\r
578 taskENTER_CRITICAL();
\r
580 /* Is there room on the queue now? The running task must be
\r
581 the highest priority task wanting to access the queue. If
\r
582 the head item in the queue is to be overwritten then it does
\r
583 not matter if the queue is full. */
\r
584 if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
\r
586 traceQUEUE_SEND( pxQueue );
\r
587 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
\r
589 #if ( configUSE_QUEUE_SETS == 1 )
\r
591 if( pxQueue->pxQueueSetContainer != NULL )
\r
593 if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE )
\r
595 /* The queue is a member of a queue set, and posting
\r
596 to the queue set caused a higher priority task to
\r
597 unblock. A context switch is required. */
\r
598 portYIELD_WITHIN_API();
\r
603 /* If there was a task waiting for data to arrive on the
\r
604 queue then unblock it now. */
\r
605 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
607 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )
\r
609 /* The unblocked task has a priority higher than
\r
610 our own so yield immediately. Yes it is ok to
\r
611 do this from within the critical section - the
\r
612 kernel takes care of that. */
\r
613 portYIELD_WITHIN_API();
\r
618 #else /* configUSE_QUEUE_SETS */
\r
620 /* If there was a task waiting for data to arrive on the
\r
621 queue then unblock it now. */
\r
622 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
624 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )
\r
626 /* The unblocked task has a priority higher than
\r
627 our own so yield immediately. Yes it is ok to do
\r
628 this from within the critical section - the kernel
\r
629 takes care of that. */
\r
630 portYIELD_WITHIN_API();
\r
634 #endif /* configUSE_QUEUE_SETS */
\r
636 taskEXIT_CRITICAL();
\r
638 /* Return to the original privilege level before exiting the
\r
644 if( xTicksToWait == ( portTickType ) 0 )
\r
646 /* The queue was full and no block time is specified (or
\r
647 the block time has expired) so leave now. */
\r
648 taskEXIT_CRITICAL();
\r
650 /* Return to the original privilege level before exiting
\r
652 traceQUEUE_SEND_FAILED( pxQueue );
\r
653 return errQUEUE_FULL;
\r
655 else if( xEntryTimeSet == pdFALSE )
\r
657 /* The queue was full and a block time was specified so
\r
658 configure the timeout structure. */
\r
659 vTaskSetTimeOutState( &xTimeOut );
\r
660 xEntryTimeSet = pdTRUE;
\r
664 /* Entry time was already set. */
\r
668 taskEXIT_CRITICAL();
\r
670 /* Interrupts and other tasks can send to and receive from the queue
\r
671 now the critical section has been exited. */
\r
674 prvLockQueue( pxQueue );
\r
676 /* Update the timeout state to see if it has expired yet. */
\r
677 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
679 if( prvIsQueueFull( pxQueue ) != pdFALSE )
\r
681 traceBLOCKING_ON_QUEUE_SEND( pxQueue );
\r
682 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );
\r
684 /* Unlocking the queue means queue events can effect the
\r
685 event list. It is possible that interrupts occurring now
\r
686 remove this task from the event list again - but as the
\r
687 scheduler is suspended the task will go onto the pending
\r
688 ready last instead of the actual ready list. */
\r
689 prvUnlockQueue( pxQueue );
\r
691 /* Resuming the scheduler will move tasks from the pending
\r
692 ready list into the ready list - so it is feasible that this
\r
693 task is already in a ready list before it yields - in which
\r
694 case the yield will not cause a context switch unless there
\r
695 is also a higher priority task in the pending ready list. */
\r
696 if( xTaskResumeAll() == pdFALSE )
\r
698 portYIELD_WITHIN_API();
\r
704 prvUnlockQueue( pxQueue );
\r
705 ( void ) xTaskResumeAll();
\r
710 /* The timeout has expired. */
\r
711 prvUnlockQueue( pxQueue );
\r
712 ( void ) xTaskResumeAll();
\r
714 /* Return to the original privilege level before exiting the
\r
716 traceQUEUE_SEND_FAILED( pxQueue );
\r
717 return errQUEUE_FULL;
\r
721 /*-----------------------------------------------------------*/
\r
723 #if ( configUSE_ALTERNATIVE_API == 1 )
\r
725 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )
\r
727 signed portBASE_TYPE xEntryTimeSet = pdFALSE;
\r
728 xTimeOutType xTimeOut;
\r
729 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
\r
731 configASSERT( pxQueue );
\r
732 configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );
\r
736 taskENTER_CRITICAL();
\r
738 /* Is there room on the queue now? To be running we must be
\r
739 the highest priority task wanting to access the queue. */
\r
740 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
742 traceQUEUE_SEND( pxQueue );
\r
743 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
\r
745 /* If there was a task waiting for data to arrive on the
\r
746 queue then unblock it now. */
\r
747 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
749 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )
\r
751 /* The unblocked task has a priority higher than
\r
752 our own so yield immediately. */
\r
753 portYIELD_WITHIN_API();
\r
757 taskEXIT_CRITICAL();
\r
762 if( xTicksToWait == ( portTickType ) 0 )
\r
764 taskEXIT_CRITICAL();
\r
765 return errQUEUE_FULL;
\r
767 else if( xEntryTimeSet == pdFALSE )
\r
769 vTaskSetTimeOutState( &xTimeOut );
\r
770 xEntryTimeSet = pdTRUE;
\r
774 taskEXIT_CRITICAL();
\r
776 taskENTER_CRITICAL();
\r
778 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
780 if( prvIsQueueFull( pxQueue ) != pdFALSE )
\r
782 traceBLOCKING_ON_QUEUE_SEND( pxQueue );
\r
783 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );
\r
784 portYIELD_WITHIN_API();
\r
789 taskEXIT_CRITICAL();
\r
790 traceQUEUE_SEND_FAILED( pxQueue );
\r
791 return errQUEUE_FULL;
\r
794 taskEXIT_CRITICAL();
\r
798 #endif /* configUSE_ALTERNATIVE_API */
\r
799 /*-----------------------------------------------------------*/
\r
801 #if ( configUSE_ALTERNATIVE_API == 1 )
\r
803 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )
\r
805 signed portBASE_TYPE xEntryTimeSet = pdFALSE;
\r
806 xTimeOutType xTimeOut;
\r
807 signed char *pcOriginalReadPosition;
\r
808 xQUEUE * const 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 /* Data is actually being removed (not just peeked). */
\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
937 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
\r
939 configASSERT( pxQueue );
\r
940 configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );
\r
941 configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
\r
943 /* RTOS ports that support interrupt nesting have the concept of a maximum
\r
944 system call (or maximum API call) interrupt priority. Interrupts that are
\r
945 above the maximum system call priority are keep permanently enabled, even
\r
946 when the RTOS kernel is in a critical section, but cannot make any calls to
\r
947 FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
\r
948 then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
\r
949 failure if a FreeRTOS API function is called from an interrupt that has been
\r
950 assigned a priority above the configured maximum system call priority.
\r
951 Only FreeRTOS functions that end in FromISR can be called from interrupts
\r
952 that have been assigned a priority at or (logically) below the maximum
\r
953 system call interrupt priority. FreeRTOS maintains a separate interrupt
\r
954 safe API to ensure interrupt entry is as fast and as simple as possible.
\r
955 More information (albeit Cortex-M specific) is provided on the following
\r
956 link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */
\r
957 portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
\r
959 /* Similar to xQueueGenericSend, except we don't block if there is no room
\r
960 in the queue. Also we don't directly wake a task that was blocked on a
\r
961 queue read, instead we return a flag to say whether a context switch is
\r
962 required or not (i.e. has a task with a higher priority than us been woken
\r
964 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
\r
966 if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )
\r
968 traceQUEUE_SEND_FROM_ISR( pxQueue );
\r
970 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
\r
972 /* If the queue is locked we do not alter the event list. This will
\r
973 be done when the queue is unlocked later. */
\r
974 if( pxQueue->xTxLock == queueUNLOCKED )
\r
976 #if ( configUSE_QUEUE_SETS == 1 )
\r
978 if( pxQueue->pxQueueSetContainer != NULL )
\r
980 if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE )
\r
982 /* The queue is a member of a queue set, and posting
\r
983 to the queue set caused a higher priority task to
\r
984 unblock. A context switch is required. */
\r
985 if( pxHigherPriorityTaskWoken != NULL )
\r
987 *pxHigherPriorityTaskWoken = pdTRUE;
\r
993 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
995 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
997 /* The task waiting has a higher priority so record that a
\r
998 context switch is required. */
\r
999 if( pxHigherPriorityTaskWoken != NULL )
\r
1001 *pxHigherPriorityTaskWoken = pdTRUE;
\r
1007 #else /* configUSE_QUEUE_SETS */
\r
1009 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
1011 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1013 /* The task waiting has a higher priority so record that a
\r
1014 context switch is required. */
\r
1015 if( pxHigherPriorityTaskWoken != NULL )
\r
1017 *pxHigherPriorityTaskWoken = pdTRUE;
\r
1022 #endif /* configUSE_QUEUE_SETS */
\r
1026 /* Increment the lock count so the task that unlocks the queue
\r
1027 knows that data was posted while it was locked. */
\r
1028 ++( pxQueue->xTxLock );
\r
1035 traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );
\r
1036 xReturn = errQUEUE_FULL;
\r
1039 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
\r
1043 /*-----------------------------------------------------------*/
\r
1045 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )
\r
1047 signed portBASE_TYPE xEntryTimeSet = pdFALSE;
\r
1048 xTimeOutType xTimeOut;
\r
1049 signed char *pcOriginalReadPosition;
\r
1050 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
\r
1052 configASSERT( pxQueue );
\r
1053 configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );
\r
1055 /* This function relaxes the coding standard somewhat to allow return
\r
1056 statements within the function itself. This is done in the interest
\r
1057 of execution time efficiency. */
\r
1061 taskENTER_CRITICAL();
\r
1063 /* Is there data in the queue now? To be running we must be
\r
1064 the highest priority task wanting to access the queue. */
\r
1065 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
1067 /* Remember the read position in case the queue is only being
\r
1069 pcOriginalReadPosition = pxQueue->u.pcReadFrom;
\r
1071 prvCopyDataFromQueue( pxQueue, pvBuffer );
\r
1073 if( xJustPeeking == pdFALSE )
\r
1075 traceQUEUE_RECEIVE( pxQueue );
\r
1077 /* Actually removing data, not just peeking. */
\r
1078 --( pxQueue->uxMessagesWaiting );
\r
1080 #if ( configUSE_MUTEXES == 1 )
\r
1082 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
1084 /* Record the information required to implement
\r
1085 priority inheritance should it become necessary. */
\r
1086 pxQueue->pxMutexHolder = ( void * ) xTaskGetCurrentTaskHandle(); /*lint !e961 Cast is not redundant as xTaskHandle is a typedef. */
\r
1091 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
1093 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )
\r
1095 portYIELD_WITHIN_API();
\r
1101 traceQUEUE_PEEK( pxQueue );
\r
1103 /* The data is not being removed, so reset the read
\r
1105 pxQueue->u.pcReadFrom = pcOriginalReadPosition;
\r
1107 /* The data is being left in the queue, so see if there are
\r
1108 any other tasks waiting for the data. */
\r
1109 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
1111 /* Tasks that are removed from the event list will get added to
\r
1112 the pending ready list as the scheduler is still suspended. */
\r
1113 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1115 /* The task waiting has a higher priority than this task. */
\r
1116 portYIELD_WITHIN_API();
\r
1121 taskEXIT_CRITICAL();
\r
1126 if( xTicksToWait == ( portTickType ) 0 )
\r
1128 /* The queue was empty and no block time is specified (or
\r
1129 the block time has expired) so leave now. */
\r
1130 taskEXIT_CRITICAL();
\r
1131 traceQUEUE_RECEIVE_FAILED( pxQueue );
\r
1132 return errQUEUE_EMPTY;
\r
1134 else if( xEntryTimeSet == pdFALSE )
\r
1136 /* The queue was empty and a block time was specified so
\r
1137 configure the timeout structure. */
\r
1138 vTaskSetTimeOutState( &xTimeOut );
\r
1139 xEntryTimeSet = pdTRUE;
\r
1143 /* Entry time was already set. */
\r
1147 taskEXIT_CRITICAL();
\r
1149 /* Interrupts and other tasks can send to and receive from the queue
\r
1150 now the critical section has been exited. */
\r
1152 vTaskSuspendAll();
\r
1153 prvLockQueue( pxQueue );
\r
1155 /* Update the timeout state to see if it has expired yet. */
\r
1156 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )
\r
1158 if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
\r
1160 traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );
\r
1162 #if ( configUSE_MUTEXES == 1 )
\r
1164 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
1166 portENTER_CRITICAL();
\r
1168 vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );
\r
1170 portEXIT_CRITICAL();
\r
1175 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
\r
1176 prvUnlockQueue( pxQueue );
\r
1177 if( xTaskResumeAll() == pdFALSE )
\r
1179 portYIELD_WITHIN_API();
\r
1185 prvUnlockQueue( pxQueue );
\r
1186 ( void ) xTaskResumeAll();
\r
1191 prvUnlockQueue( pxQueue );
\r
1192 ( void ) xTaskResumeAll();
\r
1193 traceQUEUE_RECEIVE_FAILED( pxQueue );
\r
1194 return errQUEUE_EMPTY;
\r
1198 /*-----------------------------------------------------------*/
\r
1200 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, const void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken )
\r
1202 signed portBASE_TYPE xReturn;
\r
1203 unsigned portBASE_TYPE uxSavedInterruptStatus;
\r
1204 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
\r
1206 configASSERT( pxQueue );
\r
1207 configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );
\r
1209 /* RTOS ports that support interrupt nesting have the concept of a maximum
\r
1210 system call (or maximum API call) interrupt priority. Interrupts that are
\r
1211 above the maximum system call priority are keep permanently enabled, even
\r
1212 when the RTOS kernel is in a critical section, but cannot make any calls to
\r
1213 FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h
\r
1214 then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion
\r
1215 failure if a FreeRTOS API function is called from an interrupt that has been
\r
1216 assigned a priority above the configured maximum system call priority.
\r
1217 Only FreeRTOS functions that end in FromISR can be called from interrupts
\r
1218 that have been assigned a priority at or (logically) below the maximum
\r
1219 system call interrupt priority. FreeRTOS maintains a separate interrupt
\r
1220 safe API to ensure interrupt entry is as fast and as simple as possible.
\r
1221 More information (albeit Cortex-M specific) is provided on the following
\r
1222 link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */
\r
1223 portASSERT_IF_INTERRUPT_PRIORITY_INVALID();
\r
1225 uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
\r
1227 /* Cannot block in an ISR, so check there is data available. */
\r
1228 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
1230 traceQUEUE_RECEIVE_FROM_ISR( pxQueue );
\r
1232 prvCopyDataFromQueue( pxQueue, pvBuffer );
\r
1233 --( pxQueue->uxMessagesWaiting );
\r
1235 /* If the queue is locked the event list will not be modified.
\r
1236 Instead update the lock count so the task that unlocks the queue
\r
1237 will know that an ISR has removed data while the queue was
\r
1239 if( pxQueue->xRxLock == queueUNLOCKED )
\r
1241 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
1243 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
1245 /* The task waiting has a higher priority than us so
\r
1246 force a context switch. */
\r
1247 if( pxHigherPriorityTaskWoken != NULL )
\r
1249 *pxHigherPriorityTaskWoken = pdTRUE;
\r
1256 /* Increment the lock count so the task that unlocks the queue
\r
1257 knows that data was removed while it was locked. */
\r
1258 ++( pxQueue->xRxLock );
\r
1266 traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue );
\r
1269 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
\r
1273 /*-----------------------------------------------------------*/
\r
1275 signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, const void * const pvBuffer )
\r
1277 signed portBASE_TYPE xReturn;
\r
1278 unsigned portBASE_TYPE uxSavedInterruptStatus;
\r
1279 signed char *pcOriginalReadPosition;
\r
1280 xQUEUE * const 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
1339 } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */
\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
1351 } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */
\r
1352 /*-----------------------------------------------------------*/
\r
1354 void vQueueDelete( xQueueHandle xQueue )
\r
1356 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
\r
1358 configASSERT( pxQueue );
\r
1360 traceQUEUE_DELETE( pxQueue );
\r
1361 #if ( configQUEUE_REGISTRY_SIZE > 0 )
\r
1363 vQueueUnregisterQueue( pxQueue );
\r
1366 vPortFree( pxQueue->pcHead );
\r
1367 vPortFree( pxQueue );
\r
1369 /*-----------------------------------------------------------*/
\r
1371 #if ( configUSE_TRACE_FACILITY == 1 )
\r
1373 unsigned char ucQueueGetQueueNumber( xQueueHandle xQueue )
\r
1375 return ( ( xQUEUE * ) xQueue )->ucQueueNumber;
\r
1378 #endif /* configUSE_TRACE_FACILITY */
\r
1379 /*-----------------------------------------------------------*/
\r
1381 #if ( configUSE_TRACE_FACILITY == 1 )
\r
1383 void vQueueSetQueueNumber( xQueueHandle xQueue, unsigned char ucQueueNumber )
\r
1385 ( ( xQUEUE * ) xQueue )->ucQueueNumber = ucQueueNumber;
\r
1388 #endif /* configUSE_TRACE_FACILITY */
\r
1389 /*-----------------------------------------------------------*/
\r
1391 #if ( configUSE_TRACE_FACILITY == 1 )
\r
1393 unsigned char ucQueueGetQueueType( xQueueHandle xQueue )
\r
1395 return ( ( xQUEUE * ) xQueue )->ucQueueType;
\r
1398 #endif /* configUSE_TRACE_FACILITY */
\r
1399 /*-----------------------------------------------------------*/
\r
1401 static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition )
\r
1403 if( pxQueue->uxItemSize == ( unsigned portBASE_TYPE ) 0 )
\r
1405 #if ( configUSE_MUTEXES == 1 )
\r
1407 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )
\r
1409 /* The mutex is no longer being held. */
\r
1410 vTaskPriorityDisinherit( ( void * ) pxQueue->pxMutexHolder );
\r
1411 pxQueue->pxMutexHolder = NULL;
\r
1414 #endif /* configUSE_MUTEXES */
\r
1416 else if( xPosition == queueSEND_TO_BACK )
\r
1418 ( void ) memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 MISRA exception as the casts are only redundant for some ports, plus previous logic ensures a null pointer can only be passed to memcpy() if the copy size is 0. */
\r
1419 pxQueue->pcWriteTo += pxQueue->uxItemSize;
\r
1420 if( pxQueue->pcWriteTo >= pxQueue->pcTail ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */
\r
1422 pxQueue->pcWriteTo = pxQueue->pcHead;
\r
1427 ( void ) memcpy( ( void * ) pxQueue->u.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
\r
1428 pxQueue->u.pcReadFrom -= pxQueue->uxItemSize;
\r
1429 if( pxQueue->u.pcReadFrom < pxQueue->pcHead ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */
\r
1431 pxQueue->u.pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );
\r
1434 if( xPosition == queueOVERWRITE )
\r
1436 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
1438 /* An item is not being added but overwritten, so subtract
\r
1439 one from the recorded number of items in the queue so when
\r
1440 one is added again below the number of recorded items remains
\r
1442 --( pxQueue->uxMessagesWaiting );
\r
1447 ++( pxQueue->uxMessagesWaiting );
\r
1449 /*-----------------------------------------------------------*/
\r
1451 static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void * const pvBuffer )
\r
1453 if( pxQueue->uxQueueType != queueQUEUE_IS_MUTEX )
\r
1455 pxQueue->u.pcReadFrom += pxQueue->uxItemSize;
\r
1456 if( pxQueue->u.pcReadFrom >= pxQueue->pcTail ) /*lint !e946 MISRA exception justified as use of the relational operator is the cleanest solutions. */
\r
1458 pxQueue->u.pcReadFrom = pxQueue->pcHead;
\r
1460 ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 MISRA exception as the casts are only redundant for some ports. Also previous logic ensures a null pointer can only be passed to memcpy() when the count is 0. */
\r
1463 /*-----------------------------------------------------------*/
\r
1465 static void prvUnlockQueue( xQUEUE *pxQueue )
\r
1467 /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */
\r
1469 /* The lock counts contains the number of extra data items placed or
\r
1470 removed from the queue while the queue was locked. When a queue is
\r
1471 locked items can be added or removed, but the event lists cannot be
\r
1473 taskENTER_CRITICAL();
\r
1475 /* See if data was added to the queue while it was locked. */
\r
1476 while( pxQueue->xTxLock > queueLOCKED_UNMODIFIED )
\r
1478 /* Data was posted while the queue was locked. Are any tasks
\r
1479 blocked waiting for data to become available? */
\r
1480 #if ( configUSE_QUEUE_SETS == 1 )
\r
1482 if( pxQueue->pxQueueSetContainer != NULL )
\r
1484 if( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) == pdTRUE )
\r
1486 /* The queue is a member of a queue set, and posting to
\r
1487 the queue set caused a higher priority task to unblock.
\r
1488 A context switch is required. */
\r
1489 vTaskMissedYield();
\r
1494 /* Tasks that are removed from the event list will get added to
\r
1495 the pending ready list as the scheduler is still suspended. */
\r
1496 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
1498 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1500 /* The task waiting has a higher priority so record that a
\r
1501 context switch is required. */
\r
1502 vTaskMissedYield();
\r
1511 #else /* configUSE_QUEUE_SETS */
\r
1513 /* Tasks that are removed from the event list will get added to
\r
1514 the pending ready list as the scheduler is still suspended. */
\r
1515 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
1517 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1519 /* The task waiting has a higher priority so record that a
\r
1520 context switch is required. */
\r
1521 vTaskMissedYield();
\r
1529 #endif /* configUSE_QUEUE_SETS */
\r
1531 --( pxQueue->xTxLock );
\r
1534 pxQueue->xTxLock = queueUNLOCKED;
\r
1536 taskEXIT_CRITICAL();
\r
1538 /* Do the same for the Rx lock. */
\r
1539 taskENTER_CRITICAL();
\r
1541 while( pxQueue->xRxLock > queueLOCKED_UNMODIFIED )
\r
1543 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
1545 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
1547 vTaskMissedYield();
\r
1550 --( pxQueue->xRxLock );
\r
1558 pxQueue->xRxLock = queueUNLOCKED;
\r
1560 taskEXIT_CRITICAL();
\r
1562 /*-----------------------------------------------------------*/
\r
1564 static signed portBASE_TYPE prvIsQueueEmpty( const xQUEUE *pxQueue )
\r
1566 signed portBASE_TYPE xReturn;
\r
1568 taskENTER_CRITICAL();
\r
1570 if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )
\r
1576 xReturn = pdFALSE;
\r
1579 taskEXIT_CRITICAL();
\r
1583 /*-----------------------------------------------------------*/
\r
1585 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle xQueue )
\r
1587 signed portBASE_TYPE xReturn;
\r
1589 configASSERT( xQueue );
\r
1590 if( ( ( xQUEUE * ) xQueue )->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )
\r
1596 xReturn = pdFALSE;
\r
1600 } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */
\r
1601 /*-----------------------------------------------------------*/
\r
1603 static signed portBASE_TYPE prvIsQueueFull( const xQUEUE *pxQueue )
\r
1605 signed portBASE_TYPE xReturn;
\r
1607 taskENTER_CRITICAL();
\r
1609 if( pxQueue->uxMessagesWaiting == pxQueue->uxLength )
\r
1615 xReturn = pdFALSE;
\r
1618 taskEXIT_CRITICAL();
\r
1622 /*-----------------------------------------------------------*/
\r
1624 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle xQueue )
\r
1626 signed portBASE_TYPE xReturn;
\r
1628 configASSERT( xQueue );
\r
1629 if( ( ( xQUEUE * ) xQueue )->uxMessagesWaiting == ( ( xQUEUE * ) xQueue )->uxLength )
\r
1635 xReturn = pdFALSE;
\r
1639 } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */
\r
1640 /*-----------------------------------------------------------*/
\r
1642 #if ( configUSE_CO_ROUTINES == 1 )
\r
1644 signed portBASE_TYPE xQueueCRSend( xQueueHandle xQueue, const void *pvItemToQueue, portTickType xTicksToWait )
\r
1646 signed portBASE_TYPE xReturn;
\r
1647 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
\r
1649 /* If the queue is already full we may have to block. A critical section
\r
1650 is required to prevent an interrupt removing something from the queue
\r
1651 between the check to see if the queue is full and blocking on the queue. */
\r
1652 portDISABLE_INTERRUPTS();
\r
1654 if( prvIsQueueFull( pxQueue ) != pdFALSE )
\r
1656 /* The queue is full - do we want to block or just leave without
\r
1658 if( xTicksToWait > ( portTickType ) 0 )
\r
1660 /* As this is called from a coroutine we cannot block directly, but
\r
1661 return indicating that we need to block. */
\r
1662 vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToSend ) );
\r
1663 portENABLE_INTERRUPTS();
\r
1664 return errQUEUE_BLOCKED;
\r
1668 portENABLE_INTERRUPTS();
\r
1669 return errQUEUE_FULL;
\r
1673 portENABLE_INTERRUPTS();
\r
1675 portDISABLE_INTERRUPTS();
\r
1677 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
1679 /* There is room in the queue, copy the data into the queue. */
\r
1680 prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );
\r
1683 /* Were any co-routines waiting for data to become available? */
\r
1684 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
1686 /* In this instance the co-routine could be placed directly
\r
1687 into the ready list as we are within a critical section.
\r
1688 Instead the same pending ready list mechanism is used as if
\r
1689 the event were caused from within an interrupt. */
\r
1690 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1692 /* The co-routine waiting has a higher priority so record
\r
1693 that a yield might be appropriate. */
\r
1694 xReturn = errQUEUE_YIELD;
\r
1700 xReturn = errQUEUE_FULL;
\r
1703 portENABLE_INTERRUPTS();
\r
1708 #endif /* configUSE_CO_ROUTINES */
\r
1709 /*-----------------------------------------------------------*/
\r
1711 #if ( configUSE_CO_ROUTINES == 1 )
\r
1713 signed portBASE_TYPE xQueueCRReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait )
\r
1715 signed portBASE_TYPE xReturn;
\r
1716 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
\r
1718 /* If the queue is already empty we may have to block. A critical section
\r
1719 is required to prevent an interrupt adding something to the queue
\r
1720 between the check to see if the queue is empty and blocking on the queue. */
\r
1721 portDISABLE_INTERRUPTS();
\r
1723 if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )
\r
1725 /* There are no messages in the queue, do we want to block or just
\r
1726 leave with nothing? */
\r
1727 if( xTicksToWait > ( portTickType ) 0 )
\r
1729 /* As this is a co-routine we cannot block directly, but return
\r
1730 indicating that we need to block. */
\r
1731 vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToReceive ) );
\r
1732 portENABLE_INTERRUPTS();
\r
1733 return errQUEUE_BLOCKED;
\r
1737 portENABLE_INTERRUPTS();
\r
1738 return errQUEUE_FULL;
\r
1742 portENABLE_INTERRUPTS();
\r
1744 portDISABLE_INTERRUPTS();
\r
1746 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
1748 /* Data is available from the queue. */
\r
1749 pxQueue->u.pcReadFrom += pxQueue->uxItemSize;
\r
1750 if( pxQueue->u.pcReadFrom >= pxQueue->pcTail )
\r
1752 pxQueue->u.pcReadFrom = pxQueue->pcHead;
\r
1754 --( pxQueue->uxMessagesWaiting );
\r
1755 memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );
\r
1759 /* Were any co-routines waiting for space to become available? */
\r
1760 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
1762 /* In this instance the co-routine could be placed directly
\r
1763 into the ready list as we are within a critical section.
\r
1764 Instead the same pending ready list mechanism is used as if
\r
1765 the event were caused from within an interrupt. */
\r
1766 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
1768 xReturn = errQUEUE_YIELD;
\r
1777 portENABLE_INTERRUPTS();
\r
1782 #endif /* configUSE_CO_ROUTINES */
\r
1783 /*-----------------------------------------------------------*/
\r
1785 #if ( configUSE_CO_ROUTINES == 1 )
\r
1787 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle xQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken )
\r
1789 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
\r
1791 /* Cannot block within an ISR so if there is no space on the queue then
\r
1792 exit without doing anything. */
\r
1793 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )
\r
1795 prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );
\r
1797 /* We only want to wake one co-routine per ISR, so check that a
\r
1798 co-routine has not already been woken. */
\r
1799 if( xCoRoutinePreviouslyWoken == pdFALSE )
\r
1801 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
\r
1803 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )
\r
1811 return xCoRoutinePreviouslyWoken;
\r
1814 #endif /* configUSE_CO_ROUTINES */
\r
1815 /*-----------------------------------------------------------*/
\r
1817 #if ( configUSE_CO_ROUTINES == 1 )
\r
1819 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle xQueue, void *pvBuffer, signed portBASE_TYPE *pxCoRoutineWoken )
\r
1821 signed portBASE_TYPE xReturn;
\r
1822 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
\r
1824 /* We cannot block from an ISR, so check there is data available. If
\r
1825 not then just leave without doing anything. */
\r
1826 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
\r
1828 /* Copy the data from the queue. */
\r
1829 pxQueue->u.pcReadFrom += pxQueue->uxItemSize;
\r
1830 if( pxQueue->u.pcReadFrom >= pxQueue->pcTail )
\r
1832 pxQueue->u.pcReadFrom = pxQueue->pcHead;
\r
1834 --( pxQueue->uxMessagesWaiting );
\r
1835 memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );
\r
1837 if( ( *pxCoRoutineWoken ) == pdFALSE )
\r
1839 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
\r
1841 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )
\r
1843 *pxCoRoutineWoken = pdTRUE;
\r
1858 #endif /* configUSE_CO_ROUTINES */
\r
1859 /*-----------------------------------------------------------*/
\r
1861 #if ( configQUEUE_REGISTRY_SIZE > 0 )
\r
1863 void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcQueueName )
\r
1865 unsigned portBASE_TYPE ux;
\r
1867 /* See if there is an empty space in the registry. A NULL name denotes
\r
1869 for( ux = ( unsigned portBASE_TYPE ) 0U; ux < ( unsigned portBASE_TYPE ) configQUEUE_REGISTRY_SIZE; ux++ )
\r
1871 if( xQueueRegistry[ ux ].pcQueueName == NULL )
\r
1873 /* Store the information on this queue. */
\r
1874 xQueueRegistry[ ux ].pcQueueName = pcQueueName;
\r
1875 xQueueRegistry[ ux ].xHandle = xQueue;
\r
1881 #endif /* configQUEUE_REGISTRY_SIZE */
\r
1882 /*-----------------------------------------------------------*/
\r
1884 #if ( configQUEUE_REGISTRY_SIZE > 0 )
\r
1886 void vQueueUnregisterQueue( xQueueHandle xQueue )
\r
1888 unsigned portBASE_TYPE ux;
\r
1890 /* See if the handle of the queue being unregistered in actually in the
\r
1892 for( ux = ( unsigned portBASE_TYPE ) 0U; ux < ( unsigned portBASE_TYPE ) configQUEUE_REGISTRY_SIZE; ux++ )
\r
1894 if( xQueueRegistry[ ux ].xHandle == xQueue )
\r
1896 /* Set the name to NULL to show that this slot if free again. */
\r
1897 xQueueRegistry[ ux ].pcQueueName = NULL;
\r
1902 } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */
\r
1904 #endif /* configQUEUE_REGISTRY_SIZE */
\r
1905 /*-----------------------------------------------------------*/
\r
1907 #if ( configUSE_TIMERS == 1 )
\r
1909 void vQueueWaitForMessageRestricted( xQueueHandle xQueue, portTickType xTicksToWait )
\r
1911 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
\r
1913 /* This function should not be called by application code hence the
\r
1914 'Restricted' in its name. It is not part of the public API. It is
\r
1915 designed for use by kernel code, and has special calling requirements.
\r
1916 It can result in vListInsert() being called on a list that can only
\r
1917 possibly ever have one item in it, so the list will be fast, but even
\r
1918 so it should be called with the scheduler locked and not from a critical
\r
1921 /* Only do anything if there are no messages in the queue. This function
\r
1922 will not actually cause the task to block, just place it on a blocked
\r
1923 list. It will not block until the scheduler is unlocked - at which
\r
1924 time a yield will be performed. If an item is added to the queue while
\r
1925 the queue is locked, and the calling task blocks on the queue, then the
\r
1926 calling task will be immediately unblocked when the queue is unlocked. */
\r
1927 prvLockQueue( pxQueue );
\r
1928 if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0U )
\r
1930 /* There is nothing in the queue, block for the specified period. */
\r
1931 vTaskPlaceOnEventListRestricted( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
\r
1933 prvUnlockQueue( pxQueue );
\r
1936 #endif /* configUSE_TIMERS */
\r
1937 /*-----------------------------------------------------------*/
\r
1939 #if ( configUSE_QUEUE_SETS == 1 )
\r
1941 xQueueSetHandle xQueueCreateSet( unsigned portBASE_TYPE uxEventQueueLength )
\r
1943 xQueueSetHandle pxQueue;
\r
1945 pxQueue = xQueueGenericCreate( uxEventQueueLength, sizeof( xQUEUE * ), queueQUEUE_TYPE_SET );
\r
1950 #endif /* configUSE_QUEUE_SETS */
\r
1951 /*-----------------------------------------------------------*/
\r
1953 #if ( configUSE_QUEUE_SETS == 1 )
\r
1955 portBASE_TYPE xQueueAddToSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet )
\r
1957 portBASE_TYPE xReturn;
\r
1959 if( ( ( xQUEUE * ) xQueueOrSemaphore )->pxQueueSetContainer != NULL )
\r
1961 /* Cannot add a queue/semaphore to more than one queue set. */
\r
1964 else if( ( ( xQUEUE * ) xQueueOrSemaphore )->uxMessagesWaiting != ( unsigned portBASE_TYPE ) 0 )
\r
1966 /* Cannot add a queue/semaphore to a queue set if there are already
\r
1967 items in the queue/semaphore. */
\r
1972 taskENTER_CRITICAL();
\r
1974 ( ( xQUEUE * ) xQueueOrSemaphore )->pxQueueSetContainer = xQueueSet;
\r
1976 taskEXIT_CRITICAL();
\r
1983 #endif /* configUSE_QUEUE_SETS */
\r
1984 /*-----------------------------------------------------------*/
\r
1986 #if ( configUSE_QUEUE_SETS == 1 )
\r
1988 portBASE_TYPE xQueueRemoveFromSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet )
\r
1990 portBASE_TYPE xReturn;
\r
1991 xQUEUE * const pxQueueOrSemaphore = ( xQUEUE * ) xQueueOrSemaphore;
\r
1993 if( pxQueueOrSemaphore->pxQueueSetContainer != xQueueSet )
\r
1995 /* The queue was not a member of the set. */
\r
1998 else if( pxQueueOrSemaphore->uxMessagesWaiting != ( unsigned portBASE_TYPE ) 0 )
\r
2000 /* It is dangerous to remove a queue from a set when the queue is
\r
2001 not empty because the queue set will still hold pending events for
\r
2007 taskENTER_CRITICAL();
\r
2009 /* The queue is no longer contained in the set. */
\r
2010 pxQueueOrSemaphore->pxQueueSetContainer = NULL;
\r
2012 taskEXIT_CRITICAL();
\r
2017 } /*lint !e818 xQueueSet could not be declared as pointing to const as it is a typedef. */
\r
2019 #endif /* configUSE_QUEUE_SETS */
\r
2020 /*-----------------------------------------------------------*/
\r
2022 #if ( configUSE_QUEUE_SETS == 1 )
\r
2024 xQueueSetMemberHandle xQueueSelectFromSet( xQueueSetHandle xQueueSet, portTickType xBlockTimeTicks )
\r
2026 xQueueSetMemberHandle xReturn = NULL;
\r
2028 ( void ) xQueueGenericReceive( ( xQueueHandle ) xQueueSet, &xReturn, xBlockTimeTicks, pdFALSE ); /*lint !e961 Casting from one typedef to another is not redundant. */
\r
2032 #endif /* configUSE_QUEUE_SETS */
\r
2033 /*-----------------------------------------------------------*/
\r
2035 #if ( configUSE_QUEUE_SETS == 1 )
\r
2037 xQueueSetMemberHandle xQueueSelectFromSetFromISR( xQueueSetHandle xQueueSet )
\r
2039 xQueueSetMemberHandle xReturn = NULL;
\r
2041 ( void ) xQueueReceiveFromISR( ( xQueueHandle ) xQueueSet, &xReturn, NULL ); /*lint !e961 Casting from one typedef to another is not redundant. */
\r
2045 #endif /* configUSE_QUEUE_SETS */
\r
2046 /*-----------------------------------------------------------*/
\r
2048 #if ( configUSE_QUEUE_SETS == 1 )
\r
2050 static portBASE_TYPE prvNotifyQueueSetContainer( const xQUEUE * const pxQueue, portBASE_TYPE xCopyPosition )
\r
2052 xQUEUE *pxQueueSetContainer = pxQueue->pxQueueSetContainer;
\r
2053 portBASE_TYPE xReturn = pdFALSE;
\r
2055 configASSERT( pxQueueSetContainer );
\r
2056 configASSERT( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength );
\r
2058 if( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength )
\r
2060 traceQUEUE_SEND( pxQueueSetContainer );
\r
2061 /* The data copies is the handle of the queue that contains data. */
\r
2062 prvCopyDataToQueue( pxQueueSetContainer, &pxQueue, xCopyPosition );
\r
2063 if( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE )
\r
2065 if( xTaskRemoveFromEventList( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) != pdFALSE )
\r
2067 /* The task waiting has a higher priority */
\r
2076 #endif /* configUSE_QUEUE_SETS */
\r