arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BufferZephyr< T > Class Template Reference

Buffer implementation using Zephyr semaphores + mutex as a bounded ring buffer. More...

#include <BufferZephyr.h>

Inheritance diagram for BufferZephyr< T >:
BaseBuffer< T >

Public Member Functions

 BufferZephyr (size_t streamBufferSize, size_t xTriggerLevel=1, TickType_t writeMaxWait=portMAX_DELAY, TickType_t readMaxWait=portMAX_DELAY, Allocator &allocator=DefaultAllocator)
 
 ~BufferZephyr ()
 
Taddress () override
 returns the address of the start of the physical read buffer
 
int available () override
 provides the number of entries that are available to read
 
int availableForWrite () override
 provides the number of entries that are available to write
 
virtual int bufferCountEmpty ()
 Provides the number of entries that are available to write: -1 does not apply.
 
virtual int bufferCountFilled ()
 Provides the number of entries that are available to read: -1 does not apply.
 
void clear ()
 same as reset
 
virtual int clearArray (int len)
 Removes the next len entries.
 
virtual void flush ()
 
bool isEmpty ()
 
bool isFull () override
 checks if the buffer is full
 
virtual float levelPercent ()
 Returns the level of the buffer in %.
 
 operator bool ()
 
bool peek (T &result) override
 peeks the actual entry from the buffer
 
bool read (T &result) override
 reads a single value
 
int readArray (T data[], int len) override
 reads multiple values
 
void reset () override
 clears the buffer
 
bool resize (size_t size)
 Re-Allocates the memory and queue.
 
void setReadFromISR (bool active)
 
void setReadMaxWait (TickType_t ticks)
 
void setWriteFromISR (bool active)
 
void setWriteMaxWait (TickType_t ticks)
 
size_t size () override
 
bool write (T data) override
 write add an entry to the buffer
 
int writeArray (const T data[], int len) override
 Fills the buffer data.
 
virtual int writeArrayOverwrite (const T data[], int len)
 Fills the buffer data and overwrites the oldest data if the buffer is full.
 

Protected Member Functions

void end ()
 Release resources: call resize to restart again.
 
bool readOne (T &value)
 
bool setup ()
 
bool writeOne (const T &value)
 

Protected Attributes

struct k_mutex buffer_mutex
 
size_t buffer_size_public = 0
 
size_t current_size_entries = 0
 
size_t head = 0
 
struct k_sem items_sem
 
Allocatorp_allocator = nullptr
 
Tp_data = nullptr
 
bool read_from_isr = false
 
TickType_t readWait = portMAX_DELAY
 
struct k_sem spaces_sem
 
size_t tail = 0
 
bool write_from_isr = false
 
TickType_t writeWait = portMAX_DELAY
 

Detailed Description

template<typename T>
class audio_tools::BufferZephyr< T >

Buffer implementation using Zephyr semaphores + mutex as a bounded ring buffer.

Note
Supported by all Zephyr platforms

Constructor & Destructor Documentation

◆ BufferZephyr()

template<typename T >
BufferZephyr ( size_t  streamBufferSize,
size_t  xTriggerLevel = 1,
TickType_t  writeMaxWait = portMAX_DELAY,
TickType_t  readMaxWait = portMAX_DELAY,
Allocator allocator = DefaultAllocator 
)
inline

◆ ~BufferZephyr()

template<typename T >
~BufferZephyr ( )
inline

Member Function Documentation

◆ address()

template<typename T >
T * address ( )
inlineoverridevirtual

returns the address of the start of the physical read buffer

Implements BaseBuffer< T >.

◆ available()

template<typename T >
int available ( )
inlineoverridevirtual

provides the number of entries that are available to read

Implements BaseBuffer< T >.

◆ availableForWrite()

template<typename T >
int availableForWrite ( )
inlineoverridevirtual

provides the number of entries that are available to write

Implements BaseBuffer< T >.

◆ bufferCountEmpty()

virtual int bufferCountEmpty ( )
inlinevirtualinherited

Provides the number of entries that are available to write: -1 does not apply.

Reimplemented in SynchronizedNBufferRTOST< T >, SynchronizedNBufferZephyrT< T >, and NBuffer< T >.

◆ bufferCountFilled()

virtual int bufferCountFilled ( )
inlinevirtualinherited

Provides the number of entries that are available to read: -1 does not apply.

