libxr
1.0
Want to be the best embedded framework
|
双缓冲区管理类 / Double buffer manager class More...
#include <double_buffer.hpp>
Public Member Functions | |
DoubleBuffer (const LibXR::RawData &raw_data) | |
构造函数,使用连续内存构造两个缓冲区 Constructs a double buffer using one continuous memory block | |
uint8_t * | ActiveBuffer () |
获取当前正在使用的缓冲区指针 Returns the currently active buffer | |
uint8_t * | PendingBuffer () |
获取备用缓冲区的指针 Returns the pending (inactive) buffer | |
size_t | Size () const |
获取每个缓冲区的大小(单位:字节) Gets the size of each buffer in bytes | |
void | Switch () |
切换到备用缓冲区(若其有效) Switches to the pending buffer if it's valid | |
bool | HasPending () const |
判断是否有待切换的缓冲区 Checks whether a pending buffer is ready | |
bool | FillPending (const uint8_t *data, size_t len) |
向备用缓冲区写入数据(不可重入) Fills the pending buffer with data (non-reentrant) | |
bool | FillActive (const uint8_t *data, size_t len) |
向当前使用的缓冲区直接写入数据 Fills the active buffer directly | |
void | EnablePending () |
手动启用 pending 状态 Manually sets the pending state to true | |
size_t | GetPendingLength () const |
获取 pending 缓冲区中准备好的数据长度 Gets the size of valid data in pending buffer | |
void | SetPendingLength (size_t size) |
设置备用缓冲区的数据长度 Sets the size of the pending buffer | |
Private Attributes | |
uint8_t * | buffer_ [2] |
双缓冲区指针 / Double buffer pointers | |
size_t | size_ |
单个缓冲区大小 / Size of each buffer | |
int | active_ = 0 |
当前活动缓冲区编号 / Index of active buffer | |
bool | pending_valid_ |
标记备用区是否准备好 / Whether pending buffer is ready | |
size_t | pending_len_ = 0 |
备用缓冲区有效数据长度 / Length of pending data | |
双缓冲区管理类 / Double buffer manager class
该类用于在嵌入式场景中管理双缓冲传输结构,支持主动缓冲、备用缓冲切换与填充。 用于实现无缝 DMA 或 USB 数据流水线发送,提高吞吐效率。 This class provides double-buffer control for efficient pipelined transmission such as USB or DMA streaming.
Definition at line 20 of file double_buffer.hpp.
|
explicit |
构造函数,使用连续内存构造两个缓冲区 Constructs a double buffer using one continuous memory block
raw_data | 连续内存区,大小必须为两个缓冲区之和 / The raw memory to be split |
Definition at line 5 of file double_buffer.cpp.
uint8_t * DoubleBuffer::ActiveBuffer | ( | ) |
获取当前正在使用的缓冲区指针 Returns the currently active buffer
Definition at line 11 of file double_buffer.cpp.
void DoubleBuffer::EnablePending | ( | ) |
手动启用 pending 状态 Manually sets the pending state to true
通常与 FillActive() 配合使用,表示下次发送使用 FillActive 写入的缓冲。
Definition at line 50 of file double_buffer.cpp.
bool DoubleBuffer::FillActive | ( | const uint8_t * | data, |
size_t | len ) |
向当前使用的缓冲区直接写入数据 Fills the active buffer directly
data | 数据源指针 / Source data pointer |
len | 数据长度 / Length to write |
Definition at line 40 of file double_buffer.cpp.
bool DoubleBuffer::FillPending | ( | const uint8_t * | data, |
size_t | len ) |
向备用缓冲区写入数据(不可重入) Fills the pending buffer with data (non-reentrant)
data | 数据源指针 / Pointer to the source data |
len | 数据长度(字节) / Data length in bytes |
Definition at line 28 of file double_buffer.cpp.
size_t DoubleBuffer::GetPendingLength | ( | ) | const |
获取 pending 缓冲区中准备好的数据长度 Gets the size of valid data in pending buffer
Definition at line 52 of file double_buffer.cpp.
bool DoubleBuffer::HasPending | ( | ) | const |
判断是否有待切换的缓冲区 Checks whether a pending buffer is ready
Definition at line 26 of file double_buffer.cpp.
uint8_t * DoubleBuffer::PendingBuffer | ( | ) |
获取备用缓冲区的指针 Returns the pending (inactive) buffer
Definition at line 13 of file double_buffer.cpp.
|
inline |
设置备用缓冲区的数据长度 Sets the size of the pending buffer
size | 数据长度(字节) / Data length in bytes |
Definition at line 116 of file double_buffer.hpp.
size_t DoubleBuffer::Size | ( | ) | const |
获取每个缓冲区的大小(单位:字节) Gets the size of each buffer in bytes
Definition at line 15 of file double_buffer.cpp.
void DoubleBuffer::Switch | ( | ) |
切换到备用缓冲区(若其有效) Switches to the pending buffer if it's valid
Definition at line 17 of file double_buffer.cpp.
|
private |
当前活动缓冲区编号 / Index of active buffer
Definition at line 121 of file double_buffer.hpp.
|
private |
双缓冲区指针 / Double buffer pointers
Definition at line 119 of file double_buffer.hpp.
|
private |
备用缓冲区有效数据长度 / Length of pending data
Definition at line 124 of file double_buffer.hpp.
|
private |
标记备用区是否准备好 / Whether pending buffer is ready
Definition at line 122 of file double_buffer.hpp.
|
private |
单个缓冲区大小 / Size of each buffer
Definition at line 120 of file double_buffer.hpp.