Skip to content

Commit e0a9a76

Browse files
matthijskooijmancmaglie
authored andcommitted
Use uint8_t for HardwareSerial ringbuffer pointers
Since the buffers aren't bigger than 64 bytes, these values can be smaller. This saves a few bytes of ram, but also saves around 50 bytes of program space, since the values can now be loaded using a single instruction. To prevent problems when people manually increase the buffer size, a compile-time check is added. Closes: arduino#1078
1 parent d6a5e41 commit e0a9a76

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

hardware/arduino/avr/cores/arduino/HardwareSerial.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,14 @@
6262
struct ring_buffer
6363
{
6464
unsigned char buffer[SERIAL_BUFFER_SIZE];
65-
volatile unsigned int head;
66-
volatile unsigned int tail;
65+
volatile uint8_t head;
66+
volatile uint8_t tail;
6767
};
6868

69+
#if SERIAL_BUFFER_SIZE > 256
70+
#error Serial buffer size too big for head and tail pointers
71+
#endif
72+
6973
#if defined(USBCON)
7074
ring_buffer rx_buffer = { { 0 }, 0, 0};
7175
ring_buffer tx_buffer = { { 0 }, 0, 0};

0 commit comments

Comments
 (0)