Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 2131 → Rev 2132

/branches/dongfang_FC_fixedwing/arduino_atmega328/timer0.c
1,6 → 1,7
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include "eeprom.h"
#include "analog.h"
#include "controlMixer.h"
8,8 → 9,10
#include "timer0.h"
#include "output.h"
 
#ifdef USE_MK3MAG
#include "mk3mag.h"
#ifdef DO_PROFILE
volatile uint32_t global10kHzClock = 0;
volatile int32_t profileTimers[NUM_PROFILE_TIMERS];
volatile int32_t runningProfileTimers[NUM_PROFILE_TIMERS];
#endif
 
volatile uint32_t globalMillisClock = 0;
17,10 → 20,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
*****************************************************/
65,6 → 64,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;
}
 
75,8 → 80,8
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
#ifdef DO_PROFILE
global10kHzClock++;
#endif
 
if (!cnt--) { // every 10th run (9.765625kHz/10 = 976.5625Hz)
83,10 → 88,6
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
134,7 → 135,7
void delay_ms(uint16_t w) {
uint16_t t_stop = setDelay(w);
while (!checkDelay(t_stop))
;
wdt_reset();
}
 
// -----------------------------------------------------------------------
142,6 → 143,7
uint16_t t_stop;
t_stop = setDelay(w);
while (!checkDelay(t_stop)) {
wdt_reset();
debugOut.analog[30]++;
if (sensorDataReady == ALL_DATA_READY) {
analog_update();
151,6 → 153,26
if (stop) {
// Wait for new samples to get prepared but do not restart AD conversion after that!
// Caller MUST to that.
// while (!sensorDataReady != ALL_DATA_READY);
while (!sensorDataReady != ALL_DATA_READY) wdt_reset();
}
}
 
#ifdef DO_PROFILE
void startProfileTimer(uint8_t timer) {
runningProfileTimers[timer] = global10kHzClock++;
}
 
void stopProfileTimer(uint8_t timer) {
int32_t t = global10kHzClock++ - 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] / 1000L;
debugOut.analog[i+index] = tenths;
}
uint16_t tenths = global10kHzClock / 1000L;
debugOut.analog[index + NUM_PROFILE_TIMERS] = tenths;
}
#endif;