libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::CH32CAN Class Reference

CH32 CAN 驱动实现 / CH32 CAN driver implementation. More...

#include <ch32_can.hpp>

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

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.
 

Detailed Description

CH32 CAN 驱动实现 / CH32 CAN driver implementation.

设计目标与 STM32 CAN 驱动行为保持一致。 Designed to keep behavior aligned with the STM32 CAN driver.

Note
基于 WCH StdPeriph CAN 接口实现 / Implemented on top of WCH StdPeriph CAN APIs.

Definition at line 23 of file ch32_can.hpp.

Constructor & Destructor Documentation

◆ CH32CAN()

CH32CAN::CH32CAN ( ch32_can_id_t id,
uint32_t queue_size )
explicit

构造 CAN 驱动对象 / Construct CAN driver object

Parameters
idCAN 实例编号 / CAN instance ID
queue_size发送队列大小 / TX queue size (ClassicPack entries)
Precondition
queue_size 必须大于 1 / queue_size must be greater than 1.

Definition at line 128 of file ch32_can.cpp.

129 : CAN(), instance_(CH32_CAN_GetInstanceID(id)), id_(id), tx_queue_(queue_size)
130{
131 if constexpr (LibXR::CH32UsbCanShared::usb_can_share_enabled())
132 {
133 // 端点地址在 Stop 后仍有效,不能在分配 PMA 后扩大 CAN 过滤器占用。
134 // Endpoint addresses survive Stop; reserve CAN filters before allocating PMA.
135 ASSERT(!LibXR::CH32UsbCanShared::usb_pma_configured.load(std::memory_order_acquire));
136 }
137
138#if LIBXR_CH32_HAS_CAN2
139 if (id == CH32_CAN1)
140 {
141 filter_bank_ = 0;
142 fifo_ = CAN_FilterFIFO0; // 0
143 }
144 else
145 {
146 filter_bank_ = 14;
147 fifo_ = CAN_FilterFIFO1; // 1
148 }
149#else
150 filter_bank_ = 0;
151 fifo_ = CAN_FilterFIFO0; // 0
152#endif
153
154 ASSERT(id_ < CH32_CAN_NUMBER);
155 ASSERT(instance_ != nullptr);
156
157 map[id_] = this;
158
159 // 打开外设时钟。
160 // Enable the peripheral clock.
161 RCC_APB1PeriphClockCmd(CH32_CAN_RCC_PERIPH_MAP[id_], ENABLE);
162#if LIBXR_CH32_HAS_CAN2
163 if (id_ == CH32_CAN2)
164 {
165 // CAN2 的共享过滤器寄存器位于 CAN1,不能依赖应用先创建 CAN1 对象。
166 // CAN2 filter registers belong to CAN1, even in a CAN2-only application.
167 RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
168 }
169#endif
170
171 // 在调用 SetConfig() 之前,保持 CAN 处于初始化模式。
172 // Keep CAN in initialization mode until SetConfig() is called.
173 (void)CAN_OperatingModeRequest(instance_, CAN_OperatingMode_Initialization);
174
175#if LIBXR_CH32_HAS_CAN2
176 // 在双 CAN 变体上,配置默认的共享过滤器分界点。
177 // On dual-CAN variants, configure the default shared filter split point.
178 CAN_SlaveStartBank(CH32_CAN_DEFAULT_SLAVE_START_BANK);
179#endif
180
181 (void)Init();
182}
CAN()=default
构造函数 / Constructor.
ErrorCode Init()
初始化过滤器和中断路由 / Initialize filters and IRQ routing
Definition ch32_can.cpp:184
static CH32CAN * map[CH32_CAN_NUMBER]
中断分发表 / IRQ dispatch map
Definition ch32_can.hpp:77

Member Function Documentation

◆ AddMessage()

ErrorCode CH32CAN::AddMessage ( const ClassicPack & pack)
overridevirtual

发送消息入队 / Enqueue TX message

Implements LibXR::CAN.

Definition at line 571 of file ch32_can.cpp.

572{
573 if (pack.type == Type::ERROR)
574 {
575 return ErrorCode::ARG_ERR;
576 }
577
578 if (tx_queue_.Put(pack) != ErrorCode::OK)
579 {
580 return ErrorCode::FULL;
581 }
582
583 TxService();
584 return ErrorCode::OK;
585}
@ ERROR
错误帧(虚拟事件) / Error frame (virtual event).
ErrorCode Put(const T &value)
便捷入队:Acquire + 拷贝 + Publish / Convenient enqueue: Acquire + copy + Publish.
@ FULL
已满 / Full
@ OK
操作成功 / Operation successful
@ ARG_ERR
参数错误 / Argument error

