MCPcopy Create free account
hub / github.com/FreeRTOS/FreeRTOS-Kernel / xStreamBufferReceive

Function xStreamBufferReceive

stream_buffer.c:752–853  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

750/*-----------------------------------------------------------*/
751
752size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer,
753 void * pvRxData,
754 size_t xBufferLengthBytes,
755 TickType_t xTicksToWait )
756{
757 StreamBuffer_t * const pxStreamBuffer = xStreamBuffer;
758 size_t xReceivedLength = 0, xBytesAvailable, xBytesToStoreMessageLength;
759
760 configASSERT( pvRxData );
761 configASSERT( pxStreamBuffer );
762
763 /* This receive function is used by both message buffers, which store
764 * discrete messages, and stream buffers, which store a continuous stream of
765 * bytes. Discrete messages include an additional
766 * sbBYTES_TO_STORE_MESSAGE_LENGTH bytes that hold the length of the
767 * message. */
768 if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )
769 {
770 xBytesToStoreMessageLength = sbBYTES_TO_STORE_MESSAGE_LENGTH;
771 }
772 else
773 {
774 xBytesToStoreMessageLength = 0;
775 }
776
777 if( xTicksToWait != ( TickType_t ) 0 )
778 {
779 /* Checking if there is data and clearing the notification state must be
780 * performed atomically. */
781 taskENTER_CRITICAL();
782 {
783 xBytesAvailable = prvBytesInBuffer( pxStreamBuffer );
784
785 /* If this function was invoked by a message buffer read then
786 * xBytesToStoreMessageLength holds the number of bytes used to hold
787 * the length of the next discrete message. If this function was
788 * invoked by a stream buffer read then xBytesToStoreMessageLength will
789 * be 0. */
790 if( xBytesAvailable <= xBytesToStoreMessageLength )
791 {
792 /* Clear notification state as going to wait for data. */
793 ( void ) xTaskNotifyStateClear( NULL );
794
795 /* Should only be one reader. */
796 configASSERT( pxStreamBuffer->xTaskWaitingToReceive == NULL );
797 pxStreamBuffer->xTaskWaitingToReceive = xTaskGetCurrentTaskHandle();
798 }
799 else
800 {
801 mtCOVERAGE_TEST_MARKER();
802 }
803 }
804 taskEXIT_CRITICAL();
805
806 if( xBytesAvailable <= xBytesToStoreMessageLength )
807 {
808 /* Wait for data to be available. */
809 traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer );

Callers 1

MPU_xStreamBufferReceiveFunction · 0.85

Calls 3

prvBytesInBufferFunction · 0.85
prvReadMessageFromBufferFunction · 0.85

Tested by

no test coverage detected