Commit Graph

3563 Commits

Author SHA1 Message Date
Cristian Maglie 92958ef4cb Merge pull request #1863 from matthijskooijman/ide-1.5.x-serial-int
In HardwareSerial, don't use int for buffer indices
2014-02-14 15:42:26 +01:00
Cristian Maglie 8504bca280 Merge branch 'ide-1.5.x' of github.com:dpslwk/Arduino into dpslwk-ide-1.5.x 2014-02-14 15:35:47 +01:00
Matthijs Kooijman 6372eb8c6c In HardwareSerial, don't use int for buffer indices
The index attributes have been uint8_t for a while, so there is no point
in using int for local variables. This should allow the compiler to
generate slightly more efficient code, but (at least on gcc 4.8.2) it
also confuses the register allocator, causing this change to increase
code size by 2 bytes instead due to extra push/pop instructions (but
this will probably change in the future if the compiler improves).
2014-02-14 10:25:34 +01:00
Cristian Maglie 6104b2879d Merge remote-tracking branch 'arduino/master' into ide-1.5.x 2014-02-13 18:16:48 +01:00
Cristian Maglie cc6d7cdbd1 Added license for Client, IPAddressm and Server (master branch)
See #1847 and #1117
2014-02-13 17:49:14 +01:00
Cristian Maglie 8eaaeebadf Added license for Arduino.h, binary.h and main.cpp (master branch)
See #1847 and #1117
2014-02-13 17:48:47 +01:00
Cristian Maglie 79f5a34954 Revert "Changed pins definition in variants from constants to #defines."
This reverts commit e2b15c852b.
2014-02-13 17:37:00 +01:00
Cristian Maglie a96c8cab12 Merge branch 'master' into ide-1.5.x 2014-02-12 17:17:33 +01:00
Cristian Maglie 2a8c06381f Added some friendly messages for Arduino Robot include errors on old sketches
After merging #1859, old sketches that uses Robot_Control library must include
Wire.h and SPI.h to work properly.
2014-02-12 15:28:53 +01:00
Cristian Maglie 9dd425515b Merge branch 'master' of github.com:X-Y/Arduino into X-Y-master 2014-02-12 14:51:46 +01:00
Cristian Maglie eb1e2f2db1 Revert "Changed pins definition in variants from constants to #defines."
This reverts commit 7fcba37acf.
2014-02-12 14:46:48 +01:00
Xun Yang 53adddcb33 Fixed issue #1478, #1599, #1709, motors being opposite, updated turning algorithm 2014-02-12 02:02:20 +01:00
Cristian Maglie a44f4bef7c Merge remote-tracking branch 'arduino/master' into ide-1.5.x
Conflicts:
	app/src/processing/app/Base.java
