Rev 355 | Rev 362 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
||
3 | /*#######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + www.MikroKopter.com |
||
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
360 | holgerb | 7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
||
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
||
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
||
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
||
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
||
1 | ingob | 13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
360 | holgerb | 14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
||
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
||
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
||
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
||
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
||
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
||
22 | // + des Mitverschuldens offen. |
||
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
||
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
||
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
||
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
||
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
||
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
||
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
||
1 | ingob | 31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
360 | holgerb | 32 | // + Software LICENSING TERMS |
1 | ingob | 33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
360 | holgerb | 34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
||
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
||
37 | // + The Software may only be used with the Licensor's products. |
||
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
||
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
||
40 | // + agreement shall be the property of the Licensor. |
||
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
||
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
||
43 | // + The customer shall be responsible for taking reasonable precautions |
||
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
||
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
||
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
||
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
||
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
||
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
||
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
||
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
||
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
||
53 | // + #### END OF LICENSING TERMS #### |
||
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
||
1 | ingob | 55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
41 | ingob | 56 | //#define MCLK96MHZ |
1 | ingob | 57 | const unsigned long _Main_Crystal = 25000; |
41 | ingob | 58 | #include <stdio.h> |
59 | #include "91x_lib.h" |
||
60 | #include "led.h" |
||
61 | #include "uart0.h" |
||
62 | #include "uart1.h" |
||
63 | #include "uart2.h" |
||
215 | killagreg | 64 | #include "gps.h" |
41 | ingob | 65 | #include "i2c.h" |
242 | killagreg | 66 | #include "compass.h" |
119 | killagreg | 67 | #include "timer1.h" |
68 | #include "timer2.h" |
||
134 | killagreg | 69 | #include "analog.h" |
41 | ingob | 70 | #include "spi_slave.h" |
71 | #include "fat16.h" |
||
72 | #include "usb.h" |
||
73 | #include "sdc.h" |
||
82 | killagreg | 74 | #include "logging.h" |
156 | killagreg | 75 | #include "params.h" |
88 | killagreg | 76 | #include "settings.h" |
154 | killagreg | 77 | #include "config.h" |
1 | ingob | 78 | #include "main.h" |
250 | ingob | 79 | #include "debug.h" |
254 | killagreg | 80 | #include "eeprom.h" |
350 | holgerb | 81 | #include "ssc.h" |
254 | killagreg | 82 | |
314 | killagreg | 83 | #ifdef FOLLOW_ME |
84 | u8 TransmitAlsoToFC = 0; |
||
85 | #endif |
||
41 | ingob | 86 | u32 TimerCheckError; |
234 | killagreg | 87 | u8 ErrorCode = 0; |
41 | ingob | 88 | u16 BeepTime; |
92 | killagreg | 89 | u8 NCFlags = 0; |
153 | killagreg | 90 | s16 GeoMagDec = 0; // local magnetic declination in 0.1 deg |
328 | holgerb | 91 | u8 ErrorGpsFixLost = 0; |
1 | ingob | 92 | |
255 | killagreg | 93 | u8 ClearFCStatusFlags = 0; |
41 | ingob | 94 | u8 StopNavigation = 0; |
95 | Param_t Parameter; |
||
78 | holgerb | 96 | volatile FC_t FC; |
1 | ingob | 97 | |
41 | ingob | 98 | s8 ErrorMSG[25]; |
99 | |||
1 | ingob | 100 | //---------------------------------------------------------------------------------------------------- |
41 | ingob | 101 | void SCU_Config(void) |
1 | ingob | 102 | { |
41 | ingob | 103 | /* configure PLL and set it as master clock source */ |
104 | SCU_MCLKSourceConfig(SCU_MCLK_OSC); // set master clock source to external oscillator clock (25MHz) before diabling the PLL |
||
105 | SCU_PLLCmd(DISABLE); // now disable the PLL |
||
106 | #ifdef MCLK96MHZ |
||
107 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div2); // set BRCLK to MCLK/2 = 48MHz |
||
108 | SCU_PCLKDivisorConfig(SCU_PCLK_Div4); // set PCLK (APB bus clock) divisor to 4 (half Reference Clock) |
||
109 | SCU_RCLKDivisorConfig(SCU_RCLK_Div2); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
||
110 | SCU_HCLKDivisorConfig(SCU_HCLK_Div2); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
||
111 | SCU_PLLFactorsConfig(192,25,2); // PLL = 96 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=2 |
||
112 | #else |
||
113 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div1); // set BRCLK to MCLK = 48MHz |
||
114 | SCU_PCLKDivisorConfig(SCU_PCLK_Div2); // set PCLK (APB bus clock) divisor to 2 (half Reference Clock) |
||
115 | SCU_RCLKDivisorConfig(SCU_RCLK_Div1); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
||
116 | SCU_HCLKDivisorConfig(SCU_HCLK_Div1); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
||
117 | SCU_PLLFactorsConfig(192,25,3); // PLL = 48 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=3 |
||
118 | #endif |
||
119 | SCU_PLLCmd(ENABLE); // Enable PLL (is disabled by SCU_PLLFactorsConfig) |
||
120 | SCU_MCLKSourceConfig(SCU_MCLK_PLL); // set master clock source to PLL |
||
121 | } |
||
1 | ingob | 122 | |
41 | ingob | 123 | //---------------------------------------------------------------------------------------------------- |
124 | void GetNaviCtrlVersion(void) |
||
1 | ingob | 125 | { |
41 | ingob | 126 | u8 msg[25]; |
270 | killagreg | 127 | |
264 | killagreg | 128 | sprintf(msg,"\n\r NaviCtrl HW: V%d.%d SW: V%d.%d%c", Version_HW/10, Version_HW%10, VERSION_MAJOR, VERSION_MINOR, 'a'+ VERSION_PATCH); |
110 | killagreg | 129 | UART1_PutString(msg); |
1 | ingob | 130 | } |
131 | |||
132 | //---------------------------------------------------------------------------------------------------- |
||
231 | holgerb | 133 | |
41 | ingob | 134 | void CheckErrors(void) |
135 | { |
||
329 | holgerb | 136 | static s32 no_error_delay = 0; |
328 | holgerb | 137 | s32 newErrorCode = 0; |
232 | killagreg | 138 | UART_VersionInfo.HardwareError[0] = 0; |
231 | holgerb | 139 | |
338 | holgerb | 140 | if(CheckDelay(I2C1_Timeout) || (Compass_Heading < 0)) DebugOut.StatusRed |= AMPEL_COMPASS; |
141 | else DebugOut.StatusRed &= ~AMPEL_COMPASS; // MK3Mag green status |
||
231 | holgerb | 142 | |
338 | holgerb | 143 | if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.StatusRed |= AMPEL_BL; |
144 | else DebugOut.StatusRed &= ~AMPEL_BL; // BL-Ctrl green status |
||
232 | killagreg | 145 | |
338 | holgerb | 146 | if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.StatusRed |= AMPEL_NC; |
147 | else DebugOut.StatusRed &= ~AMPEL_NC; |
||
148 | |||
146 | killagreg | 149 | if(CheckDelay(SPI0_Timeout)) |
41 | ingob | 150 | { |
151 | LED_RED_ON; |
||
152 | sprintf(ErrorMSG,"no FC communication "); |
||
328 | holgerb | 153 | newErrorCode = 3; |
41 | ingob | 154 | StopNavigation = 1; |
338 | holgerb | 155 | DebugOut.StatusGreen &= ~AMPEL_FC; // status of FC Present |
156 | DebugOut.StatusGreen &= ~AMPEL_BL; // status of BL Present |
||
256 | killagreg | 157 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_SPI_RX; |
41 | ingob | 158 | } |
229 | holgerb | 159 | else if(CheckDelay(I2C1_Timeout)) |
41 | ingob | 160 | { |
161 | LED_RED_ON; |
||
256 | killagreg | 162 | sprintf(ErrorMSG,"no compass communication "); |
149 | killagreg | 163 | //Reset I2CBus |
164 | I2C1_Deinit(); |
||
165 | I2C1_Init(); |
||
328 | holgerb | 166 | newErrorCode = 4; |
41 | ingob | 167 | StopNavigation = 1; |
256 | killagreg | 168 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
338 | holgerb | 169 | DebugOut.StatusRed |= AMPEL_COMPASS; |
41 | ingob | 170 | } |
171 | else if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
||
172 | { |
||
173 | LED_RED_ON; |
||
318 | holgerb | 174 | #ifndef FOLLOW_ME |
41 | ingob | 175 | sprintf(ErrorMSG,"FC not compatible "); |
318 | holgerb | 176 | #else |
177 | sprintf(ErrorMSG,"! FollowMe only ! "); |
||
178 | #endif |
||
328 | holgerb | 179 | newErrorCode = 1; |
41 | ingob | 180 | StopNavigation = 1; |
256 | killagreg | 181 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE; |
338 | holgerb | 182 | DebugOut.StatusRed |= AMPEL_NC; |
41 | ingob | 183 | } |
231 | holgerb | 184 | |
255 | killagreg | 185 | else if(FC.Error[0] & FC_ERROR0_GYRO_NICK) |
231 | holgerb | 186 | { |
187 | LED_RED_ON; |
||
188 | sprintf(ErrorMSG,"ERR: FC Nick Gyro"); |
||
328 | holgerb | 189 | newErrorCode = 10; |
232 | killagreg | 190 | } |
255 | killagreg | 191 | else if(FC.Error[0] & FC_ERROR0_GYRO_ROLL) |
231 | holgerb | 192 | { |
193 | LED_RED_ON; |
||
194 | sprintf(ErrorMSG,"ERR: FC Roll Gyro"); |
||
328 | holgerb | 195 | newErrorCode = 11; |
232 | killagreg | 196 | } |
255 | killagreg | 197 | else if(FC.Error[0] & FC_ERROR0_GYRO_YAW) |
231 | holgerb | 198 | { |
199 | LED_RED_ON; |
||
200 | sprintf(ErrorMSG,"ERR: FC Yaw Gyro"); |
||
328 | holgerb | 201 | newErrorCode = 12; |
232 | killagreg | 202 | } |
255 | killagreg | 203 | else if(FC.Error[0] & FC_ERROR0_ACC_NICK) |
231 | holgerb | 204 | { |
205 | LED_RED_ON; |
||
206 | sprintf(ErrorMSG,"ERR: FC Nick ACC"); |
||
328 | holgerb | 207 | newErrorCode = 13; |
232 | killagreg | 208 | } |
255 | killagreg | 209 | else if(FC.Error[0] & FC_ERROR0_ACC_ROLL) |
231 | holgerb | 210 | { |
211 | LED_RED_ON; |
||
212 | sprintf(ErrorMSG,"ERR: FC Roll ACC"); |
||
328 | holgerb | 213 | newErrorCode = 14; |
232 | killagreg | 214 | } |
255 | killagreg | 215 | else if(FC.Error[0] & FC_ERROR0_ACC_TOP) |
231 | holgerb | 216 | { |
217 | LED_RED_ON; |
||
327 | holgerb | 218 | sprintf(ErrorMSG,"ERR:FC Z-ACC"); |
328 | holgerb | 219 | newErrorCode = 15; |
232 | killagreg | 220 | } |
351 | holgerb | 221 | else if(NC_To_FC_Flags & NC_TO_FC_FLYING_RANGE) |
222 | { |
||
223 | LED_RED_ON; |
||
224 | sprintf(ErrorMSG,"ERR:Flying range!"); |
||
225 | newErrorCode = 28; |
||
226 | } |
||
255 | killagreg | 227 | else if(FC.Error[0] & FC_ERROR0_PRESSURE) |
231 | holgerb | 228 | { |
229 | LED_RED_ON; |
||
327 | holgerb | 230 | sprintf(ErrorMSG,"ERR:Pressure sensor"); |
328 | holgerb | 231 | newErrorCode = 16; |
232 | killagreg | 232 | } |
255 | killagreg | 233 | else if(FC.Error[1] & FC_ERROR1_I2C) |
231 | holgerb | 234 | { |
235 | LED_RED_ON; |
||
327 | holgerb | 236 | sprintf(ErrorMSG,"ERR:I2C FC to BL"); |
328 | holgerb | 237 | newErrorCode = 17; |
232 | killagreg | 238 | } |
255 | killagreg | 239 | else if(FC.Error[1] & FC_ERROR1_BL_MISSING) |
231 | holgerb | 240 | { |
241 | LED_RED_ON; |
||
242 | sprintf(ErrorMSG,"ERR: Bl Missing"); |
||
328 | holgerb | 243 | newErrorCode = 18; |
232 | killagreg | 244 | } |
255 | killagreg | 245 | else if(FC.Error[1] & FC_ERROR1_MIXER) |
231 | holgerb | 246 | { |
247 | LED_RED_ON; |
||
248 | sprintf(ErrorMSG,"Mixer Error"); |
||
328 | holgerb | 249 | newErrorCode = 19; |
232 | killagreg | 250 | } |
350 | holgerb | 251 | else if(CheckDelay(UBX_Timeout) && Parameter.GlobalConfig & FC_CFG_GPS_AKTIV) |
41 | ingob | 252 | { |
253 | LED_RED_ON; |
||
350 | holgerb | 254 | // if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected "); |
255 | // else |
||
320 | holgerb | 256 | { |
257 | sprintf(ErrorMSG,"no GPS communication "); |
||
258 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX; |
||
328 | holgerb | 259 | newErrorCode = 5; |
320 | holgerb | 260 | } |
41 | ingob | 261 | StopNavigation = 1; |
320 | holgerb | 262 | // UBX_Timeout = SetDelay(500); |
41 | ingob | 263 | } |
254 | killagreg | 264 | else if(Compass_Heading < 0) |
41 | ingob | 265 | { |
266 | LED_RED_ON; |
||
267 | sprintf(ErrorMSG,"bad compass value "); |
||
328 | holgerb | 268 | newErrorCode = 6; |
41 | ingob | 269 | StopNavigation = 1; |
256 | killagreg | 270 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
41 | ingob | 271 | } |
255 | killagreg | 272 | else if((FC.Error[1] & FC_ERROR1_SPI_RX)) |
199 | killagreg | 273 | { |
274 | LED_RED_ON; |
||
275 | sprintf(ErrorMSG,"FC spi rx error "); |
||
328 | holgerb | 276 | newErrorCode = 8; |
213 | killagreg | 277 | StopNavigation = 1; |
199 | killagreg | 278 | } |
255 | killagreg | 279 | else if(FC.Error[0] & FC_ERROR0_CAREFREE) |
231 | holgerb | 280 | { |
281 | LED_RED_ON; |
||
282 | sprintf(ErrorMSG,"FC: Carefree Error"); |
||
328 | holgerb | 283 | newErrorCode = 20; |
232 | killagreg | 284 | } |
255 | killagreg | 285 | else if(FC.Error[1] & FC_ERROR1_PPM) |
41 | ingob | 286 | { |
287 | LED_RED_ON; |
||
288 | sprintf(ErrorMSG,"RC Signal lost "); |
||
328 | holgerb | 289 | newErrorCode = 7; |
41 | ingob | 290 | } |
328 | holgerb | 291 | else if(ErrorGpsFixLost) |
292 | { |
||
293 | LED_RED_ON; |
||
294 | sprintf(ErrorMSG,"GPS Fix lost "); |
||
295 | newErrorCode = 21; |
||
296 | } |
||
330 | holgerb | 297 | else if(ErrorDisturbedEarthMagnetField) |
298 | { |
||
299 | LED_RED_ON; |
||
300 | sprintf(ErrorMSG,"Magnet error "); |
||
301 | newErrorCode = 22; |
||
338 | holgerb | 302 | DebugOut.StatusRed |= AMPEL_COMPASS | AMPEL_NC; |
303 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
||
330 | holgerb | 304 | } |
338 | holgerb | 305 | else if(BL_MinOfMaxPWM == 40 && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
306 | { |
||
307 | LED_RED_ON; |
||
308 | sprintf(ErrorMSG,"ERR:Motor restart "); |
||
309 | newErrorCode = 23; |
||
310 | DebugOut.StatusRed |= AMPEL_BL; |
||
311 | } |
||
312 | else if(BL_MinOfMaxPWM != 255 && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
||
313 | { |
||
314 | LED_RED_ON; |
||
315 | sprintf(ErrorMSG,"ERR:BL Limitation "); |
||
316 | newErrorCode = 24; |
||
317 | DebugOut.StatusRed |= AMPEL_BL; |
||
318 | } |
||
348 | holgerb | 319 | else if(NCFlags & NC_FLAG_RANGE_LIMIT && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
320 | { |
||
321 | LED_RED_ON; |
||
351 | holgerb | 322 | sprintf(ErrorMSG,"ERR:GPS range "); |
348 | holgerb | 323 | newErrorCode = 25; |
324 | DebugOut.StatusRed |= AMPEL_NC; |
||
325 | } |
||
350 | holgerb | 326 | else if(!SD_SWITCH && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START) |
327 | { |
||
328 | LED_RED_ON; |
||
329 | sprintf(ErrorMSG,"ERR:No SD-Card "); |
||
330 | newErrorCode = 26; |
||
331 | DebugOut.StatusRed |= AMPEL_NC; |
||
332 | } |
||
351 | holgerb | 333 | else if(SD_LoggingError && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START) |
334 | { |
||
335 | LED_RED_ON; |
||
336 | sprintf(ErrorMSG,"ERR:SD Logging aborted"); |
||
337 | newErrorCode = 27; |
||
338 | DebugOut.StatusRed |= AMPEL_NC; |
||
339 | SD_LoggingError = 0; |
||
340 | } |
||
355 | holgerb | 341 | else if(((AbsoluteFlyingAltitude) && (NaviData.Altimeter / 20 >= AbsoluteFlyingAltitude)) && (FC.StatusFlags & FC_STATUS_FLY)) |
342 | { |
||
343 | LED_RED_ON; |
||
344 | sprintf(ErrorMSG,"ERR:Max Altitude "); |
||
345 | newErrorCode = 29; |
||
346 | DebugOut.StatusRed |= AMPEL_NC; |
||
347 | } |
||
41 | ingob | 348 | else // no error occured |
349 | { |
||
350 | StopNavigation = 0; |
||
351 | LED_RED_OFF; |
||
328 | holgerb | 352 | if(no_error_delay) { no_error_delay--; } |
353 | else |
||
354 | { |
||
355 | sprintf(ErrorMSG,"No Error "); |
||
356 | ErrorCode = 0; |
||
357 | } |
||
41 | ingob | 358 | } |
328 | holgerb | 359 | |
360 | if(newErrorCode) |
||
361 | { |
||
339 | holgerb | 362 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) no_error_delay = 8; // delay the errors if the motors are running |
328 | holgerb | 363 | ErrorCode = newErrorCode; |
364 | } |
||
365 | FC.Error[0] = 0; |
||
366 | FC.Error[1] = 0; |
||
367 | FC.Error[2] = 0; |
||
368 | FC.Error[3] = 0; |
||
369 | FC.Error[4] = 0; |
||
370 | ErrorGpsFixLost = 0; |
||
41 | ingob | 371 | } |
24 | StephanB | 372 | |
154 | killagreg | 373 | // the handler will be cyclic called by the timer 1 ISR |
213 | killagreg | 374 | // used is for critical timing parts that normaly would handled |
154 | killagreg | 375 | // within the main loop that could block longer at logging activities |
376 | void EXTIT3_IRQHandler(void) |
||
377 | { |
||
195 | killagreg | 378 | IENABLE; |
379 | |||
154 | killagreg | 380 | VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq |
195 | killagreg | 381 | VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit |
292 | killagreg | 382 | Compass_Update(); // update compass communication |
154 | killagreg | 383 | Analog_Update(); // get new ADC values |
195 | killagreg | 384 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq |
154 | killagreg | 385 | |
195 | killagreg | 386 | IDISABLE; |
154 | killagreg | 387 | } |
388 | |||
41 | ingob | 389 | //---------------------------------------------------------------------------------------------------- |
390 | int main(void) |
||
391 | { |
||
324 | killagreg | 392 | /* |
393 | static u32 ftimer =0; |
||
394 | static u8 fstate = 0; |
||
395 | static File_t* f = NULL; |
||
396 | */ |
||
397 | |||
41 | ingob | 398 | /* Configure the system clocks */ |
399 | SCU_Config(); |
||
400 | /* init VIC (Vectored Interrupt Controller) */ |
||
401 | SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC |
||
402 | SCU_AHBPeriphReset(__VIC, DISABLE); // disable reset state for VIC |
||
403 | VIC_DeInit(); // deinitializes the VIC module registers to their default reset values. |
||
196 | killagreg | 404 | VIC_InitDefaultVectors(); |
405 | |||
119 | killagreg | 406 | // initialize timer 1 for System Clock and delay rountines |
41 | ingob | 407 | TIMER1_Init(); |
408 | // initialize the LEDs (needs Timer 1) |
||
409 | Led_Init(); |
||
410 | // initialize the debug UART1 |
||
411 | UART1_Init(); |
||
110 | killagreg | 412 | UART1_PutString("\r\n---------------------------------------------"); |
275 | killagreg | 413 | // initialize usb |
414 | USB_ConfigInit(); |
||
120 | killagreg | 415 | // initialize timer 2 for servo outputs |
180 | killagreg | 416 | //TIMER2_Init(); |
41 | ingob | 417 | // initialize UART2 to FLIGHTCTRL |
418 | UART2_Init(); |
||
419 | // initialize UART0 (to MKGPS or MK3MAG) |
||
420 | UART0_Init(); |
||
134 | killagreg | 421 | // initialize adc |
422 | Analog_Init(); |
||
41 | ingob | 423 | // initialize SPI0 to FC |
424 | SPI0_Init(); |
||
242 | killagreg | 425 | // initialize i2c bus (needs Timer 1) |
41 | ingob | 426 | I2C1_Init(); |
247 | killagreg | 427 | // initialize fat16 partition on sd card (needs Timer 1) |
41 | ingob | 428 | Fat16_Init(); |
156 | killagreg | 429 | // initialize NC params |
430 | NCParams_Init(); |
||
88 | killagreg | 431 | // initialize the settings |
432 | Settings_Init(); |
||
92 | killagreg | 433 | // initialize logging (needs settings) |
82 | killagreg | 434 | Logging_Init(); |
1 | ingob | 435 | |
41 | ingob | 436 | TimerCheckError = SetDelay(3000); |
175 | holgerb | 437 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
110 | killagreg | 438 | UART1_PutString("\n\r Version information:"); |
116 | killagreg | 439 | |
41 | ingob | 440 | GetNaviCtrlVersion(); |
338 | holgerb | 441 | DebugOut.StatusGreen = AMPEL_NC | AMPEL_COMPASS; // NC and MK3Mag |
442 | DebugOut.StatusRed = 0x00; |
||
149 | killagreg | 443 | |
242 | killagreg | 444 | Compass_Init(); |
270 | killagreg | 445 | |
314 | killagreg | 446 | #ifdef FOLLOW_ME |
447 | TransmitAlsoToFC = 1; |
||
448 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
||
449 | UART1_PutString("\n\r FOLLOW-ME Transmitter only!"); |
||
450 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++\r\n\r\n"); |
||
451 | TransmitAlsoToFC = 0; |
||
452 | #else |
||
150 | killagreg | 453 | SPI0_GetFlightCtrlVersion(); |
454 | if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
||
41 | ingob | 455 | { |
150 | killagreg | 456 | UART1_PutString("\n\r Flight-Ctrl not compatible"); |
41 | ingob | 457 | LED_RED_ON; |
458 | } |
||
314 | killagreg | 459 | #endif |
1 | ingob | 460 | |
270 | killagreg | 461 | GPS_Init(); |
116 | killagreg | 462 | |
213 | killagreg | 463 | // ---------- Prepare the isr driven |
154 | killagreg | 464 | // set to absolute lowest priority |
465 | VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW); |
||
195 | killagreg | 466 | // enable interrupts |
154 | killagreg | 467 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); |
244 | killagreg | 468 | |
250 | ingob | 469 | Debug_OK("START"); |
270 | killagreg | 470 | |
154 | killagreg | 471 | for (;;) // the endless main loop |
41 | ingob | 472 | { |
155 | killagreg | 473 | UART0_ProcessRxData(); // process request |
474 | UART1_ProcessRxData(); // process request |
||
254 | killagreg | 475 | USB_ProcessRxData(); // process request |
154 | killagreg | 476 | UART0_TransmitTxData(); // send answer |
146 | killagreg | 477 | UART1_TransmitTxData(); // send answer |
190 | killagreg | 478 | UART2_TransmitTxData(); // send answer |
254 | killagreg | 479 | USB_TransmitTxData(); // send answer |
155 | killagreg | 480 | SPI0_UpdateBuffer(); // handle new SPI Data |
327 | holgerb | 481 | |
41 | ingob | 482 | // ---------------- Error Check Timing ---------------------------- |
483 | if(CheckDelay(TimerCheckError)) |
||
1 | ingob | 484 | { |
114 | killagreg | 485 | TimerCheckError = SetDelay(1000); |
327 | holgerb | 486 | if(CheckDelay(SPI0_Timeout) && (DebugUART == UART1)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected |
487 | |||
488 | if(!CheckDelay(SPI0_Timeout) || (DebugUART == UART1)) CheckErrors(); |
||
489 | |||
255 | killagreg | 490 | if(FC.StatusFlags & FC_STATUS_FLY) NaviData.FlyingTime++; // we want to count the battery-time |
146 | killagreg | 491 | // else NaviData.FlyingTime = 0; // not the time per flight |
92 | killagreg | 492 | if(SerialLinkOkay) SerialLinkOkay--; |
493 | if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication |
||
494 | else NCFlags &= ~NC_FLAG_NOSERIALLINK; |
||
320 | holgerb | 495 | if(StopNavigation && (Parameter.NaviGpsModeControl >= 50) && (Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) BeepTime = 1000; |
1 | ingob | 496 | } |
327 | holgerb | 497 | |
82 | killagreg | 498 | // ---------------- Logging --------------------------------------- |
146 | killagreg | 499 | Logging_Update(); // could be block some time for at max. 2 seconds, therefore move time critical part of the mainloop into the ISR of timer 1 |
327 | holgerb | 500 | |
324 | killagreg | 501 | /* |
502 | // test |
||
503 | if(CheckDelay(ftimer)) |
||
504 | { |
||
505 | |||
506 | s8* filename = "test.txt"; |
||
507 | |||
508 | ftimer = SetDelay(100); |
||
509 | if(FC.Poti[3]>100 && fstate == 0) |
||
510 | { |
||
511 | fstate = 1; |
||
512 | } |
||
513 | else if(FC.Poti[3]<100 && fstate == 2) |
||
514 | { |
||
515 | fstate = 3; |
||
516 | } |
||
517 | |||
518 | switch(fstate) |
||
519 | { |
||
520 | case 1: |
||
521 | sprintf(text,"\r\nStart writing file: %s", filename); |
||
522 | UART1_PutString(text); |
||
523 | f = fopen_(filename, 'a'); |
||
524 | if(f== NULL) Fat16_Init(); |
||
525 | fstate = 2; |
||
526 | break; |
||
527 | |||
528 | case 2: |
||
529 | fputs_("\r\ntest edins sdv dsivbds iv dsivb disbv idsv bisd bv d suiv dsibsivbdis fbvisdöb visdbvisdb vidbfibds ibv", f); |
||
530 | break; |
||
531 | |||
532 | case 3: |
||
533 | sprintf(text,"\r\nClosing file: %s", filename); |
||
534 | UART1_PutString(text); |
||
535 | fclose_(f); |
||
536 | fstate = 0; |
||
537 | break; |
||
538 | |||
539 | default: |
||
540 | break; |
||
541 | } |
||
542 | } |
||
543 | */ |
||
24 | StephanB | 544 | } |
1 | ingob | 545 | } |
546 | |||
342 | holgerb | 547 | // DebugOut.Analog[] |