1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-29 10:24:12 +01:00
Go to file
Matthijs Kooijman 4fb15f29ed Fix HardwareSerial::flush() when interrupts are kept disabled for a while
It turns out there is an additional corner case. The analysis in the
previous commit wrt to flush() assumes that the data register is always
kept filled by the interrupt handler, so the TXC bit won't get set until
all the queued bytes have been transmitted. But, when interrupts are
disabled for a longer period (for example when an interrupt handler for
another device is running for longer than 1-2 byte times), it could
happen that the UART stops transmitting while there are still more bytes
queued (but these are in the buffer, not in the UDR register, so the
UART can't know about them).

In this case, the TXC bit would get set, but the transmission is not
complete yet. We can easily detect this case by looking at the head and
tail pointers, but it seems easier to instead look at the UDRIE bit
(the TX interrupt is enabled if and only if there are bytes in the
queue). To fix this corner case, this commit:
 - Checks the UDRIE bit and only if it is unset, looks at the TXC bit.
 - Moves the clearing of TXC from write() to the tx interrupt handler.
   This (still) causes the TXC bit to be cleared whenever a byte is
   queued when the buffer is empty (in this case the tx interrupt will
   trigger directly after write() is called). It also causes the TXC bit
   to be cleared whenever transmission is resumed after it halted
   because interrupts have been disabled for too long.

As a side effect, another race condition is prevented. This could occur
at very high bitrates, where the transmission would be completed before
the code got time to clear the TXC0 register, making the clear happen
_after_ the transmission was already complete. With the new code, the
clearing of TXC happens directly after writing to the UDR register,
while interrupts are disabled, and we can be certain the data
transmission needs more time than one instruction to complete. This
fixes #1463 and replaces #1456.
2014-01-22 09:38:04 +01:00
.settings Update to eclipse project files 2011-12-31 15:30:50 +01:00
app Merge branch 'lib-1.5-rev2' into HEAD 2014-01-09 14:56:23 +01:00
build Merge remote-tracking branch 'matthijs/ide-1.5.x-ipaddress-const' into ide-1.5.x 2014-01-16 13:17:44 +01:00
core working on #223: Auto-detection of serial ports. Linux version ready 2013-05-06 12:31:01 +02:00
hardware Fix HardwareSerial::flush() when interrupts are kept disabled for a while 2014-01-22 09:38:04 +01:00
libraries Merge branch 'lib-1.5-rev2' into HEAD 2014-01-09 14:56:23 +01:00
.classpath jssc: updated config files (eclipse, ant build.xml, windows launcher, mac template.app), removed rxtx binaries 2013-11-28 17:27:13 +01:00
.gitignore Introducing Artistic Style: new IDE autoformatter 2013-10-14 18:11:30 +02:00
.project Fix eclipse project files 2012-01-11 14:18:48 +01:00
format.every.sketch.sh Added script to run astyle every once in a while against all .ino files 2013-12-11 21:55:00 +01:00
license.txt adding LGPL (a bit late, whoops). 2007-10-12 01:58:48 +00:00
readme.txt Update readme.txt 2013-10-23 18:39:19 +02:00
todo.txt Updates to build.xml. (version auto defetect for "dist" target) 2013-01-24 14:46:57 +01:00

Arduino is an open-source physical computing platform based on a simple i/o
board and a development environment that implements the Processing/Wiring
language. Arduino can be used to develop stand-alone interactive objects or
can be connected to software on your computer (e.g. Flash, Processing, MaxMSP).
The boards can be assembled by hand or purchased preassembled; the open-source
IDE can be downloaded for free.

For more information, see the website at: http://www.arduino.cc/
or the forums at: http://arduino.cc/forum/

To report a *bug* in the software or to request *a simple enhancement* go to:
http://github.com/arduino/Arduino/issues

More complex requests and technical discussion should go on the Arduino Developers
mailing list:
https://groups.google.com/a/arduino.cc/forum/#!forum/developers

If you're interested in modifying or extending the Arduino software, we strongly 
suggest discussing your ideas on the Developers mailing list *before* starting
to work on them. That way you can coordinate with the Arduino Team and others,
giving your work a higher chance of being integrated into the official release
https://groups.google.com/a/arduino.cc/forum/#!forum/developers

INSTALLATION
Detailed instructions are in reference/Guide_Windows.html and
reference/Guide_MacOSX.html.  For Linux, see the Arduino playground:
http://www.arduino.cc/playground/Learning/Linux

CREDITS
Arduino is an open source project, supported by many.

The Arduino team is composed of Massimo Banzi, David Cuartielles, Tom Igoe,
Gianluca Martino, Daniela Antonietti, and David A. Mellis.

Arduino uses the GNU avr-gcc toolchain, avrdude, avr-libc, and code from
Processing and Wiring.

Icon and about image designed by ToDo: http://www.todo.to.it/