Skip to content

Commit c3cfe6b

Browse files
committed
Merge commit '1ad74' into ide-1.5.x
2 parents 0099416 + 9769bac commit c3cfe6b

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

Diff for: cores/arduino/HardwareSerial.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void HardwareSerial::_tx_udr_empty_irq(void)
8383
// If interrupts are enabled, there must be more data in the output
8484
// buffer. Send the next byte
8585
unsigned char c = _tx_buffer[_tx_buffer_tail];
86-
_tx_buffer_tail = (_tx_buffer_tail + 1) % SERIAL_BUFFER_SIZE;
86+
_tx_buffer_tail = (_tx_buffer_tail + 1) % SERIAL_TX_BUFFER_SIZE;
8787

8888
*_udr = c;
8989

@@ -152,7 +152,7 @@ void HardwareSerial::end()
152152

153153
int HardwareSerial::available(void)
154154
{
155-
return (unsigned int)(SERIAL_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail) % SERIAL_BUFFER_SIZE;
155+
return (unsigned int)(SERIAL_RX_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail) % SERIAL_RX_BUFFER_SIZE;
156156
}
157157

158158
int HardwareSerial::peek(void)
@@ -171,7 +171,7 @@ int HardwareSerial::read(void)
171171
return -1;
172172
} else {
173173
unsigned char c = _rx_buffer[_rx_buffer_tail];
174-
_rx_buffer_tail = (uint8_t)(_rx_buffer_tail + 1) % SERIAL_BUFFER_SIZE;
174+
_rx_buffer_tail = (rx_buffer_index_t)(_rx_buffer_tail + 1) % SERIAL_RX_BUFFER_SIZE;
175175
return c;
176176
}
177177
}
@@ -207,7 +207,7 @@ size_t HardwareSerial::write(uint8_t c)
207207
sbi(*_ucsra, TXC0);
208208
return 1;
209209
}
210-
uint8_t i = (_tx_buffer_head + 1) % SERIAL_BUFFER_SIZE;
210+
tx_buffer_index_t i = (_tx_buffer_head + 1) % SERIAL_TX_BUFFER_SIZE;
211211

212212
// If the output buffer is full, there's nothing for it other than to
213213
// wait for the interrupt handler to empty it a bit

Diff for: cores/arduino/HardwareSerial.h

+22-8
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,24 @@
3232
// using a ring buffer (I think), in which head is the index of the location
3333
// to which to write the next incoming character and tail is the index of the
3434
// location from which to read.
35+
#if !(defined(SERIAL_TX_BUFFER_SIZE) && defined(SERIAL_RX_BUFFER_SIZE))
3536
#if (RAMEND < 1000)
36-
#define SERIAL_BUFFER_SIZE 16
37+
#define SERIAL_TX_BUFFER_SIZE 16
38+
#define SERIAL_RX_BUFFER_SIZE 16
3739
#else
38-
#define SERIAL_BUFFER_SIZE 64
40+
#define SERIAL_TX_BUFFER_SIZE 64
41+
#define SERIAL_RX_BUFFER_SIZE 64
42+
#endif
43+
#endif
44+
#if (SERIAL_TX_BUFFER_SIZE>256)
45+
typedef uint16_t tx_buffer_index_t;
46+
#else
47+
typedef uint8_t tx_buffer_index_t;
48+
#endif
49+
#if (SERIAL_RX_BUFFER_SIZE>256)
50+
typedef uint16_t rx_buffer_index_t;
51+
#else
52+
typedef uint8_t rx_buffer_index_t;
3953
#endif
4054

4155
// Define config for Serial.begin(baud, config);
@@ -76,16 +90,16 @@ class HardwareSerial : public Stream
7690
// Has any byte been written to the UART since begin()
7791
bool _written;
7892

79-
volatile uint8_t _rx_buffer_head;
80-
volatile uint8_t _rx_buffer_tail;
81-
volatile uint8_t _tx_buffer_head;
82-
volatile uint8_t _tx_buffer_tail;
93+
volatile rx_buffer_index_t _rx_buffer_head;
94+
volatile rx_buffer_index_t _rx_buffer_tail;
95+
volatile tx_buffer_index_t _tx_buffer_head;
96+
volatile tx_buffer_index_t _tx_buffer_tail;
8397

8498
// Don't put any members after these buffers, since only the first
8599
// 32 bytes of this struct can be accessed quickly using the ldd
86100
// instruction.
87-
unsigned char _rx_buffer[SERIAL_BUFFER_SIZE];
88-
unsigned char _tx_buffer[SERIAL_BUFFER_SIZE];
101+
unsigned char _rx_buffer[SERIAL_RX_BUFFER_SIZE];
102+
unsigned char _tx_buffer[SERIAL_TX_BUFFER_SIZE];
89103

90104
public:
91105
inline HardwareSerial(

Diff for: cores/arduino/HardwareSerial_private.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void HardwareSerial::_rx_complete_irq(void)
9999
// No Parity error, read byte and store it in the buffer if there is
100100
// room
101101
unsigned char c = *_udr;
102-
uint8_t i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_BUFFER_SIZE;
102+
rx_buffer_index_t i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_RX_BUFFER_SIZE;
103103

104104
// if we should be storing the received character into the location
105105
// just before the tail (meaning that the head would advance to the

0 commit comments

Comments
 (0)