aboutsummaryrefslogtreecommitdiff
path: root/firmwares/wifishield/wifi_dnld/src/clocks.c
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2013-04-18 14:17:47 +0200
committerCristian Maglie <c.maglie@bug.st>2014-01-16 16:36:06 +0100
commit3babfc2a855e49c5781f433fb5bd1227c8161dd8 (patch)
treecbcec87d2121c11ace8cefd93161d99d9ddc9bb8 /firmwares/wifishield/wifi_dnld/src/clocks.c
parent494929495ea1d64850f77a198d67a66f18a85630 (diff)
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.
Diffstat (limited to 'firmwares/wifishield/wifi_dnld/src/clocks.c')
0 files changed, 0 insertions, 0 deletions