arduino / arduino/ArduinoCore-avr

condense register initialization in init(). [imported]

Open
#238 0 comments 0 reactions 1 assignee Claimed by @cmaglie View on GitHub
Dominant language
C
Stars
1.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

This is [Issue 367](http://code.google.com/p/arduino/issues/detail?id=367) moved from a Google Code project.
Added by 2010-10-03T05:59:53.000Z by [wes...@gmail.com](http://code.google.com/u/103342639718054305536/).
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Enhancement, Priority-Medium
### Original description

init() in wiring.c currently does a series of sbi() calls to set bits in the configuration registers for timers, ADC, and etc.

There are two problems with this:

1) since the registers are all volatile, they get read and re-written for each bit, resulting in rather bulky code.
2) The code makes assumptions that the other bits in the register are already in the desired state, which need not be true (leading to http://code.google.com/p/arduino/issues/detail?id=364 for example.)

The attached code sets the desired state of the registers all 8 bits at once. Faster, smaller, and less prone to errors caused by unexpected initial states.

(I checked that the initial state of the registers in question is 0, and This compiles for all three platforms, and I checked that Fading.pde works on all PWM pins on an Uno, but making this sort of large change makes me nervous...)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.