Closed GoogleCodeExporter closed 9 years ago
I guess the ring_buffer needs changed as well.
struct ring_buffer {
unsigned char buffer[RX_BUFFER_SIZE];
int head;
int tail;
};
really should be
struct ring_buffer {
unsigned char buffer[RX_BUFFER_SIZE];
uint8_t head;
uint8_t tail;
};
Original comment by gabebear@gmail.com
on 15 Jul 2009 at 2:14
oops, one more; the store_char() functino in HardwareSerial.cpp needs a cast
inline void store_char(unsigned char c, ring_buffer *rx_buffer)
{
int i = ((uint8_t)(rx_buffer->head + 1)) % RX_BUFFER_SIZE;
// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
if (i != rx_buffer->tail) {
rx_buffer->buffer[rx_buffer->head] = c;
rx_buffer->head = i;
}
}
Original comment by gabebear@gmail.com
on 15 Jul 2009 at 4:11
Bleck, one more in read()
int HardwareSerial::read(void)
{
// if the head isn't ahead of the tail, we don't have any characters
if (_rx_buffer->head == _rx_buffer->tail) {
return -1;
} else {
unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
_rx_buffer->tail = ((uint8_t)(_rx_buffer->tail + 1)) % RX_BUFFER_SIZE;
return c;
}
}
Original comment by gabebear@gmail.com
on 15 Jul 2009 at 4:16
Can you attach a patch? (Against the code in the processing-5503 branch.)
Original comment by dmel...@gmail.com
on 15 Jul 2009 at 6:25
After looking through everything. Only available() really had the issue after
changing the definition of "struct ring_buffer".
To completely get rid of modulus/division, you need to inline begin(). Inlining
begin() allows all the baud rate calculations to be done at compile-time, which
is a
HUGE win.
This patch
- removes modulus from available()
- changes the definition of "struct ring_buffer" so other functions
don't need change to be fixed.
- moves begin() to an inline function to remove modulus
(unless you don't use a constant to set baud-rate)
Original comment by gabebear@gmail.com
on 16 Jul 2009 at 8:02
Attachments:
[deleted comment]
I checked out "svn/branches/processing-5503/hardware/cores/arduino" to
"arduino-5503/"
So you will probably need to change all instances of "arduino-5503" to whatever
you
check that directory out to for the last patch, here is one with references
back to
the http server... don't know if your svn client works with that or not
made with:
svn diff
--old=http://arduino.googlecode.com/svn/branches/processing-5503/hardware/cores/
ardui
--new=arduino-5503/ > a.diff
Original comment by gabebear@gmail.com
on 16 Jul 2009 at 8:18
Attachments:
This seems to be fixed in current versions (1.0 and later, at least.)
At least, there is no longer a division call.
Original comment by wes...@gmail.com
on 30 Aug 2012 at 4:25
Original comment by c.mag...@arduino.cc
on 27 May 2015 at 10:37
Original issue reported on code.google.com by
gabebear@gmail.com
on 15 Jul 2009 at 2:08