Reimplemented in SynchronizedNBufferRTOST< T >, SynchronizedNBufferZephyrT< T >, and NBuffer< T >.

◆ clear()

void clear ( )
inlineinherited

same as reset

◆ clearArray()

virtual int clearArray ( int  len)
inlinevirtualinherited

Removes the next len entries.

Reimplemented in SingleBuffer< T >.

◆ end()

template<typename T >
void end ( )
inlineprotected

Release resources: call resize to restart again.

◆ flush()

virtual void flush ( )
inlinevirtualinherited

Submit any partially-filled write buffer so the reader can access it. Only meaningful for NBuffer-style block pools; no-op for ring buffers.

Reimplemented in NBuffer< T >.

◆ isEmpty()

template<typename T >
bool isEmpty ( )
inline

◆ isFull()

template<typename T >
bool isFull ( )
inlineoverridevirtual

checks if the buffer is full

Reimplemented from BaseBuffer< T >.

◆ levelPercent()

virtual float levelPercent ( )
inlinevirtualinherited

Returns the level of the buffer in %.

◆ operator bool()

template<typename T >
operator bool ( )
inline

◆ peek()

template<typename T >
bool peek ( T result)
inlineoverridevirtual

peeks the actual entry from the buffer

Implements BaseBuffer< T >.

◆ read()

template<typename T >
bool read ( T result)
inlineoverridevirtual

reads a single value

Implements BaseBuffer< T >.

◆ readArray()

template<typename T >
int readArray ( T  data[],
int  len 
)
inlineoverridevirtual

reads multiple values

Reimplemented from BaseBuffer< T >.

◆ readOne()

template<typename T >
bool readOne ( T value)
inlineprotected

◆ reset()

template<typename T >
void reset ( )
inlineoverridevirtual

clears the buffer

Implements BaseBuffer< T >.

◆ resize()

template<typename T >
bool resize ( size_t  size)
inlinevirtual

Re-Allocates the memory and queue.

Reimplemented from BaseBuffer< T >.

◆ setReadFromISR()

template<typename T >
void setReadFromISR ( bool  active)
inline

◆ setReadMaxWait()

template<typename T >
void setReadMaxWait ( TickType_t  ticks)
inline

◆ setup()

template<typename T >
bool setup ( )
inlineprotected

Allocation has been postponed to be done here so that e.g. psram can be used.

◆ setWriteFromISR()

template<typename T >
void setWriteFromISR ( bool  active)
inline

◆ setWriteMaxWait()

template<typename T >
void setWriteMaxWait ( TickType_t  ticks)
inline

◆ size()

template<typename T >
size_t size ( )
inlineoverridevirtual

Implements BaseBuffer< T >.

◆ write()

template<typename T >
bool write ( T  data)
inlineoverridevirtual

write add an entry to the buffer

Implements BaseBuffer< T >.

◆ writeArray()

template<typename T >
int writeArray ( const T  data[],
int  len 
)
inlineoverridevirtual

Fills the buffer data.

Reimplemented from BaseBuffer< T >.

◆ writeArrayOverwrite()

virtual int writeArrayOverwrite ( const T  data[],
int  len 
)
inlinevirtualinherited

Fills the buffer data and overwrites the oldest data if the buffer is full.

◆ writeOne()

template<typename T >
bool writeOne ( const T value)
inlineprotected

Member Data Documentation

◆ buffer_mutex

template<typename T >
struct k_mutex buffer_mutex
protected

◆ buffer_size_public

template<typename T >
size_t buffer_size_public = 0
protected

◆ current_size_entries

template<typename T >
size_t current_size_entries = 0
protected

◆ head

template<typename T >
size_t head = 0
protected

◆ items_sem

template<typename T >
struct k_sem items_sem
protected

◆ p_allocator

template<typename T >
Allocator* p_allocator = nullptr
protected

◆ p_data

template<typename T >
T* p_data = nullptr
protected

◆ read_from_isr

template<typename T >
bool read_from_isr = false
protected

◆ readWait

template<typename T >
TickType_t readWait = portMAX_DELAY
protected

◆ spaces_sem

template<typename T >
struct k_sem spaces_sem
protected

◆ tail

template<typename T >
size_t tail = 0
protected

◆ write_from_isr

template<typename T >
bool write_from_isr = false
protected

◆ writeWait

template<typename T >
TickType_t writeWait = portMAX_DELAY
protected

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