Pages: [1]   Go Down
Author Topic: 64-byte serial receive buffer  (Read 623 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi --

We are evaluating the Due for a project and it all looks great except for the 64-byte receive buffer for serial communications.  I realize the 1.5 code is still in beta and it is a port of the earlier product.  Does anyone know if this buffer is going to be increasing in size before the release?  I know that the past code has had to run on some very limited hardware -- is that going to be the case with 1.5 or is it just for Due and better?  Our project involves a chatty serial protocol running at 115,200, which means we have to poll that buffer every 5 ms or we lose data.  We'd be much more comfortable with another order of magnitude and it definitely seems as though the Due can afford that.  But if 1.5 is eventually going to run on hardware with 2K of SRAM, I can understand the decision to limit to 64 bytes and we'll look for another platform.

Thanks for any advice.

Tom
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26627
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Does anyone know if this buffer is going to be increasing in size before the release?
Why wait for a release?
You have the source - change it yourself!
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why wait for a release?
You have the source - change it yourself!
Thanks for the suggestion.  That's definitely an option.  I was thinking others might be facing the same problem and that Arduino was looking for beta feedback. 
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

AFAIK it's just a matter of changing the SERIAL_BUFFER_SIZE #define in HardwareSerial.cpp, however the same value is used for both Tx and Rx so you waste a lot of RAM if your comms is one-sided.

This should really be a parameter or another Serial method call IMO.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26627
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This should really be a parameter or another Serial method call IMO
Certainly a defaulted parameter, agreed.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

AFAIK it's just a matter of changing the SERIAL_BUFFER_SIZE #define in HardwareSerial.cpp, however the same value is used for both Tx and Rx so you waste a lot of RAM if your comms is one-sided.

This should really be a parameter or another Serial method call IMO.

______
Rob
That makes a lot of sense.  There are two issues that I know of.  The first is that 1.5 doesn't appear to be using a Tx buffer from what I see in the sourcecode.  I might be wrong about that, but at first read it appears to be the case.  The single-byte write() method has a spin lock until the TXRDY status bit is set.  We're working around that by testing TXRDY ourselves in the main loop() and only calling write() when we know the bit is set.  The second issue is that we would need to make sure the variables in the ring buffer are being updated atomically if they're going to be holding values bigger than 255.  That's probably true for the Due, but we would need to be sure.

Tom
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The second issue is that we would need to make sure the variables in the ring buffer are being updated atomically
Doesn't look like it.

Code:
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 = (unsigned int)(_rx_buffer->tail + 1) % SERIAL_BUFFER_SIZE;
    return c;
  }
}

The Due would be the same I assume.

______
Rob
« Last Edit: July 16, 2013, 10:57:41 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1]   Go Up
Jump to: