|
libxr
1.0
Want to be the best embedded framework
|
CAN 通信抽象类,定义经典 CAN 帧与订阅接口。 Abstract class for CAN communication with classic CAN frames and subscription API. More...
#include <can.hpp>
Data Structures | |
| struct | BitTiming |
| CAN 位时序配置。Bit timing configuration for CAN. More... | |
| struct | ClassicPack |
| 经典 CAN 帧数据结构。Classic CAN frame structure. More... | |
| struct | Configuration |
| CAN 配置参数。CAN configuration parameters. More... | |
| struct | ErrorState |
| CAN 当前错误状态快照(来自硬件计数器/状态机)。 Snapshot of current CAN controller error state (from HW counters/state). More... | |
| struct | Filter |
| 经典 CAN 订阅过滤器。Classic CAN subscription filter. More... | |
| struct | Mode |
| CAN 工作模式。CAN operating mode. More... | |
Public Types | |
| enum class | Type : uint8_t { STANDARD = 0 , EXTENDED = 1 , REMOTE_STANDARD = 2 , REMOTE_EXTENDED = 3 , ERROR = 4 , TYPE_NUM = 5 } |
| CAN 消息类型。CAN frame type. More... | |
| enum class | ErrorID : uint32_t { CAN_ERROR_ID_GENERIC = CAN_ERROR_ID_PREFIX , CAN_ERROR_ID_BUS_OFF = CAN_ERROR_ID_PREFIX + 1 , CAN_ERROR_ID_ERROR_PASSIVE = CAN_ERROR_ID_PREFIX + 2 , CAN_ERROR_ID_ERROR_WARNING = CAN_ERROR_ID_PREFIX + 3 , CAN_ERROR_ID_PROTOCOL = CAN_ERROR_ID_PREFIX + 4 , CAN_ERROR_ID_ACK = CAN_ERROR_ID_PREFIX + 5 , CAN_ERROR_ID_STUFF = CAN_ERROR_ID_PREFIX + 6 , CAN_ERROR_ID_FORM = CAN_ERROR_ID_PREFIX + 7 , CAN_ERROR_ID_BIT0 = CAN_ERROR_ID_PREFIX + 8 , CAN_ERROR_ID_BIT1 = CAN_ERROR_ID_PREFIX + 9 , CAN_ERROR_ID_CRC = CAN_ERROR_ID_PREFIX + 10 , CAN_ERROR_ID_OTHER = CAN_ERROR_ID_PREFIX + 11 } |
| ClassicPack::type == Type::ERROR 时使用的虚拟 ID。 Virtual IDs used when ClassicPack::type == Type::ERROR. More... | |
| enum class | FilterMode : uint8_t { ID_MASK = 0 , ID_RANGE = 1 } |
| CAN 过滤器模式。CAN filter mode. More... | |
| using | Callback = LibXR::Callback<const ClassicPack &> |
| 回调类型。Callback type. | |
Public Member Functions | |
| virtual ErrorCode | SetConfig (const CAN::Configuration &cfg)=0 |
| 设置 CAN 配置。Set CAN configuration. | |
| virtual uint32_t | GetClockFreq () const =0 |
| 获取 CAN 外设时钟频率(Hz)。 Get CAN peripheral clock frequency in Hz. | |
| virtual ErrorCode | GetErrorState (ErrorState &state) const |
| 查询当前错误状态(快照)。 Query current CAN controller error state (snapshot). | |
| CAN ()=default | |
| 构造函数。Constructor. | |
| virtual | ~CAN ()=default |
| 虚析构函数。Virtual destructor. | |
| void | Register (Callback cb, Type type, FilterMode mode=FilterMode::ID_RANGE, uint32_t start_id_mask=0, uint32_t end_id_mask=UINT32_MAX) |
| 注册经典 CAN 消息回调。 Register classic CAN message callback. | |
| virtual ErrorCode | AddMessage (const ClassicPack &pack)=0 |
| 添加经典 CAN 消息。Add classic CAN message. | |
Static Public Member Functions | |
| static constexpr uint32_t | FromErrorID (ErrorID e) noexcept |
| 将 ErrorID 转为 id。Convert ErrorID to ClassicPack::id. | |
| static constexpr bool | IsErrorId (uint32_t id) noexcept |
| 判断 id 是否处于错误 ID 空间。Check if id is in error ID space. | |
| static constexpr ErrorID | ToErrorID (uint32_t id) noexcept |
| 将 id 解释为 ErrorID。Interpret id as ErrorID. | |
Static Public Attributes | |
| static constexpr uint32_t | CAN_ERROR_ID_PREFIX = 0xFFFF0000u |
| 错误 ID 前缀 Error ID prefix. | |
Protected Member Functions | |
| void | OnMessage (const ClassicPack &pack, bool in_isr) |
| 分发接收到的经典 CAN 帧。 Dispatch a received classic CAN frame. | |
Private Attributes | |
| LockFreeList | subscriber_list_ [static_cast< uint8_t >(Type::TYPE_NUM)] |
| 按帧类型划分的订阅者链表数组。Subscriber lists per frame type. | |
CAN 通信抽象类,定义经典 CAN 帧与订阅接口。 Abstract class for CAN communication with classic CAN frames and subscription API.
| using LibXR::CAN::Callback = LibXR::Callback<const ClassicPack &> |
|
strong |
ClassicPack::type == Type::ERROR 时使用的虚拟 ID。 Virtual IDs used when ClassicPack::type == Type::ERROR.
Definition at line 145 of file can.hpp.
|
strong |
CAN 过滤器模式。CAN filter mode.
|
strong |
CAN 消息类型。CAN frame type.
Definition at line 22 of file can.hpp.
|
pure virtual |
添加经典 CAN 消息。Add classic CAN message.
Implemented in LibXR::FDCAN, LibXR::STM32CAN, and LibXR::STM32CANFD.
|
inlinestaticconstexprnoexcept |
将 ErrorID 转为 id。Convert ErrorID to ClassicPack::id.
Definition at line 162 of file can.hpp.
|
pure virtual |
获取 CAN 外设时钟频率(Hz)。 Get CAN peripheral clock frequency in Hz.
Implemented in LibXR::STM32CAN, and LibXR::STM32CANFD.
|
inlinevirtual |
查询当前错误状态(快照)。 Query current CAN controller error state (snapshot).
默认实现返回 ErrorCode::NOT_SUPPORT;具体实现(如 bxCAN/FDCAN)可重载, 从硬件寄存器读取 TEC/REC 及状态位,并填充 ErrorState。
| state | 输出参数,用于返回当前错误状态。 |
Reimplemented in LibXR::STM32CAN, and LibXR::STM32CANFD.
Definition at line 107 of file can.hpp.
|
inlinestaticconstexprnoexcept |
判断 id 是否处于错误 ID 空间。Check if id is in error ID space.
|
protected |
分发接收到的经典 CAN 帧。 Dispatch a received classic CAN frame.
| pack | 接收到的帧。Received frame. |
| in_isr | 是否在中断上下文中。True if called in ISR context. |
Definition at line 18 of file can.cpp.
| void CAN::Register | ( | Callback | cb, |
| Type | type, | ||
| FilterMode | mode = FilterMode::ID_RANGE, | ||
| uint32_t | start_id_mask = 0, | ||
| uint32_t | end_id_mask = UINT32_MAX ) |
注册经典 CAN 消息回调。 Register classic CAN message callback.
| cb | 回调函数。Callback function. |
| type | 帧类型。Frame type. |
| mode | 过滤器模式。Filter mode. |
| start_id_mask | 起始 ID 或掩码。Start ID or mask. |
| end_id_mask | 结束 ID 或匹配值。End ID or match value. |
Definition at line 8 of file can.cpp.
|
pure virtual |
设置 CAN 配置。Set CAN configuration.
| cfg | 配置参数。Configuration parameters. |
Implemented in LibXR::FDCAN, LibXR::STM32CAN, and LibXR::STM32CANFD.
|
inlinestaticconstexprnoexcept |
将 id 解释为 ErrorID。Interpret id as ErrorID.
Definition at line 174 of file can.hpp.
|
staticconstexpr |
|
private |