/*\r
- * FreeRTOS Kernel V10.0.0\r
+ * FreeRTOS Kernel V10.0.1\r
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
*\r
* Permission is hereby granted, free of charge, to any person obtaining a copy of\r
* subject to the following conditions:\r
*\r
* The above copyright notice and this permission notice shall be included in all\r
- * copies or substantial portions of the Software. If you wish to use our Amazon\r
- * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
+ * copies or substantial portions of the Software.\r
*\r
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
#include "task.h"\r
#include "stream_buffer.h"\r
\r
+#if( configUSE_TASK_NOTIFICATIONS != 1 )\r
+ #error configUSE_TASK_NOTIFICATIONS must be set to 1 to build stream_buffer.c\r
+#endif\r
+\r
/* Lint e961 and e750 are suppressed as a MISRA exception justified because the\r
MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the\r
header files above, but not in this file, in order to generate the correct\r
/*lint -restore (9026) */\r
\r
/* The number of bytes used to hold the length of a message in the buffer. */\r
-#define sbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( size_t ) )\r
+#define sbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) )\r
\r
/* Bits stored in the ucFlags field of the stream buffer. */\r
#define sbFLAGS_IS_MESSAGE_BUFFER ( ( uint8_t ) 1 ) /* Set if the stream buffer was created as a message buffer, in which case it holds discrete messages rather than a stream. */\r
if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )\r
{\r
xRequiredSpace += sbBYTES_TO_STORE_MESSAGE_LENGTH;\r
+\r
+ /* Overflow? */\r
+ configASSERT( xRequiredSpace > xDataLengthBytes );\r
}\r
else\r
{\r
taskEXIT_CRITICAL();\r
\r
traceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer );\r
- ( void ) xTaskNotifyWait( ( uint32_t ) 0, UINT32_MAX, NULL, xTicksToWait );\r
+ ( void ) xTaskNotifyWait( ( uint32_t ) 0, ( uint32_t ) 0, NULL, xTicksToWait );\r
pxStreamBuffer->xTaskWaitingToSend = NULL;\r
\r
} while( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE );\r
{\r
/* Wait for data to be available. */\r
traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer );\r
- ( void ) xTaskNotifyWait( ( uint32_t ) 0, UINT32_MAX, NULL, xTicksToWait );\r
+ ( void ) xTaskNotifyWait( ( uint32_t ) 0, ( uint32_t ) 0, NULL, xTicksToWait );\r
pxStreamBuffer->xTaskWaitingToReceive = NULL;\r
\r
/* Recheck the data available after blocking. */\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
+configMESSAGE_BUFFER_LENGTH_TYPE xTempReturn;\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 * ) &xTempReturn, sbBYTES_TO_STORE_MESSAGE_LENGTH, xBytesAvailable );\r
+ xReturn = ( size_t ) xTempReturn;\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
size_t xBytesToStoreMessageLength )\r
{\r
size_t xOriginalTail, xReceivedLength, xNextMessageLength;\r
+configMESSAGE_BUFFER_LENGTH_TYPE xTempNextMessageLength;\r
\r
if( xBytesToStoreMessageLength != ( size_t ) 0 )\r
{\r
returned to its prior state if the length of the message is too\r
large for the provided buffer. */\r
xOriginalTail = pxStreamBuffer->xTail;\r
- ( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xNextMessageLength, xBytesToStoreMessageLength, xBytesAvailable );\r
+ ( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xTempNextMessageLength, xBytesToStoreMessageLength, xBytesAvailable );\r
+ xNextMessageLength = ( size_t ) xTempNextMessageLength;\r
\r
/* Reduce the number of bytes available by the number of bytes just\r
read out. */\r
\r
uint8_t ucStreamBufferGetStreamBufferType( StreamBufferHandle_t xStreamBuffer )\r
{\r
- return ( ( StreamBuffer_t * )xStreamBuffer )->ucFlags | sbFLAGS_IS_MESSAGE_BUFFER;\r
+ return ( ( StreamBuffer_t * )xStreamBuffer )->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER;\r
}\r
\r
#endif /* configUSE_TRACE_FACILITY */\r