新增了CAN变长度数据帧的基本支持
This commit is contained in:
parent
36df442214
commit
cb3f5d92d1
|
@ -86,6 +86,14 @@ void CANTransmit(can_instance *_instance)
|
||||||
HAL_CAN_AddTxMessage(_instance->can_handle, &_instance->txconf, _instance->tx_buff, &_instance->tx_mailbox);
|
HAL_CAN_AddTxMessage(_instance->can_handle, &_instance->txconf, _instance->tx_buff, &_instance->tx_mailbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CANSetDLC(can_instance *_instance, uint8_t length)
|
||||||
|
{
|
||||||
|
if (length > 8)
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
_instance->txconf.DLC = length;
|
||||||
|
}
|
||||||
|
|
||||||
/* -----------------------belows are callback definitions--------------------------*/
|
/* -----------------------belows are callback definitions--------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,11 +110,12 @@ static void CANFIFOxCallback(CAN_HandleTypeDef *_hcan, uint32_t fifox)
|
||||||
HAL_CAN_GetRxMessage(_hcan, fifox, &rxconf, can_rx_buff);
|
HAL_CAN_GetRxMessage(_hcan, fifox, &rxconf, can_rx_buff);
|
||||||
for (size_t i = 0; i < DEVICE_CAN_CNT; i++)
|
for (size_t i = 0; i < DEVICE_CAN_CNT; i++)
|
||||||
{
|
{
|
||||||
if(instance[i]!=NULL)
|
if (instance[i] != NULL)
|
||||||
{
|
{
|
||||||
if (_hcan == instance[i]->can_handle && rxconf.StdId == instance[i]->rx_id)
|
if (_hcan == instance[i]->can_handle && rxconf.StdId == instance[i]->rx_id)
|
||||||
{
|
{
|
||||||
memcpy(instance[i]->rx_buff, can_rx_buff, 8);
|
instance[i]->rx_len=rxconf.DLC;
|
||||||
|
memcpy(instance[i]->rx_buff, can_rx_buff, rxconf.DLC);
|
||||||
instance[i]->can_module_callback(instance[i]);
|
instance[i]->can_module_callback(instance[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ typedef struct _
|
||||||
uint8_t tx_buff[8];
|
uint8_t tx_buff[8];
|
||||||
uint8_t rx_buff[8];
|
uint8_t rx_buff[8];
|
||||||
uint32_t rx_id;
|
uint32_t rx_id;
|
||||||
|
uint8_t rx_len;
|
||||||
void (*can_module_callback)(struct _ *); // callback needs an instance to tell among registered ones
|
void (*can_module_callback)(struct _ *); // callback needs an instance to tell among registered ones
|
||||||
} can_instance;
|
} can_instance;
|
||||||
|
|
||||||
|
@ -49,4 +50,12 @@ void CANTransmit(can_instance *_instance);
|
||||||
*/
|
*/
|
||||||
void CANRegister(can_instance *instance, can_instance_config_s config);
|
void CANRegister(can_instance *instance, can_instance_config_s config);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 修改CAN发送报文的数据帧长度;注意最大长度为8,在没有进行修改的时候,默认长度为8
|
||||||
|
*
|
||||||
|
* @param _instance 要修改长度的can实例
|
||||||
|
* @param length 设定长度
|
||||||
|
*/
|
||||||
|
void CANSetDLC(can_instance *_instance,uint8_t length);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,10 +11,6 @@
|
||||||
|
|
||||||
若你希望新增一个基于CAN的module,首先在该模块下应该有一个包含`can_instance`指针的module结构体(或当功能简单的时候,可以是单独存在的`can_instance`,但不推荐这样做)。
|
若你希望新增一个基于CAN的module,首先在该模块下应该有一个包含`can_instance`指针的module结构体(或当功能简单的时候,可以是单独存在的`can_instance`,但不推荐这样做)。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 代码结构
|
## 代码结构
|
||||||
|
|
||||||
.h文件内包括了外部接口和类型定义,以及模块对应的宏。c文件内为私有函数和外部接口的定义。
|
.h文件内包括了外部接口和类型定义,以及模块对应的宏。c文件内为私有函数和外部接口的定义。
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
<p align='right'>neozng1@hnu.edu.cn</p>
|
<p align='right'>neozng1@hnu.edu.cn</p>
|
||||||
|
|
||||||
双板CAN通信模块
|
> TODO:
|
||||||
|
>
|
||||||
|
> 1. 增加数据长度可变的协议支持
|
||||||
|
> 2. 简化接收流程
|
||||||
|
|
||||||
## 总览和封装说明
|
## 总览和封装说明
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue