mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-09-13 01:27:48 -04:00
Edit some prv functions for simplicity and consistency
- prvWriteMessageToBuffer - prvReadMessageFromBuffer - prvWriteBytesToBuffer - prvReadBytesFromBuffer
This commit is contained in:
parent
819046743a
commit
0f3149e2a7
1 changed files with 45 additions and 60 deletions
|
@ -759,9 +759,8 @@ static size_t prvWriteMessageToBuffer( StreamBuffer_t * const pxStreamBuffer,
|
||||||
|
|
||||||
if( xShouldWrite != pdFALSE )
|
if( xShouldWrite != pdFALSE )
|
||||||
{
|
{
|
||||||
/* Writes the data itself. */
|
/* Write the actual data and update the head to mark the data as officially written. */
|
||||||
xNextHead = prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) pvTxData, xDataLengthBytes, xNextHead ); /*lint !e9079 Storage buffer is implemented as uint8_t for ease of sizing, alignment and access. */
|
pxStreamBuffer->xHead = prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) pvTxData, xDataLengthBytes, xNextHead ); /*lint !e9079 Storage buffer is implemented as uint8_t for ease of sizing, alignment and access. */
|
||||||
pxStreamBuffer->xHead = xNextHead;
|
|
||||||
xReturn = xDataLengthBytes;
|
xReturn = xDataLengthBytes;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -979,16 +978,15 @@ static size_t prvReadMessageFromBuffer( StreamBuffer_t * pxStreamBuffer,
|
||||||
size_t xBufferLengthBytes,
|
size_t xBufferLengthBytes,
|
||||||
size_t xBytesAvailable )
|
size_t xBytesAvailable )
|
||||||
{
|
{
|
||||||
size_t xTail, xCount, xNextMessageLength;
|
size_t xCount, xNextMessageLength;
|
||||||
configMESSAGE_BUFFER_LENGTH_TYPE xTempNextMessageLength;
|
configMESSAGE_BUFFER_LENGTH_TYPE xTempNextMessageLength;
|
||||||
|
size_t xNextTail = pxStreamBuffer->xTail;
|
||||||
xTail = pxStreamBuffer->xTail;
|
|
||||||
|
|
||||||
if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )
|
if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )
|
||||||
{
|
{
|
||||||
/* A discrete message is being received. First receive the length
|
/* A discrete message is being received. First receive the length
|
||||||
* of the message. */
|
* of the message. */
|
||||||
xTail = prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xTempNextMessageLength, sbBYTES_TO_STORE_MESSAGE_LENGTH, xTail );
|
xNextTail = prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xTempNextMessageLength, sbBYTES_TO_STORE_MESSAGE_LENGTH, xNextTail );
|
||||||
xNextMessageLength = ( size_t ) xTempNextMessageLength;
|
xNextMessageLength = ( size_t ) xTempNextMessageLength;
|
||||||
|
|
||||||
/* Reduce the number of bytes available by the number of bytes just
|
/* Reduce the number of bytes available by the number of bytes just
|
||||||
|
@ -1019,11 +1017,8 @@ static size_t prvReadMessageFromBuffer( StreamBuffer_t * pxStreamBuffer,
|
||||||
|
|
||||||
if( xCount != ( size_t ) 0 )
|
if( xCount != ( size_t ) 0 )
|
||||||
{
|
{
|
||||||
/* Read the actual data. */
|
/* Read the actual data and update the tail to mark the data as officially consumed. */
|
||||||
xTail = prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) pvRxData, xCount, xTail); /*lint !e9079 Data storage area is implemented as uint8_t array for ease of sizing, indexing and alignment. */
|
pxStreamBuffer->xTail = prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) pvRxData, xCount, xNextTail); /*lint !e9079 Data storage area is implemented as uint8_t array for ease of sizing, indexing and alignment. */
|
||||||
|
|
||||||
/* Update the tail to mark the data as officially consumed. */
|
|
||||||
pxStreamBuffer->xTail = xTail;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return xCount;
|
return xCount;
|
||||||
|
@ -1156,20 +1151,18 @@ static size_t prvWriteBytesToBuffer( StreamBuffer_t * const pxStreamBuffer,
|
||||||
size_t xCount,
|
size_t xCount,
|
||||||
size_t xHead )
|
size_t xHead )
|
||||||
{
|
{
|
||||||
size_t xNextHead, xFirstLength;
|
size_t xFirstLength;
|
||||||
|
|
||||||
configASSERT( xCount > ( size_t ) 0 );
|
configASSERT( xCount > ( size_t ) 0 );
|
||||||
|
|
||||||
xNextHead = xHead;
|
|
||||||
|
|
||||||
/* Calculate the number of bytes that can be added in the first write -
|
/* Calculate the number of bytes that can be added in the first write -
|
||||||
* which may be less than the total number of bytes that need to be added if
|
* which may be less than the total number of bytes that need to be added if
|
||||||
* the buffer will wrap back to the beginning. */
|
* the buffer will wrap back to the beginning. */
|
||||||
xFirstLength = configMIN( pxStreamBuffer->xLength - xNextHead, xCount );
|
xFirstLength = configMIN( pxStreamBuffer->xLength - xHead, xCount );
|
||||||
|
|
||||||
/* Write as many bytes as can be written in the first write. */
|
/* Write as many bytes as can be written in the first write. */
|
||||||
configASSERT( ( xNextHead + xFirstLength ) <= pxStreamBuffer->xLength );
|
configASSERT( ( xHead + xFirstLength ) <= pxStreamBuffer->xLength );
|
||||||
( void ) memcpy( ( void * ) ( &( pxStreamBuffer->pucBuffer[ xNextHead ] ) ), ( const void * ) pucData, xFirstLength ); /*lint !e9087 memcpy() requires void *. */
|
( void ) memcpy( ( void * ) ( &( pxStreamBuffer->pucBuffer[ xHead ] ) ), ( const void * ) pucData, xFirstLength ); /*lint !e9087 memcpy() requires void *. */
|
||||||
|
|
||||||
/* If the number of bytes written was less than the number that could be
|
/* If the number of bytes written was less than the number that could be
|
||||||
* written in the first write... */
|
* written in the first write... */
|
||||||
|
@ -1184,18 +1177,18 @@ static size_t prvWriteBytesToBuffer( StreamBuffer_t * const pxStreamBuffer,
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
|
|
||||||
xNextHead += xCount;
|
xHead += xCount;
|
||||||
|
|
||||||
if( xNextHead >= pxStreamBuffer->xLength )
|
if( xHead >= pxStreamBuffer->xLength )
|
||||||
{
|
{
|
||||||
xNextHead -= pxStreamBuffer->xLength;
|
xHead -= pxStreamBuffer->xLength;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
|
|
||||||
return xNextHead;
|
return xHead;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -1204,22 +1197,20 @@ static size_t prvReadBytesFromBuffer( StreamBuffer_t * pxStreamBuffer,
|
||||||
size_t xCount,
|
size_t xCount,
|
||||||
size_t xTail )
|
size_t xTail )
|
||||||
{
|
{
|
||||||
size_t xFirstLength, xNextTail;
|
size_t xFirstLength;
|
||||||
|
|
||||||
xNextTail = xTail;
|
configASSERT( xCount != ( size_t ) 0 );
|
||||||
if( xCount > ( size_t ) 0 )
|
|
||||||
{
|
|
||||||
|
|
||||||
/* Calculate the number of bytes that can be read - which may be
|
/* Calculate the number of bytes that can be read - which may be
|
||||||
* less than the number wanted if the data wraps around to the start of
|
* less than the number wanted if the data wraps around to the start of
|
||||||
* the buffer. */
|
* the buffer. */
|
||||||
xFirstLength = configMIN( pxStreamBuffer->xLength - xNextTail, xCount );
|
xFirstLength = configMIN( pxStreamBuffer->xLength - xTail, xCount );
|
||||||
|
|
||||||
/* Obtain the number of bytes it is possible to obtain in the first
|
/* Obtain the number of bytes it is possible to obtain in the first
|
||||||
* read. Asserts check bounds of read and write. */
|
* read. Asserts check bounds of read and write. */
|
||||||
configASSERT( xFirstLength <= xCount );
|
configASSERT( xFirstLength <= xCount );
|
||||||
configASSERT( ( xNextTail + xFirstLength ) <= pxStreamBuffer->xLength );
|
configASSERT( ( xTail + xFirstLength ) <= pxStreamBuffer->xLength );
|
||||||
( void ) memcpy( ( void * ) pucData, ( const void * ) &( pxStreamBuffer->pucBuffer[ xNextTail ] ), xFirstLength ); /*lint !e9087 memcpy() requires void *. */
|
( void ) memcpy( ( void * ) pucData, ( const void * ) &( pxStreamBuffer->pucBuffer[ xTail ] ), xFirstLength ); /*lint !e9087 memcpy() requires void *. */
|
||||||
|
|
||||||
/* If the total number of wanted bytes is greater than the number
|
/* If the total number of wanted bytes is greater than the number
|
||||||
* that could be read in the first read... */
|
* that could be read in the first read... */
|
||||||
|
@ -1234,21 +1225,15 @@ static size_t prvReadBytesFromBuffer( StreamBuffer_t * pxStreamBuffer,
|
||||||
mtCOVERAGE_TEST_MARKER();
|
mtCOVERAGE_TEST_MARKER();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move the tail pointer to effectively remove the data read from
|
/* Move the tail pointer to effectively remove the data read from the buffer. */
|
||||||
* the buffer. */
|
xTail += xCount;
|
||||||
xNextTail += xCount;
|
|
||||||
|
|
||||||
if( xNextTail >= pxStreamBuffer->xLength )
|
if( xTail >= pxStreamBuffer->xLength )
|
||||||
{
|
{
|
||||||
xNextTail -= pxStreamBuffer->xLength;
|
xTail -= pxStreamBuffer->xLength;
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return xNextTail;
|
return xTail;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue