From a056282246abd36e7b9ccc8dc60ff2abd481a1dd Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 18 Apr 2013 18:50:10 +0200 Subject: 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: #1078 --- cores/arduino/HardwareSerial.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'cores/arduino/HardwareSerial.cpp') diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp index eb2365f..7b056e9 100644 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -62,10 +62,14 @@ struct ring_buffer { unsigned char buffer[SERIAL_BUFFER_SIZE]; - volatile unsigned int head; - volatile unsigned int tail; + volatile uint8_t head; + volatile uint8_t tail; }; +#if SERIAL_BUFFER_SIZE > 256 +#error Serial buffer size too big for head and tail pointers +#endif + #if defined(USBCON) ring_buffer rx_buffer = { { 0 }, 0, 0}; ring_buffer tx_buffer = { { 0 }, 0, 0}; -- cgit v1.2.3-18-g5258