Skip to content
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

Fixed slowdown with repeated CDC bool operator test #3624

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fixed slowdown with repeated CDC bool operator test #3624

wants to merge 2 commits into from

Conversation

majenkotech
Copy link
Contributor

The delay(10) in the bool operator of the USB CDC/ACM Serial operator was being imposed on every single call to the operator when it is not needed. Instead this delay(10) should only be called when the line state transitions from ==0 to >0 (i.e., as the line enters the active state from the inactive state), otherwise repeated calls to (eg) if (Serial) cause the entire sketch to slow down to a crawl.

By only imposing the delay when the line changes state it avoids that slowdown whilst at the same time giving the system a chance to complete the port opening operation before data is allowed to be sent.

@matthijskooijman
Copy link
Collaborator

Note that #3437 has a fix for the same issue. It works by saving the timestamp of a linestate change, which can prevent unneeded additional delays, but also needs 3 additional bytes of RAM.

@facchinm facchinm added the USB: CDC serial Serial interface used by MCUs with native USB (e.g. Leonardo) to communicate with the computer label Aug 13, 2015
result = true;
delay(10);
return result;
bool res = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd not rename it to res. Res sounds weird to me. Please keep result. The rest seems like a good idea to me.

facchinm pushed a commit to arduino/ArduinoCore-avr that referenced this pull request Nov 13, 2017
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
USB: CDC serial Serial interface used by MCUs with native USB (e.g. Leonardo) to communicate with the computer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants