]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/queue.c
Multiple tidy up, documentation corrections and typo corrections highlighted by Tamas...
[freertos] / FreeRTOS / Source / queue.c
index c5c1269e1c441120c42a8cf771bf424e671c590f..43ceaca9279003fb25648d304481d61c9bb2f293 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
-    FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.\r
+    FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd.\r
+    All rights reserved\r
 \r
     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
 \r
@@ -109,6 +110,13 @@ zero. */
 #define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( unsigned portBASE_TYPE ) 0 )\r
 #define queueMUTEX_GIVE_BLOCK_TIME              ( ( portTickType ) 0U )\r
 \r
+#if( configUSE_PREEMPTION == 0 )\r
+       /* If the cooperative scheduler is being used then a yield should not be\r
+       performed just because a higher priority task has been woken. */\r
+       #define queueYIELD_IF_USING_PREEMPTION()\r
+#else\r
+       #define queueYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API()\r
+#endif\r
 \r
 /*\r
  * Definition of the queue used by the scheduler.\r
@@ -204,7 +212,7 @@ static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, port
 /*\r
  * Copies an item out of a queue.\r
  */\r
-static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void * const pvBuffer ) PRIVILEGED_FUNCTION;\r
+static void prvCopyDataFromQueue( xQUEUE * const pxQueue, void * const pvBuffer ) PRIVILEGED_FUNCTION;\r
 \r
 #if ( configUSE_QUEUE_SETS == 1 )\r
        /*\r
@@ -254,14 +262,14 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
                {\r
                        /* If there are tasks blocked waiting to read from the queue, then\r
                        the tasks will remain blocked as after this function exits the queue\r
-                       will still be empty.  If there are tasks blocked waiting to     write to\r
+                       will still be empty.  If there are tasks blocked waiting to write to\r
                        the queue, then one should be unblocked as after this function exits\r
                        it will be possible to write to it. */\r
                        if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
                        {\r
                                if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )\r
                                {\r
-                                       portYIELD_WITHIN_API();\r
+                                       queueYIELD_IF_USING_PREEMPTION();\r
                                }\r
                        }\r
                }\r
@@ -410,7 +418,7 @@ xQueueHandle xReturn = NULL;
        void *pxReturn;\r
 \r
                /* This function is called by xSemaphoreGetMutexHolder(), and should not\r
-               be called directly.  Note:  This is is a good way of determining if the\r
+               be called directly.  Note:  This is a good way of determining if the\r
                calling task is the mutex holder, but not a good way of determining the\r
                identity of the mutex holder, as the holder may change between the\r
                following critical section exiting and the function returning. */\r
@@ -497,7 +505,7 @@ xQueueHandle xReturn = NULL;
 \r
                traceTAKE_MUTEX_RECURSIVE( pxMutex );\r
 \r
-               if( pxMutex->pxMutexHolder == ( void * )  xTaskGetCurrentTaskHandle() ) /*lint !e961 Cast is not redundant as xTaskHandle is a typedef. */\r
+               if( pxMutex->pxMutexHolder == ( void * ) xTaskGetCurrentTaskHandle() ) /*lint !e961 Cast is not redundant as xTaskHandle is a typedef. */\r
                {\r
                        ( pxMutex->u.uxRecursiveCallCount )++;\r
                        xReturn = pdPASS;\r
@@ -526,11 +534,14 @@ xQueueHandle xReturn = NULL;
 \r
 #if ( configUSE_COUNTING_SEMAPHORES == 1 )\r
 \r
-       xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount )\r
+       xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxMaxCount, unsigned portBASE_TYPE uxInitialCount )\r
        {\r
        xQueueHandle xHandle;\r
 \r
-               xHandle = xQueueGenericCreate( uxCountValue, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE );\r
+               configASSERT( uxMaxCount != 0 );\r
+               configASSERT( uxInitialCount <= uxMaxCount );\r
+\r
+               xHandle = xQueueGenericCreate( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE );\r
 \r
                if( xHandle != NULL )\r
                {\r
@@ -559,6 +570,12 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
        configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\r
+       #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
+       {\r
+               configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );\r
+       }\r
+       #endif\r
+\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
@@ -585,7 +602,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
                                                        /* The queue is a member of a queue set, and posting\r
                                                        to the queue set caused a higher priority task to\r
                                                        unblock. A context switch is required. */\r
-                                                       portYIELD_WITHIN_API();\r
+                                                       queueYIELD_IF_USING_PREEMPTION();\r
                                                }\r
                                        }\r
                                        else\r
