libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::UartRxConfigGate Class Reference

Serialize UART RX hardware callbacks against configuration / 串行化 UART RX 硬件回调与配置事务 More...

#include <uart_rx_config_gate.hpp>

Public Member Functions

void RequestConfig ()
 
bool TryEnterRx ()
 
bool LeaveRx ()
 
bool TryEnterConfig ()
 
void LeaveConfig ()
 
bool ConfigRequested () const
 
 UartRxConfigGate (const UartRxConfigGate &)=delete
 
UartRxConfigGateoperator= (const UartRxConfigGate &)=delete
 

Private Attributes

std::atomic< uint32_t > state_ {0U}
 

Static Private Attributes

static constexpr uint32_t RX_ACTIVE = 1U << 0U
 
static constexpr uint32_t CONFIG_PENDING = 1U << 1U
 
static constexpr uint32_t CONFIG_ACTIVE = 1U << 2U
 

Detailed Description

Serialize UART RX hardware callbacks against configuration / 串行化 UART RX 硬件回调与配置事务

RX remains a single-producer data path. This gate only protects hardware state shared with configuration, such as DMA descriptors, positions, and stop/start operations. All transitions use one 32-bit atomic word so an RX exit cannot lose a concurrent configuration request. RX 仍是单生产者数据路径。本门仅保护与配置共享的 DMA 描述符、位置和启停等硬件状态。 所有转换共用一个 32 位原子字,避免 RX 退出时丢失并发配置请求。

Definition at line 22 of file uart_rx_config_gate.hpp.

Member Function Documentation

◆ ConfigRequested()

bool LibXR::UartRxConfigGate::ConfigRequested ( ) const
inlinenodiscard

Definition at line 74 of file uart_rx_config_gate.hpp.

75 {
76 return (state_.load(std::memory_order_acquire) & (CONFIG_PENDING | CONFIG_ACTIVE)) !=
77 0U;
78 }

◆ LeaveConfig()

void LibXR::UartRxConfigGate::LeaveConfig ( )
inline

Definition at line 59 of file uart_rx_config_gate.hpp.

60 {
61 uint32_t observed = state_.load(std::memory_order_relaxed);
62 while (true)
63 {
64 ASSERT((observed & CONFIG_ACTIVE) != 0U);
65 const uint32_t desired = observed & ~CONFIG_ACTIVE;
66 if (state_.compare_exchange_weak(observed, desired, std::memory_order_release,
67 std::memory_order_relaxed))
68 {
69 return;
70 }
71 }
72 }

◆ LeaveRx()

bool LibXR::UartRxConfigGate::LeaveRx ( )
inlinenodiscard
Returns
true when the caller must republish CONFIG after releasing RX ownership.

Definition at line 37 of file uart_rx_config_gate.hpp.

38 {
39 uint32_t observed = state_.load(std::memory_order_relaxed);
40 while (true)
41 {
42 ASSERT((observed & RX_ACTIVE) != 0U);
43 const uint32_t desired = observed & ~RX_ACTIVE;
44 if (state_.compare_exchange_weak(observed, desired, std::memory_order_release,
45 std::memory_order_relaxed))
46 {
47 return (observed & CONFIG_PENDING) != 0U;
48 }
49 }
50 }

◆ RequestConfig()

void LibXR::UartRxConfigGate::RequestConfig ( )
inline

Definition at line 25 of file uart_rx_config_gate.hpp.

25{ state_.fetch_or(CONFIG_PENDING, std::memory_order_release); }

◆ TryEnterConfig()

bool LibXR::UartRxConfigGate::TryEnterConfig ( )
inlinenodiscard

Definition at line 52 of file uart_rx_config_gate.hpp.

53 {
54 uint32_t expected = CONFIG_PENDING;
55 return state_.compare_exchange_strong(
56 expected, CONFIG_ACTIVE, std::memory_order_acquire, std::memory_order_relaxed);
57 }

◆ TryEnterRx()

bool LibXR::UartRxConfigGate::TryEnterRx ( )
inlinenodiscard

Definition at line 27 of file uart_rx_config_gate.hpp.

28 {
29 uint32_t expected = 0U;
30 return state_.compare_exchange_strong(expected, RX_ACTIVE, std::memory_order_acquire,
31 std::memory_order_relaxed);
32 }

Field Documentation

◆ CONFIG_ACTIVE

uint32_t LibXR::UartRxConfigGate::CONFIG_ACTIVE = 1U << 2U
staticconstexprprivate

Definition at line 87 of file uart_rx_config_gate.hpp.

◆ CONFIG_PENDING

uint32_t LibXR::UartRxConfigGate::CONFIG_PENDING = 1U << 1U
staticconstexprprivate

Definition at line 86 of file uart_rx_config_gate.hpp.

◆ RX_ACTIVE

uint32_t LibXR::UartRxConfigGate::RX_ACTIVE = 1U << 0U
staticconstexprprivate

Definition at line 85 of file uart_rx_config_gate.hpp.

◆ state_

std::atomic<uint32_t> LibXR::UartRxConfigGate::state_ {0U}
private

Definition at line 89 of file uart_rx_config_gate.hpp.

89{0U};

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