[bsp][novosns]:add canfd for novosns_ns800rt7p65#11442
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
|
|
There was a problem hiding this comment.
Pull request overview
This PR updates the NS800RT7P65 (novosns) BSP CAN driver to add CAN-FD support and related control paths, integrating it into RT-Thread’s CAN device framework.
Changes:
- Add CAN-FD configuration support (FD enable, FD baud, bit timing) and dynamic MB data length selection.
- Update TX/RX paths to handle multiple RX mailboxes and add
sendmsg_nonblocking. - Add an error ISR to populate CAN error counters/status.
| /* Validate DLC */ | ||
| RT_ASSERT(IS_CAN_DLC_VALID(pmsg->len)); | ||
|
|
||
| rt_memset(&fdTxMsgObj, 0, sizeof(fdTxMsgObj)); | ||
| fdTxMsgObj.msgBufId = box_no; | ||
|
|
||
| /* Set up the DLC */ | ||
| fdTxMsgObj.dlc = pmsg->len & 0x0FU; | ||
| /* Set up the data field */ | ||
| for(uint8_t i=0u; i<8u; i++) | ||
|
|
||
| /* Determine data length from DLC */ | ||
| #ifdef RT_CAN_USING_CANFD | ||
| data_len = _can_dlc_to_len((rt_uint8_t)(pmsg->len & 0x0FU)); | ||
| fdTxMsgObj.isFd = (pmsg->fd_frame != 0) ? true : false; | ||
| #else | ||
| data_len = (rt_uint8_t)(pmsg->len & 0x0FU); | ||
| if (data_len > 8) { data_len = 8; } | ||
| #endif |
| /* Validate DLC */ | ||
| if (!IS_CAN_DLC_VALID(pmsg->len)) | ||
| { | ||
| return -RT_ERROR; | ||
| } | ||
|
|
||
| return status; | ||
| rt_memset(&fdTxMsgObj, 0, sizeof(fdTxMsgObj)); | ||
| fdTxMsgObj.msgBufId = 0; /* MB0 is the dedicated TX mailbox */ | ||
|
|
||
| fdTxMsgObj.dlc = pmsg->len & 0x0FU; | ||
|
|
||
| #ifdef RT_CAN_USING_CANFD | ||
| data_len = _can_dlc_to_len((rt_uint8_t)(pmsg->len & 0x0FU)); | ||
| fdTxMsgObj.isFd = (pmsg->fd_frame != 0) ? true : false; | ||
| #else | ||
| data_len = (rt_uint8_t)(pmsg->len & 0x0FU); | ||
| if (data_len > 8) { data_len = 8; } | ||
| #endif |
| /* Zero out the message, then fill from hardware frame buffer */ | ||
| rt_memset(pmsg, 0, sizeof(struct rt_can_msg)); | ||
| pmsg->hdr_index = -1; | ||
| pmsg->rxfifo = (rt_uint32_t)fifo; | ||
|
|
||
| /* Select the correct frame buffer: MB1:frame[0], MB2:frame[1] */ | ||
| frame_idx = (fifo >= 1 && fifo <= RX_MB_COUNT) ? (rt_uint8_t)(fifo - 1) : 0; | ||
|
|
||
| /* frame[N].dlc is already converted from DLC code to byte length | ||
| * by FLEXCANDRV_DLC2DataLen() inside FLEXCANDRV_GetRxMsg(). | ||
| * Convert back to DLC code for the RT-Thread message len field. */ | ||
| pmsg->id = frame[frame_idx].msgId; | ||
| #ifdef RT_CAN_USING_CANFD | ||
| pmsg->len = _can_len_to_dlc((rt_uint8_t)frame[frame_idx].dlc); | ||
| #else | ||
| pmsg->len = (rt_uint8_t)frame[frame_idx].dlc; | ||
| if (pmsg->len > 8) { pmsg->len = 8; } | ||
| #endif | ||
|
|
||
| /* Copy frame metadata */ | ||
| #ifdef RT_CAN_USING_CANFD | ||
| pmsg->fd_frame = frame[frame_idx].isFd ? 1 : 0; | ||
| /* BRS is not available from FLEXCANDRV_GetRxMsg() set to 1 for FD frames */ | ||
| pmsg->brs = frame[frame_idx].isFd ? 1 : 0; | ||
| #endif |
| for (i = 0; i < filter_cfg->count; i++) | ||
| { | ||
| struct rt_can_filter_item *item = &filter_cfg->items[i]; | ||
|
|
||
| drv_can->FilterConfig[i].msgBufId = (uint16_t)(item->hdr_bank >= 0 ? item->hdr_bank : i); | ||
| drv_can->FilterConfig[i].msgBufLen = 1; | ||
| drv_can->FilterConfig[i].msgId = item->id; | ||
| drv_can->FilterConfig[i].isExtMsgId = (item->ide == RT_CAN_EXTID); | ||
| drv_can->FilterConfig[i].msgType = FLEXCANDRV_MSGTYPE_RX; /* default RX */ | ||
| drv_can->FilterConfig[i].dlc = DLC_BYTE_8; | ||
| drv_can->FilterConfig[i].isFd = drv_can->device.config.enable_canfd; | ||
| drv_can->FilterConfig[i].intEnable = true; | ||
| drv_can->FilterConfig[i].individualMask = item->mask; | ||
| drv_can->FilterConfig[i].rtrmask = false; | ||
| drv_can->FilterConfig[i].rtrfilter = false; | ||
| } | ||
|
|
||
| drv_can->FilterNum = filter_cfg->count; | ||
| } |
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
参与NS800RT7P65X 的can/canfd驱动相关移植
你的解决方案是什么 (what is your solution)
根据官方的sdk进行了移植
请提供验证的bsp和config (provide the config and bsp)
CONFIG_BSP_USING_CAN=y
CONFIG_BSP_USING_CANFD1=y
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up