54
54
// to which to write the next incoming character and tail is the index of the
55
55
// location from which to read.
56
56
#if (RAMEND < 1000)
57
- #define SERIAL_BUFFER_SIZE 16
57
+ #define SERIAL_BUFFER_SIZE 16U
58
58
#else
59
- #define SERIAL_BUFFER_SIZE 64
59
+ #define SERIAL_BUFFER_SIZE 64U
60
60
#endif
61
61
62
62
struct ring_buffer
@@ -89,7 +89,7 @@ struct ring_buffer
89
89
90
90
inline void store_char (unsigned char c, ring_buffer *buffer)
91
91
{
92
- int i = (unsigned int )(buffer->head + 1 ) % SERIAL_BUFFER_SIZE;
92
+ unsigned int i = (unsigned int )(buffer->head + 1 ) % SERIAL_BUFFER_SIZE;
93
93
94
94
// if we should be storing the received character into the location
95
95
// just before the tail (meaning that the head would advance to the
@@ -120,18 +120,20 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
120
120
#endif
121
121
{
122
122
#if defined(UDR0)
123
+ unsigned char c;
123
124
if (bit_is_clear (UCSR0A, UPE0)) {
124
- unsigned char c = UDR0;
125
+ c = UDR0;
125
126
store_char (c, &rx_buffer);
126
127
} else {
127
- unsigned char c = UDR0;
128
+ c = UDR0;
128
129
};
129
130
#elif defined(UDR)
131
+ unsigned char c;
130
132
if (bit_is_clear (UCSRA, PE)) {
131
- unsigned char c = UDR;
133
+ c = UDR;
132
134
store_char (c, &rx_buffer);
133
135
} else {
134
- unsigned char c = UDR;
136
+ c = UDR;
135
137
};
136
138
#else
137
139
#error UDR not defined
@@ -146,11 +148,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
146
148
#define serialEvent1_implemented
147
149
ISR (USART1_RX_vect)
148
150
{
151
+ unsigned char c;
149
152
if (bit_is_clear (UCSR1A, UPE1)) {
150
- unsigned char c = UDR1;
153
+ c = UDR1;
151
154
store_char (c, &rx_buffer1);
152
155
} else {
153
- unsigned char c = UDR1;
156
+ c = UDR1;
154
157
};
155
158
}
156
159
#endif
@@ -161,11 +164,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
161
164
#define serialEvent2_implemented
162
165
ISR (USART2_RX_vect)
163
166
{
167
+ unsigned char c;
164
168
if (bit_is_clear (UCSR2A, UPE2)) {
165
- unsigned char c = UDR2;
169
+ c = UDR2;
166
170
store_char (c, &rx_buffer2);
167
171
} else {
168
- unsigned char c = UDR2;
172
+ c = UDR2;
169
173
};
170
174
}
171
175
#endif
@@ -176,11 +180,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
176
180
#define serialEvent3_implemented
177
181
ISR (USART3_RX_vect)
178
182
{
183
+ unsigned char c;
179
184
if (bit_is_clear (UCSR3A, UPE3)) {
180
- unsigned char c = UDR3;
185
+ c = UDR3;
181
186
store_char (c, &rx_buffer3);
182
187
} else {
183
- unsigned char c = UDR3;
188
+ c = UDR3;
184
189
};
185
190
}
186
191
#endif
@@ -365,7 +370,6 @@ void HardwareSerial::begin(unsigned long baud)
365
370
void HardwareSerial::begin (unsigned long baud, byte config)
366
371
{
367
372
uint16_t baud_setting;
368
- uint8_t current_config;
369
373
bool use_u2x = true ;
370
374
371
375
#if F_CPU == 16000000UL
@@ -453,13 +457,14 @@ int HardwareSerial::read(void)
453
457
void HardwareSerial::flush ()
454
458
{
455
459
// UDR is kept full while the buffer is not empty, so TXC triggers when EMPTY && SENT
456
- while (transmitting && ! (*_ucsra & _BV (TXC0)));
460
+ while (transmitting && ! (*_ucsra & _BV (TXC0)))
461
+ ;
457
462
transmitting = false ;
458
463
}
459
464
460
465
size_t HardwareSerial::write (uint8_t c)
461
466
{
462
- int i = (_tx_buffer->head + 1 ) % SERIAL_BUFFER_SIZE;
467
+ unsigned int i = (_tx_buffer->head + 1 ) % SERIAL_BUFFER_SIZE;
463
468
464
469
// If the output buffer is full, there's nothing for it other than to
465
470
// wait for the interrupt handler to empty it a bit
0 commit comments