]> git.sur5r.net Git - freertos/blobdiff - Source/queue.c
Tidy up the RL78 port layer.
[freertos] / Source / queue.c
index ae1eeb97a3bfd45b0589dcb6192ffafc1b8bc73e..c2197b7c2e1188331db814ea94716cc6143d4a5c 100644 (file)
@@ -1,41 +1,47 @@
 /*\r
-    FreeRTOS V6.0.3 - Copyright (C) 2010 Real Time Engineers Ltd.\r
+    FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+       \r
+\r
+       FreeRTOS supports many tools and architectures. V7.0.0 is sponsored by:\r
+       Atollic AB - Atollic provides professional embedded systems development \r
+       tools for C/C++ development, code analysis and test automation.  \r
+       See http://www.atollic.com\r
+       \r
 \r
     ***************************************************************************\r
-    *                                                                         *\r
-    * If you are:                                                             *\r
-    *                                                                         *\r
-    *    + New to FreeRTOS,                                                   *\r
-    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
-    *    + Looking for basic training,                                        *\r
-    *    + Wanting to improve your FreeRTOS skills and productivity           *\r
-    *                                                                         *\r
-    * then take a look at the FreeRTOS eBook                                  *\r
-    *                                                                         *\r
-    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
-    *                  http://www.FreeRTOS.org/Documentation                  *\r
-    *                                                                         *\r
-    * A pdf reference manual is also available.  Both are usually delivered   *\r
-    * to your inbox within 20 minutes to two hours when purchased between 8am *\r
-    * and 8pm GMT (although please allow up to 24 hours in case of            *\r
-    * exceptional circumstances).  Thank you for your support!                *\r
-    *                                                                         *\r
+     *                                                                       *\r
+     *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
+     *    Complete, revised, and edited pdf reference manuals are also       *\r
+     *    available.                                                         *\r
+     *                                                                       *\r
+     *    Purchasing FreeRTOS documentation will not only help you, by       *\r
+     *    ensuring you get running as quickly as possible and with an        *\r
+     *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
+     *    the FreeRTOS project to continue with its mission of providing     *\r
+     *    professional grade, cross platform, de facto standard solutions    *\r
+     *    for microcontrollers - completely free of charge!                  *\r
+     *                                                                       *\r
+     *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
+     *                                                                       *\r
+     *    Thank you for using FreeRTOS, and thank you for your support!      *\r
+     *                                                                       *\r
     ***************************************************************************\r
 \r
+\r
     This file is part of the FreeRTOS distribution.\r
 \r
     FreeRTOS is free software; you can redistribute it and/or modify it under\r
     the terms of the GNU General Public License (version 2) as published by the\r
     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
-    ***NOTE*** The exception to the GPL is included to allow you to distribute\r
-    a combined work that includes FreeRTOS without being obliged to provide the\r
-    source code for proprietary components outside of the FreeRTOS kernel.\r
-    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
-    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
-    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
-    more details. You should have received a copy of the GNU General Public \r
-    License and the FreeRTOS license exception along with FreeRTOS; if not it \r
-    can be viewed here: http://www.freertos.org/a00114.html and also obtained \r
+    >>>NOTE<<< The modification to the GPL is included to allow you to\r
+    distribute a combined work that includes FreeRTOS without being obliged to\r
+    provide the source code for proprietary components outside of the FreeRTOS\r
+    kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
+    more details. You should have received a copy of the GNU General Public\r
+    License and the FreeRTOS license exception along with FreeRTOS; if not it\r
+    can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
     by writing to Richard Barry, contact details for whom are available on the\r
     FreeRTOS WEB site.\r
 \r
@@ -61,7 +67,10 @@ task.h is included from an application file. */
 \r
 #include "FreeRTOS.h"\r
 #include "task.h"\r
-#include "croutine.h"\r
+\r
+#if ( configUSE_CO_ROUTINES == 1 )\r
+       #include "croutine.h"\r
+#endif\r
 \r
 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE\r
 \r
@@ -87,9 +96,9 @@ task.h is included from an application file. */
 \r
 /* Semaphores do not actually store or copy data, so have an items size of\r
 zero. */\r
-#define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( 0 )\r
-#define queueDONT_BLOCK                                         ( ( portTickType ) 0 )\r
-#define queueMUTEX_GIVE_BLOCK_TIME              ( ( portTickType ) 0 )\r
+#define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( unsigned portBASE_TYPE ) 0 )\r
+#define queueDONT_BLOCK                                         ( ( portTickType ) 0U )\r
+#define queueMUTEX_GIVE_BLOCK_TIME              ( ( portTickType ) 0U )\r
 \r
 /*\r
  * Definition of the queue used by the scheduler.\r
@@ -144,6 +153,7 @@ signed portBASE_TYPE xQueueAltGenericReceive( xQueueHandle pxQueue, void * const
 signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
 signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;\r
+void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
 \r
 /*\r
  * Co-routine queue functions differ from task queue functions.  Co-routines are\r
@@ -222,21 +232,19 @@ static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer )
  * Macro to mark a queue as locked.  Locking a queue prevents an ISR from\r
  * accessing the queue event lists.\r
  */\r
-#define prvLockQueue( pxQueue )                                                        \\r
-{                                                                                                              \\r
-       taskENTER_CRITICAL();                                                           \\r
-       {                                                                                                       \\r
-               if( pxQueue->xRxLock == queueUNLOCKED )                 \\r
-               {                                                                                               \\r
-                       pxQueue->xRxLock = queueLOCKED_UNMODIFIED;      \\r
-               }                                                                                               \\r
-               if( pxQueue->xTxLock == queueUNLOCKED )                 \\r
-               {                                                                                               \\r
-                       pxQueue->xTxLock = queueLOCKED_UNMODIFIED;      \\r
-               }                                                                                               \\r
-       }                                                                                                       \\r
-       taskEXIT_CRITICAL();                                                            \\r
-}\r
+#define prvLockQueue( pxQueue )                                                                \\r
+       taskENTER_CRITICAL();                                                                   \\r
+       {                                                                                                               \\r
+               if( ( pxQueue )->xRxLock == queueUNLOCKED )                     \\r
+               {                                                                                                       \\r
+                       ( pxQueue )->xRxLock = queueLOCKED_UNMODIFIED;  \\r
+               }                                                                                                       \\r
+               if( ( pxQueue )->xTxLock == queueUNLOCKED )                     \\r
+               {                                                                                                       \\r
+                       ( pxQueue )->xTxLock = queueLOCKED_UNMODIFIED;  \\r
+               }                                                                                                       \\r
+       }                                                                                                               \\r
+       taskEXIT_CRITICAL()\r
 /*-----------------------------------------------------------*/\r
 \r
 \r
@@ -248,6 +256,7 @@ xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBA
 {\r
 xQUEUE *pxNewQueue;\r
 size_t xQueueSizeInBytes;\r
+xQueueHandle xReturn = NULL;\r
 \r
        /* Allocate the new queue structure. */\r
        if( uxQueueLength > ( unsigned portBASE_TYPE ) 0 )\r
@@ -265,9 +274,9 @@ size_t xQueueSizeInBytes;
                                /* Initialise the queue members as described above where the\r
                                queue type is defined. */\r
                                pxNewQueue->pcTail = pxNewQueue->pcHead + ( uxQueueLength * uxItemSize );\r
-                               pxNewQueue->uxMessagesWaiting = 0;\r
+                               pxNewQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U;\r
                                pxNewQueue->pcWriteTo = pxNewQueue->pcHead;\r
-                               pxNewQueue->pcReadFrom = pxNewQueue->pcHead + ( ( uxQueueLength - 1 ) * uxItemSize );\r
+                               pxNewQueue->pcReadFrom = pxNewQueue->pcHead + ( ( uxQueueLength - ( unsigned portBASE_TYPE ) 1U ) * uxItemSize );\r
                                pxNewQueue->uxLength = uxQueueLength;\r
                                pxNewQueue->uxItemSize = uxItemSize;\r
                                pxNewQueue->xRxLock = queueUNLOCKED;\r
@@ -278,7 +287,7 @@ size_t xQueueSizeInBytes;
                                vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );\r
 \r
                                traceQUEUE_CREATE( pxNewQueue );\r
