mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-08-20 01:58:32 -04:00
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:
parent
49cb8e8b28
commit
0b46492740
8 changed files with 306 additions and 48 deletions
|
@ -890,6 +890,12 @@
|
|||
#define configUSE_POSIX_ERRNO 0
|
||||
#endif
|
||||
|
||||
#ifndef configUSE_SB_COMPLETED_CALLBACK
|
||||
|
||||
/* By default per-instance callbacks are not enabled for stream buffer or message buffer. */
|
||||
#define configUSE_SB_COMPLETED_CALLBACK 0
|
||||
#endif
|
||||
|
||||
#ifndef portTICK_TYPE_IS_ATOMIC
|
||||
#define portTICK_TYPE_IS_ATOMIC 0
|
||||
#endif
|
||||
|
@ -1356,6 +1362,9 @@ typedef struct xSTATIC_STREAM_BUFFER
|
|||
#if ( configUSE_TRACE_FACILITY == 1 )
|
||||
UBaseType_t uxDummy4;
|
||||
#endif
|
||||
#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
|
||||
void * pvDummy5[ 2 ];
|
||||
#endif
|
||||
} StaticStreamBuffer_t;
|
||||
|
||||
/* Message buffers are built on stream buffers. */
|
||||
|
|
|
@ -107,6 +107,18 @@ typedef void * MessageBufferHandle_t;
|
|||
* 32-bit architecture, so on most 32-bit architectures a 10 byte message will
|
||||
* take up 14 bytes of message buffer space.
|
||||
*
|
||||
* @param pxSendCompletedCallback Callback invoked when a send operation to the
|
||||
* message buffer is complete. If the parameter is NULL or xMessageBufferCreate()
|
||||
* is called without the parameter, then 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 a receive operation from
|
||||
* the message buffer is complete. If the parameter is NULL or xMessageBufferCreate()
|
||||
* is called without the parameter, 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 message buffer cannot be created
|
||||
* because there is insufficient heap memory available for FreeRTOS to allocate
|
||||
* the message buffer data structures and storage area. A non-NULL value being
|
||||
|
@ -143,7 +155,12 @@ typedef void * MessageBufferHandle_t;
|
|||
* \ingroup MessageBufferManagement
|
||||
*/
|
||||
#define xMessageBufferCreate( xBufferSizeBytes ) \
|
||||
( MessageBufferHandle_t ) xStreamBufferGenericCreate( xBufferSizeBytes, ( size_t ) 0, pdTRUE )
|
||||
( MessageBufferHandle_t ) xStreamBufferGenericCreate( xBufferSizeBytes, ( size_t ) 0, pdTRUE, NULL, NULL )
|
||||
|
||||
#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
|
||||
#define xMessageBufferCreateWithCallback( xBufferSizeBytes, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
|
||||
( MessageBufferHandle_t ) xStreamBufferGenericCreate( xBufferSizeBytes, ( size_t ) 0, pdTRUE, pxSendCompletedCallback, pxReceiveCompletedCallback )
|
||||
#endif
|
||||
|
||||
/**
|
||||
* message_buffer.h
|
||||
|
@ -172,6 +189,16 @@ typedef void * MessageBufferHandle_t;
|
|||
* StaticMessageBuffer_t, which will be used to hold the message buffer's data
|
||||
* structure.
|
||||
*
|
||||
* @param pxSendCompletedCallback Callback invoked when a new message is sent to the message buffer.
|
||||
* If the parameter is NULL or xMessageBufferCreate() is called without the parameter, then 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 a message is read from a
|
||||
* message buffer. If the parameter is NULL or xMessageBufferCreate() is called without the parameter, 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 message buffer is created successfully then a handle to the
|
||||
* created message buffer is returned. If either pucMessageBufferStorageArea or
|
||||
* pxStaticmessageBuffer are NULL then NULL is returned.
|
||||
|
@ -210,7 +237,12 @@ typedef void * MessageBufferHandle_t;
|
|||
* \ingroup MessageBufferManagement
|
||||
*/
|
||||
#define xMessageBufferCreateStatic( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer ) \
|
||||
( MessageBufferHandle_t ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, 0, pdTRUE, pucMessageBufferStorageArea, pxStaticMessageBuffer )
|
||||
( MessageBufferHandle_t ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, 0, pdTRUE, pucMessageBufferStorageArea, pxStaticMessageBuffer, NULL, NULL )
|
||||
|
||||
#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
|
||||
#define xMessageBufferCreateStaticWithCallback( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
|
||||
( MessageBufferHandle_t ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, 0, pdTRUE, pucMessageBufferStorageArea, pxStaticMessageBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback )
|
||||
#endif
|
||||
|
||||
/**
|
||||
* message_buffer.h
|
||||
|
|
|
@ -248,12 +248,16 @@ BaseType_t MPU_xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer,
|
|||
size_t xTriggerLevel ) FREERTOS_SYSTEM_CALL;
|
||||
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 MPU_xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
|
||||
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;
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -71,6 +71,12 @@
|
|||
struct StreamBufferDef_t;
|
||||
typedef struct StreamBufferDef_t * StreamBufferHandle_t;
|
||||
|
||||
/**
|
||||
* Type used as a stream buffer's optional callback.
|
||||
*/
|
||||
typedef void (* StreamBufferCallbackFunction_t)( StreamBufferHandle_t xStreamBuffer,
|
||||
BaseType_t xIsInsideISR,
|
||||
BaseType_t * const pxHigherPriorityTaskWoken );
|
||||
|
||||
/**
|
||||
* stream_buffer.h
|
||||
|
@ -103,6 +109,16 @@ typedef struct StreamBufferDef_t * StreamBufferHandle_t;
|
|||
* trigger level of 1 being used. It is not valid to specify a trigger level
|
||||
* that is greater than the buffer size.
|
||||
*
|
||||
* @param pxSendCompletedCallback Callback invoked when number of bytes at least equal to
|
||||
* trigger level is sent to the stream 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 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 buffer cannot be created
|
||||
* because there is insufficient heap memory available for FreeRTOS to allocate
|
||||
* the stream buffer data structures and storage area. A non-NULL value being
|
||||
|
@ -137,7 +153,14 @@ typedef struct StreamBufferDef_t * StreamBufferHandle_t;
|
|||
* \defgroup xStreamBufferCreate xStreamBufferCreate
|
||||
* \ingroup StreamBufferManagement
|
||||
*/
|
||||
#define xStreamBufferCreate( xBufferSizeBytes, xTriggerLevelBytes ) xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE )
|
||||
|
||||
#define xStreamBufferCreate( xBufferSizeBytes, xTriggerLevelBytes ) \
|
||||
xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE, NULL, NULL )
|
||||
|
||||
#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
|
||||
#define xStreamBufferCreateWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
|
||||
xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE, pxSendCompletedCallback, pxReceiveCompletedCallback )
|
||||
#endif
|
||||
|
||||
/**
|
||||
* stream_buffer.h
|
||||
|
@ -179,6 +202,16 @@ typedef struct StreamBufferDef_t * StreamBufferHandle_t;
|
|||
* StaticStreamBuffer_t, which will be used to hold the stream buffer's data
|
||||
* structure.
|
||||
*
|
||||
* @param pxSendCompletedCallback Callback invoked when number of bytes at least equal to
|
||||
* trigger level is sent to the stream 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 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 buffer is created successfully then a handle to the
|
||||
* created stream buffer is returned. If either pucStreamBufferStorageArea or
|
||||
* pxStaticstreamBuffer are NULL then NULL is returned.
|
||||
|
@ -218,8 +251,14 @@ typedef struct StreamBufferDef_t * StreamBufferHandle_t;
|
|||
* \defgroup xStreamBufferCreateStatic xStreamBufferCreateStatic
|
||||
* \ingroup StreamBufferManagement
|
||||
*/
|
||||
|
||||
#define xStreamBufferCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer ) \
|
||||
xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE, pucStreamBufferStorageArea, pxStaticStreamBuffer )
|
||||
xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, 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 )
|
||||
#endif
|
||||
|
||||
/**
|
||||
* stream_buffer.h
|
||||
|
@ -843,13 +882,18 @@ BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuf
|
|||
/* Functions below here are not part of the public API. */
|
||||
StreamBufferHandle_t xStreamBufferGenericCreate( size_t xBufferSizeBytes,
|
||||
size_t xTriggerLevelBytes,
|
||||
BaseType_t xIsMessageBuffer ) PRIVILEGED_FUNCTION;
|
||||
BaseType_t xIsMessageBuffer,
|
||||
StreamBufferCallbackFunction_t pxSendCompletedCallback,
|
||||
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION;
|
||||
|
||||
|
||||
StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
|
||||
size_t xTriggerLevelBytes,
|
||||
BaseType_t xIsMessageBuffer,
|
||||
uint8_t * const pucStreamBufferStorageArea,
|
||||
StaticStreamBuffer_t * const pxStaticStreamBuffer ) PRIVILEGED_FUNCTION;
|
||||
StaticStreamBuffer_t * const pxStaticStreamBuffer,
|
||||
StreamBufferCallbackFunction_t pxSendCompletedCallback,
|
||||
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION;
|
||||
|
||||
size_t xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue