Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stream Batching Buffer #916

Merged
merged 18 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -2402,15 +2402,15 @@
#endif

#ifndef traceENTER_xStreamBufferGenericCreate
#define traceENTER_xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, xIsMessageBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback )
#define traceENTER_xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, xIsMessageBuffer, xIsBatchingBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following macros also need to be udpated:

  • traceSTREAM_BUFFER_CREATE_FAILED
  • traceSTREAM_BUFFER_CREATE_STATIC_FAILED
  • traceSTREAM_BUFFER_CREATE

#endif

#ifndef traceRETURN_xStreamBufferGenericCreate
#define traceRETURN_xStreamBufferGenericCreate( pvAllocatedMemory )
#endif

#ifndef traceENTER_xStreamBufferGenericCreateStatic
#define traceENTER_xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, xIsMessageBuffer, pucStreamBufferStorageArea, pxStaticStreamBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback )
#define traceENTER_xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, xIsMessageBuffer, xIsBatchingBuffer, pucStreamBufferStorageArea, pxStaticStreamBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback )
#endif

#ifndef traceRETURN_xStreamBufferGenericCreateStatic
Expand Down
8 changes: 4 additions & 4 deletions include/message_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ typedef StreamBufferHandle_t MessageBufferHandle_t;
* \ingroup MessageBufferManagement
*/
#define xMessageBufferCreate( xBufferSizeBytes ) \
xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( size_t ) 0, pdTRUE, NULL, NULL )
xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( size_t ) 0, pdTRUE, pdFALSE, NULL, NULL )

#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
#define xMessageBufferCreateWithCallback( xBufferSizeBytes, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( size_t ) 0, pdTRUE, ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( size_t ) 0, pdTRUE, pdFALSE, ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
#endif

/**
Expand Down Expand Up @@ -243,11 +243,11 @@ typedef StreamBufferHandle_t MessageBufferHandle_t;
* \ingroup MessageBufferManagement
*/
#define xMessageBufferCreateStatic( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer ) \
xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), 0, pdTRUE, ( pucMessageBufferStorageArea ), ( pxStaticMessageBuffer ), NULL, NULL )
xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), 0, pdTRUE, pdFALSE, ( pucMessageBufferStorageArea ), ( pxStaticMessageBuffer ), NULL, NULL )

#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
#define xMessageBufferCreateStaticWithCallback( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), 0, pdTRUE, ( pucMessageBufferStorageArea ), ( pxStaticMessageBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), 0, pdTRUE, pdFALSE, ( pucMessageBufferStorageArea ), ( pxStaticMessageBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
#endif

/**
Expand Down
2 changes: 2 additions & 0 deletions include/mpu_prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,13 @@ size_t MPU_xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuff
StreamBufferHandle_t MPU_xStreamBufferGenericCreate( size_t xBufferSizeBytes,
size_t xTriggerLevelBytes,
BaseType_t xIsMessageBuffer,
BaseType_t xIsBatchingBuffer,
StreamBufferCallbackFunction_t pxSendCompletedCallback,
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION;
StreamBufferHandle_t MPU_xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
size_t xTriggerLevelBytes,
BaseType_t xIsMessageBuffer,
BaseType_t xIsBatchingBuffer,
uint8_t * const pucStreamBufferStorageArea,
StaticStreamBuffer_t * const pxStaticStreamBuffer,
StreamBufferCallbackFunction_t pxSendCompletedCallback,
Expand Down
182 changes: 178 additions & 4 deletions include/stream_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ typedef void (* StreamBufferCallbackFunction_t)( StreamBufferHandle_t xStreamBuf
*/

#define xStreamBufferCreate( xBufferSizeBytes, xTriggerLevelBytes ) \
xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, NULL, NULL )
xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, pdFALSE, NULL, NULL )

#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
#define xStreamBufferCreateWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, pdFALSE, ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
#endif

/**
Expand Down Expand Up @@ -257,11 +257,183 @@ typedef void (* StreamBufferCallbackFunction_t)( StreamBufferHandle_t xStreamBuf
*/

#define xStreamBufferCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer ) \
xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), NULL, NULL )
xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, pdFALSE, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), NULL, NULL )

#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
#define xStreamBufferCreateStaticWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, pdFALSE, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
#endif