◆ GetClockFreq()

uint32_t CH32CAN::GetClockFreq ( ) const
overridevirtual

获取 CAN 时钟频率 / Get CAN clock frequency

Implements LibXR::CAN.

Definition at line 485 of file ch32_can.cpp.

486{
487 RCC_ClocksTypeDef clocks{};
488 RCC_GetClocksFreq(&clocks);
489 return clocks.PCLK1_Frequency;
490}

◆ GetErrorState()

ErrorCode CH32CAN::GetErrorState ( CAN::ErrorState & state) const
overridevirtual

获取总线错误状态 / Get bus error state

Reimplemented from LibXR::CAN.

Definition at line 758 of file ch32_can.cpp.

759{
760 if (instance_ == nullptr)
761 {
762 return ErrorCode::ARG_ERR;
763 }
764
765 state.rx_error_counter = CAN_GetReceiveErrorCounter(instance_);
766 state.tx_error_counter = CAN_GetLSBTransmitErrorCounter(instance_);
767
768 state.bus_off = (CAN_GetFlagStatus(instance_, CAN_FLAG_BOF) != RESET);
769 state.error_passive = (CAN_GetFlagStatus(instance_, CAN_FLAG_EPV) != RESET);
770 state.error_warning = (CAN_GetFlagStatus(instance_, CAN_FLAG_EWG) != RESET);
771
772 return ErrorCode::OK;
773}
bool bus_off
是否处于 BUS-OFF / True if controller is bus-off.
Definition can.hpp:92
bool error_passive
是否处于 Error Passive / True if error-passive.
Definition can.hpp:93
uint8_t tx_error_counter
发送错误计数 TEC / Transmit error counter (TEC).
Definition can.hpp:89
bool error_warning
是否处于 Error Warning / True if error-warning.
Definition can.hpp:94
uint8_t rx_error_counter
接收错误计数 REC / Receive error counter (REC).
Definition can.hpp:90

◆ Init()

ErrorCode CH32CAN::Init ( )

初始化过滤器和中断路由 / Initialize filters and IRQ routing

Definition at line 184 of file ch32_can.cpp.

185{
186 if (instance_ == nullptr)
187 {
188 return ErrorCode::ARG_ERR;
189 }
190
191 // 默认全接收过滤器(ID-mask 模式,全 0)。
192 // Default accept-all filter (ID-mask mode, all zeros).
193 CAN_FilterInitTypeDef f = {};
194 f.CAN_FilterIdHigh = 0u;
195 f.CAN_FilterIdLow = 0u;
196 f.CAN_FilterMaskIdHigh = 0u;
197 f.CAN_FilterMaskIdLow = 0u;
198 f.CAN_FilterFIFOAssignment = fifo_;
199 f.CAN_FilterNumber = filter_bank_;
200 f.CAN_FilterMode = CAN_FilterMode_IdMask;
201 f.CAN_FilterScale = CAN_FilterScale_32bit;
202 f.CAN_FilterActivation = ENABLE;
203
204 CAN_FilterInit(&f);
205
206 // 在放行中断源之前发布回调,防止已有 pending 中断进入空分发器。
207 // Publish callbacks before enabling an interrupt source with pending events.
208 if constexpr (LibXR::CH32UsbCanShared::usb_can_irq_share_enabled())
209 {
210#if defined(CAN1) && defined(RCC_APB1Periph_USB)
211 if (id_ == CH32_CAN1)
212 {
213 LibXR::CH32UsbCanShared::register_can1_rx0(&can1_rx0_thunk);
214 LibXR::CH32UsbCanShared::register_can1_tx(&can1_tx_thunk);
215 LibXR::CH32UsbCanShared::can1_inited.store(true, std::memory_order_release);
216 }
217#if LIBXR_CH32_HAS_CAN2
218 else if (id_ == CH32_CAN2)
219 {
220 LibXR::CH32UsbCanShared::can2_inited.store(true, std::memory_order_release);
221 }
222#endif
223#endif
224 }
225
226 EnableIRQs();
227 ch32_can_enable_nvic(id_, fifo_);
228
229 return ErrorCode::OK;
230}

