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

FDCAN 通信抽象类,扩展支持 CAN FD 帧。 Abstract class for FDCAN communication with CAN FD frame support. More...

#include <can.hpp>

Inheritance diagram for LibXR::FDCAN:
[legend]
Collaboration diagram for LibXR::FDCAN:
[legend]

Data Structures

struct  Configuration
 FDCAN 配置参数,扩展 CAN::Configuration。 FDCAN configuration, extending CAN::Configuration. More...
 
struct  DataBitTiming
 数据相位位时序配置。Data phase bit timing configuration. More...
 
struct  FDMode
 FDCAN FD 模式配置。FDCAN FD mode configuration. More...
 
struct  FDPack
 CAN FD 帧数据结构。CAN FD frame structure. More...
 
struct  Filter
 FDCAN 订阅过滤器。FDCAN subscription filter. More...
 

Public Types

using CallbackFD = LibXR::Callback<const FDPack &>
 FD 帧回调类型。Callback type for FD frames.
 
enum class  FilterMode
 CAN 过滤器模式。CAN filter mode. More...
 
- 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.
 

Public Member Functions

 FDCAN ()=default
 构造函数。Constructor.
 
virtual ~FDCAN ()=default
 虚析构函数。Virtual destructor.
 
virtual ErrorCode SetConfig (const CAN::Configuration &cfg) override=0
 设置经典 CAN 配置。 Set classic CAN configuration.
 
virtual ErrorCode SetConfig (const FDCAN::Configuration &cfg)=0
 设置 FDCAN 配置。 Set FDCAN configuration.
 
void Register (CallbackFD cb, Type type, FilterMode mode=FilterMode::ID_RANGE, uint32_t start_id_mask=0, uint32_t end_id_mask=UINT32_MAX)
 注册 FDCAN FD 帧回调。 Register FDCAN FD frame callback.
 
virtual ErrorCode AddMessage (const FDPack &pack)=0
 添加 FD CAN 消息。Add FD CAN message.
 
virtual ErrorCode AddMessage (const ClassicPack &pack)=0
 添加经典 CAN 消息。Add classic CAN message.
 
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.
 
- Public Member Functions inherited from LibXR::CAN
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.
 

Protected Member Functions

void OnMessage (const FDPack &pack, bool in_isr)
 分发接收到的 FD CAN 帧。 Dispatch a received FD CAN frame.
 
void OnMessage (const ClassicPack &pack, bool in_isr)
 分发接收到的经典 CAN 帧。 Dispatch a received classic CAN frame.
 
- Protected Member Functions inherited from LibXR::CAN
void OnMessage (const ClassicPack &pack, bool in_isr)
 分发接收到的经典 CAN 帧。 Dispatch a received classic CAN frame.
 

Private Attributes

LockFreeList subscriber_list_fd_ [static_cast< uint8_t >(Type::REMOTE_STANDARD)]
 按帧类型划分的 FD 订阅者链表数组。FD subscriber lists per frame type.
 

Additional Inherited Members

- 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.
 
- Static Public Attributes inherited from LibXR::CAN
static constexpr uint32_t CAN_ERROR_ID_PREFIX = 0xFFFF0000u
 错误 ID 前缀 Error ID prefix.
 

Detailed Description

FDCAN 通信抽象类,扩展支持 CAN FD 帧。 Abstract class for FDCAN communication with CAN FD frame support.

Definition at line 246 of file can.hpp.

Member Typedef Documentation

◆ CallbackFD

FD 帧回调类型。Callback type for FD frames.

Definition at line 278 of file can.hpp.

Member Enumeration Documentation

◆ FilterMode

enum class LibXR::CAN::FilterMode : uint8_t
strong

CAN 过滤器模式。CAN filter mode.

Definition at line 186 of file can.hpp.

187 {
188 ID_MASK = 0,
190 ID_RANGE = 1
192 };

Member Function Documentation

◆ AddMessage() [1/2]

virtual ErrorCode LibXR::CAN::AddMessage ( const ClassicPack & pack)
virtual

添加经典 CAN 消息。Add classic CAN message.

Parameters
pack经典 CAN 帧。Classic CAN frame.
Returns
ErrorCode 操作结果。Error code.

Implements LibXR::CAN.

Reimplemented in LibXR::STM32CANFD.

◆ AddMessage() [2/2]

virtual ErrorCode LibXR::FDCAN::AddMessage ( const FDPack & pack)
pure virtual

添加 FD CAN 消息。Add FD CAN message.

Parameters
packFD CAN 帧。FD CAN frame.
Returns
ErrorCode 操作结果。Error code.

Implemented in LibXR::STM32CANFD.

◆ OnMessage() [1/2]

void CAN::OnMessage ( const ClassicPack & pack,
bool in_isr )
protected

分发接收到的经典 CAN 帧。 Dispatch a received classic CAN frame.

Parameters
pack接收到的帧。Received frame.
in_isr是否在中断上下文中。True if called in ISR context.

Definition at line 234 of file can.cpp.

