跳转到内容

bsp::CANDriver API

文档稀疏
符号
76
已记录
60
类型
5
继承关系
0
源码分支
main

16 / 76 个公开 API 符号没有说明。

共 5 个类型

类型目录
结构体

CAN_FilterTypeDef

查看源码

CAN filter configuration structure definition.

成员变量

10

FilterActivation

变量公开
        uint32_t CAN_FilterTypeDef::FilterActivation
      

CAN_FILTER_DISABLE CAN_FILTER_ENABLE Filter activation state:or.

bsp/can_driver/can_hal_def.h:33

FilterBank

变量公开
        uint32_t CAN_FilterTypeDef::FilterBank
      

Filter bank index. Range: 0 to 13 for a single CAN instance, or 0 to 27 for dual CAN instances.

bsp/can_driver/can_hal_def.h:27

FilterFIFOAssignment

变量公开
        uint32_t CAN_FilterTypeDef::FilterFIFOAssignment
      

CAN_FILTER_FIFO0 CAN_FILTER_FIFO1 FIFO assigned to a matching filter:or.

bsp/can_driver/can_hal_def.h:25

FilterIdHigh

变量公开
        uint32_t CAN_FilterTypeDef::FilterIdHigh
      

Filter identification number MSBs for a 32-bit configuration, or the first ID for a 16-bit configuration. Range: 0x0000 to 0xFFFF.

bsp/can_driver/can_hal_def.h:13

FilterIdLow

变量公开
        uint32_t CAN_FilterTypeDef::FilterIdLow
      

Filter identification number LSBs for a 32-bit configuration, or the second ID for a 16-bit configuration. Range: 0x0000 to 0xFFFF.

bsp/can_driver/can_hal_def.h:16

FilterMaskIdHigh

变量公开
        uint32_t CAN_FilterTypeDef::FilterMaskIdHigh
      

Filter mask or identification number MSBs for a 32-bit configuration, or the first value for a 16-bit configuration. Range: 0x0000 to 0xFFFF.

bsp/can_driver/can_hal_def.h:19

FilterMaskIdLow

变量公开
        uint32_t CAN_FilterTypeDef::FilterMaskIdLow
      

Filter mask or identification number LSBs for a 32-bit configuration, or the second value for a 16-bit configuration. Range: 0x0000 to 0xFFFF.

bsp/can_driver/can_hal_def.h:22

FilterMode

变量公开
        uint32_t CAN_FilterTypeDef::FilterMode
      

CAN_FILTERMODE_IDMASK CAN_FILTERMODE_IDLIST Filter mode: identifier mask or identifier list; seeand.

bsp/can_driver/can_hal_def.h:29

FilterScale

变量公开
        uint32_t CAN_FilterTypeDef::FilterScale
      

CAN_FILTERSCALE_16BIT CAN_FILTERSCALE_32BIT Filter scale: two 16-bit filters or one 32-bit filter; seeand.

bsp/can_driver/can_hal_def.h:31

SlaveStartFilterBank

变量公开
        uint32_t CAN_FilterTypeDef::SlaveStartFilterBank
      

Start bank assigned to the slave CAN instance. Meaningless for a single CAN instance; for dual CAN, lower banks belong to the master and higher banks to the slave. Range: 0 to 27.

bsp/can_driver/can_hal_def.h:35
结构体

CAN_RxHeaderTypeDef

查看源码

CAN Rx message header structure definition.

成员变量

7

FilterMatchIndex

变量公开
        uint32_t CAN_RxHeaderTypeDef::FilterMatchIndex
      

Index of the matching acceptance filter. 在 FDCAN 后端下填入的是 FDCAN 滤波器元素索引, 与 bxCAN 的 FilterBank 编号不是同一套编号。 Range: 0 to 0xFF.

bsp/can_driver/can_hal_def.h:69

Timestamp

变量公开
        uint32_t CAN_RxHeaderTypeDef::Timestamp
      

Timestamp captured at the start of reception. Range: 0 to 0xFFFF.

bsp/can_driver/can_hal_def.h:67
结构体

CAN_TxHeaderTypeDef

查看源码

CAN Tx message header structure definition.

成员变量

6

TransmitGlobalTime

变量公开
        FunctionalState CAN_TxHeaderTypeDef::TransmitGlobalTime
      

Enable or disable transmission of the timestamp captured at the start of transmission. Time-triggered communication must be enabled; with DLC set to 8, the timestamp replaces DATA6 and DATA7.

bsp/can_driver/can_hal_def.h:51
结构体

anonymous_namespace{can_driver.cpp}::CAN_CallbackMap

查看源码

CAN 回调函数表 由于 HAL 只允许将一个函数作为回调函数,如果想在一条总线上处理不同种类的 信息(有多个不同的回调函数),就必须要通过一个主回调函数进行分发 STM32 的 CAN mailbox 数量往往有限,但是在很短的时间内可能连续发送多条消息 自带的 mailbox 无法满足要求,故需要做一个软件缓冲区来临时储存溢出的消息

成员变量

4

buffer

变量公开
        libs::RingBuffer<CAN_MessageDef, CAN_TX_QUEUE_SIZE + 1, true> anonymous_namespace{can_driver.cpp}::CAN_CallbackMap::buffer
      

上游未提供说明。

bsp/can_driver/can_driver.cpp:620

callbacks

变量公开
        CAN_FifoReceiveCallback_t anonymous_namespace{can_driver.cpp}::CAN_CallbackMap::callbacks[CAN_MAX_CALLBACK_NUM] [CAN_MAX_CALLBACK_NUM]
      

上游未提供说明。

bsp/can_driver/can_driver.cpp:616
结构体

anonymous_namespace{can_driver.cpp}::CAN_MessageDef

查看源码

储存于软件缓冲区的 CAN 消息类型 包括 TxHeader 和 至多 8 bytes 的数据

成员变量

2

其他公开符号

函数

13

CAN_Fifo0ReceiveCallback

函数
        void CAN_Fifo0ReceiveCallback (CAN_HandleTypeDef *hcan)
      

CAN Rx FIFO0 接收处理函数 hcan can handle 取出 FIFO0 中的所有待处理帧,并分发到该总线上注册的各个回调函数。

bsp/can_driver/can_driver.cpp:795

CAN_Fifo1ReceiveCallback

函数
        void CAN_Fifo1ReceiveCallback (CAN_HandleTypeDef *hcan)
      

CAN Rx FIFO1 接收处理函数 hcan can handle 取出 FIFO1 中的所有待处理帧,并分发到该总线上注册的各个回调函数。

bsp/can_driver/can_driver.cpp:805

CAN_InitMainCallback

函数
        void CAN_InitMainCallback (CAN_HandleTypeDef *hcan)
      

注册 CAN 主回调函数 hcan can handle hcan can handle CAN_Start() 需在 HAL_CAN_Init() 之后、CAN_Start() 之前调用,注册后驱动才能收到接收与发送完成中断。注册接收 FIFO 与三个发送 mailbox 完成回调,需在 HAL_CAN_Init() 之后、之前调用。

bsp/can_driver/can_driver.hpp:131

CAN_InitMainCallback

函数
        void CAN_InitMainCallback (CAN_HandleTypeDef *hcan)
      

注册 CAN 主回调函数 CAN_Start() hcan can handle 注册接收 FIFO 与三个发送 mailbox 完成回调,需在 HAL_CAN_Init() 之后、之前调用。

bsp/can_driver/can_driver.cpp:842

CAN_RegisterCallback

函数
        void CAN_RegisterCallback (CAN_HandleTypeDef *hcan, CAN_FifoReceiveCallback_t callback)
      

注册 CAN 接收回调 hcan can handle callback 接收回调函数,不可为空 hcan can handle callback 回调函数指针,不可为空 非线程安全,建议在总线启动前完成注册 本函数非线程安全,调用时请注意 同一条总线上可以注册多个回调,收到帧后会依次调用。同一条总线上可以注册多个回调,收到帧后会依次调用。

bsp/can_driver/can_driver.hpp:152