◆ ProcessErrorInterrupt()

void CH32CAN::ProcessErrorInterrupt ( )

处理错误中断 / Handle error interrupt

Definition at line 663 of file ch32_can.cpp.

664{
665 if (instance_ == nullptr)
666 {
667 return;
668 }
669
670 // 在清 pending 位前先快照错误标志和 LEC。
671 // Snapshot error flags and LEC before clearing pending bits.
672 const bool BOF = (CAN_GetFlagStatus(instance_, CAN_FLAG_BOF) != RESET);
673 const bool EPV = (CAN_GetFlagStatus(instance_, CAN_FLAG_EPV) != RESET);
674 const bool EWG = (CAN_GetFlagStatus(instance_, CAN_FLAG_EWG) != RESET);
675 const uint8_t LEC = CAN_GetLastErrorCode(instance_);
676
677#ifdef CAN_IT_LEC
678 if (CAN_GetITStatus(instance_, CAN_IT_LEC) != RESET)
679 {
680 CAN_ClearITPendingBit(instance_, CAN_IT_LEC);
681 }
682#endif
683#ifdef CAN_IT_ERR
684 if (CAN_GetITStatus(instance_, CAN_IT_ERR) != RESET)
685 {
686 CAN_ClearITPendingBit(instance_, CAN_IT_ERR);
687 }
688#endif
689#ifdef CAN_IT_BOF
690 if (CAN_GetITStatus(instance_, CAN_IT_BOF) != RESET)
691 {
692 CAN_ClearITPendingBit(instance_, CAN_IT_BOF);
693 }
694#endif
695#ifdef CAN_IT_EPV
696 if (CAN_GetITStatus(instance_, CAN_IT_EPV) != RESET)
697 {
698 CAN_ClearITPendingBit(instance_, CAN_IT_EPV);
699 }
700#endif
701#ifdef CAN_IT_EWG
702 if (CAN_GetITStatus(instance_, CAN_IT_EWG) != RESET)
703 {
704 CAN_ClearITPendingBit(instance_, CAN_IT_EWG);
705 }
706#endif
707
708 ClassicPack p{};
709 p.type = Type::ERROR;
710 p.dlc = 0u;
711
712 CAN::ErrorID eid = CAN::ErrorID::CAN_ERROR_ID_GENERIC;
713
714 if (BOF)
715 {
716 eid = CAN::ErrorID::CAN_ERROR_ID_BUS_OFF;
717 }
718 else if (EPV)
719 {
720 eid = CAN::ErrorID::CAN_ERROR_ID_ERROR_PASSIVE;
721 }
722 else if (EWG)
723 {
724 eid = CAN::ErrorID::CAN_ERROR_ID_ERROR_WARNING;
725 }
726 else
727 {
728 switch (LEC)
729 {
730 case CAN_ErrorCode_StuffErr:
731 eid = CAN::ErrorID::CAN_ERROR_ID_STUFF;
732 break;
733 case CAN_ErrorCode_FormErr:
734 eid = CAN::ErrorID::CAN_ERROR_ID_FORM;
735 break;
736 case CAN_ErrorCode_ACKErr:
737 eid = CAN::ErrorID::CAN_ERROR_ID_ACK;
738 break;
739 case CAN_ErrorCode_BitRecessiveErr:
740 eid = CAN::ErrorID::CAN_ERROR_ID_BIT1;
741 break;
742 case CAN_ErrorCode_BitDominantErr:
743 eid = CAN::ErrorID::CAN_ERROR_ID_BIT0;
744 break;
745 case CAN_ErrorCode_CRCErr:
746 eid = CAN::ErrorID::CAN_ERROR_ID_CRC;
747 break;
748 default:
749 eid = CAN::ErrorID::CAN_ERROR_ID_OTHER;
750 break;
751 }
752 }
753
754 p.id = static_cast<uint32_t>(eid);
755 OnMessage(p, true);
756}
void OnMessage(const ClassicPack &pack, bool in_isr)
分发接收到的经典 CAN 帧。 Dispatch a received classic CAN frame.
Definition can.cpp:18
ErrorID
ClassicPack::type == Type::ERROR 时使用的虚拟 ID。 Virtual IDs used when ClassicPack::type == Type::ERROR.
Definition can.hpp:147

◆ ProcessRxInterrupt()

void CH32CAN::ProcessRxInterrupt ( )

