2 * FreeRTOS Kernel V10.4.4
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
30 * Stream buffers are used to send a continuous stream of data from one task or
31 * interrupt to another. Their implementation is light weight, making them
32 * particularly suited for interrupt to task and core to core communication
35 * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
36 * implementation (so also the message buffer implementation, as message buffers
37 * are built on top of stream buffers) assumes there is only one task or
38 * interrupt that will write to the buffer (the writer), and only one task or
39 * interrupt that will read from the buffer (the reader). It is safe for the
40 * writer and reader to be different tasks or interrupts, but, unlike other
41 * FreeRTOS objects, it is not safe to have multiple different writers or
42 * multiple different readers. If there are to be multiple different writers
43 * then the application writer must place each call to a writing API function
44 * (such as xStreamBufferSend()) inside a critical section and set the send
45 * block time to 0. Likewise, if there are to be multiple different readers
46 * then the application writer must place each call to a reading API function
47 * (such as xStreamBufferReceive()) inside a critical section section and set the
48 * receive block time to 0.
52 #ifndef STREAM_BUFFER_H
53 #define STREAM_BUFFER_H
55 #ifndef INC_FREERTOS_H
56 #error "include FreeRTOS.h must appear in source files before include stream_buffer.h"
60 #if defined( __cplusplus )
66 * Type by which stream buffers are referenced. For example, a call to
67 * xStreamBufferCreate() returns an StreamBufferHandle_t variable that can
68 * then be used as a parameter to xStreamBufferSend(), xStreamBufferReceive(),
71 struct StreamBufferDef_t;
72 typedef struct StreamBufferDef_t * StreamBufferHandle_t;
79 * StreamBufferHandle_t xStreamBufferCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes );
82 * Creates a new stream buffer using dynamically allocated memory. See
83 * xStreamBufferCreateStatic() for a version that uses statically allocated
84 * memory (memory that is allocated at compile time).
86 * configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in
87 * FreeRTOSConfig.h for xStreamBufferCreate() to be available.
89 * @param xBufferSizeBytes The total number of bytes the stream buffer will be
90 * able to hold at any one time.
92 * @param xTriggerLevelBytes The number of bytes that must be in the stream
93 * buffer before a task that is blocked on the stream buffer to wait for data is
94 * moved out of the blocked state. For example, if a task is blocked on a read
95 * of an empty stream buffer that has a trigger level of 1 then the task will be
96 * unblocked when a single byte is written to the buffer or the task's block
97 * time expires. As another example, if a task is blocked on a read of an empty
98 * stream buffer that has a trigger level of 10 then the task will not be
99 * unblocked until the stream buffer contains at least 10 bytes or the task's
100 * block time expires. If a reading task's block time expires before the
101 * trigger level is reached then the task will still receive however many bytes
102 * are actually available. Setting a trigger level of 0 will result in a
103 * trigger level of 1 being used. It is not valid to specify a trigger level
104 * that is greater than the buffer size.
106 * @return If NULL is returned, then the stream buffer cannot be created
107 * because there is insufficient heap memory available for FreeRTOS to allocate
108 * the stream buffer data structures and storage area. A non-NULL value being
109 * returned indicates that the stream buffer has been created successfully -
110 * the returned value should be stored as the handle to the created stream
116 * void vAFunction( void )
118 * StreamBufferHandle_t xStreamBuffer;
119 * const size_t xStreamBufferSizeBytes = 100, xTriggerLevel = 10;
121 * // Create a stream buffer that can hold 100 bytes. The memory used to hold
122 * // both the stream buffer structure and the data in the stream buffer is
123 * // allocated dynamically.
124 * xStreamBuffer = xStreamBufferCreate( xStreamBufferSizeBytes, xTriggerLevel );
126 * if( xStreamBuffer == NULL )
128 * // There was not enough heap memory space available to create the
133 * // The stream buffer was created successfully and can now be used.
137 * \defgroup xStreamBufferCreate xStreamBufferCreate
138 * \ingroup StreamBufferManagement
140 #define xStreamBufferCreate( xBufferSizeBytes, xTriggerLevelBytes ) xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE )
146 * StreamBufferHandle_t xStreamBufferCreateStatic( size_t xBufferSizeBytes,
147 * size_t xTriggerLevelBytes,
148 * uint8_t *pucStreamBufferStorageArea,
149 * StaticStreamBuffer_t *pxStaticStreamBuffer );
151 * Creates a new stream buffer using statically allocated memory. See
152 * xStreamBufferCreate() for a version that uses dynamically allocated memory.
154 * configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h for
155 * xStreamBufferCreateStatic() to be available.
157 * @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the
158 * pucStreamBufferStorageArea parameter.
160 * @param xTriggerLevelBytes The number of bytes that must be in the stream
161 * buffer before a task that is blocked on the stream buffer to wait for data is
162 * moved out of the blocked state. For example, if a task is blocked on a read
163 * of an empty stream buffer that has a trigger level of 1 then the task will be
164 * unblocked when a single byte is written to the buffer or the task's block
165 * time expires. As another example, if a task is blocked on a read of an empty
166 * stream buffer that has a trigger level of 10 then the task will not be
167 * unblocked until the stream buffer contains at least 10 bytes or the task's
168 * block time expires. If a reading task's block time expires before the
169 * trigger level is reached then the task will still receive however many bytes
170 * are actually available. Setting a trigger level of 0 will result in a
171 * trigger level of 1 being used. It is not valid to specify a trigger level
172 * that is greater than the buffer size.
174 * @param pucStreamBufferStorageArea Must point to a uint8_t array that is at
175 * least xBufferSizeBytes + 1 big. This is the array to which streams are
176 * copied when they are written to the stream buffer.
178 * @param pxStaticStreamBuffer Must point to a variable of type
179 * StaticStreamBuffer_t, which will be used to hold the stream buffer's data
182 * @return If the stream buffer is created successfully then a handle to the
183 * created stream buffer is returned. If either pucStreamBufferStorageArea or
184 * pxStaticstreamBuffer are NULL then NULL is returned.
189 * // Used to dimension the array used to hold the streams. The available space
190 * // will actually be one less than this, so 999.
191 #define STORAGE_SIZE_BYTES 1000
193 * // Defines the memory that will actually hold the streams within the stream
195 * static uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];
197 * // The variable used to hold the stream buffer structure.
198 * StaticStreamBuffer_t xStreamBufferStruct;
200 * void MyFunction( void )
202 * StreamBufferHandle_t xStreamBuffer;
203 * const size_t xTriggerLevel = 1;
205 * xStreamBuffer = xStreamBufferCreateStatic( sizeof( ucBufferStorage ),
208 * &xStreamBufferStruct );
210 * // As neither the pucStreamBufferStorageArea or pxStaticStreamBuffer
211 * // parameters were NULL, xStreamBuffer will not be NULL, and can be used to
212 * // reference the created stream buffer in other stream buffer API calls.
214 * // Other code that uses the stream buffer can go here.
218 * \defgroup xStreamBufferCreateStatic xStreamBufferCreateStatic
219 * \ingroup StreamBufferManagement
221 #define xStreamBufferCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer ) \
222 xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE, pucStreamBufferStorageArea, pxStaticStreamBuffer )
228 * size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
229 * const void *pvTxData,
230 * size_t xDataLengthBytes,
231 * TickType_t xTicksToWait );
234 * Sends bytes to a stream buffer. The bytes are copied into the stream buffer.
236 * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
237 * implementation (so also the message buffer implementation, as message buffers
238 * are built on top of stream buffers) assumes there is only one task or
239 * interrupt that will write to the buffer (the writer), and only one task or
240 * interrupt that will read from the buffer (the reader). It is safe for the
241 * writer and reader to be different tasks or interrupts, but, unlike other
242 * FreeRTOS objects, it is not safe to have multiple different writers or
243 * multiple different readers. If there are to be multiple different writers
244 * then the application writer must place each call to a writing API function
245 * (such as xStreamBufferSend()) inside a critical section and set the send
246 * block time to 0. Likewise, if there are to be multiple different readers
247 * then the application writer must place each call to a reading API function
248 * (such as xStreamBufferReceive()) inside a critical section and set the receive
251 * Use xStreamBufferSend() to write to a stream buffer from a task. Use
252 * xStreamBufferSendFromISR() to write to a stream buffer from an interrupt
253 * service routine (ISR).
255 * @param xStreamBuffer The handle of the stream buffer to which a stream is
258 * @param pvTxData A pointer to the buffer that holds the bytes to be copied
259 * into the stream buffer.
261 * @param xDataLengthBytes The maximum number of bytes to copy from pvTxData
262 * into the stream buffer.
264 * @param xTicksToWait The maximum amount of time the task should remain in the
265 * Blocked state to wait for enough space to become available in the stream
266 * buffer, should the stream buffer contain too little space to hold the
267 * another xDataLengthBytes bytes. The block time is specified in tick periods,
268 * so the absolute time it represents is dependent on the tick frequency. The
269 * macro pdMS_TO_TICKS() can be used to convert a time specified in milliseconds
270 * into a time specified in ticks. Setting xTicksToWait to portMAX_DELAY will
271 * cause the task to wait indefinitely (without timing out), provided
272 * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. If a task times out
273 * before it can write all xDataLengthBytes into the buffer it will still write
274 * as many bytes as possible. A task does not use any CPU time when it is in
277 * @return The number of bytes written to the stream buffer. If a task times
278 * out before it can write all xDataLengthBytes into the buffer it will still
279 * write as many bytes as possible.
283 * void vAFunction( StreamBufferHandle_t xStreamBuffer )
286 * uint8_t ucArrayToSend[] = { 0, 1, 2, 3 };
287 * char *pcStringToSend = "String to send";
288 * const TickType_t x100ms = pdMS_TO_TICKS( 100 );
290 * // Send an array to the stream buffer, blocking for a maximum of 100ms to
291 * // wait for enough space to be available in the stream buffer.
292 * xBytesSent = xStreamBufferSend( xStreamBuffer, ( void * ) ucArrayToSend, sizeof( ucArrayToSend ), x100ms );
294 * if( xBytesSent != sizeof( ucArrayToSend ) )
296 * // The call to xStreamBufferSend() times out before there was enough
297 * // space in the buffer for the data to be written, but it did
298 * // successfully write xBytesSent bytes.
301 * // Send the string to the stream buffer. Return immediately if there is not
302 * // enough space in the buffer.
303 * xBytesSent = xStreamBufferSend( xStreamBuffer, ( void * ) pcStringToSend, strlen( pcStringToSend ), 0 );
305 * if( xBytesSent != strlen( pcStringToSend ) )
307 * // The entire string could not be added to the stream buffer because
308 * // there was not enough free space in the buffer, but xBytesSent bytes
309 * // were sent. Could try again to send the remaining bytes.
313 * \defgroup xStreamBufferSend xStreamBufferSend
314 * \ingroup StreamBufferManagement
316 size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
317 const void * pvTxData,
318 size_t xDataLengthBytes,
319 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
325 * size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer,
326 * const void *pvTxData,
327 * size_t xDataLengthBytes,
328 * BaseType_t *pxHigherPriorityTaskWoken );
331 * Interrupt safe version of the API function that sends a stream of bytes to
334 * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
335 * implementation (so also the message buffer implementation, as message buffers
336 * are built on top of stream buffers) assumes there is only one task or
337 * interrupt that will write to the buffer (the writer), and only one task or
338 * interrupt that will read from the buffer (the reader). It is safe for the
339 * writer and reader to be different tasks or interrupts, but, unlike other
340 * FreeRTOS objects, it is not safe to have multiple different writers or
341 * multiple different readers. If there are to be multiple different writers
342 * then the application writer must place each call to a writing API function
343 * (such as xStreamBufferSend()) inside a critical section and set the send
344 * block time to 0. Likewise, if there are to be multiple different readers
345 * then the application writer must place each call to a reading API function
346 * (such as xStreamBufferReceive()) inside a critical section and set the receive
349 * Use xStreamBufferSend() to write to a stream buffer from a task. Use
350 * xStreamBufferSendFromISR() to write to a stream buffer from an interrupt
351 * service routine (ISR).
353 * @param xStreamBuffer The handle of the stream buffer to which a stream is
356 * @param pvTxData A pointer to the data that is to be copied into the stream
359 * @param xDataLengthBytes The maximum number of bytes to copy from pvTxData
360 * into the stream buffer.
362 * @param pxHigherPriorityTaskWoken It is possible that a stream buffer will
363 * have a task blocked on it waiting for data. Calling
364 * xStreamBufferSendFromISR() can make data available, and so cause a task that
365 * was waiting for data to leave the Blocked state. If calling
366 * xStreamBufferSendFromISR() causes a task to leave the Blocked state, and the
367 * unblocked task has a priority higher than the currently executing task (the
368 * task that was interrupted), then, internally, xStreamBufferSendFromISR()
369 * will set *pxHigherPriorityTaskWoken to pdTRUE. If
370 * xStreamBufferSendFromISR() sets this value to pdTRUE, then normally a
371 * context switch should be performed before the interrupt is exited. This will
372 * ensure that the interrupt returns directly to the highest priority Ready
373 * state task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it
374 * is passed into the function. See the example code below for an example.
376 * @return The number of bytes actually written to the stream buffer, which will
377 * be less than xDataLengthBytes if the stream buffer didn't have enough free
378 * space for all the bytes to be written.
382 * // A stream buffer that has already been created.
383 * StreamBufferHandle_t xStreamBuffer;
385 * void vAnInterruptServiceRoutine( void )
388 * char *pcStringToSend = "String to send";
389 * BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
391 * // Attempt to send the string to the stream buffer.
392 * xBytesSent = xStreamBufferSendFromISR( xStreamBuffer,
393 * ( void * ) pcStringToSend,
394 * strlen( pcStringToSend ),
395 * &xHigherPriorityTaskWoken );
397 * if( xBytesSent != strlen( pcStringToSend ) )
399 * // There was not enough free space in the stream buffer for the entire
400 * // string to be written, ut xBytesSent bytes were written.
403 * // If xHigherPriorityTaskWoken was set to pdTRUE inside
404 * // xStreamBufferSendFromISR() then a task that has a priority above the
405 * // priority of the currently executing task was unblocked and a context
406 * // switch should be performed to ensure the ISR returns to the unblocked
407 * // task. In most FreeRTOS ports this is done by simply passing
408 * // xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the
409 * // variables value, and perform the context switch if necessary. Check the
410 * // documentation for the port in use for port specific instructions.
411 * taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );
414 * \defgroup xStreamBufferSendFromISR xStreamBufferSendFromISR
415 * \ingroup StreamBufferManagement
417 size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer,
418 const void * pvTxData,
419 size_t xDataLengthBytes,
420 BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
426 * size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer,
428 * size_t xBufferLengthBytes,
429 * TickType_t xTicksToWait );
432 * Receives bytes from a stream buffer.
434 * ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
435 * implementation (so also the message buffer implementation, as message buffers
436 * are built on top of stream buffers) assumes there is only one task or
437 * interrupt that will write to the buffer (the writer), and only one task or
438 * interrupt that will read from the buffer (the reader). It is safe for the
439 * writer and reader to be different tasks or interrupts, but, unlike other
440 * FreeRTOS objects, it is not safe to have multiple different writers or
441 * multiple different readers. If there are to be multiple different writers
442 * then the application writer must place each call to a writing API function
443 * (such as xStreamBufferSend()) inside a critical section and set the send
444 * block time to 0. Likewise, if there are to be multiple different readers
445 * then the application writer must place each call to a reading API function
446 * (such as xStreamBufferReceive()) inside a critical section and set the receive
449 * Use xStreamBufferReceive() to read from a stream buffer from a task. Use
450 * xStreamBufferReceiveFromISR() to read from a stream buffer from an
451 * interrupt service routine (ISR).
453 * @param xStreamBuffer The handle of the stream buffer from which bytes are to
456 * @param pvRxData A pointer to the buffer into which the received bytes will be
459 * @param xBufferLengthBytes The length of the buffer pointed to by the
460 * pvRxData parameter. This sets the maximum number of bytes to receive in one
461 * call. xStreamBufferReceive will return as many bytes as possible up to a
462 * maximum set by xBufferLengthBytes.
464 * @param xTicksToWait The maximum amount of time the task should remain in the
465 * Blocked state to wait for data to become available if the stream buffer is
466 * empty. xStreamBufferReceive() will return immediately if xTicksToWait is
467 * zero. The block time is specified in tick periods, so the absolute time it
468 * represents is dependent on the tick frequency. The macro pdMS_TO_TICKS() can
469 * be used to convert a time specified in milliseconds into a time specified in
470 * ticks. Setting xTicksToWait to portMAX_DELAY will cause the task to wait
471 * indefinitely (without timing out), provided INCLUDE_vTaskSuspend is set to 1
472 * in FreeRTOSConfig.h. A task does not use any CPU time when it is in the
475 * @return The number of bytes actually read from the stream buffer, which will
476 * be less than xBufferLengthBytes if the call to xStreamBufferReceive() timed
477 * out before xBufferLengthBytes were available.
481 * void vAFunction( StreamBuffer_t xStreamBuffer )
483 * uint8_t ucRxData[ 20 ];
484 * size_t xReceivedBytes;
485 * const TickType_t xBlockTime = pdMS_TO_TICKS( 20 );
487 * // Receive up to another sizeof( ucRxData ) bytes from the stream buffer.
488 * // Wait in the Blocked state (so not using any CPU processing time) for a
489 * // maximum of 100ms for the full sizeof( ucRxData ) number of bytes to be
491 * xReceivedBytes = xStreamBufferReceive( xStreamBuffer,
492 * ( void * ) ucRxData,
493 * sizeof( ucRxData ),
496 * if( xReceivedBytes > 0 )
498 * // A ucRxData contains another xRecievedBytes bytes of data, which can
499 * // be processed here....
503 * \defgroup xStreamBufferReceive xStreamBufferReceive
504 * \ingroup StreamBufferManagement
506 size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer,
508 size_t xBufferLengthBytes,
509 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
515 * size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer,
517 * size_t xBufferLengthBytes,
518 * BaseType_t *pxHigherPriorityTaskWoken );
521 * An interrupt safe version of the API function that receives bytes from a
524 * Use xStreamBufferReceive() to read bytes from a stream buffer from a task.
525 * Use xStreamBufferReceiveFromISR() to read bytes from a stream buffer from an
526 * interrupt service routine (ISR).
528 * @param xStreamBuffer The handle of the stream buffer from which a stream
531 * @param pvRxData A pointer to the buffer into which the received bytes are
534 * @param xBufferLengthBytes The length of the buffer pointed to by the
535 * pvRxData parameter. This sets the maximum number of bytes to receive in one
536 * call. xStreamBufferReceive will return as many bytes as possible up to a
537 * maximum set by xBufferLengthBytes.
539 * @param pxHigherPriorityTaskWoken It is possible that a stream buffer will
540 * have a task blocked on it waiting for space to become available. Calling
541 * xStreamBufferReceiveFromISR() can make space available, and so cause a task
542 * that is waiting for space to leave the Blocked state. If calling
543 * xStreamBufferReceiveFromISR() causes a task to leave the Blocked state, and
544 * the unblocked task has a priority higher than the currently executing task
545 * (the task that was interrupted), then, internally,
546 * xStreamBufferReceiveFromISR() will set *pxHigherPriorityTaskWoken to pdTRUE.
547 * If xStreamBufferReceiveFromISR() sets this value to pdTRUE, then normally a
548 * context switch should be performed before the interrupt is exited. That will
549 * ensure the interrupt returns directly to the highest priority Ready state
550 * task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it is
551 * passed into the function. See the code example below for an example.
553 * @return The number of bytes read from the stream buffer, if any.
557 * // A stream buffer that has already been created.
558 * StreamBuffer_t xStreamBuffer;
560 * void vAnInterruptServiceRoutine( void )
562 * uint8_t ucRxData[ 20 ];
563 * size_t xReceivedBytes;
564 * BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
566 * // Receive the next stream from the stream buffer.
567 * xReceivedBytes = xStreamBufferReceiveFromISR( xStreamBuffer,
568 * ( void * ) ucRxData,
569 * sizeof( ucRxData ),
570 * &xHigherPriorityTaskWoken );
572 * if( xReceivedBytes > 0 )
574 * // ucRxData contains xReceivedBytes read from the stream buffer.
575 * // Process the stream here....
578 * // If xHigherPriorityTaskWoken was set to pdTRUE inside
579 * // xStreamBufferReceiveFromISR() then a task that has a priority above the
580 * // priority of the currently executing task was unblocked and a context
581 * // switch should be performed to ensure the ISR returns to the unblocked
582 * // task. In most FreeRTOS ports this is done by simply passing
583 * // xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the
584 * // variables value, and perform the context switch if necessary. Check the
585 * // documentation for the port in use for port specific instructions.
586 * taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );
589 * \defgroup xStreamBufferReceiveFromISR xStreamBufferReceiveFromISR
590 * \ingroup StreamBufferManagement
592 size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer,
594 size_t xBufferLengthBytes,
595 BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
601 * void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer );
604 * Deletes a stream buffer that was previously created using a call to
605 * xStreamBufferCreate() or xStreamBufferCreateStatic(). If the stream
606 * buffer was created using dynamic memory (that is, by xStreamBufferCreate()),
607 * then the allocated memory is freed.
609 * A stream buffer handle must not be used after the stream buffer has been
612 * @param xStreamBuffer The handle of the stream buffer to be deleted.
614 * \defgroup vStreamBufferDelete vStreamBufferDelete
615 * \ingroup StreamBufferManagement
617 void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
623 * BaseType_t xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer );
626 * Queries a stream buffer to see if it is full. A stream buffer is full if it
627 * does not have any free space, and therefore cannot accept any more data.
629 * @param xStreamBuffer The handle of the stream buffer being queried.
631 * @return If the stream buffer is full then pdTRUE is returned. Otherwise
632 * pdFALSE is returned.
634 * \defgroup xStreamBufferIsFull xStreamBufferIsFull
635 * \ingroup StreamBufferManagement
637 BaseType_t xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
643 * BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer );
646 * Queries a stream buffer to see if it is empty. A stream buffer is empty if
647 * it does not contain any data.
649 * @param xStreamBuffer The handle of the stream buffer being queried.
651 * @return If the stream buffer is empty then pdTRUE is returned. Otherwise
652 * pdFALSE is returned.
654 * \defgroup xStreamBufferIsEmpty xStreamBufferIsEmpty
655 * \ingroup StreamBufferManagement
657 BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
663 * BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer );
666 * Resets a stream buffer to its initial, empty, state. Any data that was in
667 * the stream buffer is discarded. A stream buffer can only be reset if there
668 * are no tasks blocked waiting to either send to or receive from the stream
671 * @param xStreamBuffer The handle of the stream buffer being reset.
673 * @return If the stream buffer is reset then pdPASS is returned. If there was
674 * a task blocked waiting to send to or read from the stream buffer then the
675 * stream buffer is not reset and pdFAIL is returned.
677 * \defgroup xStreamBufferReset xStreamBufferReset
678 * \ingroup StreamBufferManagement
680 BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
686 * size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer );
689 * Queries a stream buffer to see how much free space it contains, which is
690 * equal to the amount of data that can be sent to the stream buffer before it
693 * @param xStreamBuffer The handle of the stream buffer being queried.
695 * @return The number of bytes that can be written to the stream buffer before
696 * the stream buffer would be full.
698 * \defgroup xStreamBufferSpacesAvailable xStreamBufferSpacesAvailable
699 * \ingroup StreamBufferManagement
701 size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
707 * size_t xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer );
710 * Queries a stream buffer to see how much data it contains, which is equal to
711 * the number of bytes that can be read from the stream buffer before the stream
712 * buffer would be empty.
714 * @param xStreamBuffer The handle of the stream buffer being queried.
716 * @return The number of bytes that can be read from the stream buffer before
717 * the stream buffer would be empty.
719 * \defgroup xStreamBufferBytesAvailable xStreamBufferBytesAvailable
720 * \ingroup StreamBufferManagement
722 size_t xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
728 * BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevel );
731 * A stream buffer's trigger level is the number of bytes that must be in the
732 * stream buffer before a task that is blocked on the stream buffer to
733 * wait for data is moved out of the blocked state. For example, if a task is
734 * blocked on a read of an empty stream buffer that has a trigger level of 1
735 * then the task will be unblocked when a single byte is written to the buffer
736 * or the task's block time expires. As another example, if a task is blocked
737 * on a read of an empty stream buffer that has a trigger level of 10 then the
738 * task will not be unblocked until the stream buffer contains at least 10 bytes
739 * or the task's block time expires. If a reading task's block time expires
740 * before the trigger level is reached then the task will still receive however
741 * many bytes are actually available. Setting a trigger level of 0 will result
742 * in a trigger level of 1 being used. It is not valid to specify a trigger
743 * level that is greater than the buffer size.
745 * A trigger level is set when the stream buffer is created, and can be modified
746 * using xStreamBufferSetTriggerLevel().
748 * @param xStreamBuffer The handle of the stream buffer being updated.
750 * @param xTriggerLevel The new trigger level for the stream buffer.
752 * @return If xTriggerLevel was less than or equal to the stream buffer's length
753 * then the trigger level will be updated and pdTRUE is returned. Otherwise
754 * pdFALSE is returned.
756 * \defgroup xStreamBufferSetTriggerLevel xStreamBufferSetTriggerLevel
757 * \ingroup StreamBufferManagement
759 BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer,
760 size_t xTriggerLevel ) PRIVILEGED_FUNCTION;
766 * BaseType_t xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
769 * For advanced users only.
771 * The sbSEND_COMPLETED() macro is called from within the FreeRTOS APIs when
772 * data is sent to a message buffer or stream buffer. If there was a task that
773 * was blocked on the message or stream buffer waiting for data to arrive then
774 * the sbSEND_COMPLETED() macro sends a notification to the task to remove it
775 * from the Blocked state. xStreamBufferSendCompletedFromISR() does the same
776 * thing. It is provided to enable application writers to implement their own
777 * version of sbSEND_COMPLETED(), and MUST NOT BE USED AT ANY OTHER TIME.
779 * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for
780 * additional information.
782 * @param xStreamBuffer The handle of the stream buffer to which data was
785 * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be
786 * initialised to pdFALSE before it is passed into
787 * xStreamBufferSendCompletedFromISR(). If calling
788 * xStreamBufferSendCompletedFromISR() removes a task from the Blocked state,
789 * and the task has a priority above the priority of the currently running task,
790 * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a
791 * context switch should be performed before exiting the ISR.
793 * @return If a task was removed from the Blocked state then pdTRUE is returned.
794 * Otherwise pdFALSE is returned.
796 * \defgroup xStreamBufferSendCompletedFromISR xStreamBufferSendCompletedFromISR
797 * \ingroup StreamBufferManagement
799 BaseType_t xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer,
800 BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
806 * BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
809 * For advanced users only.
811 * The sbRECEIVE_COMPLETED() macro is called from within the FreeRTOS APIs when
812 * data is read out of a message buffer or stream buffer. If there was a task
813 * that was blocked on the message or stream buffer waiting for data to arrive
814 * then the sbRECEIVE_COMPLETED() macro sends a notification to the task to
815 * remove it from the Blocked state. xStreamBufferReceiveCompletedFromISR()
816 * does the same thing. It is provided to enable application writers to
817 * implement their own version of sbRECEIVE_COMPLETED(), and MUST NOT BE USED AT
820 * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for
821 * additional information.
823 * @param xStreamBuffer The handle of the stream buffer from which data was
826 * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be
827 * initialised to pdFALSE before it is passed into
828 * xStreamBufferReceiveCompletedFromISR(). If calling
829 * xStreamBufferReceiveCompletedFromISR() removes a task from the Blocked state,
830 * and the task has a priority above the priority of the currently running task,
831 * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a
832 * context switch should be performed before exiting the ISR.
834 * @return If a task was removed from the Blocked state then pdTRUE is returned.
835 * Otherwise pdFALSE is returned.
837 * \defgroup xStreamBufferReceiveCompletedFromISR xStreamBufferReceiveCompletedFromISR
838 * \ingroup StreamBufferManagement
840 BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer,
841 BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
843 /* Functions below here are not part of the public API. */
844 StreamBufferHandle_t xStreamBufferGenericCreate( size_t xBufferSizeBytes,
845 size_t xTriggerLevelBytes,
846 BaseType_t xIsMessageBuffer ) PRIVILEGED_FUNCTION;
848 StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
849 size_t xTriggerLevelBytes,
850 BaseType_t xIsMessageBuffer,
851 uint8_t * const pucStreamBufferStorageArea,
852 StaticStreamBuffer_t * const pxStaticStreamBuffer ) PRIVILEGED_FUNCTION;
854 size_t xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
856 #if ( configUSE_TRACE_FACILITY == 1 )
857 void vStreamBufferSetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer,
858 UBaseType_t uxStreamBufferNumber ) PRIVILEGED_FUNCTION;
859 UBaseType_t uxStreamBufferGetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
860 uint8_t ucStreamBufferGetStreamBufferType( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
864 #if defined( __cplusplus )
869 #endif /* !defined( STREAM_BUFFER_H ) */