1#include "stm32_canfd.hpp"
3#ifdef HAL_FDCAN_MODULE_ENABLED
7STM32CANFD* STM32CANFD::map[STM32_FDCAN_NUMBER] = {
nullptr};
15stm32_fdcan_id_t STM32_FDCAN_GetID(FDCAN_GlobalTypeDef* addr)
19 return stm32_fdcan_id_t::STM32_FDCAN_ID_ERROR;
22 else if (addr == FDCAN1)
24 return stm32_fdcan_id_t::STM32_FDCAN1;
28 else if (addr == FDCAN2)
30 return stm32_fdcan_id_t::STM32_FDCAN2;
34 else if (addr == FDCAN3)
36 return stm32_fdcan_id_t::STM32_FDCAN3;
41 return stm32_fdcan_id_t::STM32_FDCAN_ID_ERROR;
45static inline uint32_t BytesToDlc(uint32_t n)
53 return FDCAN_DLC_BYTES_12;
57 return FDCAN_DLC_BYTES_16;
61 return FDCAN_DLC_BYTES_20;
65 return FDCAN_DLC_BYTES_24;
69 return FDCAN_DLC_BYTES_32;
73 return FDCAN_DLC_BYTES_48;
75 return FDCAN_DLC_BYTES_64;
78static inline uint32_t DlcToBytes(uint32_t dlc)
80 if (dlc <= FDCAN_DLC_BYTES_8)
84 else if (dlc == FDCAN_DLC_BYTES_12)
88 else if (dlc == FDCAN_DLC_BYTES_16)
92 else if (dlc == FDCAN_DLC_BYTES_20)
96 else if (dlc == FDCAN_DLC_BYTES_24)
100 else if (dlc == FDCAN_DLC_BYTES_32)
104 else if (dlc == FDCAN_DLC_BYTES_48)
114inline void STM32CANFD::BuildTxHeader(
const ClassicPack& p, FDCAN_TxHeaderTypeDef& h)
121 h.IdType = is_ext ? FDCAN_EXTENDED_ID : FDCAN_STANDARD_ID;
122 h.TxFrameType = is_rtr ? FDCAN_REMOTE_FRAME : FDCAN_DATA_FRAME;
124 uint32_t bytes = (p.dlc <= 8u) ? p.dlc : 8u;
125 h.DataLength = BytesToDlc(bytes);
127 h.ErrorStateIndicator = FDCAN_ESI_PASSIVE;
128 h.BitRateSwitch = FDCAN_BRS_OFF;
129 h.FDFormat = FDCAN_CLASSIC_CAN;
131 h.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
132 h.MessageMarker = 0x01;
135inline void STM32CANFD::BuildTxHeader(
const FDPack& p, FDCAN_TxHeaderTypeDef& h)
142 h.IdType = FDCAN_STANDARD_ID;
143 h.TxFrameType = FDCAN_DATA_FRAME;
147 h.IdType = FDCAN_EXTENDED_ID;
148 h.TxFrameType = FDCAN_DATA_FRAME;
156 ASSERT(p.len <= 64u);
157 h.DataLength = BytesToDlc(p.len);
159 h.ErrorStateIndicator = FDCAN_ESI_PASSIVE;
160 h.BitRateSwitch = FDCAN_BRS_ON;
161 h.FDFormat = FDCAN_FD_CAN;
163 h.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
164 h.MessageMarker = 0x00;
170 id_(STM32_FDCAN_GetID(hcan->Instance)),
171 tx_pool_(queue_size),
172 tx_pool_fd_(queue_size)
174 CheckMessageRAMOffset(hcan);
181 FDCAN_FilterTypeDef can_filter = {};
182 can_filter.IdType = FDCAN_STANDARD_ID;
183 can_filter.FilterType = FDCAN_FILTER_MASK;
184 can_filter.FilterID1 = 0x0000;
185 can_filter.FilterID2 = 0x0000;
186 can_filter.FilterIndex = 0;
189 if (id_ == STM32_FDCAN1)
191 can_filter.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
193 else if (id_ == STM32_FDCAN2)
195 can_filter.FilterConfig = FDCAN_FILTER_TO_RXFIFO1;
197 else if (id_ == STM32_FDCAN3)
199 can_filter.FilterConfig = FDCAN_FILTER_TO_RXFIFO1;
203 if (id_ == STM32_FDCAN1)
205 can_filter.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
207 else if (id_ == STM32_FDCAN2)
209 can_filter.FilterConfig = FDCAN_FILTER_TO_RXFIFO1;
212 can_filter.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
216 if (HAL_FDCAN_ConfigFilter(hcan_, &can_filter) != HAL_OK)
218 return ErrorCode::FAILED;
221 can_filter.IdType = FDCAN_EXTENDED_ID;
223 if (HAL_FDCAN_ConfigFilter(hcan_, &can_filter) != HAL_OK)
225 return ErrorCode::FAILED;
228 if (HAL_FDCAN_Start(hcan_) != HAL_OK)
230 return ErrorCode::FAILED;
233 if (can_filter.FilterConfig == FDCAN_FILTER_TO_RXFIFO0)
235 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);
239 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_RX_FIFO1_NEW_MESSAGE, 0);
242 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_ERROR_PASSIVE, 0);
243 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_ERROR_WARNING, 0);
244 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_BUS_OFF, 0);
245 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_TX_FIFO_EMPTY, 0);
246 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_TX_COMPLETE, 0xFFFFFFFF);
248 return ErrorCode::OK;
255 return ErrorCode::ARG_ERR;
259 if (tx_pool_.
Put(pack) != ErrorCode::OK)
262 if (tx_pool_.
Put(pack) != ErrorCode::OK)
264 return ErrorCode::FULL;
269 return ErrorCode::OK;
279 fd_cfg.mode = cfg.
mode;
286 if (hcan_ ==
nullptr || hcan_->Instance ==
nullptr)
289 return ErrorCode::ARG_ERR;
292 FDCAN_GlobalTypeDef* can = hcan_->Instance;
295 uint32_t it_mask = 0u;
297#ifdef FDCAN_IT_RX_FIFO0_NEW_MESSAGE
298 it_mask |= FDCAN_IT_RX_FIFO0_NEW_MESSAGE;
300#ifdef FDCAN_IT_RX_FIFO1_NEW_MESSAGE
301 it_mask |= FDCAN_IT_RX_FIFO1_NEW_MESSAGE;
303#ifdef FDCAN_IT_TX_FIFO_EMPTY
304 it_mask |= FDCAN_IT_TX_FIFO_EMPTY;
309 HAL_FDCAN_DeactivateNotification(hcan_, it_mask);
313 if (HAL_FDCAN_Stop(hcan_) != HAL_OK)
315 return ErrorCode::FAILED;
318#ifdef FDCAN_CCCR_INIT
319 SET_BIT(can->CCCR, FDCAN_CCCR_INIT);
322 SET_BIT(can->CCCR, FDCAN_CCCR_CCE);
331 SET_BIT(can->CCCR, FDCAN_CCCR_DAR);
335 CLEAR_BIT(can->CCCR, FDCAN_CCCR_DAR);
342#ifdef FDCAN_CCCR_TEST
343#ifdef FDCAN_TEST_LBCK
347 SET_BIT(can->CCCR, FDCAN_CCCR_TEST);
348 SET_BIT(can->TEST, FDCAN_TEST_LBCK);
352 CLEAR_BIT(can->TEST, FDCAN_TEST_LBCK);
353 CLEAR_BIT(can->CCCR, FDCAN_CCCR_TEST);
362 SET_BIT(can->CCCR, FDCAN_CCCR_MON);
366 CLEAR_BIT(can->CCCR, FDCAN_CCCR_MON);
375#ifdef FDCAN_NBTP_NBRP_Msk
376 constexpr uint32_t NBRP_FIELD_MAX = (FDCAN_NBTP_NBRP_Msk >> FDCAN_NBTP_NBRP_Pos);
377 constexpr uint32_t NTSEG1_FIELD_MAX = (FDCAN_NBTP_NTSEG1_Msk >> FDCAN_NBTP_NTSEG1_Pos);
378 constexpr uint32_t NTSEG2_FIELD_MAX = (FDCAN_NBTP_NTSEG2_Msk >> FDCAN_NBTP_NTSEG2_Pos);
379 constexpr uint32_t NSJW_FIELD_MAX = (FDCAN_NBTP_NSJW_Msk >> FDCAN_NBTP_NSJW_Pos);
381 constexpr uint32_t NBRP_MAX = NBRP_FIELD_MAX + 1u;
382 constexpr uint32_t NTSEG1_MAX = NTSEG1_FIELD_MAX + 1u;
383 constexpr uint32_t NTSEG2_MAX = NTSEG2_FIELD_MAX + 1u;
384 constexpr uint32_t NSJW_MAX = NSJW_FIELD_MAX + 1u;
389 if (bt.brp < 1u || bt.brp > NBRP_MAX)
392 return ErrorCode::ARG_ERR;
396 uint32_t tseg1 = bt.
prop_seg + bt.phase_seg1;
397 if (bt.prop_seg != 0u || bt.phase_seg1 != 0u)
399 if (tseg1 < 1u || tseg1 > NTSEG1_MAX)
402 return ErrorCode::ARG_ERR;
406 if (bt.phase_seg2 != 0u)
408 if (bt.phase_seg2 < 1u || bt.phase_seg2 > NTSEG2_MAX)
411 return ErrorCode::ARG_ERR;
417 if (bt.sjw < 1u || bt.sjw > NSJW_MAX)
420 return ErrorCode::ARG_ERR;
422 if (bt.phase_seg2 != 0u && bt.sjw > bt.phase_seg2)
425 return ErrorCode::ARG_ERR;
429 uint32_t nbtp_old = can->NBTP;
430 uint32_t nbtp_new = nbtp_old;
431 uint32_t nbtp_mask = 0u;
436 uint32_t nbrp = (bt.brp - 1u) & NBRP_FIELD_MAX;
437 uint32_t mask = FDCAN_NBTP_NBRP_Msk;
440 nbtp_new |= (nbrp << FDCAN_NBTP_NBRP_Pos);
444 if (bt.prop_seg != 0u || bt.phase_seg1 != 0u)
446 uint32_t ntseg1 = (tseg1 - 1u) & NTSEG1_FIELD_MAX;
447 uint32_t mask = FDCAN_NBTP_NTSEG1_Msk;
450 nbtp_new |= (ntseg1 << FDCAN_NBTP_NTSEG1_Pos);
454 if (bt.phase_seg2 != 0u)
456 uint32_t ntseg2 = (bt.phase_seg2 - 1u) & NTSEG2_FIELD_MAX;
457 uint32_t mask = FDCAN_NBTP_NTSEG2_Msk;
460 nbtp_new |= (ntseg2 << FDCAN_NBTP_NTSEG2_Pos);
466 uint32_t nsjw = (bt.sjw - 1u) & NSJW_FIELD_MAX;
467 uint32_t mask = FDCAN_NBTP_NSJW_Msk;
470 nbtp_new |= (nsjw << FDCAN_NBTP_NSJW_Pos);
475 nbtp_old &= ~nbtp_mask;
476 nbtp_old |= (nbtp_new & nbtp_mask);
477 can->NBTP = nbtp_old;
485#ifdef FDCAN_DBTP_DBRP_Msk
486 constexpr uint32_t DBRP_FIELD_MAX = (FDCAN_DBTP_DBRP_Msk >> FDCAN_DBTP_DBRP_Pos);
487 constexpr uint32_t DTSEG1_FIELD_MAX = (FDCAN_DBTP_DTSEG1_Msk >> FDCAN_DBTP_DTSEG1_Pos);
488 constexpr uint32_t DTSEG2_FIELD_MAX = (FDCAN_DBTP_DTSEG2_Msk >> FDCAN_DBTP_DTSEG2_Pos);
489 constexpr uint32_t DSJW_FIELD_MAX = (FDCAN_DBTP_DSJW_Msk >> FDCAN_DBTP_DSJW_Pos);
491 constexpr uint32_t DBRP_MAX = DBRP_FIELD_MAX + 1u;
492 constexpr uint32_t DTSEG1_MAX = DTSEG1_FIELD_MAX + 1u;
493 constexpr uint32_t DTSEG2_MAX = DTSEG2_FIELD_MAX + 1u;
494 constexpr uint32_t DSJW_MAX = DSJW_FIELD_MAX + 1u;
498 if (dbt.brp < 1u || dbt.brp > DBRP_MAX)
501 return ErrorCode::ARG_ERR;
505 uint32_t dtseg1 = dbt.
prop_seg + dbt.phase_seg1;
506 if (dbt.prop_seg != 0u || dbt.phase_seg1 != 0u)
508 if (dtseg1 < 1u || dtseg1 > DTSEG1_MAX)
511 return ErrorCode::ARG_ERR;
515 if (dbt.phase_seg2 != 0u)
517 if (dbt.phase_seg2 < 1u || dbt.phase_seg2 > DTSEG2_MAX)
520 return ErrorCode::ARG_ERR;
526 if (dbt.sjw < 1u || dbt.sjw > DSJW_MAX)
529 return ErrorCode::ARG_ERR;
531 if (dbt.phase_seg2 != 0u && dbt.sjw > dbt.phase_seg2)
534 return ErrorCode::ARG_ERR;
538 uint32_t dbtp_old = can->DBTP;
539 uint32_t dbtp_new = dbtp_old;
540 uint32_t dbtp_mask = 0u;
544 uint32_t dbrp = (dbt.brp - 1u) & DBRP_FIELD_MAX;
545 uint32_t mask = FDCAN_DBTP_DBRP_Msk;
548 dbtp_new |= (dbrp << FDCAN_DBTP_DBRP_Pos);
551 if (dbt.prop_seg != 0u || dbt.phase_seg1 != 0u)
553 uint32_t dt1 = (dtseg1 - 1u) & DTSEG1_FIELD_MAX;
554 uint32_t mask = FDCAN_DBTP_DTSEG1_Msk;
557 dbtp_new |= (dt1 << FDCAN_DBTP_DTSEG1_Pos);
560 if (dbt.phase_seg2 != 0u)
562 uint32_t dt2 = (dbt.phase_seg2 - 1u) & DTSEG2_FIELD_MAX;
563 uint32_t mask = FDCAN_DBTP_DTSEG2_Msk;
566 dbtp_new |= (dt2 << FDCAN_DBTP_DTSEG2_Pos);
571 uint32_t dsjw = (dbt.sjw - 1u) & DSJW_FIELD_MAX;
572 uint32_t mask = FDCAN_DBTP_DSJW_Msk;
575 dbtp_new |= (dsjw << FDCAN_DBTP_DSJW_Pos);
580 dbtp_old &= ~dbtp_mask;
581 dbtp_old |= (dbtp_new & dbtp_mask);
582 can->DBTP = dbtp_old;
592 if (HAL_FDCAN_Start(hcan_) != HAL_OK)
594 return ErrorCode::FAILED;
597 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_ERROR_PASSIVE, 0);
598 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_ERROR_WARNING, 0);
599 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_BUS_OFF, 0);
600 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);
601 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_RX_FIFO1_NEW_MESSAGE, 0);
602 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_TX_FIFO_EMPTY, 0);
603 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_TX_COMPLETE, 0xFFFFFFFF);
605 return ErrorCode::OK;
611#if defined(RCC_PERIPHCLK_FDCAN)
612 return HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_FDCAN);
613#elif defined(RCC_PERIPHCLK_FDCAN1)
614 return HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_FDCAN1);
626 return ErrorCode::ARG_ERR;
629 ASSERT(pack.
len <= 64u);
633 return ErrorCode::FAILED;
637 if (tx_pool_fd_.
Put(pack) != ErrorCode::OK)
640 if (tx_pool_fd_.
Put(pack) != ErrorCode::OK)
642 return ErrorCode::FULL;
647 return ErrorCode::OK;
652 if (HAL_FDCAN_GetRxMessage(hcan_, fifo, &rx_buff_.header, rx_buff_.pack_fd.data) ==
655 if (rx_buff_.header.FDFormat == FDCAN_FD_CAN)
657 rx_buff_.pack_fd.id = rx_buff_.header.Identifier;
658 rx_buff_.pack_fd.type =
661 if (rx_buff_.header.RxFrameType != FDCAN_DATA_FRAME)
673 rx_buff_.pack_fd.len = DlcToBytes(rx_buff_.header.DataLength);
679 rx_buff_.pack.id = rx_buff_.header.Identifier;
683 uint32_t bytes = DlcToBytes(rx_buff_.header.DataLength);
689 if (rx_buff_.header.RxFrameType != FDCAN_DATA_FRAME)
699 rx_buff_.pack.dlc =
static_cast<uint8_t
>(bytes);
703 rx_buff_.pack.dlc =
static_cast<uint8_t
>(bytes);
715void STM32CANFD::TxService()
717 if (hcan_ ==
nullptr || hcan_->Instance ==
nullptr)
722 tx_pend_.store(1u, std::memory_order_release);
724 uint32_t expected = 0u;
725 if (!tx_lock_.compare_exchange_strong(expected, 1u, std::memory_order_acquire,
726 std::memory_order_relaxed))
733 tx_pend_.store(0u, std::memory_order_release);
739 if (tx_pool_fd_.
Get(pfd) == ErrorCode::OK)
741 FDCAN_TxHeaderTypeDef hdr{};
742 BuildTxHeader(pfd, hdr);
744 if (HAL_FDCAN_AddMessageToTxFifoQ(hcan_, &hdr, pfd.data) != HAL_OK)
747 if (tx_pool_fd_.
Put(pfd) != ErrorCode::OK)
758 if (tx_pool_.
Get(pc) == ErrorCode::OK)
760 FDCAN_TxHeaderTypeDef hdr{};
761 BuildTxHeader(pc, hdr);
763 if (HAL_FDCAN_AddMessageToTxFifoQ(hcan_, &hdr, pc.data) != HAL_OK)
765 if (tx_pool_.
Put(pc) != ErrorCode::OK)
777 tx_lock_.store(0u, std::memory_order_release);
779 if (tx_pend_.load(std::memory_order_acquire) == 0u)
785 if (!tx_lock_.compare_exchange_strong(expected, 1u, std::memory_order_acquire,
786 std::memory_order_relaxed))
795 FDCAN_ProtocolStatusTypeDef protocol_status = {};
796 HAL_FDCAN_GetProtocolStatus(hcan_, &protocol_status);
798#ifdef FDCAN_IT_BUS_OFF
799#ifdef FDCAN_CCCR_INIT
800 if ((error_status_its & FDCAN_IT_BUS_OFF) != 0u && protocol_status.BusOff != 0u)
802 CLEAR_BIT(hcan_->Instance->CCCR, FDCAN_CCCR_INIT);
813 if (protocol_status.BusOff != 0u)
815 eid = CAN::ErrorID::CAN_ERROR_ID_BUS_OFF;
817 else if (protocol_status.ErrorPassive != 0u)
819 eid = CAN::ErrorID::CAN_ERROR_ID_ERROR_PASSIVE;
821 else if (protocol_status.Warning != 0u)
823 eid = CAN::ErrorID::CAN_ERROR_ID_ERROR_WARNING;
827 uint32_t lec = protocol_status.LastErrorCode & 0x7u;
830 lec = protocol_status.DataLastErrorCode & 0x7u;
836 eid = CAN::ErrorID::CAN_ERROR_ID_STUFF;
839 eid = CAN::ErrorID::CAN_ERROR_ID_FORM;
842 eid = CAN::ErrorID::CAN_ERROR_ID_ACK;
845 eid = CAN::ErrorID::CAN_ERROR_ID_BIT1;
848 eid = CAN::ErrorID::CAN_ERROR_ID_BIT0;
851 eid = CAN::ErrorID::CAN_ERROR_ID_CRC;
854 eid = CAN::ErrorID::CAN_ERROR_ID_OTHER;
859 pack.
id =
static_cast<uint32_t
>(eid);
866 if (hcan_ ==
nullptr || hcan_->Instance ==
nullptr)
868 return ErrorCode::ARG_ERR;
871 FDCAN_ErrorCountersTypeDef counters{};
872 if (HAL_FDCAN_GetErrorCounters(hcan_, &counters) != HAL_OK)
874 return ErrorCode::FAILED;
877 FDCAN_ProtocolStatusTypeDef proto{};
878 if (HAL_FDCAN_GetProtocolStatus(hcan_, &proto) != HAL_OK)
880 return ErrorCode::FAILED;
886 state.
bus_off = (proto.BusOff != 0u);
890 return ErrorCode::OK;
893extern "C" void HAL_FDCAN_ErrorCallback(FDCAN_HandleTypeDef* hcan)
895 hcan->ErrorCode = HAL_FDCAN_ERROR_NONE;
896 auto can = STM32CANFD::map[STM32_FDCAN_GetID(hcan->Instance)];
903extern "C" void HAL_FDCAN_ErrorStatusCallback(FDCAN_HandleTypeDef* hfdcan,
904 uint32_t ErrorStatusITs)
906 auto can = STM32CANFD::map[STM32_FDCAN_GetID(hfdcan->Instance)];
909 can->ProcessErrorStatusInterrupt(ErrorStatusITs);
914extern "C" void HAL_FDCAN_TxBufferCompleteCallback(FDCAN_HandleTypeDef* hcan,
915 uint32_t BufferIndexes)
917 UNUSED(BufferIndexes);
918 auto can = STM32CANFD::map[STM32_FDCAN_GetID(hcan->Instance)];
925extern "C" void HAL_FDCAN_TxFifoEmptyCallback(FDCAN_HandleTypeDef* hcan)
927 auto can = STM32CANFD::map[STM32_FDCAN_GetID(hcan->Instance)];
934extern "C" void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef* hcan, uint32_t RxFifo0ITs)
937 auto can = STM32CANFD::map[STM32_FDCAN_GetID(hcan->Instance)];
940 can->ProcessRxInterrupt(FDCAN_RX_FIFO0);
944extern "C" void HAL_FDCAN_RxFifo1Callback(FDCAN_HandleTypeDef* hcan, uint32_t RxFifo1ITs)
947 auto can = STM32CANFD::map[STM32_FDCAN_GetID(hcan->Instance)];
950 can->ProcessRxInterrupt(FDCAN_RX_FIFO1);
@ 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.
@ ERROR
错误帧(虚拟事件)。Error frame (virtual event).
ErrorID
ClassicPack::type == Type::ERROR 时使用的虚拟 ID。 Virtual IDs used when ClassicPack::type == Type::ERROR.
FDCAN 通信抽象类,扩展支持 CAN FD 帧。 Abstract class for FDCAN communication with CAN FD frame support.
void OnMessage(const FDPack &pack, bool in_isr)
分发接收到的 FD CAN 帧。 Dispatch a received FD CAN frame.
ErrorCode Put(const Data &data)
向池中放入一个元素 / Put an element into the pool
ErrorCode Get(Data &data)
从池中取出一个元素 / Retrieve an element from the pool
static void FastCopy(void *dst, const void *src, size_t size)
快速内存拷贝 / Fast memory copy
STM32 FDCAN 驱动实现 / STM32 FDCAN driver implementation.
void ProcessErrorStatusInterrupt(uint32_t error_status_its)
处理错误状态中断 / Handle error-status interrupt
uint32_t GetClockFreq() const override
获取 FDCAN 外设时钟 / Get FDCAN kernel clock
ErrorCode Init(void)
初始化驱动 / Initialize driver
void ProcessRxInterrupt(uint32_t fifo)
处理接收中断 / Handle RX interrupt
STM32CANFD(FDCAN_HandleTypeDef *hcan, uint32_t queue_size)
构造 FDCAN 驱动对象 / Construct FDCAN driver object
ErrorCode GetErrorState(CAN::ErrorState &state) const override
查询当前错误状态 / Query current FDCAN error state
ErrorCode AddMessage(const ClassicPack &pack) override
添加经典 CAN 消息。Add classic CAN message.
size_t HardwareTxQueueEmptySize()
获取硬件发送队列空闲数 / Get free level of hardware TX queue
ErrorCode SetConfig(const CAN::Configuration &cfg) override
设置 CAN/FDCAN 配置 / Set CAN/FDCAN configuration
uint32_t prop_seg
传播段。Propagation segment.
经典 CAN 帧数据结构。Classic CAN frame structure.
uint32_t id
CAN ID(11/29 bit 或 ErrorID)。CAN ID (11/29 bits or ErrorID).
uint8_t dlc
有效数据长度(0~8)。Data length code (0–8).
CAN 配置参数。CAN configuration parameters.
BitTiming bit_timing
位时序配置。Bit timing configuration.
float sample_point
仲裁相位采样点(0~1)。Nominal sample point (0–1).
Mode mode
工作模式。Operating mode.
uint32_t bitrate
仲裁相位目标波特率。Target nominal bitrate.
CAN 当前错误状态快照(来自硬件计数器/状态机)。 Snapshot of current CAN controller error state (from HW counters/state).
bool bus_off
是否处于 BUS-OFF。True if controller is bus-off.
bool error_passive
是否处于 Error Passive。True if error-passive.
uint8_t tx_error_counter
发送错误计数 TEC。Transmit error counter (TEC).
bool error_warning
是否处于 Error Warning。True if error-warning.
uint8_t rx_error_counter
接收错误计数 REC。Receive error counter (REC).
bool triple_sampling
三采样。Triple sampling.
bool loopback
回环模式。Loopback mode.
bool one_shot
单次发送模式。One-shot transmission.
bool listen_only
只听(静默)模式。Listen-only (silent) mode.
FDCAN 配置参数,扩展 CAN::Configuration。 FDCAN configuration, extending CAN::Configuration.
FDMode fd_mode
FD 模式配置。FD mode configuration.
DataBitTiming data_timing
数据相位位时序。Data-phase bit timing.
uint32_t prop_seg
传播段。Propagation segment.
CAN FD 帧数据结构。CAN FD frame structure.
uint8_t len
数据长度(0~64)。Data length (0–64 bytes).