From e0a9a7676b7b3b0db359b4edcabaf3ef9946eae7 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 18 Apr 2013 18:50:10 +0200 Subject: [PATCH] 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 --- hardware/arduino/avr/cores/arduino/HardwareSerial.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/HardwareSerial.cpp b/hardware/arduino/avr/cores/arduino/HardwareSerial.cpp index eb2365f33..7b056e989 100644 --- a/hardware/arduino/avr/cores/arduino/HardwareSerial.cpp +++ b/hardware/arduino/avr/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};