2014-02-11 16:44:07 +01:00
Cristian Maglie b78fcf5139 Merge pull request #1853 from PaulStoffregen/master
If 2 libs have same .h file, use the lib with same dir name
2014-02-11 16:24:05 +01:00
PaulStoffregen ef4f0f3bc9 If 2 libs have same .h file, use the lib with same dir name 2014-02-10 14:18:47 -08:00
Cristian Maglie 397046a844 Added license for Arduino.h, binary.h and main.cpp
See #1847
2014-02-10 12:55:16 +01:00
Cristian Maglie 9eb0c1495c Added license for Client, IPAddressm and Server
See #1847
2014-02-10 12:55:16 +01:00
Cristian Maglie 9d46f1ff12 Added license for avr/HardwareSerial.
See #1847
2014-02-10 12:55:16 +01:00
Cristian Maglie d60f1df996 Added command line option --verbose-build and --verbose-upload 2014-02-10 12:55:16 +01:00
Fede85 5dfafe7847 WiFi Shield examples: added the firmware version check 2014-02-06 18:40:48 +01:00
Federico Fissore 1fe82d847c Merge remote-tracking branch 'arduino/ide-1.5.x' into ide-1.5.x 2014-02-06 10:22:20 +01:00
Federico Fissore 0c62798fcb Fixed typo in test 2014-02-06 10:21:54 +01:00
Cristian Maglie 793b139d39 Merge remote-tracking branch 'arduino/master' into ide-1.5.x 2014-02-05 15:58:30 +01:00
Cristian Maglie b415903b69 Merge pull request #1836 from KonradIT/master
Use markdown lang in the readme.
2014-02-05 12:32:20 +01:00
Scott Fitzgerald 1c28dab57b Updated Listfiles SD example
Changed SS pin to 4 for consistency with other examples
2014-02-02 14:35:04 +04:00
Cristian Maglie b6fa3c7261 Update .classpath 2014-01-30 11:03:22 +01:00
Konrad Iturbe 7ea7c5291d Rename README.mkdn to README.md 2014-01-29 22:18:24 +01:00
Konrad Iturbe ede9b56407 Update and rename readme.txt to README.mkdn 2014-01-29 21:59:23 +01:00
Konrad Iturbe 9b86cb6e42 Update readme.txt 2014-01-29 21:57:29 +01:00
Cristian Maglie 5cf8671b4a Merge pull request #1835 from ribbons/hardwareserial-warning
Reorder HardwareSerial initialisation list to fix compiler warnings
2014-01-29 12:44:55 -08:00
Matt Robinson 6315177191 Reorder HardwareSerial init to fix compiler warn
Switch the tx and rx buffer head/tail entries in the HardwareSerial
initialisation list so that they match the order the fields are defined
in. This fixes a compiler warning (repeated for each of the
HardwareSerial source files the header is used in).
2014-01-29 20:10:32 +00:00
Cristian Maglie fbea640055 Fixed macosx app template to reflect jssc update 2014-01-29 16:40:49 +01:00
Scott Fitzgerald 017326acc6 Minor changes to Communication Examples
Added a note to the included Processing sketches about replacing
println(Serial.list()) with Serial.printArray() if using Processing 2.1
or later
2014-01-29 14:27:09 +04:00
Matt Robinson cd9657ffd0 Clean up unused var from HardwareSerial_private.h 2014-01-28 20:39:15 +00:00
Cristian Maglie 9ebfe233b8 Merge branch 'patch-1' of github.com:bobh66/Arduino into bobh66-patch-1 2014-01-28 19:01:26 +01:00
Cristian Maglie bcfa1a7479 Updated revision log 2014-01-28 18:33:08 +01:00
Cristian Maglie 5b48b1e4fe Merge branch 'serial-patch-2' into ide-1.5.x 2014-01-27 22:48:17 +01:00
Cristian Maglie 48c1223762 Update to jssc 2.8.0
Fixes #1811
2014-01-27 16:06:55 +01:00
Cristian Maglie f876733491 Updated manpage 2014-01-25 23:29:35 +01:00
Cristian Maglie a013ab2dda Added some string to translate 2014-01-23 17:24:13 +01:00
Cristian Maglie 895d394565 Added command line option "--preferences-file" to manually set the path of preferences. 2014-01-23 17:20:58 +01:00
Cristian Maglie dd02dcffab Merge branch 'master' into ide-1.5.x
Conflicts:
	app/src/processing/app/debug/Compiler.java
2014-01-23 13:17:46 +01:00
Matthijs Kooijman 9ad14b2f0c In HardwareSerial::write, bypass the queue when it's empty
This helps improve the effective datarate on high (>500kbit/s) bitrates,
by skipping the interrupt and associated overhead. At 1 Mbit/s the
implementation previously got up to about 600-700 kbit/s, but now it
actually gets up to the 1Mbit/s (values are rough estimates, though).
2014-01-22 12:06:02 +01:00
Cristian Maglie 275c0a02b1 Inlined HardwareSerial calls to RX ISR.
Moreover, declaring pointers-to-registers as const and using initializer
list in class constructor allows the compiler to further improve inlining
performance.

This change recovers about 50 bytes of program space on single-UART devices.

See #1711
2014-01-22 11:19:35 +01:00
Matthijs Kooijman 0e97bcb2df Put each HardwareSerial instance in its own .cpp file
By putting the ISRs and HardwareSerial instance for each instance in a
separate compilation unit, the compile will only consider them for
linking when the instance is actually used. The ISR is always referenced
by the compiler runtime and the Serialx_available() function is always
referenced by SerialEventRun(), but both references are weak and thus do
not cause the compilation to be included in the link by themselves.

