Go to most recent revision | Details | 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 |
||
489 | killagreg | 10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
360 | holgerb | 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 |
||
489 | killagreg | 21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
360 | holgerb | 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 - |
489 | killagreg | 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 |
360 | holgerb | 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; |
491 | killagreg | 58 | //#include <stdio.h> |
693 | holgerb | 59 | #include <string.h> |
41 | ingob | 60 | #include "91x_lib.h" |
61 | #include "led.h" |
||
62 | #include "uart0.h" |
||
63 | #include "uart1.h" |
||
64 | #include "uart2.h" |
||
215 | killagreg | 65 | #include "gps.h" |
489 | killagreg | 66 | #include "i2c.h" |
242 | killagreg | 67 | #include "compass.h" |
426 | holgerb | 68 | #include "ncmag.h" |
119 | killagreg | 69 | #include "timer1.h" |
70 | #include "timer2.h" |
||
134 | killagreg | 71 | #include "analog.h" |
41 | ingob | 72 | #include "spi_slave.h" |
73 | #include "fat16.h" |
||
74 | #include "sdc.h" |
||
82 | killagreg | 75 | #include "logging.h" |
156 | killagreg | 76 | #include "params.h" |
88 | killagreg | 77 | #include "settings.h" |
154 | killagreg | 78 | #include "config.h" |
1 | ingob | 79 | #include "main.h" |
250 | ingob | 80 | #include "debug.h" |
254 | killagreg | 81 | #include "eeprom.h" |
350 | holgerb | 82 | #include "ssc.h" |
362 | holgerb | 83 | #include "sdc.h" |
380 | holgerb | 84 | #include "uart1.h" |
688 | holgerb | 85 | #include "canbus.h" |
706 | holgerb | 86 | #include "triggerlog.h" |
727 | holgerb | 87 | #include "CamCtrl.h" |
254 | killagreg | 88 | |
427 | killagreg | 89 | |
314 | killagreg | 90 | #ifdef FOLLOW_ME |
91 | u8 TransmitAlsoToFC = 0; |
||
92 | #endif |
||
41 | ingob | 93 | u32 TimerCheckError; |
489 | killagreg | 94 | u8 ErrorCode = 0; |
41 | ingob | 95 | u16 BeepTime; |
92 | killagreg | 96 | u8 NCFlags = 0; |
153 | killagreg | 97 | s16 GeoMagDec = 0; // local magnetic declination in 0.1 deg |
328 | holgerb | 98 | u8 ErrorGpsFixLost = 0; |
513 | killagreg | 99 | u8 FromFC_LoadWP_List = 0, FromFC_Load_SinglePoint = 0, FromFC_Save_SinglePoint = 0; |
531 | holgerb | 100 | u8 ToFC_MaxWpListIndex = 4; |
255 | killagreg | 101 | u8 ClearFCStatusFlags = 0; |
41 | ingob | 102 | u8 StopNavigation = 0; |
378 | holgerb | 103 | volatile u32 PollingTimeout = 10000; |
41 | ingob | 104 | Param_t Parameter; |
699 | holgerb | 105 | Partner_t Partner; |
78 | holgerb | 106 | volatile FC_t FC; |
378 | holgerb | 107 | volatile u32 SPIWatchDog = 15000; // stop Navigation if this goes to zero |
400 | holgerb | 108 | volatile u32 SD_WatchDog = 15000; // stop Logging if this goes to zero |
663 | holgerb | 109 | u32 CountGpsProcessedIn5Sec = 50,CountNewGpsDataIn5Sec = 25, FreqGpsNavProcessed = 0, FreqNewGpsData = 0; |
504 | holgerb | 110 | u8 NewWPL_Name = 0; |
532 | holgerb | 111 | u32 MaxWP_Radius_in_m = 0; |
41 | ingob | 112 | s8 ErrorMSG[25]; |
699 | holgerb | 113 | s8 PartnerErrorMSG[25] = " --- \0"; |
533 | holgerb | 114 | u32 TimeSinceMotorStart = 0; |
699 | holgerb | 115 | u8 IamMaster = NOTHING; // for Master/Slave Redundance |
41 | ingob | 116 | |
1 | ingob | 117 | //---------------------------------------------------------------------------------------------------- |
41 | ingob | 118 | void SCU_Config(void) |
1 | ingob | 119 | { |
41 | ingob | 120 | /* configure PLL and set it as master clock source */ |
121 | SCU_MCLKSourceConfig(SCU_MCLK_OSC); // set master clock source to external oscillator clock (25MHz) before diabling the PLL |
||
122 | SCU_PLLCmd(DISABLE); // now disable the PLL |
||
123 | #ifdef MCLK96MHZ |
||
124 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div2); // set BRCLK to MCLK/2 = 48MHz |
||
125 | SCU_PCLKDivisorConfig(SCU_PCLK_Div4); // set PCLK (APB bus clock) divisor to 4 (half Reference Clock) |
||
126 | SCU_RCLKDivisorConfig(SCU_RCLK_Div2); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
||
127 | SCU_HCLKDivisorConfig(SCU_HCLK_Div2); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
||
128 | SCU_PLLFactorsConfig(192,25,2); // PLL = 96 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=2 |
||
129 | #else |
||
130 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div1); // set BRCLK to MCLK = 48MHz |
||
131 | SCU_PCLKDivisorConfig(SCU_PCLK_Div2); // set PCLK (APB bus clock) divisor to 2 (half Reference Clock) |
||
132 | SCU_RCLKDivisorConfig(SCU_RCLK_Div1); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
||
133 | SCU_HCLKDivisorConfig(SCU_HCLK_Div1); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
||
134 | SCU_PLLFactorsConfig(192,25,3); // PLL = 48 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=3 |
||
135 | #endif |
||
136 | SCU_PLLCmd(ENABLE); // Enable PLL (is disabled by SCU_PLLFactorsConfig) |
||
137 | SCU_MCLKSourceConfig(SCU_MCLK_PLL); // set master clock source to PLL |
||
138 | } |
||
1 | ingob | 139 | |
41 | ingob | 140 | //---------------------------------------------------------------------------------------------------- |
141 | void GetNaviCtrlVersion(void) |
||
1 | ingob | 142 | { |
41 | ingob | 143 | u8 msg[25]; |
270 | killagreg | 144 | |
530 | holgerb | 145 | sprintf(msg,"\n\r NaviCtrl HW: V%d.%d SW: V%d.%02d%c", UART_VersionInfo.HWMajor/10, UART_VersionInfo.HWMajor%10, VERSION_MAJOR, VERSION_MINOR, 'a'+ VERSION_PATCH); |
110 | killagreg | 146 | UART1_PutString(msg); |
1 | ingob | 147 | } |
148 | |||
149 | //---------------------------------------------------------------------------------------------------- |
||
231 | holgerb | 150 | |
41 | ingob | 151 | void CheckErrors(void) |
152 | { |
||
516 | holgerb | 153 | static s32 no_error_delay = 0; |
328 | holgerb | 154 | s32 newErrorCode = 0; |
232 | killagreg | 155 | UART_VersionInfo.HardwareError[0] = 0; |
231 | holgerb | 156 | |
489 | killagreg | 157 | if(CheckDelay(I2CBus(Compass_I2CPort)->Timeout) || (Compass_Heading < 0)) DebugOut.StatusRed |= AMPEL_COMPASS; |
338 | holgerb | 158 | else DebugOut.StatusRed &= ~AMPEL_COMPASS; // MK3Mag green status |
231 | holgerb | 159 | |
338 | holgerb | 160 | if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.StatusRed |= AMPEL_BL; |
161 | else DebugOut.StatusRed &= ~AMPEL_BL; // BL-Ctrl green status |
||
232 | killagreg | 162 | |
338 | holgerb | 163 | if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.StatusRed |= AMPEL_NC; |
164 | else DebugOut.StatusRed &= ~AMPEL_NC; |
||
165 | |||
489 | killagreg | 166 | if(CheckDelay(I2CBus(Compass_I2CPort)->Timeout)) |
41 | ingob | 167 | { |
489 | killagreg | 168 | LED_RED_ON; |
472 | holgerb | 169 | sprintf(ErrorMSG,"no compass communica"); |
489 | killagreg | 170 | //Reset Compass communication |
501 | holgerb | 171 | if(Compass_I2CPort == NCMAG_PORT_EXTERN) I2CBus_Init(I2C0); else I2CBus_Init(I2C1); |
489 | killagreg | 172 | Compass_Init(); |
472 | holgerb | 173 | newErrorCode = 4; |
41 | ingob | 174 | StopNavigation = 1; |
472 | holgerb | 175 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
176 | DebugOut.StatusRed |= AMPEL_COMPASS; |
||
41 | ingob | 177 | } |
488 | holgerb | 178 | else if(CompassValueErrorCount > 30) |
179 | { |
||
180 | LED_RED_ON; |
||
181 | sprintf(ErrorMSG,"compass sensor error"); |
||
182 | newErrorCode = 34; |
||
183 | StopNavigation = 1; |
||
184 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
||
501 | holgerb | 185 | if(Compass_I2CPort == NCMAG_PORT_EXTERN) I2CBus_Init(I2C0); else I2CBus_Init(I2C1); |
489 | killagreg | 186 | Compass_Init(); |
488 | holgerb | 187 | } |
489 | killagreg | 188 | else if((FCCalibActive || CompassCalState) && FC_Version.Hardware) |
189 | { |
||
488 | holgerb | 190 | sprintf(ErrorMSG,"Calibrate... "); |
489 | killagreg | 191 | newErrorCode = 0; |
488 | holgerb | 192 | ErrorCode = 0; |
193 | no_error_delay = 1; |
||
489 | killagreg | 194 | } |
195 | else if(CheckDelay(SPI0_Timeout)) |
||
483 | holgerb | 196 | { |
489 | killagreg | 197 | LED_RED_ON; |
472 | holgerb | 198 | sprintf(ErrorMSG,"no FC communication "); |
199 | newErrorCode = 3; |
||
200 | StopNavigation = 1; |
||
201 | DebugOut.StatusGreen &= ~AMPEL_FC; // status of FC Present |
||
202 | DebugOut.StatusGreen &= ~AMPEL_BL; // status of BL Present |
||
203 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_SPI_RX; |
||
204 | } |
||
41 | ingob | 205 | else if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
206 | { |
||
207 | LED_RED_ON; |
||
318 | holgerb | 208 | #ifndef FOLLOW_ME |
41 | ingob | 209 | sprintf(ErrorMSG,"FC not compatible "); |
318 | holgerb | 210 | #else |
211 | sprintf(ErrorMSG,"! FollowMe only ! "); |
||
212 | #endif |
||
328 | holgerb | 213 | newErrorCode = 1; |
41 | ingob | 214 | StopNavigation = 1; |
256 | killagreg | 215 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE; |
338 | holgerb | 216 | DebugOut.StatusRed |= AMPEL_NC; |
41 | ingob | 217 | } |
255 | killagreg | 218 | else if(FC.Error[0] & FC_ERROR0_GYRO_NICK) |
231 | holgerb | 219 | { |
220 | LED_RED_ON; |
||
221 | sprintf(ErrorMSG,"ERR: FC Nick Gyro"); |
||
328 | holgerb | 222 | newErrorCode = 10; |
232 | killagreg | 223 | } |
255 | killagreg | 224 | else if(FC.Error[0] & FC_ERROR0_GYRO_ROLL) |
231 | holgerb | 225 | { |
226 | LED_RED_ON; |
||
227 | sprintf(ErrorMSG,"ERR: FC Roll Gyro"); |
||
328 | holgerb | 228 | newErrorCode = 11; |
232 | killagreg | 229 | } |
255 | killagreg | 230 | else if(FC.Error[0] & FC_ERROR0_GYRO_YAW) |
231 | holgerb | 231 | { |
232 | LED_RED_ON; |
||
233 | sprintf(ErrorMSG,"ERR: FC Yaw Gyro"); |
||
328 | holgerb | 234 | newErrorCode = 12; |
232 | killagreg | 235 | } |
255 | killagreg | 236 | else if(FC.Error[0] & FC_ERROR0_ACC_NICK) |
231 | holgerb | 237 | { |
238 | LED_RED_ON; |
||
239 | sprintf(ErrorMSG,"ERR: FC Nick ACC"); |
||
328 | holgerb | 240 | newErrorCode = 13; |
232 | killagreg | 241 | } |
255 | killagreg | 242 | else if(FC.Error[0] & FC_ERROR0_ACC_ROLL) |
231 | holgerb | 243 | { |
244 | LED_RED_ON; |
||
245 | sprintf(ErrorMSG,"ERR: FC Roll ACC"); |
||
328 | holgerb | 246 | newErrorCode = 14; |
232 | killagreg | 247 | } |
255 | killagreg | 248 | else if(FC.Error[0] & FC_ERROR0_ACC_TOP) |
231 | holgerb | 249 | { |
250 | LED_RED_ON; |
||
327 | holgerb | 251 | sprintf(ErrorMSG,"ERR:FC Z-ACC"); |
328 | holgerb | 252 | newErrorCode = 15; |
232 | killagreg | 253 | } |
351 | holgerb | 254 | else if(NC_To_FC_Flags & NC_TO_FC_FLYING_RANGE) |
255 | { |
||
256 | LED_RED_ON; |
||
257 | sprintf(ErrorMSG,"ERR:Flying range!"); |
||
258 | newErrorCode = 28; |
||
259 | } |
||
255 | killagreg | 260 | else if(FC.Error[0] & FC_ERROR0_PRESSURE) |
231 | holgerb | 261 | { |
489 | killagreg | 262 | LED_RED_ON; |
327 | holgerb | 263 | sprintf(ErrorMSG,"ERR:Pressure sensor"); |
328 | holgerb | 264 | newErrorCode = 16; |
232 | killagreg | 265 | } |
255 | killagreg | 266 | else if(FC.Error[1] & FC_ERROR1_I2C) |
231 | holgerb | 267 | { |
268 | LED_RED_ON; |
||
327 | holgerb | 269 | sprintf(ErrorMSG,"ERR:I2C FC to BL"); |
328 | holgerb | 270 | newErrorCode = 17; |
232 | killagreg | 271 | } |
255 | killagreg | 272 | else if(FC.Error[1] & FC_ERROR1_BL_MISSING) |
231 | holgerb | 273 | { |
274 | LED_RED_ON; |
||
275 | sprintf(ErrorMSG,"ERR: Bl Missing"); |
||
328 | holgerb | 276 | newErrorCode = 18; |
232 | killagreg | 277 | } |
255 | killagreg | 278 | else if(FC.Error[1] & FC_ERROR1_MIXER) |
231 | holgerb | 279 | { |
280 | LED_RED_ON; |
||
281 | sprintf(ErrorMSG,"Mixer Error"); |
||
328 | holgerb | 282 | newErrorCode = 19; |
232 | killagreg | 283 | } |
350 | holgerb | 284 | else if(CheckDelay(UBX_Timeout) && Parameter.GlobalConfig & FC_CFG_GPS_AKTIV) |
41 | ingob | 285 | { |
286 | LED_RED_ON; |
||
548 | holgerb | 287 | sprintf(ErrorMSG,"no GPS communication"); |
288 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX; |
||
289 | UART_VersionInfo.Flags &= ~NC_VERSION_FLAG_GPS_PRESENT; |
||
290 | newErrorCode = 5; |
||
41 | ingob | 291 | StopNavigation = 1; |
292 | } |
||
426 | holgerb | 293 | else if(Compass_Heading < 0 && NCMAG_Present && !NCMAG_IsCalibrated) |
294 | { |
||
295 | LED_RED_ON; |
||
296 | sprintf(ErrorMSG,"compass not calibr."); |
||
297 | newErrorCode = 31; |
||
298 | StopNavigation = 1; |
||
299 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
||
300 | } |
||
254 | killagreg | 301 | else if(Compass_Heading < 0) |
41 | ingob | 302 | { |
303 | LED_RED_ON; |
||
304 | sprintf(ErrorMSG,"bad compass value "); |
||
328 | holgerb | 305 | newErrorCode = 6; |
41 | ingob | 306 | StopNavigation = 1; |
256 | killagreg | 307 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
41 | ingob | 308 | } |
255 | killagreg | 309 | else if((FC.Error[1] & FC_ERROR1_SPI_RX)) |
199 | killagreg | 310 | { |
311 | LED_RED_ON; |
||
312 | sprintf(ErrorMSG,"FC spi rx error "); |
||
328 | holgerb | 313 | newErrorCode = 8; |
213 | killagreg | 314 | StopNavigation = 1; |
199 | killagreg | 315 | } |
255 | killagreg | 316 | else if(FC.Error[0] & FC_ERROR0_CAREFREE) |
231 | holgerb | 317 | { |
318 | LED_RED_ON; |
||
319 | sprintf(ErrorMSG,"FC: Carefree Error"); |
||
328 | holgerb | 320 | newErrorCode = 20; |
232 | killagreg | 321 | } |
706 | holgerb | 322 | else if(FC.BAT_Voltage < 45) |
323 | { |
||
324 | LED_RED_ON; |
||
325 | sprintf(ErrorMSG,"ERR:Power Supply"); |
||
326 | newErrorCode = 41; |
||
327 | } |
||
328 | else |
||
329 | if(FC.Error[1] & FC_ERROR1_RC_VOLTAGE) |
||
330 | { |
||
331 | LED_RED_ON; |
||
332 | sprintf(ErrorMSG,"ERR: 5V RC-Supply"); |
||
333 | newErrorCode = 40; |
||
334 | } |
||
255 | killagreg | 335 | else if(FC.Error[1] & FC_ERROR1_PPM) |
41 | ingob | 336 | { |
337 | LED_RED_ON; |
||
338 | sprintf(ErrorMSG,"RC Signal lost "); |
||
328 | holgerb | 339 | newErrorCode = 7; |
41 | ingob | 340 | } |
489 | killagreg | 341 | else if(ErrorGpsFixLost) |
328 | holgerb | 342 | { |
489 | killagreg | 343 | LED_RED_ON; |
344 | sprintf(ErrorMSG,"GPS Fix lost "); |
||
345 | newErrorCode = 21; |
||
328 | holgerb | 346 | } |
330 | holgerb | 347 | else if(ErrorDisturbedEarthMagnetField) |
348 | { |
||
489 | killagreg | 349 | LED_RED_ON; |
350 | sprintf(ErrorMSG,"Magnet error "); |
||
351 | newErrorCode = 22; |
||
352 | DebugOut.StatusRed |= AMPEL_COMPASS | AMPEL_NC; |
||
353 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
||
330 | holgerb | 354 | } |
533 | holgerb | 355 | else if(((ErrorCheck_BL_MinOfMaxPWM == 40 && (TimeSinceMotorStart > 3)) || (ErrorCheck_BL_MinOfMaxPWM == 39)) && !ErrorCode) |
338 | holgerb | 356 | { |
489 | killagreg | 357 | LED_RED_ON; |
358 | sprintf(ErrorMSG,"ERR:Motor restart "); |
||
359 | newErrorCode = 23; |
||
360 | DebugOut.StatusRed |= AMPEL_BL; |
||
338 | holgerb | 361 | } |
731 | holgerb | 362 | else if(BL_MinOfMaxPWM && BL_MinOfMaxPWM < 30 && !ErrorCode) |
338 | holgerb | 363 | { |
489 | killagreg | 364 | u16 i; |
731 | holgerb | 365 | for(i = 0; i < 16; i++) if(Motor[i].MaxPWM == BL_MinOfMaxPWM) break; // find the motor number |
489 | killagreg | 366 | LED_RED_ON; |
367 | sprintf(ErrorMSG,"ERR:BL%2d Test:%2d ",i+1,BL_MinOfMaxPWM); |
||
516 | holgerb | 368 | newErrorCode = 32; |
369 | DebugOut.StatusRed |= AMPEL_BL; |
||
472 | holgerb | 370 | } |
533 | holgerb | 371 | else if(ErrorCheck_BL_MinOfMaxPWM < 248 && (TimeSinceMotorStart > 3) && !ErrorCode) |
472 | holgerb | 372 | { |
489 | killagreg | 373 | LED_RED_ON; |
374 | sprintf(ErrorMSG,"ERR:BL Limitation "); |
||
375 | newErrorCode = 24; |
||
376 | DebugOut.StatusRed |= AMPEL_BL; |
||
338 | holgerb | 377 | } |
491 | killagreg | 378 | else if((NCFlags & NC_FLAG_RANGE_LIMIT) && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
348 | holgerb | 379 | { |
489 | killagreg | 380 | LED_RED_ON; |
532 | holgerb | 381 | sprintf(ErrorMSG,"ERR:GPS WP range "); |
489 | killagreg | 382 | newErrorCode = 25; |
383 | DebugOut.StatusRed |= AMPEL_NC; |
||
348 | holgerb | 384 | } |
397 | holgerb | 385 | else if((!SD_SWITCH || (SDCardInfo.Valid == 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START && !(FC.StatusFlags & FC_STATUS_FLY)) |
350 | holgerb | 386 | { |
489 | killagreg | 387 | LED_RED_ON; |
388 | sprintf(ErrorMSG,"ERR:No SD-Card "); |
||
389 | newErrorCode = 26; |
||
390 | DebugOut.StatusRed |= AMPEL_NC; |
||
350 | holgerb | 391 | } |
383 | holgerb | 392 | else if((SD_LoggingError || (SD_WatchDog < 2000 && SD_WatchDog != 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START) |
351 | holgerb | 393 | { |
489 | killagreg | 394 | LED_RED_ON; |
395 | sprintf(ErrorMSG,"ERR:SD Logging abort"); |
||
396 | newErrorCode = 27; |
||
397 | DebugOut.StatusRed |= AMPEL_NC; |
||
398 | SD_LoggingError = 0; |
||
351 | holgerb | 399 | } |
355 | holgerb | 400 | else if(((AbsoluteFlyingAltitude) && (NaviData.Altimeter / 20 >= AbsoluteFlyingAltitude)) && (FC.StatusFlags & FC_STATUS_FLY)) |
401 | { |
||
489 | killagreg | 402 | LED_RED_ON; |
403 | sprintf(ErrorMSG,"ERR:Max Altitude "); |
||
404 | newErrorCode = 29; |
||
405 | DebugOut.StatusRed |= AMPEL_NC; |
||
355 | holgerb | 406 | } |
516 | holgerb | 407 | else if(Parameter.GlobalConfig3 & CFG3_NO_GPSFIX_NO_START && !(NCFlags & NC_FLAG_GPS_OK) && ((FC.StatusFlags & (FC_STATUS_START | FC_STATUS_MOTOR_RUN)) || (FC.StickGas < -50 && FC.StickYaw < -50))) |
489 | killagreg | 408 | { |
409 | LED_RED_ON; |
||
410 | sprintf(ErrorMSG,"No GPS Fix "); |
||
411 | newErrorCode = 30; |
||
398 | holgerb | 412 | } |
663 | holgerb | 413 | else if((FreqNewGpsData <= 35 || FreqNewGpsData > 60) && TimeSinceMotorStart > 15) |
646 | holgerb | 414 | { |
415 | LED_RED_ON; |
||
659 | holgerb | 416 | sprintf(ErrorMSG,"GPS Update rate "); |
417 | newErrorCode = 38; |
||
646 | holgerb | 418 | } |
615 | holgerb | 419 | else if(NC_GPS_ModeCharacter == 'F') |
420 | { |
||
421 | sprintf(ErrorMSG,"FAILSAFE pos.! "); |
||
422 | newErrorCode = 35; |
||
423 | } |
||
424 | else if(FC.StatusFlags3 & FC_STATUS3_REDUNDANCE_ERROR) |
||
425 | { |
||
426 | sprintf(ErrorMSG,"ERR:Redundancy "); |
||
427 | newErrorCode = 36; |
||
428 | } |
||
429 | else if(FC.StatusFlags3 & FC_STATUS3_REDUNDANCE_TEST) |
||
430 | { |
||
431 | sprintf(ErrorMSG,"Redundancy test "); |
||
432 | newErrorCode = 37; |
||
433 | } |
||
699 | holgerb | 434 | else if(CanbusTimeOut == 1) |
435 | { |
||
436 | sprintf(ErrorMSG,"ERR: Canbus"); |
||
715 | holgerb | 437 | CanbusInit(); |
699 | holgerb | 438 | newErrorCode = 39; |
439 | } |
||
706 | holgerb | 440 | else |
441 | if(FC.Error[1] & FC_ERROR1_ACC_NOT_CAL) |
||
442 | { |
||
443 | LED_RED_ON; |
||
444 | sprintf(ErrorMSG,"ACC not calib."); |
||
445 | newErrorCode = 42; |
||
446 | } |
||
41 | ingob | 447 | else // no error occured |
448 | { |
||
449 | StopNavigation = 0; |
||
450 | LED_RED_OFF; |
||
489 | killagreg | 451 | if(no_error_delay) { no_error_delay--; } |
452 | else |
||
453 | { |
||
454 | sprintf(ErrorMSG,"No Error "); |
||
455 | ErrorCode = 0; |
||
456 | } |
||
41 | ingob | 457 | } |
328 | holgerb | 458 | |
516 | holgerb | 459 | if(newErrorCode) |
460 | { |
||
461 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) no_error_delay = 8; // delay the errors if the motors are running |
||
462 | ErrorCode = newErrorCode; |
||
463 | } |
||
464 | FC.Error[0] = 0; |
||
465 | FC.Error[1] = 0; |
||
466 | FC.Error[2] = 0; |
||
467 | FC.Error[3] = 0; |
||
468 | FC.Error[4] = 0; |
||
469 | ErrorGpsFixLost = 0; |
||
530 | holgerb | 470 | ErrorCheck_BL_MinOfMaxPWM = BL_MinOfMaxPWM; |
41 | ingob | 471 | } |
24 | StephanB | 472 | |
693 | holgerb | 473 | unsigned char RAM_Checksum(unsigned char* pBuffer, u16 len) |
474 | { |
||
475 | u8 crc = 0xAA; |
||
476 | u16 i; |
||
477 | for(i=0; i<len; i++) crc += pBuffer[i]; |
||
478 | return crc; |
||
479 | } |
||
378 | holgerb | 480 | |
481 | |||
484 | holgerb | 482 | u8 Polling(void) |
378 | holgerb | 483 | { |
564 | holgerb | 484 | static u8 running = 0, oldFcFlags = 0, count5sec, TimeoutGPS_Process; |
489 | killagreg | 485 | static u32 old_ms = 0; |
486 | |||
516 | holgerb | 487 | if(running) {/*DebugOut.Analog[]++;*/ return(1);}; |
489 | killagreg | 488 | running = 1; |
489 | |||
490 | if(CountMilliseconds != old_ms) // 1 ms |
||
491 | { |
||
699 | holgerb | 492 | if(CanbusTimeOut >= 2) CanbusTimeOut--; |
727 | holgerb | 493 | if(CamCtrlTimeout) |
494 | { |
||
495 | if(--CamCtrlTimeout == 1) CamCtrlCharacter = '?'; |
||
496 | else if(CamCtrlTimeout == 10000) CamCtrlTimeout = 0; // this is used during NC startup-Time phase |
||
497 | } |
||
498 | else |
||
499 | { |
||
500 | if(TrigLogging.CountExternal) CamCtrlCharacter = TrigLogging.CountExternal % 10 + '0'; |
||
501 | FromCamCtrl.CamStatus = 0; |
||
502 | }; |
||
483 | holgerb | 503 | old_ms = CountMilliseconds; |
504 | Compass_Update(); // update compass communication |
||
505 | Analog_Update(); // get new ADC values |
||
506 | CalcHeadFree(); |
||
727 | holgerb | 507 | if(CamCtrlTimeout > 1) CamCtrl_GetData(3); |
688 | holgerb | 508 | if(UART_VersionInfo.HWMajor >= 30) ProcessCanBus(); |
564 | holgerb | 509 | if(!CheckDelay(SPI0_Timeout)) TimeoutGPS_Process = 0; |
510 | else if(CountMilliseconds - SPI0_Timeout > 30000000L) SPI0_Timeout = CountMilliseconds; // avoid too long overflows |
||
511 | if(++TimeoutGPS_Process >= 25) |
||
512 | { |
||
513 | GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected |
||
514 | TimeoutGPS_Process = 0; |
||
515 | } |
||
483 | holgerb | 516 | } |
488 | holgerb | 517 | |
489 | killagreg | 518 | SPI0_UpdateBuffer(); // also calls the GPS-functions |
519 | UART0_ProcessRxData(); // GPS process request |
||
520 | UART0_TransmitTxData(); // GPS send answer |
||
521 | UART1_ProcessRxData(); // PC process request |
||
522 | UART1_TransmitTxData(); // PC send answer |
||
523 | UART2_TransmitTxData(); // FC send answer |
||
524 | |||
533 | holgerb | 525 | if(!(FC.StatusFlags & FC_STATUS_MOTOR_RUN)) TimeSinceMotorStart = 0; |
526 | |||
693 | holgerb | 527 | if(HugeBlockFromFC.WhoAmI == 1) // contains eeprom-Data |
528 | { |
||
529 | u8 crc1, crc2; |
||
530 | crc1 = HugeBlockFromFC.Data[sizeof(EE_Parameter)-1]; // contains the EE_Parameter.crc |
||
531 | crc2 = RAM_Checksum((u8 *)(&HugeBlockFromFC.Data), sizeof(EE_Parameter)-1); // calculates the current crc |
||
532 | if(crc1 == crc2) |
||
533 | { |
||
534 | memcpy(&EE_Parameter, (u8 *) HugeBlockFromFC.Data, sizeof(EE_Parameter)); |
||
535 | RequestConfigFromFC = 0; |
||
536 | } |
||
537 | HugeBlockFromFC.WhoAmI = 0; |
||
538 | } |
||
539 | |||
663 | holgerb | 540 | if(FCCalibActive) |
541 | { |
||
542 | count5sec = 0; |
||
543 | FreqNewGpsData = 50; |
||
544 | CountNewGpsDataIn5Sec = 25; |
||
545 | CountGpsProcessedIn5Sec = 0; |
||
546 | TimerCheckError = SetDelay(1000); |
||
547 | } |
||
548 | |||
489 | killagreg | 549 | // ---------------- Error Check Timing ---------------------------- |
550 | if(CheckDelay(TimerCheckError) || (FC.StatusFlags & FC_STATUS_START && !(oldFcFlags & FC_STATUS_START))) // Timer or FY wants to start |
||
551 | { |
||
552 | if(CheckDelay(TimerCheckError)) |
||
380 | holgerb | 553 | { |
727 | holgerb | 554 | if(!(FC.StatusFlags & FC_STATUS_FLY)) // do not change the Bit during flight |
555 | { |
||
556 | if(!BLITZ_CONNECTED) BlitzSchuhConnected = 1; |
||
557 | else BlitzSchuhConnected = 0; |
||
558 | } |
||
489 | killagreg | 559 | TimerCheckError = SetDelay(1000); |
560 | if(CompassValueErrorCount) CompassValueErrorCount--; |
||
561 | if(++count5sec == 5) |
||
562 | { |
||
663 | holgerb | 563 | FreqGpsNavProcessed = CountGpsProcessedIn5Sec * 2; //400 = 40Hz |
564 | FreqNewGpsData = CountNewGpsDataIn5Sec; // 50 = 5,0Hz |
||
565 | |||
453 | holgerb | 566 | count5sec = 0; |
489 | killagreg | 567 | CountGpsProcessedIn5Sec = 0; |
659 | holgerb | 568 | CountNewGpsDataIn5Sec = FreqNewGpsData / 2; |
663 | holgerb | 569 | ConfirmGpsUpdateRate(FreqNewGpsData); |
489 | killagreg | 570 | } |
380 | holgerb | 571 | } |
489 | killagreg | 572 | oldFcFlags = FC.StatusFlags; |
564 | holgerb | 573 | // if(CheckDelay(SPI0_Timeout) && (DebugUART == UART1)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected |
489 | killagreg | 574 | |
575 | if(!CheckDelay(SPI0_Timeout) || (DebugUART == UART1)) CheckErrors(); |
||
576 | |||
533 | holgerb | 577 | if(FC.StatusFlags & FC_STATUS_FLY) |
578 | { |
||
579 | NaviData.FlyingTime++; // we want to count the battery-time |
||
580 | TimeSinceMotorStart++; |
||
581 | } |
||
731 | holgerb | 582 | |
583 | if(EE_Parameter.Revision == 0) RequestConfigFromFC = 1; |
||
489 | killagreg | 584 | if(SerialLinkOkay) SerialLinkOkay--; |
594 | holgerb | 585 | if(SerialLinkOkay < 250 - 6) NCFlags |= NC_FLAG_NOSERIALLINK; // 6 seconds timeout for serial communication |
489 | killagreg | 586 | else NCFlags &= ~NC_FLAG_NOSERIALLINK; |
587 | if(StopNavigation && (Parameter.NaviGpsModeControl >= 50) && (Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) BeepTime = 1000; |
||
588 | } |
||
589 | running = 0; |
||
514 | holgerb | 590 | // if(!PollingTimeout) DebugOut.Analog[17]++; |
489 | killagreg | 591 | return(0); |
378 | holgerb | 592 | } |
593 | |||
380 | holgerb | 594 | // the handler will be cyclic called by the timer 1 ISR |
595 | // used is for critical timing parts that normaly would handled |
||
596 | // within the main loop that could block longer at logging activities |
||
483 | holgerb | 597 | void EXTIT3_IRQHandler(void) // 1ms - Takt |
154 | killagreg | 598 | { |
195 | killagreg | 599 | IENABLE; |
154 | killagreg | 600 | VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq |
489 | killagreg | 601 | |
516 | holgerb | 602 | if(PollingTimeout == 0) |
603 | { |
||
604 | PollingTimeout = 5; |
||
605 | //if(Polling() == 0) DebugOut.Analog[]++; |
||
606 | Polling(); |
||
380 | holgerb | 607 | } |
378 | holgerb | 608 | |
609 | VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit |
||
195 | killagreg | 610 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq |
611 | IDISABLE; |
||
378 | holgerb | 612 | VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register |
154 | killagreg | 613 | } |
614 | |||
41 | ingob | 615 | //---------------------------------------------------------------------------------------------------- |
616 | int main(void) |
||
617 | { |
||
489 | killagreg | 618 | |
619 | // static u32 ftimer =0; |
||
620 | // static u8 fstate = 0; |
||
456 | holgerb | 621 | // static File_t* f = NULL; |
489 | killagreg | 622 | |
623 | |||
41 | ingob | 624 | /* Configure the system clocks */ |
625 | SCU_Config(); |
||
626 | /* init VIC (Vectored Interrupt Controller) */ |
||
627 | SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC |
||
628 | SCU_AHBPeriphReset(__VIC, DISABLE); // disable reset state for VIC |
||
629 | VIC_DeInit(); // deinitializes the VIC module registers to their default reset values. |
||
196 | killagreg | 630 | VIC_InitDefaultVectors(); |
631 | |||
119 | killagreg | 632 | // initialize timer 1 for System Clock and delay rountines |
41 | ingob | 633 | TIMER1_Init(); |
634 | // initialize the LEDs (needs Timer 1) |
||
635 | Led_Init(); |
||
636 | // initialize the debug UART1 |
||
637 | UART1_Init(); |
||
110 | killagreg | 638 | UART1_PutString("\r\n---------------------------------------------"); |
120 | killagreg | 639 | // initialize timer 2 for servo outputs |
180 | killagreg | 640 | //TIMER2_Init(); |
41 | ingob | 641 | // initialize UART2 to FLIGHTCTRL |
642 | UART2_Init(); |
||
643 | // initialize UART0 (to MKGPS or MK3MAG) |
||
644 | UART0_Init(); |
||
134 | killagreg | 645 | // initialize adc |
646 | Analog_Init(); |
||
41 | ingob | 647 | // initialize SPI0 to FC |
648 | SPI0_Init(); |
||
469 | killagreg | 649 | // initialize i2c busses (needs Timer 1) |
727 | holgerb | 650 | InitCamCtrl(); |
489 | killagreg | 651 | I2CBus_Init(I2C0); |
652 | I2CBus_Init(I2C1); |
||
247 | killagreg | 653 | // initialize fat16 partition on sd card (needs Timer 1) |
41 | ingob | 654 | Fat16_Init(); |
156 | killagreg | 655 | // initialize NC params |
656 | NCParams_Init(); |
||
88 | killagreg | 657 | // initialize the settings |
658 | Settings_Init(); |
||
92 | killagreg | 659 | // initialize logging (needs settings) |
82 | killagreg | 660 | Logging_Init(); |
1 | ingob | 661 | |
699 | holgerb | 662 | //UART_VersionInfo.HWMajor = 30; |
362 | holgerb | 663 | LED_GRN_ON; |
41 | ingob | 664 | TimerCheckError = SetDelay(3000); |
175 | holgerb | 665 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
110 | killagreg | 666 | UART1_PutString("\n\r Version information:"); |
116 | killagreg | 667 | |
41 | ingob | 668 | GetNaviCtrlVersion(); |
338 | holgerb | 669 | DebugOut.StatusGreen = AMPEL_NC | AMPEL_COMPASS; // NC and MK3Mag |
670 | DebugOut.StatusRed = 0x00; |
||
400 | holgerb | 671 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
516 | holgerb | 672 | Compass_Init(); |
314 | killagreg | 673 | #ifdef FOLLOW_ME |
674 | TransmitAlsoToFC = 1; |
||
675 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
||
676 | UART1_PutString("\n\r FOLLOW-ME Transmitter only!"); |
||
677 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++\r\n\r\n"); |
||
678 | TransmitAlsoToFC = 0; |
||
679 | #else |
||
150 | killagreg | 680 | SPI0_GetFlightCtrlVersion(); |
681 | if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
||
41 | ingob | 682 | { |
461 | holgerb | 683 | UART1_PutString("\n\r Flight-Ctrl not compatible\n\r"); |
41 | ingob | 684 | LED_RED_ON; |
685 | } |
||
314 | killagreg | 686 | #endif |
706 | holgerb | 687 | if(IamMaster == SLAVE) UART1_PutString(" SLAVE\r\n"); |
688 | if(IamMaster == MASTER) UART1_PutString(" MASTER\r\n"); |
||
528 | holgerb | 689 | |
731 | holgerb | 690 | // +++++++++++++++++++++++++++++++++++++++ |
691 | // ++ check CamCtrl version (if connected) |
||
692 | if(Compass_I2CPort == NCMAG_PORT_INTERN) |
||
693 | { |
||
694 | if(I2CBus_LockBuffer(I2C0,3)) I2CBus_Transmission(I2C0, CAM_SLAVE_ADDRESS, &ToCamCtrl, 4, &CamCtrl_UpdateData, sizeof(FromCamCtrl)); |
||
695 | } |
||
696 | else CamCtrlTimeout = 0; // disable CamCtrl communication if external compass is connected |
||
697 | // +++++++++++++++++++++++++++++++++++++++ |
||
715 | holgerb | 698 | if(UBX_Setup() == 0) UBX_Setup(); // inits the GPS-Module via ubx -> try twice |
706 | holgerb | 699 | GPS_Init(); |
213 | killagreg | 700 | // ---------- Prepare the isr driven |
154 | killagreg | 701 | // set to absolute lowest priority |
516 | holgerb | 702 | VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW); |
195 | killagreg | 703 | // enable interrupts |
516 | holgerb | 704 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); |
244 | killagreg | 705 | |
250 | ingob | 706 | Debug_OK("START"); |
362 | holgerb | 707 | UART1_PutString("\r\n"); |
380 | holgerb | 708 | fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer |
709 | LED_GRN_ON; |
||
710 | LED_RED_OFF; |
||
530 | holgerb | 711 | Settings_GetParamValue(PID_SEND_NMEA,(u16 *) &NMEA_Interval); |
461 | holgerb | 712 | UART1_PutString("\r\n"); |
528 | holgerb | 713 | |
487 | holgerb | 714 | CompassValueErrorCount = 0; |
503 | holgerb | 715 | I2CBus(Compass_I2CPort)->Timeout = SetDelay(3000); |
688 | holgerb | 716 | |
717 | // Intilizes the Canbus |
||
719 | holgerb | 718 | if(UART_VersionInfo.HWMajor >= 30) |
719 | { |
||
720 | EXT2_Init(); // External Output EXT2 |
||
721 | CanbusInit(); |
||
722 | } |
||
731 | holgerb | 723 | if(FromCamCtrl.CamStatus) |
724 | { |
||
725 | u8 msg[30]; |
||
726 | sprintf(msg, " CamCtrl found V%i.%02i \r\n",1 + FromCamCtrl.Version / 100, FromCamCtrl.Version % 100); |
||
727 | UART1_PutString(msg); |
||
728 | } |
||
729 | else UART1_PutString(" No CamCtrl connected \r\n"); |
||
528 | holgerb | 730 | // ++++++++++++++++++++++++++++++++++++++++++++++ |
154 | killagreg | 731 | for (;;) // the endless main loop |
41 | ingob | 732 | { |
484 | holgerb | 733 | PollingTimeout = 5; |
431 | killagreg | 734 | Polling(); |
500 | holgerb | 735 | // ++++++++++++++++++++++++++++++++++++++++++++++ |
736 | if(FromFC_LoadWP_List) |
||
516 | holgerb | 737 | { |
738 | WPL_Store.Index = (FromFC_LoadWP_List & ~0x80); |
||
739 | if(WPL_Store.Index <= ToFC_MaxWpListIndex) |
||
740 | { |
||
513 | killagreg | 741 | if(PointList_ReadFromFile(&WPL_Store) == WPL_OK) |
742 | { |
||
743 | if(FromFC_LoadWP_List & 0x80)// -> load relative |
||
516 | holgerb | 744 | { |
540 | holgerb | 745 | u32 angle; |
746 | angle = (360 + GyroCompassCorrected/10 + Parameter.OrientationAngle * 15) % 360; |
||
513 | killagreg | 747 | if(NCFlags & NC_FLAG_FREE || NaviData.TargetPositionDeviation.Distance > 7*10) |
516 | holgerb | 748 | { // take actual position |
540 | holgerb | 749 | if(!PointList_Move(1,&(GPSData.Position),angle)) PointList_Clear(); // try to move wp-list so that 1st entry matches the current position |
516 | holgerb | 750 | } |
751 | else |
||
513 | killagreg | 752 | { // take last target position |
540 | holgerb | 753 | if(!PointList_Move(1, &(NaviData.TargetPosition),angle)) PointList_Clear(); // try to move wp-list so that 1st entry matches the current position |
513 | killagreg | 754 | } |
755 | } |
||
756 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
||
757 | GPS_pWaypoint = PointList_WPBegin(); // updates POI index |
||
519 | holgerb | 758 | SpeakWaypointRached = 1; // Speak once when the last Point is reached |
759 | SpeakNextWaypoint = 1; // Speak once as soon as the Points are active |
||
760 | NCFlags &= ~NC_FLAG_TARGET_REACHED; |
||
513 | killagreg | 761 | BeepTime = 150; |
762 | } |
||
763 | } |
||
764 | FromFC_LoadWP_List = 0; |
||
765 | } |
||
766 | // ++++++++++++++++++++++++++++++++++++++++++++++ |
||
767 | if(FromFC_Save_SinglePoint) |
||
768 | { |
||
769 | WPL_Store.Index = FromFC_Save_SinglePoint; |
||
516 | holgerb | 770 | if(WPL_Store.Index <= ToFC_MaxWpListIndex) if(PointList_SaveSinglePoint(&WPL_Store) == WPL_OK) BeepTime = 150; |
513 | killagreg | 771 | FromFC_Save_SinglePoint = 0; |
772 | } |
||
773 | // ++++++++++++++++++++++++++++++++++++++++++++++ |
||
774 | if(FromFC_Load_SinglePoint) |
||
775 | { |
||
516 | holgerb | 776 | WPL_Store.Index = FromFC_Load_SinglePoint; |
777 | if(WPL_Store.Index <= ToFC_MaxWpListIndex) |
||
778 | { |
||
513 | killagreg | 779 | if(PointList_LoadSinglePoint(&WPL_Store) == WPL_OK) |
502 | killagreg | 780 | { |
781 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
||
782 | GPS_pWaypoint = PointList_WPBegin(); // updates POI index |
||
519 | holgerb | 783 | SpeakWaypointRached = 1; // Speak once when the last Point is reached |
784 | SpeakNextWaypoint = 1; // Speak once as soon as the Points are active |
||
785 | NCFlags &= ~NC_FLAG_TARGET_REACHED; |
||
502 | killagreg | 786 | BeepTime = 150; |
787 | } |
||
516 | holgerb | 788 | } |
513 | killagreg | 789 | FromFC_Load_SinglePoint = 0; |
504 | holgerb | 790 | } |
500 | holgerb | 791 | // ++++++++++++++++++++++++++++++++++++++++++++++ |
431 | killagreg | 792 | // ---------------- Logging --------------------------------------- |
489 | killagreg | 793 | if(SD_WatchDog) |
431 | killagreg | 794 | { |
795 | SD_WatchDog = 30000; |
||
796 | if(SDCardInfo.Valid == 1) 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 |
||
516 | holgerb | 797 | else |
798 | { |
||
799 | ToFC_MaxWpListIndex = 0; |
||
800 | if(FC.StatusFlags & FC_STATUS_START) SD_LoggingError = 100; |
||
503 | holgerb | 801 | } |
431 | killagreg | 802 | if(!SD_WatchDog) UART1_PutString("\n\rSD-Watchdog - Logging aborted\n\r"); |
803 | } |
||
489 | killagreg | 804 | |
805 | /* |
||
324 | killagreg | 806 | if(CheckDelay(ftimer)) |
807 | { |
||
808 | |||
431 | killagreg | 809 | static s8 filename[35]; |
810 | static u8 i = 0; |
||
811 | s8 dbgmsg[40]; |
||
324 | killagreg | 812 | |
489 | killagreg | 813 | |
814 | |||
324 | killagreg | 815 | ftimer = SetDelay(100); |
816 | if(FC.Poti[3]>100 && fstate == 0) |
||
817 | { |
||
818 | fstate = 1; |
||
431 | killagreg | 819 | sprintf(filename, "/toast/toasta/toast%02i.txt",i++); |
324 | killagreg | 820 | } |
821 | else if(FC.Poti[3]<100 && fstate == 2) |
||
822 | { |
||
823 | fstate = 3; |
||
824 | } |
||
825 | |||
826 | switch(fstate) |
||
827 | { |
||
828 | case 1: |
||
431 | killagreg | 829 | sprintf(dbgmsg,"\r\nStart writing file: %s", filename); |
830 | Debug(dbgmsg); |
||
324 | killagreg | 831 | f = fopen_(filename, 'a'); |
832 | if(f== NULL) Fat16_Init(); |
||
833 | fstate = 2; |
||
834 | break; |
||
835 | |||
836 | case 2: |
||
837 | fputs_("\r\ntest edins sdv dsivbds iv dsivb disbv idsv bisd bv d suiv dsibsivbdis fbvisdöb visdbvisdb vidbfibds ibv", f); |
||
838 | break; |
||
489 | killagreg | 839 | |
324 | killagreg | 840 | case 3: |
431 | killagreg | 841 | sprintf(dbgmsg,"\r\nClosing file: %s", filename); |
842 | Debug(dbgmsg); |
||
324 | killagreg | 843 | fclose_(f); |
844 | fstate = 0; |
||
845 | break; |
||
846 | |||
847 | default: |
||
848 | break; |
||
849 | } |
||
850 | } |
||
594 | holgerb | 851 | */ |
24 | StephanB | 852 | } |
1 | ingob | 853 | } |
516 | holgerb | 854 | //DebugOut.Analog[] |