|
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,16 @@ 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 | + if (rt_completion_wait(&(tx_tosnd->completion), RT_CANSND_MSG_TIMEOUT) != RT_EOK) |
| 170 | + { |
| 171 | + level = rt_hw_interrupt_disable(); |
| 172 | + rt_list_insert_before(&tx_fifo->freelist, &tx_tosnd->list); |
| 173 | + can->status.sndchange &= ~ (1<<no); |
| 174 | + rt_hw_interrupt_enable(level); |
| 175 | + rt_sem_release(&(tx_fifo->sem)); |
| 176 | + goto err_ret; |
| 177 | + } |
170 | 178 |
|
171 | 179 | level = rt_hw_interrupt_disable();
|
172 | 180 | result = tx_tosnd->result;
|
@@ -237,8 +245,12 @@ rt_inline int _can_int_tx_priv(struct rt_can_device *can, const struct rt_can_ms
|
237 | 245 | {
|
238 | 246 | continue;
|
239 | 247 | }
|
240 |
| - can->status.sndchange = 1; |
241 |
| - rt_completion_wait(&(tx_fifo->buffer[no].completion), RT_WAITING_FOREVER); |
| 248 | + can->status.sndchange |= 1<<no; |
| 249 | + if (rt_completion_wait(&(tx_fifo->buffer[no].completion), RT_CANSND_MSG_TIMEOUT) != RT_EOK) |
| 250 | + { |
| 251 | + can->status.sndchange &= ~ (1<<no); |
| 252 | + continue; |
| 253 | + } |
242 | 254 |
|
243 | 255 | result = tx_fifo->buffer[no].result;
|
244 | 256 | if (result == RT_CAN_SND_RESULT_OK)
|
@@ -892,16 +904,18 @@ void rt_hw_can_isr(struct rt_can_device *can, int event)
|
892 | 904 | no = event >> 8;
|
893 | 905 | tx_fifo = (struct rt_can_tx_fifo *) can->can_tx;
|
894 | 906 | RT_ASSERT(tx_fifo != RT_NULL);
|
895 |
| - |
896 |
| - if ((event & 0xff) == RT_CAN_EVENT_TX_DONE) |
| 907 | + if (can->status.sndchange&(1<<no)) |
897 | 908 | {
|
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; |
| 909 | + if ((event & 0xff) == RT_CAN_EVENT_TX_DONE) |
| 910 | + { |
| 911 | + tx_fifo->buffer[no].result = RT_CAN_SND_RESULT_OK; |
| 912 | + } |
| 913 | + else |
| 914 | + { |
| 915 | + tx_fifo->buffer[no].result = RT_CAN_SND_RESULT_ERR; |
| 916 | + } |
| 917 | + rt_completion_done(&(tx_fifo->buffer[no].completion)); |
903 | 918 | }
|
904 |
| - rt_completion_done(&(tx_fifo->buffer[no].completion)); |
905 | 919 | break;
|
906 | 920 | }
|
907 | 921 | }
|
@@ -972,3 +986,4 @@ int cmd_canstat(int argc, void **argv)
|
972 | 986 | }
|
973 | 987 | MSH_CMD_EXPORT_ALIAS(cmd_canstat, canstat, stat can device status);
|
974 | 988 | #endif
|
| 989 | + |
0 commit comments