aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/wiring_digital.c
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2010-06-12 20:32:58 +0000
committerDavid A. Mellis <d.mellis@arduino.cc>2010-06-12 20:32:58 +0000
commit3b6611ae2de2caac0d2baae32f4f05bd2a3bb9b9 (patch)
tree7ed7108204513564e17b63f1190cba3bb8dd6f84 /cores/arduino/wiring_digital.c
parenta771267f69260f19f1bcde30ff1636d064671b17 (diff)
Disabling interrupts while digitalWrite() and pinMode() modify registers (issue #146).
Updating revisions.
Diffstat (limited to 'cores/arduino/wiring_digital.c')
-rwxr-xr-xcores/arduino/wiring_digital.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c
index 1cdbf6c..3529923 100755
--- a/cores/arduino/wiring_digital.c
+++ b/cores/arduino/wiring_digital.c
@@ -36,8 +36,17 @@ void pinMode(uint8_t pin, uint8_t mode)
// JWS: can I let the optimizer do this?
reg = portModeRegister(port);
- if (mode == INPUT) *reg &= ~bit;
- else *reg |= bit;
+ if (mode == INPUT) {
+ 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
@@ -90,8 +99,17 @@ void digitalWrite(uint8_t pin, uint8_t val)
out = portOutputRegister(port);
- if (val == LOW) *out &= ~bit;
- else *out |= bit;
+ if (val == LOW) {
+ uint8_t oldSREG = SREG;
+ cli();
+ *out &= ~bit;
+ SREG = oldSREG;
+ } else {
+ uint8_t oldSREG = SREG;
+ cli();
+ *out |= bit;
+ SREG = oldSREG;
+ }
}
int digitalRead(uint8_t pin)