aboutsummaryrefslogtreecommitdiff
path: root/cores
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2014-10-21 17:18:26 +0200
committerCristian Maglie <c.maglie@bug.st>2014-10-21 17:18:26 +0200
commit02f5b999581287001fb83f5304c06a3d144b3b42 (patch)
treefc033adcab31047ff100e315b4731366ff5fcef2 /cores
parentd62d06308248e7d5d32df1a4c7a3151939984d92 (diff)
Revert "Match return value to type in available()"
This reverts commit f40e4713542fa862d5b99b256a642e001a796988. Added an hint for the buffer sizes. See #2057 Fixes #2367
Diffstat (limited to 'cores')
-rw-r--r--cores/arduino/HardwareSerial.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp
index 1a2f8ce..2a256e0 100644
--- a/cores/arduino/HardwareSerial.cpp
+++ b/cores/arduino/HardwareSerial.cpp
@@ -53,6 +53,8 @@
// using a ring buffer (I think), in which head is the index of the location
// to which to write the next incoming character and tail is the index of the
// location from which to read.
+// NOTE: a "power of 2" buffer size is reccomended to dramatically
+// optimize all the modulo operations for ring buffers.
#if (RAMEND < 1000)
#define SERIAL_BUFFER_SIZE 16
#else
@@ -426,7 +428,7 @@ void HardwareSerial::end()
int HardwareSerial::available(void)
{
- return (int)(SERIAL_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % SERIAL_BUFFER_SIZE;
+ return ((unsigned int)(SERIAL_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail)) % SERIAL_BUFFER_SIZE;
}
int HardwareSerial::peek(void)