libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
esp_tx_double_buffer.hpp
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
6#include "double_buffer.hpp"
7#include "flag.hpp"
8#include "libxr_assert.hpp"
9#include "operation.hpp"
10
11namespace LibXR
12{
13
24{
25 public:
30 ESPTxDoubleBuffer() = default;
31
42 void Init(RawData storage)
43 {
44 bytes_.Init(storage);
45 Reset();
46 }
47
52 void Reset()
53 {
54 bytes_.Reset();
57 }
58
63 uint8_t* ActiveBuffer() const { return bytes_.ActiveBuffer(); }
64
69 uint8_t* PendingBuffer() const { return bytes_.PendingBuffer(); }
70
75 size_t BufferSize() const { return bytes_.Size(); }
76
81 bool HasActive() const { return active_valid_; }
82
87 bool HasPending() const { return pending_valid_.IsSet(); }
88
93 size_t ActiveLength() const { return active_length_; }
94
99 size_t ActiveOffset() const { return active_offset_; }
100
108 void SetActiveOffset(size_t offset) { active_offset_ = offset; }
109
115
120 const WriteInfoBlock& ActiveInfo() const { return active_info_; }
121
127
132 const WriteInfoBlock& PendingInfo() const { return pending_info_; }
133
143 void LoadActive(size_t size, const WriteInfoBlock& info)
144 {
145 active_length_ = size;
146 active_offset_ = 0U;
147 active_info_ = info;
148 active_valid_ = true;
149 }
150
160 void LoadPending(size_t size, const WriteInfoBlock& info)
161 {
162 pending_length_ = size;
163 pending_info_ = info;
165 }
166
178 {
180 {
181 return false;
182 }
183
186 active_offset_ = 0U;
188 active_valid_ = true;
189 pending_length_ = 0U;
190 pending_info_ = {};
191 return true;
192 }
193
199 {
200 active_length_ = 0U;
201 active_offset_ = 0U;
202 active_info_ = {};
203 active_valid_ = false;
204 }
205
211 {
213 pending_length_ = 0U;
214 pending_info_ = {};
215 }
216
217 private:
219 size_t active_length_ = 0U;
220 size_t pending_length_ = 0U;
221 size_t active_offset_ = 0U;
225 false;
228};
229
230} // namespace LibXR
双缓冲区管理类 / Double buffer manager class
void Reset()
重置 active/pending 状态,但保留已绑定的 backing storage Resets active/pending state while keeping bound backing ...
void FlipActiveBlock()
翻转当前活动缓冲区编号 Flips the current active block index
size_t Size() const
获取每个缓冲区的大小(单位:字节) Gets the size of each buffer in bytes
uint8_t * ActiveBuffer() const
获取当前正在使用的缓冲区指针 Returns the currently active buffer
void Init(const LibXR::RawData &raw_data)
绑定连续 backing storage 并重置双缓冲状态 Binds continuous backing storage and resets double-buffer state
uint8_t * PendingBuffer() const
获取备用缓冲区的指针 Returns the pending (inactive) buffer
ESP 发送路径双缓冲辅助器。
void Reset()
重置当前 active/pending 发送状态。
void LoadActive(size_t size, const WriteInfoBlock &info)
装载一个 active 请求的长度与元数据。
size_t ActiveOffset() const
获取当前 active payload 已推进的偏移量。
size_t active_length_
active payload 长度。 Active payload length.
const WriteInfoBlock & PendingInfo() const
获取 pending 请求元数据常量引用。
void LoadPending(size_t size, const WriteInfoBlock &info)
装载一个 pending 请求的长度与元数据。
void ClearActive()
清除当前 active 请求状态。
void Init(RawData storage)
绑定外部双缓冲 backing storage 并重置状态。
bool HasActive() const
判断是否存在有效 active 请求。
WriteInfoBlock pending_info_
pending 请求元数据。 Pending request metadata.
Flag::Atomic pending_valid_
pending 请求是否有效。 Whether a pending request is valid.
const WriteInfoBlock & ActiveInfo() const
获取 active 请求元数据常量引用。
WriteInfoBlock active_info_
active 请求元数据。 Active request metadata.
size_t active_offset_
active payload 已推进偏移。 Active progressed offset.
size_t pending_length_
pending payload 长度。 Pending payload length.
bool PromotePending()
将 pending 请求提升为 active 请求。
void SetActiveOffset(size_t offset)
更新当前 active payload 已推进的偏移量。
uint8_t * PendingBuffer() const
获取当前 pending payload 缓冲区指针。
WriteInfoBlock & PendingInfo()
获取 pending 请求元数据引用。
bool HasPending() const
判断是否存在有效 pending 请求。
DoubleBuffer bytes_
payload 双缓冲对象。 Payload double-buffer object.
bool active_valid_
active 请求是否有效。 Whether an active request is valid.
ESPTxDoubleBuffer()=default
默认构造辅助器。
uint8_t * ActiveBuffer() const
获取当前 active payload 缓冲区指针。
WriteInfoBlock & ActiveInfo()
获取 active 请求元数据引用。
size_t ActiveLength() const
获取当前 active payload 长度。
void ClearPending()
清除当前 pending 请求状态。
size_t BufferSize() const
获取单个半缓冲区大小。
原子标志位 / Atomic flag
Definition flag.hpp:32
void Set() noexcept
置位标志 / Set the flag
Definition flag.hpp:42
bool TestAndClear() noexcept
测试并清除:清除并返回旧状态 / Test-and-clear: clear and return previous state
Definition flag.hpp:77
bool IsSet() const noexcept
判断是否已置位 / Check whether the flag is set
Definition flag.hpp:55
void Clear() noexcept
清除标志 / Clear the flag
Definition flag.hpp:47
可写原始数据视图 / Mutable raw data view
LibXR 命名空间
Definition ch32_can.hpp:14