-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Update CDC.cpp - Remove delay in operator bool() #3437
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
Conversation
Remove 10ms blocking wait from bool() operator in CDC code. Instead, set a timestamp and wait 10ms before returning true.
Thanks for picking this up! This code introduces a race condition, since CDC_Setup is run in ISR context, so the timestamp might be changed halfway through reading it. To fix it, copy the timestamp into a local variable while interrupts are disabled ( Also, the "Update CDC.cpp" from the commit message isn't very helpful, the first summary line should explain what actually happened (git can tell me what file it changed). The first sentence from your extended description actually looks fine as the summary line to me :-) |
This code was only changed for the Due though. It's native 32 bit so the timestamp code should be atomic isn't it? I've changed the title summary to better describe this pull request. |
Oh, didn't realize that the Due's CDC.cpp was so similar. I think that on the Due, it should already be atomic indeed. I guess it would be best to apply the same change to AVR as well, though. Regarding the summary - I was referring to the actual commit message, not just the pullrequest description. However, to edit you would need to commit --amend or rebase using a git client, and I suspect you just edited the file through github? If so, just keep this in mind for future contributions :-) |
Yeah, what happened is that I edited the file locally on my machine to make On Thu, Jul 2, 2015 at 8:12 AM, Matthijs Kooijman notifications@github.com
|
Why is there a 10 ms delay anyways? To wait a bit more before sending new bytes with the CDC? However I would definitely NOT go for this fix on AVR. 4 bytes of ram vs 10ms at startup, and ONLY if this function (the bool operator) is used. For due, I have no idea how much ram it has and I dont use it anyways :P |
@NicoHood, the goal is not to save 10ms at startup, the goal is to save 10ms whenever checking the serial status after startup. Here's the thread where the discussion about this PR started: https://groups.google.com/a/arduino.cc/forum/#!topic/developers/SQEvifbj0S4 |
Doesnt #3343 solve this? You can check the DTR and RTS states yourself and keep the delay for its simple "nooby" usage. I would not add 4 more bytes to ram just for such a simple thing, now that we DO have dtr() and rts() functions. |
@NicoHood, AFAIU, the problem is that shortly after dtr is asserted, writing data to the host still fails, so essentially dtr is sort-of lying for a short while after the port is opened. Using the newly introduced |
Yes, and so I'm still unsure of any other fix than the one I suggested On Sun, Aug 16, 2015 at 6:19 AM, Matthijs Kooijman <notifications@github.com
|
#3624 contains a different approach, needing only 1 byte of RAM (at the cost of a bit of delay even when not strictly required, but for your loop usecase this would only lead to 10ms once, not on every loop invocation). As for reproducing the issue, I haven't tried, nor have I seen anyone else say something about this. The original commit message suggested that @ffissore noticed this bug, but IIRC I highlighted him before without a response. Trying again now :-) |
You know what, I like that other solution better. It saves memory, still On Sun, Aug 16, 2015 at 10:34 AM, Matthijs Kooijman <
|
Yep the other PR looks better. You could close it then. But the same issue is for HID. The issue is still opened somewhere from me. And there is no fix yet for this. I dont know if this is really an OS only problem or if we can somehow check if the endpoint is ready to transmit data somehow. If it is a general USB problem, cant we add a fix for the whole USB thing, not only CDC but HID and MIDI as well? |
PR 3624 is a better idea and better implementation of this. Use that one instead. I'm closing my PR because the other one is better. |
No, it could not and is completely unrelated. See https://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter#Break_condition
I don't think there is a generic "endpoint opened" flag in generic USB. For CDC, the DTR flag is used for this since usually the flag is asserted only while the port is opened, but even that is not necessarily true. I'm not sure if HID and MIDI have a similar feature, you'd have to check the specs for those protocols (and it's certainly off-topic for this PR). |
Remove 10ms blocking wait from bool() operator in CDC code. Instead, set a timestamp and wait 10ms before returning true.