The effect of this is that when multiple HardwareSerial ports are
available, but not all are used, buffers are only allocated and ISRs are
only included for the serial ports that are used. On the mega, this
lowers memory usage from 653 bytes to just 182 when only using the first
serial port.

On boards with just a single port, there is no change, since the code
and memory was already left out when no serial port was used at all.

This fixes #1425 and fixes #1259.
2014-01-22 09:39:19 +01:00
Matthijs Kooijman 8e43c1a0cd Centrally decide which hardware UARTS are available
Before, this decision was made in few different places, based on
sometimes different register defines.

Now, HardwareSerial.h decides wich UARTS are available, defines
USE_HWSERIALn macros and HardwareSerial.cpp simply checks these macros
(together with some #ifs to decide which registers to use for UART 0).
For consistency, USBAPI.h also defines a HAVE_CDCSERIAL macro when
applicable.

For supported targets, this should change any behaviour. For unsupported
targets, the error messages might subtly change because some checks are
moved or changed.

Additionally, this moves the USBAPI.h include form HardareSerial.h into
Arduino.h and raises an error when both CDC serial and UART0 are
available (previously this would silently use UART0 instead of CDC, but
there is not currently any Atmel chip available for which this would
occur).
2014-01-22 09:38:34 +01:00
Matthijs Kooijman 0be4e8cd3c Disable the UDRE interrupt sooner in HardwareSerial
Before, the interrupt was disabled when it was triggered and it turned
out there was no data to send. However, the interrupt can be disabled
already when the last byte is written to the UART, since write() will
always re-enable the interrupt when it adds new data to the buffer.

Closes: #1008
2014-01-22 09:38:25 +01:00
Matthijs Kooijman ccd8880a37 Fix lockup when writing to HardwareSerial with interrupts disabled
When interrupts are disabled, writing to HardwareSerial could cause a
lockup. When the tx buffer is full, a busy-wait loop is used to wait for
the interrupt handler to free up a byte in the buffer. However, when
interrupts are disabled, this will of course never happen and the
Arduino will lock up. This often caused lockups when doing (big) debug
printing from an interrupt handler.

Additionally, calling flush() with interrupts disabled while
transmission was in progress would also cause a lockup.

When interrupts are disabled, the code now actively checks the UDRE
(UART Data Register Empty) and calls the interrupt handler to free up
room if the bit is set.

This can lead to delays in interrupt handlers when the serial buffer is
full, but a delay is of course always preferred to a lockup.

Closes: #672
References: #1147
2014-01-22 09:38:16 +01:00
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
Matthijs Kooijman 3d346518e0 Improve HardwareSerial::flush()
The flush() method blocks until all characters in the serial buffer have
been written to the uart _and_ transmitted. This is checked by waiting
until the "TXC" (TX Complete) bit is set by the UART, signalling
completion. This bit is cleared by write() when adding a new byte to the
buffer and set by the hardware after tranmission ends, so it is always
guaranteed to be zero from the moment the first byte in a sequence is
queued until the moment the last byte is transmitted, and it is one from
the moment the last byte in the buffer is transmitted until the first
byte in the next sequence is queued.

However, the TXC bit is also zero from initialization to the moment the
first byte ever is queued (and then continues to be zero until the first
sequence of bytes completes transmission). Unfortunately we cannot
manually set the TXC bit during initialization, we can only clear it. To
make sure that flush() would not (indefinitely) block when it is called
_before_ anything was written to the serial device, the "transmitting"
variable was introduced.

This variable suggests that it is only true when something is
transmitting, which isn't currently the case (it remains true after
transmission is complete until flush() is called, for example).
Furthermore, there is no need to keep the status of transmission, the
only thing needed is to remember if anything has ever been written, so
the corner case described above can be detected.

This commit improves the code by:
 - Renaming the "transmitting" variable to _written (making it more
   clear and following the leading underscore naming convention).
 - Not resetting the value of _written at the end of flush(), there is
   no point to this.
 - Only checking the "_written" value once in flush(), since it can
   never be toggled off anyway.
 - Initializing the value of _written in both versions of _begin (though
   it probably gets initialized to 0 by default anyway, better to be
   explicit).
2014-01-22 09:37:54 +01:00