/**
* stream_buffer.h
*
* @code{c}
* StreamBufferHandle_t xStreamBatchingBufferCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes );
* @endcode
*
* Creates a new stream batching buffer using dynamically allocated memory. See
* xStreamBatchingBufferCreateStatic() for a version that uses statically
* allocated memory (memory that is allocated at compile time).
*
* configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in
* FreeRTOSConfig.h for xStreamBatchingBufferCreate() to be available.
* configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for
* xStreamBatchingBufferCreate() to be available.
*
* @param xBufferSizeBytes The total number of bytes the stream batching buffer
* will be able to hold at any one time.
*
* @param xTriggerLevelBytes The number of bytes that must be in the stream
* batching buffer to unblock a task calling xStreamBufferReceive before the
* block time expires.
*
* @param pxSendCompletedCallback Callback invoked when number of bytes at least
* equal to trigger level is sent to the stream batching buffer. If the
* parameter is NULL, it will use the default implementation provided by
* sbSEND_COMPLETED macro. To enable the callback, configUSE_SB_COMPLETED_CALLBACK
* must be set to 1 in FreeRTOSConfig.h.
*
* @param pxReceiveCompletedCallback Callback invoked when more than zero bytes
* are read from a stream batching buffer. If the parameter is NULL, it will use
* the default implementation provided by sbRECEIVE_COMPLETED macro. To enable
* the callback, configUSE_SB_COMPLETED_CALLBACK must be set to 1 in
* FreeRTOSConfig.h.
*
* @return If NULL is returned, then the stream batching buffer cannot be created
* because there is insufficient heap memory available for FreeRTOS to allocate
* the stream batching buffer data structures and storage area. A non-NULL value
* being returned indicates that the stream batching buffer has been created
* successfully - the returned value should be stored as the handle to the
* created stream batching buffer.
*
* Example use:
* @code{c}
*
* void vAFunction( void )
* {
* StreamBufferHandle_t xStreamBatchingBuffer;
* const size_t xStreamBufferSizeBytes = 100, xTriggerLevel = 10;
*
* // Create a stream batching buffer that can hold 100 bytes. The memory used
* // to hold both the stream batching buffer structure and the data in the stream
* // batching buffer is allocated dynamically.
* xStreamBatchingBuffer = xStreamBatchingBufferCreate( xStreamBufferSizeBytes, xTriggerLevel );
*
* if( xStreamBatchingBuffer == NULL )
* {
* // There was not enough heap memory space available to create the
* // stream batching buffer.
* }
* else
* {
* // The stream batching buffer was created successfully and can now be used.
* }
* }
* @endcode
* \defgroup xStreamBatchingBufferCreate xStreamBatchingBufferCreate
* \ingroup StreamBatchingBufferManagement
*/

#define xStreamBatchingBufferCreate( xBufferSizeBytes, xTriggerLevelBytes ) \
xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, pdTRUE, NULL, NULL )

#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
#define xStreamBatchingBufferCreateWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, pdTRUE, ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
#endif

/**
* stream_buffer.h
*
* @code{c}
* StreamBufferHandle_t xStreamBatchingBufferCreateStatic( size_t xBufferSizeBytes,
* size_t xTriggerLevelBytes,
* uint8_t *pucStreamBufferStorageArea,
* StaticStreamBuffer_t *pxStaticStreamBuffer );
* @endcode
* Creates a new stream batching buffer using statically allocated memory. See
* xStreamBatchingBufferCreate() for a version that uses dynamically allocated
* memory.
*
* configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h for
* xStreamBatchingBufferCreateStatic() to be available. configUSE_STREAM_BUFFERS
* must be set to 1 in for FreeRTOSConfig.h for xStreamBatchingBufferCreateStatic()
* to be available.
*
* @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the
* pucStreamBufferStorageArea parameter.
*
* @param xTriggerLevelBytes The number of bytes that must be in the stream
* batching buffer to unblock a task calling xStreamBufferReceive before the
* block time expires.
*
* @param pucStreamBufferStorageArea Must point to a uint8_t array that is at
* least xBufferSizeBytes big. This is the array to which streams are
* copied when they are written to the stream batching buffer.
*
* @param pxStaticStreamBuffer Must point to a variable of type
* StaticStreamBuffer_t, which will be used to hold the stream batching buffer's
* data structure.
*
* @param pxSendCompletedCallback Callback invoked when number of bytes at least
* equal to trigger level is sent to the stream batching buffer. If the parameter
* is NULL, it will use the default implementation provided by sbSEND_COMPLETED
* macro. To enable the callback, configUSE_SB_COMPLETED_CALLBACK must be set to
* 1 in FreeRTOSConfig.h.
*
* @param pxReceiveCompletedCallback Callback invoked when more than zero bytes
* are read from a stream batching buffer. If the parameter is NULL, it will use
* the default implementation provided by sbRECEIVE_COMPLETED macro. To enable
* the callback, configUSE_SB_COMPLETED_CALLBACK must be set to 1 in
* FreeRTOSConfig.h.
*
* @return If the stream batching buffer is created successfully then a handle
* to the created stream batching buffer is returned. If either pucStreamBufferStorageArea
* or pxStaticstreamBuffer are NULL then NULL is returned.
*
* Example use:
* @code{c}
*
* // Used to dimension the array used to hold the streams. The available space
* // will actually be one less than this, so 999.
* #define STORAGE_SIZE_BYTES 1000
*
* // Defines the memory that will actually hold the streams within the stream
* // batching buffer.
* static uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];
*
* // The variable used to hold the stream batching buffer structure.
* StaticStreamBuffer_t xStreamBufferStruct;
*
* void MyFunction( void )
* {
* StreamBufferHandle_t xStreamBatchingBuffer;
* const size_t xTriggerLevel = 1;
*
* xStreamBatchingBuffer = xStreamBatchingBufferCreateStatic( sizeof( ucStorageBuffer ),
* xTriggerLevel,
* ucStorageBuffer,
* &xStreamBufferStruct );
*
* // As neither the pucStreamBufferStorageArea or pxStaticStreamBuffer
* // parameters were NULL, xStreamBatchingBuffer will not be NULL, and can be
* // used to reference the created stream batching buffer in other stream
* // buffer API calls.
*
* // Other code that uses the stream batching buffer can go here.
* }
*
* @endcode
* \defgroup xStreamBatchingBufferCreateStatic xStreamBatchingBufferCreateStatic
* \ingroup StreamBatchingBufferManagement
*/

