Skip to content

Commit 18d2ac7

Browse files
committed
Speed up 'available' function by inserting uint16_t cast
See arduino/ArduinoCore-avr#433 for details
1 parent b11388b commit 18d2ac7

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

avr/libraries/SoftwareSerial/src/SoftwareSerial.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
SoftwareSerial.cpp (formerly NewSoftSerial.cpp) -
2+
SoftwareSerial.cpp (formerly NewSoftSerial.cpp) -
33
Multi-instance software serial library for Arduino/Wiring
44
-- Interrupt-driven receive and other improvements by ladyada
55
(http://ladyada.net)
66
-- Tuning, circular buffer, derivation from class Print/Stream,
77
multi-instance support, porting to 8MHz processors,
8-
various optimizations, PROGMEM delay tables, inverse logic and
8+
various optimizations, PROGMEM delay tables, inverse logic and
99
direct port writing by Mikal Hart (http://www.arduiniana.org)
1010
-- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com)
1111
-- 20MHz processor support by Garrett Mace (http://www.macetech.com)
@@ -37,9 +37,9 @@ The latest version of this library can always be found at
3737
#define _DEBUG 0
3838
#define _DEBUG_PIN1 11
3939
#define _DEBUG_PIN2 13
40-
//
40+
//
4141
// Includes
42-
//
42+
//
4343
#include <avr/interrupt.h>
4444
#include <avr/pgmspace.h>
4545
#include <Arduino.h>
@@ -50,7 +50,7 @@ The latest version of this library can always be found at
5050
// Statics
5151
//
5252
SoftwareSerial *SoftwareSerial::active_object = 0;
53-
uint8_t SoftwareSerial::_receive_buffer[_SS_MAX_RX_BUFF];
53+
uint8_t SoftwareSerial::_receive_buffer[_SS_MAX_RX_BUFF];
5454
volatile uint8_t SoftwareSerial::_receive_buffer_tail = 0;
5555
volatile uint8_t SoftwareSerial::_receive_buffer_head = 0;
5656

@@ -79,13 +79,13 @@ inline void DebugPulse(uint8_t, uint8_t) {}
7979
// Private methods
8080
//
8181

82-
/* static */
83-
inline void SoftwareSerial::tunedDelay(uint16_t delay) {
82+
/* static */
83+
inline void SoftwareSerial::tunedDelay(uint16_t delay) {
8484
_delay_loop_2(delay);
8585
}
8686

8787
// This function sets the current object as the "listening"
88-
// one and returns true if it replaces another
88+
// one and returns true if it replaces another
8989
bool SoftwareSerial::listen()
9090
{
9191
if (!_rx_delay_stopbit)
@@ -139,7 +139,7 @@ void SoftwareSerial::recv()
139139
"push r26 \n\t"
140140
"push r27 \n\t"
141141
::);
142-
#endif
142+
#endif
143143

144144
uint8_t d = 0;
145145

@@ -176,8 +176,8 @@ void SoftwareSerial::recv()
176176
// save new data in buffer: tail points to where byte goes
177177
_receive_buffer[_receive_buffer_tail] = d; // save new byte
178178
_receive_buffer_tail = next;
179-
}
180-
else
179+
}
180+
else
181181
{
182182
DebugPulse(_DEBUG_PIN1, 1);
183183
_buffer_overflow = true;
@@ -256,7 +256,7 @@ ISR(PCINT3_vect, ISR_ALIASOF(PCINT0_vect));
256256
//
257257
// Constructor
258258
//
259-
SoftwareSerial::SoftwareSerial(int8_t receivePin, int8_t transmitPin, bool inverse_logic /* = false */) :
259+
SoftwareSerial::SoftwareSerial(int8_t receivePin, int8_t transmitPin, bool inverse_logic /* = false */) :
260260
_rx_delay_centering(0),
261261
_rx_delay_intrabit(0),
262262
_rx_delay_stopbit(0),
@@ -312,7 +312,7 @@ uint16_t SoftwareSerial::subtract_cap(uint16_t num, uint16_t sub) {
312312
//
313313

314314
void SoftwareSerial::begin(long speed)
315-
{
315+
{
316316
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
317317

318318
// Precalculate the various delays, in number of 4-cycle delays
@@ -380,12 +380,12 @@ void SoftwareSerial::begin(long speed)
380380

381381
#if defined(INT_AND_PCINT)
382382
else
383-
#endif
383+
#endif
384384
#if defined(INT_ONLY) || defined(INT_AND_PCINT)
385385
{
386386
// Direct interrupts
387387
attachInterrupt(digitalPinToInterrupt(_receivePin), isr, CHANGE);
388-
388+
389389
#if GCC_VERSION > 40800
390390
// Timings counted from gcc 4.8.2 output. This works up to 115200 on
391391
// 16Mhz and 57600 on 8Mhz.
@@ -469,7 +469,7 @@ int SoftwareSerial::available()
469469
if (!isListening())
470470
return 0;
471471

472-
return (_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head) % _SS_MAX_RX_BUFF;
472+
return ((uint16_t)(_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head)) % _SS_MAX_RX_BUFF;
473473
}
474474

475475
size_t SoftwareSerial::write(uint8_t b)
@@ -523,7 +523,7 @@ size_t SoftwareSerial::write(uint8_t b)
523523

524524
SREG = oldSREG; // turn interrupts back on
525525
tunedDelay(_tx_delay);
526-
526+
527527
return 1;
528528
}
529529

0 commit comments

Comments
 (0)