1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00
Commit Graph

4303 Commits

Author SHA1 Message Date
Matthijs Kooijman
9cf3740a03 Remove unneeded #ifdef in SoftwareSerial
The debugPulse function definition already checks for _DEBUG, resulting
in an empty function definiton and the function call being optimized
away.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
ead2881b1c Fix SoftwareSerial timings
Instead of using a lookup table with (wrong) timings, this calculates
the timings in SoftwareSerial::begin. This is probably a bit slower, but
since it typically happens once, this shouldn't be a problem.
Additionally, since the lookup tables can be removed, this is also a lot
smaller, as well as supporting arbitrary CPU speeds and baudrates,
instead of the limited set that was defined before.

Furthermore, this switches to use the _delay_loop_2 function from
avr-libc instead of a handcoded delay function. The avr-libc function
only takes two instructions, as opposed to four instructions for the old
one. The compiler also inlines the avr-libc function, which makes the
timings more reliable.

The calculated timings directly rely on the instructions generated by
the compiler, since a significant amount of time is spent processing
(compared to the delays, especially at higher speeds). This means that
if the code is changed, or a different compiler is used, the
calculations might need changing (though a few cycles more or less
shouldn't cause immediate breakage).

The timings in the code have been calculated from the assembly generated
by gcc 4.8.2 and gcc 4.3.2.

The RX baudrates supported by SoftwareSerial are still not unlimited. At
16Mhz, using gcc 4.8.2, everything up to 115200 works. At 8Mhz, it works
up to 57600. Using gcc 4.3.2, it also works up to 57600 at 16Mhz and up
to 38400 at 8Mhz. Note that at these highest speeds, communication
works, but is still quite sensitive to other interrupts (like the
millis() interrupts) when bytes are sent back-to-back, so there still
are corrupted bytes in RX.

TX works up to 115200 for all combinations of compiler and clock rates.

This fixes #2019
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
08fa593916 Disable the RX PCINT inside SoftwareSerial::recv
Before, the interrupt would remain enabled during reception, which would
re-set the PCINT flag because of the level changes inside the received
byte. Because interrupts are globally disabled, this would not
immediately trigger an interrupt, but the flag would be remembered to
trigger another PCINT interrupt immediately after the first one is
processed.

Typically this was not a problem, because the second interrupt would see
the stop bit, or an idle line, and decide that the interrupt triggered
for someone else. However, at high baud rates, this could cause the
next interrupt for the real start bit to be delayed so much that the
byte got corrupted.

By clearing the interrupt mask bit for just the RX pin (as opposed to
the PCINT mask bit for the entire port), any PCINT events on other bits
can still set the PCINT flag and be processed as normal. In this case,
it's likely that there will be corruption, but that's inevitable when
(other) interrupts happen during SoftwareSerial reception.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
ce6b0f89e3 Optimize SoftwareSerial::setRxIntMsk()
This precalculates the mask register and value, making setRxIntMask
considerably less complicated. Right now, this is not a big deal, but
simplifying it allows using it inside the ISR next.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
ddbe3174f0 In SoftwareSerial::recv, only calculate the new tail once
This shortens the generated code a bit more.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
9d8f350ffe Mark SoftwareSerial::recv and handle_interrupt as always_inline
Since those functions are only called once now, it makes sense to inline
them. This saves a few bytes of program space, but also saves a few
cycles in the critical RX path.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
5af847d3a4 In SoftwareSerial, use ISR_ALIASOF to prevent duplication
Previously, up to four separate but identical ISR routines were defined,
for PCINT0, PCINT1, PCINT2 and PCINT3. Each of these would generate
their own function, with a lot of push-popping because another function
was called.

Now, the ISR_ALIASOF macro from avr-libc is used to declare just the
PCINT0 version and make all other ISRs point to that one, saving a lot
of program space, as well as some speed because of improved inlining.

On an Arduino Uno with gcc 4.3, this saves 168 bytes. With gcc 4.8, this
saves 150 bytes.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
87f89f6100 Optimize SoftwareSerial::recv
Similar to SoftwareSerial::write, this rewrites the loop to only touch
the MSB and then shift those bits up, allowing the compiler to generate
more efficient code. Unlike the write function however, it is not needed
to put all instance variables used into local variables, for some reason
the compiler already does this (and doing it manually even makes the
code bigger).

On the Arduino Uno using gcc 4.3 this saves 26 bytes. Using gcc 4.8 this
saves 30 bytes.

Note that this removes the else clause in the code, making the C code
unbalanced, which looks like it breaks timing balance. However, looking
at the code generated by the compiler, it turns out that the old code
was actually unbalanced, while the new code is properly balanced.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
764f24266e Further optimize SoftwareSerial::write
This change restructures the loop, to help the compiler generate shorter
code (because now only the LSB of the data byte is checked and
subsequent bytes are shifted down one by one, it can use th "skip if bit
set" instruction).

Furthermore, it puts most attributes in local variables, which causes
the compiler to put them into registers. This makes the timing-critical
part of the code smaller, making it easier to provide accurate timings.

On an Arduino uno using gcc 4.3, this saves 58 bytes. On gcc 4.8, this
saves 14 bytes.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
80ea38b1dc Mark SoftwareSerial::tx_pin_write as "always_inline"
Somehow gcc 4.8 doesn't inline this function, even though it is always
called with constant arguments and can be reduced to just a few
instructions when inlined. Adding the always_inline attribute makes gcc
inline it, saving 46 bytes on the Arduino uno.

gcc 4.3 already inlined this function, so there are no space
savings there.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
416198a03b Simplify SoftwareSerial::write
Before, there was nearly identical code for the inverted and regular
cases. However, simply inverting the byte in the inverted case allows
using the regular code twice, reducing the generated code size by 100
bytes (on an Arduino Uno and gcc 4.3, on gcc 4.8 the reduction is 50
bytes).
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
6685aa999c Use stopListening() in SoftwareSerial::end()
stopListening also disabled the interrupt, if needed, so calling that
function makes more sense. Since stopListening only disables the
interrupt when the current SoftwareSerial is the active object, and that
can only be the case when _rx_delay_stopbit is non-zero, there is no
need to separately check _rx_delay_stopbit anymore.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
f3aa5f23c4 Fix race condition in SoftwareSerial::overflow()
If an interrupt causing overflow would occur between reading
_buffer_overflow and clearing it, this overflow condition would be
immediately cleared and never be returned by overflow().

By only clearing the overflow flag if an overflow actually occurred,
this problem goes away (worst case overflow() returns false even though
an overflow _just_ occurred, but then the next call to overflow() will
return true).
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
b1de3e6621 Toggle SoftwareSerial interrupts when starting / stopping to listen
This prevents interrupts from triggering when the SoftwareSerial
instance is not even listening.

Additionally, this removes the need to disable interrupts in
SoftwareSerial::listen, since no interrupts are active while it touches
the variables.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
934393398b Add SoftwareSerial::stopListening()
This allows one to explicitly stop a SoftwareSerial instance from
listening, without having to make another one listening.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
db1a4ad139 Add SoftwareSerial::setRxIntMsk()
This moves the interrupt mask enabling / disabling code into a separate
method, so we can call it from multiple spots next.
2015-01-26 17:03:25 +01:00
Matthijs Kooijman
1704e7e820 Let SoftwareSerial::end also check against _rx_delay_stopbit
The current check is still always false when the old check was, but
additionally it will not disable the interrupts when they were never
enabled (which shouldn't matter much, but this is more consistent).
2015-01-26 17:03:24 +01:00
Matthijs Kooijman
b1c7a3d05f Let SoftwareSerial::listen() fail on invalid rx baud rates
In this case, SoftwareSerial::begin will not have enabled the
interrupts, so better not allow the SoftwareSerial instance to enter the
listening state either.
2015-01-26 17:03:24 +01:00
Matthijs Kooijman
937cc51c69 Clear SoftwareSerial rx delay if no interrupt register is found
Before enabling interupts, begin would see if the given receive pin
actually has an associated PCINT register. If not, the interrupts would
not be enabled.

Now, the same check is done, but when no register is available, the rx
parameters are not loaded at all (which in turn prevents the interrupt
from being enabled). This allows all code to use the same "is rx
enabled" (which will be added next).
2015-01-26 17:03:24 +01:00
Cristian Maglie
379df90b30 Update revision log 2015-01-23 11:22:40 +01:00
Federico Fissore
db8cbf24c9 Merge branch 'ide-1.5.x' 2015-01-22 17:15:05 +01:00
Arturo Guadalupi
1f08b5ede4 Cherry picked fix from 87865ac19d 2015-01-22 17:04:59 +01:00
Cristian Maglie
136c04ad28 Merge branch 'ide-1.5.x' of github.com:arduino/Arduino into ide-1.5.x 2015-01-20 15:50:25 +01:00
Cristian Maglie
14fe427050 Updated revision log 2015-01-20 15:50:13 +01:00
Federico Fissore
7a4de50ff8 Merge pull request #2552 from agdl/ide-1.5.x_library_adoc
Added README.adoc for the library manager project
2015-01-20 09:18:22 +01:00
Cristian Maglie
00dfd93726 Added dependencies for AStylej.dll 2015-01-19 23:08:08 +04:30
Cristian Maglie
f4a6b623b3 Updated translations 2015-01-19 14:57:31 +01:00
Cristian Maglie
d2269ca89e Update revision log 2015-01-19 13:50:57 +01:00
Cristian Maglie
0e013406bc Merge branch 'sam-usart-mode-fix' into ide-1.5.x 2015-01-19 13:43:42 +01:00
Cristian Maglie
07d1abfe43 Merge pull request #2556 from cmaglie/ide-1.5.x-pulsein-regression
Temporary fix for pulseIn() regression
2015-01-19 13:40:09 +01:00
Cristian Maglie
8ddc5198f6 Temporary fix for pulseIn() regression.
Fixes #2538
2015-01-18 17:34:40 +01:00
Arturo Guadalupi
ce412a0461 Added README.adoc for the library manager project 2015-01-16 17:14:02 +01:00
Cristian Maglie
6d7751cf5f Fixed some libraries metadata. 2015-01-16 12:22:24 +01:00
Cristian Maglie
5ff4c9f8dc Temporary disabled DefaultTargetTest under certain conditions 2015-01-14 18:42:19 +01:00
Cristian Maglie
3a062f0582 Updated translation from transifex 2015-01-14 18:27:27 +01:00
Cristian Maglie
ff95d03663 Updated some translation strings 2015-01-14 18:05:00 +01:00
Cristian Maglie
81808d532e Merge branch 'ide-1.5.x-fail-when-no-platform-txt' of https://github.com/ffissore/Arduino into ide-1.5.x 2015-01-14 17:19:11 +01:00
Cristian Maglie
60309fe8b8 Fixed test 2015-01-14 17:18:43 +01:00
Cristian Maglie
00f23d3aad sam: Fixed initialization of UART/USART mode register 2015-01-14 00:08:59 +01:00
Cristian Maglie
244a750bef Merge branch 'wayoda-fix-find-dialog-layout' into ide-1.5.x 2015-01-13 23:30:22 +01:00
Cristian Maglie
fdbb45ec47 update revision log 2015-01-13 23:28:19 +01:00
Cristian Maglie
17115b0a9b Fixed NPE when import menu are empty 2015-01-13 23:16:53 +01:00
Cristian Maglie
56b9f1cd6f Fixed NPE when currently selected platform is no more installed.
BaseNoGui.getTargetBoard() now handles null TargetBoard.
Removed unused method Base.getTargetBoard()
2015-01-13 23:16:53 +01:00
Cristian Maglie
ec67b0d4be Optimized FileUtils.recursiveDelete(File) function 2015-01-13 23:16:53 +01:00
Cristian Maglie
29d2ab72e2 Fixed a bunch of simple warnings in java code 2015-01-13 23:16:50 +01:00
Cristian Maglie
99715d22d9 Removed unused classes Commander.java and Webserver.java 2015-01-13 23:05:36 +01:00
Arturo Guadalupi
87865ac19d Update setCursor.ino
Changedfrom (thisRow, thisCol) to lcd.Setcursor(thisCol, thisRow). It was an error.
2015-01-12 14:37:50 +01:00
Chris
7e9cf6d612 sam: updated UART/USART modes 2015-01-09 20:25:09 +00:00
Cristian Maglie
5e33ca4cd4 Merge pull request #2546 from zorzano/ide-1.5.x.GSM.1
Minor modifications aligning internal and Arduino versions
2015-01-09 14:06:10 +01:00
Javier Zorzano
2b14a9349c Align types: int to unsigned int
Block send SMS until finished operation.
GSM3IO.h. Keeps most of board-dependant pins
Flush buffer after GPRS detach
Delete some references to HardwareSerial.h
Include OFF modem status
2015-01-08 18:36:41 +01:00