Rev 1227 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1227 | Rev 1342 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
2 | // + Copyright (c) 04.2007 Holger Buss |
3 | // + Nur für den privaten Gebrauch |
3 | // + Nur für den privaten Gebrauch |
4 | // + www.MikroKopter.com |
4 | // + www.MikroKopter.com |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist. |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist. |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
17 | // + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
17 | // + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
21 | // + Benutzung auf eigene Gefahr |
21 | // + Benutzung auf eigene Gefahr |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
25 | // + mit unserer Zustimmung zulässig |
25 | // + mit unserer Zustimmung zulässig |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
30 | // + this list of conditions and the following disclaimer. |
30 | // + this list of conditions and the following disclaimer. |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
32 | // + from this software without specific prior written permission. |
32 | // + from this software without specific prior written permission. |
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
34 | // + for non-commercial use (directly or indirectly) |
34 | // + for non-commercial use (directly or indirectly) |
35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
36 | // + with our written permission |
36 | // + with our written permission |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
38 | // + clearly linked as origin |
38 | // + clearly linked as origin |
39 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
39 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
48 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
48 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | #include <avr/boot.h> |
52 | #include <avr/boot.h> |
53 | 53 | ||
54 | #include <avr/io.h> |
54 | #include <avr/io.h> |
55 | #include <avr/interrupt.h> |
55 | #include <avr/interrupt.h> |
56 | #include <util/delay.h> |
56 | #include <util/delay.h> |
57 | 57 | ||
58 | #include "main.h" |
58 | #include "main.h" |
59 | #include "timer0.h" |
59 | #include "timer0.h" |
60 | #include "timer2.h" |
60 | #include "timer2.h" |
61 | #include "uart0.h" |
61 | #include "uart0.h" |
62 | #include "uart1.h" |
62 | #include "uart1.h" |
63 | #include "led.h" |
63 | #include "led.h" |
64 | #include "menu.h" |
64 | #include "menu.h" |
65 | #include "fc.h" |
65 | #include "fc.h" |
66 | #include "rc.h" |
66 | #include "rc.h" |
67 | #include "analog.h" |
67 | #include "analog.h" |
68 | #include "printf_P.h" |
68 | #include "printf_P.h" |
69 | #ifdef USE_KILLAGREG |
69 | #ifdef USE_KILLAGREG |
70 | #include "mm3.h" |
70 | #include "mm3.h" |
71 | #endif |
71 | #endif |
72 | #ifdef USE_NAVICTRL |
72 | #ifdef USE_NAVICTRL |
73 | #include "spi.h" |
73 | #include "spi.h" |
74 | #endif |
74 | #endif |
75 | #ifdef USE_MK3MAG |
75 | #ifdef USE_MK3MAG |
76 | #include "mk3mag.h" |
76 | #include "mk3mag.h" |
77 | #endif |
77 | #endif |
78 | #include "twimaster.h" |
78 | #include "twimaster.h" |
79 | #include "eeprom.h" |
79 | #include "eeprom.h" |
- | 80 | ||
- | 81 | #include "CapCalc.h" |
|
80 | 82 | ||
81 | 83 | ||
82 | uint8_t BoardRelease = 10; |
84 | uint8_t BoardRelease = 10; |
83 | uint8_t CPUType = ATMEGA644; |
85 | uint8_t CPUType = ATMEGA644; |
84 | 86 | ||
85 | 87 | ||
86 | uint8_t GetCPUType(void) |
88 | uint8_t GetCPUType(void) |
87 | { // works only after reset or power on when the registers have default values |
89 | { // works only after reset or power on when the registers have default values |
88 | uint8_t CPUType = ATMEGA644; |
90 | uint8_t CPUType = ATMEGA644; |
89 | if( (UCSR1A == 0x20) && (UCSR1C == 0x06) ) CPUType = ATMEGA644P; // initial Values for 644P after reset |
91 | if( (UCSR1A == 0x20) && (UCSR1C == 0x06) ) CPUType = ATMEGA644P; // initial Values for 644P after reset |
90 | return CPUType; |
92 | return CPUType; |
91 | } |
93 | } |
92 | 94 | ||
93 | 95 | ||
94 | uint8_t GetBoardRelease(void) |
96 | uint8_t GetBoardRelease(void) |
95 | { |
97 | { |
96 | uint8_t BoardRelease = 10; |
98 | uint8_t BoardRelease = 10; |
97 | // the board release is coded via the pull up or down the 2 status LED |
99 | // the board release is coded via the pull up or down the 2 status LED |
98 | 100 | ||
99 | PORTB &= ~((1 << PORTB1)|(1 << PORTB0)); // set tristate |
101 | PORTB &= ~((1 << PORTB1)|(1 << PORTB0)); // set tristate |
100 | DDRB &= ~((1 << DDB0)|(1 << DDB0)); // set port direction as input |
102 | DDRB &= ~((1 << DDB0)|(1 << DDB0)); // set port direction as input |
101 | 103 | ||
102 | _delay_loop_2(1000); // make some delay |
104 | _delay_loop_2(1000); // make some delay |
103 | 105 | ||
104 | switch( PINB & ((1<<PINB1)|(1<<PINB0)) ) |
106 | switch( PINB & ((1<<PINB1)|(1<<PINB0)) ) |
105 | { |
107 | { |
106 | case 0x00: |
108 | case 0x00: |
107 | BoardRelease = 10; // 1.0 |
109 | BoardRelease = 10; // 1.0 |
108 | break; |
110 | break; |
109 | case 0x01: |
111 | case 0x01: |
110 | BoardRelease = 11; // 1.1 or 1.2 |
112 | BoardRelease = 11; // 1.1 or 1.2 |
111 | break; |
113 | break; |
112 | case 0x02: |
114 | case 0x02: |
113 | BoardRelease = 20; // 2.0 |
115 | BoardRelease = 20; // 2.0 |
114 | break; |
116 | break; |
115 | case 0x03: |
117 | case 0x03: |
116 | BoardRelease = 13; // 1.3 |
118 | BoardRelease = 13; // 1.3 |
117 | break; |
119 | break; |
118 | default: |
120 | default: |
119 | break; |
121 | break; |
120 | } |
122 | } |
121 | // set LED ports as output |
123 | // set LED ports as output |
122 | DDRB |= (1<<DDB1)|(1<<DDB0); |
124 | DDRB |= (1<<DDB1)|(1<<DDB0); |
123 | RED_ON; |
125 | RED_ON; |
124 | GRN_OFF; |
126 | GRN_OFF; |
125 | return BoardRelease; |
127 | return BoardRelease; |
126 | } |
128 | } |
127 | 129 | ||
128 | 130 | ||
129 | int16_t main (void) |
131 | int16_t main (void) |
130 | { |
132 | { |
131 | uint16_t timer; |
133 | uint16_t timer; |
132 | uint8_t i; |
134 | uint8_t i; |
133 | 135 | ||
134 | // disable interrupts global |
136 | // disable interrupts global |
135 | cli(); |
137 | cli(); |
136 | 138 | ||
137 | // analyze hardware environment |
139 | // analyze hardware environment |
138 | CPUType = GetCPUType(); |
140 | CPUType = GetCPUType(); |
139 | BoardRelease = GetBoardRelease(); |
141 | BoardRelease = GetBoardRelease(); |
140 | 142 | ||
141 | // disable watchdog |
143 | // disable watchdog |
142 | MCUSR &=~(1<<WDRF); |
144 | MCUSR &=~(1<<WDRF); |
143 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
145 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
144 | WDTCSR = 0; |
146 | WDTCSR = 0; |
145 | 147 | ||
146 | BeepTime = 2000; |
148 | BeepTime = 2000; |
147 | 149 | ||
148 | PPM_in[CH_GAS] = 0; |
150 | PPM_in[CH_GAS] = 0; |
149 | StickYaw = 0; |
151 | StickYaw = 0; |
150 | StickRoll = 0; |
152 | StickRoll = 0; |
151 | StickNick = 0; |
153 | StickNick = 0; |
152 | 154 | ||
153 | RED_OFF; |
155 | RED_OFF; |
154 | 156 | ||
155 | // initalize modules |
157 | // initalize modules |
156 | LED_Init(); |
158 | LED_Init(); |
157 | TIMER0_Init(); |
159 | TIMER0_Init(); |
158 | TIMER2_Init(); |
160 | TIMER2_Init(); |
159 | USART0_Init(); |
161 | USART0_Init(); |
160 | if(CPUType == ATMEGA644P) USART1_Init(); |
162 | if(CPUType == ATMEGA644P) USART1_Init(); |
161 | RC_Init(); |
163 | RC_Init(); |
162 | ADC_Init(); |
164 | ADC_Init(); |
163 | I2C_Init(); |
165 | I2C_Init(); |
164 | #ifdef USE_NAVICTRL |
166 | #ifdef USE_NAVICTRL |
165 | SPI_MasterInit(); |
167 | SPI_MasterInit(); |
166 | #endif |
168 | #endif |
167 | #ifdef USE_KILLAGREG |
169 | #ifdef USE_KILLAGREG |
168 | MM3_Init(); |
170 | MM3_Init(); |
169 | #endif |
171 | #endif |
170 | #ifdef USE_MK3MAG |
172 | #ifdef USE_MK3MAG |
171 | MK3MAG_Init(); |
173 | MK3MAG_Init(); |
172 | #endif |
174 | #endif |
- | 175 | ||
- | 176 | CapCalc_Init(); |
|
173 | 177 | ||
174 | // enable interrupts global |
178 | // enable interrupts global |
175 | sei(); |
179 | sei(); |
176 | 180 | ||
177 | printf("\n\r==================================="); |
181 | printf("\n\r==================================="); |
178 | printf("\n\rFlightControl"); |
182 | printf("\n\rFlightControl"); |
179 | printf("\n\rHardware: %d.%d", BoardRelease/10, BoardRelease%10); |
183 | printf("\n\rHardware: %d.%d", BoardRelease/10, BoardRelease%10); |
180 | if(CPUType == ATMEGA644P) |
184 | if(CPUType == ATMEGA644P) |
181 | printf("\r\n CPU: Atmega644p"); |
185 | printf("\r\n CPU: Atmega644p"); |
182 | else |
186 | else |
183 | printf("\r\n CPU: Atmega644"); |
187 | printf("\r\n CPU: Atmega644"); |
184 | printf("\n\rSoftware: V%d.%d%c",VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a'); |
188 | printf("\n\rSoftware: V%d.%d%c",VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a'); |
185 | printf("\n\r==================================="); |
189 | printf("\n\r==================================="); |
186 | GRN_ON; |
190 | GRN_ON; |
187 | 191 | ||
188 | // Parameter Set handling |
192 | // Parameter Set handling |
189 | ParamSet_Init(); |
193 | ParamSet_Init(); |
190 | 194 | ||
191 | // Check connected BL-Ctrls |
195 | // Check connected BL-Ctrls |
192 | printf("\n\rFound BL-Ctrl: "); |
196 | printf("\n\rFound BL-Ctrl: "); |
193 | motor_read = 0; |
197 | motor_read = 0; |
194 | UpdateMotor = 0; |
198 | UpdateMotor = 0; |
195 | SendMotorData(); |
199 | SendMotorData(); |
196 | while(!UpdateMotor); |
200 | while(!UpdateMotor); |
197 | motor_read = 0; // read the first I2C-Data |
201 | motor_read = 0; // read the first I2C-Data |
198 | for(i = 0; i < MAX_MOTORS; i++) |
202 | for(i = 0; i < MAX_MOTORS; i++) |
199 | { |
203 | { |
200 | UpdateMotor = 0; |
204 | UpdateMotor = 0; |
201 | SendMotorData(); |
205 | SendMotorData(); |
202 | while(!UpdateMotor); |
206 | while(!UpdateMotor); |
203 | if(Motor[i].Present) printf("%d ",i+1); |
207 | if(Motor[i].Present) printf("%d ",i+1); |
204 | } |
208 | } |
205 | for(i = 0; i < MAX_MOTORS; i++) |
209 | for(i = 0; i < MAX_MOTORS; i++) |
206 | { |
210 | { |
207 | if(!Motor[i].Present && Mixer.Motor[i][MIX_GAS] > 0) printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
211 | if(!Motor[i].Present && Mixer.Motor[i][MIX_GAS] > 0) printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1); |
208 | Motor[i].Error = 0; |
212 | Motor[i].Error = 0; |
209 | } |
213 | } |
210 | printf("\n\r==================================="); |
214 | printf("\n\r==================================="); |
211 | 215 | ||
212 | 216 | ||
213 | if(GetParamWord(PID_ACC_NICK) > 2048) |
217 | if(GetParamWord(PID_ACC_NICK) > 2048) |
214 | { |
218 | { |
215 | printf("\n\rACC not calibrated!"); |
219 | printf("\n\rACC not calibrated!"); |
216 | } |
220 | } |
217 | 221 | ||
218 | //wait for a short time (otherwise the RC channel check won't work below) |
222 | //wait for a short time (otherwise the RC channel check won't work below) |
219 | timer = SetDelay(500); |
223 | timer = SetDelay(500); |
220 | while(!CheckDelay(timer)); |
224 | while(!CheckDelay(timer)); |
221 | 225 | ||
222 | if(ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) |
226 | if(ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) |
223 | { |
227 | { |
224 | printf("\n\rCalibrating air pressure sensor.."); |
228 | printf("\n\rCalibrating air pressure sensor.."); |
225 | timer = SetDelay(1000); |
229 | timer = SetDelay(1000); |
226 | SearchAirPressureOffset(); |
230 | SearchAirPressureOffset(); |
227 | while (!CheckDelay(timer)); |
231 | while (!CheckDelay(timer)); |
228 | printf("OK\n\r"); |
232 | printf("OK\n\r"); |
229 | } |
233 | } |
230 | 234 | ||
231 | #ifdef USE_NAVICTRL |
235 | #ifdef USE_NAVICTRL |
232 | printf("\n\rSupport for NaviCtrl"); |
236 | printf("\n\rSupport for NaviCtrl"); |
233 | #ifdef USE_RC_DSL |
237 | #ifdef USE_RC_DSL |
234 | printf("\r\nSupport for DSL RC at 2nd UART"); |
238 | printf("\r\nSupport for DSL RC at 2nd UART"); |
235 | #endif |
239 | #endif |
236 | #ifdef USE_RC_SPECTRUM |
240 | #ifdef USE_RC_SPECTRUM |
237 | printf("\r\nSupport for SPECTRUM RC at 2nd UART"); |
241 | printf("\r\nSupport for SPECTRUM RC at 2nd UART"); |
238 | #endif |
242 | #endif |
239 | #endif |
243 | #endif |
240 | 244 | ||
241 | #ifdef USE_KILLAGREG |
245 | #ifdef USE_KILLAGREG |
242 | printf("\n\rSupport for MicroMag3 Compass"); |
246 | printf("\n\rSupport for MicroMag3 Compass"); |
243 | #endif |
247 | #endif |
244 | 248 | ||
245 | #ifdef USE_MK3MAG |
249 | #ifdef USE_MK3MAG |
246 | printf("\n\rSupport for MK3MAG Compass"); |
250 | printf("\n\rSupport for MK3MAG Compass"); |
247 | #endif |
251 | #endif |
248 | 252 | ||
249 | #if (defined (USE_KILLAGREG) || defined (USE_MK3MAG)) |
253 | #if (defined (USE_KILLAGREG) || defined (USE_MK3MAG)) |
250 | if(CPUType == ATMEGA644P) printf("\n\rSupport for GPS at 2nd UART"); |
254 | if(CPUType == ATMEGA644P) printf("\n\rSupport for GPS at 2nd UART"); |
251 | else printf("\n\rSupport for GPS at 1st UART"); |
255 | else printf("\n\rSupport for GPS at 1st UART"); |
252 | #endif |
256 | #endif |
253 | 257 | ||
254 | 258 | ||
255 | SetNeutral(NO_ACC_CALIB); |
259 | SetNeutral(NO_ACC_CALIB); |
256 | 260 | ||
257 | RED_OFF; |
261 | RED_OFF; |
258 | 262 | ||
259 | BeepTime = 2000; |
263 | BeepTime = 2000; |
260 | ExternControl.Digital[0] = 0x55; |
264 | ExternControl.Digital[0] = 0x55; |
261 | 265 | ||
262 | 266 | ||
263 | printf("\n\rControl: "); |
267 | printf("\n\rControl: "); |
264 | if (ParamSet.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
268 | if (ParamSet.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
265 | else printf("Neutral (ACC-Mode)"); |
269 | else printf("Neutral (ACC-Mode)"); |
266 | 270 | ||
267 | printf("\n\n\r"); |
271 | printf("\n\n\r"); |
268 | 272 | ||
269 | LCD_Clear(); |
273 | LCD_Clear(); |
270 | 274 | ||
271 | I2CTimeout = 5000; |
275 | I2CTimeout = 5000; |
272 | while (1) |
276 | while (1) |
273 | { |
277 | { |
274 | if(UpdateMotor && ADReady) // control interval |
278 | if(UpdateMotor && ADReady) // control interval |
275 | { |
279 | { |
276 | UpdateMotor = 0; // reset Flag, is enabled every 2 ms by ISR of timer0 |
280 | UpdateMotor = 0; // reset Flag, is enabled every 2 ms by ISR of timer0 |
277 | 281 | ||
278 | //J4HIGH; |
282 | //J4HIGH; |
279 | MotorControl(); |
283 | MotorControl(); |
280 | //J4LOW; |
284 | //J4LOW; |
281 | 285 | ||
282 | SendMotorData(); // the flight control code |
286 | SendMotorData(); // the flight control code |
283 | RED_OFF; |
287 | RED_OFF; |
284 | 288 | ||
285 | 289 | ||
286 | 290 | ||
287 | if(PcAccess) PcAccess--; |
291 | if(PcAccess) PcAccess--; |
288 | else |
292 | else |
289 | { |
293 | { |
290 | ExternControl.Config = 0; |
294 | ExternControl.Config = 0; |
291 | ExternStickNick= 0; |
295 | ExternStickNick= 0; |
292 | ExternStickRoll = 0; |
296 | ExternStickRoll = 0; |
293 | ExternStickYaw = 0; |
297 | ExternStickYaw = 0; |
294 | } |
298 | } |
295 | if(RC_Quality) RC_Quality--; |
299 | if(RC_Quality) RC_Quality--; |
296 | 300 | ||
297 | #ifdef USE_NAVICTRL |
301 | #ifdef USE_NAVICTRL |
298 | if(NCDataOkay) |
302 | if(NCDataOkay) |
299 | { |
303 | { |
300 | if(--NCDataOkay == 0) // no data from NC |
304 | if(--NCDataOkay == 0) // no data from NC |
301 | { // set gps control sticks neutral |
305 | { // set gps control sticks neutral |
302 | GPSStickNick = 0; |
306 | GPSStickNick = 0; |
303 | GPSStickRoll = 0; |
307 | GPSStickRoll = 0; |
304 | NCSerialDataOkay = 0; |
308 | NCSerialDataOkay = 0; |
305 | } |
309 | } |
306 | } |
310 | } |
307 | #endif |
311 | #endif |
308 | 312 | ||
309 | if(!--I2CTimeout || MissingMotor) // try to reset the i2c if motor is missing ot timeout |
313 | if(!--I2CTimeout || MissingMotor) // try to reset the i2c if motor is missing ot timeout |
310 | { |
314 | { |
311 | RED_ON; |
315 | RED_ON; |
312 | if(!I2CTimeout) |
316 | if(!I2CTimeout) |
313 | { |
317 | { |
314 | I2C_Reset(); |
318 | I2C_Reset(); |
315 | I2CTimeout = 5; |
319 | I2CTimeout = 5; |
316 | } |
320 | } |
317 | if((BeepModulation == 0xFFFF) && (MKFlags & MKFLAG_MOTOR_RUN) ) |
321 | if((BeepModulation == 0xFFFF) && (MKFlags & MKFLAG_MOTOR_RUN) ) |
318 | { |
322 | { |
319 | BeepTime = 10000; // 1 second |
323 | BeepTime = 10000; // 1 second |
320 | BeepModulation = 0x0080; |
324 | BeepModulation = 0x0080; |
321 | } |
325 | } |
322 | } |
326 | } |
323 | else |
327 | else |
324 | { |
328 | { |
325 | RED_OFF; |
329 | RED_OFF; |
326 | } |
330 | } |
327 | 331 | ||
328 | // allow Serial Data Transmit if motors must not updated or motors are not running |
332 | // allow Serial Data Transmit if motors must not updated or motors are not running |
329 | if( !UpdateMotor || !(MKFlags & MKFLAG_MOTOR_RUN) ) |
333 | if( !UpdateMotor || !(MKFlags & MKFLAG_MOTOR_RUN) ) |
330 | { |
334 | { |
331 | USART0_TransmitTxData(); |
335 | USART0_TransmitTxData(); |
332 | } |
336 | } |
333 | USART0_ProcessRxData(); |
337 | USART0_ProcessRxData(); |
334 | 338 | ||
335 | if(CheckDelay(timer)) |
339 | if(CheckDelay(timer)) |
336 | { |
340 | { |
337 | if(UBat < ParamSet.LowVoltageWarning) |
341 | if(UBat < ParamSet.LowVoltageWarning) |
338 | { |
342 | { |
339 | BeepModulation = 0x0300; |
343 | BeepModulation = 0x0300; |
340 | if(!BeepTime ) |
344 | if(!BeepTime ) |
341 | { |
345 | { |
342 | BeepTime = 6000; // 0.6 seconds |
346 | BeepTime = 6000; // 0.6 seconds |
343 | } |
347 | } |
344 | } |
348 | } |
345 | #ifdef USE_NAVICTRL |
349 | #ifdef USE_NAVICTRL |
346 | SPI_StartTransmitPacket(); |
350 | SPI_StartTransmitPacket(); |
347 | SendSPI = 4; |
351 | SendSPI = 4; |
348 | #endif |
352 | #endif |
349 | timer = SetDelay(20); // every 20 ms |
353 | timer = SetDelay(20); // every 20 ms |
350 | } |
354 | } |
351 | - | ||
- | 355 | CapCalc_Update(); |
|
352 | LED_Update(); |
356 | LED_Update(); |
353 | } |
357 | } |
354 | 358 | ||
355 | #ifdef USE_NAVICTRL |
359 | #ifdef USE_NAVICTRL |
356 | if(!SendSPI) |
360 | if(!SendSPI) |
357 | { // SendSPI is decremented in timer0.c with a rate of 9.765 kHz. |
361 | { // SendSPI is decremented in timer0.c with a rate of 9.765 kHz. |
358 | // within the SPI_TransmitByte() routine the value is set to 4. |
362 | // within the SPI_TransmitByte() routine the value is set to 4. |
359 | // I.e. the SPI_TransmitByte() is called at a rate of 9.765 kHz/4= 2441.25 Hz, |
363 | // I.e. the SPI_TransmitByte() is called at a rate of 9.765 kHz/4= 2441.25 Hz, |
360 | // and therefore the time of transmission of a complete spi-packet (32 bytes) is 32*4/9.765 kHz = 13.1 ms. |
364 | // and therefore the time of transmission of a complete spi-packet (32 bytes) is 32*4/9.765 kHz = 13.1 ms. |
361 | SPI_TransmitByte(); |
365 | SPI_TransmitByte(); |
362 | } |
366 | } |
363 | #endif |
367 | #endif |
364 | } |
368 | } |
365 | return (1); |
369 | return (1); |
366 | } |
370 | } |
367 | 371 | ||
368 | 372 |