Skip to content

Commit 3276214

Browse files
authored
Merge branch 'main' into rp2040_cmake_fix
2 parents 84ed737 + d5771a7 commit 3276214

File tree

9 files changed

+317
-55
lines changed

9 files changed

+317
-55
lines changed

.github/lexicon.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,10 +1693,12 @@ pxqueuesetcontainer
16931693
pxramstack
16941694
pxreadycoroutinelists
16951695
pxreadytaskslists
1696+
pxreceivecompletedcallback
16961697
pxregions
16971698
pxresult
16981699
pxrxedmessage
16991700
pxsemaphorebuffer
1701+
pxsendcompletedcallback
17001702
pxstack
17011703
pxstackbase
17021704
pxstackbuffer
@@ -2796,6 +2798,7 @@ xinterruptcontroller
27962798
xinterruptdescriptortable
27972799
xisfeasable
27982800
xisfeasible
2801+
xisinsideisr
27992802
xismessagebuffer
28002803
xisprivileged
28012804
xitemvalue

History.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ Documentation and download available at https://www.FreeRTOS.org/
1313
are both typedefs of the same struct xLIST_ITEM. This addresses some issues
1414
observed when strict-aliasing and link time optimization are enabled.
1515
To maintain backwards compatibility, configUSE_MINI_LIST_ITEM defaults to 1.
16+
+ Add the ability to override send and receive completed callbacks for each
17+
instance of a stream buffer or message buffer. The feature can be controlled
18+
by setting the configuration option configUSE_SB_COMPLETED_CALLBACK in
19+
FreeRTOSConfig.h. When the option is set to 1, APIs
20+
xStreamBufferCreateWithCallback() or xStreamBufferCreateStaticWithCallback()
21+
(and likewise APIs from message buffer) can be used to create a stream buffer
22+
or message buffer instance with application provided callback overrides. When
23+
the option is set to 0, then the default callbacks as defined by
24+
sbSEND_COMPLETED() and sbRECEIVE_COMPLETED() macros are invoked. To maintain
25+
backwards compatibility, configUSE_SB_COMPLETED_CALLBACK defaults to 0. The
26+
functionaility is currently not supported for MPU enabled ports.
1627

1728
Changes between FreeRTOS V10.4.5 and FreeRTOS V10.4.6 released November 12 2021
1829

include/FreeRTOS.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,12 @@
890890
#define configUSE_POSIX_ERRNO 0
891891
#endif
892892

893+
#ifndef configUSE_SB_COMPLETED_CALLBACK
894+
895+
/* By default per-instance callbacks are not enabled for stream buffer or message buffer. */
896+
#define configUSE_SB_COMPLETED_CALLBACK 0
897+
#endif
898+
893899
#ifndef portTICK_TYPE_IS_ATOMIC
894900
#define portTICK_TYPE_IS_ATOMIC 0
895901
#endif
@@ -1356,6 +1362,9 @@ typedef struct xSTATIC_STREAM_BUFFER
13561362
#if ( configUSE_TRACE_FACILITY == 1 )
13571363
UBaseType_t uxDummy4;
13581364
#endif
1365+
#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
1366+
void * pvDummy5[ 2 ];
1367+
#endif
13591368
} StaticStreamBuffer_t;
13601369

13611370
/* Message buffers are built on stream buffers. */

include/message_buffer.h

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ typedef void * MessageBufferHandle_t;
107107
* 32-bit architecture, so on most 32-bit architectures a 10 byte message will
108108
* take up 14 bytes of message buffer space.
109109
*
110+
* @param pxSendCompletedCallback Callback invoked when a send operation to the
111+
* message buffer is complete. If the parameter is NULL or xMessageBufferCreate()
112+
* is called without the parameter, then it will use the default implementation
113+
* provided by sbSEND_COMPLETED macro. To enable the callback,
114+
* configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
115+
*
116+
* @param pxReceiveCompletedCallback Callback invoked when a receive operation from
117+
* the message buffer is complete. If the parameter is NULL or xMessageBufferCreate()
118+
* is called without the parameter, it will use the default implementation provided
119+
* by sbRECEIVE_COMPLETED macro. To enable the callback,
120+
* configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
121+
*
110122
* @return If NULL is returned, then the message buffer cannot be created
111123
* because there is insufficient heap memory available for FreeRTOS to allocate
112124
* the message buffer data structures and storage area. A non-NULL value being
@@ -143,7 +155,12 @@ typedef void * MessageBufferHandle_t;
143155
* \ingroup MessageBufferManagement
144156
*/
145157
#define xMessageBufferCreate( xBufferSizeBytes ) \
146-
( MessageBufferHandle_t ) xStreamBufferGenericCreate( xBufferSizeBytes, ( size_t ) 0, pdTRUE )
158+
( MessageBufferHandle_t ) xStreamBufferGenericCreate( xBufferSizeBytes, ( size_t ) 0, pdTRUE, NULL, NULL )
159+
160+
#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
161+
#define xMessageBufferCreateWithCallback( xBufferSizeBytes, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
162+
( MessageBufferHandle_t ) xStreamBufferGenericCreate( xBufferSizeBytes, ( size_t ) 0, pdTRUE, pxSendCompletedCallback, pxReceiveCompletedCallback )
163+
#endif
147164

