8,8 → 8,9 |
#include "timer0.h" |
#include "output.h" |
|
#ifdef USE_MK3MAG |
#include "mk3mag.h" |
#ifdef DO_PROFILE |
uint32_t profileTimers[NUM_PROFILE_TIMERS]; |
uint32_t runningProfileTimers[NUM_PROFILE_TIMERS]; |
#endif |
|
volatile uint32_t globalMillisClock = 0; |
17,10 → 18,6 |
volatile uint16_t beepTime = 0; |
volatile uint16_t beepModulation = BEEP_MODULATION_NONE; |
|
#ifdef USE_NAVICTRL |
volatile uint8_t SendSPI = 0; |
#endif |
|
/***************************************************** |
* Initialize Timer 0 |
*****************************************************/ |
74,6 → 71,12 |
TIMSK0 &= ~((1 << OCIE0B) | (1 << OCIE0A)); |
TIMSK0 |= (1 << TOIE0); |
|
#ifdef DO_PROFILE |
for (uint8_t i=0; i<NUM_PROFILE_TIMERS; i++) { |
profileTimers[i] = 0; |
} |
#endif |
|
SREG = sreg; |
} |
|
84,18 → 87,10 |
static uint8_t cnt_1ms = 1, cnt = 0; |
uint8_t beeperOn = 0; |
|
#ifdef USE_NAVICTRL |
if(SendSPI) SendSPI--; // if SendSPI is 0, the transmit of a byte via SPI bus to and from The Navicontrol is done |
#endif |
|
if (!cnt--) { // every 10th run (9.765625kHz/10 = 976.5625Hz) |
cnt = 9; |
cnt_1ms ^= 1; |
if (!cnt_1ms) { |
if (runFlightControl == 1) |
debugOut.digital[1] |= DEBUG_MAINLOOP_TIMER; |
else |
debugOut.digital[1] &= ~DEBUG_MAINLOOP_TIMER; |
runFlightControl = 1; // every 2nd run (976.5625 Hz/2 = 488.28125 Hz) |
} |
globalMillisClock++; // increment millisecond counter |
168,3 → 163,23 |
while (!analogDataReady); |
} |
} |
|
#ifdef DO_PROFILE |
void startProfileTimer(uint8_t timer) { |
runningProfileTimers[timer] = globalMillisClock; |
} |
|
void stopProfileTimer(uint8_t timer) { |
int32_t t = globalMillisClock - runningProfileTimers[timer]; |
profileTimers[timer] += t; |
} |
|
void debugProfileTimers(uint8_t index) { |
for (uint8_t i=0; i<NUM_PROFILE_TIMERS; i++) { |
uint16_t tenths = profileTimers[i] / 10000L; |
debugOut.analog[i+index] = tenths; |
} |
uint16_t tenths = globalMillisClock / 10000L; |
debugOut.analog[index + NUM_PROFILE_TIMERS] = tenths; |
} |
#endif; |