Fix regressions introduced by introduction of configMESSAGE_BUFFER_LENGTH_TYPE constant - specifically enabling big endian support and updates to xStreamBufferNextMessageLengthBytes.

This commit is contained in:
Richard Barry 2018-03-15 18:31:02 +00:00
parent 3ec86b7a98
commit 025088c280
2 changed files with 24 additions and 16 deletions

View file

@ -41,7 +41,7 @@
#define mbMESSAGE_BUFFER_LENGTH_BYTES ( ( size_t ) 50 ) #define mbMESSAGE_BUFFER_LENGTH_BYTES ( ( size_t ) 50 )
/* The number of additional bytes used to store the length of each message. */ /* The number of additional bytes used to store the length of each message. */
#define mbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( size_t ) ) #define mbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) )
/* Start and end ASCII characters used in messages sent to the buffers. */ /* Start and end ASCII characters used in messages sent to the buffers. */
#define mbASCII_SPACE 32 #define mbASCII_SPACE 32
@ -191,7 +191,8 @@ UBaseType_t uxOriginalPriority;
additional 4 bytes are added to hold the item's size. That means adding additional 4 bytes are added to hold the item's size. That means adding
6 bytes to the buffer will actually add 10 bytes to the buffer. Therefore, 6 bytes to the buffer will actually add 10 bytes to the buffer. Therefore,
with a 50 byte buffer, a maximum of 5 6 bytes items can be added before the with a 50 byte buffer, a maximum of 5 6 bytes items can be added before the
buffer is completely full. */ buffer is completely full. NOTE: The numbers in this paragraph assume
sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) == 4. */
for( xItem = 0; xItem < xMax6ByteMessages; xItem++ ) for( xItem = 0; xItem < xMax6ByteMessages; xItem++ )
{ {
configASSERT( xMessageBufferIsFull( xMessageBuffer ) == pdFALSE ); configASSERT( xMessageBufferIsFull( xMessageBuffer ) == pdFALSE );
@ -377,15 +378,21 @@ UBaseType_t uxOriginalPriority;
xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES, mbDONT_BLOCK ); xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES, mbDONT_BLOCK );
configASSERT( xReturned == 0 ); configASSERT( xReturned == 0 );
( void ) xReturned; /* In case configASSERT() is not defined. */ ( void ) xReturned; /* In case configASSERT() is not defined. */
xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 1, mbDONT_BLOCK ); #ifndef configMESSAGE_BUFFER_LENGTH_TYPE
configASSERT( xReturned == 0 ); {
( void ) xReturned; /* In case configASSERT() is not defined. */ /* The following will fail if configMESSAGE_BUFFER_LENGTH_TYPE is set
xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 2, mbDONT_BLOCK ); to a non 32-bit type. */
configASSERT( xReturned == 0 ); xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 1, mbDONT_BLOCK );
( void ) xReturned; /* In case configASSERT() is not defined. */ configASSERT( xReturned == 0 );
xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 3, mbDONT_BLOCK ); ( void ) xReturned; /* In case configASSERT() is not defined. */
configASSERT( xReturned == 0 ); xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 2, mbDONT_BLOCK );
( void ) xReturned; /* In case configASSERT() is not defined. */ configASSERT( xReturned == 0 );
( void ) xReturned; /* In case configASSERT() is not defined. */
xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 3, mbDONT_BLOCK );
configASSERT( xReturned == 0 );
( void ) xReturned; /* In case configASSERT() is not defined. */
}
#endif
/* Don't expect any messages to be available as the above were too large to /* Don't expect any messages to be available as the above were too large to
get written. */ get written. */

View file

@ -799,6 +799,7 @@ size_t xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer )
{ {
StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */ StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */
size_t xReturn, xBytesAvailable, xOriginalTail; size_t xReturn, xBytesAvailable, xOriginalTail;
configMESSAGE_BUFFER_LENGTH_TYPE xTempReturn;
configASSERT( pxStreamBuffer ); configASSERT( pxStreamBuffer );
@ -815,7 +816,8 @@ size_t xReturn, xBytesAvailable, xOriginalTail;
returned to its prior state as the message is not actually being returned to its prior state as the message is not actually being
removed from the buffer. */ removed from the buffer. */
xOriginalTail = pxStreamBuffer->xTail; xOriginalTail = pxStreamBuffer->xTail;
( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xReturn, sbBYTES_TO_STORE_MESSAGE_LENGTH, xBytesAvailable ); ( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xTempReturn, sbBYTES_TO_STORE_MESSAGE_LENGTH, xBytesAvailable );
xReturn = ( size_t ) xTempReturn;
pxStreamBuffer->xTail = xOriginalTail; pxStreamBuffer->xTail = xOriginalTail;
} }
else else
@ -901,6 +903,7 @@ static size_t prvReadMessageFromBuffer( StreamBuffer_t *pxStreamBuffer,
size_t xBytesToStoreMessageLength ) size_t xBytesToStoreMessageLength )
{ {
size_t xOriginalTail, xReceivedLength, xNextMessageLength; size_t xOriginalTail, xReceivedLength, xNextMessageLength;
configMESSAGE_BUFFER_LENGTH_TYPE xTempNextMessageLength;
if( xBytesToStoreMessageLength != ( size_t ) 0 ) if( xBytesToStoreMessageLength != ( size_t ) 0 )
{ {
@ -909,10 +912,8 @@ size_t xOriginalTail, xReceivedLength, xNextMessageLength;
returned to its prior state if the length of the message is too returned to its prior state if the length of the message is too
large for the provided buffer. */ large for the provided buffer. */
xOriginalTail = pxStreamBuffer->xTail; xOriginalTail = pxStreamBuffer->xTail;
/* Ensure xNextMessageLength is cleared to 0 in case ( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xTempNextMessageLength, xBytesToStoreMessageLength, xBytesAvailable );
sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) != sizeof( size_t ). */ xNextMessageLength = ( size_t ) xTempNextMessageLength;
xNextMessageLength = 0;
( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xNextMessageLength, xBytesToStoreMessageLength, xBytesAvailable );
/* Reduce the number of bytes available by the number of bytes just /* Reduce the number of bytes available by the number of bytes just
read out. */ read out. */