-                               return  pxNewQueue;\r
+                               xReturn = pxNewQueue;\r
                        }\r
                        else\r
                        {\r
@@ -288,9 +297,9 @@ size_t xQueueSizeInBytes;
                }\r
        }\r
 \r
-       /* Will only reach here if we could not allocate enough memory or no memory\r
-       was required. */\r
-       return NULL;\r
+       configASSERT( xReturn );\r
+\r
+       return xReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -316,9 +325,9 @@ size_t xQueueSizeInBytes;
                        /* Each mutex has a length of 1 (like a binary semaphore) and\r
                        an item size of 0 as nothing is actually copied into or out\r
                        of the mutex. */\r
-                       pxNewQueue->uxMessagesWaiting = 0;\r
-                       pxNewQueue->uxLength = 1;\r
-                       pxNewQueue->uxItemSize = 0;\r
+                       pxNewQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U;\r
+                       pxNewQueue->uxLength = ( unsigned portBASE_TYPE ) 1U;\r
+                       pxNewQueue->uxItemSize = ( unsigned portBASE_TYPE ) 0U;\r
                        pxNewQueue->xRxLock = queueUNLOCKED;\r
                        pxNewQueue->xTxLock = queueUNLOCKED;\r
 \r
@@ -327,7 +336,7 @@ size_t xQueueSizeInBytes;
                        vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );\r
 \r
                        /* Start with the semaphore in the expected state. */\r
-                       xQueueGenericSend( pxNewQueue, NULL, 0, queueSEND_TO_BACK );\r
+                       xQueueGenericSend( pxNewQueue, NULL, ( portTickType ) 0U, queueSEND_TO_BACK );\r
 \r
                        traceCREATE_MUTEX( pxNewQueue );\r
                }\r
@@ -336,6 +345,7 @@ size_t xQueueSizeInBytes;
                        traceCREATE_MUTEX_FAILED();\r
                }\r
 \r
+               configASSERT( pxNewQueue );\r
                return pxNewQueue;\r
        }\r
 \r
@@ -348,6 +358,8 @@ size_t xQueueSizeInBytes;
        {\r
        portBASE_TYPE xReturn;\r
 \r
+               configASSERT( pxMutex );\r
+\r
                /* If this is the task that holds the mutex then pxMutexHolder will not\r
                change outside of this task.  If this task does not hold the mutex then\r
                pxMutexHolder can never coincidentally equal the tasks handle, and as\r
@@ -395,6 +407,8 @@ size_t xQueueSizeInBytes;
        {\r
        portBASE_TYPE xReturn;\r
 \r
+               configASSERT( pxMutex );\r
+\r
                /* Comments regarding mutual exclusion as per those within\r
                xQueueGiveMutexRecursive(). */\r
 \r
@@ -415,6 +429,10 @@ size_t xQueueSizeInBytes;
                        {\r
                                ( pxMutex->uxRecursiveCallCount )++;\r
                        }\r
+                       else\r
+                       {\r
+                               traceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex );\r
+                       }\r
                }\r
 \r
                return xReturn;\r
@@ -442,6 +460,7 @@ size_t xQueueSizeInBytes;
                        traceCREATE_COUNTING_SEMAPHORE_FAILED();\r
                }\r
 \r
+               configASSERT( pxHandle );\r
                return pxHandle;\r
        }\r
 \r
@@ -453,6 +472,9 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const
 signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
 xTimeOutType xTimeOut;\r
 \r
+       configASSERT( pxQueue );\r
+       configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
+\r
        /* This function relaxes the coding standard somewhat to allow return\r
        statements within the function itself.  This is done in the interest\r
        of execution time efficiency. */\r
