mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-05-16 19:57:52 +08:00
feat[can][gd32]: Implement non-blocking send mechanism
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
ToolsCI / Tools (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
ToolsCI / Tools (push) Has been cancelled
This commit is contained in:
@@ -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)
|
||||
{
|
||||
RT_ASSERT(can);
|
||||
|
||||
can_trasnmit_message_struct transmit_message;
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user