1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-30 11:24:12 +01:00
Arduino/hardware/arduino/avr
Matthijs Kooijman e40cf5b7b8 Use constants for register bit positions in HardwareSerial
Previously, the constants to use for the bit positions of the various
UARTs were passed to the HardwareSerial constructor. However, this
meant that whenever these values were used, the had to be indirectly
loaded, resulting in extra code overhead. Additionally, since there is
no instruction to shift a value by a variable amount, the 1 << x
expressions (inside _BV and sbi() / cbi()) would be compiled as a loop
instead of being evaluated at compiletime.

Now, the HardwareSerial class always uses the constants for the bit
positions of UART 0 (and some code is present to make sure these
constants exist, even for targets that only have a single unnumbered
UART or start at UART1).

This was already done for the TXC0 constant, for some reason. For the
actual register addresses, this approach does not work, since these are
of course different between the different UARTs on a single chip.

Of course, always using the UART 0 constants is only correct when the
constants are actually identical for the different UARTs. It has been
verified that this is currently the case for all targets supported by
avr-gcc 4.7.2, and the code contains compile-time checks to verify this
for the current target, in case a new target is added for which this
does not hold. This verification was done using:

for i in TXC RXEN TXEN RXCIE UDRIE U2X UPE; do echo $i; grep --no-filename -r "#define $i[0-9]\? " /usr/lib/avr/include/avr/io* | sed "s/#define $i[0-9]\?\s*\(\S\)\+\s*\(\/\*.*\*\/\)\?$/\1/" | sort | uniq ; done

This command shows that the above constants are identical for all uarts
on all platforms, except for TXC, which is sometimes 6 and sometimes 0.
Further investigation shows that it is always 6, except in io90scr100.h,
but that file defines TXC0 with value 6 for the UART and uses TXC with
value 0 for some USB-related register.

This commit reduces program size on the uno by around 120 bytes.
2014-01-16 16:36:06 +01:00
..
bootloaders merge 2013-10-14 12:42:42 +02:00
cores/arduino Use constants for register bit positions in HardwareSerial 2014-01-16 16:36:06 +01:00
firmwares Merged 1.0.5 2013-04-03 13:51:04 +02:00
libraries Revert "SPI library to new format" 2013-11-21 15:05:36 +01:00
variants Merge branch 'pins-define' into ide-1.5.x 2013-12-13 15:09:40 +01:00
boards.txt In boards.txt, rename atmega328diecimila to diecimila 2013-12-08 18:16:31 +01:00
platform.txt Fixed "runtime.hardware.path" and "runtime.platform.path" values 2014-01-05 12:42:27 +01:00
programmers.txt Set correct speed of Arduino ISP programmer 2013-04-06 01:59:25 +02:00