From f9095e9a16268198198f83c31c40e35a51658f4a Mon Sep 17 00:00:00 2001 From: rtel Date: Thu, 15 Mar 2018 18:31:02 +0000 Subject: [PATCH] Fix regressions introduced by introduction of configMESSAGE_BUFFER_LENGTH_TYPE constant - specifically enabling big endian support and updates to xStreamBufferNextMessageLengthBytes. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2536 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../Demo/Common/Minimal/MessageBufferDemo.c | 29 ++++++++++++------- FreeRTOS/Source/stream_buffer.c | 11 +++---- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c b/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c index 4422b2bd5..819600db1 100644 --- a/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c +++ b/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c @@ -41,7 +41,7 @@ #define mbMESSAGE_BUFFER_LENGTH_BYTES ( ( size_t ) 50 ) /* 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. */ #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 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 - 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++ ) { configASSERT( xMessageBufferIsFull( xMessageBuffer ) == pdFALSE ); @@ -377,15 +378,21 @@ UBaseType_t uxOriginalPriority; xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES, mbDONT_BLOCK ); configASSERT( xReturned == 0 ); ( void ) xReturned; /* In case configASSERT() is not defined. */ - xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 1, mbDONT_BLOCK ); - configASSERT( xReturned == 0 ); - ( void ) xReturned; /* In case configASSERT() is not defined. */ - xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 2, mbDONT_BLOCK ); - 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. */ + #ifndef configMESSAGE_BUFFER_LENGTH_TYPE + { + /* The following will fail if configMESSAGE_BUFFER_LENGTH_TYPE is set + to a non 32-bit type. */ + xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 1, mbDONT_BLOCK ); + configASSERT( xReturned == 0 ); + ( void ) xReturned; /* In case configASSERT() is not defined. */ + xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 2, mbDONT_BLOCK ); + 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 get written. */ diff --git a/FreeRTOS/Source/stream_buffer.c b/FreeRTOS/Source/stream_buffer.c index ed8baef91..1f053b7dd 100644 --- a/FreeRTOS/Source/stream_buffer.c +++ b/FreeRTOS/Source/stream_buffer.c @@ -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. */ size_t xReturn, xBytesAvailable, xOriginalTail; +configMESSAGE_BUFFER_LENGTH_TYPE xTempReturn; configASSERT( pxStreamBuffer ); @@ -815,7 +816,8 @@ size_t xReturn, xBytesAvailable, xOriginalTail; returned to its prior state as the message is not actually being removed from the buffer. */ 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; } else @@ -901,6 +903,7 @@ static size_t prvReadMessageFromBuffer( StreamBuffer_t *pxStreamBuffer, size_t xBytesToStoreMessageLength ) { size_t xOriginalTail, xReceivedLength, xNextMessageLength; +configMESSAGE_BUFFER_LENGTH_TYPE xTempNextMessageLength; 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 large for the provided buffer. */ xOriginalTail = pxStreamBuffer->xTail; - /* Ensure xNextMessageLength is cleared to 0 in case - sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) != sizeof( size_t ). */ - xNextMessageLength = 0; - ( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xNextMessageLength, xBytesToStoreMessageLength, xBytesAvailable ); + ( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xTempNextMessageLength, xBytesToStoreMessageLength, xBytesAvailable ); + xNextMessageLength = ( size_t ) xTempNextMessageLength; /* Reduce the number of bytes available by the number of bytes just read out. */ -- 2.39.5