Rev 2109 | Rev 2135 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2109 | Rev 2132 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include <inttypes.h> |
1 | #include <inttypes.h> |
2 | #include <avr/io.h> |
2 | #include <avr/io.h> |
3 | #include <avr/interrupt.h> |
3 | #include <avr/interrupt.h> |
- | 4 | #include <avr/wdt.h> |
|
4 | #include "eeprom.h" |
5 | #include "eeprom.h" |
5 | #include "analog.h" |
6 | #include "analog.h" |
6 | #include "controlMixer.h" |
7 | #include "controlMixer.h" |
Line 7... | Line 8... | ||
7 | 8 | ||
8 | #include "timer0.h" |
9 | #include "timer0.h" |
Line 9... | Line 10... | ||
9 | #include "output.h" |
10 | #include "output.h" |
10 | 11 | ||
- | 12 | #ifdef DO_PROFILE |
|
- | 13 | volatile uint32_t global10kHzClock = 0; |
|
11 | #ifdef USE_MK3MAG |
14 | volatile int32_t profileTimers[NUM_PROFILE_TIMERS]; |
Line 12... | Line 15... | ||
12 | #include "mk3mag.h" |
15 | volatile int32_t runningProfileTimers[NUM_PROFILE_TIMERS]; |
13 | #endif |
16 | #endif |
14 | 17 | ||
15 | volatile uint32_t globalMillisClock = 0; |
18 | 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 |
19 | volatile uint8_t runFlightControl = 0; |
21 | volatile uint8_t SendSPI = 0; |
20 | volatile uint16_t beepTime = 0; |
22 | #endif |
21 | volatile uint16_t beepModulation = BEEP_MODULATION_NONE; |
23 | 22 | ||
24 | /***************************************************** |
23 | /***************************************************** |
Line 63... | Line 62... | ||
63 | // Timer/Counter 0 Interrupt Mask Register |
62 | // Timer/Counter 0 Interrupt Mask Register |
64 | // enable timer overflow interrupt only |
63 | // enable timer overflow interrupt only |
65 | TIMSK0 &= ~((1 << OCIE0B) | (1 << OCIE0A)); |
64 | TIMSK0 &= ~((1 << OCIE0B) | (1 << OCIE0A)); |
66 | TIMSK0 |= (1 << TOIE0); |
65 | TIMSK0 |= (1 << TOIE0); |
Line -... | Line 66... | ||
- | 66 | ||
- | 67 | #ifdef DO_PROFILE |
|
- | 68 | for (uint8_t i=0; i<NUM_PROFILE_TIMERS; i++) { |
|
- | 69 | profileTimers[i] = 0; |
|
- | 70 | } |
|
- | 71 | #endif |
|
67 | 72 | ||
68 | SREG = sreg; |
73 | SREG = sreg; |
Line 69... | Line 74... | ||
69 | } |
74 | } |
70 | 75 | ||
71 | /*****************************************************/ |
76 | /*****************************************************/ |
72 | /* Interrupt Routine of Timer 0 */ |
77 | /* Interrupt Routine of Timer 0 */ |
73 | /*****************************************************/ |
78 | /*****************************************************/ |
74 | ISR(TIMER0_OVF_vect) { // 9765.625 Hz |
79 | ISR(TIMER0_OVF_vect) { // 9765.625 Hz |
Line 75... | Line 80... | ||
75 | static uint8_t cnt_1ms = 1, cnt = 0; |
80 | static uint8_t cnt_1ms = 1, cnt = 0; |
76 | uint8_t beeperOn = 0; |
81 | uint8_t beeperOn = 0; |
77 | 82 | ||
Line 78... | Line 83... | ||
78 | #ifdef USE_NAVICTRL |
83 | #ifdef DO_PROFILE |
79 | if(SendSPI) SendSPI--; // if SendSPI is 0, the transmit of a byte via SPI bus to and from The Navicontrol is done |
84 | global10kHzClock++; |
80 | #endif |
85 | #endif |
81 | 86 | ||
82 | if (!cnt--) { // every 10th run (9.765625kHz/10 = 976.5625Hz) |
- | |
83 | cnt = 9; |
- | |
84 | cnt_1ms ^= 1; |
- | |
85 | if (!cnt_1ms) { |
- | |
86 | if (runFlightControl == 1) |
87 | if (!cnt--) { // every 10th run (9.765625kHz/10 = 976.5625Hz) |
87 | debugOut.digital[1] |= DEBUG_MAINLOOP_TIMER; |
88 | cnt = 9; |
88 | else |
89 | cnt_1ms ^= 1; |
89 | debugOut.digital[1] &= ~DEBUG_MAINLOOP_TIMER; |
90 | if (!cnt_1ms) { |
Line 132... | Line 133... | ||
132 | 133 | ||
133 | // ----------------------------------------------------------------------- |
134 | // ----------------------------------------------------------------------- |
134 | void delay_ms(uint16_t w) { |
135 | void delay_ms(uint16_t w) { |
135 | uint16_t t_stop = setDelay(w); |
136 | uint16_t t_stop = setDelay(w); |
136 | while (!checkDelay(t_stop)) |
137 | while (!checkDelay(t_stop)) |
137 | ; |
138 | wdt_reset(); |
Line 138... | Line 139... | ||
138 | } |
139 | } |
139 | 140 | ||
140 | // ----------------------------------------------------------------------- |
141 | // ----------------------------------------------------------------------- |
141 | void delay_ms_with_adc_measurement(uint16_t w, uint8_t stop) { |
142 | void delay_ms_with_adc_measurement(uint16_t w, uint8_t stop) { |
142 | uint16_t t_stop; |
143 | uint16_t t_stop; |
- | 144 | t_stop = setDelay(w); |
|
143 | t_stop = setDelay(w); |
145 | while (!checkDelay(t_stop)) { |
144 | while (!checkDelay(t_stop)) { |
146 | wdt_reset(); |
145 | debugOut.analog[30]++; |
147 | debugOut.analog[30]++; |
146 | if (sensorDataReady == ALL_DATA_READY) { |
148 | if (sensorDataReady == ALL_DATA_READY) { |
147 | analog_update(); |
149 | analog_update(); |
148 | startAnalogConversionCycle(); |
150 | startAnalogConversionCycle(); |
149 | } |
151 | } |
150 | } |
152 | } |
151 | if (stop) { |
153 | if (stop) { |
152 | // Wait for new samples to get prepared but do not restart AD conversion after that! |
154 | // Wait for new samples to get prepared but do not restart AD conversion after that! |
- | 155 | // Caller MUST to that. |
|
- | 156 | while (!sensorDataReady != ALL_DATA_READY) wdt_reset(); |
|
- | 157 | } |
|
- | 158 | } |
|
- | 159 | ||
- | 160 | #ifdef DO_PROFILE |
|
- | 161 | void startProfileTimer(uint8_t timer) { |
|
- | 162 | runningProfileTimers[timer] = global10kHzClock++; |
|
- | 163 | } |
|
- | 164 | ||
- | 165 | void stopProfileTimer(uint8_t timer) { |
|
- | 166 | int32_t t = global10kHzClock++ - runningProfileTimers[timer]; |
|
- | 167 | profileTimers[timer] += t; |
|
- | 168 | } |
|
- | 169 | ||
- | 170 | void debugProfileTimers(uint8_t index) { |
|
- | 171 | for (uint8_t i=0; i<NUM_PROFILE_TIMERS; i++) { |
|
153 | // Caller MUST to that. |
172 | uint16_t tenths = profileTimers[i] / 1000L; |
- | 173 | debugOut.analog[i+index] = tenths; |
|
- | 174 | } |
|
154 | // while (!sensorDataReady != ALL_DATA_READY); |
175 | uint16_t tenths = global10kHzClock / 1000L; |
- | 176 | debugOut.analog[index + NUM_PROFILE_TIMERS] = tenths; |