]> git.sur5r.net Git - freertos/blobdiff - Source/queue.c
Tidy up the RL78 port layer.
[freertos] / Source / queue.c
index c08d4c174ed8063476233c17ef576d29f632a297..c2197b7c2e1188331db814ea94716cc6143d4a5c 100644 (file)
@@ -1,38 +1,44 @@
 /*\r
-    FreeRTOS V6.1.1 - Copyright (C) 2011 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 books - available as PDF or paperback  *\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
+    >>>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
@@ -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
@@ -287,6 +297,8 @@ xQueueHandle xReturn = NULL;
                }\r
        }\r
 \r
+       configASSERT( xReturn );\r
+\r
        return xReturn;\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -333,6 +345,7 @@ xQueueHandle xReturn = NULL;
                        traceCREATE_MUTEX_FAILED();\r
                }\r
 \r
+               configASSERT( pxNewQueue );\r
                return pxNewQueue;\r
        }\r
 \r
@@ -345,6 +358,8 @@ xQueueHandle xReturn = NULL;
        {\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
@@ -392,6 +407,8 @@ xQueueHandle xReturn = NULL;
        {\r
        portBASE_TYPE xReturn;\r
 \r
+               configASSERT( pxMutex );\r
+\r
                /* Comments regarding mutual exclusion as per those within\r
                xQueueGiveMutexRecursive(). */\r
 \r
@@ -443,6 +460,7 @@ xQueueHandle xReturn = NULL;
                        traceCREATE_COUNTING_SEMAPHORE_FAILED();\r
                }\r
 \r
+               configASSERT( pxHandle );\r
                return pxHandle;\r
        }\r
 \r
@@ -454,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
@@ -521,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
@@ -538,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
@@ -572,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
@@ -618,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
@@ -647,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
@@ -731,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
@@ -770,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
@@ -824,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
@@ -923,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
@@ -942,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
@@ -970,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
@@ -1020,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
@@ -1032,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
@@ -1040,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
@@ -1179,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
@@ -1201,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
@@ -1217,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
@@ -1249,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
@@ -1324,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
@@ -1361,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
@@ -1396,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
@@ -1427,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
@@ -1450,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
@@ -1470,7 +1516,7 @@ signed portBASE_TYPE xReturn;
        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
+               '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