aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2015-01-18 17:34:40 +0100
committerCristian Maglie <c.maglie@bug.st>2015-01-18 17:34:40 +0100
commit61c82a1937122640f58142a1fb67aa248f0db790 (patch)
tree78d8df90f82bb93649e19f128bccfd32ebb3868b /cores/arduino
parent17db7a7843c89016ad03407c074d08a59ee62628 (diff)
Temporary fix for pulseIn() regression.
Fixes #2538
Diffstat (limited to 'cores/arduino')
-rw-r--r--cores/arduino/wiring_pulse.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/cores/arduino/wiring_pulse.c b/cores/arduino/wiring_pulse.c
index 0d96886..830c454 100644
--- a/cores/arduino/wiring_pulse.c
+++ b/cores/arduino/wiring_pulse.c
@@ -61,9 +61,25 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
width++;
}
- // convert the reading to microseconds. The loop has been determined
- // to be 20 clock cycles long and have about 16 clocks between the edge
- // and the start of the loop. There will be some error introduced by
+ // convert the reading to microseconds. There will be some error introduced by
// the interrupt handlers.
- return clockCyclesToMicroseconds(width * 21 + 16);
+
+ // Conversion constants are compiler-dependent, different compiler versions
+ // have different levels of optimization.
+#if __GNUC__==4 && __GNUC_MINOR__==3 && __GNUC_PATCHLEVEL__==2
+ // avr-gcc 4.3.2
+ return clockCyclesToMicroseconds(width * 21 + 16);
+#elif __GNUC__==4 && __GNUC_MINOR__==8 && __GNUC_PATCHLEVEL__==1
+ // avr-gcc 4.8.1
+ return clockCyclesToMicroseconds(width * 24 + 16);
+#elif __GNUC__<=4 && __GNUC_MINOR__<=3
+ // avr-gcc <=4.3.x
+ #warning "pulseIn() results may not be accurate"
+ return clockCyclesToMicroseconds(width * 21 + 16);
+#else
+ // avr-gcc >4.3.x
+ #warning "pulseIn() results may not be accurate"
+ return clockCyclesToMicroseconds(width * 24 + 16);
+#endif
+
}