]> git.sur5r.net Git - freertos/blob - Source/queue.c
Add some configASSERT() calls.
[freertos] / Source / queue.c
1 /*\r
2     FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3 \r
4     ***************************************************************************\r
5     *                                                                         *\r
6     * If you are:                                                             *\r
7     *                                                                         *\r
8     *    + New to FreeRTOS,                                                   *\r
9     *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
10     *    + Looking for basic training,                                        *\r
11     *    + Wanting to improve your FreeRTOS skills and productivity           *\r
12     *                                                                         *\r
13     * then take a look at the FreeRTOS books - available as PDF or paperback  *\r
14     *                                                                         *\r
15     *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
16     *                  http://www.FreeRTOS.org/Documentation                  *\r
17     *                                                                         *\r
18     * A pdf reference manual is also available.  Both are usually delivered   *\r
19     * to your inbox within 20 minutes to two hours when purchased between 8am *\r
20     * and 8pm GMT (although please allow up to 24 hours in case of            *\r
21     * exceptional circumstances).  Thank you for your support!                *\r
22     *                                                                         *\r
23     ***************************************************************************\r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     ***NOTE*** The exception to the GPL is included to allow you to distribute\r
31     a combined work that includes FreeRTOS without being obliged to provide the\r
32     source code for proprietary components outside of the FreeRTOS kernel.\r
33     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
34     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
35     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 #include <stdlib.h>\r
55 #include <string.h>\r
56 \r
57 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining\r
58 all the API functions to use the MPU wrappers.  That should only be done when\r
59 task.h is included from an application file. */\r
60 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE\r
61 \r
62 #include "FreeRTOS.h"\r
63 #include "task.h"\r
64 #include "croutine.h"\r
65 \r
66 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE\r
67 \r
68 /*-----------------------------------------------------------\r
69  * PUBLIC LIST API documented in list.h\r
70  *----------------------------------------------------------*/\r
71 \r
72 /* Constants used with the cRxLock and cTxLock structure members. */\r
73 #define queueUNLOCKED                                   ( ( signed portBASE_TYPE ) -1 )\r
74 #define queueLOCKED_UNMODIFIED                  ( ( signed portBASE_TYPE ) 0 )\r
75 \r
76 #define queueERRONEOUS_UNBLOCK                  ( -1 )\r
77 \r
78 /* For internal use only. */\r
79 #define queueSEND_TO_BACK                               ( 0 )\r
80 #define queueSEND_TO_FRONT                              ( 1 )\r
81 \r
82 /* Effectively make a union out of the xQUEUE structure. */\r
83 #define pxMutexHolder                                   pcTail\r
84 #define uxQueueType                                             pcHead\r
85 #define uxRecursiveCallCount                    pcReadFrom\r
86 #define queueQUEUE_IS_MUTEX                             NULL\r
87 \r
88 /* Semaphores do not actually store or copy data, so have an items size of\r
89 zero. */\r
90 #define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( 0 )\r
91 #define queueDONT_BLOCK                                  ( ( portTickType ) 0 )\r
92 #define queueMUTEX_GIVE_BLOCK_TIME               ( ( portTickType ) 0 )\r
93 \r
94 /*\r
95  * Definition of the queue used by the scheduler.\r
96  * Items are queued by copy, not reference.\r
97  */\r
98 typedef struct QueueDefinition\r
99 {\r
100         signed char *pcHead;                            /*< Points to the beginning of the queue storage area. */\r
101         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
102 \r
103         signed char *pcWriteTo;                         /*< Points to the free next place in the storage area. */\r
104         signed char *pcReadFrom;                        /*< Points to the last place that a queued item was read from. */\r
105 \r
106         xList xTasksWaitingToSend;                              /*< List of tasks that are blocked waiting to post onto this queue.  Stored in priority order. */\r
107         xList xTasksWaitingToReceive;                   /*< List of tasks that are blocked waiting to read from this queue.  Stored in priority order. */\r
108 \r
109         volatile unsigned portBASE_TYPE uxMessagesWaiting;/*< The number of items currently in the queue. */\r
110         unsigned portBASE_TYPE uxLength;                /*< The length of the queue defined as the number of items it will hold, not the number of bytes. */\r
111         unsigned portBASE_TYPE uxItemSize;              /*< The size of each items that the queue will hold. */\r
112 \r
113         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
114         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
115 \r
116 } xQUEUE;\r
117 /*-----------------------------------------------------------*/\r
118 \r
119 /*\r
120  * Inside this file xQueueHandle is a pointer to a xQUEUE structure.\r
121  * To keep the definition private the API header file defines it as a\r
122  * pointer to void.\r
123  */\r
124 typedef xQUEUE * xQueueHandle;\r
125 \r
126 /*\r
127  * Prototypes for public functions are included here so we don't have to\r
128  * include the API header file (as it defines xQueueHandle differently).  These\r
129  * functions are documented in the API header file.\r
130  */\r
131 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize ) PRIVILEGED_FUNCTION;\r
132 signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;\r
133 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
134 void vQueueDelete( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;\r
135 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;\r
136 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) PRIVILEGED_FUNCTION;\r
137 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken ) PRIVILEGED_FUNCTION;\r
138 xQueueHandle xQueueCreateMutex( void ) PRIVILEGED_FUNCTION;\r
139 xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount ) PRIVILEGED_FUNCTION;\r
140 portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime ) PRIVILEGED_FUNCTION;\r
141 portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle xMutex ) PRIVILEGED_FUNCTION;\r
142 signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION;\r
143 signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) PRIVILEGED_FUNCTION;\r
144 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
145 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
146 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
147 \r
148 /*\r
149  * Co-routine queue functions differ from task queue functions.  Co-routines are\r
150  * an optional component.\r
151  */\r
152 #if configUSE_CO_ROUTINES == 1\r
153         signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken ) PRIVILEGED_FUNCTION;\r
154         signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxTaskWoken ) PRIVILEGED_FUNCTION;\r
155         signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
156         signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
157 #endif\r
158 \r
159 /*\r
160  * The queue registry is just a means for kernel aware debuggers to locate\r
161  * queue structures.  It has no other purpose so is an optional component.\r
162  */\r
163 #if configQUEUE_REGISTRY_SIZE > 0\r
164 \r
165         /* The type stored within the queue registry array.  This allows a name\r
166         to be assigned to each queue making kernel aware debugging a little\r
167         more user friendly. */\r
168         typedef struct QUEUE_REGISTRY_ITEM\r
169         {\r
170                 signed char *pcQueueName;\r
171                 xQueueHandle xHandle;\r
172         } xQueueRegistryItem;\r
173 \r
174         /* The queue registry is simply an array of xQueueRegistryItem structures.\r
175         The pcQueueName member of a structure being NULL is indicative of the\r
176         array position being vacant. */\r
177         xQueueRegistryItem xQueueRegistry[ configQUEUE_REGISTRY_SIZE ];\r
178 \r
179         /* Removes a queue from the registry by simply setting the pcQueueName\r
180         member to NULL. */\r
181         static void vQueueUnregisterQueue( xQueueHandle xQueue ) PRIVILEGED_FUNCTION;\r
182         void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcQueueName ) PRIVILEGED_FUNCTION;\r
183 #endif\r
184 \r
185 /*\r
186  * Unlocks a queue locked by a call to prvLockQueue.  Locking a queue does not\r
187  * prevent an ISR from adding or removing items to the queue, but does prevent\r
188  * an ISR from removing tasks from the queue event lists.  If an ISR finds a\r
189  * queue is locked it will instead increment the appropriate queue lock count\r
190  * to indicate that a task may require unblocking.  When the queue in unlocked\r
191  * these lock counts are inspected, and the appropriate action taken.\r
192  */\r
193 static void prvUnlockQueue( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
194 \r
195 /*\r
196  * Uses a critical section to determine if there is any data in a queue.\r
197  *\r
198  * @return pdTRUE if the queue contains no items, otherwise pdFALSE.\r
199  */\r
200 static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
201 \r
202 /*\r
203  * Uses a critical section to determine if there is any space in a queue.\r
204  *\r
205  * @return pdTRUE if there is no space, otherwise pdFALSE;\r
206  */\r
207 static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
208 \r
209 /*\r
210  * Copies an item into the queue, either at the front of the queue or the\r
211  * back of the queue.\r
212  */\r
213 static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition ) PRIVILEGED_FUNCTION;\r
214 \r
215 /*\r
216  * Copies an item out of a queue.\r
217  */\r
218 static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer ) PRIVILEGED_FUNCTION;\r
219 /*-----------------------------------------------------------*/\r
220 \r
221 /*\r
222  * Macro to mark a queue as locked.  Locking a queue prevents an ISR from\r
223  * accessing the queue event lists.\r
224  */\r
225 #define prvLockQueue( pxQueue )                                                         \\r
226         taskENTER_CRITICAL();                                                                   \\r
227         {                                                                                                               \\r
228                 if( ( pxQueue )->xRxLock == queueUNLOCKED )                     \\r
229                 {                                                                                                       \\r
230                         ( pxQueue )->xRxLock = queueLOCKED_UNMODIFIED;  \\r
231                 }                                                                                                       \\r
232                 if( ( pxQueue )->xTxLock == queueUNLOCKED )                     \\r
233                 {                                                                                                       \\r
234                         ( pxQueue )->xTxLock = queueLOCKED_UNMODIFIED;  \\r
235                 }                                                                                                       \\r
236         }                                                                                                               \\r
237         taskEXIT_CRITICAL()\r
238 /*-----------------------------------------------------------*/\r
239 \r
240 \r
241 /*-----------------------------------------------------------\r
242  * PUBLIC QUEUE MANAGEMENT API documented in queue.h\r
243  *----------------------------------------------------------*/\r
244 \r
245 xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize )\r
246 {\r
247 xQUEUE *pxNewQueue;\r
248 size_t xQueueSizeInBytes;\r
249 xQueueHandle xReturn = NULL;\r
250 \r
251         /* Allocate the new queue structure. */\r
252         if( uxQueueLength > ( unsigned portBASE_TYPE ) 0 )\r
253         {\r
254                 pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );\r
255                 if( pxNewQueue != NULL )\r
256                 {\r
257                         /* Create the list of pointers to queue items.  The queue is one byte\r
258                         longer than asked for to make wrap checking easier/faster. */\r
259                         xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ) + ( size_t ) 1;\r
260 \r
261                         pxNewQueue->pcHead = ( signed char * ) pvPortMalloc( xQueueSizeInBytes );\r
262                         if( pxNewQueue->pcHead != NULL )\r
263                         {\r
264                                 /* Initialise the queue members as described above where the\r
265                                 queue type is defined. */\r
266                                 pxNewQueue->pcTail = pxNewQueue->pcHead + ( uxQueueLength * uxItemSize );\r
267                                 pxNewQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U;\r
268                                 pxNewQueue->pcWriteTo = pxNewQueue->pcHead;\r
269                                 pxNewQueue->pcReadFrom = pxNewQueue->pcHead + ( ( uxQueueLength - ( unsigned portBASE_TYPE ) 1U ) * uxItemSize );\r
270                                 pxNewQueue->uxLength = uxQueueLength;\r
271                                 pxNewQueue->uxItemSize = uxItemSize;\r
272                                 pxNewQueue->xRxLock = queueUNLOCKED;\r
273                                 pxNewQueue->xTxLock = queueUNLOCKED;\r
274 \r
275                                 /* Likewise ensure the event queues start with the correct state. */\r
276                                 vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) );\r
277                                 vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );\r
278 \r
279                                 traceQUEUE_CREATE( pxNewQueue );\r
280                                 xReturn = pxNewQueue;\r
281                         }\r
282                         else\r
283                         {\r
284                                 traceQUEUE_CREATE_FAILED();\r
285                                 vPortFree( pxNewQueue );\r
286                         }\r
287                 }\r
288         }\r
289 \r
290         configASSERT( xReturn );\r
291 \r
292         return xReturn;\r
293 }\r
294 /*-----------------------------------------------------------*/\r
295 \r
296 #if ( configUSE_MUTEXES == 1 )\r
297 \r
298         xQueueHandle xQueueCreateMutex( void )\r
299         {\r
300         xQUEUE *pxNewQueue;\r
301 \r
302                 /* Allocate the new queue structure. */\r
303                 pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );\r
304                 if( pxNewQueue != NULL )\r
305                 {\r
306                         /* Information required for priority inheritance. */\r
307                         pxNewQueue->pxMutexHolder = NULL;\r
308                         pxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX;\r
309 \r
310                         /* Queues used as a mutex no data is actually copied into or out\r
311                         of the queue. */\r
312                         pxNewQueue->pcWriteTo = NULL;\r
313                         pxNewQueue->pcReadFrom = NULL;\r
314 \r
315                         /* Each mutex has a length of 1 (like a binary semaphore) and\r
316                         an item size of 0 as nothing is actually copied into or out\r
317                         of the mutex. */\r
318                         pxNewQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U;\r
319                         pxNewQueue->uxLength = ( unsigned portBASE_TYPE ) 1U;\r
320                         pxNewQueue->uxItemSize = ( unsigned portBASE_TYPE ) 0U;\r
321                         pxNewQueue->xRxLock = queueUNLOCKED;\r
322                         pxNewQueue->xTxLock = queueUNLOCKED;\r
323 \r
324                         /* Ensure the event queues start with the correct state. */\r
325                         vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) );\r
326                         vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );\r
327 \r
328                         /* Start with the semaphore in the expected state. */\r
329                         xQueueGenericSend( pxNewQueue, NULL, ( portTickType ) 0U, queueSEND_TO_BACK );\r
330 \r
331                         traceCREATE_MUTEX( pxNewQueue );\r
332                 }\r
333                 else\r
334                 {\r
335                         traceCREATE_MUTEX_FAILED();\r
336                 }\r
337 \r
338                 configASSERT( pxNewQueue );\r
339                 return pxNewQueue;\r
340         }\r
341 \r
342 #endif /* configUSE_MUTEXES */\r
343 /*-----------------------------------------------------------*/\r
344 \r
345 #if configUSE_RECURSIVE_MUTEXES == 1\r
346 \r
347         portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex )\r
348         {\r
349         portBASE_TYPE xReturn;\r
350 \r
351                 configASSERT( pxMutex );\r
352 \r
353                 /* If this is the task that holds the mutex then pxMutexHolder will not\r
354                 change outside of this task.  If this task does not hold the mutex then\r
355                 pxMutexHolder can never coincidentally equal the tasks handle, and as\r
356                 this is the only condition we are interested in it does not matter if\r
357                 pxMutexHolder is accessed simultaneously by another task.  Therefore no\r
358                 mutual exclusion is required to test the pxMutexHolder variable. */\r
359                 if( pxMutex->pxMutexHolder == xTaskGetCurrentTaskHandle() )\r
360                 {\r
361                         traceGIVE_MUTEX_RECURSIVE( pxMutex );\r
362 \r
363                         /* uxRecursiveCallCount cannot be zero if pxMutexHolder is equal to\r
364                         the task handle, therefore no underflow check is required.  Also,\r
365                         uxRecursiveCallCount is only modified by the mutex holder, and as\r
366                         there can only be one, no mutual exclusion is required to modify the\r
367                         uxRecursiveCallCount member. */\r
368                         ( pxMutex->uxRecursiveCallCount )--;\r
369 \r
370                         /* Have we unwound the call count? */\r
371                         if( pxMutex->uxRecursiveCallCount == 0 )\r
372                         {\r
373                                 /* Return the mutex.  This will automatically unblock any other\r
374                                 task that might be waiting to access the mutex. */\r
375                                 xQueueGenericSend( pxMutex, NULL, queueMUTEX_GIVE_BLOCK_TIME, queueSEND_TO_BACK );\r
376                         }\r
377 \r
378                         xReturn = pdPASS;\r
379                 }\r
380                 else\r
381                 {\r
382                         /* We cannot give the mutex because we are not the holder. */\r
383                         xReturn = pdFAIL;\r
384 \r
385                         traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex );\r
386                 }\r
387 \r
388                 return xReturn;\r
389         }\r
390 \r
391 #endif /* configUSE_RECURSIVE_MUTEXES */\r
392 /*-----------------------------------------------------------*/\r
393 \r
394 #if configUSE_RECURSIVE_MUTEXES == 1\r
395 \r
396         portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime )\r
397         {\r
398         portBASE_TYPE xReturn;\r
399 \r
400                 configASSERT( pxMutex );\r
401 \r
402                 /* Comments regarding mutual exclusion as per those within\r
403                 xQueueGiveMutexRecursive(). */\r
404 \r
405                 traceTAKE_MUTEX_RECURSIVE( pxMutex );\r
406 \r
407                 if( pxMutex->pxMutexHolder == xTaskGetCurrentTaskHandle() )\r
408                 {\r
409                         ( pxMutex->uxRecursiveCallCount )++;\r
410                         xReturn = pdPASS;\r
411                 }\r
412                 else\r
413                 {\r
414                         xReturn = xQueueGenericReceive( pxMutex, NULL, xBlockTime, pdFALSE );\r
415 \r
416                         /* pdPASS will only be returned if we successfully obtained the mutex,\r
417                         we may have blocked to reach here. */\r
418                         if( xReturn == pdPASS )\r
419                         {\r
420                                 ( pxMutex->uxRecursiveCallCount )++;\r
421                         }\r
422                         else\r
423                         {\r
424                                 traceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex );\r
425                         }\r
426                 }\r
427 \r
428                 return xReturn;\r
429         }\r
430 \r
431 #endif /* configUSE_RECURSIVE_MUTEXES */\r
432 /*-----------------------------------------------------------*/\r
433 \r
434 #if configUSE_COUNTING_SEMAPHORES == 1\r
435 \r
436         xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount )\r
437         {\r
438         xQueueHandle pxHandle;\r
439 \r
440                 pxHandle = xQueueCreate( ( unsigned portBASE_TYPE ) uxCountValue, queueSEMAPHORE_QUEUE_ITEM_LENGTH );\r
441 \r
442                 if( pxHandle != NULL )\r
443                 {\r
444                         pxHandle->uxMessagesWaiting = uxInitialCount;\r
445 \r
446                         traceCREATE_COUNTING_SEMAPHORE();\r
447                 }\r
448                 else\r
449                 {\r
450                         traceCREATE_COUNTING_SEMAPHORE_FAILED();\r
451                 }\r
452 \r
453                 configASSERT( pxHandle );\r
454                 return pxHandle;\r
455         }\r
456 \r
457 #endif /* configUSE_COUNTING_SEMAPHORES */\r
458 /*-----------------------------------------------------------*/\r
459 \r
460 signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )\r
461 {\r
462 signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
463 xTimeOutType xTimeOut;\r
464 \r
465         configASSERT( pxQueue );\r
466         configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
467 \r
468         /* This function relaxes the coding standard somewhat to allow return\r
469         statements within the function itself.  This is done in the interest\r
470         of execution time efficiency. */\r
471         for( ;; )\r
472         {\r
473                 taskENTER_CRITICAL();\r
474                 {\r
475                         /* Is there room on the queue now?  To be running we must be\r
476                         the highest priority task wanting to access the queue. */\r
477                         if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
478                         {\r
479                                 traceQUEUE_SEND( pxQueue );\r
480                                 prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
481 \r
482                                 /* If there was a task waiting for data to arrive on the\r
483                                 queue then unblock it now. */\r
484                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
485                                 {\r
486                                         if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )\r
487                                         {\r
488                                                 /* The unblocked task has a priority higher than\r
489                                                 our own so yield immediately.  Yes it is ok to do\r
490                                                 this from within the critical section - the kernel\r
491                                                 takes care of that. */\r
492                                                 portYIELD_WITHIN_API();\r
493                                         }\r
494                                 }\r
495 \r
496                                 taskEXIT_CRITICAL();\r
497 \r
498                                 /* Return to the original privilege level before exiting the\r
499                                 function. */\r
500                                 return pdPASS;\r
501                         }\r
502                         else\r
503                         {\r
504                                 if( xTicksToWait == ( portTickType ) 0 )\r
505                                 {\r
506                                         /* The queue was full and no block time is specified (or\r
507                                         the block time has expired) so leave now. */\r
508                                         taskEXIT_CRITICAL();\r
509 \r
510                                         /* Return to the original privilege level before exiting\r
511                                         the function. */\r
512                                         traceQUEUE_SEND_FAILED( pxQueue );\r
513                                         return errQUEUE_FULL;\r
514                                 }\r
515                                 else if( xEntryTimeSet == pdFALSE )\r
516                                 {\r
517                                         /* The queue was full and a block time was specified so\r
518                                         configure the timeout structure. */\r
519                                         vTaskSetTimeOutState( &xTimeOut );\r
520                                         xEntryTimeSet = pdTRUE;\r
521                                 }\r
522                         }\r
523                 }\r
524                 taskEXIT_CRITICAL();\r
525 \r
526                 /* Interrupts and other tasks can send to and receive from the queue\r
527                 now the critical section has been exited. */\r
528 \r
529                 vTaskSuspendAll();\r
530                 prvLockQueue( pxQueue );\r
531 \r
532                 /* Update the timeout state to see if it has expired yet. */\r
533                 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
534                 {\r
535                         if( prvIsQueueFull( pxQueue ) )\r
536                         {\r
537                                 traceBLOCKING_ON_QUEUE_SEND( pxQueue );\r
538                                 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );\r
539 \r
540                                 /* Unlocking the queue means queue events can effect the\r
541                                 event list.  It is possible     that interrupts occurring now\r
542                                 remove this task from the event list again - but as the\r
543                                 scheduler is suspended the task will go onto the pending\r
544                                 ready last instead of the actual ready list. */\r
545                                 prvUnlockQueue( pxQueue );\r
546 \r
547                                 /* Resuming the scheduler will move tasks from the pending\r
548                                 ready list into the ready list - so it is feasible that this\r
549                                 task is already in a ready list before it yields - in which\r
550                                 case the yield will not cause a context switch unless there\r
551                                 is also a higher priority task in the pending ready list. */\r
552                                 if( !xTaskResumeAll() )\r
553                                 {\r
554                                         portYIELD_WITHIN_API();\r
555                                 }\r
556                         }\r
557                         else\r
558                         {\r
559                                 /* Try again. */\r
560                                 prvUnlockQueue( pxQueue );\r
561                                 ( void ) xTaskResumeAll();\r
562                         }\r
563                 }\r
564                 else\r
565                 {\r
566                         /* The timeout has expired. */\r
567                         prvUnlockQueue( pxQueue );\r
568                         ( void ) xTaskResumeAll();\r
569 \r
570                         /* Return to the original privilege level before exiting the\r
571                         function. */\r
572                         traceQUEUE_SEND_FAILED( pxQueue );\r
573                         return errQUEUE_FULL;\r
574                 }\r
575         }\r
576 }\r
577 /*-----------------------------------------------------------*/\r
578 \r
579 #if configUSE_ALTERNATIVE_API == 1\r
580 \r
581         signed portBASE_TYPE xQueueAltGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )\r
582         {\r
583         signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
584         xTimeOutType xTimeOut;\r
585 \r
586                 configASSERT( pxQueue );\r
587                 configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
588 \r
589                 for( ;; )\r
590                 {\r
591                         taskENTER_CRITICAL();\r
592                         {\r
593                                 /* Is there room on the queue now?  To be running we must be\r
594                                 the highest priority task wanting to access the queue. */\r
595                                 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
596                                 {\r
597                                         traceQUEUE_SEND( pxQueue );\r
598                                         prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
599 \r
600                                         /* If there was a task waiting for data to arrive on the\r
601                                         queue then unblock it now. */\r
602                                         if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
603                                         {\r
604                                                 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) == pdTRUE )\r
605                                                 {\r
606                                                         /* The unblocked task has a priority higher than\r
607                                                         our own so yield immediately. */\r
608                                                         portYIELD_WITHIN_API();\r
609                                                 }\r
610                                         }\r
611 \r
612                                         taskEXIT_CRITICAL();\r
613                                         return pdPASS;\r
614                                 }\r
615                                 else\r
616                                 {\r
617                                         if( xTicksToWait == ( portTickType ) 0 )\r
618                                         {\r
619                                                 taskEXIT_CRITICAL();\r
620                                                 return errQUEUE_FULL;\r
621                                         }\r
622                                         else if( xEntryTimeSet == pdFALSE )\r
623                                         {\r
624                                                 vTaskSetTimeOutState( &xTimeOut );\r
625                                                 xEntryTimeSet = pdTRUE;\r
626                                         }\r
627                                 }\r
628                         }\r
629                         taskEXIT_CRITICAL();\r
630 \r
631                         taskENTER_CRITICAL();\r
632                         {\r
633                                 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
634                                 {\r
635                                         if( prvIsQueueFull( pxQueue ) )\r
636                                         {\r
637                                                 traceBLOCKING_ON_QUEUE_SEND( pxQueue );\r
638                                                 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );\r
639                                                 portYIELD_WITHIN_API();\r
640                                         }\r
641                                 }\r
642                                 else\r
643                                 {\r
644                                         taskEXIT_CRITICAL();\r
645                                         traceQUEUE_SEND_FAILED( pxQueue );\r
646                                         return errQUEUE_FULL;\r
647                                 }\r
648                         }\r
649                         taskEXIT_CRITICAL();\r
650                 }\r
651         }\r
652 \r
653 #endif /* configUSE_ALTERNATIVE_API */\r
654 /*-----------------------------------------------------------*/\r
655 \r
656 #if configUSE_ALTERNATIVE_API == 1\r
657 \r
658         signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )\r
659         {\r
660         signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
661         xTimeOutType xTimeOut;\r
662         signed char *pcOriginalReadPosition;\r
663 \r
664                 configASSERT( pxQueue );\r
665                 configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
666 \r
667                 for( ;; )\r
668                 {\r
669                         taskENTER_CRITICAL();\r
670                         {\r
671                                 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
672                                 {\r
673                                         /* Remember our read position in case we are just peeking. */\r
674                                         pcOriginalReadPosition = pxQueue->pcReadFrom;\r
675 \r
676                                         prvCopyDataFromQueue( pxQueue, pvBuffer );\r
677 \r
678                                         if( xJustPeeking == pdFALSE )\r
679                                         {\r
680                                                 traceQUEUE_RECEIVE( pxQueue );\r
681 \r
682                                                 /* We are actually removing data. */\r
683                                                 --( pxQueue->uxMessagesWaiting );\r
684 \r
685                                                 #if ( configUSE_MUTEXES == 1 )\r
686                                                 {\r
687                                                         if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
688                                                         {\r
689                                                                 /* Record the information required to implement\r
690                                                                 priority inheritance should it become necessary. */\r
691                                                                 pxQueue->pxMutexHolder = xTaskGetCurrentTaskHandle();\r
692                                                         }\r
693                                                 }\r
694                                                 #endif\r
695 \r
696                                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
697                                                 {\r
698                                                         if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )\r
699                                                         {\r
700                                                                 portYIELD_WITHIN_API();\r
701                                                         }\r
702                                                 }\r
703                                         }\r
704                                         else\r
705                                         {\r
706                                                 traceQUEUE_PEEK( pxQueue );\r
707 \r
708                                                 /* We are not removing the data, so reset our read\r
709                                                 pointer. */\r
710                                                 pxQueue->pcReadFrom = pcOriginalReadPosition;\r
711 \r
712                                                 /* The data is being left in the queue, so see if there are\r
713                                                 any other tasks waiting for the data. */\r
714                                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
715                                                 {\r
716                                                         /* Tasks that are removed from the event list will get added to\r
717                                                         the pending ready list as the scheduler is still suspended. */\r
718                                                         if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
719                                                         {\r
720                                                                 /* The task waiting has a higher priority than this task. */\r
721                                                                 portYIELD_WITHIN_API();\r
722                                                         }\r
723                                                 }\r
724 \r
725                                         }\r
726 \r
727                                         taskEXIT_CRITICAL();\r
728                                         return pdPASS;\r
729                                 }\r
730                                 else\r
731                                 {\r
732                                         if( xTicksToWait == ( portTickType ) 0 )\r
733                                         {\r
734                                                 taskEXIT_CRITICAL();\r
735                                                 traceQUEUE_RECEIVE_FAILED( pxQueue );\r
736                                                 return errQUEUE_EMPTY;\r
737                                         }\r
738                                         else if( xEntryTimeSet == pdFALSE )\r
739                                         {\r
740                                                 vTaskSetTimeOutState( &xTimeOut );\r
741                                                 xEntryTimeSet = pdTRUE;\r
742                                         }\r
743                                 }\r
744                         }\r
745                         taskEXIT_CRITICAL();\r
746 \r
747                         taskENTER_CRITICAL();\r
748                         {\r
749                                 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
750                                 {\r
751                                         if( prvIsQueueEmpty( pxQueue ) )\r
752                                         {\r
753                                                 traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
754 \r
755                                                 #if ( configUSE_MUTEXES == 1 )\r
756                                                 {\r
757                                                         if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
758                                                         {\r
759                                                                 portENTER_CRITICAL();\r
760                                                                         vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );\r
761                                                                 portEXIT_CRITICAL();\r
762                                                         }\r
763                                                 }\r
764                                                 #endif\r
765 \r
766                                                 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
767                                                 portYIELD_WITHIN_API();\r
768                                         }\r
769                                 }\r
770                                 else\r
771                                 {\r
772                                         taskEXIT_CRITICAL();\r
773                                         traceQUEUE_RECEIVE_FAILED( pxQueue );\r
774                                         return errQUEUE_EMPTY;\r
775                                 }\r
776                         }\r
777                         taskEXIT_CRITICAL();\r
778                 }\r
779         }\r
780 \r
781 \r
782 #endif /* configUSE_ALTERNATIVE_API */\r
783 /*-----------------------------------------------------------*/\r
784 \r
785 signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition )\r
786 {\r
787 signed portBASE_TYPE xReturn;\r
788 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
789 \r
790         configASSERT( pxQueue );\r
791         configASSERT( pxHigherPriorityTaskWoken );\r
792         configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
793 \r
794         /* Similar to xQueueGenericSend, except we don't block if there is no room\r
795         in the queue.  Also we don't directly wake a task that was blocked on a\r
796         queue read, instead we return a flag to say whether a context switch is\r
797         required or not (i.e. has a task with a higher priority than us been woken\r
798         by this post). */\r
799         uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
800         {\r
801                 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
802                 {\r
803                         traceQUEUE_SEND_FROM_ISR( pxQueue );\r
804 \r
805                         prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
806 \r
807                         /* If the queue is locked we do not alter the event list.  This will\r
808                         be done when the queue is unlocked later. */\r
809                         if( pxQueue->xTxLock == queueUNLOCKED )\r
810                         {\r
811                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
812                                 {\r
813                                         if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
814                                         {\r
815                                                 /* The task waiting has a higher priority so record that a\r
816                                                 context switch is required. */\r
817                                                 *pxHigherPriorityTaskWoken = pdTRUE;\r
818                                         }\r
819                                 }\r
820                         }\r
821                         else\r
822                         {\r
823                                 /* Increment the lock count so the task that unlocks the queue\r
824                                 knows that data was posted while it was locked. */\r
825                                 ++( pxQueue->xTxLock );\r
826                         }\r
827 \r
828                         xReturn = pdPASS;\r
829                 }\r
830                 else\r
831                 {\r
832                         traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );\r
833                         xReturn = errQUEUE_FULL;\r
834                 }\r
835         }\r
836         portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
837 \r
838         return xReturn;\r
839 }\r
840 /*-----------------------------------------------------------*/\r
841 \r
842 signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )\r
843 {\r
844 signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
845 xTimeOutType xTimeOut;\r
846 signed char *pcOriginalReadPosition;\r
847 \r
848         configASSERT( pxQueue );\r
849         configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
850 \r
851         /* This function relaxes the coding standard somewhat to allow return\r
852         statements within the function itself.  This is done in the interest\r
853         of execution time efficiency. */\r
854 \r
855         for( ;; )\r
856         {\r
857                 taskENTER_CRITICAL();\r
858                 {\r
859                         /* Is there data in the queue now?  To be running we must be\r
860                         the highest priority task wanting to access the queue. */\r
861                         if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
862                         {\r
863                                 /* Remember our read position in case we are just peeking. */\r
864                                 pcOriginalReadPosition = pxQueue->pcReadFrom;\r
865 \r
866                                 prvCopyDataFromQueue( pxQueue, pvBuffer );\r
867 \r
868                                 if( xJustPeeking == pdFALSE )\r
869                                 {\r
870                                         traceQUEUE_RECEIVE( pxQueue );\r
871 \r
872                                         /* We are actually removing data. */\r
873                                         --( pxQueue->uxMessagesWaiting );\r
874 \r
875                                         #if ( configUSE_MUTEXES == 1 )\r
876                                         {\r
877                                                 if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
878                                                 {\r
879                                                         /* Record the information required to implement\r
880                                                         priority inheritance should it become necessary. */\r
881                                                         pxQueue->pxMutexHolder = xTaskGetCurrentTaskHandle();\r
882                                                 }\r
883                                         }\r
884                                         #endif\r
885 \r
886                                         if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
887                                         {\r
888                                                 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )\r
889                                                 {\r
890                                                         portYIELD_WITHIN_API();\r
891                                                 }\r
892                                         }\r
893                                 }\r
894                                 else\r
895                                 {\r
896                                         traceQUEUE_PEEK( pxQueue );\r
897 \r
898                                         /* We are not removing the data, so reset our read\r
899                                         pointer. */\r
900                                         pxQueue->pcReadFrom = pcOriginalReadPosition;\r
901 \r
902                                         /* The data is being left in the queue, so see if there are\r
903                                         any other tasks waiting for the data. */\r
904                                         if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
905                                         {\r
906                                                 /* Tasks that are removed from the event list will get added to\r
907                                                 the pending ready list as the scheduler is still suspended. */\r
908                                                 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
909                                                 {\r
910                                                         /* The task waiting has a higher priority than this task. */\r
911                                                         portYIELD_WITHIN_API();\r
912                                                 }\r
913                                         }\r
914 \r
915                                 }\r
916 \r
917                                 taskEXIT_CRITICAL();\r
918                                 return pdPASS;\r
919                         }\r
920                         else\r
921                         {\r
922                                 if( xTicksToWait == ( portTickType ) 0 )\r
923                                 {\r
924                                         /* The queue was empty and no block time is specified (or\r
925                                         the block time has expired) so leave now. */\r
926                                         taskEXIT_CRITICAL();\r
927                                         traceQUEUE_RECEIVE_FAILED( pxQueue );\r
928                                         return errQUEUE_EMPTY;\r
929                                 }\r
930                                 else if( xEntryTimeSet == pdFALSE )\r
931                                 {\r
932                                         /* The queue was empty and a block time was specified so\r
933                                         configure the timeout structure. */\r
934                                         vTaskSetTimeOutState( &xTimeOut );\r
935                                         xEntryTimeSet = pdTRUE;\r
936                                 }\r
937                         }\r
938                 }\r
939                 taskEXIT_CRITICAL();\r
940 \r
941                 /* Interrupts and other tasks can send to and receive from the queue\r
942                 now the critical section has been exited. */\r
943 \r
944                 vTaskSuspendAll();\r
945                 prvLockQueue( pxQueue );\r
946 \r
947                 /* Update the timeout state to see if it has expired yet. */\r
948                 if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
949                 {\r
950                         if( prvIsQueueEmpty( pxQueue ) )\r
951                         {\r
952                                 traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
953 \r
954                                 #if ( configUSE_MUTEXES == 1 )\r
955                                 {\r
956                                         if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
957                                         {\r
958                                                 portENTER_CRITICAL();\r
959                                                 {\r
960                                                         vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );\r
961                                                 }\r
962                                                 portEXIT_CRITICAL();\r
963                                         }\r
964                                 }\r
965                                 #endif\r
966 \r
967                                 vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
968                                 prvUnlockQueue( pxQueue );\r
969                                 if( !xTaskResumeAll() )\r
970                                 {\r
971                                         portYIELD_WITHIN_API();\r
972                                 }\r
973                         }\r
974                         else\r
975                         {\r
976                                 /* Try again. */\r
977                                 prvUnlockQueue( pxQueue );\r
978                                 ( void ) xTaskResumeAll();\r
979                         }\r
980                 }\r
981                 else\r
982                 {\r
983                         prvUnlockQueue( pxQueue );\r
984                         ( void ) xTaskResumeAll();\r
985                         traceQUEUE_RECEIVE_FAILED( pxQueue );\r
986                         return errQUEUE_EMPTY;\r
987                 }\r
988         }\r
989 }\r
990 /*-----------------------------------------------------------*/\r
991 \r
992 signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken )\r
993 {\r
994 signed portBASE_TYPE xReturn;\r
995 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
996 \r
997         configASSERT( pxQueue );\r
998         configASSERT( pxTaskWoken );\r
999         configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
1000 \r
1001         uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
1002         {\r
1003                 /* We cannot block from an ISR, so check there is data available. */\r
1004                 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
1005                 {\r
1006                         traceQUEUE_RECEIVE_FROM_ISR( pxQueue );\r
1007 \r
1008                         prvCopyDataFromQueue( pxQueue, pvBuffer );\r
1009                         --( pxQueue->uxMessagesWaiting );\r
1010 \r
1011                         /* If the queue is locked we will not modify the event list.  Instead\r
1012                         we update the lock count so the task that unlocks the queue will know\r
1013                         that an ISR has removed data while the queue was locked. */\r
1014                         if( pxQueue->xRxLock == queueUNLOCKED )\r
1015                         {\r
1016                                 if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
1017                                 {\r
1018                                         if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
1019                                         {\r
1020                                                 /* The task waiting has a higher priority than us so\r
1021                                                 force a context switch. */\r
1022                                                 *pxTaskWoken = pdTRUE;\r
1023                                         }\r
1024                                 }\r
1025                         }\r
1026                         else\r
1027                         {\r
1028                                 /* Increment the lock count so the task that unlocks the queue\r
1029                                 knows that data was removed while it was locked. */\r
1030                                 ++( pxQueue->xRxLock );\r
1031                         }\r
1032 \r
1033                         xReturn = pdPASS;\r
1034                 }\r
1035                 else\r
1036                 {\r
1037                         xReturn = pdFAIL;\r
1038                         traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue );\r
1039                 }\r
1040         }\r
1041         portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
1042 \r
1043         return xReturn;\r
1044 }\r
1045 /*-----------------------------------------------------------*/\r
1046 \r
1047 unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue )\r
1048 {\r
1049 unsigned portBASE_TYPE uxReturn;\r
1050 \r
1051         configASSERT( pxQueue );\r
1052 \r
1053         taskENTER_CRITICAL();\r
1054                 uxReturn = pxQueue->uxMessagesWaiting;\r
1055         taskEXIT_CRITICAL();\r
1056 \r
1057         return uxReturn;\r
1058 }\r
1059 /*-----------------------------------------------------------*/\r
1060 \r
1061 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue )\r
1062 {\r
1063 unsigned portBASE_TYPE uxReturn;\r
1064 \r
1065         configASSERT( pxQueue );\r
1066 \r
1067         uxReturn = pxQueue->uxMessagesWaiting;\r
1068 \r
1069         return uxReturn;\r
1070 }\r
1071 /*-----------------------------------------------------------*/\r
1072 \r
1073 void vQueueDelete( xQueueHandle pxQueue )\r
1074 {\r
1075         configASSERT( pxQueue );\r
1076 \r
1077         traceQUEUE_DELETE( pxQueue );\r
1078         vQueueUnregisterQueue( pxQueue );\r
1079         vPortFree( pxQueue->pcHead );\r
1080         vPortFree( pxQueue );\r
1081 }\r
1082 /*-----------------------------------------------------------*/\r
1083 \r
1084 static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, portBASE_TYPE xPosition )\r
1085 {\r
1086         if( pxQueue->uxItemSize == ( unsigned portBASE_TYPE ) 0 )\r
1087         {\r
1088                 #if ( configUSE_MUTEXES == 1 )\r
1089                 {\r
1090                         if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
1091                         {\r
1092                                 /* The mutex is no longer being held. */\r
1093                                 vTaskPriorityDisinherit( ( void * ) pxQueue->pxMutexHolder );\r
1094                                 pxQueue->pxMutexHolder = NULL;\r
1095                         }\r
1096                 }\r
1097                 #endif\r
1098         }\r
1099         else if( xPosition == queueSEND_TO_BACK )\r
1100         {\r
1101                 memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( unsigned ) pxQueue->uxItemSize );\r
1102                 pxQueue->pcWriteTo += pxQueue->uxItemSize;\r
1103                 if( pxQueue->pcWriteTo >= pxQueue->pcTail )\r
1104                 {\r
1105                         pxQueue->pcWriteTo = pxQueue->pcHead;\r
1106                 }\r
1107         }\r
1108         else\r
1109         {\r
1110                 memcpy( ( void * ) pxQueue->pcReadFrom, pvItemToQueue, ( unsigned ) pxQueue->uxItemSize );\r
1111                 pxQueue->pcReadFrom -= pxQueue->uxItemSize;\r
1112                 if( pxQueue->pcReadFrom < pxQueue->pcHead )\r
1113                 {\r
1114                         pxQueue->pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );\r
1115                 }\r
1116         }\r
1117 \r
1118         ++( pxQueue->uxMessagesWaiting );\r
1119 }\r
1120 /*-----------------------------------------------------------*/\r
1121 \r
1122 static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer )\r
1123 {\r
1124         if( pxQueue->uxQueueType != queueQUEUE_IS_MUTEX )\r
1125         {\r
1126                 pxQueue->pcReadFrom += pxQueue->uxItemSize;\r
1127                 if( pxQueue->pcReadFrom >= pxQueue->pcTail )\r
1128                 {\r
1129                         pxQueue->pcReadFrom = pxQueue->pcHead;\r
1130                 }\r
1131                 memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
1132         }\r
1133 }\r
1134 /*-----------------------------------------------------------*/\r
1135 \r
1136 static void prvUnlockQueue( xQueueHandle pxQueue )\r
1137 {\r
1138         /* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */\r
1139 \r
1140         /* The lock counts contains the number of extra data items placed or\r
1141         removed from the queue while the queue was locked.  When a queue is\r
1142         locked items can be added or removed, but the event lists cannot be\r
1143         updated. */\r
1144         taskENTER_CRITICAL();\r
1145         {\r
1146                 /* See if data was added to the queue while it was locked. */\r
1147                 while( pxQueue->xTxLock > queueLOCKED_UNMODIFIED )\r
1148                 {\r
1149                         /* Data was posted while the queue was locked.  Are any tasks\r
1150                         blocked waiting for data to become available? */\r
1151                         if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
1152                         {\r
1153                                 /* Tasks that are removed from the event list will get added to\r
1154                                 the pending ready list as the scheduler is still suspended. */\r
1155                                 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
1156                                 {\r
1157                                         /* The task waiting has a higher priority so record that a\r
1158                                         context switch is required. */\r
1159                                         vTaskMissedYield();\r
1160                                 }\r
1161 \r
1162                                 --( pxQueue->xTxLock );\r
1163                         }\r
1164                         else\r
1165                         {\r
1166                                 break;\r
1167                         }\r
1168                 }\r
1169 \r
1170                 pxQueue->xTxLock = queueUNLOCKED;\r
1171         }\r
1172         taskEXIT_CRITICAL();\r
1173 \r
1174         /* Do the same for the Rx lock. */\r
1175         taskENTER_CRITICAL();\r
1176         {\r
1177                 while( pxQueue->xRxLock > queueLOCKED_UNMODIFIED )\r
1178                 {\r
1179                         if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
1180                         {\r
1181                                 if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
1182                                 {\r
1183                                         vTaskMissedYield();\r
1184                                 }\r
1185 \r
1186                                 --( pxQueue->xRxLock );\r
1187                         }\r
1188                         else\r
1189                         {\r
1190                                 break;\r
1191                         }\r
1192                 }\r
1193 \r
1194                 pxQueue->xRxLock = queueUNLOCKED;\r
1195         }\r
1196         taskEXIT_CRITICAL();\r
1197 }\r
1198 /*-----------------------------------------------------------*/\r
1199 \r
1200 static signed portBASE_TYPE prvIsQueueEmpty( const xQueueHandle pxQueue )\r
1201 {\r
1202 signed portBASE_TYPE xReturn;\r
1203 \r
1204         taskENTER_CRITICAL();\r
1205                 xReturn = ( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 );\r
1206         taskEXIT_CRITICAL();\r
1207 \r
1208         return xReturn;\r
1209 }\r
1210 /*-----------------------------------------------------------*/\r
1211 \r
1212 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue )\r
1213 {\r
1214 signed portBASE_TYPE xReturn;\r
1215 \r
1216         configASSERT( pxQueue );\r
1217         xReturn = ( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 );\r
1218 \r
1219         return xReturn;\r
1220 }\r
1221 /*-----------------------------------------------------------*/\r
1222 \r
1223 static signed portBASE_TYPE prvIsQueueFull( const xQueueHandle pxQueue )\r
1224 {\r
1225 signed portBASE_TYPE xReturn;\r
1226 \r
1227         taskENTER_CRITICAL();\r
1228                 xReturn = ( pxQueue->uxMessagesWaiting == pxQueue->uxLength );\r
1229         taskEXIT_CRITICAL();\r
1230 \r
1231         return xReturn;\r
1232 }\r
1233 /*-----------------------------------------------------------*/\r
1234 \r
1235 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue )\r
1236 {\r
1237 signed portBASE_TYPE xReturn;\r
1238 \r
1239         configASSERT( pxQueue );\r
1240         xReturn = ( pxQueue->uxMessagesWaiting == pxQueue->uxLength );\r
1241 \r
1242         return xReturn;\r
1243 }\r
1244 /*-----------------------------------------------------------*/\r
1245 \r
1246 #if configUSE_CO_ROUTINES == 1\r
1247 signed portBASE_TYPE xQueueCRSend( xQueueHandle pxQueue, const void *pvItemToQueue, portTickType xTicksToWait )\r
1248 {\r
1249 signed portBASE_TYPE xReturn;\r
1250 \r
1251         /* If the queue is already full we may have to block.  A critical section\r
1252         is required to prevent an interrupt removing something from the queue\r
1253         between the check to see if the queue is full and blocking on the queue. */\r
1254         portDISABLE_INTERRUPTS();\r
1255         {\r
1256                 if( prvIsQueueFull( pxQueue ) )\r
1257                 {\r
1258                         /* The queue is full - do we want to block or just leave without\r
1259                         posting? */\r
1260                         if( xTicksToWait > ( portTickType ) 0 )\r
1261                         {\r
1262                                 /* As this is called from a coroutine we cannot block directly, but\r
1263                                 return indicating that we need to block. */\r
1264                                 vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToSend ) );\r
1265                                 portENABLE_INTERRUPTS();\r
1266                                 return errQUEUE_BLOCKED;\r
1267                         }\r
1268                         else\r
1269                         {\r
1270                                 portENABLE_INTERRUPTS();\r
1271                                 return errQUEUE_FULL;\r
1272                         }\r
1273                 }\r
1274         }\r
1275         portENABLE_INTERRUPTS();\r
1276 \r
1277         portNOP();\r
1278 \r
1279         portDISABLE_INTERRUPTS();\r
1280         {\r
1281                 if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
1282                 {\r
1283                         /* There is room in the queue, copy the data into the queue. */\r
1284                         prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );\r
1285                         xReturn = pdPASS;\r
1286 \r
1287                         /* Were any co-routines waiting for data to become available? */\r
1288                         if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )\r
1289                         {\r
1290                                 /* In this instance the co-routine could be placed directly\r
1291                                 into the ready list as we are within a critical section.\r
1292                                 Instead the same pending ready list mechanism is used as if\r
1293                                 the event were caused from within an interrupt. */\r
1294                                 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
1295                                 {\r
1296                                         /* The co-routine waiting has a higher priority so record\r
1297                                         that a yield might be appropriate. */\r
1298                                         xReturn = errQUEUE_YIELD;\r
1299                                 }\r
1300                         }\r
1301                 }\r
1302                 else\r
1303                 {\r
1304                         xReturn = errQUEUE_FULL;\r
1305                 }\r
1306         }\r
1307         portENABLE_INTERRUPTS();\r
1308 \r
1309         return xReturn;\r
1310 }\r
1311 #endif\r
1312 /*-----------------------------------------------------------*/\r
1313 \r
1314 #if configUSE_CO_ROUTINES == 1\r
1315 signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait )\r
1316 {\r
1317 signed portBASE_TYPE xReturn;\r
1318 \r
1319         /* If the queue is already empty we may have to block.  A critical section\r
1320         is required to prevent an interrupt adding something to the queue\r
1321         between the check to see if the queue is empty and blocking on the queue. */\r
1322         portDISABLE_INTERRUPTS();\r
1323         {\r
1324                 if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 )\r
1325                 {\r
1326                         /* There are no messages in the queue, do we want to block or just\r
1327                         leave with nothing? */\r
1328                         if( xTicksToWait > ( portTickType ) 0 )\r
1329                         {\r
1330                                 /* As this is a co-routine we cannot block directly, but return\r
1331                                 indicating that we need to block. */\r
1332                                 vCoRoutineAddToDelayedList( xTicksToWait, &( pxQueue->xTasksWaitingToReceive ) );\r
1333                                 portENABLE_INTERRUPTS();\r
1334                                 return errQUEUE_BLOCKED;\r
1335                         }\r
1336                         else\r
1337                         {\r
1338                                 portENABLE_INTERRUPTS();\r
1339                                 return errQUEUE_FULL;\r
1340                         }\r
1341                 }\r
1342         }\r
1343         portENABLE_INTERRUPTS();\r
1344 \r
1345         portNOP();\r
1346 \r
1347         portDISABLE_INTERRUPTS();\r
1348         {\r
1349                 if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
1350                 {\r
1351                         /* Data is available from the queue. */\r
1352                         pxQueue->pcReadFrom += pxQueue->uxItemSize;\r
1353                         if( pxQueue->pcReadFrom >= pxQueue->pcTail )\r
1354                         {\r
1355                                 pxQueue->pcReadFrom = pxQueue->pcHead;\r
1356                         }\r
1357                         --( pxQueue->uxMessagesWaiting );\r
1358                         memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
1359 \r
1360                         xReturn = pdPASS;\r
1361 \r
1362                         /* Were any co-routines waiting for space to become available? */\r
1363                         if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )\r
1364                         {\r
1365                                 /* In this instance the co-routine could be placed directly\r
1366                                 into the ready list as we are within a critical section.\r
1367                                 Instead the same pending ready list mechanism is used as if\r
1368                                 the event were caused from within an interrupt. */\r
1369                                 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
1370                                 {\r
1371                                         xReturn = errQUEUE_YIELD;\r
1372                                 }\r
1373                         }\r
1374                 }\r
1375                 else\r
1376                 {\r
1377                         xReturn = pdFAIL;\r
1378                 }\r
1379         }\r
1380         portENABLE_INTERRUPTS();\r
1381 \r
1382         return xReturn;\r
1383 }\r
1384 #endif\r
1385 /*-----------------------------------------------------------*/\r
1386 \r
1387 \r
1388 \r
1389 #if configUSE_CO_ROUTINES == 1\r
1390 signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken )\r
1391 {\r
1392         /* Cannot block within an ISR so if there is no space on the queue then\r
1393         exit without doing anything. */\r
1394         if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
1395         {\r
1396                 prvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );\r
1397 \r
1398                 /* We only want to wake one co-routine per ISR, so check that a\r
1399                 co-routine has not already been woken. */\r
1400                 if( !xCoRoutinePreviouslyWoken )\r
1401                 {\r
1402                         if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )\r
1403                         {\r
1404                                 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
1405                                 {\r
1406                                         return pdTRUE;\r
1407                                 }\r
1408                         }\r
1409                 }\r
1410         }\r
1411 \r
1412         return xCoRoutinePreviouslyWoken;\r
1413 }\r
1414 #endif\r
1415 /*-----------------------------------------------------------*/\r
1416 \r
1417 #if configUSE_CO_ROUTINES == 1\r
1418 signed portBASE_TYPE xQueueCRReceiveFromISR( xQueueHandle pxQueue, void *pvBuffer, signed portBASE_TYPE *pxCoRoutineWoken )\r
1419 {\r
1420 signed portBASE_TYPE xReturn;\r
1421 \r
1422         /* We cannot block from an ISR, so check there is data available. If\r
1423         not then just leave without doing anything. */\r
1424         if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )\r
1425         {\r
1426                 /* Copy the data from the queue. */\r
1427                 pxQueue->pcReadFrom += pxQueue->uxItemSize;\r
1428                 if( pxQueue->pcReadFrom >= pxQueue->pcTail )\r
1429                 {\r
1430                         pxQueue->pcReadFrom = pxQueue->pcHead;\r
1431                 }\r
1432                 --( pxQueue->uxMessagesWaiting );\r
1433                 memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
1434 \r
1435                 if( !( *pxCoRoutineWoken ) )\r
1436                 {\r
1437                         if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )\r
1438                         {\r
1439                                 if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
1440                                 {\r
1441                                         *pxCoRoutineWoken = pdTRUE;\r
1442                                 }\r
1443                         }\r
1444                 }\r
1445 \r
1446                 xReturn = pdPASS;\r
1447         }\r
1448         else\r
1449         {\r
1450                 xReturn = pdFAIL;\r
1451         }\r
1452 \r
1453         return xReturn;\r
1454 }\r
1455 #endif\r
1456 /*-----------------------------------------------------------*/\r
1457 \r
1458 #if configQUEUE_REGISTRY_SIZE > 0\r
1459 \r
1460         void vQueueAddToRegistry( xQueueHandle xQueue, signed char *pcQueueName )\r
1461         {\r
1462         unsigned portBASE_TYPE ux;\r
1463 \r
1464                 /* See if there is an empty space in the registry.  A NULL name denotes\r
1465                 a free slot. */\r
1466                 for( ux = 0; ux < configQUEUE_REGISTRY_SIZE; ux++ )\r
1467                 {\r
1468                         if( xQueueRegistry[ ux ].pcQueueName == NULL )\r
1469                         {\r
1470                                 /* Store the information on this queue. */\r
1471                                 xQueueRegistry[ ux ].pcQueueName = pcQueueName;\r
1472                                 xQueueRegistry[ ux ].xHandle = xQueue;\r
1473                                 break;\r
1474                         }\r
1475                 }\r
1476         }\r
1477 \r
1478 #endif\r
1479 /*-----------------------------------------------------------*/\r
1480 \r
1481 #if configQUEUE_REGISTRY_SIZE > 0\r
1482 \r
1483         static void vQueueUnregisterQueue( xQueueHandle xQueue )\r
1484         {\r
1485         unsigned portBASE_TYPE ux;\r
1486 \r
1487                 /* See if the handle of the queue being unregistered in actually in the\r
1488                 registry. */\r
1489                 for( ux = 0; ux < configQUEUE_REGISTRY_SIZE; ux++ )\r
1490                 {\r
1491                         if( xQueueRegistry[ ux ].xHandle == xQueue )\r
1492                         {\r
1493                                 /* Set the name to NULL to show that this slot if free again. */\r
1494                                 xQueueRegistry[ ux ].pcQueueName = NULL;\r
1495                                 break;\r
1496                         }\r
1497                 }\r
1498 \r
1499         }\r
1500 \r
1501 #endif\r
1502 /*-----------------------------------------------------------*/\r
1503 \r
1504 #if configUSE_TIMERS == 1\r
1505 \r
1506         void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait )\r
1507         {\r
1508                 /* This function should not be called by application code hence the\r
1509                 'Restricted' in its name.  It is not part of the public API.  It is \r
1510                 designed for use by kernel code, and has special calling requirements.\r
1511                 It can result in vListInsert() being called on a list that can only\r
1512                 possibly ever have one item in it, so the list will be fast, but even\r
1513                 so it should be called with the scheduler locked and not from a critical\r
1514                 section. */\r
1515 \r
1516                 /* Only do anything if there are no messages in the queue.  This function\r
1517                 will not actually cause the task to block, just place it on a blocked\r
1518                 list.  It will not block until the scheduler is unlocked - at which\r
1519                 time a yield will be performed.  If an item is added to the queue while\r
1520                 the queue is locked, and the calling task blocks on the queue, then the\r
1521                 calling task will be immediately unblocked when the queue is unlocked. */\r
1522                 prvLockQueue( pxQueue );\r
1523                 if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0U )\r
1524                 {\r
1525                         /* There is nothing in the queue, block for the specified period. */\r
1526                         vTaskPlaceOnEventListRestricted( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
1527                 }\r
1528                 prvUnlockQueue( pxQueue );\r
1529         }\r
1530 \r
1531 #endif\r
1532 \r