Stream Buffer

Stream buffers transfer data between two tasks, or from an ISR to a task. Unlike queues, the stream buffer assumes that there is only one reader and only one writer. When creating a stream buffer, the maximum size of the buffer is specified. As the name implies, a stream buffer allows a stream of bytes to be transferred between a writer and a reader. The byte stream can be of an arbitrary length as long as it is within the size of the buffer.

A stream buffer is created using the function xStreamBufferCreate(BufferSizeBytes, TriggerLevelBytes). The first input argument specifies the total number of bytes the buffer is able to hold. The second argument, the trigger level, specifies the number of bytes that must be in the buffer before a blocked receiver is moved out of the blocked state.

The sender may block if the buffer is full. How long the sender task should block while waiting for data is given by a time-out that is set in the send function. Similarly, a receiver will block if the buffer is empty.

Unlike a queue, the sender is not required to have the complete message ready before putting it in the buffer.

The send and receive functions are shown below.
xStreamBufferSend(streamBuffer, *pvTxData, dataLengthBytes, ticksToWait);
xStreamBufferReceive(streamBuffer, *pvRxData, bufferLengthBytes, ticksToWait);