[CAN]update struct can_filter_item and rt_can_msg (#6556)
* 修改ry命令,已便于自定义保存路径 * modified: components/utilities/ymodem/ry_sy.c * 修复从被动错误恢复后发送返回异常 * 修复在自动重传模式下,ACK异常阻塞线程 - 删除TX中断函数else分支。仅当RQCP位 置一才进入该中断 - 添加SCE中断函数中关于ACK_ERR的else判断。自动重传模式下会进入该判断,打断自动重传释放完成量。 * 增加对于CAN1与CAN2的SCE中断和TX中断的公共处理函数 * formatting格式化代码 * update struct can_filter_item and rt_can_msg 1. 对过滤器号和索引号结构体定义中同一名称hdr进行重命名hdr_bank和hdr_index, 以便准确区分.采用宏定义兼容以前变量名. 2. 添加接收标识rxfifo,已指明是哪个RXFIFO. * 更正42M下的波特率 * 修复接收获取索引号错误 * 添加接收标识 * 更新注释 * 取消CANFD限制 * update struct can_filter_item and rt_can_msg
This commit is contained in:
parent
84eab69604
commit
569e2ae1e8
|
@ -368,13 +368,13 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
/* get default filter */
|
||||
for (int i = 0; i < filter_cfg->count; i++)
|
||||
{
|
||||
if (filter_cfg->items[i].hdr == -1)
|
||||
if (filter_cfg->items[i].hdr_bank == -1)
|
||||
{
|
||||
can_instance->config.filter_init_struct.filter_number = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
can_instance->config.filter_init_struct.filter_number = filter_cfg->items[i].hdr;
|
||||
can_instance->config.filter_init_struct.filter_number = filter_cfg->items[i].hdr_bank;
|
||||
}
|
||||
/**
|
||||
* ID | CAN_FxR1[31:24] | CAN_FxR1[23:16] | CAN_FxR1[15:8] | CAN_FxR1[7:0] |
|
||||
|
@ -597,7 +597,7 @@ static int _can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t fifo)
|
|||
pmsg->ide = rx_message.extended_id;
|
||||
|
||||
pmsg->rtr = rx_message.frame_type;
|
||||
pmsg->hdr = rx_message.filter_index;
|
||||
pmsg->hdr_index = rx_message.filter_index;
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
|
|
@ -232,8 +232,8 @@ static rt_err_t _can_control(struct rt_can_device *can_device, int cmd, void *ar
|
|||
{
|
||||
|
||||
/*默认过滤表判断*/
|
||||
if(filter_cfg->items[i].hdr < drv_can->device.config.maxhdr)
|
||||
drv_can->FilterConfig.number = filter_cfg->items[i].hdr;
|
||||
if(filter_cfg->items[i].hdr_bank < drv_can->device.config.maxhdr)
|
||||
drv_can->FilterConfig.number = filter_cfg->items[i].hdr_bank;
|
||||
else
|
||||
drv_can->FilterConfig.number = ES_C_CAN_DEFAULT_FILTER_NUMBER;
|
||||
|
||||
|
@ -499,8 +499,8 @@ static int _can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t fifo)
|
|||
}
|
||||
/* get len */
|
||||
pmsg->len = rxheader.len;
|
||||
/* get hdr */
|
||||
pmsg->hdr = (rxheader.fmi + 1) >> 1;
|
||||
/* get hdr_index */
|
||||
pmsg->hdr_index = (rxheader.fmi + 1) >> 1;
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
|
|
@ -225,8 +225,8 @@ static rt_err_t _can_control(struct rt_can_device *can_device, int cmd, void *ar
|
|||
{
|
||||
|
||||
/*默认过滤表判断*/
|
||||
if(filter_cfg->items[i].hdr < drv_can->device.config.maxhdr)
|
||||
drv_can->FilterConfig.number = filter_cfg->items[i].hdr;
|
||||
if(filter_cfg->items[i].hdr_bank < drv_can->device.config.maxhdr)
|
||||
drv_can->FilterConfig.number = filter_cfg->items[i].hdr_bank;
|
||||
else
|
||||
drv_can->FilterConfig.number = ES_C_CAN_DEFAULT_FILTER_NUMBER;
|
||||
|
||||
|
@ -496,8 +496,8 @@ static int _can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t fifo)
|
|||
}
|
||||
/* get len */
|
||||
pmsg->len = rxheader.len;
|
||||
/* get hdr */
|
||||
pmsg->hdr = (rxheader.fmi + 1) >> 1;
|
||||
/* get hdr_index */
|
||||
pmsg->hdr_index = (rxheader.fmi + 1) >> 1;
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
|
|
@ -172,22 +172,22 @@ static uint16_t _get_filter_idx(struct rt_can_filter_config *filter_cfg)
|
|||
|
||||
for (int i = 0; i < filter_cfg->count; i++)
|
||||
{
|
||||
if (filter_cfg->items[i].hdr != -1)
|
||||
if (filter_cfg->items[i].hdr_bank != -1)
|
||||
{
|
||||
u16FilterSelected |= 1 << filter_cfg->items[i].hdr;
|
||||
u16FilterSelected |= 1 << filter_cfg->items[i].hdr_bank;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < filter_cfg->count; i++)
|
||||
{
|
||||
if (filter_cfg->items[i].hdr == -1)
|
||||
if (filter_cfg->items[i].hdr_bank == -1)
|
||||
{
|
||||
for (int j = 0; j < FILTER_COUNT; j++)
|
||||
{
|
||||
if ((u16FilterSelected & 1 << j) == 0)
|
||||
{
|
||||
filter_cfg->items[i].hdr = j;
|
||||
u16FilterSelected |= 1 << filter_cfg->items[i].hdr;
|
||||
filter_cfg->items[i].hdr_bank = j;
|
||||
u16FilterSelected |= 1 << filter_cfg->items[i].hdr_bank;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -435,8 +435,8 @@ static int _can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t fifo)
|
|||
}
|
||||
/* get len */
|
||||
pmsg->len = ll_rx_frame.DLC;
|
||||
/* get hdr */
|
||||
pmsg->hdr = 0;
|
||||
/* get hdr_index */
|
||||
pmsg->hdr_index = 0;
|
||||
rt_memcpy(pmsg->data, &ll_rx_frame.au8Data, ll_rx_frame.DLC);
|
||||
|
||||
return RT_EOK;
|
||||
|
|
|
@ -398,7 +398,7 @@ static rt_err_t hpm_can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
RT_ASSERT(filter->count <= CAN_FILTER_NUM_MAX);
|
||||
for (uint32_t i=0; i<filter->count; i++)
|
||||
{
|
||||
drv_can->filter_list[i].index = (filter->items[i].hdr == -1) ? i : filter->items[i].hdr;
|
||||
drv_can->filter_list[i].index = (filter->items[i].hdr_bank == -1) ? i : filter->items[i].hdr_bank;
|
||||
drv_can->filter_list[i].enable = (filter->actived != 0U) ? true : false;
|
||||
drv_can->filter_list[i].code = filter->items[i].id;
|
||||
drv_can->filter_list[i].id_mode = (filter->items[i].ide != 0U) ? can_filter_id_mode_extended_frames : can_filter_id_mode_standard_frames;
|
||||
|
|
|
@ -299,8 +299,8 @@ static rt_err_t can_control(struct rt_can_device *can_dev, int cmd, void *arg)
|
|||
mbConfig.type = kFLEXCAN_FrameTypeData;
|
||||
}
|
||||
|
||||
/* user does not specify hdr index,set hdr from RX MB 1 */
|
||||
if (item->hdr == -1)
|
||||
/* user does not specify hdr index,set hdr_bank from RX MB 1 */
|
||||
if (item->hdr_bank == -1)
|
||||
{
|
||||
|
||||
for (i = 0; i < 32; i++)
|
||||
|
@ -312,17 +312,17 @@ static rt_err_t can_control(struct rt_can_device *can_dev, int cmd, void *arg)
|
|||
}
|
||||
}
|
||||
}
|
||||
else /* use user specified hdr */
|
||||
else /* use user specified hdr_bank */
|
||||
{
|
||||
if (filter_mask & (1 << item->hdr))
|
||||
if (filter_mask & (1 << item->hdr_bank))
|
||||
{
|
||||
res = RT_ERROR;
|
||||
LOG_E("%s hdr%d filter already set!\n", can->name, item->hdr);
|
||||
LOG_E("%s hdr%d filter already set!\n", can->name, item->hdr_bank);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
index = item->hdr;
|
||||
index = item->hdr_bank;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -463,7 +463,7 @@ static int can_recv(struct rt_can_device *can_dev, void *buf, rt_uint32_t boxno)
|
|||
{
|
||||
pmsg->rtr = RT_CAN_RTR;
|
||||
}
|
||||
pmsg->hdr = index; /* one hdr filter per MB */
|
||||
pmsg->hdr_index = index; /* one hdr filter per MB */
|
||||
pmsg->len = frame[index].length;
|
||||
pmsg->data[0] = frame[index].dataByte0;
|
||||
pmsg->data[1] = frame[index].dataByte1;
|
||||
|
|
|
@ -50,7 +50,7 @@ static rt_err_t bxmodifyfilter(struct ls1c_bxcan *pbxcan, struct rt_can_filter_i
|
|||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
else if (pitem->hdr == -1)
|
||||
else if (pitem->hdr_bank == -1)
|
||||
{
|
||||
res = -1;
|
||||
if (res != RT_EOK)
|
||||
|
@ -58,7 +58,7 @@ static rt_err_t bxmodifyfilter(struct ls1c_bxcan *pbxcan, struct rt_can_filter_i
|
|||
return res;
|
||||
}
|
||||
}
|
||||
else if (pitem->hdr >= 0)
|
||||
else if (pitem->hdr_bank >= 0)
|
||||
{
|
||||
rt_enter_critical();
|
||||
res = RT_EOK;
|
||||
|
@ -66,7 +66,7 @@ static rt_err_t bxmodifyfilter(struct ls1c_bxcan *pbxcan, struct rt_can_filter_i
|
|||
{
|
||||
return res;
|
||||
}
|
||||
hdr = pitem->hdr;
|
||||
hdr = pitem->hdr_bank;
|
||||
rt_exit_critical();
|
||||
}
|
||||
}
|
||||
|
@ -387,7 +387,7 @@ static int recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t boxno)
|
|||
pmsg->id = RxMessage.StdId;
|
||||
pmsg->len = RxMessage.DLC;
|
||||
pmsg->rtr = RxMessage.RTR;
|
||||
pmsg->hdr = 0;
|
||||
pmsg->hdr_index = 0;
|
||||
for(i= 0;i< RxMessage.DLC; i++)
|
||||
{
|
||||
pmsg->data[i] = RxMessage.Data[i];
|
||||
|
|
|
@ -510,7 +510,7 @@ static rt_err_t control(struct rt_can_device *can, int cmd, void *arg)
|
|||
/* Get default filter */
|
||||
for(int i = 0; i < filter_cfg->count; i++)
|
||||
{
|
||||
if (filter_cfg->items[i].hdr == -1)
|
||||
if (filter_cfg->items[i].hdr_bank == -1)
|
||||
{
|
||||
/* Can banks 0~13 */
|
||||
drv_can->FilterConfig.Filter_Num = i;
|
||||
|
@ -518,7 +518,7 @@ static rt_err_t control(struct rt_can_device *can, int cmd, void *arg)
|
|||
else
|
||||
{
|
||||
/* Use user-defined filter bank settings */
|
||||
drv_can->FilterConfig.Filter_Num = filter_cfg->items[i].hdr;
|
||||
drv_can->FilterConfig.Filter_Num = filter_cfg->items[i].hdr_bank;
|
||||
}
|
||||
|
||||
/* Filter groups work in identifier masking bit mode */
|
||||
|
@ -826,22 +826,22 @@ static int can_recvmsg_rtmsg(CAN_Module *CANx, struct rt_can_msg *pmsg, uint32_t
|
|||
pmsg->rtr = RT_CAN_RTR;
|
||||
}
|
||||
|
||||
/* get hdr */
|
||||
/* get hdr_index */
|
||||
#if defined(SOC_N32G45X) || defined(SOC_N32WB452)
|
||||
if (CANx == CAN1)
|
||||
{
|
||||
pmsg->hdr = (RxMessage->FMI + 1) >> 1;
|
||||
pmsg->hdr_index = (RxMessage->FMI + 1) >> 1;
|
||||
}
|
||||
#ifdef CAN2
|
||||
else if (CANx == CAN2)
|
||||
{
|
||||
pmsg->hdr = (RxMessage->FMI + 1) >> 1;
|
||||
pmsg->hdr_index = (RxMessage->FMI + 1) >> 1;
|
||||
}
|
||||
#endif
|
||||
#elif defined(SOC_N32L43X) || defined(SOC_N32L40X) || defined(SOC_N32G43X)
|
||||
if (CANx == CAN)
|
||||
{
|
||||
pmsg->hdr = (RxMessage->FMI + 1) >> 1;
|
||||
pmsg->hdr_index = (RxMessage->FMI + 1) >> 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -361,13 +361,13 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
/* get default filter */
|
||||
for (int i = 0; i < filter_cfg->count; i++)
|
||||
{
|
||||
if (filter_cfg->items[i].hdr == -1)
|
||||
if (filter_cfg->items[i].hdr_bank == -1)
|
||||
{
|
||||
drv_can->can_filter_init.Filter_Num = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
drv_can->can_filter_init.Filter_Num = filter_cfg->items[i].hdr;
|
||||
drv_can->can_filter_init.Filter_Num = filter_cfg->items[i].hdr_bank;
|
||||
}
|
||||
|
||||
if (filter_cfg->items[i].mode == 0x00)
|
||||
|
@ -667,14 +667,14 @@ static int _can_recvmsg_rtmsg(CAN_Module* can_base, struct rt_can_msg *pmsg, uin
|
|||
pmsg->rtr = RT_CAN_RTR;
|
||||
}
|
||||
|
||||
/* get hdr */
|
||||
/* get hdr_index */
|
||||
if (can_base == CAN1)
|
||||
{
|
||||
pmsg->hdr = (RxMessage->FMI + 1) >> 1;
|
||||
pmsg->hdr_index = (RxMessage->FMI + 1) >> 1;
|
||||
}
|
||||
else if (can_base == CAN2)
|
||||
{
|
||||
pmsg->hdr = (RxMessage->FMI >> 1) + 14;
|
||||
pmsg->hdr_index = (RxMessage->FMI >> 1) + 14;
|
||||
}
|
||||
/* Release the DATFIFO */
|
||||
/* Release FIFO0 */
|
||||
|
|
|
@ -309,7 +309,7 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
/*set the filter message object*/
|
||||
if (filter_cfg->items[i].mode == 1)
|
||||
{
|
||||
if (CAN_SetRxMsgObjAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask, FALSE) == FALSE)
|
||||
if (CAN_SetRxMsgObjAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr_bank + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask, FALSE) == FALSE)
|
||||
{
|
||||
return -(RT_ERROR);
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
else
|
||||
{
|
||||
/*set the filter message object*/
|
||||
if (CAN_SetRxMsgAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask) == FALSE)
|
||||
if (CAN_SetRxMsgAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr_bank + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask) == FALSE)
|
||||
{
|
||||
return -(RT_ERROR);
|
||||
}
|
||||
|
@ -507,8 +507,8 @@ static int nu_can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t boxn
|
|||
|
||||
#ifdef RT_CAN_USING_HDR
|
||||
/* Hardware filter messages are valid */
|
||||
pmsg->hdr = boxno - RX_MSG_ID_INDEX;
|
||||
can->hdr[pmsg->hdr].connected = 1;
|
||||
pmsg->hdr_index = boxno - RX_MSG_ID_INDEX;
|
||||
can->hdr[pmsg->hdr_index].connected = 1;
|
||||
#endif
|
||||
|
||||
pmsg->ide = (tMsg.IdType == CAN_STD_ID) ? RT_CAN_STDID : RT_CAN_EXTID;
|
||||
|
|
|
@ -360,7 +360,7 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
/*set the filter message object*/
|
||||
if (filter_cfg->items[i].mode == 1)
|
||||
{
|
||||
if (CAN_SetRxMsgObjAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask, FALSE) == FALSE)
|
||||
if (CAN_SetRxMsgObjAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr_bank + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask, FALSE) == FALSE)
|
||||
{
|
||||
return -(RT_ERROR);
|
||||
}
|
||||
|
@ -368,7 +368,7 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
else
|
||||
{
|
||||
/*set the filter message object*/
|
||||
if (CAN_SetRxMsgAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask) == FALSE)
|
||||
if (CAN_SetRxMsgAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr_bank + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask) == FALSE)
|
||||
{
|
||||
return -(RT_ERROR);
|
||||
}
|
||||
|
@ -558,8 +558,8 @@ static int nu_can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t boxn
|
|||
|
||||
#ifdef RT_CAN_USING_HDR
|
||||
/* Hardware filter messages are valid */
|
||||
pmsg->hdr = boxno - RX_MSG_ID_INDEX;
|
||||
can->hdr[pmsg->hdr].connected = 1;
|
||||
pmsg->hdr_index = boxno - RX_MSG_ID_INDEX;
|
||||
can->hdr[pmsg->hdr_index].connected = 1;
|
||||
#endif
|
||||
|
||||
pmsg->ide = (tMsg.IdType == CAN_STD_ID) ? RT_CAN_STDID : RT_CAN_EXTID;
|
||||
|
|
|
@ -611,8 +611,8 @@ static int nu_canfd_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t bo
|
|||
|
||||
#ifdef RT_CAN_USING_HDR
|
||||
/* Hardware filter messages are valid */
|
||||
pmsg->hdr = boxno;
|
||||
can->hdr[pmsg->hdr].connected = 1;
|
||||
pmsg->hdr_index = boxno;
|
||||
can->hdr[pmsg->hdr_index].connected = 1;
|
||||
#endif
|
||||
|
||||
pmsg->ide = (sRxMsg.eIdType == eCANFD_SID) ? RT_CAN_STDID : RT_CAN_EXTID;
|
||||
|
|
|
@ -309,7 +309,7 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
/*set the filter message object*/
|
||||
if (filter_cfg->items[i].mode == 1)
|
||||
{
|
||||
if (CAN_SetRxMsgObjAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask, FALSE) == FALSE)
|
||||
if (CAN_SetRxMsgObjAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr_bank + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask, FALSE) == FALSE)
|
||||
{
|
||||
return -(RT_ERROR);
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
else
|
||||
{
|
||||
/*set the filter message object*/
|
||||
if (CAN_SetRxMsgAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask) == FALSE)
|
||||
if (CAN_SetRxMsgAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr_bank + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask) == FALSE)
|
||||
{
|
||||
return -(RT_ERROR);
|
||||
}
|
||||
|
@ -507,8 +507,8 @@ static int nu_can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t boxn
|
|||
|
||||
#ifdef RT_CAN_USING_HDR
|
||||
/* Hardware filter messages are valid */
|
||||
pmsg->hdr = boxno - RX_MSG_ID_INDEX;
|
||||
can->hdr[pmsg->hdr].connected = 1;
|
||||
pmsg->hdr_index = boxno - RX_MSG_ID_INDEX;
|
||||
can->hdr[pmsg->hdr_index].connected = 1;
|
||||
#endif
|
||||
|
||||
pmsg->ide = (tMsg.IdType == CAN_STD_ID) ? RT_CAN_STDID : RT_CAN_EXTID;
|
||||
|
|
|
@ -333,7 +333,7 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
/*set the filter message object*/
|
||||
if (filter_cfg->items[i].mode == 1)
|
||||
{
|
||||
if (CAN_SetRxMsgObjAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask, FALSE) == FALSE)
|
||||
if (CAN_SetRxMsgObjAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr_bank + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask, FALSE) == FALSE)
|
||||
{
|
||||
return -(RT_ERROR);
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
else
|
||||
{
|
||||
/*set the filter message object*/
|
||||
if (CAN_SetRxMsgAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask) == FALSE)
|
||||
if (CAN_SetRxMsgAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr_bank + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask) == FALSE)
|
||||
{
|
||||
return -(RT_ERROR);
|
||||
}
|
||||
|
@ -531,8 +531,8 @@ static int nu_can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t boxn
|
|||
|
||||
#ifdef RT_CAN_USING_HDR
|
||||
/* Hardware filter messages are valid */
|
||||
pmsg->hdr = boxno - RX_MSG_ID_INDEX;
|
||||
can->hdr[pmsg->hdr].connected = 1;
|
||||
pmsg->hdr_index = boxno - RX_MSG_ID_INDEX;
|
||||
can->hdr[pmsg->hdr_index].connected = 1;
|
||||
#endif
|
||||
|
||||
pmsg->ide = (tMsg.IdType == CAN_STD_ID) ? RT_CAN_STDID : RT_CAN_EXTID;
|
||||
|
|
|
@ -212,7 +212,7 @@ int ra_can_recvmsg(struct rt_can_device *can_dev, void *buf, rt_uint32_t boxno)
|
|||
msg_rt->rsv = RT_NULL;
|
||||
msg_rt->len = msg_ra->data_length_code;
|
||||
msg_rt->priv = boxno;
|
||||
msg_rt->hdr = RT_NULL;
|
||||
msg_rt->hdr_index = RT_NULL;
|
||||
memcpy(msg_rt->data, msg_ra->data, msg_ra->data_length_code);
|
||||
return sizeof(struct rt_can_msg);
|
||||
}
|
||||
|
|
|
@ -42,14 +42,14 @@ static const struct stm32_baud_rate_tab can_baud_rate_tab[] =
|
|||
static const struct stm32_baud_rate_tab can_baud_rate_tab[] =
|
||||
{
|
||||
{CAN1MBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_4TQ | 3)},
|
||||
{CAN800kBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ | CAN_BS2_5TQ | 4)},
|
||||
{CAN500kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 6)},
|
||||
{CAN250kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 12)},
|
||||
{CAN125kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 24)},
|
||||
{CAN100kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 30)},
|
||||
{CAN50kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 60)},
|
||||
{CAN20kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 150)},
|
||||
{CAN10kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_5TQ | 300)}
|
||||
{CAN800kBaud, (CAN_SJW_2TQ | CAN_BS1_8TQ | CAN_BS2_4TQ | 4)},
|
||||
{CAN500kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_4TQ | 6)},
|
||||
{CAN250kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_4TQ | 12)},
|
||||
{CAN125kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_4TQ | 24)},
|
||||
{CAN100kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_4TQ | 30)},
|
||||
{CAN50kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_4TQ | 60)},
|
||||
{CAN20kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_4TQ | 150)},
|
||||
{CAN10kBaud, (CAN_SJW_2TQ | CAN_BS1_9TQ | CAN_BS2_4TQ | 300)}
|
||||
};
|
||||
#else /* APB1 45MHz(max) */
|
||||
static const struct stm32_baud_rate_tab can_baud_rate_tab[] =
|
||||
|
@ -333,7 +333,7 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
/* get default filter */
|
||||
for (int i = 0; i < filter_cfg->count; i++)
|
||||
{
|
||||
if (filter_cfg->items[i].hdr == -1)
|
||||
if (filter_cfg->items[i].hdr_bank == -1)
|
||||
{
|
||||
/* use default filter bank settings */
|
||||
if (rt_strcmp(drv_can->name, "can1") == 0)
|
||||
|
@ -350,7 +350,7 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
else
|
||||
{
|
||||
/* use user-defined filter bank settings */
|
||||
drv_can->FilterConfig.FilterBank = filter_cfg->items[i].hdr;
|
||||
drv_can->FilterConfig.FilterBank = filter_cfg->items[i].hdr_bank;
|
||||
}
|
||||
/**
|
||||
* ID | CAN_FxR1[31:24] | CAN_FxR1[23:16] | CAN_FxR1[15:8] | CAN_FxR1[7:0] |
|
||||
|
@ -401,6 +401,7 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
drv_can->FilterConfig.FilterMaskIdLow = mask_l;
|
||||
|
||||
drv_can->FilterConfig.FilterMode = filter_cfg->items[i].mode;
|
||||
drv_can->FilterConfig.FilterFIFOAssignment = filter_cfg->items[i].rxfifo;/*rxfifo = CAN_RX_FIFO0/CAN_RX_FIFO1*/
|
||||
/* Filter conf */
|
||||
HAL_CAN_ConfigFilter(&drv_can->CanHandle, &drv_can->FilterConfig);
|
||||
}
|
||||
|
@ -610,17 +611,20 @@ static int _can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t fifo)
|
|||
{
|
||||
pmsg->rtr = RT_CAN_RTR;
|
||||
}
|
||||
/*get rxfifo = CAN_RX_FIFO0/CAN_RX_FIFO1*/
|
||||
pmsg->rxfifo = fifo;
|
||||
|
||||
/* get len */
|
||||
pmsg->len = rxheader.DLC;
|
||||
/* get hdr */
|
||||
/* get hdr_index */
|
||||
if (hcan->Instance == CAN1)
|
||||
{
|
||||
pmsg->hdr = (rxheader.FilterMatchIndex + 1) >> 1;
|
||||
pmsg->hdr_index = rxheader.FilterMatchIndex;
|
||||
}
|
||||
#ifdef CAN2
|
||||
else if (hcan->Instance == CAN2)
|
||||
{
|
||||
pmsg->hdr = (rxheader.FilterMatchIndex >> 1) + 14;
|
||||
pmsg->hdr_index = rxheader.FilterMatchIndex;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ static void can_rx_thread(void *parameter)
|
|||
while (1)
|
||||
{
|
||||
/* hdr 值为 - 1,表示直接从 uselist 链表读取数据 */
|
||||
rxmsg.hdr = -1;
|
||||
v .hdr = -1;
|
||||
/* 阻塞等待接收信号量 */
|
||||
rt_sem_take(&rx_sem, RT_WAITING_FOREVER);
|
||||
/* 从 CAN 读取一帧数据 */
|
||||
|
|
|
@ -226,13 +226,13 @@ static rt_err_t swm_can_control(struct rt_can_device *can_device, int cmd, void
|
|||
/* get default filter */
|
||||
for (int i = 0; i < filter_cfg->count; i++)
|
||||
{
|
||||
if (filter_cfg->items[i].hdr == -1)
|
||||
if (filter_cfg->items[i].hdr_bank == -1)
|
||||
{
|
||||
filter_idx = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
filter_idx = filter_cfg->items[i].hdr;
|
||||
filter_idx = filter_cfg->items[i].hdr_bank;
|
||||
}
|
||||
|
||||
if (filter_cfg->items[i].ide == RT_CAN_STDID)
|
||||
|
|
|
@ -441,14 +441,14 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
|
|||
/* get default filter */
|
||||
for (int i = 0; i < filter_cfg->count; i++)
|
||||
{
|
||||
if (filter_cfg->items[i].hdr == -1)
|
||||
if (filter_cfg->items[i].hdr_bank == -1)
|
||||
{
|
||||
drv_can_obj->can_filter_init.CAN_FilterNumber = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* use user-defined filter bank settings */
|
||||
drv_can_obj->can_filter_init.CAN_FilterNumber = filter_cfg->items[i].hdr;
|
||||
drv_can_obj->can_filter_init.CAN_FilterNumber = filter_cfg->items[i].hdr_bank;
|
||||
}
|
||||
|
||||
if (filter_cfg->items[i].mode == 0x00) //CAN_FILTERMODE_IDMASK
|
||||
|
@ -725,14 +725,14 @@ static int _can_recv_rtmsg(CAN_TypeDef *can_base, struct rt_can_msg *pmsg, uint3
|
|||
pmsg->rtr = RT_CAN_RTR;
|
||||
}
|
||||
|
||||
/* get hdr */
|
||||
/* get hdr_index */
|
||||
if (can_base == CAN1)
|
||||
{
|
||||
pmsg->hdr = (RxMessage->FMI + 1) >> 1;
|
||||
pmsg->hdr_index = (RxMessage->FMI + 1) >> 1;
|
||||
}
|
||||
else if (can_base == CAN2)
|
||||
{
|
||||
pmsg->hdr = (RxMessage->FMI >> 1) + 14;
|
||||
pmsg->hdr_index = (RxMessage->FMI >> 1) + 14;
|
||||
}
|
||||
/* Release FIFO */
|
||||
CAN_FIFORelease(can_base,FIFONum);
|
||||
|
|
|
@ -65,7 +65,7 @@ rt_inline int _can_int_rx(struct rt_can_device *can, struct rt_can_msg *data, in
|
|||
/* disable interrupt */
|
||||
level = rt_hw_interrupt_disable();
|
||||
#ifdef RT_CAN_USING_HDR
|
||||
hdr = data->hdr;
|
||||
hdr = data->hdr_index;
|
||||
|
||||
if (hdr >= 0 && can->hdr && hdr < can->config.maxhdr && !rt_list_isempty(&can->hdr[hdr].list))
|
||||
{
|
||||
|
@ -581,7 +581,7 @@ static rt_err_t rt_can_control(struct rt_device *dev,
|
|||
{
|
||||
while (count)
|
||||
{
|
||||
if (pitem->hdr >= can->config.maxhdr || pitem->hdr < 0)
|
||||
if (pitem->hdr_bank >= can->config.maxhdr || pitem->hdr_bank < 0)
|
||||
{
|
||||
count--;
|
||||
pitem++;
|
||||
|
@ -589,15 +589,15 @@ static rt_err_t rt_can_control(struct rt_device *dev,
|
|||
}
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
if (!can->hdr[pitem->hdr].connected)
|
||||
if (!can->hdr[pitem->hdr_bank].connected)
|
||||
{
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_memcpy(&can->hdr[pitem->hdr].filter, pitem,
|
||||
rt_memcpy(&can->hdr[pitem->hdr_bank].filter, pitem,
|
||||
sizeof(struct rt_can_filter_item));
|
||||
level = rt_hw_interrupt_disable();
|
||||
can->hdr[pitem->hdr].connected = 1;
|
||||
can->hdr[pitem->hdr].msgs = 0;
|
||||
rt_list_init(&can->hdr[pitem->hdr].list);
|
||||
can->hdr[pitem->hdr_bank].connected = 1;
|
||||
can->hdr[pitem->hdr_bank].msgs = 0;
|
||||
rt_list_init(&can->hdr[pitem->hdr_bank].list);
|
||||
}
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
|
@ -609,7 +609,7 @@ static rt_err_t rt_can_control(struct rt_device *dev,
|
|||
{
|
||||
while (count)
|
||||
{
|
||||
if (pitem->hdr >= can->config.maxhdr || pitem->hdr < 0)
|
||||
if (pitem->hdr_bank >= can->config.maxhdr || pitem->hdr_bank < 0)
|
||||
{
|
||||
count--;
|
||||
pitem++;
|
||||
|
@ -617,16 +617,16 @@ static rt_err_t rt_can_control(struct rt_device *dev,
|
|||
}
|
||||
level = rt_hw_interrupt_disable();
|
||||
|
||||
if (can->hdr[pitem->hdr].connected)
|
||||
if (can->hdr[pitem->hdr_bank].connected)
|
||||
{
|
||||
can->hdr[pitem->hdr].connected = 0;
|
||||
can->hdr[pitem->hdr].msgs = 0;
|
||||
if (!rt_list_isempty(&can->hdr[pitem->hdr].list))
|
||||
can->hdr[pitem->hdr_bank].connected = 0;
|
||||
can->hdr[pitem->hdr_bank].msgs = 0;
|
||||
if (!rt_list_isempty(&can->hdr[pitem->hdr_bank].list))
|
||||
{
|
||||
rt_list_remove(can->hdr[pitem->hdr].list.next);
|
||||
rt_list_remove(can->hdr[pitem->hdr_bank].list.next);
|
||||
}
|
||||
rt_hw_interrupt_enable(level);
|
||||
rt_memset(&can->hdr[pitem->hdr].filter, 0,
|
||||
rt_memset(&can->hdr[pitem->hdr_bank].filter, 0,
|
||||
sizeof(struct rt_can_filter_item));
|
||||
}
|
||||
else
|
||||
|
@ -829,7 +829,7 @@ void rt_hw_can_isr(struct rt_can_device *can, int event)
|
|||
level = rt_hw_interrupt_disable();
|
||||
rt_list_insert_before(&rx_fifo->uselist, &listmsg->list);
|
||||
#ifdef RT_CAN_USING_HDR
|
||||
hdr = tmpmsg.hdr;
|
||||
hdr = tmpmsg.hdr_index;
|
||||
if (can->hdr != RT_NULL)
|
||||
{
|
||||
RT_ASSERT(hdr < can->config.maxhdr && hdr >= 0);
|
||||
|
|
|
@ -63,6 +63,12 @@ enum CANBAUD
|
|||
#define RT_CAN_MODE_PRIV 0x01
|
||||
#define RT_CAN_MODE_NOPRIV 0x00
|
||||
|
||||
/** @defgroup CAN_receive_FIFO_number CAN Receive FIFO Number
|
||||
* @{
|
||||
*/
|
||||
#define CAN_RX_FIFO0 (0x00000000U) /*!< CAN receive FIFO 0 */
|
||||
#define CAN_RX_FIFO1 (0x00000001U) /*!< CAN receive FIFO 1 */
|
||||
|
||||
struct rt_can_filter_item
|
||||
{
|
||||
rt_uint32_t id : 29;
|
||||
|
@ -70,16 +76,18 @@ struct rt_can_filter_item
|
|||
rt_uint32_t rtr : 1;
|
||||
rt_uint32_t mode : 1;
|
||||
rt_uint32_t mask;
|
||||
rt_int32_t hdr;
|
||||
rt_int32_t hdr_bank;/*Should be defined as:rx.FilterBank,which should be changed to rt_int32_t hdr_bank*/
|
||||
rt_uint32_t rxfifo;/*Add a configuration item that CAN_RX_FIFO0/CAN_RX_FIFO1*/
|
||||
#ifdef RT_CAN_USING_HDR
|
||||
rt_err_t (*ind)(rt_device_t dev, void *args , rt_int32_t hdr, rt_size_t size);
|
||||
void *args;
|
||||
#endif /*RT_CAN_USING_HDR*/
|
||||
};
|
||||
|
||||
|
||||
#ifdef RT_CAN_USING_HDR
|
||||
#define RT_CAN_FILTER_ITEM_INIT(id,ide,rtr,mode,mask,ind,args) \
|
||||
{(id), (ide), (rtr), (mode), (mask), -1, (ind), (args)}
|
||||
{(id), (ide), (rtr), (mode),(mask), -1, CAN_RX_FIFO0,(ind), (args)}/*0:CAN_RX_FIFO0*/
|
||||
#define RT_CAN_FILTER_STD_INIT(id,ind,args) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,0,0,0,0xFFFFFFFF,ind,args)
|
||||
#define RT_CAN_FILTER_EXT_INIT(id,ind,args) \
|
||||
|
@ -95,7 +103,7 @@ struct rt_can_filter_item
|
|||
#else
|
||||
|
||||
#define RT_CAN_FILTER_ITEM_INIT(id,ide,rtr,mode,mask) \
|
||||
{(id), (ide), (rtr), (mode), (mask), -1, }
|
||||
{(id), (ide), (rtr), (mode), (mask), -1, CAN_RX_FIFO0 }/*0:CAN_RX_FIFO0*/
|
||||
#define RT_CAN_FILTER_STD_INIT(id) \
|
||||
RT_CAN_FILTER_ITEM_INIT(id,0,0,0,0xFFFFFFFF)
|
||||
#define RT_CAN_FILTER_EXT_INIT(id) \
|
||||
|
@ -269,6 +277,7 @@ typedef struct rt_can_device *rt_can_t;
|
|||
#define RT_CAN_RTR 1
|
||||
|
||||
typedef struct rt_can_status *rt_can_status_t;
|
||||
|
||||
struct rt_can_msg
|
||||
{
|
||||
rt_uint32_t id : 29;
|
||||
|
@ -277,12 +286,14 @@ struct rt_can_msg
|
|||
rt_uint32_t rsv : 1;
|
||||
rt_uint32_t len : 8;
|
||||
rt_uint32_t priv : 8;
|
||||
rt_int32_t hdr : 8;
|
||||
rt_int32_t hdr_index : 8;/*Should be defined as:rx.FilterMatchIndex,which should be changed to rt_int32_t hdr_index : 8*/
|
||||
#ifdef RT_CAN_USING_CANFD
|
||||
rt_uint32_t fd_frame : 1;
|
||||
rt_uint32_t reserved : 7;
|
||||
rt_uint32_t rxfifo : 2;/*Redefined to return :CAN RX FIFO0/CAN RX FIFO1*/
|
||||
rt_uint32_t reserved : 5;
|
||||
#else
|
||||
rt_uint32_t reserved : 8;
|
||||
rt_uint32_t rxfifo : 2;/*Redefined to return :CAN RX FIFO0/CAN RX FIFO1*/
|
||||
rt_uint32_t reserved : 6;
|
||||
#endif
|
||||
#ifdef RT_CAN_USING_CANFD
|
||||
rt_uint8_t data[64];
|
||||
|
|
Loading…
Reference in New Issue