-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Improve CDC read code #1953
Improve CDC read code #1953
Conversation
Read CDC data from USB FIFO on demand instead of in ISR. Remove superfluous ring buffer. Signed-off-by: Paul Brook <[email protected]>
It seems like your modified peek function should be |
You are right. Patch fixed and branch updated. |
ring_buffer *buffer = &cdc_rx_buffer; | ||
return (unsigned int)(SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % SERIAL_BUFFER_SIZE; | ||
if (peek_buffer >= 0) { | ||
return 1; |
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.
I guess that the
return 1;
should be:
return 1 + USB_Available(CDC_RX);
To avoid situations where queued chars may seems to "disappear":
av1 = Serial.available(); // av1 may be > 1
Serial.peek();
av2 = Serial.available(); // after the peek av2 is 1
assert(av2>=av1); // Assertion fails if av1>1
This PR introduced a regression. I've opened issue #2123 |
Remove superfluous ring buffer from the CDC read code. The USB hardware already buffers 128 bytes of data, so just read from that on demand.
The result is smaller, faster, uses substantially less ram, and does not do large data copies in an interrupt handler.