|
1 | 1 | /* |
2 | | - * Copyright (c) 2006-2024 RT-Thread Development Team |
| 2 | + * Copyright (c) 2006-2025, RT-Thread Development Team |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | * |
@@ -165,8 +165,17 @@ rt_inline int _can_int_tx(struct rt_can_device *can, const struct rt_can_msg *da |
165 | 165 | goto err_ret; |
166 | 166 | } |
167 | 167 |
|
168 | | - can->status.sndchange = 1; |
169 | | - rt_completion_wait(&(tx_tosnd->completion), RT_WAITING_FOREVER); |
| 168 | + can->status.sndchange |= 1<<no; |
| 169 | + |
| 170 | + if( rt_completion_wait(&(tx_tosnd->completion), RT_CANSND_MSG_TIMEOUT)!=RT_EOK) |
| 171 | + { |
| 172 | + level = rt_hw_interrupt_disable(); |
| 173 | + rt_list_insert_before(&tx_fifo->freelist, &tx_tosnd->list); |
| 174 | + can->status.sndchange &= ~ (1<<no); |
| 175 | + rt_hw_interrupt_enable(level); |
| 176 | + rt_sem_release(&(tx_fifo->sem)); |
| 177 | + goto err_ret; |
| 178 | + } |
170 | 179 |
|
171 | 180 | level = rt_hw_interrupt_disable(); |
172 | 181 | 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 |
237 | 246 | { |
238 | 247 | continue; |
239 | 248 | } |
240 | | - can->status.sndchange = 1; |
241 | | - rt_completion_wait(&(tx_fifo->buffer[no].completion), RT_WAITING_FOREVER); |
| 249 | + can->status.sndchange |= 1<<no; |
| 250 | + if(rt_completion_wait(&(tx_fifo->buffer[no].completion), RT_CANSND_MSG_TIMEOUT)!= RT_EOK) |
| 251 | + { |
| 252 | + can->status.sndchange &= ~ (1<<no); |
| 253 | + continue; |
| 254 | + } |
242 | 255 |
|
243 | 256 | result = tx_fifo->buffer[no].result; |
244 | 257 | if (result == RT_CAN_SND_RESULT_OK) |
@@ -892,16 +905,18 @@ void rt_hw_can_isr(struct rt_can_device *can, int event) |
892 | 905 | no = event >> 8; |
893 | 906 | tx_fifo = (struct rt_can_tx_fifo *) can->can_tx; |
894 | 907 | RT_ASSERT(tx_fifo != RT_NULL); |
895 | | - |
896 | | - if ((event & 0xff) == RT_CAN_EVENT_TX_DONE) |
| 908 | + if (can->status.sndchange&(1<<no)) |
897 | 909 | { |
898 | | - tx_fifo->buffer[no].result = RT_CAN_SND_RESULT_OK; |
899 | | - } |
900 | | - else |
901 | | - { |
902 | | - tx_fifo->buffer[no].result = RT_CAN_SND_RESULT_ERR; |
| 910 | + if ((event & 0xff) == RT_CAN_EVENT_TX_DONE) |
| 911 | + { |
| 912 | + tx_fifo->buffer[no].result = RT_CAN_SND_RESULT_OK; |
| 913 | + } |
| 914 | + else |
| 915 | + { |
| 916 | + tx_fifo->buffer[no].result = RT_CAN_SND_RESULT_ERR; |
| 917 | + } |
| 918 | + rt_completion_done(&(tx_fifo->buffer[no].completion)); |
903 | 919 | } |
904 | | - rt_completion_done(&(tx_fifo->buffer[no].completion)); |
905 | 920 | break; |
906 | 921 | } |
907 | 922 | } |
@@ -972,3 +987,4 @@ int cmd_canstat(int argc, void **argv) |
972 | 987 | } |
973 | 988 | MSH_CMD_EXPORT_ALIAS(cmd_canstat, canstat, stat can device status); |
974 | 989 | #endif |
| 990 | + |
0 commit comments