CAN_RegisterCallback

函数
        void CAN_RegisterCallback (CAN_HandleTypeDef *hcan, const CAN_FifoReceiveCallback_t callback)
      

注册 CAN 接收回调 本函数非线程安全,调用时请注意 hcan can handle callback 回调函数指针,不可为空 同一条总线上可以注册多个回调,收到帧后会依次调用。

bsp/can_driver/can_driver.cpp:717

CAN_RxDispatch

函数
        void CAN_RxDispatch (CAN_HandleTypeDef *hcan, uint32_t fifo)
      

取消注册 CAN Fifo 处理回调 本函数非线程安全,调用时请注意 hcan can handle filter_match_index 需要取消注册对应的过滤器对应的 id CAN 接收分发 hcan can handle fifo CAN_RX_FIFO0 或 CAN_RX_FIFO1 循环取出指定 FIFO 中的所有帧,并依次调用该总线上注册的各个回调函数。

bsp/can_driver/can_driver.cpp:765

CAN_SendMessage

函数
        uint32_t CAN_SendMessage (CAN_HandleTypeDef *hcan, const CAN_TxHeaderTypeDef *header, const uint8_t data[])
      

发送一条 CAN 消息 hcan can handle header 发送帧头,包含 ID 类型、数据/远程帧标志与 DLC data 待发送数据,长度由 header->DLC 决定(不超过 8 字节) 本函数是线程安全的 发送使用的 mailbox 编号,CAN_SEND_FAILED(0xFFFF) 表示发送失败

bsp/can_driver/can_driver.cpp:647

CAN_SendMessage

函数
        uint32_t CAN_SendMessage (CAN_HandleTypeDef *hcan, const CAN_TxHeaderTypeDef *header, const uint8_t data[])
      

发送一条 CAN 消息 hcan can handle header 发送帧头,包含 ID 类型、数据/远程帧标志与 DLC data 待发送数据,长度由 header->DLC 决定(不超过 8 字节) hcan can handle header 发送帧头,包含 ID 类型、数据/远程帧标志与 DLC data 待发送数据,长度由 header->DLC 决定(不超过 8 字节) 线程安全:内部会短暂关闭中断 DLC 大于 8 时不会发出空帧,直接返回 CAN_SEND_FAILED 成功时返回发送使用的 mailbox 编号(FDCAN 兼容接口返回 0), 失败时返回 CAN_SEND_FAILED 本函数是线程安全的 发送使用的 mailbox 编号,CAN_SEND_FAILED(0xFFFF) 表示发送失败

bsp/can_driver/can_driver.hpp:121

CAN_Start

函数
        void CAN_Start (CAN_HandleTypeDef *hcan, const uint32_t ActiveITs)
      

启动 CAN 并开启中断 hcan can handle ActiveITs 需要额外开启的中断,如 CAN_IT_RX_FIFO0_MSG_PENDING | CAN_IT_RX_FIFO1_MSG_PENDING 驱动会额外开启 CAN_IT_TX_MAILBOX_EMPTY,软件发送队列依赖该中断

bsp/can_driver/can_driver.cpp:693

CAN_Start

函数
        void CAN_Start (CAN_HandleTypeDef *hcan, uint32_t ActiveITs)
      

启动 CAN 并开启中断 hcan can handle ActiveITs can_hal_def.h 需要额外开启的中断,如 CAN_IT_RX_FIFO0_MSG_PENDING | CAN_IT_RX_FIFO1_MSG_PENDING。 bxCAN 后端使用 HAL 原生宏;FDCAN 后端使用提供的兼容 别名(取值等于对应的 FDCAN_IT_*),直接传 FDCAN_IT_* 亦可。 hcan can handle ActiveITs 需要额外开启的中断,如 CAN_IT_RX_FIFO0_MSG_PENDING | CAN_IT_RX_FIFO1_MSG_PENDING 驱动会额外开启发送完成中断,以驱动软件发送队列 驱动会额外开启 CAN_IT_TX_MAILBOX_EMPTY,软件发送队列依赖该中断

bsp/can_driver/can_driver.hpp:142

CAN_TxMailboxCpltCallback

函数
        void CAN_TxMailboxCpltCallback (CAN_HandleTypeDef *hcan)
      

HAL CAN Tx 完成中断回调 hcan can handle 硬件 mailbox 空出后,从软件发送队列中取出待发送帧继续发送。

bsp/can_driver/can_driver.cpp:816

anonymous_namespace{can_driver.cpp}::get_map

函数
        CAN_CallbackMap * anonymous_namespace{can_driver.cpp}::get_map (const CAN_HandleTypeDef *hcan)
      

上游未提供说明。

bsp/can_driver/can_driver.cpp:629

类型定义

1

CAN_FifoReceiveCallback_t

类型定义
        typedef void(* CAN_FifoReceiveCallback_t) (const CAN_HandleTypeDef *hcan, const CAN_RxHeaderTypeDef *header, const uint8_t *data) )(const CAN_HandleTypeDef *hcan, const CAN_RxHeaderTypeDef *header, const uint8_t *data)
      

bxCAN 风格接收回调函数类型 hcan 触发接收的 CAN 句柄 header 接收帧头,包含标准/扩展 ID、数据/远程帧标志与 DLC data 接收数据,有效长度由 header->DLC 决定(不超过 8 字节)

bsp/can_driver/can_driver.hpp:105

变量

2

anonymous_namespace{can_driver.cpp}::map_size

变量
        size_t anonymous_namespace{can_driver.cpp}::map_size
      

当前已登记的回调表数量

bsp/can_driver/can_driver.cpp:626

anonymous_namespace{can_driver.cpp}::maps

变量
        CAN_CallbackMap anonymous_namespace{can_driver.cpp}::maps[CAN_NUM] [CAN_NUM]
      

上游未提供说明。

bsp/can_driver/can_driver.cpp:625

宏定义

21

CAN_IT_RX_FIFO0_MSG_PENDING

宏定义

bxCAN 中断标志兼容别名。取值即对应的 FDCAN_IT_*,因此可以原样传给 FDCAN_Start(),用 bxCAN 接口编写的上层无需改动中断参数。 注意 bxCAN 与 FDCAN 的同名中断位并非一一对应(例如 bxCAN 的 CAN_IT_RX_FIFO0_MSG_PENDING 与 CAN_IT_RX_FIFO0_FULL 都是 0x2, 而 FDCAN 的分别是 0x1 和 0x2),必须通过这些别名而非数值使用。

bsp/can_driver/can_hal_def.h:98

文件

4

bsp/can_driver/can_driver.cpp

文件

syhanjin 2025-09-04This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. https://www.gnu.org/licenses/ You should have received a copy of the GNU General Public License along with this program. If not, see. https://github.com/HITSZ-WTRobot-Packages/BasicComponents Project repository:

bsp/can_driver/can_driver.cpp

bsp/can_driver/can_driver.hpp

文件

CAN wrapper based on HAL library. syhanjin 2025-09-04 定义 HAL_FDCAN_MODULE_ENABLED 时使用 FDCAN 外设,对外提供 FDCAN_* 原生接口, 同时保留仅支持 classic 帧的 CAN_* 兼容接口; 定义 HAL_CAN_MODULE_ENABLED 时使用传统 bxCAN 外设,只提供 CAN_* 接口。 本驱动是对 HAL 库的一层简要封装。根据 HAL 启用的外设自动选择后端: 由于 HAL 对同一事件只允许注册一个回调函数,接收方向统一由主回调进入驱动内部的 回调表,再分发给业务模块注册的多个回调函数(见 CAN_RegisterCallback)。 TODO: 统一化 FDCAN 与 bxCAN 的接口,避免 bxCAN 类 API 与 FDCAN 类 API 互转造成的性能损失 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. https://www.gnu.org/licenses/ You should have received a copy of the GNU General Public License along with this program. If not, see. https://github.com/HITSZ-WTRobot-Packages/BasicComponents Project repository:

bsp/can_driver/can_driver.hpp