Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions bsp/gd32/arm/libraries/gd32_drivers/drv_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,12 +662,74 @@ static rt_ssize_t _can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t
return RT_EOK;
}

rt_ssize_t _can_get_freebox(rt_uint32_t can_x)
{
rt_uint32_t freebox = 0;
if ((CAN_STAT(can_x) & CAN_TSTAT_TME0) != 0U)
{
freebox++;
}
if ((CAN_STAT(can_x) & CAN_TSTAT_TME1) != 0U)
{
freebox++;
}
if ((CAN_STAT(can_x) & CAN_TSTAT_TME2) != 0U)
{
freebox++;
}
return freebox;
}

rt_ssize_t _can_sendmsg_nonblocking(struct rt_can_device *can, const void *buf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不同函数后需要加一个换行

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不同函数后需要加一个换行

已修改

{
RT_ASSERT(can);

can_trasnmit_message_struct transmit_message;
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in variable type / 变量类型拼写错误: The type name contains a typo. It should be can_transmit_message_struct instead of can_trasnmit_message_struct. / 类型名称包含拼写错误,应该是 can_transmit_message_struct 而不是 can_trasnmit_message_struct

Suggested change
can_trasnmit_message_struct transmit_message;
can_transmit_message_struct transmit_message;

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也修改下吧,很有用

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也修改下吧,很有用

这个copilot好像review还是旧的代码,然后你指的修改是
PixPin_2025-10-13_15-05-03
zhegm这个吗,这个gd32的库名字就是这个了,如果修改的话就跟库不匹配了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

官方的编码规范问题,出现过很多次了,需要注意下其他系列是不是也有这个问题,然后从rtt的软件包中统一一下命名

can_struct_para_init(CAN_TX_MESSAGE_STRUCT, &transmit_message);
rt_uint32_t can_x = ((struct gd32_can_device *)can->parent.user_data)->can_x;
struct rt_can_msg *pmsg = (struct rt_can_msg *)buf;

if(_can_get_freebox(can_x) == 0)
{
return -RT_EBUSY;
}
if (RT_CAN_STDID == pmsg->ide)
{
transmit_message.tx_ff = CAN_FF_STANDARD;
transmit_message.tx_sfid = pmsg->id;
}
else
{
transmit_message.tx_ff = CAN_FF_EXTENDED;
transmit_message.tx_efid = pmsg->id;
}

if (RT_CAN_DTR == pmsg->rtr)
{
transmit_message.tx_ft = CAN_FT_DATA;
memcpy(transmit_message.tx_data, pmsg->data, pmsg->len);
}
else
{
transmit_message.tx_ft = CAN_FT_REMOTE;
}

transmit_message.tx_dlen = pmsg->len;
if(can_message_transmit(can_x, &transmit_message) == CAN_NOMAILBOX)
{
return -RT_ERROR;
}

return RT_EOK;
}

static const struct rt_can_ops _can_ops =
{
_can_config,
_can_control,
_can_sendmsg,
_can_recvmsg,
_can_sendmsg_nonblocking,
};

static void _can_rx_isr(struct rt_can_device *can, rt_uint32_t fifo)
Expand Down