mirror of
https://gitee.com/dlmu-cone/tronone-h7-scaffold
synced 2026-07-24 19:37:45 +08:00
changed bsp_fdcan.c/bsp_fdcan.h
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#ifndef __BSP_FDCAN_H__
|
||||
#define __BSP_FDCAN_H__
|
||||
|
||||
#include "main.h"
|
||||
#include "fdcan.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define hcan_t FDCAN_HandleTypeDef
|
||||
|
||||
#define CAN_MX_REGISTER_CNT 16 // 最大CAN设备注册数量
|
||||
#define CAN_MX_REGISTER_CNT 16 // 最大FDCAN设备注册数量
|
||||
#define MX_CAN_FILTER_CNT (3 * 14) // 最多可以使用的CAN过滤器数量,支持3个CAN
|
||||
#define DEVICE_CAN_CNT 3 // FDCAN1, FDCAN2, FDCAN3
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
/* FDCAN实例结构体,每个注册到FDCAN的模块都应该有这个变量 */
|
||||
#pragma pack(1)
|
||||
typedef struct _
|
||||
typedef struct _FDCANInstance
|
||||
{
|
||||
FDCAN_HandleTypeDef *can_handle; // FDCAN句柄
|
||||
FDCAN_TxHeaderTypeDef txconf; // FDCAN报文发送配置
|
||||
@@ -36,7 +36,7 @@ typedef struct _
|
||||
uint32_t rx_id; // 接收id
|
||||
uint8_t rx_len; // 接收长度
|
||||
// 接收的回调函数,用于解析接收到的数据
|
||||
void (*can_module_callback)(struct _ *); // 回调函数需要实例来区分注册的设备
|
||||
void (*can_module_callback)(struct _FDCANInstance *); // 回调函数需要实例来区分注册的设备
|
||||
void *id; // 使用FDCAN外设的模块指针
|
||||
} FDCANInstance;
|
||||
#pragma pack()
|
||||
@@ -67,9 +67,13 @@ void FDCANSetDLC(FDCANInstance *_instance, uint8_t length);
|
||||
|
||||
/**
|
||||
* @brief 通过FDCAN实例发送消息
|
||||
* 发送前需要向FDCAN实例的tx_buff写入发送数据
|
||||
*
|
||||
* @attention 超时时间不应该超过调用此函数的任务的周期,否则会导致任务阻塞
|
||||
*
|
||||
* @param _instance 模块拥有的FDCAN实例
|
||||
* @param timeout 超时时间,单位为ms
|
||||
* @return uint8_t 发送成功返回1,失败返回0
|
||||
* @param timeout 超时时间,单位为ms
|
||||
* @return uint8_t 发送成功返回1,失败返回0
|
||||
*/
|
||||
uint8_t FDCANTransmit(FDCANInstance *_instance, float timeout);
|
||||
|
||||
@@ -79,7 +83,7 @@ uint8_t FDCANTransmit(FDCANInstance *_instance, float timeout);
|
||||
* @param mode CAN模式:CAN_CLASS或CAN_FD_BRS
|
||||
* @param baud 波特率选择
|
||||
*/
|
||||
void bsp_fdcan_set_baud(hcan_t *hfdcan, uint8_t mode, uint8_t baud);
|
||||
void bsp_fdcan_set_baud(FDCAN_HandleTypeDef *hfdcan, uint8_t mode, uint8_t baud);
|
||||
|
||||
// 弱定义的接收回调函数,用户可重写
|
||||
__weak void fdcan1_rx_callback(void);
|
||||
|
||||
Reference in New Issue
Block a user