aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/CDC.cpp
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2012-10-18 18:47:50 +0200
committerCristian Maglie <c.maglie@bug.st>2012-10-18 18:47:50 +0200
commit037020e938f7dde469f828764976635a69b74a3e (patch)
tree4677e869e5ceb7db0c076f32eb830b3e86e75dfc /cores/arduino/CDC.cpp
parent6a45ba48ab1f2d0a168373a02ba7fded40a3470e (diff)
Merged latest changes in AVR arduino core
Diffstat (limited to 'cores/arduino/CDC.cpp')
-rw-r--r--cores/arduino/CDC.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/cores/arduino/CDC.cpp b/cores/arduino/CDC.cpp
index 1ee3a48..701e483 100644
--- a/cores/arduino/CDC.cpp
+++ b/cores/arduino/CDC.cpp
@@ -141,16 +141,22 @@ void Serial_::end(void)
void Serial_::accept(void)
{
ring_buffer *buffer = &cdc_rx_buffer;
- int c = USB_Recv(CDC_RX);
int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE;
// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
- if (i != buffer->tail) {
+
+ // while we have room to store a byte
+ while (i != buffer->tail) {
+ int c = USB_Recv(CDC_RX);
+ if (c == -1)
+ break; // no more data
buffer->buffer[buffer->head] = c;
buffer->head = i;
+
+ i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE;
}
}