+ if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+ {\r
+ if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+ {\r
+ /* The task waiting has a higher priority so record that a\r
+ context switch is required. */\r
+ if( pxHigherPriorityTaskWoken != NULL )\r
+ {\r
+ *pxHigherPriorityTaskWoken = pdTRUE;\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ #endif /* configUSE_QUEUE_SETS */\r
+ }\r
+ else\r
+ {\r
+ /* Increment the lock count so the task that unlocks the queue\r
+ knows that data was posted while it was locked. */\r
+ pxQueue->cTxLock = ( int8_t ) ( cTxLock + 1 );\r
+ }\r
+\r
+ xReturn = pdPASS;\r
+ }\r
+ else\r
+ {\r
+ traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );\r
+ xReturn = errQUEUE_FULL;\r
+ }\r
+ }\r
+ portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+\r
+ return xReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+BaseType_t xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait )\r
+{\r
+BaseType_t xEntryTimeSet = pdFALSE;\r
+TimeOut_t xTimeOut;\r
+Queue_t * const pxQueue = xQueue;\r
+\r
+ /* Check the pointer is not NULL. */\r
+ configASSERT( ( pxQueue ) );\r
+\r
+ /* The buffer into which data is received can only be NULL if the data size\r
+ is zero (so no data is copied into the buffer. */\r
+ configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
+\r
+ /* 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
+ /*lint -save -e904 This function relaxes the coding standard somewhat to\r
+ allow return statements within the function itself. This is done in the\r
+ interest of execution time efficiency. */\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
+ vTaskInternalSetTimeOutState( &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
+ } /*lint -restore */\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 = 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
+ configASSERT( pxQueue->uxItemSize == 0 );\r
+\r
+ /* 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
+ /*lint -save -e904 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
+ for( ;; )\r
+ {\r
+ taskENTER_CRITICAL();\r
+ {\r
+ /* Semaphores are queues with an item size of 0, and where the\r
+ number of messages in the queue is the semaphore's count value. */\r
+ const UBaseType_t uxSemaphoreCount = 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( uxSemaphoreCount > ( UBaseType_t ) 0 )\r
+ {\r
+ traceQUEUE_RECEIVE( pxQueue );\r
+\r
+ /* Semaphores are queues with a data size of zero and where the\r
+ messages waiting is the semaphore's count. Reduce the count. */\r
+ pxQueue->uxMessagesWaiting = uxSemaphoreCount - ( UBaseType_t ) 1;\r
+\r
+ #if ( configUSE_MUTEXES == 1 )\r
+ {\r
+ if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
+ {\r
+ /* Record the information required to implement\r
+ priority inheritance should it become necessary. */\r
+ pxQueue->u.xSemaphore.xMutexHolder = pvTaskIncrementMutexHeldCount();\r
+ }\r
+ else\r
+ {\r
+ mtCOVERAGE_TEST_MARKER();\r
+ }\r
+ }\r
+ #endif /* configUSE_MUTEXES */\r
+\r
+ /* Check to see if other tasks are blocked waiting to give the\r
+ semaphore, and if so, unblock the highest priority such 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
+ /* For inheritance to have occurred there must have been an\r
+ initial timeout, and an adjusted timeout cannot become 0, as\r
+ if it were 0 the function would have exited. */\r
+ #if( configUSE_MUTEXES == 1 )\r
+ {\r
+ configASSERT( xInheritanceOccurred == pdFALSE );\r
+ }\r
+ #endif /* configUSE_MUTEXES */\r
+\r
+ /* The semaphore count was 0 and no block time is specified\r
+ (or the block time has expired) so exit now. */\r
+ taskEXIT_CRITICAL();\r
+ traceQUEUE_RECEIVE_FAILED( pxQueue );\r
+ return errQUEUE_EMPTY;\r
+ }\r
+ else if( xEntryTimeSet == pdFALSE )\r
+ {\r
+ /* The semaphore count was 0 and a block time was specified\r
+ so configure the timeout structure ready to block. */\r
+ vTaskInternalSetTimeOutState( &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 give to and take from the semaphore\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
+ /* A block time is specified and not expired. If the semaphore\r
+ count is 0 then enter the Blocked state to wait for a semaphore to\r
+ become available. As semaphores are implemented with queues the\r
+ queue being empty is equivalent to the semaphore count being 0. */\r
+ if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
+ {\r
+ traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
+\r
+ #if ( configUSE_MUTEXES == 1 )\r
+ {\r
+ if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r