处理接收中断 / Handle RX interrupt

Definition at line 605 of file ch32_can.cpp.

606{
607 if (instance_ == nullptr)
608 {
609 return;
610 }
611
612 // 先排空 RX FIFO,再确认 RX 挂起标志。
613 // Drain the RX FIFO first, then acknowledge RX pending flags.
614 while (CAN_MessagePending(instance_, fifo_) != 0u)
615 {
616 CAN_Receive(instance_, fifo_, &rx_msg_);
617
618 ClassicPack p{};
619 if (rx_msg_.IDE == CAN_ID_STD)
620 {
621 p.id = rx_msg_.StdId;
622 p.type = Type::STANDARD;
623 }
624 else
625 {
626 p.id = rx_msg_.ExtId;
627 p.type = Type::EXTENDED;
628 }
629
630 if (rx_msg_.RTR == CAN_RTR_REMOTE)
631 {
633 }
634
635 p.dlc = (rx_msg_.DLC <= 8u) ? rx_msg_.DLC : 8u;
636 std::memcpy(p.data, rx_msg_.Data, 8);
637
638 OnMessage(p, true);
639 }
640
641 // 确认 RX 挂起标志。
642 // Acknowledge RX pending flags.
643#ifdef CAN_IT_FMP0
644 if (fifo_ == 0u)
645 {
646 if (CAN_GetITStatus(instance_, CAN_IT_FMP0) != RESET)
647 {
648 CAN_ClearITPendingBit(instance_, CAN_IT_FMP0);
649 }
650 }
651#endif
652#ifdef CAN_IT_FMP1
653 if (fifo_ == 1u)
654 {
655 if (CAN_GetITStatus(instance_, CAN_IT_FMP1) != RESET)
656 {
657 CAN_ClearITPendingBit(instance_, CAN_IT_FMP1);
658 }
659 }
660#endif
661}
Type
CAN 消息类型 / CAN frame type.
Definition can.hpp:23
@ EXTENDED
扩展数据帧(29-bit ID) / Extended data frame (29-bit ID).
@ REMOTE_EXTENDED
扩展远程帧 / Extended remote frame.
@ STANDARD
标准数据帧(11-bit ID) / Standard data frame (11-bit ID).
@ REMOTE_STANDARD
标准远程帧 / Standard remote frame.

◆ ProcessTxInterrupt()

void CH32CAN::ProcessTxInterrupt ( )

处理发送中断 / Handle TX interrupt

Definition at line 587 of file ch32_can.cpp.

588{
589#ifdef CAN_IT_TME
590 if (instance_ == nullptr)
591 {
592 return;
593 }
594
595 if (CAN_GetITStatus(instance_, CAN_IT_TME) != RESET)
596 {
597 CAN_ClearITPendingBit(instance_, CAN_IT_TME);
598 TxService();
599 }
600#else
601 TxService();
602#endif
603}

◆ SetConfig()

ErrorCode CH32CAN::SetConfig ( const CAN::Configuration & cfg)
overridevirtual

设置 CAN 配置 / Set CAN configuration

Implements LibXR::CAN.

Definition at line 364 of file ch32_can.cpp.

