Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 62cf4b6

Browse files
committedOct 21, 2014
Revert "Match return value to type in available()"
This reverts commit f40e471. Added an hint for the buffer sizes. See #2057 Fixes #2367
1 parent 58b6fd4 commit 62cf4b6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed
 

‎hardware/arduino/cores/arduino/HardwareSerial.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
// using a ring buffer (I think), in which head is the index of the location
5454
// to which to write the next incoming character and tail is the index of the
5555
// location from which to read.
56+
// NOTE: a "power of 2" buffer size is reccomended to dramatically
57+
// optimize all the modulo operations for ring buffers.
5658
#if (RAMEND < 1000)
5759
#define SERIAL_BUFFER_SIZE 16
5860
#else
@@ -426,7 +428,7 @@ void HardwareSerial::end()
426428

427429
int HardwareSerial::available(void)
428430
{
429-
return (int)(SERIAL_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % SERIAL_BUFFER_SIZE;
431+
return ((unsigned int)(SERIAL_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail)) % SERIAL_BUFFER_SIZE;
430432
}
431433

432434
int HardwareSerial::peek(void)

0 commit comments

Comments
 (0)
Please sign in to comment.