|
23 | 23 | #if defined(USBCON)
|
24 | 24 | #ifdef CDC_ENABLED
|
25 | 25 |
|
26 |
| -#if (RAMEND < 1000) |
27 |
| -#define SERIAL_BUFFER_SIZE 16 |
28 |
| -#else |
29 |
| -#define SERIAL_BUFFER_SIZE 64 |
30 |
| -#endif |
31 |
| - |
32 |
| -struct ring_buffer |
33 |
| -{ |
34 |
| - unsigned char buffer[SERIAL_BUFFER_SIZE]; |
35 |
| - volatile int head; |
36 |
| - volatile int tail; |
37 |
| -}; |
38 |
| - |
39 |
| -ring_buffer cdc_rx_buffer = { { 0 }, 0, 0}; |
40 |
| - |
41 | 26 | typedef struct
|
42 | 27 | {
|
43 | 28 | u32 dwDTERate;
|
@@ -140,51 +125,47 @@ void Serial_::end(void)
|
140 | 125 |
|
141 | 126 | void Serial_::accept(void)
|
142 | 127 | {
|
143 |
| - ring_buffer *buffer = &cdc_rx_buffer; |
144 |
| - int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE; |
| 128 | + int i = (unsigned int)(_rx_buffer_head+1) % SERIAL_BUFFER_SIZE; |
145 | 129 |
|
146 | 130 | // if we should be storing the received character into the location
|
147 | 131 | // just before the tail (meaning that the head would advance to the
|
148 | 132 | // current location of the tail), we're about to overflow the buffer
|
149 | 133 | // and so we don't write the character or advance the head.
|
150 | 134 |
|
151 | 135 | // while we have room to store a byte
|
152 |
| - while (i != buffer->tail) { |
| 136 | + while (i != _rx_buffer_tail) { |
153 | 137 | int c = USB_Recv(CDC_RX);
|
154 | 138 | if (c == -1)
|
155 | 139 | break; // no more data
|
156 |
| - buffer->buffer[buffer->head] = c; |
157 |
| - buffer->head = i; |
| 140 | + _rx_buffer[_rx_buffer_head] = c; |
| 141 | + _rx_buffer_head = i; |
158 | 142 |
|
159 |
| - i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE; |
| 143 | + i = (unsigned int)(_rx_buffer_head+1) % SERIAL_BUFFER_SIZE; |
160 | 144 | }
|
161 | 145 | }
|
162 | 146 |
|
163 | 147 | int Serial_::available(void)
|
164 | 148 | {
|
165 |
| - ring_buffer *buffer = &cdc_rx_buffer; |
166 |
| - return (unsigned int)(SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % SERIAL_BUFFER_SIZE; |
| 149 | + return (unsigned int)(SERIAL_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail) % SERIAL_BUFFER_SIZE; |
167 | 150 | }
|
168 | 151 |
|
169 | 152 | int Serial_::peek(void)
|
170 | 153 | {
|
171 |
| - ring_buffer *buffer = &cdc_rx_buffer; |
172 |
| - if (buffer->head == buffer->tail) { |
| 154 | + if (_rx_buffer_head == _rx_buffer_tail) { |
173 | 155 | return -1;
|
174 | 156 | } else {
|
175 |
| - return buffer->buffer[buffer->tail]; |
| 157 | + return _rx_buffer[_rx_buffer_tail]; |
176 | 158 | }
|
177 | 159 | }
|
178 | 160 |
|
179 | 161 | int Serial_::read(void)
|
180 | 162 | {
|
181 |
| - ring_buffer *buffer = &cdc_rx_buffer; |
182 | 163 | // if the head isn't ahead of the tail, we don't have any characters
|
183 |
| - if (buffer->head == buffer->tail) { |
| 164 | + if (_rx_buffer_head == _rx_buffer_tail) { |
184 | 165 | return -1;
|
185 | 166 | } else {
|
186 |
| - unsigned char c = buffer->buffer[buffer->tail]; |
187 |
| - buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE; |
| 167 | + unsigned char c = _rx_buffer[_rx_buffer_tail]; |
| 168 | + _rx_buffer_tail = (unsigned int)(_rx_buffer_tail + 1) % SERIAL_BUFFER_SIZE; |
188 | 169 | return c;
|
189 | 170 | }
|
190 | 171 | }
|
|
0 commit comments