-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[update] components: drivers: can: add RT_CAN_CMD_SET_SENDMODE for no… #11070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| * 2015-05-14 aubrcool@qq.com first version | ||
| * 2015-07-06 Bernard code cleanup and remove RT_CAN_USING_LED; | ||
| * 2025-09-20 wdfk_prog Implemented non-blocking, ISR-safe send logic unified under rt_device_write. | ||
| * 2025-12-17 RCSN Support global send mode control, enable TX completion callback via RT_CAN_CMD_SET_SENDMODE | ||
| */ | ||
|
|
||
| #include <rthw.h> | ||
|
|
@@ -652,7 +653,7 @@ static rt_ssize_t rt_can_write(struct rt_device *dev, | |
| * 1. Called from within an interrupt context. | ||
| * 2. Called from a thread, but the user explicitly set the nonblocking flag on the first message. | ||
| */ | ||
| if (rt_interrupt_get_nest() > 0 || pmsg->nonblocking) | ||
| if (rt_interrupt_get_nest() > 0 || pmsg->nonblocking || can->send_mode_nonblocking) | ||
| { | ||
| return _can_nonblocking_tx(can, pmsg, size); | ||
| } | ||
|
|
@@ -1097,12 +1098,30 @@ void rt_hw_can_isr(struct rt_can_device *can, int event) | |
| { | ||
| struct rt_can_tx_fifo *tx_fifo; | ||
| rt_uint32_t no; | ||
| struct rt_device *device; | ||
| no = event >> 8; | ||
| tx_fifo = (struct rt_can_tx_fifo *) can->can_tx; | ||
| RT_ASSERT(tx_fifo != RT_NULL); | ||
|
|
||
| if (can->status.sndchange&(1<<no)) | ||
| /** | ||
| * @brief Handle blocking (synchronous) send completion notification. | ||
| * | ||
| * This section is ONLY executed for blocking (synchronous) send operations. | ||
| * Specifically: | ||
| * 1. The sndchange flag is set ONLY by blocking send functions (_can_int_tx, _can_int_tx_priv) | ||
| * to indicate that there is an ongoing blocking operation waiting for this mailbox. | ||
| * 2. For non-blocking sends, the sndchange flag is NOT set, so this condition is skipped. | ||
| * 3. When a blocking send completes (via interrupt), we: | ||
| * - Store the result (OK or ERR) in tx_fifo->buffer[no].result | ||
| * - Wake up the blocked thread using rt_completion_done() | ||
| * - The blocked thread then checks the result and resumes execution | ||
| * | ||
| * Non-blocking sends are handled separately by the tx_complete callback | ||
| * (see the send_mode_nonblocking section below). | ||
| */ | ||
| if (can->status.sndchange & (1<<no)) | ||
| { | ||
| /* Update the transmission result based on the event type */ | ||
| if ((event & 0xff) == RT_CAN_EVENT_TX_DONE) | ||
| { | ||
| tx_fifo->buffer[no].result = RT_CAN_SND_RESULT_OK; | ||
|
|
@@ -1111,11 +1130,19 @@ void rt_hw_can_isr(struct rt_can_device *can, int event) | |
| { | ||
| tx_fifo->buffer[no].result = RT_CAN_SND_RESULT_ERR; | ||
| } | ||
|
|
||
| /* Wake up the blocked thread waiting on this mailbox's completion */ | ||
| rt_completion_done(&(tx_fifo->buffer[no].completion)); | ||
| } | ||
|
|
||
| if (can->ops->sendmsg_nonblocking != RT_NULL) | ||
| } | ||
|
||
| else if (can->ops->sendmsg_nonblocking != RT_NULL) | ||
|
Comment on lines
+1136
to
+1137
|
||
| { | ||
| if (can->send_mode_nonblocking == 1) { | ||
|
||
| device = &(can->parent); | ||
| if (device->tx_complete != RT_NULL) | ||
| { | ||
| device->tx_complete(device, RT_NULL); | ||
|
Comment on lines
+1140
to
+1143
|
||
| } | ||
| } | ||
|
Comment on lines
+1139
to
+1145
|
||
| while (RT_TRUE) | ||
| { | ||
| struct rt_can_msg msg_to_send; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| * 2015-07-06 Bernard remove RT_CAN_USING_LED. | ||
| * 2022-05-08 hpmicro add CANFD support, fixed typos | ||
| * 2025-09-20 wdfk_prog Added non-blocking send mechanism APIs and data structures. | ||
| * 2025-12-17 RCSN Added send_mode_nonblocking and RT_CAN_CMD_SET_SENDMODE for TX completion callback control | ||
| */ | ||
|
|
||
| #ifndef __DEV_CAN_H_ | ||
|
|
@@ -417,6 +418,7 @@ struct rt_can_ops; | |
| #define RT_CAN_CMD_SET_BAUD_FD 0x1B | ||
| #define RT_CAN_CMD_SET_BITTIMING 0x1C | ||
| #define RT_CAN_CMD_START 0x1D | ||
| #define RT_CAN_CMD_SET_SENDMODE 0x1E | ||
|
||
|
|
||
| #define RT_DEVICE_CAN_INT_ERR 0x1000 | ||
|
|
||
|
|
@@ -563,6 +565,7 @@ struct rt_can_device | |
| #else | ||
| rt_uint8_t nb_tx_rb_pool[RT_CAN_NB_TX_FIFO_SIZE]; /**< The statically allocated pool for the non-blocking TX ring buffer. */ | ||
| #endif /* RT_CAN_MALLOC_NB_TX_BUFFER */ | ||
| rt_uint8_t send_mode_nonblocking; /**< Global send mode: 0=Blocking (default), 1=Non-blocking. */ | ||
|
||
| }; | ||
| typedef struct rt_can_device *rt_can_t; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Spelling/拼写]: Extra blank line after condition check / 条件检查后有多余的空行
English: There is an unnecessary blank line at line 1133 after the closing brace. According to RT-Thread coding standards, avoid extra blank lines within function blocks unless separating logical sections.
中文:第 1133 行的右大括号后有一个不必要的空行。根据 RT-Thread 编码标准,除非分隔逻辑部分,否则应避免在函数块内使用额外的空行。