+ /* Cannot block if the scheduler is suspended. */\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
+ of execution time efficiency. */\r
+\r
+ for( ;; )\r
+ {\r
+ taskENTER_CRITICAL();\r
+ {\r
+ const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;\r
+\r
+ /* Is there data in the queue now? To be running the calling task\r
+ must be the highest priority task wanting to access the queue. */\r
+ if( uxMessagesWaiting > ( UBaseType_t ) 0 )\r
+ {\r
+ /* Data available, remove one item. */\r
+ prvCopyDataFromQueue( pxQueue, pvBuffer );\r
+ traceQUEUE_RECEIVE( pxQueue );\r
+ pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1;\r
+\r
+ /* There is now space in the queue, were any tasks waiting to\r
+ post to the queue? If so, unblock the highest priority waiting\r
+ task. */\r
+ if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
+ {\r
+ if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
+ {\r
+ queueYIELD_IF_USING_PREEMPTION();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+\r
+ taskEXIT_CRITICAL();\r
+ return pdPASS;\r
+ }\r
+ else\r
+ {\r
+ if( xTicksToWait == ( TickType_t ) 0 )\r
+ {\r
+ /* The queue was empty and no block time is specified (or\r
+ the block time has expired) so leave now. */\r
+ taskEXIT_CRITICAL();\r
+ traceQUEUE_RECEIVE_FAILED( pxQueue );\r
+ return errQUEUE_EMPTY;\r
+ }\r
+ else if( xEntryTimeSet == pdFALSE )\r
+ {\r
+ /* The queue was empty and a block time was specified so\r
+ configure the timeout structure. */\r
+ vTaskSetTimeOutState( &xTimeOut );\r
+ xEntryTimeSet = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ /* Entry time was already set. */\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ }\r
+ taskEXIT_CRITICAL();\r
+\r
+ /* Interrupts and other tasks can send to and receive from the queue\r
+ now the critical section has been exited. */\r
+\r
+ vTaskSuspendAll();\r
+ prvLockQueue( pxQueue );\r
+\r
+ /* Update the timeout state to see if it has expired yet. */\r
+ if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
+ {\r
+ /* The timeout has not expired. If the queue is still empty place\r
+ the task on the list of tasks waiting to receive from the queue. */\r
+ if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
+ {\r
+ traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
+ vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
+ prvUnlockQueue( pxQueue );\r
+ if( xTaskResumeAll() == pdFALSE )\r
+ {\r
+ portYIELD_WITHIN_API();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* The queue contains data again. Loop back to try and read the\r
+ data. */\r
+ prvUnlockQueue( pxQueue );\r
+ ( void ) xTaskResumeAll();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* Timed out. If there is no data in the queue exit, otherwise loop\r
+ back and attempt to read the data. */\r
+ prvUnlockQueue( pxQueue );\r
+ ( void ) xTaskResumeAll();\r
+\r
+ if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
+ {\r
+ traceQUEUE_RECEIVE_FAILED( pxQueue );\r
+ return errQUEUE_EMPTY;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait )\r
+{\r
+BaseType_t xEntryTimeSet = pdFALSE;\r
+TimeOut_t xTimeOut;\r
+Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+\r
+#if( configUSE_MUTEXES == 1 )\r
+ BaseType_t xInheritanceOccurred = pdFALSE;\r
+#endif\r
+\r
+ /* Check the queue pointer is not NULL. */\r
+ configASSERT( ( pxQueue ) );\r
+\r
+ /* Check this really is a semaphore, in which case the item size will be\r
+ 0. */\r