148165
/**
149166
* message_buffer.h
@@ -172,6 +189,16 @@ typedef void * MessageBufferHandle_t;
172189
* StaticMessageBuffer_t, which will be used to hold the message buffer's data
173190
* structure.
174191
*
192+
* @param pxSendCompletedCallback Callback invoked when a new message is sent to the message buffer.
193+
* If the parameter is NULL or xMessageBufferCreate() is called without the parameter, then it will use the default
194+
* implementation provided by sbSEND_COMPLETED macro. To enable the callback,
195+
* configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
196+
*
197+
* @param pxReceiveCompletedCallback Callback invoked when a message is read from a
198+
* message buffer. If the parameter is NULL or xMessageBufferCreate() is called without the parameter, it will
199+
* use the default implementation provided by sbRECEIVE_COMPLETED macro. To enable the callback,
200+
* configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
201+
*
175202
* @return If the message buffer is created successfully then a handle to the
176203
* created message buffer is returned. If either pucMessageBufferStorageArea or
177204
* pxStaticmessageBuffer are NULL then NULL is returned.
@@ -210,7 +237,12 @@ typedef void * MessageBufferHandle_t;
210237
* \ingroup MessageBufferManagement
211238
*/
212239
#define xMessageBufferCreateStatic( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer ) \
213-
( MessageBufferHandle_t ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, 0, pdTRUE, pucMessageBufferStorageArea, pxStaticMessageBuffer )
240+
( MessageBufferHandle_t ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, 0, pdTRUE, pucMessageBufferStorageArea, pxStaticMessageBuffer, NULL, NULL )
241+
242+
#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
243+
#define xMessageBufferCreateStaticWithCallback( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
244+
( MessageBufferHandle_t ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, 0, pdTRUE, pucMessageBufferStorageArea, pxStaticMessageBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback )
245+
#endif
214246

215247
/**
216248
* message_buffer.h

include/mpu_prototypes.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,16 @@ BaseType_t MPU_xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer,
248248
size_t xTriggerLevel ) FREERTOS_SYSTEM_CALL;
249249
StreamBufferHandle_t MPU_xStreamBufferGenericCreate( size_t xBufferSizeBytes,
250250
size_t xTriggerLevelBytes,
251-
BaseType_t xIsMessageBuffer ) FREERTOS_SYSTEM_CALL;
251+
BaseType_t xIsMessageBuffer,
252+
StreamBufferCallbackFunction_t pxSendCompletedCallback,
253+
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) FREERTOS_SYSTEM_CALL;
252254
StreamBufferHandle_t MPU_xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
253255
size_t xTriggerLevelBytes,
254256
BaseType_t xIsMessageBuffer,
255257
uint8_t * const pucStreamBufferStorageArea,
256-
StaticStreamBuffer_t * const pxStaticStreamBuffer ) FREERTOS_SYSTEM_CALL;
258+
StaticStreamBuffer_t * const pxStaticStreamBuffer,
259+
StreamBufferCallbackFunction_t pxSendCompletedCallback,
260+
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) FREERTOS_SYSTEM_CALL;
257261

258262

259263

include/semphr.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ typedef QueueHandle_t SemaphoreHandle_t;
731731
* \defgroup xSemaphoreCreateMutex xSemaphoreCreateMutex
732732
* \ingroup Semaphores
733733
*/
734-
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
734+
#if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_MUTEXES == 1 ) )
735735
#define xSemaphoreCreateMutex() xQueueCreateMutex( queueQUEUE_TYPE_MUTEX )
736736
#endif
737737

