mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Fixing bug in calling micros() from interrupts: http://code.google.com/p/arduino/issues/detail?id=55
This commit is contained in:
parent
ba5935e273
commit
3063c34ebe
@ -75,21 +75,21 @@ unsigned long millis()
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned long micros() {
|
unsigned long micros() {
|
||||||
unsigned long m, t;
|
unsigned long m;
|
||||||
uint8_t oldSREG = SREG;
|
uint8_t oldSREG = SREG, t;
|
||||||
|
|
||||||
cli();
|
cli();
|
||||||
|
m = timer0_overflow_count;
|
||||||
t = TCNT0;
|
t = TCNT0;
|
||||||
|
|
||||||
#ifdef TIFR0
|
#ifdef TIFR0
|
||||||
if ((TIFR0 & _BV(TOV0)) && (t == 0))
|
if ((TIFR0 & _BV(TOV0)) && (t < 255))
|
||||||
t = 256;
|
m++;
|
||||||
#else
|
#else
|
||||||
if ((TIFR & _BV(TOV0)) && (t == 0))
|
if ((TIFR & _BV(TOV0)) && (t < 255))
|
||||||
t = 256;
|
m++;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m = timer0_overflow_count;
|
|
||||||
SREG = oldSREG;
|
SREG = oldSREG;
|
||||||
|
|
||||||
return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
|
return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
|
||||||
|
Loading…
Reference in New Issue
Block a user