]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/queue.c
Update version number.
[freertos] / FreeRTOS / Source / queue.c
1 /*\r
2     FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
5 \r
6     ***************************************************************************\r
7      *                                                                       *\r
8      *    FreeRTOS provides completely free yet professionally developed,    *\r
9      *    robust, strictly quality controlled, supported, and cross          *\r
10      *    platform software that has become a de facto standard.             *\r
11      *                                                                       *\r
12      *    Help yourself get started quickly and support the FreeRTOS         *\r
13      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
14      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
15      *                                                                       *\r
16      *    Thank you!                                                         *\r
17      *                                                                       *\r
18     ***************************************************************************\r
19 \r
20     This file is part of the FreeRTOS distribution.\r
21 \r
22     FreeRTOS is free software; you can redistribute it and/or modify it under\r
23     the terms of the GNU General Public License (version 2) as published by the\r
24     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
25 \r
26     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
27     >>! a combined work that includes FreeRTOS without being obliged to provide\r
28     >>! the source code for proprietary components outside of the FreeRTOS\r
29     >>! kernel.\r
30 \r
31     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
32     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
33     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
34     link: http://www.freertos.org/a00114.html\r
35 \r
36     1 tab == 4 spaces!\r
37 \r
38     ***************************************************************************\r
39      *                                                                       *\r
40      *    Having a problem?  Start by reading the FAQ "My application does   *\r
41      *    not run, what could be wrong?"                                     *\r
42      *                                                                       *\r
43      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
44      *                                                                       *\r
45     ***************************************************************************\r
46 \r
47     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
48     license and Real Time Engineers Ltd. contact details.\r
49 \r
50     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
51     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
52     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
53 \r
54     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
55     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
56     licenses offer ticketed support, indemnification and middleware.\r
57 \r
58     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
59     engineered and independently SIL3 certified version for use in safety and\r
60     mission critical applications that require provable dependability.\r
61 \r
62     1 tab == 4 spaces!\r
63 */\r
64 \r
65 #include <stdlib.h>\r
66 #include <string.h>\r
67 \r
68 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining\r
69 all the API functions to use the MPU wrappers.  That should only be done when\r
70 task.h is included from an application file. */\r
71 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE\r
72 \r
73 #include "FreeRTOS.h"\r
74 #include "task.h"\r
75 #include "queue.h"\r
76 \r
77 #if ( configUSE_CO_ROUTINES == 1 )\r
78         #include "croutine.h"\r
79 #endif\r
80 \r
81 /* Lint e961 and e750 are suppressed as a MISRA exception justified because the\r
82 MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the\r
83 header files above, but not in this file, in order to generate the correct\r
84 privileged Vs unprivileged linkage and placement. */\r
85 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */\r
86 \r
87 \r
88 /* Constants used with the cRxLock and xTxLock structure members. */\r
89 #define queueUNLOCKED                                   ( ( signed portBASE_TYPE ) -1 )\r
90 #define queueLOCKED_UNMODIFIED                  ( ( signed portBASE_TYPE ) 0 )\r
91 \r
92 /* When the xQUEUE structure is used to represent a base queue its pcHead and\r
93 pcTail members are used as pointers into the queue storage area.  When the\r
94 xQUEUE structure is used to represent a mutex pcHead and pcTail pointers are\r
95 not necessary, and the pcHead pointer is set to NULL to indicate that the\r
96 pcTail pointer actually points to the mutex holder (if any).  Map alternative\r
97 names to the pcHead and pcTail structure members to ensure the readability of\r
98 the code is maintained despite this dual use of two structure members.  An\r
99 alternative implementation would be to use a union, but use of a union is\r
100 against the coding standard (although an exception to the standard has been\r
101 permitted where the dual use also significantly changes the type of the\r
102 structure member). */\r
103 #define pxMutexHolder                                   pcTail\r
104 #define uxQueueType                                             pcHead\r
105 #define queueQUEUE_IS_MUTEX                             NULL\r
106 \r
107 /* Semaphores do not actually store or copy data, so have an item size of\r
108 zero. */\r
109 #define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( unsigned portBASE_TYPE ) 0 )\r
110 #define queueMUTEX_GIVE_BLOCK_TIME               ( ( portTickType ) 0U )\r
111 \r
112 \r
113 /*\r
114  * Definition of the queue used by the scheduler.\r
115  * Items are queued by copy, not reference.\r
116  */\r
117 typedef struct QueueDefinition\r
118 {\r
119         signed char *pcHead;                                    /*< Points to the beginning of the queue storage area. */\r
120         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
121 \r
122         signed char *pcWriteTo;                                 /*< Points to the free next place in the storage area. */\r
123 \r
124         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
125         {\r
126                 signed char *pcReadFrom;                        /*< Points to the last place that a queued item was read from when the structure is used as a queue. */\r
127                 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
128         } u;\r
129 \r
130         xList xTasksWaitingToSend;                              /*< List of tasks that are blocked waiting to post onto this queue.  Stored in priority order. */\r
131         xList xTasksWaitingToReceive;                   /*< List of tasks that are blocked waiting to read from this queue.  Stored in priority order. */\r
132 \r
133         volatile unsigned portBASE_TYPE uxMessagesWaiting;/*< The number of items currently in the queue. */\r
134         unsigned portBASE_TYPE uxLength;                /*< The length of the queue defined as the number of items it will hold, not the number of bytes. */\r
135         unsigned portBASE_TYPE uxItemSize;              /*< The size of each items that the queue will hold. */\r
136 \r
137         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
138         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
139 \r
140         #if ( configUSE_TRACE_FACILITY == 1 )\r
141                 unsigned char ucQueueNumber;\r
142                 unsigned char ucQueueType;\r
143         #endif\r
144 \r
145         #if ( configUSE_QUEUE_SETS == 1 )\r
146                 struct QueueDefinition *pxQueueSetContainer;\r
147         #endif\r
148 \r
149 } xQUEUE;\r
150 /*-----------------------------------------------------------*/\r
151 \r
152 /*\r
153  * The queue registry is just a means for kernel aware debuggers to locate\r
154  * queue structures.  It has no other purpose so is an optional component.\r
155  */\r
156 #if ( configQUEUE_REGISTRY_SIZE > 0 )\r
157 \r
158         /* The type stored within the queue registry array.  This allows a name\r
159         to be assigned to each queue making kernel aware debugging a little\r
160         more user friendly. */\r
161         typedef struct QUEUE_REGISTRY_ITEM\r
162         {\r
163                 signed char *pcQueueName;\r
164                 xQueueHandle xHandle;\r
165         } xQueueRegistryItem;\r
166 \r
167         /* The queue registry is simply an array of xQueueRegistryItem structures.\r
168         The pcQueueName member of a structure being NULL is indicative of the\r
169         array position being vacant. */\r
170         xQueueRegistryItem xQueueRegistry[ configQUEUE_REGISTRY_SIZE ];\r
171 \r
172 #endif /* configQUEUE_REGISTRY_SIZE */\r
173 \r
174 /*\r
175  * Unlocks a queue locked by a call to prvLockQueue.  Locking a queue does not\r
176  * prevent an ISR from adding or removing items to the queue, but does prevent\r
177  * an ISR from removing tasks from the queue event lists.  If an ISR finds a\r
178  * queue is locked it will instead increment the appropriate queue lock count\r
179  * to indicate that a task may require unblocking.  When the queue in unlocked\r
180  * these lock counts are inspected, and the appropriate action taken.\r
181  */\r
182 static void prvUnlockQueue( xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;\r
183 \r
184 /*\r
185  * Uses a critical section to determine if there is any data in a queue.\r
186  *\r
187  * @return pdTRUE if the queue contains no items, otherwise pdFALSE.\r
188  */\r
189 static signed portBASE_TYPE prvIsQueueEmpty( const xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;\r
190 \r
191 /*\r
192  * Uses a critical section to determine if there is any space in a queue.\r
193  *\r
194  * @return pdTRUE if there is no space, otherwise pdFALSE;\r
195  */\r
196 static signed portBASE_TYPE prvIsQueueFull( const xQUEUE *pxQueue ) PRIVILEGED_FUNCTION;\r
197 \r
198 /*\r
199  * Copies an item into the queue, either at the front of the queue or the\r
200  * back of the queue.\r
201  */\r
202 static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition ) PRIVILEGED_FUNCTION;\r
203 \r
204 /*\r
205  * Copies an item out of a queue.\r
206  */\r
207 static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void * const pvBuffer ) PRIVILEGED_FUNCTION;\r
208 \r
209 #if ( configUSE_QUEUE_SETS == 1 )\r
210         /*\r
211          * Checks to see if a queue is a member of a queue set, and if so, notifies\r
212          * the queue set that the queue contains data.\r
213          */\r
214         static portBASE_TYPE prvNotifyQueueSetContainer( const xQUEUE * const pxQueue, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;\r
215 #endif\r
216 \r
217 /*-----------------------------------------------------------*/\r
218 \r
219 /*\r
220  * Macro to mark a queue as locked.  Locking a queue prevents an ISR from\r
221  * accessing the queue event lists.\r
222  */\r
223 #define prvLockQueue( pxQueue )                                                         \\r
224         taskENTER_CRITICAL();                                                                   \\r
225         {                                                                                                               \\r
226                 if( ( pxQueue )->xRxLock == queueUNLOCKED )                     \\r
227                 {                                                                                                       \\r
228                         ( pxQueue )->xRxLock = queueLOCKED_UNMODIFIED;  \\r
229                 }                                                                                                       \\r
230                 if( ( pxQueue )->xTxLock == queueUNLOCKED )                     \\r
231                 {                                                                                                       \\r
232                         ( pxQueue )->xTxLock = queueLOCKED_UNMODIFIED;  \\r
233                 }                                                                                                       \\r
234         }                                                                                                               \\r
235         taskEXIT_CRITICAL()\r
236 /*-----------------------------------------------------------*/\r
237 \r
238 portBASE_TYPE xQueueGenericReset( xQueueHandle xQueue, portBASE_TYPE xNewQueue )\r
239 {\r
240 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
241 \r
242         configASSERT( pxQueue );\r
243 \r
244         taskENTER_CRITICAL();\r
245         {\r
246                 pxQueue->pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize );\r
247                 pxQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U;\r
248                 pxQueue->pcWriteTo = pxQueue->pcHead;\r
249                 pxQueue->u.pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - ( unsigned portBASE_TYPE ) 1U ) * pxQueue->uxItemSize );\r
250                 pxQueue->xRxLock = queueUNLOCKED;\r
251                 pxQueue->xTxLock = queueUNLOCKED;\r
252 \r
253                 if( xNewQueue == pdFALSE )\r
254                 {\r
255                         /* If there are tasks blocked waiting to read from the queue, then\r
256                         the tasks will remain blocked as after this function exits the queue\r
257                         will still be empty.  If there are tasks blocked waiting to     write to\r
258                         the queue, then one should be unblocked as after this function exits\r
259                         it will be possible to write to it. */\r
260                         if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
261                         {\r
262                                 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )\r
263                                 {\r
264                                         portYIELD_WITHIN_API();\r
265                                 }\r
266                         }\r
267                 }\r
268                 else\r
269                 {\r
270                         /* Ensure the event queues start in the correct state. */\r
271                         vListInitialise( &( pxQueue->xTasksWaitingToSend ) );\r
272                         vListInitialise( &( pxQueue->xTasksWaitingToReceive ) );\r
273                 }\r
274         }\r
275         taskEXIT_CRITICAL();\r
276 \r
277         /* A value is returned for calling semantic consistency with previous\r
278         versions. */\r
279         return pdPASS;\r
280 }\r
281 /*-----------------------------------------------------------*/\r
282 \r
283 xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType )\r
284 {\r
285 xQUEUE *pxNewQueue;\r
286 size_t xQueueSizeInBytes;\r
287 xQueueHandle xReturn = NULL;\r
288 \r
289         /* Remove compiler warnings about unused parameters should\r
290         configUSE_TRACE_FACILITY not be set to 1. */\r
291         ( void ) ucQueueType;\r
292 \r
293         /* Allocate the new queue structure. */\r
294         if( uxQueueLength > ( unsigned portBASE_TYPE ) 0 )\r
295         {\r
296                 pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );\r
297                 if( pxNewQueue != NULL )\r
298                 {\r
299                         /* Create the list of pointers to queue items.  The queue is one byte\r
300                         longer than asked for to make wrap checking easier/faster. */\r
301                         xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ) + ( size_t ) 1; /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
302 \r
303                         pxNewQueue->pcHead = ( signed char * ) pvPortMalloc( xQueueSizeInBytes );\r
304                         if( pxNewQueue->pcHead != NULL )\r
305                         {\r
306                                 /* Initialise the queue members as described above where the\r
307                                 queue type is defined. */\r
308                                 pxNewQueue->uxLength = uxQueueLength;\r
309                                 pxNewQueue->uxItemSize = uxItemSize;\r
310                                 ( void ) xQueueGenericReset( pxNewQueue, pdTRUE );\r
311 \r
312                                 #if ( configUSE_TRACE_FACILITY == 1 )\r
313                                 {\r
314                                         pxNewQueue->ucQueueType = ucQueueType;\r
315                                 }\r
316                                 #endif /* configUSE_TRACE_FACILITY */\r
317 \r
318                                 #if( configUSE_QUEUE_SETS == 1 )\r
319                                 {\r
320                                         pxNewQueue->pxQueueSetContainer = NULL;\r
321                                 }\r
322                                 #endif /* configUSE_QUEUE_SETS */\r
323 \r
324                                 traceQUEUE_CREATE( pxNewQueue );\r
325                                 xReturn = pxNewQueue;\r
326                         }\r
327                         else\r
328                         {\r
329                                 traceQUEUE_CREATE_FAILED( ucQueueType );\r
330                                 vPortFree( pxNewQueue );\r
331                         }\r
332                 }\r
333         }\r
334 \r
335         configASSERT( xReturn );\r
336 \r
337         return xReturn;\r
338 }\r
339 /*-----------------------------------------------------------*/\r
340 \r
341 #if ( configUSE_MUTEXES == 1 )\r
342 \r
343         xQueueHandle xQueueCreateMutex( unsigned char ucQueueType )\r
344         {\r
345         xQUEUE *pxNewQueue;\r
346 \r
347                 /* Prevent compiler warnings about unused parameters if\r
348                 configUSE_TRACE_FACILITY does not equal 1. */\r
349                 ( void ) ucQueueType;\r
350 \r
351                 /* Allocate the new queue structure. */\r
352                 pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );\r
353                 if( pxNewQueue != NULL )\r
354                 {\r
355                         /* Information required for priority inheritance. */\r
356                         pxNewQueue->pxMutexHolder = NULL;\r
357                         pxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX;\r
358 \r
359                         /* Queues used as a mutex no data is actually copied into or out\r
360                         of the queue. */\r
361                         pxNewQueue->pcWriteTo = NULL;\r
362                         pxNewQueue->u.pcReadFrom = NULL;\r
363 \r
364                         /* Each mutex has a length of 1 (like a binary semaphore) and\r
365                         an item size of 0 as nothing is actually copied into or out\r
366                         of the mutex. */\r
367                         pxNewQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U;\r
368                         pxNewQueue->uxLength = ( unsigned portBASE_TYPE ) 1U;\r
369                         pxNewQueue->uxItemSize = ( unsigned portBASE_TYPE ) 0U;\r
370                         pxNewQueue->xRxLock = queueUNLOCKED;\r
371                         pxNewQueue->xTxLock = queueUNLOCKED;\r
372 \r
373                         #if ( configUSE_TRACE_FACILITY == 1 )\r
374                         {\r
375                                 pxNewQueue->ucQueueType = ucQueueType;\r
376                         }\r
377                         #endif\r
378 \r
379                         #if ( configUSE_QUEUE_SETS == 1 )\r
380                         {\r
381                                 pxNewQueue->pxQueueSetContainer = NULL;\r
382                         }\r
383                         #endif\r
384 \r
385                         /* Ensure the event queues start with the correct state. */\r
386                         vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) );\r
387                         vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );\r
388 \r
389                         traceCREATE_MUTEX( pxNewQueue );\r
390 \r
391                         /* Start with the semaphore in the expected state. */\r
392                         ( void ) xQueueGenericSend( pxNewQueue, NULL, ( portTickType ) 0U, queueSEND_TO_BACK );\r
393                 }\r
394                 else\r
395                 {\r
396                         traceCREATE_MUTEX_FAILED();\r
397                 }\r
398 \r
399                 configASSERT( pxNewQueue );\r
400                 return pxNewQueue;\r
401         }\r
402 \r
403 #endif /* configUSE_MUTEXES */\r
404 /*-----------------------------------------------------------*/\r
405 \r
406 #if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )\r
407 \r
408         void* xQueueGetMutexHolder( xQueueHandle xSemaphore )\r
409         {\r
410         void *pxReturn;\r
411 \r
412                 /* This function is called by xSemaphoreGetMutexHolder(), and should not\r
413                 be called directly.  Note:  This is is a good way of determining if the\r
414                 calling task is the mutex holder, but not a good way of determining the\r
415                 identity of the mutex holder, as the holder may change between the\r
416                 following critical section exiting and the function returning. */\r
417                 taskENTER_CRITICAL();\r
418                 {\r
419                         if( ( ( xQUEUE * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX )\r
420                         {\r
421                                 pxReturn = ( void * ) ( ( xQUEUE * ) xSemaphore )->pxMutexHolder;\r
422                         }\r
423                         else\r
424                         {\r
425                                 pxReturn = NULL;\r
426                         }\r
427                 }\r
428                 taskEXIT_CRITICAL();\r
429 \r
430                 return pxReturn;\r
431         }\r
432 \r
433 #endif\r
434 /*-----------------------------------------------------------*/\r
435 \r
436 #if ( configUSE_RECURSIVE_MUTEXES == 1 )\r
437 \r
438         portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex )\r
439         {\r
440         portBASE_TYPE xReturn;\r
441         xQUEUE * const pxMutex = ( xQUEUE * ) xMutex;\r
442 \r
443                 configASSERT( pxMutex );\r
444 \r
445                 /* If this is the task that holds the mutex then pxMutexHolder will not\r
446                 change outside of this task.  If this task does not hold the mutex then\r
447                 pxMutexHolder can never coincidentally equal the tasks handle, and as\r
448                 this is the only condition we are interested in it does not matter if\r
449                 pxMutexHolder is accessed simultaneously by another task.  Therefore no\r
450                 mutual exclusion is required to test the pxMutexHolder variable. */\r
451                 if( pxMutex->pxMutexHolder == ( void * ) xTaskGetCurrentTaskHandle() ) /*lint !e961 Not a redundant cast as xTaskHandle is a typedef. */\r
452                 {\r
453                         traceGIVE_MUTEX_RECURSIVE( pxMutex );\r
454 \r
455                         /* uxRecursiveCallCount cannot be zero if pxMutexHolder is equal to\r
456                         the task handle, therefore no underflow check is required.  Also,\r
457                         uxRecursiveCallCount is only modified by the mutex holder, and as\r
458                         there can only be one, no mutual exclusion is required to modify the\r
459                         uxRecursiveCallCount member. */\r
460                         ( pxMutex->u.uxRecursiveCallCount )--;\r
461 \r
462                         /* Have we unwound the call count? */\r
463                         if( pxMutex->u.uxRecursiveCallCount == ( unsigned portBASE_TYPE ) 0 )\r
464                         {\r
465                                 /* Return the mutex.  This will automatically unblock any other\r
466                                 task that might be waiting to access the mutex. */\r
467                                 ( void ) xQueueGenericSend( pxMutex, NULL, queueMUTEX_GIVE_BLOCK_TIME, queueSEND_TO_BACK );\r
468                         }\r
469 \r
470                         xReturn = pdPASS;\r
471                 }\r
472                 else\r
473                 {\r
474                         /* We cannot give the mutex because we are not the holder. */\r
475                         xReturn = pdFAIL;\r
476 \r
477                         traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex );\r
478                 }\r
479 \r
480                 return xReturn;\r
481         }\r
482 \r
483 #endif /* configUSE_RECURSIVE_MUTEXES */\r
484 /*-----------------------------------------------------------*/\r
485 \r
486 #if ( configUSE_RECURSIVE_MUTEXES == 1 )\r
487 \r
488         portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime )\r
489         {\r
490         portBASE_TYPE xReturn;\r
491         xQUEUE * const pxMutex = ( xQUEUE * ) xMutex;\r
492 \r
493                 configASSERT( pxMutex );\r
494 \r
495                 /* Comments regarding mutual exclusion as per those within\r
496                 xQueueGiveMutexRecursive(). */\r
497 \r
498                 traceTAKE_MUTEX_RECURSIVE( pxMutex );\r
499 \r
500                 if( pxMutex->pxMutexHolder == ( void * )  xTaskGetCurrentTaskHandle() ) /*lint !e961 Cast is not redundant as xTaskHandle is a typedef. */\r
501                 {\r
502                         ( pxMutex->u.uxRecursiveCallCount )++;\r
503                         xReturn = pdPASS;\r
504                 }\r
505                 else\r
506                 {\r
507                         xReturn = xQueueGenericReceive( pxMutex, NULL, xBlockTime, pdFALSE );\r
508 \r
509                         /* pdPASS will only be returned if we successfully obtained the mutex,\r
510                         we may have blocked to reach here. */\r
511                         if( xReturn == pdPASS )\r
512                         {\r
513                                 ( pxMutex->u.uxRecursiveCallCount )++;\r
514                         }\r
515                         else\r
516                         {\r
517                                 traceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex );\r
518                         }\r
519                 }\r
520 \r
521                 return xReturn;\r
522         }\r
523 \r
524 #endif /* configUSE_RECURSIVE_MUTEXES */\r
525 /*-----------------------------------------------------------*/\r
526 \r
527 #if ( configUSE_COUNTING_SEMAPHORES == 1 )\r
528 \r
529         xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount )\r
530         {\r
531         xQueueHandle xHandle;\r
532 \r
533                 xHandle = xQueueGenericCreate( uxCountValue, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE );\r
534 \r
535                 if( xHandle != NULL )\r
536                 {\r
537                         ( ( xQUEUE * ) xHandle )->uxMessagesWaiting = uxInitialCount;\r
538 \r
539                         traceCREATE_COUNTING_SEMAPHORE();\r
540                 }\r
541                 else\r
542                 {\r
543                         traceCREATE_COUNTING_SEMAPHORE_FAILED();\r
544                 }\r
545 \r
546                 configASSERT( xHandle );\r
547                 return xHandle;\r
548         }\r
549 \r
550 #endif /* configUSE_COUNTING_SEMAPHORES */\r
551 /*-----------------------------------------------------------*/\r
552 \r
553 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )\r
554 {\r
555 signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
556 xTimeOutType xTimeOut;\r
557 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
558 \r
559         configASSERT( pxQueue );\r
560         configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
561         configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\r
562 \r
563         /* This function relaxes the coding standard somewhat to allow return\r
564         statements within the function itself.  This is done in the interest\r
565         of execution time efficiency. */\r
566         for( ;; )\r
567         {\r
568                 taskENTER_CRITICAL();\r
569                 {\r
570                         /* Is there room on the queue now?  The running task must be\r
571                         the highest priority task wanting to access the queue.  If\r
572                         the head item in the queue is to be overwritten then it does\r
573                         not matter if the queue is full. */\r
574                         if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )\r
575                         {\r
576                                 traceQUEUE_SEND( pxQueue );\r
577                                 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
578 \r
579                                 #if ( configUSE_QUEUE_SETS == 1 )\r
580                                 {\r
581                                         if( pxQueue->pxQueueSetContainer != NULL )\r
582                                         {\r
583                                                 if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE )\r
584                                                 {\r
585                                                         /* The queue is a member of a queue set, and posting\r
586                                                         to the queue set caused a higher priority task to\r
587                                                         unblock. A context switch is required. */\r
588                                                         portYIELD_WITHIN_API();\r
589                                                 }\r
590                                         }\r
591                                         else\r
592                                         {\r
593                                                 /* If there was a task waiting for data to arrive on the\r
594                                                 queue then unblock it now. */\r
595                                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
596                                                 {\r
597                                                         if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )\r
598                                                         {\r
599                                                                 /* The unblocked task has a priority higher than\r
600                                                                 our own so yield immediately.  Yes it is ok to\r
601                                                                 do this from within the critical section - the\r
602                                                                 kernel takes care of that. */\r
603                                                                 portYIELD_WITHIN_API();\r
604                                                         }\r
605                                                 }\r
606                                         }\r
607                                 }\r
608                                 #else /* configUSE_QUEUE_SETS */\r
609                                 {\r
610                                         /* If there was a task waiting for data to arrive on the\r
611                                         queue then unblock it now. */\r
612                                         if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
613                                         {\r
614                                                 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )\r
615                                                 {\r
616                                                         /* The unblocked task has a priority higher than\r
617                                                         our own so yield immediately.  Yes it is ok to do\r
618                                                         this from within the critical section - the kernel\r
619                                                         takes care of that. */\r
620                                                         portYIELD_WITHIN_API();\r
621                                                 }\r
622                                         }\r
623                                 }\r
624                                 #endif /* configUSE_QUEUE_SETS */\r
625 \r
626                                 taskEXIT_CRITICAL();\r
627 \r
628                                 /* Return to the original privilege level before exiting the\r
629                                 function. */\r
630                                 return pdPASS;\r
631                         }\r
632                         else\r
633                         {\r
634                                 if( xTicksToWait == ( portTickType ) 0 )\r
635                                 {\r
636                                         /* The queue was full and no block time is specified (or\r
637                                         the block time has expired) so leave now. */\r
638                                         taskEXIT_CRITICAL();\r
639 \r
640                                         /* Return to the original privilege level before exiting\r
641                                         the function. */\r
642                                         traceQUEUE_SEND_FAILED( pxQueue );\r
643                                         return errQUEUE_FULL;\r
644                                 }\r
645                                 else if( xEntryTimeSet == pdFALSE )\r
646                                 {\r
647                                         /* The queue was full and a block time was specified so\r
648                                         configure the timeout structure. */\r
649                                         vTaskSetTimeOutState( &xTimeOut );\r
650                                         xEntryTimeSet = pdTRUE;\r
651                                 }\r
652                                 else\r
653                                 {\r
654                                         /* Entry time was already set. */                                       \r
655                                 }\r
656                         }\r
657                 }\r
658                 taskEXIT_CRITICAL();\r
659 \r
660                 /* Interrupts and other tasks can send to and receive from the queue\r
661                 now the critical section has been exited. */\r
662 \r
663                 vTaskSuspendAll();\r
664                 prvLockQueue( pxQueue );\r
665 \r
666                 /* Update the timeout state to see if it has expired yet. */\r
667                 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
668                 {\r
669                         if( prvIsQueueFull( pxQueue ) != pdFALSE )\r
670                         {\r
671                                 traceBLOCKING_ON_QUEUE_SEND( pxQueue );\r
672                                 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );\r
673 \r
674                                 /* Unlocking the queue means queue events can effect the\r
675                                 event list.  It is possible     that interrupts occurring now\r
676                                 remove this task from the event list again - but as the\r
677                                 scheduler is suspended the task will go onto the pending\r
678                                 ready last instead of the actual ready list. */\r
679                                 prvUnlockQueue( pxQueue );\r
680 \r
681                                 /* Resuming the scheduler will move tasks from the pending\r
682                                 ready list into the ready list - so it is feasible that this\r
683                                 task is already in a ready list before it yields - in which\r
684                                 case the yield will not cause a context switch unless there\r
685                                 is also a higher priority task in the pending ready list. */\r
686                                 if( xTaskResumeAll() == pdFALSE )\r
687                                 {\r
688                                         portYIELD_WITHIN_API();\r
689                                 }\r
690                         }\r
691                         else\r
692                         {\r
693                                 /* Try again. */\r
694                                 prvUnlockQueue( pxQueue );\r
695                                 ( void ) xTaskResumeAll();\r
696                         }\r
697                 }\r
698                 else\r
699                 {\r
700                         /* The timeout has expired. */\r
701                         prvUnlockQueue( pxQueue );\r
702                         ( void ) xTaskResumeAll();\r
703 \r
704                         /* Return to the original privilege level before exiting the\r
705                         function. */\r
706                         traceQUEUE_SEND_FAILED( pxQueue );\r
707                         return errQUEUE_FULL;\r
708                 }\r
709         }\r
710 }\r
711 /*-----------------------------------------------------------*/\r
712 \r
713 #if ( configUSE_ALTERNATIVE_API == 1 )\r
714 \r
715         signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )\r
716         {\r
717         signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
718         xTimeOutType xTimeOut;\r
719         xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
720 \r
721                 configASSERT( pxQueue );\r
722                 configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
723 \r
724                 for( ;; )\r
725                 {\r
726                         taskENTER_CRITICAL();\r
727                         {\r
728                                 /* Is there room on the queue now?  To be running we must be\r
729                                 the highest priority task wanting to access the queue. */\r
730                                 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
731                                 {\r
732                                         traceQUEUE_SEND( pxQueue );\r
733                                         prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
734 \r
735                                         /* If there was a task waiting for data to arrive on the\r
736                                         queue then unblock it now. */\r
737                                         if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
738                                         {\r
739                                                 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )\r
740                                                 {\r
741                                                         /* The unblocked task has a priority higher than\r
742                                                         our own so yield immediately. */\r
743                                                         portYIELD_WITHIN_API();\r
744                                                 }\r
745                                         }\r
746 \r
747                                         taskEXIT_CRITICAL();\r
748                                         return pdPASS;\r
749                                 }\r
750                                 else\r
751                                 {\r
752                                         if( xTicksToWait == ( portTickType ) 0 )\r
753                                         {\r
754                                                 taskEXIT_CRITICAL();\r
755                                                 return errQUEUE_FULL;\r
756                                         }\r
757                                         else if( xEntryTimeSet == pdFALSE )\r
758                                         {\r
759                                                 vTaskSetTimeOutState( &xTimeOut );\r
760                                                 xEntryTimeSet = pdTRUE;\r
761                                         }\r
762                                 }\r
763                         }\r
764                         taskEXIT_CRITICAL();\r
765 \r
766                         taskENTER_CRITICAL();\r
767                         {\r
768                                 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
769                                 {\r
770                                         if( prvIsQueueFull( pxQueue ) != pdFALSE )\r
771                                         {\r
772                                                 traceBLOCKING_ON_QUEUE_SEND( pxQueue );\r
773                                                 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );\r
774                                                 portYIELD_WITHIN_API();\r
775                                         }\r
776                                 }\r
777                                 else\r
778                                 {\r
779                                         taskEXIT_CRITICAL();\r
780                                         traceQUEUE_SEND_FAILED( pxQueue );\r
781                                         return errQUEUE_FULL;\r
782                                 }\r
783                         }\r
784                         taskEXIT_CRITICAL();\r
785                 }\r
786         }\r
787 \r
788 #endif /* configUSE_ALTERNATIVE_API */\r
789 /*-----------------------------------------------------------*/\r
790 \r
791 #if ( configUSE_ALTERNATIVE_API == 1 )\r
792 \r
793         signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )\r
794         {\r
795         signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
796         xTimeOutType xTimeOut;\r
797         signed char *pcOriginalReadPosition;\r
798         xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
799 \r
800                 configASSERT( pxQueue );\r
801                 configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
802 \r
803                 for( ;; )\r
804                 {\r
805                         taskENTER_CRITICAL();\r
806                         {\r
807                                 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
808                                 {\r
809                                         /* Remember our read position in case we are just peeking. */\r
810                                         pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
811 \r
812                                         prvCopyDataFromQueue( pxQueue, pvBuffer );\r
813 \r
814                                         if( xJustPeeking == pdFALSE )\r
815                                         {\r
816                                                 traceQUEUE_RECEIVE( pxQueue );\r
817 \r
818                                                 /* Data is actually being removed (not just peeked). */\r
819                                                 --( pxQueue->uxMessagesWaiting );\r
820 \r
821                                                 #if ( configUSE_MUTEXES == 1 )\r
822                                                 {\r
823                                                         if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
824                                                         {\r
825                                                                 /* Record the information required to implement\r
826                                                                 priority inheritance should it become necessary. */\r
827                                                                 pxQueue->pxMutexHolder = ( signed char * ) xTaskGetCurrentTaskHandle();\r
828                                                         }\r
829                                                 }\r
830                                                 #endif\r
831 \r
832                                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
833                                                 {\r
834                                                         if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )\r
835                                                         {\r
836                                                                 portYIELD_WITHIN_API();\r
837                                                         }\r
838                                                 }\r
839                                         }\r
840                                         else\r
841                                         {\r
842                                                 traceQUEUE_PEEK( pxQueue );\r
843 \r
844                                                 /* We are not removing the data, so reset our read\r
845                                                 pointer. */\r
846                                                 pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
847 \r
848                                                 /* The data is being left in the queue, so see if there are\r
849                                                 any other tasks waiting for the data. */\r
850                                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
851                                                 {\r
852                                                         /* Tasks that are removed from the event list will get added to\r
853                                                         the pending ready list as the scheduler is still suspended. */\r
854                                                         if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
855                                                         {\r
856                                                                 /* The task waiting has a higher priority than this task. */\r
857                                                                 portYIELD_WITHIN_API();\r
858                                                         }\r
859                                                 }\r
860 \r
861                                         }\r
862 \r
863                                         taskEXIT_CRITICAL();\r
864                                         return pdPASS;\r
865                                 }\r
866                                 else\r
867                                 {\r
868                                         if( xTicksToWait == ( portTickType ) 0 )\r
869                                         {\r
870                                                 taskEXIT_CRITICAL();\r
871                                                 traceQUEUE_RECEIVE_FAILED( pxQueue );\r
872                                                 return errQUEUE_EMPTY;\r
873                                         }\r
874                                         else if( xEntryTimeSet == pdFALSE )\r
875                                         {\r
876                                                 vTaskSetTimeOutState( &xTimeOut );\r
877                                                 xEntryTimeSet = pdTRUE;\r
878                                         }\r
879                                 }\r
880                         }\r
881                         taskEXIT_CRITICAL();\r
882 \r
883                         taskENTER_CRITICAL();\r
884                         {\r
885                                 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
886                                 {\r
887                                         if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
888                                         {\r
889                                                 traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
890 \r
891                                                 #if ( configUSE_MUTEXES == 1 )\r
892                                                 {\r
893                                                         if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
894                                                         {\r
895                                                                 portENTER_CRITICAL();\r
896                                                                 {\r
897                                                                         vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );\r
898                                                                 }\r
899                                                                 portEXIT_CRITICAL();\r
900                                                         }\r
901                                                 }\r
902                                                 #endif\r
903 \r
904                                                 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
905                                                 portYIELD_WITHIN_API();\r
906                                         }\r
907                                 }\r
908                                 else\r
909                                 {\r
910                                         taskEXIT_CRITICAL();\r
911                                         traceQUEUE_RECEIVE_FAILED( pxQueue );\r
912                                         return errQUEUE_EMPTY;\r
913                                 }\r
914                         }\r
915                         taskEXIT_CRITICAL();\r
916                 }\r
917         }\r
918 \r
919 \r
920 #endif /* configUSE_ALTERNATIVE_API */\r
921 /*-----------------------------------------------------------*/\r
922 \r
923 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle xQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition )\r
924 {\r
925 signed portBASE_TYPE xReturn;\r
926 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
927 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
928 \r
929         configASSERT( pxQueue );\r
930         configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
931         configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\r
932 \r
933         /* RTOS ports that support interrupt nesting have the concept of a maximum\r
934         system call (or maximum API call) interrupt priority.  Interrupts that are\r
935         above the maximum system call priority are keep permanently enabled, even\r
936         when the RTOS kernel is in a critical section, but cannot make any calls to\r
937         FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\r
938         then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
939         failure if a FreeRTOS API function is called from an interrupt that has been\r
940         assigned a priority above the configured maximum system call priority.\r
941         Only FreeRTOS functions that end in FromISR can be called from interrupts\r
942         that have been assigned a priority at or (logically) below the maximum\r
943         system call     interrupt priority.  FreeRTOS maintains a separate interrupt\r
944         safe API to ensure interrupt entry is as fast and as simple as possible.\r
945         More information (albeit Cortex-M specific) is provided on the following\r
946         link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
947         portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
948 \r
949         /* Similar to xQueueGenericSend, except we don't block if there is no room\r
950         in the queue.  Also we don't directly wake a task that was blocked on a\r
951         queue read, instead we return a flag to say whether a context switch is\r
952         required or not (i.e. has a task with a higher priority than us been woken\r
953         by this post). */\r
954         uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
955         {\r
956                 if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )\r
957                 {\r
958                         traceQUEUE_SEND_FROM_ISR( pxQueue );\r
959 \r
960                         prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
961 \r
962                         /* If the queue is locked we do not alter the event list.  This will\r
963                         be done when the queue is unlocked later. */\r
964                         if( pxQueue->xTxLock == queueUNLOCKED )\r
965                         {\r
966                                 #if ( configUSE_QUEUE_SETS == 1 )\r
967                                 {\r
968                                         if( pxQueue->pxQueueSetContainer != NULL )\r
969                                         {\r
970                                                 if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE )\r
971                                                 {\r
972                                                         /* The queue is a member of a queue set, and posting\r
973                                                         to the queue set caused a higher priority task to\r
974                                                         unblock.  A context switch is required. */\r
975                                                         if( pxHigherPriorityTaskWoken != NULL )\r
976                                                         {\r
977                                                                 *pxHigherPriorityTaskWoken = pdTRUE;\r
978                                                         }\r
979                                                 }\r
980                                         }\r
981                                         else\r
982                                         {\r
983                                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
984                                                 {\r
985                                                         if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
986                                                         {\r
987                                                                 /* The task waiting has a higher priority so record that a\r
988                                                                 context switch is required. */\r
989                                                                 if( pxHigherPriorityTaskWoken != NULL )\r
990                                                                 {\r
991                                                                         *pxHigherPriorityTaskWoken = pdTRUE;\r
992                                                                 }\r
993                                                         }\r
994                                                 }\r
995                                         }\r
996                                 }\r
997                                 #else /* configUSE_QUEUE_SETS */\r
998                                 {\r
999                                         if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
1000                                         {\r
1001                                                 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
1002                                                 {\r
1003                                                         /* The task waiting has a higher priority so record that a\r
1004                                                         context switch is required. */\r
1005                                                         if( pxHigherPriorityTaskWoken != NULL )\r
1006                                                         {\r
1007                                                                 *pxHigherPriorityTaskWoken = pdTRUE;\r
1008                                                         }\r
1009                                                 }\r
1010                                         }\r
1011                                 }\r
1012                                 #endif /* configUSE_QUEUE_SETS */\r
1013                         }\r
1014                         else\r
1015                         {\r
1016                                 /* Increment the lock count so the task that unlocks the queue\r
1017                                 knows that data was posted while it was locked. */\r
1018                                 ++( pxQueue->xTxLock );\r
1019                         }\r
1020 \r
1021                         xReturn = pdPASS;\r
1022                 }\r
1023                 else\r
1024                 {\r
1025                         traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );\r
1026                         xReturn = errQUEUE_FULL;\r
1027                 }\r
1028         }\r
1029         portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
1030 \r
1031         return xReturn;\r
1032 }\r
1033 /*-----------------------------------------------------------*/\r
1034 \r
1035 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )\r
1036 {\r
1037 signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
1038 xTimeOutType xTimeOut;\r
1039 signed char *pcOriginalReadPosition;\r
1040 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
1041 \r
1042         configASSERT( pxQueue );\r
1043         configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
1044 \r
1045         /* This function relaxes the coding standard somewhat to allow return\r
1046         statements within the function itself.  This is done in the interest\r
1047         of execution time efficiency. */\r
1048 \r
1049         for( ;; )\r
1050         {\r
1051                 taskENTER_CRITICAL();\r
1052                 {\r
1053                         /* Is there data in the queue now?  To be running we must be\r
1054                         the highest priority task wanting to access the queue. */\r
1055                         if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
1056                         {\r
1057                                 /* Remember the read position in case the queue is only being\r
1058                                 peeked. */\r
1059                                 pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
1060 \r
1061                                 prvCopyDataFromQueue( pxQueue, pvBuffer );\r
1062 \r
1063                                 if( xJustPeeking == pdFALSE )\r
1064                                 {\r
1065                                         traceQUEUE_RECEIVE( pxQueue );\r
1066 \r
1067                                         /* Actually removing data, not just peeking. */\r
1068                                         --( pxQueue->uxMessagesWaiting );\r
1069 \r
1070                                         #if ( configUSE_MUTEXES == 1 )\r
1071                                         {\r
1072                                                 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
1073                                                 {\r
1074                                                         /* Record the information required to implement\r
1075                                                         priority inheritance should it become necessary. */\r
1076                                                         pxQueue->pxMutexHolder = ( signed char * ) xTaskGetCurrentTaskHandle(); /*lint !e961 Cast is not redundant as xTaskHandle is a typedef. */\r
1077                                                 }\r
1078                                         }\r
1079                                         #endif\r
1080 \r
1081                                         if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
1082                                         {\r
1083                                                 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )\r
1084                                                 {\r
1085                                                         portYIELD_WITHIN_API();\r
1086                                                 }\r
1087                                         }\r
1088                                 }\r
1089                                 else\r
1090                                 {\r
1091                                         traceQUEUE_PEEK( pxQueue );\r
1092 \r
1093                                         /* The data is not being removed, so reset the read\r
1094                                         pointer. */\r
1095                                         pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
1096 \r
1097                                         /* The data is being left in the queue, so see if there are\r
1098                                         any other tasks waiting for the data. */\r
1099                                         if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
1100                                         {\r
1101                                                 /* Tasks that are removed from the event list will get added to\r
1102                                                 the pending ready list as the scheduler is still suspended. */\r
1103                                                 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
1104                                                 {\r
1105                                                         /* The task waiting has a higher priority than this task. */\r
1106                                                         portYIELD_WITHIN_API();\r
1107                                                 }\r
1108                                         }\r
1109                                 }\r
1110 \r
1111                                 taskEXIT_CRITICAL();\r
1112                                 return pdPASS;\r
1113                         }\r
1114                         else\r
1115                         {\r
1116                                 if( xTicksToWait == ( portTickType ) 0 )\r
1117                                 {\r
1118                                         /* The queue was empty and no block time is specified (or\r
1119                                         the block time has expired) so leave now. */\r
1120                                         taskEXIT_CRITICAL();\r
1121                                         traceQUEUE_RECEIVE_FAILED( pxQueue );\r
1122                                         return errQUEUE_EMPTY;\r
1123                                 }\r
1124                                 else if( xEntryTimeSet == pdFALSE )\r
1125                                 {\r
1126                                         /* The queue was empty and a block time was specified so\r
1127                                         configure the timeout structure. */\r
1128                                         vTaskSetTimeOutState( &xTimeOut );\r
1129                                         xEntryTimeSet = pdTRUE;\r
1130                                 }\r
1131                                 else\r
1132                                 {\r
1133                                         /* Entry time was already set. */\r
1134                                 }\r
1135                         }\r
1136                 }\r
1137                 taskEXIT_CRITICAL();\r
1138 \r
1139                 /* Interrupts and other tasks can send to and receive from the queue\r
1140                 now the critical section has been exited. */\r
1141 \r
1142                 vTaskSuspendAll();\r
1143                 prvLockQueue( pxQueue );\r
1144 \r
1145                 /* Update the timeout state to see if it has expired yet. */\r
1146                 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
1147                 {\r
1148                         if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
1149                         {\r
1150                                 traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
1151 \r
1152                                 #if ( configUSE_MUTEXES == 1 )\r
1153                                 {\r
1154                                         if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
1155                                         {\r
1156                                                 portENTER_CRITICAL();\r
1157                                                 {\r
1158                                                         vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );\r
1159                                                 }\r
1160                                                 portEXIT_CRITICAL();\r
1161                                         }\r
1162                                 }\r
1163                                 #endif\r
1164 \r
1165                                 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
1166                                 prvUnlockQueue( pxQueue );\r
1167                                 if( xTaskResumeAll() == pdFALSE )\r
1168                                 {\r
1169                                         portYIELD_WITHIN_API();\r
1170                                 }\r
1171                         }\r
1172                         else\r
1173                         {\r
1174                                 /* Try again. */\r
1175                                 prvUnlockQueue( pxQueue );\r
1176                                 ( void ) xTaskResumeAll();\r
1177                         }\r
1178                 }\r
1179                 else\r
1180                 {\r
1181                         prvUnlockQueue( pxQueue );\r
1182                         ( void ) xTaskResumeAll();\r
1183                         traceQUEUE_RECEIVE_FAILED( pxQueue );\r
1184                         return errQUEUE_EMPTY;\r
1185                 }\r
1186         }\r
1187 }\r
1188 /*-----------------------------------------------------------*/\r
1189 \r
1190 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, const void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken )\r
1191 {\r
1192 signed portBASE_TYPE xReturn;\r
1193 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
1194 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
1195 \r
1196         configASSERT( pxQueue );\r
1197         configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
1198 \r
1199         /* RTOS ports that support interrupt nesting have the concept of a maximum\r
1200         system call (or maximum API call) interrupt priority.  Interrupts that are\r
1201         above the maximum system call priority are keep permanently enabled, even \r
1202         when the RTOS kernel is in a critical section, but cannot make any calls to\r
1203         FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h \r
1204         then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
1205         failure if a FreeRTOS API function is called from an interrupt that has been\r
1206         assigned a priority above the configured maximum system call priority.\r
1207         Only FreeRTOS functions that end in FromISR can be called from interrupts\r
1208         that have been assigned a priority at or (logically) below the maximum \r
1209         system call     interrupt priority.  FreeRTOS maintains a separate interrupt \r
1210         safe API to ensure interrupt entry is as fast and as simple as possible.  \r
1211         More information (albeit Cortex-M specific) is provided on the following \r
1212         link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
1213         portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
1214 \r
1215         uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
1216         {\r
1217                 /* Cannot block in an ISR, so check there is data available. */\r
1218                 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
1219                 {\r
1220                         traceQUEUE_RECEIVE_FROM_ISR( pxQueue );\r
1221 \r
1222                         prvCopyDataFromQueue( pxQueue, pvBuffer );\r
1223                         --( pxQueue->uxMessagesWaiting );\r
1224 \r
1225                         /* If the queue is locked the event list will not be modified.\r
1226                         Instead update the lock count so the task that unlocks the queue\r
1227                         will know that an ISR has removed data while the queue was\r
1228                         locked. */\r
1229                         if( pxQueue->xRxLock == queueUNLOCKED )\r
1230                         {\r
1231                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
1232                                 {\r
1233                                         if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
1234                                         {\r
1235                                                 /* The task waiting has a higher priority than us so\r
1236                                                 force a context switch. */\r
1237                                                 if( pxHigherPriorityTaskWoken != NULL )\r
1238                                                 {\r
1239                                                         *pxHigherPriorityTaskWoken = pdTRUE;\r
1240                                                 }\r
1241                                         }\r
1242                                 }\r
1243                         }\r
1244                         else\r
1245                         {\r
1246                                 /* Increment the lock count so the task that unlocks the queue\r
1247                                 knows that data was removed while it was locked. */\r
1248                                 ++( pxQueue->xRxLock );\r
1249                         }\r
1250 \r
1251                         xReturn = pdPASS;\r
1252                 }\r
1253                 else\r
1254                 {\r
1255                         xReturn = pdFAIL;\r
1256                         traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue );\r
1257                 }\r
1258         }\r
1259         portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
1260 \r
1261         return xReturn;\r
1262 }\r
1263 /*-----------------------------------------------------------*/\r
1264 \r
1265 signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, const void * const pvBuffer )\r
1266 {\r
1267 signed portBASE_TYPE xReturn;\r
1268 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
1269 signed char *pcOriginalReadPosition;\r
1270 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
1271 \r
1272         configASSERT( pxQueue );\r
1273         configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
1274 \r
1275         /* RTOS ports that support interrupt nesting have the concept of a maximum\r
1276         system call (or maximum API call) interrupt priority.  Interrupts that are\r
1277         above the maximum system call priority are keep permanently enabled, even \r
1278         when the RTOS kernel is in a critical section, but cannot make any calls to\r
1279         FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h \r
1280         then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
1281         failure if a FreeRTOS API function is called from an interrupt that has been\r
1282         assigned a priority above the configured maximum system call priority.\r
1283         Only FreeRTOS functions that end in FromISR can be called from interrupts\r
1284         that have been assigned a priority at or (logically) below the maximum \r
1285         system call     interrupt priority.  FreeRTOS maintains a separate interrupt \r
1286         safe API to ensure interrupt entry is as fast and as simple as possible.  \r
1287         More information (albeit Cortex-M specific) is provided on the following \r
1288         link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
1289         portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
1290 \r
1291         uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
1292         {\r
1293                 /* Cannot block in an ISR, so check there is data available. */\r
1294                 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
1295                 {\r
1296                         traceQUEUE_PEEK_FROM_ISR( pxQueue );\r
1297 \r
1298                         /* Remember the read position so it can be reset as nothing is\r
1299                         actually being removed from the queue. */\r
1300                         pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
1301                         prvCopyDataFromQueue( pxQueue, pvBuffer );\r
1302                         pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
1303 \r
1304                         xReturn = pdPASS;\r
1305                 }\r
1306                 else\r
1307                 {\r
1308                         xReturn = pdFAIL;\r
1309                         traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue );\r
1310                 }\r
1311         }\r
1312         portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
1313 \r
1314         return xReturn;\r
1315 }\r
1316 /*-----------------------------------------------------------*/\r
1317 \r
1318 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue )\r
1319 {\r
1320 unsigned portBASE_TYPE uxReturn;\r
1321 \r
1322         configASSERT( xQueue );\r
1323 \r
1324         taskENTER_CRITICAL();\r
1325                 uxReturn = ( ( xQUEUE * ) xQueue )->uxMessagesWaiting;\r
1326         taskEXIT_CRITICAL();\r
1327 \r
1328         return uxReturn;\r
1329 } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */\r
1330 /*-----------------------------------------------------------*/\r
1331 \r
1332 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle xQueue )\r
1333 {\r
1334 unsigned portBASE_TYPE uxReturn;\r
1335 \r
1336         configASSERT( xQueue );\r
1337 \r
1338         uxReturn = ( ( xQUEUE * ) xQueue )->uxMessagesWaiting;\r
1339 \r
1340         return uxReturn;\r
1341 } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */\r
1342 /*-----------------------------------------------------------*/\r
1343 \r
1344 void vQueueDelete( xQueueHandle xQueue )\r
1345 {\r
1346 xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
1347 \r
1348         configASSERT( pxQueue );\r
1349 \r
1350         traceQUEUE_DELETE( pxQueue );\r
1351         #if ( configQUEUE_REGISTRY_SIZE > 0 )\r
1352         {\r
1353                 vQueueUnregisterQueue( pxQueue );\r
1354         }\r
1355         #endif\r
1356         vPortFree( pxQueue->pcHead );\r
1357         vPortFree( pxQueue );\r
1358 }\r
1359 /*-----------------------------------------------------------*/\r
1360 \r
1361 #if ( configUSE_TRACE_FACILITY == 1 )\r
1362 \r
1363         unsigned char ucQueueGetQueueNumber( xQueueHandle xQueue )\r
1364         {\r
1365                 return ( ( xQUEUE * ) xQueue )->ucQueueNumber;\r
1366         }\r
1367 \r
1368 #endif /* configUSE_TRACE_FACILITY */\r
1369 /*-----------------------------------------------------------*/\r
1370 \r
1371 #if ( configUSE_TRACE_FACILITY == 1 )\r
1372 \r
1373         void vQueueSetQueueNumber( xQueueHandle xQueue, unsigned char ucQueueNumber )\r
1374         {\r
1375                 ( ( xQUEUE * ) xQueue )->ucQueueNumber = ucQueueNumber;\r
1376         }\r
1377 \r
1378 #endif /* configUSE_TRACE_FACILITY */\r
1379 /*-----------------------------------------------------------*/\r
1380 \r
1381 #if ( configUSE_TRACE_FACILITY == 1 )\r
1382 \r
1383         unsigned char ucQueueGetQueueType( xQueueHandle xQueue )\r
1384         {\r
1385                 return ( ( xQUEUE * ) xQueue )->ucQueueType;\r
1386         }\r
1387 \r
1388 #endif /* configUSE_TRACE_FACILITY */\r
1389 /*-----------------------------------------------------------*/\r
1390 \r
1391 static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition )\r
1392 {\r
1393         if( pxQueue->uxItemSize == ( unsigned portBASE_TYPE ) 0 )\r
1394         {\r
1395                 #if ( configUSE_MUTEXES == 1 )\r
1396                 {\r
1397                         if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
1398                         {\r
1399                                 /* The mutex is no longer being held. */\r
1400                                 vTaskPriorityDisinherit( ( void * ) pxQueue->pxMutexHolder );\r
1401                                 pxQueue->pxMutexHolder = NULL;\r
1402                         }\r
1403                 }\r
1404                 #endif /* configUSE_MUTEXES */\r
1405         }\r
1406         else if( xPosition == queueSEND_TO_BACK )\r
1407         {\r
1408                 ( 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
1409                 pxQueue->pcWriteTo += pxQueue->uxItemSize;\r
1410                 if( pxQueue->pcWriteTo >= pxQueue->pcTail ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */\r
1411                 {\r
1412                         pxQueue->pcWriteTo = pxQueue->pcHead;\r
1413                 }\r
1414         }\r
1415         else\r
1416         {\r
1417                 ( 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
1418                 pxQueue->u.pcReadFrom -= pxQueue->uxItemSize;\r
1419                 if( pxQueue->u.pcReadFrom < pxQueue->pcHead ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */\r
1420                 {\r
1421                         pxQueue->u.pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );\r
1422                 }\r
1423 \r
1424                 if( xPosition == queueOVERWRITE )\r
1425                 {\r
1426                         if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
1427                         {\r
1428                                 /* An item is not being added but overwritten, so subtract\r
1429                                 one from the recorded number of items in the queue so when\r
1430                                 one is added again below the number of recorded items remains\r
1431                                 correct. */\r
1432                                 --( pxQueue->uxMessagesWaiting );\r
1433                         }\r
1434                 }\r
1435         }\r
1436 \r
1437         ++( pxQueue->uxMessagesWaiting );\r
1438 }\r
1439 /*-----------------------------------------------------------*/\r
1440 \r
1441 static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void * const pvBuffer )\r
1442 {\r
1443         if( pxQueue->uxQueueType != queueQUEUE_IS_MUTEX )\r
1444         {\r
1445                 pxQueue->u.pcReadFrom += pxQueue->uxItemSize;\r
1446                 if( pxQueue->u.pcReadFrom >= pxQueue->pcTail ) /*lint !e946 MISRA exception justified as use of the relational operator is the cleanest solutions. */\r
1447                 {\r
1448                         pxQueue->u.pcReadFrom = pxQueue->pcHead;\r
1449                 }\r
1450                 ( 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
1451         }\r
1452 }\r
1453 /*-----------------------------------------------------------*/\r
1454 \r
1455 static void prvUnlockQueue( xQUEUE *pxQueue )\r
1456 {\r
1457         /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */\r
1458 \r
1459         /* The lock counts contains the number of extra data items placed or\r
1460         removed from the queue while the queue was locked.  When a queue is\r
1461         locked items can be added or removed, but the event lists cannot be\r
1462         updated. */\r
1463         taskENTER_CRITICAL();\r
1464         {\r
1465                 /* See if data was added to the queue while it was locked. */\r
1466                 while( pxQueue->xTxLock > queueLOCKED_UNMODIFIED )\r
1467                 {\r
1468                         /* Data was posted while the queue was locked.  Are any tasks\r
1469                         blocked waiting for data to become available? */\r
1470                         #if ( configUSE_QUEUE_SETS == 1 )\r
1471                         {\r
1472                                 if( pxQueue->pxQueueSetContainer != NULL )\r
1473                                 {\r
1474                                         if( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) == pdTRUE )\r
1475                                         {\r
1476                                                 /* The queue is a member of a queue set, and posting to\r
1477                                                 the queue set caused a higher priority task to unblock.\r
1478                                                 A context switch is required. */\r
1479                                                 vTaskMissedYield();\r
1480                                         }\r
1481                                 }\r
1482                                 else\r
1483                                 {\r
1484                                         /* Tasks that are removed from the event list will get added to\r
1485                                         the pending ready list as the scheduler is still suspended. */\r
1486                                         if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
1487                                         {\r
1488                                                 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
1489                                                 {\r
1490                                                         /* The task waiting has a higher priority so record that a\r
1491                                                         context switch is required. */\r
1492                                                         vTaskMissedYield();\r
1493                                                 }\r
1494                                         }\r
1495                                         else\r
1496                                         {\r
1497                                                 break;\r
1498                                         }\r
1499                                 }\r
1500                         }\r
1501                         #else /* configUSE_QUEUE_SETS */\r
1502                         {\r
1503                                 /* Tasks that are removed from the event list will get added to\r
1504                                 the pending ready list as the scheduler is still suspended. */\r
1505                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
1506                                 {\r
1507                                         if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
1508                                         {\r
1509                                                 /* The task waiting has a higher priority so record that a\r
1510                                                 context switch is required. */\r
1511                                                 vTaskMissedYield();\r
1512                                         }\r
1513                                 }\r
1514                                 else\r
1515                                 {\r
1516                                         break;\r
1517                                 }\r
1518                         }\r
1519                         #endif /* configUSE_QUEUE_SETS */\r
1520 \r
1521                         --( pxQueue->xTxLock );\r
1522                 }\r
1523 \r
1524                 pxQueue->xTxLock = queueUNLOCKED;\r
1525         }\r
1526         taskEXIT_CRITICAL();\r
1527 \r
1528         /* Do the same for the Rx lock. */\r
1529         taskENTER_CRITICAL();\r
1530         {\r
1531                 while( pxQueue->xRxLock > queueLOCKED_UNMODIFIED )\r
1532                 {\r
1533                         if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
1534                         {\r
1535                                 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
1536                                 {\r
1537                                         vTaskMissedYield();\r
1538                                 }\r
1539 \r
1540                                 --( pxQueue->xRxLock );\r
1541                         }\r
1542                         else\r
1543                         {\r
1544                                 break;\r
1545                         }\r
1546                 }\r
1547 \r
1548                 pxQueue->xRxLock = queueUNLOCKED;\r
1549         }\r
1550         taskEXIT_CRITICAL();\r
1551 }\r
1552 /*-----------------------------------------------------------*/\r
1553 \r
1554 static signed portBASE_TYPE prvIsQueueEmpty( const xQUEUE *pxQueue )\r
1555 {\r
1556 signed portBASE_TYPE xReturn;\r
1557 \r
1558         taskENTER_CRITICAL();\r
1559         {\r
1560                 if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE )  0 )\r
1561                 {\r
1562                         xReturn = pdTRUE;\r
1563                 }\r
1564                 else\r
1565                 {\r
1566                         xReturn = pdFALSE;\r
1567                 }\r
1568         }\r
1569         taskEXIT_CRITICAL();\r
1570 \r
1571         return xReturn;\r
1572 }\r
1573 /*-----------------------------------------------------------*/\r
1574 \r
1575 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle xQueue )\r
1576 {\r
1577 signed portBASE_TYPE xReturn;\r
1578 \r
1579         configASSERT( xQueue );\r
1580         if( ( ( xQUEUE * ) xQueue )->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )\r
1581         {\r
1582                 xReturn = pdTRUE;\r
1583         }\r
1584         else\r
1585         {\r
1586                 xReturn = pdFALSE;\r
1587         }\r
1588 \r
1589         return xReturn;\r
1590 } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */\r
1591 /*-----------------------------------------------------------*/\r
1592 \r
1593 static signed portBASE_TYPE prvIsQueueFull( const xQUEUE *pxQueue )\r
1594 {\r
1595 signed portBASE_TYPE xReturn;\r
1596 \r
1597         taskENTER_CRITICAL();\r
1598         {\r
1599                 if( pxQueue->uxMessagesWaiting == pxQueue->uxLength )\r
1600                 {\r
1601                         xReturn = pdTRUE;\r
1602                 }\r
1603                 else\r
1604                 {\r
1605                         xReturn = pdFALSE;\r
1606                 }\r
1607         }\r
1608         taskEXIT_CRITICAL();\r
1609 \r
1610         return xReturn;\r
1611 }\r
1612 /*-----------------------------------------------------------*/\r
1613 \r
1614 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle xQueue )\r
1615 {\r
1616 signed portBASE_TYPE xReturn;\r
1617 \r
1618         configASSERT( xQueue );\r
1619         if( ( ( xQUEUE * ) xQueue )->uxMessagesWaiting == ( ( xQUEUE * ) xQueue )->uxLength )\r
1620         {\r
1621                 xReturn = pdTRUE;\r
1622         }\r
1623         else\r
1624         {\r
1625                 xReturn = pdFALSE;\r
1626         }\r
1627 \r
1628         return xReturn;\r
1629 } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */\r
1630 /*-----------------------------------------------------------*/\r
1631 \r
1632 #if ( configUSE_CO_ROUTINES == 1 )\r
1633 \r
1634         signed portBASE_TYPE xQueueCRSend( xQueueHandle xQueue, const void *pvItemToQueue, portTickType xTicksToWait )\r
1635         {\r
1636         signed portBASE_TYPE xReturn;\r
1637         xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
1638 \r
1639                 /* If the queue is already full we may have to block.  A critical section\r
1640                 is required to prevent an interrupt removing something from the queue\r
1641                 between the check to see if the queue is full and blocking on the queue. */\r
1642                 portDISABLE_INTERRUPTS();\r
1643                 {\r
1644                         if( prvIsQueueFull( pxQueue ) != pdFALSE )\r
1645                         {\r
1646                                 /* The queue is full - do we want to block or just leave without\r
1647                                 posting? */\r
1648                                 if( xTicksToWait > ( portTickType ) 0 )\r
1649                                 {\r
1650                                         /* As this is called from a coroutine we cannot block directly, but\r
1651                                         return indicating that we need to block. */\r
1652                                         vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToSend ) );\r
1653                                         portENABLE_INTERRUPTS();\r
1654                                         return errQUEUE_BLOCKED;\r
1655                                 }\r
1656                                 else\r
1657                                 {\r
1658                                         portENABLE_INTERRUPTS();\r
1659                                         return errQUEUE_FULL;\r
1660                                 }\r
1661                         }\r
1662                 }\r
1663                 portENABLE_INTERRUPTS();\r
1664 \r
1665                 portDISABLE_INTERRUPTS();\r
1666                 {\r
1667                         if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
1668                         {\r
1669                                 /* There is room in the queue, copy the data into the queue. */\r
1670                                 prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );\r
1671                                 xReturn = pdPASS;\r
1672 \r
1673                                 /* Were any co-routines waiting for data to become available? */\r
1674                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
1675                                 {\r
1676                                         /* In this instance the co-routine could be placed directly\r
1677                                         into the ready list as we are within a critical section.\r
1678                                         Instead the same pending ready list mechanism is used as if\r
1679                                         the event were caused from within an interrupt. */\r
1680                                         if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
1681                                         {\r
1682                                                 /* The co-routine waiting has a higher priority so record\r
1683                                                 that a yield might be appropriate. */\r
1684                                                 xReturn = errQUEUE_YIELD;\r
1685                                         }\r
1686                                 }\r
1687                         }\r
1688                         else\r
1689                         {\r
1690                                 xReturn = errQUEUE_FULL;\r
1691                         }\r
1692                 }\r
1693                 portENABLE_INTERRUPTS();\r
1694 \r
1695                 return xReturn;\r
1696         }\r
1697 \r
1698 #endif /* configUSE_CO_ROUTINES */\r
1699 /*-----------------------------------------------------------*/\r
1700 \r
1701 #if ( configUSE_CO_ROUTINES == 1 )\r
1702 \r
1703         signed portBASE_TYPE xQueueCRReceive( xQueueHandle xQueue, void *pvBuffer, portTickType xTicksToWait )\r
1704         {\r
1705         signed portBASE_TYPE xReturn;\r
1706         xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
1707 \r
1708                 /* If the queue is already empty we may have to block.  A critical section\r
1709                 is required to prevent an interrupt adding something to the queue\r
1710                 between the check to see if the queue is empty and blocking on the queue. */\r
1711                 portDISABLE_INTERRUPTS();\r
1712                 {\r
1713                         if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )\r
1714                         {\r
1715                                 /* There are no messages in the queue, do we want to block or just\r
1716                                 leave with nothing? */\r
1717                                 if( xTicksToWait > ( portTickType ) 0 )\r
1718                                 {\r
1719                                         /* As this is a co-routine we cannot block directly, but return\r
1720                                         indicating that we need to block. */\r
1721                                         vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToReceive ) );\r
1722                                         portENABLE_INTERRUPTS();\r
1723                                         return errQUEUE_BLOCKED;\r
1724                                 }\r
1725                                 else\r
1726                                 {\r
1727                                         portENABLE_INTERRUPTS();\r
1728                                         return errQUEUE_FULL;\r
1729                                 }\r
1730                         }\r
1731                 }\r
1732                 portENABLE_INTERRUPTS();\r
1733 \r
1734                 portDISABLE_INTERRUPTS();\r
1735                 {\r
1736                         if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
1737                         {\r
1738                                 /* Data is available from the queue. */\r
1739                                 pxQueue->u.pcReadFrom += pxQueue->uxItemSize;\r
1740                                 if( pxQueue->u.pcReadFrom >= pxQueue->pcTail )\r
1741                                 {\r
1742                                         pxQueue->u.pcReadFrom = pxQueue->pcHead;\r
1743                                 }\r
1744                                 --( pxQueue->uxMessagesWaiting );\r
1745                                 ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
1746 \r
1747                                 xReturn = pdPASS;\r
1748 \r
1749                                 /* Were any co-routines waiting for space to become available? */\r
1750                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
1751                                 {\r
1752                                         /* In this instance the co-routine could be placed directly\r
1753                                         into the ready list as we are within a critical section.\r
1754                                         Instead the same pending ready list mechanism is used as if\r
1755                                         the event were caused from within an interrupt. */\r
1756                                         if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
1757                                         {\r
1758                                                 xReturn = errQUEUE_YIELD;\r
1759                                         }\r
1760                                 }\r
1761                         }\r
1762                         else\r
1763                         {\r
1764                                 xReturn = pdFAIL;\r
1765                         }\r
1766                 }\r
1767                 portENABLE_INTERRUPTS();\r
1768 \r
1769                 return xReturn;\r
1770         }\r
1771 \r
1772 #endif /* configUSE_CO_ROUTINES */\r
1773 /*-----------------------------------------------------------*/\r
1774 \r
1775 #if ( configUSE_CO_ROUTINES == 1 )\r
1776 \r
1777         signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle xQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken )\r
1778         {\r
1779         xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
1780 \r
1781                 /* Cannot block within an ISR so if there is no space on the queue then\r
1782                 exit without doing anything. */\r
1783                 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
1784                 {\r
1785                         prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );\r
1786 \r
1787                         /* We only want to wake one co-routine per ISR, so check that a\r
1788                         co-routine has not already been woken. */\r
1789                         if( xCoRoutinePreviouslyWoken == pdFALSE )\r
1790                         {\r
1791                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
1792                                 {\r
1793                                         if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
1794                                         {\r
1795                                                 return pdTRUE;\r
1796                                         }\r
1797                                 }\r
1798                         }\r
1799                 }\r
1800 \r
1801                 return xCoRoutinePreviouslyWoken;\r
1802         }\r
1803 \r
1804 #endif /* configUSE_CO_ROUTINES */\r
1805 /*-----------------------------------------------------------*/\r
1806 \r
1807 #if ( configUSE_CO_ROUTINES == 1 )\r
1808 \r
1809         signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle xQueue, void *pvBuffer, signed portBASE_TYPE *pxCoRoutineWoken )\r
1810         {\r
1811         signed portBASE_TYPE xReturn;\r
1812         xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
1813 \r
1814                 /* We cannot block from an ISR, so check there is data available. If\r
1815                 not then just leave without doing anything. */\r
1816                 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
1817                 {\r
1818                         /* Copy the data from the queue. */\r
1819                         pxQueue->u.pcReadFrom += pxQueue->uxItemSize;\r
1820                         if( pxQueue->u.pcReadFrom >= pxQueue->pcTail )\r
1821                         {\r
1822                                 pxQueue->u.pcReadFrom = pxQueue->pcHead;\r
1823                         }\r
1824                         --( pxQueue->uxMessagesWaiting );\r
1825                         ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
1826 \r
1827                         if( ( *pxCoRoutineWoken ) == pdFALSE )\r
1828                         {\r
1829                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
1830                                 {\r
1831                                         if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
1832                                         {\r
1833                                                 *pxCoRoutineWoken = pdTRUE;\r
1834                                         }\r
1835                                 }\r
1836                         }\r
1837 \r
1838                         xReturn = pdPASS;\r
1839                 }\r
1840                 else\r
1841                 {\r
1842                         xReturn = pdFAIL;\r
1843                 }\r
1844 \r
1845                 return xReturn;\r
1846         }\r
1847 \r
1848 #endif /* configUSE_CO_ROUTINES */\r
1849 /*-----------------------------------------------------------*/\r
1850 \r
1851 #if ( configQUEUE_REGISTRY_SIZE > 0 )\r
1852 \r
1853         void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcQueueName )\r
1854         {\r
1855         unsigned portBASE_TYPE ux;\r
1856 \r
1857                 /* See if there is an empty space in the registry.  A NULL name denotes\r
1858                 a free slot. */\r
1859                 for( ux = ( unsigned portBASE_TYPE ) 0U; ux < ( unsigned portBASE_TYPE ) configQUEUE_REGISTRY_SIZE; ux++ )\r
1860                 {\r
1861                         if( xQueueRegistry[ ux ].pcQueueName == NULL )\r
1862                         {\r
1863                                 /* Store the information on this queue. */\r
1864                                 xQueueRegistry[ ux ].pcQueueName = pcQueueName;\r
1865                                 xQueueRegistry[ ux ].xHandle = xQueue;\r
1866                                 break;\r
1867                         }\r
1868                 }\r
1869         }\r
1870 \r
1871 #endif /* configQUEUE_REGISTRY_SIZE */\r
1872 /*-----------------------------------------------------------*/\r
1873 \r
1874 #if ( configQUEUE_REGISTRY_SIZE > 0 )\r
1875 \r
1876         void vQueueUnregisterQueue( xQueueHandle xQueue )\r
1877         {\r
1878         unsigned portBASE_TYPE ux;\r
1879 \r
1880                 /* See if the handle of the queue being unregistered in actually in the\r
1881                 registry. */\r
1882                 for( ux = ( unsigned portBASE_TYPE ) 0U; ux < ( unsigned portBASE_TYPE ) configQUEUE_REGISTRY_SIZE; ux++ )\r
1883                 {\r
1884                         if( xQueueRegistry[ ux ].xHandle == xQueue )\r
1885                         {\r
1886                                 /* Set the name to NULL to show that this slot if free again. */\r
1887                                 xQueueRegistry[ ux ].pcQueueName = NULL;\r
1888                                 break;\r
1889                         }\r
1890                 }\r
1891 \r
1892         } /*lint !e818 xQueue could not be pointer to const because it is a typedef. */\r
1893 \r
1894 #endif /* configQUEUE_REGISTRY_SIZE */\r
1895 /*-----------------------------------------------------------*/\r
1896 \r
1897 #if ( configUSE_TIMERS == 1 )\r
1898 \r
1899         void vQueueWaitForMessageRestricted( xQueueHandle xQueue, portTickType xTicksToWait )\r
1900         {\r
1901         xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;\r
1902 \r
1903                 /* This function should not be called by application code hence the\r
1904                 'Restricted' in its name.  It is not part of the public API.  It is\r
1905                 designed for use by kernel code, and has special calling requirements.\r
1906                 It can result in vListInsert() being called on a list that can only\r
1907                 possibly ever have one item in it, so the list will be fast, but even\r
1908                 so it should be called with the scheduler locked and not from a critical\r
1909                 section. */\r
1910 \r
1911                 /* Only do anything if there are no messages in the queue.  This function\r
1912                 will not actually cause the task to block, just place it on a blocked\r
1913                 list.  It will not block until the scheduler is unlocked - at which\r
1914                 time a yield will be performed.  If an item is added to the queue while\r
1915                 the queue is locked, and the calling task blocks on the queue, then the\r
1916                 calling task will be immediately unblocked when the queue is unlocked. */\r
1917                 prvLockQueue( pxQueue );\r
1918                 if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0U )\r
1919                 {\r
1920                         /* There is nothing in the queue, block for the specified period. */\r
1921                         vTaskPlaceOnEventListRestricted( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
1922                 }\r
1923                 prvUnlockQueue( pxQueue );\r
1924         }\r
1925 \r
1926 #endif /* configUSE_TIMERS */\r
1927 /*-----------------------------------------------------------*/\r
1928 \r
1929 #if ( configUSE_QUEUE_SETS == 1 )\r
1930 \r
1931         xQueueSetHandle xQueueCreateSet( unsigned portBASE_TYPE uxEventQueueLength )\r
1932         {\r
1933         xQueueSetHandle pxQueue;\r
1934 \r
1935                 pxQueue = xQueueGenericCreate( uxEventQueueLength, sizeof( xQUEUE * ), queueQUEUE_TYPE_SET );\r
1936 \r
1937                 return pxQueue;\r
1938         }\r
1939 \r
1940 #endif /* configUSE_QUEUE_SETS */\r
1941 /*-----------------------------------------------------------*/\r
1942 \r
1943 #if ( configUSE_QUEUE_SETS == 1 )\r
1944 \r
1945         portBASE_TYPE xQueueAddToSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet )\r
1946         {\r
1947         portBASE_TYPE xReturn;\r
1948 \r
1949                 if( ( ( xQUEUE * ) xQueueOrSemaphore )->pxQueueSetContainer != NULL )\r
1950                 {\r
1951                         /* Cannot add a queue/semaphore to more than one queue set. */\r
1952                         xReturn = pdFAIL;\r
1953                 }\r
1954                 else if( ( ( xQUEUE * ) xQueueOrSemaphore )->uxMessagesWaiting != ( unsigned portBASE_TYPE ) 0 )\r
1955                 {\r
1956                         /* Cannot add a queue/semaphore to a queue set if there are already\r
1957                         items in the queue/semaphore. */\r
1958                         xReturn = pdFAIL;\r
1959                 }\r
1960                 else\r
1961                 {\r
1962                         taskENTER_CRITICAL();\r
1963                         {\r
1964                                 ( ( xQUEUE * ) xQueueOrSemaphore )->pxQueueSetContainer = xQueueSet;\r
1965                         }\r
1966                         taskEXIT_CRITICAL();\r
1967                         xReturn = pdPASS;\r
1968                 }\r
1969 \r
1970                 return xReturn;\r
1971         }\r
1972 \r
1973 #endif /* configUSE_QUEUE_SETS */\r
1974 /*-----------------------------------------------------------*/\r
1975 \r
1976 #if ( configUSE_QUEUE_SETS == 1 )\r
1977 \r
1978         portBASE_TYPE xQueueRemoveFromSet( xQueueSetMemberHandle xQueueOrSemaphore, xQueueSetHandle xQueueSet )\r
1979         {\r
1980         portBASE_TYPE xReturn;\r
1981         xQUEUE * const pxQueueOrSemaphore = ( xQUEUE * ) xQueueOrSemaphore;\r
1982 \r
1983                 if( pxQueueOrSemaphore->pxQueueSetContainer != xQueueSet )\r
1984                 {\r
1985                         /* The queue was not a member of the set. */\r
1986                         xReturn = pdFAIL;\r
1987                 }\r
1988                 else if( pxQueueOrSemaphore->uxMessagesWaiting != ( unsigned portBASE_TYPE ) 0 )\r
1989                 {\r
1990                         /* It is dangerous to remove a queue from a set when the queue is\r
1991                         not empty because the queue set will still hold pending events for\r
1992                         the queue. */\r
1993                         xReturn = pdFAIL;\r
1994                 }\r
1995                 else\r
1996                 {\r
1997                         taskENTER_CRITICAL();\r
1998                         {\r
1999                                 /* The queue is no longer contained in the set. */\r
2000                                 pxQueueOrSemaphore->pxQueueSetContainer = NULL;\r
2001                         }\r
2002                         taskEXIT_CRITICAL();\r
2003                         xReturn = pdPASS;\r
2004                 }\r
2005 \r
2006                 return xReturn;\r
2007         } /*lint !e818 xQueueSet could not be declared as pointing to const as it is a typedef. */\r
2008 \r
2009 #endif /* configUSE_QUEUE_SETS */\r
2010 /*-----------------------------------------------------------*/\r
2011 \r
2012 #if ( configUSE_QUEUE_SETS == 1 )\r
2013 \r
2014         xQueueSetMemberHandle xQueueSelectFromSet( xQueueSetHandle xQueueSet, portTickType xBlockTimeTicks )\r
2015         {\r
2016         xQueueSetMemberHandle xReturn = NULL;\r
2017 \r
2018                 ( void ) xQueueGenericReceive( ( xQueueHandle ) xQueueSet, &xReturn, xBlockTimeTicks, pdFALSE ); /*lint !e961 Casting from one typedef to another is not redundant. */\r
2019                 return xReturn;\r
2020         }\r
2021 \r
2022 #endif /* configUSE_QUEUE_SETS */\r
2023 /*-----------------------------------------------------------*/\r
2024 \r
2025 #if ( configUSE_QUEUE_SETS == 1 )\r
2026 \r
2027         xQueueSetMemberHandle xQueueSelectFromSetFromISR( xQueueSetHandle xQueueSet )\r
2028         {\r
2029         xQueueSetMemberHandle xReturn = NULL;\r
2030 \r
2031                 ( void ) xQueueReceiveFromISR( ( xQueueHandle ) xQueueSet, &xReturn, NULL ); /*lint !e961 Casting from one typedef to another is not redundant. */\r
2032                 return xReturn;\r
2033         }\r
2034 \r
2035 #endif /* configUSE_QUEUE_SETS */\r
2036 /*-----------------------------------------------------------*/\r
2037 \r
2038 #if ( configUSE_QUEUE_SETS == 1 )\r
2039 \r
2040         static portBASE_TYPE prvNotifyQueueSetContainer( const xQUEUE * const pxQueue, portBASE_TYPE xCopyPosition )\r
2041         {\r
2042         xQUEUE *pxQueueSetContainer = pxQueue->pxQueueSetContainer;\r
2043         portBASE_TYPE xReturn = pdFALSE;\r
2044 \r
2045                 configASSERT( pxQueueSetContainer );\r
2046                 configASSERT( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength );\r
2047 \r
2048                 if( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength )\r
2049                 {\r
2050                         traceQUEUE_SEND( pxQueueSetContainer );\r
2051                         /* The data copies is the handle of the queue that contains data. */\r
2052                         prvCopyDataToQueue( pxQueueSetContainer, &pxQueue, xCopyPosition );\r
2053                         if( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE )\r
2054                         {\r
2055                                 if( xTaskRemoveFromEventList( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) != pdFALSE )\r
2056                                 {\r
2057                                         /* The task waiting has a higher priority */\r
2058                                         xReturn = pdTRUE;\r
2059                                 }\r
2060                         }\r
2061                 }\r
2062 \r
2063                 return xReturn;\r
2064         }\r
2065 \r
2066 #endif /* configUSE_QUEUE_SETS */\r
2067 \r