19{
20 ASSERT(pack.type < Type::TYPE_NUM);
21 subscriber_list_[static_cast<uint8_t>(pack.type)].Foreach<Filter>(
22 [&](Filter &node)
23 {
24 switch (node.mode)
25 {
26 case FilterMode::ID_MASK:
27 if ((pack.id & node.start_id_mask) == node.end_id_mask)
28 {
29 node.cb.Run(in_isr, pack);
30 }
31 break;
32 case FilterMode::ID_RANGE:
33 if (pack.id >= node.start_id_mask && pack.id <= node.end_id_mask)
34 {
35 node.cb.Run(in_isr, pack);
36 }
37 break;
38 }
39
40 return ErrorCode::OK;
41 });
42}
@ TYPE_NUM
类型数量上界。Number of frame types.
LockFreeList subscriber_list_[static_cast< uint8_t >(Type::TYPE_NUM)]
按帧类型划分的订阅者链表数组。Subscriber lists per frame type.
Definition can.hpp:238

◆ OnMessage() [2/2]

void FDCAN::OnMessage ( const FDPack & pack,
bool in_isr )
protected

分发接收到的 FD CAN 帧。 Dispatch a received FD CAN frame.

Parameters
pack接收到的 FD 帧。Received FD frame.
in_isr是否在中断上下文中。True if called in ISR context.

Definition at line 54 of file can.cpp.

55{
56 ASSERT(pack.type < Type::TYPE_NUM);
57 subscriber_list_fd_[static_cast<uint8_t>(pack.type)].Foreach<Filter>(
58 [&](Filter &node)
59 {
60 switch (node.mode)
61 {
62 case FilterMode::ID_MASK:
63 if ((pack.id & node.start_id_mask) == node.end_id_mask)
64 {
65 node.cb.Run(in_isr, pack);
66 }
67 break;
68 case FilterMode::ID_RANGE:
69 if (pack.id >= node.start_id_mask && pack.id <= node.end_id_mask)
70 {
71 node.cb.Run(in_isr, pack);
72 }
73 break;
74 }
75
76 return ErrorCode::OK;
77 });
78}
LockFreeList subscriber_list_fd_[static_cast< uint8_t >(Type::REMOTE_STANDARD)]
按帧类型划分的 FD 订阅者链表数组。FD subscriber lists per frame type.
Definition can.hpp:381

◆ Register() [1/2]

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.

Parameters
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 217 of file can.cpp.

10{
11 ASSERT(type < Type::TYPE_NUM);
12
13 auto node = new (std::align_val_t(LIBXR_CACHE_LINE_SIZE))
14 LockFreeList::Node<Filter>(Filter{mode, start_id_mask, end_id_mask, type, cb});
15 subscriber_list_[static_cast<uint8_t>(type)].Add(*node);
16}
数据节点模板,继承自 BaseNode,用于存储具体数据类型。 Template data node that inherits from BaseNode to store specific data...

◆ Register() [2/2]

void FDCAN::Register ( CallbackFD cb,
Type type,
FilterMode mode = FilterMode::ID_RANGE,
uint32_t start_id_mask = 0,
uint32_t end_id_mask = UINT32_MAX )

注册 FDCAN FD 帧回调。 Register FDCAN FD frame callback.

Parameters
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 44 of file can.cpp.

46{
47 ASSERT(type < Type::REMOTE_STANDARD);
48
49 auto node = new (std::align_val_t(LIBXR_CACHE_LINE_SIZE))
50 LockFreeList::Node<Filter>(Filter{mode, start_id_mask, end_id_mask, type, cb});
51 subscriber_list_fd_[static_cast<uint8_t>(type)].Add(*node);
52}
@ REMOTE_STANDARD
标准远程帧。Standard remote frame.

◆ SetConfig() [1/2]

virtual ErrorCode LibXR::FDCAN::SetConfig ( const CAN::Configuration & cfg)
overridepure virtual

设置经典 CAN 配置。 Set classic CAN configuration.

作为 FDCAN 的兼容接口,具体实现可仅使用仲裁相位配置。

Parameters
cfgCAN 配置。CAN configuration.
Returns
ErrorCode 操作结果。Error code.

Implements LibXR::CAN.

Implemented in LibXR::STM32CANFD.

◆ SetConfig() [2/2]

virtual ErrorCode LibXR::FDCAN::SetConfig ( const FDCAN::Configuration & cfg)
pure virtual

设置 FDCAN 配置。 Set FDCAN configuration.

Parameters
cfgFDCAN 配置。FDCAN configuration.
Returns
ErrorCode 操作结果。Error code.

Implemented in LibXR::STM32CANFD.

Field Documentation

◆ subscriber_list_fd_

LockFreeList LibXR::FDCAN::subscriber_list_fd_[static_cast< uint8_t >(Type::REMOTE_STANDARD)]
private

按帧类型划分的 FD 订阅者链表数组。FD subscriber lists per frame type.

Definition at line 381 of file can.hpp.


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