Add callback overrides for stream buffer and message buffers (#437)

* Let each stream/message can use its own sbSEND_COMPLETED

In FreeRTOS.h, set the default value of configUSE_SB_COMPLETED_CALLBACK
to zero, and add additional space for the function pointer when
the buffer created statically.

In stream_buffer.c, modify the macro of sbSEND_COMPLETED which let
the stream buffer to use its own implementation, and then add an
pointer to the stream buffer's structure, and modify the
implementation of the buffer creating and initializing

Co-authored-by: eddie9712 <qw1562435@gmail.com>
This commit is contained in:
Ravishankar Bhagavandas 2022-06-20 17:48:34 -07:00 committed by GitHub
parent 49cb8e8b28
commit 0b46492740
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 306 additions and 48 deletions

View file

@ -1429,14 +1429,36 @@
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
StreamBufferHandle_t MPU_xStreamBufferGenericCreate( size_t xBufferSizeBytes,
size_t xTriggerLevelBytes,
BaseType_t xIsMessageBuffer ) /* FREERTOS_SYSTEM_CALL */
BaseType_t xIsMessageBuffer,
StreamBufferCallbackFunction_t pxSendCompletedCallback,
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) /* FREERTOS_SYSTEM_CALL */
{
StreamBufferHandle_t xReturn;
BaseType_t xRunningPrivileged;
xPortRaisePrivilege( xRunningPrivileged );
xReturn = xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, xIsMessageBuffer );
vPortResetPrivilege( xRunningPrivileged );
/**
* Streambuffer application level callback functionality is disabled for MPU
* enabled ports.
*/
configASSERT( ( pxSendCompletedCallback == NULL ) &&
( pxReceiveCompletedCallback == NULL ) );
if( ( pxSendCompletedCallback == NULL ) &&
( pxReceiveCompletedCallback == NULL ) )
{
xPortRaisePrivilege( xRunningPrivileged );
xReturn = xStreamBufferGenericCreate( xBufferSizeBytes,
xTriggerLevelBytes,
xIsMessageBuffer,
NULL,
NULL );
vPortResetPrivilege( xRunningPrivileged );
}
else
{
traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer );
xReturn = NULL;
}
return xReturn;
}
@ -1448,14 +1470,38 @@
size_t xTriggerLevelBytes,
BaseType_t xIsMessageBuffer,
uint8_t * const pucStreamBufferStorageArea,
StaticStreamBuffer_t * const pxStaticStreamBuffer ) /* FREERTOS_SYSTEM_CALL */
StaticStreamBuffer_t * const pxStaticStreamBuffer,
StreamBufferCallbackFunction_t pxSendCompletedCallback,
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) /* FREERTOS_SYSTEM_CALL */
{
StreamBufferHandle_t xReturn;
BaseType_t xRunningPrivileged;
xPortRaisePrivilege( xRunningPrivileged );
xReturn = xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, xIsMessageBuffer, pucStreamBufferStorageArea, pxStaticStreamBuffer );
vPortResetPrivilege( xRunningPrivileged );
/**
* Streambuffer application level callback functionality is disabled for MPU
* enabled ports.
*/
configASSERT( ( pxSendCompletedCallback == NULL ) &&
( pxReceiveCompletedCallback == NULL ) );
if( ( pxSendCompletedCallback == NULL ) &&
( pxReceiveCompletedCallback == NULL ) )
{
xPortRaisePrivilege( xRunningPrivileged );
xReturn = xStreamBufferGenericCreateStatic( xBufferSizeBytes,
xTriggerLevelBytes,
xIsMessageBuffer,
pucStreamBufferStorageArea,
pxStaticStreamBuffer,
NULL,
NULL );
vPortResetPrivilege( xRunningPrivileged );
}
else
{
traceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xIsMessageBuffer );
xReturn = NULL;
}
return xReturn;
}