|
libxr
Embedded C++ framework for bare-metal, RTOS and Linux
|
CH32 CAN 驱动实现 / CH32 CAN driver implementation. More...
#include <ch32_can.hpp>
Public Member Functions | |
| CH32CAN (ch32_can_id_t id, uint32_t queue_size) | |
| 构造 CAN 驱动对象 / Construct CAN driver object | |
| ErrorCode | Init () |
| 初始化过滤器和中断路由 / Initialize filters and IRQ routing | |
| ErrorCode | SetConfig (const CAN::Configuration &cfg) override |
| 设置 CAN 配置 / Set CAN configuration | |
| uint32_t | GetClockFreq () const override |
| 获取 CAN 时钟频率 / Get CAN clock frequency | |
| ErrorCode | AddMessage (const ClassicPack &pack) override |
| 发送消息入队 / Enqueue TX message | |
| ErrorCode | GetErrorState (CAN::ErrorState &state) const override |
| 获取总线错误状态 / Get bus error state | |
| void | ProcessRxInterrupt () |
| 处理接收中断 / Handle RX interrupt | |
| void | ProcessTxInterrupt () |
| 处理发送中断 / Handle TX interrupt | |
| void | ProcessErrorInterrupt () |
| 处理错误中断 / Handle error interrupt | |
Public Member Functions inherited from LibXR::CAN | |
| 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. | |
Static Public Attributes | |
| static CH32CAN * | map [CH32_CAN_NUMBER] = {nullptr} |
| 中断分发表 / IRQ dispatch map | |
Static Public Attributes inherited from LibXR::CAN | |
| static LIBXR_PACKED_END constexpr uint32_t | CAN_ERROR_ID_PREFIX = 0xFFFF0000u |
| 错误 ID 前缀 / Error ID prefix. | |
Additional Inherited Members | |
Public Types inherited from LibXR::CAN | |
| 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. | |
Static Public Member Functions inherited from LibXR::CAN | |
| 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. | |
Protected Member Functions inherited from LibXR::CAN | |
| void | OnMessage (const ClassicPack &pack, bool in_isr) |
| 分发接收到的经典 CAN 帧。 Dispatch a received classic CAN frame. | |
CH32 CAN 驱动实现 / CH32 CAN driver implementation.
设计目标与 STM32 CAN 驱动行为保持一致。 Designed to keep behavior aligned with the STM32 CAN driver.
Definition at line 23 of file ch32_can.hpp.
|
explicit |
构造 CAN 驱动对象 / Construct CAN driver object
Definition at line 128 of file ch32_can.cpp.
|
overridevirtual |
发送消息入队 / Enqueue TX message
Implements LibXR::CAN.
Definition at line 571 of file ch32_can.cpp.
|
overridevirtual |
获取 CAN 时钟频率 / Get CAN clock frequency
Implements LibXR::CAN.
Definition at line 485 of file ch32_can.cpp.
|
overridevirtual |
获取总线错误状态 / Get bus error state
Reimplemented from LibXR::CAN.
Definition at line 758 of file ch32_can.cpp.
| ErrorCode CH32CAN::Init | ( | ) |
初始化过滤器和中断路由 / Initialize filters and IRQ routing
Definition at line 184 of file ch32_can.cpp.
| void CH32CAN::ProcessErrorInterrupt | ( | ) |
处理错误中断 / Handle error interrupt
Definition at line 663 of file ch32_can.cpp.
| void CH32CAN::ProcessRxInterrupt | ( | ) |
处理接收中断 / Handle RX interrupt
Definition at line 605 of file ch32_can.cpp.
| void CH32CAN::ProcessTxInterrupt | ( | ) |
处理发送中断 / Handle TX interrupt
Definition at line 587 of file ch32_can.cpp.
|
overridevirtual |
设置 CAN 配置 / Set CAN configuration
Implements LibXR::CAN.
Definition at line 364 of file ch32_can.cpp.
|
static |
中断分发表 / IRQ dispatch map
Definition at line 77 of file ch32_can.hpp.