|
62 | 62 | #endif |
63 | 63 | /* *INDENT-ON* */ |
64 | 64 |
|
| 65 | +/** |
| 66 | + * Type of stream buffer. For internal use only. |
| 67 | + */ |
| 68 | +#define sbTYPE_STREAM_BUFFER ( ( BaseType_t ) 0 ) |
| 69 | +#define sbTYPE_MESSAGE_BUFFER ( ( BaseType_t ) 1 ) |
| 70 | +#define sbTYPE_STREAM_BATCHING_BUFFER ( ( BaseType_t ) 2 ) |
| 71 | + |
65 | 72 | /** |
66 | 73 | * Type by which stream buffers are referenced. For example, a call to |
67 | 74 | * xStreamBufferCreate() returns an StreamBufferHandle_t variable that can |
@@ -157,11 +164,11 @@ typedef void (* StreamBufferCallbackFunction_t)( StreamBufferHandle_t xStreamBuf |
157 | 164 | */ |
158 | 165 |
|
159 | 166 | #define xStreamBufferCreate( xBufferSizeBytes, xTriggerLevelBytes ) \ |
160 | | - xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, NULL, NULL ) |
| 167 | + xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BUFFER, NULL, NULL ) |
161 | 168 |
|
162 | 169 | #if ( configUSE_SB_COMPLETED_CALLBACK == 1 ) |
163 | 170 | #define xStreamBufferCreateWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pxSendCompletedCallback, pxReceiveCompletedCallback ) \ |
164 | | - xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) ) |
| 171 | + xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BUFFER, ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) ) |
165 | 172 | #endif |
166 | 173 |
|
167 | 174 | /** |
@@ -257,11 +264,199 @@ typedef void (* StreamBufferCallbackFunction_t)( StreamBufferHandle_t xStreamBuf |
257 | 264 | */ |
258 | 265 |
|
259 | 266 | #define xStreamBufferCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer ) \ |
260 | | - xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), NULL, NULL ) |
| 267 | + xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BUFFER, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), NULL, NULL ) |
261 | 268 |
|
262 | 269 | #if ( configUSE_SB_COMPLETED_CALLBACK == 1 ) |
263 | 270 | #define xStreamBufferCreateStaticWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback ) \ |
264 | | - xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) ) |
| 271 | + xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BUFFER, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) ) |
| 272 | +#endif |
| 273 | + |
| 274 | +/** |
| 275 | + * stream_buffer.h |
| 276 | + * |
| 277 | + * @code{c} |
| 278 | + * StreamBufferHandle_t xStreamBatchingBufferCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes ); |
| 279 | + * @endcode |
| 280 | + * |
| 281 | + * Creates a new stream batching buffer using dynamically allocated memory. See |
| 282 | + * xStreamBatchingBufferCreateStatic() for a version that uses statically |
| 283 | + * allocated memory (memory that is allocated at compile time). |
| 284 | + * |
| 285 | + * configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in |
| 286 | + * FreeRTOSConfig.h for xStreamBatchingBufferCreate() to be available. |
| 287 | + * configUSE_STREAM_BUFFERS must be set to 1 in for FreeRTOSConfig.h for |
| 288 | + * xStreamBatchingBufferCreate() to be available. |
| 289 | + * |
| 290 | + * The difference between a stream buffer and a stream batching buffer is when |
| 291 | + * a task performs read on a non-empty buffer: |
| 292 | + * - The task reading from a non-empty stream buffer returns immediately |
| 293 | + * regardless of the amount of data in the buffer. |
| 294 | + * - The task reading from a non-empty steam batching buffer blocks until the |
| 295 | + * amount of data in the buffer exceeds the trigger level or the block time |
| 296 | + * expires. |
| 297 | + * |
| 298 | + * @param xBufferSizeBytes The total number of bytes the stream batching buffer |
| 299 | + * will be able to hold at any one time. |
| 300 | + * |
| 301 | + * @param xTriggerLevelBytes The number of bytes that must be in the stream |
| 302 | + * batching buffer to unblock a task calling xStreamBufferReceive before the |
| 303 | + * block time expires. |
| 304 | + * |
| 305 | + * @param pxSendCompletedCallback Callback invoked when number of bytes at least |
| 306 | + * equal to trigger level is sent to the stream batching buffer. If the |
| 307 | + * parameter is NULL, it will use the default implementation provided by |
| 308 | + * sbSEND_COMPLETED macro. To enable the callback, configUSE_SB_COMPLETED_CALLBACK |
| 309 | + * must be set to 1 in FreeRTOSConfig.h. |
| 310 | + * |
| 311 | + * @param pxReceiveCompletedCallback Callback invoked when more than zero bytes |
| 312 | + * are read from a stream batching buffer. If the parameter is NULL, it will use |
| 313 | + * the default implementation provided by sbRECEIVE_COMPLETED macro. To enable |
| 314 | + * the callback, configUSE_SB_COMPLETED_CALLBACK must be set to 1 in |
| 315 | + * FreeRTOSConfig.h. |
| 316 | + * |
| 317 | + * @return If NULL is returned, then the stream batching buffer cannot be created |
| 318 | + * because there is insufficient heap memory available for FreeRTOS to allocate |
| 319 | + * the stream batching buffer data structures and storage area. A non-NULL value |
| 320 | + * being returned indicates that the stream batching buffer has been created |
| 321 | + * successfully - the returned value should be stored as the handle to the |
| 322 | + * created stream batching buffer. |
| 323 | + * |
| 324 | + * Example use: |
| 325 | + * @code{c} |
| 326 | + * |
| 327 | + * void vAFunction( void ) |
| 328 | + * { |
| 329 | + * StreamBufferHandle_t xStreamBatchingBuffer; |
| 330 | + * const size_t xStreamBufferSizeBytes = 100, xTriggerLevel = 10; |
| 331 | + * |
| 332 | + * // Create a stream batching buffer that can hold 100 bytes. The memory used |
| 333 | + * // to hold both the stream batching buffer structure and the data in the stream |
| 334 | + * // batching buffer is allocated dynamically. |
| 335 | + * xStreamBatchingBuffer = xStreamBatchingBufferCreate( xStreamBufferSizeBytes, xTriggerLevel ); |
| 336 | + * |
| 337 | + * if( xStreamBatchingBuffer == NULL ) |
| 338 | + * { |
| 339 | + * // There was not enough heap memory space available to create the |
| 340 | + * // stream batching buffer. |
| 341 | + * } |
| 342 | + * else |
| 343 | + * { |
| 344 | + * // The stream batching buffer was created successfully and can now be used. |
| 345 | + * } |
| 346 | + * } |
| 347 | + * @endcode |
| 348 | + * \defgroup xStreamBatchingBufferCreate xStreamBatchingBufferCreate |
| 349 | + * \ingroup StreamBatchingBufferManagement |
| 350 | + */ |
| 351 | + |
| 352 | +#define xStreamBatchingBufferCreate( xBufferSizeBytes, xTriggerLevelBytes ) \ |
| 353 | + xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BATCHING_BUFFER, NULL, NULL ) |
| 354 | + |
| 355 | +#if ( configUSE_SB_COMPLETED_CALLBACK == 1 ) |
| 356 | + #define xStreamBatchingBufferCreateWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pxSendCompletedCallback, pxReceiveCompletedCallback ) \ |
| 357 | + xStreamBufferGenericCreate( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BATCHING_BUFFER, ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) ) |
| 358 | +#endif |
| 359 | + |
| 360 | +/** |
| 361 | + * stream_buffer.h |
| 362 | + * |
| 363 | + * @code{c} |
| 364 | + * StreamBufferHandle_t xStreamBatchingBufferCreateStatic( size_t xBufferSizeBytes, |
| 365 | + * size_t xTriggerLevelBytes, |
| 366 | + * uint8_t *pucStreamBufferStorageArea, |
| 367 | + * StaticStreamBuffer_t *pxStaticStreamBuffer ); |
| 368 | + * @endcode |
| 369 | + * Creates a new stream batching buffer using statically allocated memory. See |
| 370 | + * xStreamBatchingBufferCreate() for a version that uses dynamically allocated |
| 371 | + * memory. |
| 372 | + * |
| 373 | + * configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h for |
| 374 | + * xStreamBatchingBufferCreateStatic() to be available. configUSE_STREAM_BUFFERS |
| 375 | + * must be set to 1 in for FreeRTOSConfig.h for xStreamBatchingBufferCreateStatic() |
| 376 | + * to be available. |
| 377 | + * |
| 378 | + * The difference between a stream buffer and a stream batching buffer is when |
| 379 | + * a task performs read on a non-empty buffer: |
| 380 | + * - The task reading from a non-empty stream buffer returns immediately |
| 381 | + * regardless of the amount of data in the buffer. |
| 382 | + * - The task reading from a non-empty steam batching buffer blocks until the |
| 383 | + * amount of data in the buffer exceeds the trigger level or the block time |
| 384 | + * expires. |
| 385 | + * |
| 386 | + * @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the |
| 387 | + * pucStreamBufferStorageArea parameter. |
| 388 | + * |
| 389 | + * @param xTriggerLevelBytes The number of bytes that must be in the stream |
| 390 | + * batching buffer to unblock a task calling xStreamBufferReceive before the |
| 391 | + * block time expires. |
| 392 | + * |
| 393 | + * @param pucStreamBufferStorageArea Must point to a uint8_t array that is at |
| 394 | + * least xBufferSizeBytes big. This is the array to which streams are |
| 395 | + * copied when they are written to the stream batching buffer. |
| 396 | + * |
| 397 | + * @param pxStaticStreamBuffer Must point to a variable of type |
| 398 | + * StaticStreamBuffer_t, which will be used to hold the stream batching buffer's |
| 399 | + * data structure. |
| 400 | + * |
| 401 | + * @param pxSendCompletedCallback Callback invoked when number of bytes at least |
| 402 | + * equal to trigger level is sent to the stream batching buffer. If the parameter |
| 403 | + * is NULL, it will use the default implementation provided by sbSEND_COMPLETED |
| 404 | + * macro. To enable the callback, configUSE_SB_COMPLETED_CALLBACK must be set to |
| 405 | + * 1 in FreeRTOSConfig.h. |
| 406 | + * |
| 407 | + * @param pxReceiveCompletedCallback Callback invoked when more than zero bytes |
| 408 | + * are read from a stream batching buffer. If the parameter is NULL, it will use |
| 409 | + * the default implementation provided by sbRECEIVE_COMPLETED macro. To enable |
| 410 | + * the callback, configUSE_SB_COMPLETED_CALLBACK must be set to 1 in |
| 411 | + * FreeRTOSConfig.h. |
| 412 | + * |
| 413 | + * @return If the stream batching buffer is created successfully then a handle |
| 414 | + * to the created stream batching buffer is returned. If either pucStreamBufferStorageArea |
| 415 | + * or pxStaticstreamBuffer are NULL then NULL is returned. |
| 416 | + * |
| 417 | + * Example use: |
| 418 | + * @code{c} |
| 419 | + * |
| 420 | + * // Used to dimension the array used to hold the streams. The available space |
| 421 | + * // will actually be one less than this, so 999. |
| 422 | + * #define STORAGE_SIZE_BYTES 1000 |
| 423 | + * |
| 424 | + * // Defines the memory that will actually hold the streams within the stream |
| 425 | + * // batching buffer. |
| 426 | + * static uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ]; |
| 427 | + * |
| 428 | + * // The variable used to hold the stream batching buffer structure. |
| 429 | + * StaticStreamBuffer_t xStreamBufferStruct; |
| 430 | + * |
| 431 | + * void MyFunction( void ) |
| 432 | + * { |
| 433 | + * StreamBufferHandle_t xStreamBatchingBuffer; |
| 434 | + * const size_t xTriggerLevel = 1; |
| 435 | + * |
| 436 | + * xStreamBatchingBuffer = xStreamBatchingBufferCreateStatic( sizeof( ucStorageBuffer ), |
| 437 | + * xTriggerLevel, |
| 438 | + * ucStorageBuffer, |
| 439 | + * &xStreamBufferStruct ); |
| 440 | + * |
| 441 | + * // As neither the pucStreamBufferStorageArea or pxStaticStreamBuffer |
| 442 | + * // parameters were NULL, xStreamBatchingBuffer will not be NULL, and can be |
| 443 | + * // used to reference the created stream batching buffer in other stream |
| 444 | + * // buffer API calls. |
| 445 | + * |
| 446 | + * // Other code that uses the stream batching buffer can go here. |
| 447 | + * } |
| 448 | + * |
| 449 | + * @endcode |
| 450 | + * \defgroup xStreamBatchingBufferCreateStatic xStreamBatchingBufferCreateStatic |
| 451 | + * \ingroup StreamBatchingBufferManagement |
| 452 | + */ |
| 453 | + |
| 454 | +#define xStreamBatchingBufferCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer ) \ |
| 455 | + xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BATCHING_BUFFER, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), NULL, NULL ) |
| 456 | + |
| 457 | +#if ( configUSE_SB_COMPLETED_CALLBACK == 1 ) |
| 458 | + #define xStreamBatchingBufferCreateStaticWithCallback( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer, pxSendCompletedCallback, pxReceiveCompletedCallback ) \ |
| 459 | + xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), sbTYPE_STREAM_BATCHING_BUFFER, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) ) |
265 | 460 | #endif |
266 | 461 |
|
267 | 462 | /** |
@@ -1053,14 +1248,14 @@ void vStreamBufferSetStreamBufferNotificationIndex( StreamBufferHandle_t xStream |
1053 | 1248 | /* Functions below here are not part of the public API. */ |
1054 | 1249 | StreamBufferHandle_t xStreamBufferGenericCreate( size_t xBufferSizeBytes, |
1055 | 1250 | size_t xTriggerLevelBytes, |
1056 | | - BaseType_t xIsMessageBuffer, |
| 1251 | + BaseType_t xStreamBufferType, |
1057 | 1252 | StreamBufferCallbackFunction_t pxSendCompletedCallback, |
1058 | 1253 | StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION; |
1059 | 1254 |
|
1060 | 1255 | #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) |
1061 | 1256 | StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes, |
1062 | 1257 | size_t xTriggerLevelBytes, |
1063 | | - BaseType_t xIsMessageBuffer, |
| 1258 | + BaseType_t xStreamBufferType, |
1064 | 1259 | uint8_t * const pucStreamBufferStorageArea, |
1065 | 1260 | StaticStreamBuffer_t * const pxStaticStreamBuffer, |
1066 | 1261 | StreamBufferCallbackFunction_t pxSendCompletedCallback, |
|
0 commit comments