Example: Here is the code the Teensy 3 code for this:
unsigned long startMillis = millis();
c = read();
if (c >= 0) return c;
} while(millis() - startMillis < _timeout);
return -1; // -1 indicates timeout
By reading the code you posted I could suggest you a couple of things:
1. Look for the value of _timeout and how it gets it, check if it is a constant or if there's a formula to calculate it.
2. You could edit Stream::timedRead, and change _timeout for something you think is more appropriate, I mean so you would get a timeout sooner.
I'm not really sure but I hope this helps.
The code I posted is part of the Arduino IDE and part of the Serial (Stream) class. On my machine it is in the file:
That is these function are controlled by the value you set in the api call: serial.setTimeout() (actually implemented by Stream::setTimeout)
What I am personally suggesting is that for the next release of the IDE that a minimum the code be changed, like Paul of PJRC did for the Teensy and do a yield or what I have done in the past in add a delay(1). I know from the past, doing the delay knocked the process usage of 50%(one whole processor) down to maybe 1 percent?... Have not tried that here yet. I rolled my own code.
I'm sorry, I misinterpreted your first post, we will take it into consideration, I will pass your suggestion to the appropriate team.
It would be great if they could take a look through these files and look for loops that eat up the processor time. In the same file I mentioned there is at lease one other function (timedPeek) that should get the same fix.
Thanks for your suggestion, it has been reported to the engineering team, they will take it into consideration. If you have any other suggestions or doubts, don't hesitate to post them on the community.