aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2013-04-18 18:50:10 +0200
committerCristian Maglie <c.maglie@bug.st>2013-07-26 12:18:56 +0200
commita056282246abd36e7b9ccc8dc60ff2abd481a1dd (patch)
treeb8bd9fb83f0da910f34b3382b040fe3a8d3fd06f
parentbda85506eae7807ac4ad96ee9df5c1760761002f (diff)
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
-rw-r--r--cores/arduino/HardwareSerial.cpp8
1 files changed, 6 insertions, 2 deletions
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};