@@ -520,7 +542,7 @@ xTimeOutType xTimeOut;
                /* Update the timeout state to see if it has expired yet. */\r
                if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
                {\r
-                       if( prvIsQueueFull( pxQueue ) )\r
+                       if( prvIsQueueFull( pxQueue ) != pdFALSE )\r
                        {\r
                                traceBLOCKING_ON_QUEUE_SEND( pxQueue );\r
                                vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );\r
@@ -537,7 +559,7 @@ xTimeOutType xTimeOut;
                                task is already in a ready list before it yields - in which\r
                                case the yield will not cause a context switch unless there\r
                                is also a higher priority task in the pending ready list. */\r
-                               if( !xTaskResumeAll() )\r
+                               if( xTaskResumeAll() == pdFALSE )\r
                                {\r
                                        portYIELD_WITHIN_API();\r
                                }\r
@@ -571,6 +593,9 @@ xTimeOutType xTimeOut;
        signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
        xTimeOutType xTimeOut;\r
 \r
+               configASSERT( pxQueue );\r
+               configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
+\r
                for( ;; )\r
                {\r
                        taskENTER_CRITICAL();\r
@@ -617,7 +642,7 @@ xTimeOutType xTimeOut;
                        {\r
                                if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
                                {\r
-                                       if( prvIsQueueFull( pxQueue ) )\r
+                                       if( prvIsQueueFull( pxQueue ) != pdFALSE )\r
                                        {\r
                                                traceBLOCKING_ON_QUEUE_SEND( pxQueue );\r
                                                vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), xTicksToWait );\r
@@ -646,6 +671,9 @@ xTimeOutType xTimeOut;
        xTimeOutType xTimeOut;\r
        signed char *pcOriginalReadPosition;\r
 \r
+               configASSERT( pxQueue );\r
+               configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
+\r
                for( ;; )\r
                {\r
                        taskENTER_CRITICAL();\r
@@ -693,7 +721,7 @@ xTimeOutType xTimeOut;
 \r
                                                /* The data is being left in the queue, so see if there are\r
                                                any other tasks waiting for the data. */\r
-                                               if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )\r
+                                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
                                                {\r
                                                        /* Tasks that are removed from the event list will get added to\r
                                                        the pending ready list as the scheduler is still suspended. */\r
@@ -730,7 +758,7 @@ xTimeOutType xTimeOut;
                        {\r
                                if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
                                {\r
-                                       if( prvIsQueueEmpty( pxQueue ) )\r
+                                       if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
                                        {\r
                                                traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
 \r
@@ -769,6 +797,10 @@ signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void
 signed portBASE_TYPE xReturn;\r
 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
 \r
+       configASSERT( pxQueue );\r
+       configASSERT( pxHigherPriorityTaskWoken );\r
+       configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
+\r
        /* Similar to xQueueGenericSend, except we don't block if there is no room\r
        in the queue.  Also we don't directly wake a task that was blocked on a\r
        queue read, instead we return a flag to say whether a context switch is\r
@@ -786,7 +818,7 @@ unsigned portBASE_TYPE uxSavedInterruptStatus;
                        be done when the queue is unlocked later. */\r
                        if( pxQueue->xTxLock == queueUNLOCKED )\r
                        {\r
-                               if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )\r
+                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
                                {\r
                                        if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
                                        {\r
@@ -823,6 +855,9 @@ signed portBASE_TYPE xEntryTimeSet = pdFALSE;
 xTimeOutType xTimeOut;\r
 signed char *pcOriginalReadPosition;\r
 \r
+       configASSERT( pxQueue );\r
+       configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
+\r
        /* This function relaxes the coding standard somewhat to allow return\r
        statements within the function itself.  This is done in the interest\r
        of execution time efficiency. */\r
@@ -876,7 +911,7 @@ signed char *pcOriginalReadPosition;
 \r
                                        /* The data is being left in the queue, so see if there are\r
                                        any other tasks waiting for the data. */\r
-                                       if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )\r
+                                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
                                        {\r
                                                /* Tasks that are removed from the event list will get added to\r
                                                the pending ready list as the scheduler is still suspended. */\r
@@ -922,7 +957,7 @@ signed char *pcOriginalReadPosition;
                /* Update the timeout state to see if it has expired yet. */\r
                if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
                {\r
-                       if( prvIsQueueEmpty( pxQueue ) )\r
+                       if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
                        {\r
                                traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
 \r
@@ -941,7 +976,7 @@ signed char *pcOriginalReadPosition;
 \r
                                vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
                                prvUnlockQueue( pxQueue );\r
-                               if( !xTaskResumeAll() )\r
+                               if( xTaskResumeAll() == pdFALSE )\r
                                {\r
                                        portYIELD_WITHIN_API();\r
                                }\r
@@ -969,6 +1004,10 @@ signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pv
 signed portBASE_TYPE xReturn;\r
 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
 \r
+       configASSERT( pxQueue );\r
+       configASSERT( pxTaskWoken );\r
+       configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
+\r
        uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
        {\r
                /* We cannot block from an ISR, so check there is data available. */\r
@@ -984,7 +1023,7 @@ unsigned portBASE_TYPE uxSavedInterruptStatus;
                        that an ISR has removed data while the queue was locked. */\r
                        if( pxQueue->xRxLock == queueUNLOCKED )\r
                        {\r
-                               if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )\r
+                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
                                {\r
                                        if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
                                        {\r
@@ -1019,6 +1058,8 @@ unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue )
 {\r
 unsigned portBASE_TYPE uxReturn;\r
 \r
+       configASSERT( pxQueue );\r
+\r
        taskENTER_CRITICAL();\r
                uxReturn = pxQueue->uxMessagesWaiting;\r
        taskEXIT_CRITICAL();\r
@@ -1031,6 +1072,8 @@ unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle pxQueue
 {\r
 unsigned portBASE_TYPE uxReturn;\r
 \r
+       configASSERT( pxQueue );\r
+\r
        uxReturn = pxQueue->uxMessagesWaiting;\r
 \r
        return uxReturn;\r
@@ -1039,6 +1082,8 @@ unsigned portBASE_TYPE uxReturn;
 \r
 void vQueueDelete( xQueueHandle pxQueue )\r
 {\r
+       configASSERT( pxQueue );\r
+\r
        traceQUEUE_DELETE( pxQueue );\r
        vQueueUnregisterQueue( pxQueue );\r
        vPortFree( pxQueue->pcHead );\r
@@ -1113,7 +1158,7 @@ static void prvUnlockQueue( xQueueHandle pxQueue )
                {\r
                        /* Data was posted while the queue was locked.  Are any tasks\r
                        blocked waiting for data to become available? */\r
-                       if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )\r
+                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
                        {\r
                                /* Tasks that are removed from the event list will get added to\r
                                the pending ready list as the scheduler is still suspended. */\r
@@ -1141,7 +1186,7 @@ static void prvUnlockQueue( xQueueHandle pxQueue )
        {\r
                while( pxQueue->xRxLock > queueLOCKED_UNMODIFIED )\r
                {\r
-                       if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )\r
+                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
                        {\r
                                if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
                                {\r
@@ -1178,6 +1223,7 @@ signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue )
 {\r
 signed portBASE_TYPE xReturn;\r
 \r
+       configASSERT( pxQueue );\r
        xReturn = ( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0 );\r
 \r
        return xReturn;\r
@@ -1200,6 +1246,7 @@ signed portBASE_TYPE xQueueIsQueueFullFromISR( const xQueueHandle pxQueue )
 {\r
 signed portBASE_TYPE xReturn;\r
 \r
+       configASSERT( pxQueue );\r
        xReturn = ( pxQueue->uxMessagesWaiting == pxQueue->uxLength );\r
 \r
        return xReturn;\r
@@ -1216,7 +1263,7 @@ signed portBASE_TYPE xReturn;
        between the check to see if the queue is full and blocking on the queue. */\r
        portDISABLE_INTERRUPTS();\r
        {\r
-               if( prvIsQueueFull( pxQueue ) )\r
+               if( prvIsQueueFull( pxQueue ) != pdFALSE )\r
                {\r
                        /* The queue is full - do we want to block or just leave without\r
                        posting? */\r
@@ -1248,7 +1295,7 @@ signed portBASE_TYPE xReturn;
                        xReturn = pdPASS;\r
 \r
                        /* Were any co-routines waiting for data to become available? */\r
-                       if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )\r
+                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
                        {\r
                                /* In this instance the co-routine could be placed directly\r
                                into the ready list as we are within a critical section.\r
@@ -1323,7 +1370,7 @@ signed portBASE_TYPE xReturn;
                        xReturn = pdPASS;\r
 \r
                        /* Were any co-routines waiting for space to become available? */\r
-                       if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )\r
+                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
                        {\r
                                /* In this instance the co-routine could be placed directly\r
                                into the ready list as we are within a critical section.\r
@@ -1360,9 +1407,9 @@ signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvIt
 \r
                /* We only want to wake one co-routine per ISR, so check that a\r
                co-routine has not already been woken. */\r
-               if( !xCoRoutinePreviouslyWoken )\r
+               if( xCoRoutinePreviouslyWoken == pdFALSE )\r
                {\r
-                       if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) )\r
+                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
                        {\r
                                if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
                                {\r
@@ -1395,9 +1442,9 @@ signed portBASE_TYPE xReturn;
                --( pxQueue->uxMessagesWaiting );\r
                memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\r
 \r
-               if( !( *pxCoRoutineWoken ) )\r
+               if( ( *pxCoRoutineWoken ) == pdFALSE )\r
                {\r
-                       if( !listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) )\r
+                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
                        {\r
                                if( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
                                {\r
@@ -1426,7 +1473,7 @@ signed portBASE_TYPE xReturn;
 \r
                /* See if there is an empty space in the registry.  A NULL name denotes\r
                a free slot. */\r
-               for( ux = 0; ux < configQUEUE_REGISTRY_SIZE; ux++ )\r
+               for( ux = ( unsigned portBASE_TYPE ) 0U; ux < ( unsigned portBASE_TYPE ) configQUEUE_REGISTRY_SIZE; ux++ )\r
                {\r
                        if( xQueueRegistry[ ux ].pcQueueName == NULL )\r
                        {\r
@@ -1439,7 +1486,7 @@ signed portBASE_TYPE xReturn;
        }\r
 \r
 #endif\r
-       /*-----------------------------------------------------------*/\r
+/*-----------------------------------------------------------*/\r
 \r
 #if configQUEUE_REGISTRY_SIZE > 0\r
 \r
@@ -1449,7 +1496,7 @@ signed portBASE_TYPE xReturn;
 \r
                /* See if the handle of the queue being unregistered in actually in the\r
                registry. */\r
-               for( ux = 0; ux < configQUEUE_REGISTRY_SIZE; ux++ )\r
+               for( ux = ( unsigned portBASE_TYPE ) 0U; ux < ( unsigned portBASE_TYPE ) configQUEUE_REGISTRY_SIZE; ux++ )\r
                {\r
                        if( xQueueRegistry[ ux ].xHandle == xQueue )\r
                        {\r
@@ -1462,4 +1509,34 @@ signed portBASE_TYPE xReturn;
        }\r
 \r
 #endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if configUSE_TIMERS == 1\r
+\r
+       void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait )\r
+       {\r
+               /* This function should not be called by application code hence the\r
+               'Restricted' in its name.  It is not part of the public API.  It is\r
+               designed for use by kernel code, and has special calling requirements.\r
+               It can result in vListInsert() being called on a list that can only\r
+               possibly ever have one item in it, so the list will be fast, but even\r
+               so it should be called with the scheduler locked and not from a critical\r
+               section. */\r
+\r
+               /* Only do anything if there are no messages in the queue.  This function\r
+               will not actually cause the task to block, just place it on a blocked\r
+               list.  It will not block until the scheduler is unlocked - at which\r
+               time a yield will be performed.  If an item is added to the queue while\r
+               the queue is locked, and the calling task blocks on the queue, then the\r
+               calling task will be immediately unblocked when the queue is unlocked. */\r
+               prvLockQueue( pxQueue );\r
+               if( pxQueue->uxMessagesWaiting == ( unsigned portBASE_TYPE ) 0U )\r
+               {\r
+                       /* There is nothing in the queue, block for the specified period. */\r
+                       vTaskPlaceOnEventListRestricted( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
+               }\r
+               prvUnlockQueue( pxQueue );\r
+       }\r
+\r
+#endif\r
 \r