From 3c3acb93f7539b1a0733eac6120d3f8f806ba030 Mon Sep 17 00:00:00 2001 From: liuyucai <1486344514@qq.com> Date: Tue, 29 Jul 2025 10:15:03 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20:drivers/can/dev=5Fcan.c=20?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8DCAN=E5=BA=95=E5=B1=82=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=97=B6=E5=AF=BC=E8=87=B4=E8=B0=83=E7=94=A8?= =?UTF-8?q?=20=5Fcan=5Fint=5Ftx=20=E7=9A=84=E7=BA=BF=E7=A8=8B=E4=B8=80?= =?UTF-8?q?=E7=9B=B4=E6=8C=82=E8=B5=B7=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Solution: 使用 can->status.sndchange 的bit位来表示某个发送邮箱超时 如果超时 底层驱动再通知tx_done或者tx_fail事件时不予处理 Signed-off-by: Yucai Liu <1486344514@qq.com> --- components/drivers/can/dev_can.c | 42 ++++++++++++++------ components/drivers/include/drivers/dev_can.h | 6 ++- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/components/drivers/can/dev_can.c b/components/drivers/can/dev_can.c index 186f1138284..8d7ac501247 100644 --- a/components/drivers/can/dev_can.c +++ b/components/drivers/can/dev_can.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2024 RT-Thread Development Team + * Copyright (c) 2006-2025, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -165,8 +165,17 @@ rt_inline int _can_int_tx(struct rt_can_device *can, const struct rt_can_msg *da goto err_ret; } - can->status.sndchange = 1; - rt_completion_wait(&(tx_tosnd->completion), RT_WAITING_FOREVER); + can->status.sndchange |= 1<completion), RT_CANSND_MSG_TIMEOUT)!=RT_EOK) + { + level = rt_hw_interrupt_disable(); + rt_list_insert_before(&tx_fifo->freelist, &tx_tosnd->list); + can->status.sndchange &= ~ (1<sem)); + goto err_ret; + } level = rt_hw_interrupt_disable(); result = tx_tosnd->result; @@ -237,8 +246,12 @@ rt_inline int _can_int_tx_priv(struct rt_can_device *can, const struct rt_can_ms { continue; } - can->status.sndchange = 1; - rt_completion_wait(&(tx_fifo->buffer[no].completion), RT_WAITING_FOREVER); + can->status.sndchange |= 1<buffer[no].completion), RT_CANSND_MSG_TIMEOUT)!= RT_EOK) + { + can->status.sndchange &= ~ (1<buffer[no].result; if (result == RT_CAN_SND_RESULT_OK) @@ -892,16 +905,18 @@ void rt_hw_can_isr(struct rt_can_device *can, int event) no = event >> 8; tx_fifo = (struct rt_can_tx_fifo *) can->can_tx; RT_ASSERT(tx_fifo != RT_NULL); - - if ((event & 0xff) == RT_CAN_EVENT_TX_DONE) + if (can->status.sndchange&(1<buffer[no].result = RT_CAN_SND_RESULT_OK; - } - else - { - tx_fifo->buffer[no].result = RT_CAN_SND_RESULT_ERR; + if ((event & 0xff) == RT_CAN_EVENT_TX_DONE) + { + tx_fifo->buffer[no].result = RT_CAN_SND_RESULT_OK; + } + else + { + tx_fifo->buffer[no].result = RT_CAN_SND_RESULT_ERR; + } + rt_completion_done(&(tx_fifo->buffer[no].completion)); } - rt_completion_done(&(tx_fifo->buffer[no].completion)); break; } } @@ -972,3 +987,4 @@ int cmd_canstat(int argc, void **argv) } MSH_CMD_EXPORT_ALIAS(cmd_canstat, canstat, stat can device status); #endif + diff --git a/components/drivers/include/drivers/dev_can.h b/components/drivers/include/drivers/dev_can.h index 35755dead03..81ea0927edb 100644 --- a/components/drivers/include/drivers/dev_can.h +++ b/components/drivers/include/drivers/dev_can.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2024 RT-Thread Development Team + * Copyright (c) 2006-2025, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -21,6 +21,9 @@ #ifndef RT_CANSND_BOX_NUM #define RT_CANSND_BOX_NUM 1 #endif +#ifndef RT_CANSND_MSG_TIMEOUT +#define RT_CANSND_MSG_TIMEOUT 100 +#endif enum CAN_DLC { @@ -541,3 +544,4 @@ void rt_hw_can_isr(struct rt_can_device *can, int event); /*! @}*/ #endif /*__DEV_CAN_H*/ +