ArduinoCore-avr/cores/arduino
robert rozee 95bb83ef96 make serial.available, peek, read atomic
when SERIAL_RX_BUFFER_SIZE is defined as greater than 256, the current HardwareSerial.cpp code almost works correctly. but not quite. the function serial.available may return an incorrect number of characters waiting (though when treated purely as a boolean it seems not to fault).serial.peek has a similar issue detecting if a character is waiting, while serial.read may also leave _rx_buffer_tail corrupt to an interrupt occurring mid-update (this corruption may cause the ISR to be mistaken about how much free is available in the Rx buffer).

the proposed changes to these three functions add cli/sti pairings around the critical pieces of code. i have tested and verified the change made to serial.available as correcting the problem, while the change to serial.peek follows the exact same pattern. the changes to serial.read have been confirmed as not breaking the function, but i have not been in a position to test the failure of the original (non-atomic) version to make comparisons.

multiple testing was conducted at 115,200 baud and 500,000 baud using data streams of 1,000,000 characters sent over a 2 minute interval. any error causing loss of character would have resulted in a catastrophic (ie, very obvious) failure.

cheers,
rob   :-)

-> Squash and rebase of https://github.com/arduino/Arduino/pull/3848
2017-11-13 17:04:29 +01:00
..
Arduino.h Requested changes to not change code for non ATtinyX5s 2016-09-07 19:02:48 +02:00
CDC.cpp [AVR] Discover newer bootloader at runtime 2016-04-06 17:41:06 +02:00
Client.h Added license for Client, IPAddressm and Server (master branch) 2014-02-13 17:49:14 +01:00
HardwareSerial.cpp make serial.available, peek, read atomic 2017-11-13 17:04:29 +01:00
HardwareSerial.h Add Print::availableForWrite 2017-05-16 14:52:47 +02:00
HardwareSerial0.cpp Remove unneeded register and ISR names in HardwareSerialx.cpp 2014-05-06 10:26:46 +02:00
HardwareSerial1.cpp Remove unneeded register and ISR names in HardwareSerialx.cpp 2014-05-06 10:26:46 +02:00
HardwareSerial2.cpp Remove unneeded register and ISR names in HardwareSerialx.cpp 2014-05-06 10:26:46 +02:00
HardwareSerial3.cpp Remove unneeded register and ISR names in HardwareSerialx.cpp 2014-05-06 10:26:46 +02:00
HardwareSerial_private.h Support Atmega8 (and similar that define PE instead of UPE) again 2014-06-25 17:20:07 +02:00
IPAddress.cpp Remove old TODOs for non-standard ipv4 format support 2017-01-08 23:51:53 +01:00
IPAddress.h Fixed another regression in IPAddress.h 2015-09-24 15:52:32 +02:00
PluggableUSB.cpp [USB] use plugged modules name to create iSerial field 2015-10-21 15:23:56 +02:00
PluggableUSB.h [USB] use plugged modules name to create iSerial field 2015-10-21 15:23:56 +02:00
Print.cpp Change double quotes to single quotes 2017-01-07 19:48:12 +01:00
Print.h Removed unneeded include in Print.h 2017-05-23 17:03:42 +02:00
Printable.h Printable.h doesn't need new.h but only stdlib.h for size_t. 2014-09-06 12:37:57 +02:00
Server.h Add #include "Print.h" in Server.h 2014-09-26 22:58:19 +03:00
Stream.cpp Update comments to reflect Stream functions changed from private to protected 2017-07-07 01:28:27 +02:00
Stream.h Update comments to reflect Stream functions changed from private to protected 2017-07-07 01:28:27 +02:00
Tone.cpp Remove Compiler Warning in Tone.cpp 2015-09-28 16:30:39 +02:00
USBAPI.h Add Print::availableForWrite 2017-05-16 14:52:47 +02:00
USBCore.cpp Fixed warning about unused variable 2017-03-20 17:36:08 +01:00
USBCore.h configurable USB_VERSION string via define 2016-07-13 14:28:17 +02:00
USBDesc.h [USB] use plugged modules name to create iSerial field 2015-10-21 15:23:56 +02:00
Udp.h Add virtual beginMulticast(...) stub to UDP class 2017-02-08 15:33:41 +01:00
WCharacter.h Replacing custom String.toInt() function with a call to atol(). 2010-12-03 23:12:41 -05:00
WInterrupts.c Boilerplate compression on ISR declaration 2016-02-03 22:43:57 -02:00
WMath.cpp Removed a handful of SVN expansion keywords. See #277 2015-07-03 10:38:07 +02:00
WString.cpp Spaces to tab 2016-09-12 09:00:04 +02:00
WString.h Spaces to tab 2016-09-12 09:00:04 +02:00
abi.cpp Correct implementation of gcc specific internal functions 2014-09-06 12:42:25 +02:00
binary.h Added license for Arduino.h, binary.h and main.cpp (master branch) 2014-02-13 17:48:47 +01:00
hooks.c Added general yield()-hook for cooperative scheduling development (part 2) 2012-11-02 18:12:21 +01:00
main.cpp remove setupUSB weak hook and replace with global constructors 2015-07-16 13:13:49 +02:00
new.cpp Fixed license for new.cpp and small cosmetic changes 2014-09-06 12:44:53 +02:00
new.h Fixed license for new.cpp and small cosmetic changes 2014-09-06 12:44:53 +02:00
wiring.c Create timer0 overflow interrupt service routine for all ATtinies not just 24, 44 and 84 2017-11-13 16:16:43 +01:00
wiring_analog.c Requested changes to not change code for non ATtinyX5s 2016-09-07 19:02:48 +02:00
wiring_digital.c Fixed wrong condition in turnOffPWM(..) 2015-09-18 11:01:08 +02:00
wiring_private.h Added EXTERNAL_NUM_INTERRUPTS for AVR xxU2 series 2015-08-31 18:12:13 +02:00
wiring_pulse.S pulseInASM: rework comment style 2015-05-29 15:01:38 +02:00
wiring_pulse.c fix pulseInLong considering overflow 2015-09-21 11:59:20 +02:00
wiring_shift.c Removed a handful of SVN expansion keywords. See #277 2015-07-03 10:38:07 +02:00