Subversion Repositories FlightCtrl

Rev

Rev 2099 | Rev 2125 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2099 Rev 2124
Line 6... Line 6...
6
#include "controlMixer.h"
6
#include "controlMixer.h"
Line 7... Line 7...
7
 
7
 
8
#include "timer0.h"
8
#include "timer0.h"
Line 9... Line 9...
9
#include "output.h"
9
#include "output.h"
10
 
10
 
-
 
11
#ifdef DO_PROFILE
11
#ifdef USE_MK3MAG
12
uint32_t profileTimers[NUM_PROFILE_TIMERS];
Line 12... Line 13...
12
#include "mk3mag.h"
13
uint32_t runningProfileTimers[NUM_PROFILE_TIMERS];
13
#endif
14
#endif
14
 
15
 
15
volatile uint32_t globalMillisClock = 0;
16
volatile uint32_t globalMillisClock = 0;
Line 16... Line -...
16
volatile uint8_t  runFlightControl = 0;
-
 
17
volatile uint16_t beepTime = 0;
-
 
18
volatile uint16_t beepModulation = BEEP_MODULATION_NONE;
-
 
19
 
-
 
20
#ifdef USE_NAVICTRL
17
volatile uint8_t  runFlightControl = 0;
21
volatile uint8_t SendSPI = 0;
18
volatile uint16_t beepTime = 0;
22
#endif
19
volatile uint16_t beepModulation = BEEP_MODULATION_NONE;
23
 
20
 
24
/*****************************************************
21
/*****************************************************
Line 72... Line 69...
72
  // Timer/Counter 0 Interrupt Mask Register
69
  // Timer/Counter 0 Interrupt Mask Register
73
  // enable timer overflow interrupt only
70
  // enable timer overflow interrupt only
74
  TIMSK0 &= ~((1 << OCIE0B) | (1 << OCIE0A));
71
  TIMSK0 &= ~((1 << OCIE0B) | (1 << OCIE0A));
75
  TIMSK0 |= (1 << TOIE0);
72
  TIMSK0 |= (1 << TOIE0);
Line -... Line 73...
-
 
73
 
-
 
74
#ifdef DO_PROFILE
-
 
75
  for (uint8_t i=0; i<NUM_PROFILE_TIMERS; i++) {
-
 
76
          profileTimers[i] = 0;
-
 
77
  }
-
 
78
#endif
76
 
79
 
77
  SREG = sreg;
80
  SREG = sreg;
Line 78... Line 81...
78
}
81
}
79
 
82
 
80
/*****************************************************/
83
/*****************************************************/
81
/*          Interrupt Routine of Timer 0             */
84
/*          Interrupt Routine of Timer 0             */
82
/*****************************************************/
85
/*****************************************************/
83
ISR(TIMER0_OVF_vect) { // 9765.625 Hz
86
ISR(TIMER0_OVF_vect) { // 9765.625 Hz
Line 84... Line -...
84
  static uint8_t cnt_1ms = 1, cnt = 0;
-
 
85
  uint8_t beeperOn = 0;
-
 
86
 
-
 
87
#ifdef USE_NAVICTRL
-
 
88
  if(SendSPI) SendSPI--; // if SendSPI is 0, the transmit of a byte via SPI bus to and from The Navicontrol is done
87
  static uint8_t cnt_1ms = 1, cnt = 0;
89
#endif
88
  uint8_t beeperOn = 0;
90
 
89
 
91
  if (!cnt--) { // every 10th run (9.765625kHz/10 = 976.5625Hz)
90
  if (!cnt--) { // every 10th run (9.765625kHz/10 = 976.5625Hz)
92
    cnt = 9;
-
 
93
    cnt_1ms ^= 1;
-
 
94
    if (!cnt_1ms) {
-
 
95
      if (runFlightControl == 1)
-
 
96
        debugOut.digital[1] |= DEBUG_MAINLOOP_TIMER;
91
    cnt = 9;
97
      else
92
    cnt_1ms ^= 1;
98
        debugOut.digital[1] &= ~DEBUG_MAINLOOP_TIMER;
93
    if (!cnt_1ms) {
99
      runFlightControl = 1; // every 2nd run (976.5625 Hz/2 = 488.28125 Hz)
94
      runFlightControl = 1; // every 2nd run (976.5625 Hz/2 = 488.28125 Hz)
Line 166... Line 161...
166
  // Wait for new samples to get prepared but do not restart AD conversion after that!
161
  // Wait for new samples to get prepared but do not restart AD conversion after that!
167
  // Caller MUST to that.
162
  // Caller MUST to that.
168
        while (!analogDataReady);
163
        while (!analogDataReady);
169
  }
164
  }
170
}
165
}
-
 
166
 
-
 
167
#ifdef DO_PROFILE
-
 
168
void startProfileTimer(uint8_t timer) {
-
 
169
  runningProfileTimers[timer] = globalMillisClock;
-
 
170
}
-
 
171
 
-
 
172
void stopProfileTimer(uint8_t timer) {
-
 
173
  int32_t t = globalMillisClock - runningProfileTimers[timer];
-
 
174
  profileTimers[timer] += t;
-
 
175
}
-
 
176
 
-
 
177
void debugProfileTimers(uint8_t index) {
-
 
178
  for (uint8_t i=0; i<NUM_PROFILE_TIMERS; i++) {
-
 
179
        uint16_t tenths = profileTimers[i] / 10000L;
-
 
180
        debugOut.analog[i+index] = tenths;
-
 
181
  }
-
 
182
  uint16_t tenths = globalMillisClock / 10000L;
-
 
183
  debugOut.analog[index + NUM_PROFILE_TIMERS] = tenths;
-
 
184
}
-
 
185
#endif;