@@ -794,9 +794,9 @@ typedef QueueHandle_t SemaphoreHandle_t;
794794
* \defgroup xSemaphoreCreateMutexStatic xSemaphoreCreateMutexStatic
795795
* \ingroup Semaphores
796796
*/
797-
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
797+
#if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_MUTEXES == 1 ) )
798798
#define xSemaphoreCreateMutexStatic( pxMutexBuffer ) xQueueCreateMutexStatic( queueQUEUE_TYPE_MUTEX, ( pxMutexBuffer ) )
799-
#endif /* configSUPPORT_STATIC_ALLOCATION */
799+
#endif
800800

801801

802802
/**
@@ -1126,7 +1126,7 @@ typedef QueueHandle_t SemaphoreHandle_t;
11261126
* \defgroup vSemaphoreDelete vSemaphoreDelete
11271127
* \ingroup Semaphores
11281128
*/
1129-
#define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( QueueHandle_t ) ( xSemaphore ) )
1129+
#define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( QueueHandle_t ) ( xSemaphore ) )
11301130

11311131
/**
11321132
* semphr.h
@@ -1143,7 +1143,9 @@ typedef QueueHandle_t SemaphoreHandle_t;
11431143
* the holder may change between the function exiting and the returned value
11441144
* being tested.
11451145
*/
1146-
#define xSemaphoreGetMutexHolder( xSemaphore ) xQueueGetMutexHolder( ( xSemaphore ) )
1146+
#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
1147+
#define xSemaphoreGetMutexHolder( xSemaphore ) xQueueGetMutexHolder( ( xSemaphore ) )
1148+
#endif
11471149

11481150
/**
11491151
* semphr.h
@@ -1156,7 +1158,9 @@ typedef QueueHandle_t SemaphoreHandle_t;
11561158
* by a task), return NULL.
11571159
*
11581160
*/
1159-
#define xSemaphoreGetMutexHolderFromISR( xSemaphore ) xQueueGetMutexHolderFromISR( ( xSemaphore ) )
1161+
#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
1162+
#define xSemaphoreGetMutexHolderFromISR( xSemaphore ) xQueueGetMutexHolderFromISR( ( xSemaphore ) )
1163+
#endif
11601164

11611165
/**
11621166
* semphr.h
@@ -1170,7 +1174,7 @@ typedef QueueHandle_t SemaphoreHandle_t;
11701174
* semaphore is not available.
11711175
*
11721176
*/
1173-
#define uxSemaphoreGetCount( xSemaphore ) uxQueueMessagesWaiting( ( QueueHandle_t ) ( xSemaphore ) )
1177+
#define uxSemaphoreGetCount( xSemaphore ) uxQueueMessagesWaiting( ( QueueHandle_t ) ( xSemaphore ) )
11741178

11751179
/**
11761180
* semphr.h
@@ -1184,6 +1188,6 @@ typedef QueueHandle_t SemaphoreHandle_t;
11841188
* semaphore is not available.
11851189
*
11861190
*/
1187-
#define uxSemaphoreGetCountFromISR( xSemaphore ) uxQueueMessagesWaitingFromISR( ( QueueHandle_t ) ( xSemaphore ) )
1191+
#define uxSemaphoreGetCountFromISR( xSemaphore ) uxQueueMessagesWaitingFromISR( ( QueueHandle_t ) ( xSemaphore ) )
11881192

11891193
#endif /* SEMAPHORE_H */

include/stream_buffer.h

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@
7171
struct StreamBufferDef_t;
7272
typedef struct StreamBufferDef_t * StreamBufferHandle_t;
7373

74+
/**
75+
* Type used as a stream buffer's optional callback.
76+
*/
77+
typedef void (* StreamBufferCallbackFunction_t)( StreamBufferHandle_t xStreamBuffer,
78+
BaseType_t xIsInsideISR,
79+
BaseType_t * const pxHigherPriorityTaskWoken );
7480