365{
366 if (instance_ == nullptr)
367 {
368 return ErrorCode::ARG_ERR;
369 }
370
371 // 保证所有返回路径都会恢复 IRQ 状态。
372 // Ensure IRQ state restoration on all return paths.
373 struct IrqGuard
374 {
375 CH32CAN* self;
376 explicit IrqGuard(CH32CAN* s) : self(s) { self->DisableIRQs(); }
377 ~IrqGuard() { self->EnableIRQs(); }
378 } guard(this);
379
381 bool entered_init = false;
382
383 // 构造实际使用的时序参数;为 0 的字段复用缓存配置。
384 // Build effective timing values; zero fields reuse cached configuration.
385 CAN::Configuration cfg = cfg_in;
386
387 if (!fill_keep_zero_from_cache(cfg.bit_timing, cfg_cache_.bit_timing))
388 {
389 return ErrorCode::ARG_ERR;
390 }
391
392 // 校验 bxCAN 时序约束。
393 // Validate bxCAN timing constraints.
394 const CAN::BitTiming& bt = cfg.bit_timing;
395
396 // BRP: 1..1024.
397 if (bt.brp < 1u || bt.brp > 1024u)
398 {
399 return ErrorCode::ARG_ERR;
400 }
401
402 // BS1 = PROP_SEG + PHASE_SEG1: 1..16.
403 const uint32_t BS1 = bt.prop_seg + bt.phase_seg1;
404 if (BS1 < 1u || BS1 > 16u)
405 {
406 return ErrorCode::ARG_ERR;
407 }
408
409 // BS2: 1..8.
410 if (bt.phase_seg2 < 1u || bt.phase_seg2 > 8u)
411 {
412 return ErrorCode::ARG_ERR;
413 }
414
415 // SJW: 1..4 and SJW <= BS2.
416 if (bt.sjw < 1u || bt.sjw > 4u || bt.sjw > bt.phase_seg2)
417 {
418 return ErrorCode::ARG_ERR;
419 }
420
421 // 进入初始化模式。
422 // Enter initialization mode.
423 if (CAN_OperatingModeRequest(instance_, CAN_OperatingMode_Initialization) ==
424 CAN_ModeStatus_Failed)
425 {
426 return ErrorCode::FAILED;
427 }
428 entered_init = true;
429
430 // 填充并应用初始化结构体。
431 // Apply the initialization structure.
432 CAN_InitTypeDef init;
433 std::memset(&init, 0, sizeof(init));
434 CAN_StructInit(&init);
435
436 init.CAN_Prescaler = static_cast<uint16_t>(bt.brp);
437 init.CAN_Mode = ch32_can_mode_macro(cfg.mode);
438
439 init.CAN_SJW = static_cast<uint8_t>(bt.sjw - 1u);
440 init.CAN_BS1 = static_cast<uint8_t>(BS1 - 1u);
441 init.CAN_BS2 = static_cast<uint8_t>(bt.phase_seg2 - 1u);
442
443 // 工作模式映射。
444 // Mode mapping.
445 init.CAN_NART = cfg.mode.one_shot ? ENABLE : DISABLE;
446
447 // 控制器默认选项。
448 // Default controller options.
449 init.CAN_TTCM = DISABLE;
450 init.CAN_ABOM = ENABLE; // auto bus-off management
451 init.CAN_AWUM = DISABLE; // auto wake-up
452 init.CAN_RFLM = DISABLE; // FIFO not locked
453 init.CAN_TXFP = ENABLE; // prioritize by TX request order
454
455 if (CAN_Init(instance_, &init) != CAN_InitStatus_Success)
456 {
458 }
459 else
460 {
461 if (CAN_OperatingModeRequest(instance_, CAN_OperatingMode_Normal) ==
462 CAN_ModeStatus_Failed)
463 {
465 }
466 else
467 {
468 // 仅在配置成功后更新缓存。
469 // Update the cache only on successful configuration.
470 cfg_cache_ = cfg;
471 ec = ErrorCode::OK;
472 }
473 }
474
475 // 如果进入 init 模式后配置失败,则请求回到 normal 模式。
476 // If configuration fails after entering init mode, request normal mode.
477 if (ec != ErrorCode::OK && entered_init)
478 {
479 (void)CAN_OperatingModeRequest(instance_, CAN_OperatingMode_Normal);
480 }
481
482 return ec;
483}
CH32 CAN 驱动实现 / CH32 CAN driver implementation.
Definition ch32_can.hpp:24
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
@ FAILED
操作失败 / Operation failed
CAN 位时序配置 / Bit timing configuration for CAN.
Definition can.hpp:37
uint32_t brp
预分频 / Baud rate prescaler.
Definition can.hpp:38
uint32_t sjw
同步跳宽 / Synchronization jump width.
Definition can.hpp:42
uint32_t phase_seg2
相位段 2 / Phase segment 2.
Definition can.hpp:41
uint32_t prop_seg
传播段 / Propagation segment.
Definition can.hpp:39
uint32_t phase_seg1
相位段 1 / Phase segment 1.
Definition can.hpp:40
CAN 配置参数 / CAN configuration parameters.
Definition can.hpp:62
BitTiming bit_timing
位时序配置 / Bit timing configuration.
Definition can.hpp:65
Mode mode
工作模式 / Operating mode.
Definition can.hpp:66
bool one_shot
单次发送模式 / One-shot transmission.
Definition can.hpp:54

Member Data Documentation

◆ map

CH32CAN * CH32CAN::map = {nullptr}
static

中断分发表 / IRQ dispatch map

Definition at line 77 of file ch32_can.hpp.


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