-
Notifications
You must be signed in to change notification settings - Fork 5.4k
fix(can): 连续多包发送,是传输顺序与应用层调用一致 #11270
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
Open
meng-plus
wants to merge
1
commit into
RT-Thread:master
Choose a base branch
from
meng-plus:fix.can
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+33
−28
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -229,7 +229,7 @@ rt_inline int _can_int_tx(struct rt_can_device *can, const struct rt_can_msg *da | |
| } | ||
| else | ||
| { | ||
| err_ret: | ||
| err_ret: | ||
| level = rt_hw_local_irq_disable(); | ||
| can->status.dropedsndpkg++; | ||
| rt_hw_local_irq_enable(level); | ||
|
|
@@ -345,34 +345,41 @@ static rt_ssize_t _can_nonblocking_tx(struct rt_can_device *can, const struct rt | |
| { | ||
| return -RT_EINVAL; | ||
| } | ||
|
|
||
| level = rt_hw_local_irq_disable(); | ||
| while (sent_size < size) | ||
| { | ||
| if (can->ops->sendmsg_nonblocking(can, pmsg) == RT_EOK) | ||
| if (rt_ringbuffer_data_len(&can->nb_tx_rb) >= sizeof(struct rt_can_msg)) | ||
| { | ||
| pmsg++; | ||
| sent_size += sizeof(struct rt_can_msg); | ||
| continue; | ||
| if (rt_ringbuffer_space_len(&can->nb_tx_rb) >= sizeof(struct rt_can_msg)) | ||
| { | ||
| rt_ringbuffer_put(&can->nb_tx_rb, (rt_uint8_t *)pmsg, sizeof(struct rt_can_msg)); | ||
| pmsg++; | ||
| sent_size += sizeof(struct rt_can_msg); | ||
| continue; | ||
| } | ||
| else | ||
| { | ||
| /* Buffer is full, cannot process this message or subsequent ones. */ | ||
| can->status.dropedsndpkg += (size - sent_size) / sizeof(struct rt_can_msg); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| level = rt_hw_local_irq_disable(); | ||
| if (rt_ringbuffer_space_len(&can->nb_tx_rb) >= sizeof(struct rt_can_msg)) | ||
| else | ||
| { | ||
| rt_ringbuffer_put(&can->nb_tx_rb, (rt_uint8_t *)pmsg, sizeof(struct rt_can_msg)); | ||
| rt_hw_local_irq_enable(level); | ||
| if (can->ops->sendmsg_nonblocking(can, pmsg) != RT_EOK) | ||
| { | ||
| level = rt_hw_local_irq_disable(); | ||
| rt_ringbuffer_put_force(&can->nb_tx_rb, (rt_uint8_t *)pmsg, sizeof(struct rt_can_msg)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| rt_hw_local_irq_enable(level); | ||
| } | ||
|
|
||
| pmsg++; | ||
| sent_size += sizeof(struct rt_can_msg); | ||
| } | ||
| else | ||
| { | ||
| /* Buffer is full, cannot process this message or subsequent ones. */ | ||
| can->status.dropedsndpkg += (size - sent_size) / sizeof(struct rt_can_msg); | ||
| rt_hw_local_irq_enable(level); | ||
| break; | ||
| level = rt_hw_local_irq_disable(); | ||
| } | ||
| } | ||
|
|
||
| rt_hw_local_irq_enable(level); | ||
| return sent_size; | ||
| } | ||
|
|
||
|
|
@@ -409,7 +416,7 @@ static rt_err_t rt_can_open(struct rt_device *dev, rt_uint16_t oflag) | |
| struct rt_can_rx_fifo *rx_fifo; | ||
|
|
||
| rx_fifo = (struct rt_can_rx_fifo *) rt_malloc(sizeof(struct rt_can_rx_fifo) + | ||
| can->config.msgboxsz * sizeof(struct rt_can_msg_list)); | ||
| can->config.msgboxsz * sizeof(struct rt_can_msg_list)); | ||
| RT_ASSERT(rx_fifo != RT_NULL); | ||
|
|
||
| rx_fifo->buffer = (struct rt_can_msg_list *)(rx_fifo + 1); | ||
|
|
@@ -441,12 +448,12 @@ static rt_err_t rt_can_open(struct rt_device *dev, rt_uint16_t oflag) | |
| struct rt_can_tx_fifo *tx_fifo; | ||
|
|
||
| tx_fifo = (struct rt_can_tx_fifo *) rt_malloc(sizeof(struct rt_can_tx_fifo) + | ||
| can->config.sndboxnumber * sizeof(struct rt_can_sndbxinx_list)); | ||
| can->config.sndboxnumber * sizeof(struct rt_can_sndbxinx_list)); | ||
| RT_ASSERT(tx_fifo != RT_NULL); | ||
|
|
||
| tx_fifo->buffer = (struct rt_can_sndbxinx_list *)(tx_fifo + 1); | ||
| rt_memset(tx_fifo->buffer, 0, | ||
| can->config.sndboxnumber * sizeof(struct rt_can_sndbxinx_list)); | ||
| can->config.sndboxnumber * sizeof(struct rt_can_sndbxinx_list)); | ||
| rt_list_init(&tx_fifo->freelist); | ||
| for (i = 0; i < can->config.sndboxnumber; i++) | ||
| { | ||
|
|
@@ -725,7 +732,6 @@ static rt_err_t rt_can_control(struct rt_device *dev, | |
| } | ||
| rt_hw_local_irq_enable(level); | ||
| } | ||
|
|
||
| } | ||
| else | ||
| { | ||
|
|
@@ -1057,7 +1063,6 @@ void rt_hw_can_isr(struct rt_can_device *can, int event) | |
| listmsg->owner = &can->hdr[hdr]; | ||
| can->hdr[hdr].msgs++; | ||
| } | ||
|
|
||
| } | ||
| #endif | ||
| rt_hw_local_irq_enable(level); | ||
|
|
@@ -1132,7 +1137,8 @@ void rt_hw_can_isr(struct rt_can_device *can, int event) | |
| level = rt_hw_local_irq_disable(); | ||
| if (rt_ringbuffer_data_len(&can->nb_tx_rb) >= sizeof(struct rt_can_msg)) | ||
| { | ||
| rt_ringbuffer_get(&can->nb_tx_rb, (rt_uint8_t *)&msg_to_send, sizeof(struct rt_can_msg)); | ||
| struct rt_ringbuffer rb_shadow = can->nb_tx_rb; | ||
| rt_ringbuffer_get(&rb_shadow, (rt_uint8_t *)&msg_to_send, sizeof(struct rt_can_msg)); | ||
| msg_was_present = RT_TRUE; | ||
| } | ||
| rt_hw_local_irq_enable(level); | ||
|
|
@@ -1141,14 +1147,13 @@ void rt_hw_can_isr(struct rt_can_device *can, int event) | |
| { | ||
| break; | ||
| } | ||
|
|
||
| if (can->ops->sendmsg_nonblocking(can, &msg_to_send) != RT_EOK) | ||
| { | ||
| level = rt_hw_local_irq_disable(); | ||
| rt_ringbuffer_put_force(&can->nb_tx_rb, (rt_uint8_t *)&msg_to_send, sizeof(struct rt_can_msg)); | ||
| rt_hw_local_irq_enable(level); | ||
| break; | ||
| } | ||
| level = rt_hw_local_irq_disable(); | ||
| rt_ringbuffer_get(&can->nb_tx_rb, (rt_uint8_t *)&msg_to_send, sizeof(struct rt_can_msg)); | ||
| rt_hw_local_irq_enable(level); | ||
| } | ||
| } | ||
| break; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
TX_DONE中断触发不了