FreeRTOS-Cpp
Loading...
Searching...
No Matches
Public Member Functions | List of all members
FreeRTOS::StreamBuffer Class Reference

Class that encapsulates the functionality of a FreeRTOS stream buffer. More...

#include <FreeRTOS/StreamBuffer.hpp>

Inheritance diagram for FreeRTOS::StreamBuffer:
Inheritance graph
[legend]
Collaboration diagram for FreeRTOS::StreamBuffer:
Collaboration graph
[legend]

Public Member Functions

 StreamBuffer (const size_t size, const size_t triggerLevel=0)
 Construct a new StreamBuffer object by calling StreamBufferHandle_t xStreamBufferCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes )
 
 StreamBuffer (const StreamBuffer &)=delete
 
StreamBufferoperator= (const StreamBuffer &)=delete
 
 StreamBuffer (StreamBuffer &&) noexcept=default
 
StreamBufferoperator= (StreamBuffer &&) noexcept=default
 
- Public Member Functions inherited from FreeRTOS::StreamBufferBase
 StreamBufferBase (const StreamBufferBase &)=delete
 
StreamBufferBaseoperator= (const StreamBufferBase &)=delete
 
bool isValid () const
 Function that checks if the underlying stream buffer handle is not NULL. This should be used to ensure a stream buffer has been created correctly.
 
size_t send (const void *data, const size_t length, const TickType_t ticksToWait=portMAX_DELAY) const
 Function that calls size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, const void *pvTxData, size_t xDataLengthBytes, TickType_t xTicksToWait )
 
size_t sendFromISR (bool &higherPriorityTaskWoken, const void *data, const size_t length) const
 Function that calls size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer, const void *pvTxData, size_t xDataLengthBytes, BaseType_t *pxHigherPriorityTaskWoken )
 
size_t sendFromISR (const void *data, const size_t length) const
 Function that calls size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer, const void *pvTxData, size_t xDataLengthBytes, BaseType_t *pxHigherPriorityTaskWoken )
 
size_t receive (void *buffer, const size_t bufferLength, const TickType_t ticksToWait=portMAX_DELAY) const
 Function that calls size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer, void *pvRxData, size_t xBufferLengthBytes, TickType_t xTicksToWait )
 
size_t receiveFromISR (bool &higherPriorityTaskWoken, void *buffer, const size_t bufferLength) const
 Function that calls size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer, void *pvRxData, size_t xBufferLengthBytes, BaseType_t *pxHigherPriorityTaskWoken )
 
size_t receiveFromISR (void *buffer, const size_t bufferLength) const
 Function that calls size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer, void *pvRxData, size_t xBufferLengthBytes, BaseType_t *pxHigherPriorityTaskWoken )
 
size_t bytesAvailable () const
 Function that calls size_t xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer )
 
size_t spacesAvailable () const
 Function that calls size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer )
 
bool setTriggerLevel (const size_t triggerLevel=0) const
 Function that calls BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevel )
 
bool reset () const
 Function that calls BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer )
 
bool isEmpty () const
 Function that calls BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer )
 
bool isFull () const
 Function that calls BaseType_t xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer )
 

Additional Inherited Members

- Static Public Member Functions inherited from FreeRTOS::StreamBufferBase
static void * operator new (size_t)=delete
 
static void * operator new[] (size_t)=delete
 
static void * operator new (size_t, void *ptr)
 
static void * operator new[] (size_t, void *ptr)
 

Detailed Description

Class that encapsulates the functionality of a FreeRTOS stream buffer.

A stream buffer using dynamically allocated memory from the FreeRTOS heap. See FreeRTOS::StaticStreamBuffer for a version that uses statically allocated memory (memory that is allocated at compile time).

Constructor & Destructor Documentation

◆ StreamBuffer()

FreeRTOS::StreamBuffer::StreamBuffer ( const size_t  size,
const size_t  triggerLevel = 0 
)
inlineexplicit

Construct a new StreamBuffer object by calling StreamBufferHandle_t xStreamBufferCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes )

StreamBuffer.hpp

See also
https://www.freertos.org/xStreamBufferCreate.html
Warning
The user should call isValid() on this object to verify that the stream buffer was created successfully in case the memory required to create the message buffer could not be allocated.
Parameters
sizeThe total number of bytes the stream buffer will be able to hold at any one time.
triggerLevelThe number of bytes that must be in the stream buffer before a task that is blocked on the stream buffer to wait for data is moved out of the blocked state. For example, if a task is blocked on a read of an empty stream buffer that has a trigger level of 1 then the task will be unblocked when a single byte is written to the buffer or the task's block time expires. As another example, if a task is blocked on a read of an empty stream buffer that has a trigger level of 10 then the task will not be unblocked until the stream buffer contains at least 10 bytes or the task's block time expires. If a reading task's block time expires before the trigger level is reached then the task will still receive however many bytes are actually available. Setting a trigger level of 0 will result in a trigger level of 1 being used. It is not valid to specify a trigger level that is greater than the buffer size.

Example Usage

#include <FreeRTOS/StreamBuffer.hpp>
#include <FreeRTOS/Task.hpp>
class MyTask : public FreeRTOS::Task {
public:
void taskFunction() final;
};
void MyTask::taskFunction() {
constexpr size_t streamBufferSize = 100;
// Create a stream buffer that can hold 100 bytes. The memory used to hold
// both the stream buffer structure and the data in the stream buffer is
// allocated dynamically.
FreeRTOS::StreamBuffer streamBuffer(streamBufferSize);
if (streamBuffer.isValid()) {
// The stream buffer was created successfully and can now be used.
} else {
// There was not enough heap memory space available to create the stream
// buffer.
}
// Rest of task code.
}
Class that encapsulates the functionality of a FreeRTOS stream buffer.
Definition StreamBuffer.hpp:470
Class that encapsulates the functionality of a FreeRTOS task.
Definition Task.hpp:1427

The documentation for this class was generated from the following file: