summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-09-18 00:58:27 +0200
committerChristian Pointner <equinox@spreadspace.org>2015-09-18 00:58:27 +0200
commit474543992511b378209457009e84d97ae14a5c9d (patch)
treea0558836a87ca07a05b49b00cb0d991a07eccf2d
parentadd target for teensy loader in contrib (diff)
add compatibility support for arduion-stub as teensy
-rw-r--r--lib/arduino-stub.cpp18
1 files changed, 12 insertions, 6 deletions
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;