Rev 916 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 916 | Rev 925 | ||
---|---|---|---|
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 | 56 | ||
57 | #include "main.h" |
57 | #include "main.h" |
58 | #include "timer0.h" |
58 | #include "timer0.h" |
59 | #include "timer2.h" |
59 | #include "timer2.h" |
60 | #include "uart.h" |
60 | #include "uart.h" |
61 | #if defined (__AVR_ATmega644P__) |
61 | #if defined (__AVR_ATmega644P__) |
62 | #include "uart1.h" |
62 | #include "uart1.h" |
63 | #endif |
63 | #endif |
64 | #include "led.h" |
64 | #include "led.h" |
65 | #include "menu.h" |
65 | #include "menu.h" |
66 | #include "fc.h" |
66 | #include "fc.h" |
67 | #include "rc.h" |
67 | #include "rc.h" |
68 | #include "analog.h" |
68 | #include "analog.h" |
69 | #include "printf_P.h" |
69 | #include "printf_P.h" |
70 | #ifdef USE_KILLAGREG |
70 | #ifdef USE_KILLAGREG |
71 | #include "mm3.h" |
71 | #include "mm3.h" |
72 | #endif |
72 | #endif |
73 | #ifdef USE_NAVICTRL |
73 | #ifdef USE_NAVICTRL |
74 | #include "spi.h" |
74 | #include "spi.h" |
75 | #endif |
75 | #endif |
76 | #ifdef USE_MK3MAG |
76 | #ifdef USE_MK3MAG |
77 | #include "mk3mag.h" |
77 | #include "mk3mag.h" |
78 | #endif |
78 | #endif |
79 | #include "twimaster.h" |
79 | #include "twimaster.h" |
80 | #include "eeprom.h" |
80 | #include "eeprom.h" |
81 | #include "_Settings.h" |
81 | #include "_Settings.h" |
82 | 82 | ||
83 | 83 | ||
84 | uint8_t BoardRelease = 10; |
84 | uint8_t BoardRelease = 10; |
85 | 85 | ||
86 | 86 | ||
87 | //############################################################################ |
87 | //############################################################################ |
88 | //Hauptprogramm |
88 | //Hauptprogramm |
89 | int main (void) |
89 | int main (void) |
90 | //############################################################################ |
90 | //############################################################################ |
91 | { |
91 | { |
92 | unsigned int timer; |
92 | unsigned int timer; |
93 | 93 | ||
94 | // disable interrupts global |
94 | // disable interrupts global |
95 | cli(); |
95 | cli(); |
96 | 96 | ||
97 | // get board release |
97 | // get board release |
98 | DDRB = 0x00; |
98 | DDRB = 0x00; |
99 | PORTB = 0x00; |
99 | PORTB = 0x00; |
100 | for(timer = 0; timer < 1000; timer++); // make some delay |
100 | for(timer = 0; timer < 1000; timer++); // make some delay |
101 | if(PINB & (1<<PINB0)) BoardRelease = 11; |
101 | if(PINB & (1<<PINB0)) BoardRelease = 11; |
102 | else BoardRelease = 10; |
102 | else BoardRelease = 10; |
103 | 103 | ||
104 | // set LED ports as output |
104 | // set LED ports as output |
105 | DDRB |= (1<<DDB1)|(1<<DDB0); |
105 | DDRB |= (1<<DDB1)|(1<<DDB0); |
106 | ROT_ON; |
106 | ROT_ON; |
107 | GRN_OFF; |
107 | GRN_OFF; |
108 | 108 | ||
109 | // disable watchdog |
109 | // disable watchdog |
110 | MCUSR &=~(1<<WDRF); |
110 | MCUSR &=~(1<<WDRF); |
111 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
111 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
112 | WDTCSR = 0; |
112 | WDTCSR = 0; |
113 | 113 | ||
114 | BeepTime = 2000; |
114 | BeepTime = 2000; |
115 | 115 | ||
116 | PPM_in[CH_GAS] = 0; |
116 | PPM_in[CH_GAS] = 0; |
117 | StickYaw = 0; |
117 | StickYaw = 0; |
118 | StickRoll = 0; |
118 | StickRoll = 0; |
119 | StickNick = 0; |
119 | StickNick = 0; |
120 | 120 | ||
121 | ROT_OFF; |
121 | ROT_OFF; |
122 | 122 | ||
123 | // initalize modules |
123 | // initalize modules |
124 | LED_Init(); |
124 | LED_Init(); |
125 | TIMER0_Init(); |
125 | TIMER0_Init(); |
126 | TIMER2_Init(); |
126 | TIMER2_Init(); |
127 | USART0_Init(); |
127 | USART0_Init(); |
128 | 128 | ||
129 | #if defined (__AVR_ATmega644P__) |
129 | #if defined (__AVR_ATmega644P__) |
130 | if (BoardRelease == 11) USART1_Init(); |
130 | if (BoardRelease == 11) USART1_Init(); |
131 | #endif |
131 | #endif |
132 | 132 | ||
133 | RC_Init(); |
133 | RC_Init(); |
134 | ADC_Init(); |
134 | ADC_Init(); |
135 | I2C_Init(); |
135 | I2C_Init(); |
136 | 136 | ||
137 | 137 | ||
138 | #ifdef USE_NAVICTRL |
138 | #ifdef USE_NAVICTRL |
139 | SPI_MasterInit(); |
139 | SPI_MasterInit(); |
140 | #endif |
140 | #endif |
141 | #ifdef USE_KILLAGREG |
141 | #ifdef USE_KILLAGREG |
142 | MM3_Init(); |
142 | MM3_Init(); |
143 | #endif |
143 | #endif |
144 | #ifdef USE_MK3MAG |
144 | #ifdef USE_MK3MAG |
145 | MK3MAG_Init(); |
145 | MK3MAG_Init(); |
146 | #endif |
146 | #endif |
147 | 147 | ||
148 | 148 | ||
149 | // enable interrupts global |
149 | // enable interrupts global |
150 | sei(); |
150 | sei(); |
151 | 151 | ||
152 | VersionInfo.Major = VERSION_MAJOR; |
152 | VersionInfo.Major = VERSION_MAJOR; |
153 | VersionInfo.Minor = VERSION_MINOR; |
153 | VersionInfo.Minor = VERSION_MINOR; |
154 | VersionInfo.PCCompatible = VERSION_COMPATIBLE; |
154 | VersionInfo.PCCompatible = VERSION_COMPATIBLE; |
155 | 155 | ||
156 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",BoardRelease/10,BoardRelease%10, VERSION_MAJOR, VERSION_MINOR,VERSION_INDEX + 'a'); |
156 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",BoardRelease/10,BoardRelease%10, VERSION_MAJOR, VERSION_MINOR,VERSION_INDEX + 'a'); |
157 | printf("\n\r=============================="); |
157 | printf("\n\r=============================="); |
158 | GRN_ON; |
158 | GRN_ON; |
159 | 159 | ||
160 | // Parameter set handling |
160 | // Parameter set handling |
161 | ParamSet_Init(); |
161 | ParamSet_Init(); |
162 | 162 | ||
163 | if(GetParamWord(PID_ACC_NICK) > 1023) |
163 | if(GetParamWord(PID_ACC_NICK) > 1023) |
164 | { |
164 | { |
165 | printf("\n\rACC not calibrated!"); |
165 | printf("\n\rACC not calibrated!"); |
166 | } |
166 | } |
167 | 167 | ||
168 | //wait for a short time (otherwise the RC channel check won't work below) |
168 | //wait for a short time (otherwise the RC channel check won't work below) |
169 | timer = SetDelay(500); |
169 | timer = SetDelay(500); |
170 | while(!CheckDelay(timer)); |
170 | while(!CheckDelay(timer)); |
171 | 171 | ||
172 | 172 | ||
173 | if(ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) |
173 | if(ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) |
174 | { |
174 | { |
175 | printf("\n\rCalibrating air pressure sensor.."); |
175 | printf("\n\rCalibrating air pressure sensor.."); |
176 | timer = SetDelay(1000); |
176 | timer = SetDelay(1000); |
177 | SearchAirPressureOffset(); |
177 | SearchAirPressureOffset(); |
178 | while (!CheckDelay(timer)); |
178 | while (!CheckDelay(timer)); |
179 | printf("OK\n\r"); |
179 | printf("OK\n\r"); |
180 | } |
180 | } |
181 | 181 | ||
182 | #ifdef USE_NAVICTRL |
182 | #ifdef USE_NAVICTRL |
183 | printf("\n\rSupport for NaviCtrl"); |
183 | printf("\n\rSupport for NaviCtrl"); |
184 | #endif |
184 | #endif |
185 | 185 | ||
186 | #ifdef USE_KILLAGREG |
186 | #ifdef USE_KILLAGREG |
187 | printf("\n\rSupport for MicroMag3 Compass"); |
187 | printf("\n\rSupport for MicroMag3 Compass"); |
188 | #endif |
188 | #endif |
189 | #ifdef USE_MK3MAG |
189 | #ifdef USE_MK3MAG |
190 | printf("\n\rSupport for MK3MAG Compass"); |
190 | printf("\n\rSupport for MK3MAG Compass"); |
191 | #endif |
191 | #endif |
192 | 192 | ||
193 | 193 | ||
194 | 194 | ||
195 | #if defined (USE_KILLAGREG) || defined (USE_MK3MAG) |
195 | #if defined (USE_KILLAGREG) || defined (USE_MK3MAG) |
196 | #if defined (__AVR_ATmega644P__) |
196 | #if defined (__AVR_ATmega644P__) |
197 | if(BoardRelease == 10) |
197 | if(BoardRelease == 10) |
198 | { |
198 | { |
199 | printf("\n\rSupport for GPS at 1st UART"); |
199 | printf("\n\rSupport for GPS at 1st UART"); |
200 | } |
200 | } |
201 | else |
201 | else |
202 | { |
202 | { |
203 | printf("\n\rSupport for GPS at 2nd UART"); |
203 | printf("\n\rSupport for GPS at 2nd UART"); |
204 | } |
204 | } |
205 | #else // (__AVR_ATmega644__) |
205 | #else // (__AVR_ATmega644__) |
206 | printf("\n\rSupport for GPS at 1st UART"); |
206 | printf("\n\rSupport for GPS at 1st UART"); |
207 | #endif |
207 | #endif |
208 | #endif |
208 | #endif |
209 | 209 | ||
210 | 210 | ||
211 | 211 | ||
212 | SetNeutral(); |
212 | SetNeutral(); |
213 | 213 | ||
214 | ROT_OFF; |
214 | ROT_OFF; |
215 | 215 | ||
216 | BeepTime = 2000; |
216 | BeepTime = 2000; |
217 | ExternControl.Digital[0] = 0x55; |
217 | ExternControl.Digital[0] = 0x55; |
218 | 218 | ||
219 | 219 | ||
220 | printf("\n\rControl: "); |
220 | printf("\n\rControl: "); |
221 | if (ParamSet.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
221 | if (ParamSet.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
222 | else printf("Neutral"); |
222 | else printf("Neutral"); |
223 | 223 | ||
224 | printf("\n\n\r"); |
224 | printf("\n\n\r"); |
225 | 225 | ||
226 | LCD_Clear(); |
226 | LCD_Clear(); |
227 | 227 | ||
228 | I2CTimeout = 5000; |
228 | I2CTimeout = 2000; |
229 | 229 | ||
230 | while (1) |
230 | while (1) |
231 | { |
231 | { |
232 | if(UpdateMotor) // control interval |
232 | if(UpdateMotor) // control interval |
233 | { |
233 | { |
234 | UpdateMotor=0; // reset Flag, is enabled every 2 ms by isr of timer0 |
234 | UpdateMotor=0; // reset Flag, is enabled every 2 ms by isr of timer0 |
235 | //PORTD |= (1<<PORTD4); |
235 | //PORTD |= (1<<PORTD4); |
236 | MotorControl(); |
236 | MotorControl(); |
237 | //PORTD &= ~(1<<PORTD4); |
237 | //PORTD &= ~(1<<PORTD4); |
238 | 238 | ||
239 | SendMotorData(); |
239 | SendMotorData(); |
240 | 240 | ||
241 | ROT_OFF; |
241 | ROT_OFF; |
242 | 242 | ||
243 | if(PcAccess) PcAccess--; |
243 | if(PcAccess) PcAccess--; |
244 | else |
244 | else |
245 | { |
245 | { |
246 | DubWiseKeys[0] = 0; |
246 | DubWiseKeys[0] = 0; |
247 | DubWiseKeys[1] = 0; |
247 | DubWiseKeys[1] = 0; |
248 | ExternControl.Config = 0; |
248 | ExternControl.Config = 0; |
249 | ExternStickNick= 0; |
249 | ExternStickNick= 0; |
250 | ExternStickRoll = 0; |
250 | ExternStickRoll = 0; |
251 | ExternStickYaw = 0; |
251 | ExternStickYaw = 0; |
252 | } |
252 | } |
253 | 253 | ||
254 | if(!I2CTimeout) |
254 | if(!I2CTimeout) |
255 | { |
255 | { |
256 | I2CTimeout = 5; |
256 | I2CTimeout = 5; |
257 | I2C_Reset(); |
257 | I2C_Reset(); |
258 | if((BeepModulation == 0xFFFF) && MotorsOn) |
258 | if((BeepModulation == 0xFFFF) && MotorsOn) |
259 | { |
259 | { |
260 | BeepTime = 10000; // 1 second |
260 | BeepTime = 10000; // 1 second |
261 | BeepModulation = 0x0080; |
261 | BeepModulation = 0x0080; |
262 | } |
262 | } |
263 | } |
263 | } |
264 | else |
264 | else |
265 | { |
265 | { |
266 | I2CTimeout--; |
266 | I2CTimeout--; |
267 | ROT_OFF; |
267 | ROT_OFF; |
268 | } |
268 | } |
269 | 269 | ||
270 | if(SIO_DEBUG && (!UpdateMotor || !MotorsOn)) |
270 | if(SIO_DEBUG && (!UpdateMotor || !MotorsOn)) |
271 | { |
271 | { |
272 | USART0_TransmitTxData(); |
272 | USART0_TransmitTxData(); |
273 | USART0_ProcessRxData(); |
273 | USART0_ProcessRxData(); |
274 | } |
274 | } |
275 | else USART0_ProcessRxData(); |
275 | else USART0_ProcessRxData(); |
276 | 276 | ||
277 | if(CheckDelay(timer)) |
277 | if(CheckDelay(timer)) |
278 | { |
278 | { |
279 | if(UBat < ParamSet.LowVoltageWarning) |
279 | if(UBat < ParamSet.LowVoltageWarning) |
280 | { |
280 | { |
281 | if(BeepModulation == 0xFFFF) |
281 | if(BeepModulation == 0xFFFF) |
282 | { |
282 | { |
283 | BeepTime = 6000; // 0.6 seconds |
283 | BeepTime = 6000; // 0.6 seconds |
284 | BeepModulation = 0x0300; |
284 | BeepModulation = 0x0300; |
285 | } |
285 | } |
286 | } |
286 | } |
287 | #ifdef USE_NAVICTRL |
287 | #ifdef USE_NAVICTRL |
288 | SPI_StartTransmitPacket(); |
288 | SPI_StartTransmitPacket(); |
289 | SendSPI = 4; |
289 | SendSPI = 4; |
290 | #endif |
290 | #endif |
291 | timer = SetDelay(20); // every 20 ms |
291 | timer = SetDelay(20); // every 20 ms |
292 | } |
292 | } |
293 | } |
293 | } |
294 | 294 | ||
295 | #ifdef USE_NAVICTRL |
295 | #ifdef USE_NAVICTRL |
296 | if(!SendSPI) |
296 | if(!SendSPI) |
297 | { // SendSPI is decremented in timer0.c with a rate of 9.765 kHz. |
297 | { // SendSPI is decremented in timer0.c with a rate of 9.765 kHz. |
298 | // within the SPI_TransmitByte() routine the value is set to 4. |
298 | // within the SPI_TransmitByte() routine the value is set to 4. |
299 | // I.e. the SPI_TransmitByte() is called at a rate of 9.765 kHz/4= 2441.25 Hz, |
299 | // I.e. the SPI_TransmitByte() is called at a rate of 9.765 kHz/4= 2441.25 Hz, |
300 | // and therefore the time of transmission of a complete spi-packet (32 bytes) is 32*4/9.765 kHz = 13.1 ms. |
300 | // and therefore the time of transmission of a complete spi-packet (32 bytes) is 32*4/9.765 kHz = 13.1 ms. |
301 | SPI_TransmitByte(); |
301 | SPI_TransmitByte(); |
302 | } |
302 | } |
303 | #endif |
303 | #endif |
304 | } |
304 | } |
305 | return (1); |
305 | return (1); |
306 | } |
306 | } |
307 | 307 | ||
308 | 308 |