|
libxr
1.0
Want to be the best embedded framework
|
ReadPort class for handling read operations. More...
#include <read_port.hpp>
Public Types | |
| enum class | BusyState : uint32_t { IDLE = 0 , PENDING = 1 , CLEARING = 2 , BLOCK_CLAIMED = 3 , BLOCK_DETACHED = 4 , EVENT = UINT32_MAX } |
Public Member Functions | |
| ReadPort (size_t buffer_size=128) | |
| Constructs a ReadPort with queue sizes. | |
| size_t | EmptySize () |
| 获取队列的剩余可用空间。 Gets the remaining available space in the queue. | |
| size_t | Size () |
| 获取当前队列的已使用大小。 Gets the currently used size of the queue. | |
| bool | Readable () |
| Checks if read operations are supported. | |
| ReadPort & | operator= (ReadFun fun) |
| 赋值运算符重载,用于设置读取函数。 Overloaded assignment operator to set the read function. | |
| void | Finish (bool in_isr, ErrorCode ans, ReadInfoBlock &info) |
| 完成已由队列路径认领的读取操作。 Completes a read operation already claimed by the queue path. | |
| void | MarkAsRunning (ReadInfoBlock &info) |
| 标记读取操作为运行中。 Marks the read operation as running. | |
| ErrorCode | operator() (RawData data, ReadOperation &op, bool in_isr=false) |
| 读取操作符重载,用于执行读取操作。 Overloaded function call operator to perform a read operation. | |
| virtual void | OnRxDequeue (bool) |
| RX 数据从软件队列成功出队后的通知。 Notification after bytes are popped from RX data queue. | |
| ErrorCode | ClearQueuedData (bool in_isr=false) |
| 清空当前已排队的 RX 字节。 | |
| void | ProcessPendingReads (bool in_isr) |
| Processes pending reads. | |
| void | FailAndClearAll (ErrorCode reason, bool in_isr) |
| 失败完成并清空当前所有挂起读操作。 | |
Data Fields | |
| ReadFun | read_fun_ = nullptr |
| Driver/backend read notification entry. 底层驱动或后端读取通知入口。 | |
| LockFreeQueue< uint8_t > * | queue_data_ = nullptr |
| RX payload queue. 接收数据字节队列。 | |
| ReadInfoBlock | info_ {} |
| In-flight read request metadata. 当前在途读取请求的元数据。 | |
| std::atomic< BusyState > | busy_ {BusyState::IDLE} |
| Shared read-progress handoff state. 共享的读进度交接状态。 | |
| ErrorCode | block_result_ = ErrorCode::OK |
| Final status for the current BLOCK read. | |
ReadPort class for handling read operations.
处理读取操作的ReadPort类。
Definition at line 17 of file read_port.hpp.
|
strong |
| Enumerator | |
|---|---|
| IDLE | No active waiter and no pending completion. 无等待者、无挂起完成。 |
| PENDING | Driver accepted the request; completion still owns progress. 请求已交给底层推进。 |
| CLEARING | ClearQueuedData() owns software dequeue progress. ClearQueuedData() 占有软件出队进度。 |
| BLOCK_CLAIMED | BLOCK wakeup already belongs to the current waiter. 当前 BLOCK 唤醒已被本次等待者认领。 |
| BLOCK_DETACHED | Timeout detached the waiter; completion must stay silent. 超时已分离等待者,完成侧不得再唤醒。 |
| EVENT | Data arrived before a waiter was armed; next caller must re-check queue. 数据先到,后续调用者要重查队列。 |
Definition at line 38 of file read_port.hpp.
| ReadPort::ReadPort | ( | size_t | buffer_size = 128 | ) |
Constructs a ReadPort with queue sizes.
以指定队列大小构造ReadPort。
| buffer_size | Size of the RX byte queue. 接收字节队列的容量。 |
Definition at line 7 of file read_port.cpp.
|
nodiscard |
清空当前已排队的 RX 字节。
Discards the RX bytes currently queued in software.
该接口只丢弃当前 queue_data_ 中已经排队的字节,不参与 backend teardown,也不会 失败完成挂起读请求。若存在正在推进的读请求,则返回 BUSY。 This API only discards the bytes already queued in queue_data_. It does not participate in backend teardown and does not fail-complete an in-flight read. Returns BUSY when a read request is currently in progress.
CLEARING 之后,普通读不会再消费当前软件队列快照;在快照 之后新到达的字节,可以留给后续读取或下次清队列。| in_isr | 是否在 ISR 上下文 / Whether running in ISR context |
OK 表示本次清队列成功完成;BUSY 表示当前有读请求占有该端口。 OK means the clear operation completed; BUSY means an active read still owns this port. Definition at line 257 of file read_port.cpp.
| size_t ReadPort::EmptySize | ( | ) |
获取队列的剩余可用空间。 Gets the remaining available space in the queue.
该函数返回 queue_data_ 中当前可用的空闲空间大小。 This function returns the size of the available empty space in queue_data_.
Definition at line 14 of file read_port.cpp.
| void ReadPort::FailAndClearAll | ( | ErrorCode | reason, |
| bool | in_isr ) |
失败完成并清空当前所有挂起读操作。
Fail-complete and clear all currently pending read operations.
| reason | 最终失败原因 / Final failure reason |
| in_isr | 是否在 ISR 上下文 / Whether running in ISR context |
Definition at line 308 of file read_port.cpp.
| void ReadPort::Finish | ( | bool | in_isr, |
| ErrorCode | ans, | ||
| ReadInfoBlock & | info ) |
完成已由队列路径认领的读取操作。 Completes a read operation already claimed by the queue path.
| in_isr | 指示是否在中断上下文中执行。 Indicates whether the operation is executed in an interrupt context. |
| ans | 错误码,用于指示操作的结果。 Error code indicating the result of the operation. |
| info | 需要更新状态的 ReadInfoBlock 引用。 Reference to the ReadInfoBlock whose status needs to be updated. |
Definition at line 34 of file read_port.cpp.
| void ReadPort::MarkAsRunning | ( | ReadInfoBlock & | info | ) |
标记读取操作为运行中。 Marks the read operation as running.
该函数用于将 info.op_ 标记为运行状态,以指示当前正在进行读取操作。 This function marks info.op_ as running to indicate an ongoing read operation.
| info | 需要更新状态的 ReadInfoBlock 引用。 Reference to the ReadInfoBlock whose status needs to be updated. |
Definition at line 52 of file read_port.cpp.
|
inlinevirtual |
RX 数据从软件队列成功出队后的通知。 Notification after bytes are popped from RX data queue.
| in_isr | 指示是否在中断上下文中执行。 Indicates whether the operation is executed in an interrupt context. |
Reimplemented in LibXR::USB::CDCUartReadPort.
Definition at line 171 of file read_port.hpp.
| ErrorCode ReadPort::operator() | ( | RawData | data, |
| ReadOperation & | op, | ||
| bool | in_isr = false ) |
读取操作符重载,用于执行读取操作。 Overloaded function call operator to perform a read operation.
该函数检查端口是否可读,并根据 data.size_ 和 op 的类型执行不同的操作。 This function checks if the port is readable and performs different actions based on data.size_ and the type of op.
| data | 包含要读取的数据。 Contains the data to be read. |
| op | 读取操作对象,包含操作类型和同步机制。 Read operation object containing the operation type and synchronization mechanism. |
| in_isr | 指示是否在中断上下文中执行。 Indicates whether the operation is executed in an interrupt context. |
Definition at line 54 of file read_port.cpp.
赋值运算符重载,用于设置读取函数。 Overloaded assignment operator to set the read function.
该函数允许使用 ReadFun 类型的函数对象赋值给 ReadPort,从而设置 read_fun_。 This function allows assigning a ReadFun function object to ReadPort, setting read_fun_.
| fun | 要分配的读取函数。 The read function to be assigned. |
Definition at line 28 of file read_port.cpp.
| void ReadPort::ProcessPendingReads | ( | bool | in_isr | ) |
Processes pending reads.
处理挂起的读取请求。
| in_isr | 指示是否在中断上下文中执行。 Indicates whether the operation is executed in an interrupt context. |
Definition at line 194 of file read_port.cpp.
| bool ReadPort::Readable | ( | ) |
| size_t ReadPort::Size | ( | ) |
获取当前队列的已使用大小。 Gets the currently used size of the queue.
该函数返回 queue_data_ 当前已占用的空间大小。 This function returns the size of the space currently used in queue_data_.
Definition at line 20 of file read_port.cpp.
| ErrorCode LibXR::ReadPort::block_result_ = ErrorCode::OK |
Final status for the current BLOCK read.
Definition at line 57 of file read_port.hpp.
| std::atomic<BusyState> LibXR::ReadPort::busy_ {BusyState::IDLE} |
Shared read-progress handoff state. 共享的读进度交接状态。
Definition at line 56 of file read_port.hpp.
| ReadInfoBlock LibXR::ReadPort::info_ {} |
| LockFreeQueue<uint8_t>* LibXR::ReadPort::queue_data_ = nullptr |
RX payload queue. 接收数据字节队列。
Definition at line 54 of file read_port.hpp.
| ReadFun LibXR::ReadPort::read_fun_ = nullptr |
Driver/backend read notification entry. 底层驱动或后端读取通知入口。
Definition at line 53 of file read_port.hpp.