#define xStreamBatchingBufferCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer ) \
xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, pdTRUE, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), NULL, NULL )

#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
#define xStreamBatchingBufferCreateStaticWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, pdTRUE, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
#endif

/**
Expand Down Expand Up @@ -1054,13 +1226,15 @@ void vStreamBufferSetStreamBufferNotificationIndex( StreamBufferHandle_t xStream
StreamBufferHandle_t xStreamBufferGenericCreate( size_t xBufferSizeBytes,
size_t xTriggerLevelBytes,
BaseType_t xIsMessageBuffer,
BaseType_t xIsBatchingBuffer,
StreamBufferCallbackFunction_t pxSendCompletedCallback,
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION;

#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
size_t xTriggerLevelBytes,
BaseType_t xIsMessageBuffer,
BaseType_t xIsBatchingBuffer,
uint8_t * const pucStreamBufferStorageArea,
StaticStreamBuffer_t * const pxStaticStreamBuffer,
StreamBufferCallbackFunction_t pxSendCompletedCallback,
Expand Down
6 changes: 6 additions & 0 deletions portable/Common/mpu_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2405,6 +2405,7 @@
StreamBufferHandle_t MPU_xStreamBufferGenericCreate( size_t xBufferSizeBytes,
size_t xTriggerLevelBytes,
BaseType_t xIsMessageBuffer,
BaseType_t xIsBatchingBuffer,
StreamBufferCallbackFunction_t pxSendCompletedCallback,
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) /* FREERTOS_SYSTEM_CALL */
{
Expand All @@ -2428,6 +2429,7 @@
xReturn = xStreamBufferGenericCreate( xBufferSizeBytes,
xTriggerLevelBytes,
xIsMessageBuffer,
xIsBatchingBuffer,
NULL,
NULL );
portMEMORY_BARRIER();
Expand All @@ -2440,6 +2442,7 @@
xReturn = xStreamBufferGenericCreate( xBufferSizeBytes,
xTriggerLevelBytes,
xIsMessageBuffer,
xIsBatchingBuffer,
NULL,
NULL );
}
Expand All @@ -2459,6 +2462,7 @@
StreamBufferHandle_t MPU_xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
size_t xTriggerLevelBytes,
BaseType_t xIsMessageBuffer,
BaseType_t xIsBatchingBuffer,
uint8_t * const pucStreamBufferStorageArea,
StaticStreamBuffer_t * const pxStaticStreamBuffer,
StreamBufferCallbackFunction_t pxSendCompletedCallback,
Expand All @@ -2484,6 +2488,7 @@
xReturn = xStreamBufferGenericCreateStatic( xBufferSizeBytes,
xTriggerLevelBytes,
xIsMessageBuffer,
xIsBatchingBuffer,
pucStreamBufferStorageArea,
pxStaticStreamBuffer,
NULL,
Expand All @@ -2498,6 +2503,7 @@
xReturn = xStreamBufferGenericCreateStatic( xBufferSizeBytes,
xTriggerLevelBytes,
xIsMessageBuffer,
xIsBatchingBuffer,
pucStreamBufferStorageArea,
pxStaticStreamBuffer,
NULL,
Expand Down
Loading
Loading