1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-12 06:54:24 +01:00

Disabling interrupts while digitalWrite() and pinMode() modify registers (issue #146).

Updating revisions.
This commit is contained in:
David A. Mellis 2010-06-12 20:32:58 +00:00
parent e2169fa0a4
commit e2f5f0c9d6
2 changed files with 23 additions and 4 deletions

View File

@ -3,6 +3,7 @@ ARDUINO 0019
[core / libraries] [core / libraries]
* More accurate delay() function from BenF. * More accurate delay() function from BenF.
* Re-enabling PWM after tone() ends.
[environment] [environment]

View File

@ -36,8 +36,17 @@ void pinMode(uint8_t pin, uint8_t mode)
// JWS: can I let the optimizer do this? // JWS: can I let the optimizer do this?
reg = portModeRegister(port); reg = portModeRegister(port);
if (mode == INPUT) *reg &= ~bit; if (mode == INPUT) {
else *reg |= bit; uint8_t oldSREG = SREG;
cli();
*reg &= ~bit;
SREG = oldSREG;
} else {
uint8_t oldSREG = SREG;
cli();
*reg |= bit;
SREG = oldSREG;
}
} }
// Forcing this inline keeps the callers from having to push their own stuff // Forcing this inline keeps the callers from having to push their own stuff
@ -90,8 +99,17 @@ void digitalWrite(uint8_t pin, uint8_t val)
out = portOutputRegister(port); out = portOutputRegister(port);
if (val == LOW) *out &= ~bit; if (val == LOW) {
else *out |= bit; uint8_t oldSREG = SREG;
cli();
*out &= ~bit;
SREG = oldSREG;
} else {
uint8_t oldSREG = SREG;
cli();
*out |= bit;
SREG = oldSREG;
}
} }
int digitalRead(uint8_t pin) int digitalRead(uint8_t pin)