7581
/**
7682
* stream_buffer.h
@@ -103,6 +109,16 @@ typedef struct StreamBufferDef_t * StreamBufferHandle_t;
103109
* trigger level of 1 being used. It is not valid to specify a trigger level
104110
* that is greater than the buffer size.
105111
*
112+
* @param pxSendCompletedCallback Callback invoked when number of bytes at least equal to
113+
* trigger level is sent to the stream buffer. If the parameter is NULL, it will use the default
114+
* implementation provided by sbSEND_COMPLETED macro. To enable the callback,
115+
* configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
116+
*
117+
* @param pxReceiveCompletedCallback Callback invoked when more than zero bytes are read from a
118+
* stream buffer. If the parameter is NULL, it will use the default
119+
* implementation provided by sbRECEIVE_COMPLETED macro. To enable the callback,
120+
* configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
121+
*
106122
* @return If NULL is returned, then the stream buffer cannot be created
107123
* because there is insufficient heap memory available for FreeRTOS to allocate
108124
* the stream buffer data structures and storage area. A non-NULL value being
@@ -137,7 +153,14 @@ typedef struct StreamBufferDef_t * StreamBufferHandle_t;
137153
* \defgroup xStreamBufferCreate xStreamBufferCreate
138154
* \ingroup StreamBufferManagement
139155
*/
140-
#define xStreamBufferCreate( xBufferSizeBytes, xTriggerLevelBytes ) xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE )
156+
157+
#define xStreamBufferCreate( xBufferSizeBytes, xTriggerLevelBytes ) \
158+
xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE, NULL, NULL )
159+
160+
#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
161+
#define xStreamBufferCreateWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
162+
xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE, pxSendCompletedCallback, pxReceiveCompletedCallback )
163+
#endif
141164

142165
/**
143166
* stream_buffer.h
@@ -179,6 +202,16 @@ typedef struct StreamBufferDef_t * StreamBufferHandle_t;
179202
* StaticStreamBuffer_t, which will be used to hold the stream buffer's data
180203
* structure.
181204
*
205+
* @param pxSendCompletedCallback Callback invoked when number of bytes at least equal to
206+
* trigger level is sent to the stream buffer. If the parameter is NULL, it will use the default
207+
* implementation provided by sbSEND_COMPLETED macro. To enable the callback,
208+
* configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
209+
*
210+
* @param pxReceiveCompletedCallback Callback invoked when more than zero bytes are read from a
211+
* stream buffer. If the parameter is NULL, it will use the default
212+
* implementation provided by sbRECEIVE_COMPLETED macro. To enable the callback,
213+
* configUSE_SB_COMPLETED_CALLBACK must be set to 1 in FreeRTOSConfig.h.
214+
*
182215
* @return If the stream buffer is created successfully then a handle to the
183216
* created stream buffer is returned. If either pucStreamBufferStorageArea or
184217
* pxStaticstreamBuffer are NULL then NULL is returned.
@@ -218,8 +251,14 @@ typedef struct StreamBufferDef_t * StreamBufferHandle_t;
218251
* \defgroup xStreamBufferCreateStatic xStreamBufferCreateStatic
219252
* \ingroup StreamBufferManagement
220253
*/
254+
221255
#define xStreamBufferCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer ) \
222-
xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE, pucStreamBufferStorageArea, pxStaticStreamBuffer )
256+
xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE, pucStreamBufferStorageArea, pxStaticStreamBuffer, NULL, NULL )
257+
258+
#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
259+
#define xStreamBufferCreateStaticWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback ) \
260+
xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE, pucStreamBufferStorageArea, pxStaticStreamBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback )
261+
#endif
223262

224263
/**
225264
* stream_buffer.h
@@ -843,13 +882,18 @@ BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuf
843882
/* Functions below here are not part of the public API. */
844883
StreamBufferHandle_t xStreamBufferGenericCreate( size_t xBufferSizeBytes,
845884
size_t xTriggerLevelBytes,
846-
BaseType_t xIsMessageBuffer ) PRIVILEGED_FUNCTION;
885+
BaseType_t xIsMessageBuffer,
886+
StreamBufferCallbackFunction_t pxSendCompletedCallback,
887+
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION;
888+
847889

848890
StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
849891
size_t xTriggerLevelBytes,
850892
BaseType_t xIsMessageBuffer,
851893
uint8_t * const pucStreamBufferStorageArea,
852-
StaticStreamBuffer_t * const pxStaticStreamBuffer ) PRIVILEGED_FUNCTION;
894+
StaticStreamBuffer_t * const pxStaticStreamBuffer,
895+
StreamBufferCallbackFunction_t pxSendCompletedCallback,
896+
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION;
853897

854898
size_t xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
855899

0 commit comments

Comments
 (0)