@@ -600,7 +617,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
                                                                our own so yield immediately.  Yes it is ok to\r
                                                                do this from within the critical section - the\r
                                                                kernel takes care of that. */\r
-                                                               portYIELD_WITHIN_API();\r
+                                                               queueYIELD_IF_USING_PREEMPTION();\r
                                                        }\r
                                                }\r
                                        }\r
@@ -617,7 +634,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
                                                        our own so yield immediately.  Yes it is ok to do\r
                                                        this from within the critical section - the kernel\r
                                                        takes care of that. */\r
-                                                       portYIELD_WITHIN_API();\r
+                                                       queueYIELD_IF_USING_PREEMPTION();\r
                                                }\r
                                        }\r
                                }\r
@@ -651,7 +668,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
                                }\r
                                else\r
                                {\r
-                                       /* Entry time was already set. */                                       \r
+                                       /* Entry time was already set. */\r
                                }\r
                        }\r
                }\r
@@ -892,11 +909,11 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
                                                {\r
                                                        if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
                                                        {\r
-                                                               portENTER_CRITICAL();\r
+                                                               taskENTER_CRITICAL();\r
                                                                {\r
                                                                        vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );\r
                                                                }\r
-                                                               portEXIT_CRITICAL();\r
+                                                               taskEXIT_CRITICAL();\r
                                                        }\r
                                                }\r
                                                #endif\r
@@ -932,7 +949,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
 \r
        /* RTOS ports that support interrupt nesting have the concept of a maximum\r
        system call (or maximum API call) interrupt priority.  Interrupts that are\r
-       above the maximum system call priority are keep permanently enabled, even\r
+       above the maximum system call priority are kept permanently enabled, even\r
        when the RTOS kernel is in a critical section, but cannot make any calls to\r
        FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\r
        then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
@@ -1032,7 +1049,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )\r
+signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking )\r
 {\r
 signed portBASE_TYPE xEntryTimeSet = pdFALSE;\r
 xTimeOutType xTimeOut;\r
@@ -1041,7 +1058,12 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
 \r
        configASSERT( pxQueue );\r
        configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) );\r
-\r
+       #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
+       {\r
+               configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );\r
+       }\r
+       #endif\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
@@ -1082,7 +1104,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
                                        {\r
                                                if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE )\r
                                                {\r
-                                                       portYIELD_WITHIN_API();\r
+                                                       queueYIELD_IF_USING_PREEMPTION();\r
                                                }\r
                                        }\r
                                }\r
@@ -1103,7 +1125,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
                                                if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
                                                {\r
                                                        /* The task waiting has a higher priority than this task. */\r
-                                                       portYIELD_WITHIN_API();\r
+                                                       queueYIELD_IF_USING_PREEMPTION();\r
                                                }\r
                                        }\r
                                }\r
@@ -1153,11 +1175,11 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
                                {\r
                                        if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
                                        {\r
-                                               portENTER_CRITICAL();\r
+                                               taskENTER_CRITICAL();\r
                                                {\r
                                                        vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );\r
                                                }\r
-                                               portEXIT_CRITICAL();\r
+                                               taskEXIT_CRITICAL();\r
                                        }\r
                                }\r
                                #endif\r
