From 474543992511b378209457009e84d97ae14a5c9d Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 18 Sep 2015 00:58:27 +0200 Subject: add compatibility support for arduion-stub as teensy --- lib/arduino-stub.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/arduino-stub.cpp') diff --git a/lib/arduino-stub.cpp b/lib/arduino-stub.cpp index 03efc95..7a62882 100644 --- a/lib/arduino-stub.cpp +++ b/lib/arduino-stub.cpp @@ -72,7 +72,13 @@ extern "C" { #define FRACT_MAX (1000 >> 3) volatile unsigned long timer0_overflow_count = 0; -volatile unsigned long timer0_millis = 0; +# if defined(CORE_TEENSY) || defined(TEENSYDUINO) +volatile unsigned long timer0_millis_count; +# define MS_COUNTER timer0_millis_count +# else +volatile unsigned long timer0_millis; +# define MS_COUNTER timer0_millis +# endif static unsigned char timer0_fract = 0; #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) @@ -83,7 +89,7 @@ ISR(TIMER0_OVF_vect) { // copy these to local variables so they can be stored in registers // (volatile variables must be read from memory on every access) - unsigned long m = timer0_millis; + unsigned long m = MS_COUNTER; unsigned char f = timer0_fract; m += MILLIS_INC; @@ -94,7 +100,7 @@ ISR(TIMER0_OVF_vect) } timer0_fract = f; - timer0_millis = m; + MS_COUNTER = m; timer0_overflow_count++; } @@ -103,10 +109,10 @@ unsigned long millis() unsigned long m; uint8_t oldSREG = SREG; - // disable interrupts while we read timer0_millis or we might get an - // inconsistent value (e.g. in the middle of a write to timer0_millis) + // disable interrupts while we read MS_COUNTER or we might get an + // inconsistent value (e.g. in the middle of a write to MS_COUNTER) cli(); - m = timer0_millis; + m = MS_COUNTER; SREG = oldSREG; return m; -- cgit v1.2.3