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);
330 SET_BIT(can->CCCR, FDCAN_CCCR_DAR);
334 CLEAR_BIT(can->CCCR, FDCAN_CCCR_DAR);
341#ifdef FDCAN_CCCR_TEST
342#ifdef FDCAN_TEST_LBCK
346 SET_BIT(can->CCCR, FDCAN_CCCR_TEST);
347 SET_BIT(can->TEST, FDCAN_TEST_LBCK);
351 CLEAR_BIT(can->TEST, FDCAN_TEST_LBCK);
352 CLEAR_BIT(can->CCCR, FDCAN_CCCR_TEST);
361 SET_BIT(can->CCCR, FDCAN_CCCR_MON);
365 CLEAR_BIT(can->CCCR, FDCAN_CCCR_MON);
373#ifdef FDCAN_NBTP_NBRP_Msk
374 constexpr uint32_t NBRP_FIELD_MAX = (FDCAN_NBTP_NBRP_Msk >> FDCAN_NBTP_NBRP_Pos);
375 constexpr uint32_t NTSEG1_FIELD_MAX = (FDCAN_NBTP_NTSEG1_Msk >> FDCAN_NBTP_NTSEG1_Pos);
376 constexpr uint32_t NTSEG2_FIELD_MAX = (FDCAN_NBTP_NTSEG2_Msk >> FDCAN_NBTP_NTSEG2_Pos);
377 constexpr uint32_t NSJW_FIELD_MAX = (FDCAN_NBTP_NSJW_Msk >> FDCAN_NBTP_NSJW_Pos);
379 constexpr uint32_t NBRP_MAX = NBRP_FIELD_MAX + 1u;
380 constexpr uint32_t NTSEG1_MAX = NTSEG1_FIELD_MAX + 1u;
381 constexpr uint32_t NTSEG2_MAX = NTSEG2_FIELD_MAX + 1u;
382 constexpr uint32_t NSJW_MAX = NSJW_FIELD_MAX + 1u;
387 if (bt.brp < 1u || bt.brp > NBRP_MAX)
390 return ErrorCode::ARG_ERR;
394 uint32_t tseg1 = bt.
prop_seg + bt.phase_seg1;
395 if (bt.prop_seg != 0u || bt.phase_seg1 != 0u)
397 if (tseg1 < 1u || tseg1 > NTSEG1_MAX)
400 return ErrorCode::ARG_ERR;
404 if (bt.phase_seg2 != 0u)
406 if (bt.phase_seg2 < 1u || bt.phase_seg2 > NTSEG2_MAX)
409 return ErrorCode::ARG_ERR;
415 if (bt.sjw < 1u || bt.sjw > NSJW_MAX)
418 return ErrorCode::ARG_ERR;
420 if (bt.phase_seg2 != 0u && bt.sjw > bt.phase_seg2)
423 return ErrorCode::ARG_ERR;
427 uint32_t nbtp_old = can->NBTP;
428 uint32_t nbtp_new = nbtp_old;
429 uint32_t nbtp_mask = 0u;
434 uint32_t nbrp = (bt.brp - 1u) & NBRP_FIELD_MAX;
435 uint32_t mask = FDCAN_NBTP_NBRP_Msk;
438 nbtp_new |= (nbrp << FDCAN_NBTP_NBRP_Pos);
442 if (bt.prop_seg != 0u || bt.phase_seg1 != 0u)
444 uint32_t ntseg1 = (tseg1 - 1u) & NTSEG1_FIELD_MAX;
445 uint32_t mask = FDCAN_NBTP_NTSEG1_Msk;
448 nbtp_new |= (ntseg1 << FDCAN_NBTP_NTSEG1_Pos);
452 if (bt.phase_seg2 != 0u)
454 uint32_t ntseg2 = (bt.phase_seg2 - 1u) & NTSEG2_FIELD_MAX;
455 uint32_t mask = FDCAN_NBTP_NTSEG2_Msk;
458 nbtp_new |= (ntseg2 << FDCAN_NBTP_NTSEG2_Pos);
464 uint32_t nsjw = (bt.sjw - 1u) & NSJW_FIELD_MAX;
465 uint32_t mask = FDCAN_NBTP_NSJW_Msk;
468 nbtp_new |= (nsjw << FDCAN_NBTP_NSJW_Pos);
473 nbtp_old &= ~nbtp_mask;
474 nbtp_old |= (nbtp_new & nbtp_mask);
475 can->NBTP = nbtp_old;
482#ifdef FDCAN_DBTP_DBRP_Msk
483 constexpr uint32_t DBRP_FIELD_MAX = (FDCAN_DBTP_DBRP_Msk >> FDCAN_DBTP_DBRP_Pos);
484 constexpr uint32_t DTSEG1_FIELD_MAX = (FDCAN_DBTP_DTSEG1_Msk >> FDCAN_DBTP_DTSEG1_Pos);
485 constexpr uint32_t DTSEG2_FIELD_MAX = (FDCAN_DBTP_DTSEG2_Msk >> FDCAN_DBTP_DTSEG2_Pos);
486 constexpr uint32_t DSJW_FIELD_MAX = (FDCAN_DBTP_DSJW_Msk >> FDCAN_DBTP_DSJW_Pos);
488 constexpr uint32_t DBRP_MAX = DBRP_FIELD_MAX + 1u;
489 constexpr uint32_t DTSEG1_MAX = DTSEG1_FIELD_MAX + 1u;
490 constexpr uint32_t DTSEG2_MAX = DTSEG2_FIELD_MAX + 1u;
491 constexpr uint32_t DSJW_MAX = DSJW_FIELD_MAX + 1u;
495 if (dbt.brp < 1u || dbt.brp > DBRP_MAX)
498 return ErrorCode::ARG_ERR;
502 uint32_t dtseg1 = dbt.
prop_seg + dbt.phase_seg1;
503 if (dbt.prop_seg != 0u || dbt.phase_seg1 != 0u)
505 if (dtseg1 < 1u || dtseg1 > DTSEG1_MAX)
508 return ErrorCode::ARG_ERR;
512 if (dbt.phase_seg2 != 0u)
514 if (dbt.phase_seg2 < 1u || dbt.phase_seg2 > DTSEG2_MAX)
517 return ErrorCode::ARG_ERR;
523 if (dbt.sjw < 1u || dbt.sjw > DSJW_MAX)
526 return ErrorCode::ARG_ERR;
528 if (dbt.phase_seg2 != 0u && dbt.sjw > dbt.phase_seg2)
531 return ErrorCode::ARG_ERR;
535 uint32_t dbtp_old = can->DBTP;
536 uint32_t dbtp_new = dbtp_old;
537 uint32_t dbtp_mask = 0u;
541 uint32_t dbrp = (dbt.brp - 1u) & DBRP_FIELD_MAX;
542 uint32_t mask = FDCAN_DBTP_DBRP_Msk;
545 dbtp_new |= (dbrp << FDCAN_DBTP_DBRP_Pos);
548 if (dbt.prop_seg != 0u || dbt.phase_seg1 != 0u)
550 uint32_t dt1 = (dtseg1 - 1u) & DTSEG1_FIELD_MAX;
551 uint32_t mask = FDCAN_DBTP_DTSEG1_Msk;
554 dbtp_new |= (dt1 << FDCAN_DBTP_DTSEG1_Pos);
557 if (dbt.phase_seg2 != 0u)
559 uint32_t dt2 = (dbt.phase_seg2 - 1u) & DTSEG2_FIELD_MAX;
560 uint32_t mask = FDCAN_DBTP_DTSEG2_Msk;
563 dbtp_new |= (dt2 << FDCAN_DBTP_DTSEG2_Pos);
568 uint32_t dsjw = (dbt.sjw - 1u) & DSJW_FIELD_MAX;
569 uint32_t mask = FDCAN_DBTP_DSJW_Msk;
572 dbtp_new |= (dsjw << FDCAN_DBTP_DSJW_Pos);
577 dbtp_old &= ~dbtp_mask;
578 dbtp_old |= (dbtp_new & dbtp_mask);
579 can->DBTP = dbtp_old;
589 if (HAL_FDCAN_Start(hcan_) != HAL_OK)
591 return ErrorCode::FAILED;
594 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_ERROR_PASSIVE, 0);
595 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_ERROR_WARNING, 0);
596 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_BUS_OFF, 0);
597 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);
598 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_RX_FIFO1_NEW_MESSAGE, 0);
599 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_TX_FIFO_EMPTY, 0);
600 HAL_FDCAN_ActivateNotification(hcan_, FDCAN_IT_TX_COMPLETE, 0xFFFFFFFF);
602 return ErrorCode::OK;
608#if defined(RCC_PERIPHCLK_FDCAN)
609 return HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_FDCAN);
610#elif defined(RCC_PERIPHCLK_FDCAN1)
611 return HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_FDCAN1);
623 return ErrorCode::ARG_ERR;
626 ASSERT(pack.
len <= 64u);
630 return ErrorCode::FAILED;
634 if (tx_pool_fd_.
Put(pack) != ErrorCode::OK)
637 if (tx_pool_fd_.
Put(pack) != ErrorCode::OK)
639 return ErrorCode::FULL;
644 return ErrorCode::OK;
649 if (HAL_FDCAN_GetRxMessage(hcan_, fifo, &rx_buff_.header, rx_buff_.pack_fd.data) ==
652 if (rx_buff_.header.FDFormat == FDCAN_FD_CAN)
654 rx_buff_.pack_fd.id = rx_buff_.header.Identifier;
655 rx_buff_.pack_fd.type =
658 if (rx_buff_.header.RxFrameType != FDCAN_DATA_FRAME)
670 rx_buff_.pack_fd.len = DlcToBytes(rx_buff_.header.DataLength);
676 rx_buff_.pack.id = rx_buff_.header.Identifier;
680 uint32_t bytes = DlcToBytes(rx_buff_.header.DataLength);
686 if (rx_buff_.header.RxFrameType != FDCAN_DATA_FRAME)
696 rx_buff_.pack.dlc =
static_cast<uint8_t
>(bytes);
700 rx_buff_.pack.dlc =
static_cast<uint8_t
>(bytes);
712void STM32CANFD::TxService()
714 if (hcan_ ==
nullptr || hcan_->Instance ==
nullptr)
719 tx_pend_.store(1u, std::memory_order_release);
721 uint32_t expected = 0u;
722 if (!tx_lock_.compare_exchange_strong(expected, 1u, std::memory_order_acquire,
723 std::memory_order_relaxed))
730 tx_pend_.store(0u, std::memory_order_release);
736 if (tx_pool_fd_.
Get(pfd) == ErrorCode::OK)
738 FDCAN_TxHeaderTypeDef hdr{};
739 BuildTxHeader(pfd, hdr);
741 if (HAL_FDCAN_AddMessageToTxFifoQ(hcan_, &hdr, pfd.data) != HAL_OK)
744 if (tx_pool_fd_.
Put(pfd) != ErrorCode::OK)
755 if (tx_pool_.
Get(pc) == ErrorCode::OK)
757 FDCAN_TxHeaderTypeDef hdr{};
758 BuildTxHeader(pc, hdr);
760 if (HAL_FDCAN_AddMessageToTxFifoQ(hcan_, &hdr, pc.data) != HAL_OK)
762 if (tx_pool_.
Put(pc) != ErrorCode::OK)
774 tx_lock_.store(0u, std::memory_order_release);
776 if (tx_pend_.load(std::memory_order_acquire) == 0u)
782 if (!tx_lock_.compare_exchange_strong(expected, 1u, std::memory_order_acquire,
783 std::memory_order_relaxed))
792 FDCAN_ProtocolStatusTypeDef protocol_status = {};
793 HAL_FDCAN_GetProtocolStatus(hcan_, &protocol_status);
795#ifdef FDCAN_IT_BUS_OFF
796#ifdef FDCAN_CCCR_INIT
797 if ((error_status_its & FDCAN_IT_BUS_OFF) != 0u && protocol_status.BusOff != 0u)
799 CLEAR_BIT(hcan_->Instance->CCCR, FDCAN_CCCR_INIT);
810 if (protocol_status.BusOff != 0u)
812 eid = CAN::ErrorID::CAN_ERROR_ID_BUS_OFF;
814 else if (protocol_status.ErrorPassive != 0u)
816 eid = CAN::ErrorID::CAN_ERROR_ID_ERROR_PASSIVE;
818 else if (protocol_status.Warning != 0u)
820 eid = CAN::ErrorID::CAN_ERROR_ID_ERROR_WARNING;
824 uint32_t lec = protocol_status.LastErrorCode & 0x7u;
827 lec = protocol_status.DataLastErrorCode & 0x7u;
833 eid = CAN::ErrorID::CAN_ERROR_ID_STUFF;
836 eid = CAN::ErrorID::CAN_ERROR_ID_FORM;
839 eid = CAN::ErrorID::CAN_ERROR_ID_ACK;
842 eid = CAN::ErrorID::CAN_ERROR_ID_BIT1;
845 eid = CAN::ErrorID::CAN_ERROR_ID_BIT0;
848 eid = CAN::ErrorID::CAN_ERROR_ID_CRC;
851 eid = CAN::ErrorID::CAN_ERROR_ID_OTHER;
856 pack.
id =
static_cast<uint32_t
>(eid);
863 if (hcan_ ==
nullptr || hcan_->Instance ==
nullptr)
865 return ErrorCode::ARG_ERR;
868 FDCAN_ErrorCountersTypeDef counters{};
869 if (HAL_FDCAN_GetErrorCounters(hcan_, &counters) != HAL_OK)
871 return ErrorCode::FAILED;
874 FDCAN_ProtocolStatusTypeDef proto{};
875 if (HAL_FDCAN_GetProtocolStatus(hcan_, &proto) != HAL_OK)
877 return ErrorCode::FAILED;
883 state.
bus_off = (proto.BusOff != 0u);
887 return ErrorCode::OK;
890extern "C" void HAL_FDCAN_ErrorCallback(FDCAN_HandleTypeDef* hcan)
892 hcan->ErrorCode = HAL_FDCAN_ERROR_NONE;
893 auto can = STM32CANFD::map[STM32_FDCAN_GetID(hcan->Instance)];
900extern "C" void HAL_FDCAN_ErrorStatusCallback(FDCAN_HandleTypeDef* hfdcan,
901 uint32_t ErrorStatusITs)
903 auto can = STM32CANFD::map[STM32_FDCAN_GetID(hfdcan->Instance)];
906 can->ProcessErrorStatusInterrupt(ErrorStatusITs);
911extern "C" void HAL_FDCAN_TxBufferCompleteCallback(FDCAN_HandleTypeDef* hcan,
912 uint32_t BufferIndexes)
914 UNUSED(BufferIndexes);
915 auto can = STM32CANFD::map[STM32_FDCAN_GetID(hcan->Instance)];
922extern "C" void HAL_FDCAN_TxFifoEmptyCallback(FDCAN_HandleTypeDef* hcan)
924 auto can = STM32CANFD::map[STM32_FDCAN_GetID(hcan->Instance)];
931extern "C" void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef* hcan, uint32_t RxFifo0ITs)
934 auto can = STM32CANFD::map[STM32_FDCAN_GetID(hcan->Instance)];
937 can->ProcessRxInterrupt(FDCAN_RX_FIFO0);
941extern "C" void HAL_FDCAN_RxFifo1Callback(FDCAN_HandleTypeDef* hcan, uint32_t RxFifo1ITs)
944 auto can = STM32CANFD::map[STM32_FDCAN_GetID(hcan->Instance)];
947 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
STM32CANFD 类,用于处理 STM32 系统的 CANFD 通道。 Provides handling for STM32 CANFD.
void ProcessErrorStatusInterrupt(uint32_t error_status_its)
处理错误状态中断
uint32_t GetClockFreq() const override
获取 FDCAN 外设时钟(Hz)。Get FDCAN kernel clock (Hz).
void ProcessRxInterrupt(uint32_t fifo)
处理接收中断
STM32CANFD(FDCAN_HandleTypeDef *hcan, uint32_t queue_size)
STM32CANFD 类,用于处理 STM32 系统的 CANFD 通道。 Provides handling for STM32 CANFD.
ErrorCode GetErrorState(CAN::ErrorState &state) const override
查询当前错误状态(快照)。 Query current FDCAN error state (snapshot).
ErrorCode AddMessage(const ClassicPack &pack) override
添加经典 CAN 消息。Add classic CAN message.
size_t HardwareTxQueueEmptySize()
获取硬件发送队列空闲大小
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).