@@ -1187,7 +1209,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, const void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken )\r
+signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken )\r
 {\r
 signed portBASE_TYPE xReturn;\r
 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
@@ -1198,17 +1220,17 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
 \r
        /* RTOS ports that support interrupt nesting have the concept of a maximum\r
        system call (or maximum API call) interrupt priority.  Interrupts that are\r
-       above the maximum system call priority are keep permanently enabled, even \r
+       above the maximum system call priority are kept permanently enabled, even\r
        when the RTOS kernel is in a critical section, but cannot make any calls to\r
-       FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h \r
+       FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\r
        then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
        failure if a FreeRTOS API function is called from an interrupt that has been\r
        assigned a priority above the configured maximum system call priority.\r
        Only FreeRTOS functions that end in FromISR can be called from interrupts\r
-       that have been assigned a priority at or (logically) below the maximum \r
-       system call     interrupt priority.  FreeRTOS maintains a separate interrupt \r
-       safe API to ensure interrupt entry is as fast and as simple as possible.  \r
-       More information (albeit Cortex-M specific) is provided on the following \r
+       that have been assigned a priority at or (logically) below the maximum\r
+       system call     interrupt priority.  FreeRTOS maintains a separate interrupt\r
+       safe API to ensure interrupt entry is as fast and as simple as possible.\r
+       More information (albeit Cortex-M specific) is provided on the following\r
        link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
        portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
 \r
@@ -1262,7 +1284,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, const void * const pvBuffer )\r
+signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue,  void * const pvBuffer )\r
 {\r
 signed portBASE_TYPE xReturn;\r
 unsigned portBASE_TYPE uxSavedInterruptStatus;\r
@@ -1274,17 +1296,17 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue;
 \r
        /* RTOS ports that support interrupt nesting have the concept of a maximum\r
        system call (or maximum API call) interrupt priority.  Interrupts that are\r
-       above the maximum system call priority are keep permanently enabled, even \r
+       above the maximum system call priority are kept permanently enabled, even\r
        when the RTOS kernel is in a critical section, but cannot make any calls to\r
-       FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h \r
+       FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\r
        then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
        failure if a FreeRTOS API function is called from an interrupt that has been\r
        assigned a priority above the configured maximum system call priority.\r
        Only FreeRTOS functions that end in FromISR can be called from interrupts\r
-       that have been assigned a priority at or (logically) below the maximum \r
-       system call     interrupt priority.  FreeRTOS maintains a separate interrupt \r
-       safe API to ensure interrupt entry is as fast and as simple as possible.  \r
-       More information (albeit Cortex-M specific) is provided on the following \r
+       that have been assigned a priority at or (logically) below the maximum\r
+       system call     interrupt priority.  FreeRTOS maintains a separate interrupt\r
+       safe API to ensure interrupt entry is as fast and as simple as possible.\r
+       More information (albeit Cortex-M specific) is provided on the following\r
        link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
        portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
 \r
@@ -1329,6 +1351,22 @@ unsigned portBASE_TYPE uxReturn;
 } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */\r
 /*-----------------------------------------------------------*/\r
 \r
+unsigned portBASE_TYPE uxQueueSpacesAvailable( const xQueueHandle xQueue )\r
+{\r
+unsigned portBASE_TYPE uxReturn;\r
+xQUEUE *pxQueue;\r
+\r
+       pxQueue = ( xQUEUE * ) xQueue;\r
+       configASSERT( pxQueue );\r
+\r
+       taskENTER_CRITICAL();\r
+               uxReturn = pxQueue->uxLength - pxQueue->uxMessagesWaiting;\r
+       taskEXIT_CRITICAL();\r
+\r
+       return uxReturn;\r
+} /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */\r
+/*-----------------------------------------------------------*/\r
+\r
 unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle xQueue )\r
 {\r
 unsigned portBASE_TYPE uxReturn;\r
@@ -1438,7 +1476,7 @@ static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, port
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void * const pvBuffer )\r
+static void prvCopyDataFromQueue( xQUEUE * const pxQueue, void * const pvBuffer )\r
 {\r
        if( pxQueue->uxQueueType != queueQUEUE_IS_MUTEX )\r
        {\r
@@ -2065,3 +2103,14 @@ signed portBASE_TYPE xReturn;
 \r
 #endif /* configUSE_QUEUE_SETS */\r
 \r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r