aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/CDC.cpp
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2013-07-27 12:06:42 +0200
committerCristian Maglie <c.maglie@bug.st>2013-07-27 12:06:42 +0200
commit4de497b72504c62cd41b9930db4a53fb2280e6c8 (patch)
treeb5a2ade5ada34f04be94ca2ccee398eb683d34f4 /cores/arduino/CDC.cpp
parentcddc83bb19e760145ea312f187371f44a6a921e8 (diff)
Move buffers into USB CDC (look #947 and #1369 for reference)
Diffstat (limited to 'cores/arduino/CDC.cpp')
-rw-r--r--cores/arduino/CDC.cpp41
1 files changed, 11 insertions, 30 deletions
diff --git a/cores/arduino/CDC.cpp b/cores/arduino/CDC.cpp
index 701e483..fb25a96 100644
--- a/cores/arduino/CDC.cpp
+++ b/cores/arduino/CDC.cpp
@@ -23,21 +23,6 @@
#if defined(USBCON)
#ifdef CDC_ENABLED
-#if (RAMEND < 1000)
-#define SERIAL_BUFFER_SIZE 16
-#else
-#define SERIAL_BUFFER_SIZE 64
-#endif
-
-struct ring_buffer
-{
- unsigned char buffer[SERIAL_BUFFER_SIZE];
- volatile int head;
- volatile int tail;
-};
-
-ring_buffer cdc_rx_buffer = { { 0 }, 0, 0};
-
typedef struct
{
u32 dwDTERate;
@@ -140,8 +125,7 @@ void Serial_::end(void)
void Serial_::accept(void)
{
- ring_buffer *buffer = &cdc_rx_buffer;
- int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE;
+ int i = (unsigned int)(_rx_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
@@ -149,42 +133,39 @@ void Serial_::accept(void)
// and so we don't write the character or advance the head.
// while we have room to store a byte
- while (i != buffer->tail) {
+ while (i != _rx_buffer_tail) {
int c = USB_Recv(CDC_RX);
if (c == -1)
break; // no more data
- buffer->buffer[buffer->head] = c;
- buffer->head = i;
+ _rx_buffer[_rx_buffer_head] = c;
+ _rx_buffer_head = i;
- i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE;
+ i = (unsigned int)(_rx_buffer_head+1) % SERIAL_BUFFER_SIZE;
}
}
int Serial_::available(void)
{
- ring_buffer *buffer = &cdc_rx_buffer;
- return (unsigned int)(SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % SERIAL_BUFFER_SIZE;
+ return (unsigned int)(SERIAL_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail) % SERIAL_BUFFER_SIZE;
}
int Serial_::peek(void)
{
- ring_buffer *buffer = &cdc_rx_buffer;
- if (buffer->head == buffer->tail) {
+ if (_rx_buffer_head == _rx_buffer_tail) {
return -1;
} else {
- return buffer->buffer[buffer->tail];
+ return _rx_buffer[_rx_buffer_tail];
}
}
int Serial_::read(void)
{
- ring_buffer *buffer = &cdc_rx_buffer;
// if the head isn't ahead of the tail, we don't have any characters
- if (buffer->head == buffer->tail) {
+ if (_rx_buffer_head == _rx_buffer_tail) {
return -1;
} else {
- unsigned char c = buffer->buffer[buffer->tail];
- buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE;
+ unsigned char c = _rx_buffer[_rx_buffer_tail];
+ _rx_buffer_tail = (unsigned int)(_rx_buffer_tail + 1) % SERIAL_BUFFER_SIZE;
return c;
}
}