\r
static void prvSingleTaskTests( MessageBufferHandle_t xMessageBuffer )\r
{\r
-size_t xReturned, xItem, xExpectedSpace;\r
+size_t xReturned, xItem, xExpectedSpace, xNextLength;\r
const size_t xMax6ByteMessages = mbMESSAGE_BUFFER_LENGTH_BYTES / ( 6 + mbBYTES_TO_STORE_MESSAGE_LENGTH );\r
const size_t x6ByteLength = 6, x17ByteLength = 17;\r
uint8_t *pucFullBuffer, *pucData, *pucReadData;\r
pucReadData = pucData + x17ByteLength;\r
\r
/* Nothing has been added or removed yet, so expect the free space to be\r
- exactly as created. */\r
+ exactly as created and the length of the next message to be 0. */\r
xExpectedSpace = xMessageBufferSpaceAvailable( xMessageBuffer );\r
configASSERT( xExpectedSpace == mbMESSAGE_BUFFER_LENGTH_BYTES );\r
configASSERT( xMessageBufferIsEmpty( xMessageBuffer ) == pdTRUE );\r
-\r
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );\r
+ configASSERT( xNextLength == 0 );\r
+ /* In case configASSERT() is not define. */\r
+ ( void ) xExpectedSpace;\r
+ ( void ) xNextLength;\r
\r
/* The buffer is 50 bytes long. When an item is added to the buffer an\r
additional 4 bytes are added to hold the item's size. That means adding\r
xReturned = xMessageBufferSpaceAvailable( xMessageBuffer );\r
configASSERT( xReturned == xExpectedSpace );\r
( void ) xReturned; /* In case configASSERT() is not defined. */\r
+\r
+ /* Only 6 byte messages are written. */\r
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );\r
+ configASSERT( xNextLength == x6ByteLength );\r
+ ( void ) xNextLength; /* In case configASSERT() is not defined. */\r
}\r
\r
/* Now the buffer should be full, and attempting to add anything will should\r
configASSERT( xReturned == 0 );\r
( void ) xReturned; /* In case configASSERT() is not defined. */\r
\r
+ /* Should still be at least one 6 byte message still available. */\r
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );\r
+ configASSERT( xNextLength == x6ByteLength );\r
+ ( void ) xNextLength; /* In case configASSERT() is not defined. */\r
+\r
/* Read the next 6 bytes out. The 'FromISR' version is used to give it\r
some exercise as a block time is not used. THa requires the code to be\r
in a critical section so this test can be run with FreeRTOS ports that\r
configASSERT( xMessageBufferIsEmpty( xMessageBuffer ) == pdTRUE );\r
xExpectedSpace = xMessageBufferSpaceAvailable( xMessageBuffer );\r
configASSERT( xExpectedSpace == mbMESSAGE_BUFFER_LENGTH_BYTES );\r
+ ( void ) xExpectedSpace; /* In case configASSERT() is not defined. */\r
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );\r
+ configASSERT( xNextLength == 0 );\r
+ ( void ) xNextLength; /* In case configASSERT() is not defined. */\r
+\r
\r
/* Reading with a timeout should also fail after the appropriate time. The\r
priority is temporarily boosted in this part of the test to keep the\r
configASSERT( xReturned == x17ByteLength );\r
( void ) xReturned; /* In case configASSERT() is not defined. */\r
\r
+ /* Only 17 byte messages are written. */\r
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );\r
+ configASSERT( xNextLength == x17ByteLength );\r
+ ( void ) xNextLength; /* In case configASSERT() is not defined. */\r
+\r
/* The space in the buffer will have reduced by the amount of user data\r
written into the buffer and the amount of space used to store the length\r
of the data written into the buffer. */\r
\r
/* Does the data read out match that expected? */\r
configASSERT( memcmp( ( void * ) pucData, ( void * ) pucReadData, x17ByteLength ) == 0 );\r
+\r
+ /* Don't expect any messages to be available as the data was read out\r
+ again. */\r
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );\r
+ configASSERT( xNextLength == 0 );\r
+ ( void ) xNextLength; /* In case configASSERT() is not defined. */\r
}\r
\r
/* The buffer should be empty again. */\r
configASSERT( xReturned == 0 );\r
( void ) xReturned; /* In case configASSERT() is not defined. */\r
\r
+ /* Don't expect any messages to be available as the above were too large to\r
+ get written. */\r
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );\r
+ configASSERT( xNextLength == 0 );\r
+ ( void ) xNextLength; /* In case configASSERT() is not defined. */\r
+\r
/* Can write mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) bytes though. */\r
xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ), mbDONT_BLOCK );\r
configASSERT( xReturned == mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) );\r
( void ) xReturned; /* In case configASSERT() is not defined. */\r
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );\r
+ configASSERT( xNextLength == ( mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) ) );\r
+ ( void ) xNextLength; /* In case configASSERT() is not defined. */\r
xReturned = xMessageBufferReceive( xMessageBuffer, ( void * ) pucFullBuffer, mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ), mbDONT_BLOCK );\r
configASSERT( xReturned == ( mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) ) );\r
( void ) xReturned; /* In case configASSERT() is not defined. */\r
}\r
/*-----------------------------------------------------------*/\r
\r
+size_t xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer )\r
+{\r
+StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as StreamBufferHandle_t is opaque Streambuffer_t. */\r
+size_t xReturn, xBytesAvailable, xOriginalTail;\r
+\r
+ configASSERT( pxStreamBuffer );\r
+\r
+ /* Ensure the stream buffer is being used as a message buffer. */\r
+ if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )\r
+ {\r
+ xBytesAvailable = prvBytesInBuffer( pxStreamBuffer );\r
+ if( xBytesAvailable > sbBYTES_TO_STORE_MESSAGE_LENGTH )\r
+ {\r
+ /* The number of bytes available is greater than the number of bytes\r
+ required to hold the length of the next message, so another message\r
+ is available. Return its length without removing the length bytes\r
+ from the buffer. A copy of the tail is stored so the buffer can be\r
+ returned to its prior state as the message is not actually being\r
+ removed from the buffer. */\r
+ xOriginalTail = pxStreamBuffer->xTail;\r
+ ( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xReturn, sbBYTES_TO_STORE_MESSAGE_LENGTH, xBytesAvailable );\r
+ pxStreamBuffer->xTail = xOriginalTail;\r
+ }\r
+ else\r
+ {\r
+ /* The minimum amount of bytes in a message buffer is\r
+ ( sbBYTES_TO_STORE_MESSAGE_LENGTH + 1 ), so if xBytesAvailable is\r
+ less than sbBYTES_TO_STORE_MESSAGE_LENGTH the only other valid\r
+ value is 0. */\r
+ configASSERT( xBytesAvailable == 0 );\r
+ xReturn = 0;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ xReturn = 0;\r
+ }\r
+\r
+ return xReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer,\r
void *pvRxData,\r
size_t xBufferLengthBytes,\r