|
|
@ -28,27 +28,24 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
#include "uClock.h" |
|
|
|
#include "uClock.h" |
|
|
|
|
|
|
|
|
|
|
|
#define ATOMIC(X) noInterrupts(); X; interrupts(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Timer setup for work clock
|
|
|
|
// Timer setup for work clock
|
|
|
|
//
|
|
|
|
//
|
|
|
|
#if defined(TEENSYDUINO) && !defined(__AVR_ATmega32U4__) |
|
|
|
#if defined(TEENSYDUINO) && !defined(__AVR_ATmega32U4__) |
|
|
|
IntervalTimer _teensyTimer; |
|
|
|
IntervalTimer _uclockTimer; |
|
|
|
void teensyInterrupt(); |
|
|
|
void uclockISR(); |
|
|
|
void workClock() |
|
|
|
void uclockInitTimer() |
|
|
|
{ |
|
|
|
{ |
|
|
|
_teensyTimer.begin(teensyInterrupt, 16); |
|
|
|
_uclockTimer.begin(uclockISR, 16); |
|
|
|
// Set the interrupt priority level, controlling which other interrupts
|
|
|
|
// Set the interrupt priority level, controlling which other interrupts
|
|
|
|
// this timer is allowed to interrupt. Lower numbers are higher priority,
|
|
|
|
// this timer is allowed to interrupt. Lower numbers are higher priority,
|
|
|
|
// with 0 the highest and 255 the lowest. Most other interrupts default to 128.
|
|
|
|
// with 0 the highest and 255 the lowest. Most other interrupts default to 128.
|
|
|
|
// As a general guideline, interrupt routines that run longer should be given
|
|
|
|
// As a general guideline, interrupt routines that run longer should be given
|
|
|
|
// lower priority (higher numerical values).
|
|
|
|
// lower priority (higher numerical values).
|
|
|
|
_teensyTimer.priority(0); |
|
|
|
_uclockTimer.priority(0); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
#else |
|
|
|
#else |
|
|
|
void workClock() |
|
|
|
void uclockInitTimer() |
|
|
|
{ |
|
|
|
{ |
|
|
|
ATOMIC( |
|
|
|
ATOMIC( |
|
|
|
// Timer1
|
|
|
|
// Timer1
|
|
|
@ -126,8 +123,8 @@ uClockClass::uClockClass() |
|
|
|
|
|
|
|
|
|
|
|
void uClockClass::init()
|
|
|
|
void uClockClass::init()
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// init work clock timer interrupt in Hz
|
|
|
|
// init work clock timer interrupt at 16 microseconds
|
|
|
|
workClock(); |
|
|
|
uclockInitTimer(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void uClockClass::start()
|
|
|
|
void uClockClass::start()
|
|
|
@ -433,7 +430,7 @@ volatile uint32_t _timer = 0; |
|
|
|
// Clocked at: 62.5kHz/16usec
|
|
|
|
// Clocked at: 62.5kHz/16usec
|
|
|
|
//
|
|
|
|
//
|
|
|
|
#if defined(TEENSYDUINO) && !defined(__AVR_ATmega32U4__) |
|
|
|
#if defined(TEENSYDUINO) && !defined(__AVR_ATmega32U4__) |
|
|
|
void teensyInterrupt()
|
|
|
|
void uclockISR()
|
|
|
|
#else |
|
|
|
#else |
|
|
|
ISR(TIMER1_COMPA_vect)
|
|
|
|
ISR(TIMER1_COMPA_vect)
|
|
|
|
//ISR(TIMER2_COMPA_vect)
|
|
|
|
//ISR(TIMER2_COMPA_vect)
|
|
|
|