Rev 473 | Rev 482 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 473 | Rev 480 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | // + Software Nutzungsbedingungen (english version: see below) |
7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
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 |
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 |
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. |
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. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
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. |
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 |
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. |
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 |
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. |
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 |
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 |
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. |
22 | // + des Mitverschuldens offen. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
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. |
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. |
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 |
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. |
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. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
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. |
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. |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Software LICENSING TERMS |
32 | // + Software LICENSING TERMS |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
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 |
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*. |
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. |
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 |
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 |
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. |
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 |
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. |
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 |
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 |
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 |
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 |
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. |
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 |
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. |
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 |
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. |
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. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
53 | // + #### END OF LICENSING TERMS #### |
53 | // + #### END OF LICENSING TERMS #### |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | //#define MCLK96MHZ |
56 | //#define MCLK96MHZ |
57 | const unsigned long _Main_Crystal = 25000; |
57 | const unsigned long _Main_Crystal = 25000; |
58 | #include <stdio.h> |
58 | #include <stdio.h> |
59 | #include "91x_lib.h" |
59 | #include "91x_lib.h" |
60 | #include "led.h" |
60 | #include "led.h" |
61 | #include "uart0.h" |
61 | #include "uart0.h" |
62 | #include "uart1.h" |
62 | #include "uart1.h" |
63 | #include "uart2.h" |
63 | #include "uart2.h" |
64 | #include "gps.h" |
64 | #include "gps.h" |
65 | #include "i2c0.h" |
65 | #include "i2c0.h" |
66 | #include "i2c1.h" |
66 | #include "i2c1.h" |
67 | #include "compass.h" |
67 | #include "compass.h" |
68 | #include "ncmag.h" |
68 | #include "ncmag.h" |
69 | #include "timer1.h" |
69 | #include "timer1.h" |
70 | #include "timer2.h" |
70 | #include "timer2.h" |
71 | #include "analog.h" |
71 | #include "analog.h" |
72 | #include "spi_slave.h" |
72 | #include "spi_slave.h" |
73 | #include "fat16.h" |
73 | #include "fat16.h" |
74 | #include "sdc.h" |
74 | #include "sdc.h" |
75 | #include "logging.h" |
75 | #include "logging.h" |
76 | #include "params.h" |
76 | #include "params.h" |
77 | #include "settings.h" |
77 | #include "settings.h" |
78 | #include "config.h" |
78 | #include "config.h" |
79 | #include "main.h" |
79 | #include "main.h" |
80 | #include "debug.h" |
80 | #include "debug.h" |
81 | #include "eeprom.h" |
81 | #include "eeprom.h" |
82 | #include "ssc.h" |
82 | #include "ssc.h" |
83 | #include "sdc.h" |
83 | #include "sdc.h" |
84 | #include "uart1.h" |
84 | #include "uart1.h" |
85 | #include "ncmag.h" |
85 | #include "ncmag.h" |
86 | 86 | ||
87 | 87 | ||
88 | #ifdef FOLLOW_ME |
88 | #ifdef FOLLOW_ME |
89 | u8 TransmitAlsoToFC = 0; |
89 | u8 TransmitAlsoToFC = 0; |
90 | #endif |
90 | #endif |
91 | u32 TimerCheckError; |
91 | u32 TimerCheckError; |
92 | u8 ErrorCode = 0; |
92 | u8 ErrorCode = 0; |
93 | u16 BeepTime; |
93 | u16 BeepTime; |
94 | u8 NCFlags = 0; |
94 | u8 NCFlags = 0; |
95 | s16 GeoMagDec = 0; // local magnetic declination in 0.1 deg |
95 | s16 GeoMagDec = 0; // local magnetic declination in 0.1 deg |
96 | u8 ErrorGpsFixLost = 0; |
96 | u8 ErrorGpsFixLost = 0; |
97 | 97 | ||
98 | u8 ClearFCStatusFlags = 0; |
98 | u8 ClearFCStatusFlags = 0; |
99 | u8 StopNavigation = 0; |
99 | u8 StopNavigation = 0; |
100 | volatile u32 PollingTimeout = 10000; |
100 | volatile u32 PollingTimeout = 10000; |
101 | Param_t Parameter; |
101 | Param_t Parameter; |
102 | volatile FC_t FC; |
102 | volatile FC_t FC; |
103 | volatile u32 SPIWatchDog = 15000; // stop Navigation if this goes to zero |
103 | volatile u32 SPIWatchDog = 15000; // stop Navigation if this goes to zero |
104 | volatile u32 SD_WatchDog = 15000; // stop Logging if this goes to zero |
104 | volatile u32 SD_WatchDog = 15000; // stop Logging if this goes to zero |
105 | u32 CountGpsProcessedIn5Sec = 0,CountNewGpsDataIn5Sec = 0, FreqGpsProcessedIn5Sec = 0, FreqNewGpsDataIn5Sec = 0; |
105 | u32 CountGpsProcessedIn5Sec = 0,CountNewGpsDataIn5Sec = 0, FreqGpsProcessedIn5Sec = 0, FreqNewGpsDataIn5Sec = 0; |
106 | 106 | ||
107 | s8 ErrorMSG[25]; |
107 | s8 ErrorMSG[25]; |
108 | 108 | ||
109 | //---------------------------------------------------------------------------------------------------- |
109 | //---------------------------------------------------------------------------------------------------- |
110 | void SCU_Config(void) |
110 | void SCU_Config(void) |
111 | { |
111 | { |
112 | /* configure PLL and set it as master clock source */ |
112 | /* configure PLL and set it as master clock source */ |
113 | SCU_MCLKSourceConfig(SCU_MCLK_OSC); // set master clock source to external oscillator clock (25MHz) before diabling the PLL |
113 | SCU_MCLKSourceConfig(SCU_MCLK_OSC); // set master clock source to external oscillator clock (25MHz) before diabling the PLL |
114 | SCU_PLLCmd(DISABLE); // now disable the PLL |
114 | SCU_PLLCmd(DISABLE); // now disable the PLL |
115 | #ifdef MCLK96MHZ |
115 | #ifdef MCLK96MHZ |
116 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div2); // set BRCLK to MCLK/2 = 48MHz |
116 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div2); // set BRCLK to MCLK/2 = 48MHz |
117 | SCU_PCLKDivisorConfig(SCU_PCLK_Div4); // set PCLK (APB bus clock) divisor to 4 (half Reference Clock) |
117 | SCU_PCLKDivisorConfig(SCU_PCLK_Div4); // set PCLK (APB bus clock) divisor to 4 (half Reference Clock) |
118 | SCU_RCLKDivisorConfig(SCU_RCLK_Div2); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
118 | SCU_RCLKDivisorConfig(SCU_RCLK_Div2); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
119 | SCU_HCLKDivisorConfig(SCU_HCLK_Div2); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
119 | SCU_HCLKDivisorConfig(SCU_HCLK_Div2); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
120 | SCU_PLLFactorsConfig(192,25,2); // PLL = 96 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=2 |
120 | SCU_PLLFactorsConfig(192,25,2); // PLL = 96 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=2 |
121 | #else |
121 | #else |
122 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div1); // set BRCLK to MCLK = 48MHz |
122 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div1); // set BRCLK to MCLK = 48MHz |
123 | SCU_PCLKDivisorConfig(SCU_PCLK_Div2); // set PCLK (APB bus clock) divisor to 2 (half Reference Clock) |
123 | SCU_PCLKDivisorConfig(SCU_PCLK_Div2); // set PCLK (APB bus clock) divisor to 2 (half Reference Clock) |
124 | SCU_RCLKDivisorConfig(SCU_RCLK_Div1); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
124 | SCU_RCLKDivisorConfig(SCU_RCLK_Div1); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
125 | SCU_HCLKDivisorConfig(SCU_HCLK_Div1); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
125 | SCU_HCLKDivisorConfig(SCU_HCLK_Div1); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
126 | SCU_PLLFactorsConfig(192,25,3); // PLL = 48 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=3 |
126 | SCU_PLLFactorsConfig(192,25,3); // PLL = 48 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=3 |
127 | #endif |
127 | #endif |
128 | SCU_PLLCmd(ENABLE); // Enable PLL (is disabled by SCU_PLLFactorsConfig) |
128 | SCU_PLLCmd(ENABLE); // Enable PLL (is disabled by SCU_PLLFactorsConfig) |
129 | SCU_MCLKSourceConfig(SCU_MCLK_PLL); // set master clock source to PLL |
129 | SCU_MCLKSourceConfig(SCU_MCLK_PLL); // set master clock source to PLL |
130 | } |
130 | } |
131 | 131 | ||
132 | //---------------------------------------------------------------------------------------------------- |
132 | //---------------------------------------------------------------------------------------------------- |
133 | void GetNaviCtrlVersion(void) |
133 | void GetNaviCtrlVersion(void) |
134 | { |
134 | { |
135 | u8 msg[25]; |
135 | u8 msg[25]; |
136 | 136 | ||
137 | sprintf(msg,"\n\r NaviCtrl HW: V%d.%d SW: V%d.%02d%c", Version_HW/10, Version_HW%10, VERSION_MAJOR, VERSION_MINOR, 'a'+ VERSION_PATCH); |
137 | sprintf(msg,"\n\r NaviCtrl HW: V%d.%d SW: V%d.%02d%c", Version_HW/10, Version_HW%10, VERSION_MAJOR, VERSION_MINOR, 'a'+ VERSION_PATCH); |
138 | UART1_PutString(msg); |
138 | UART1_PutString(msg); |
139 | } |
139 | } |
140 | 140 | ||
141 | //---------------------------------------------------------------------------------------------------- |
141 | //---------------------------------------------------------------------------------------------------- |
142 | 142 | ||
143 | void CheckErrors(void) |
143 | void CheckErrors(void) |
144 | { |
144 | { |
145 | static s32 no_error_delay = 0; |
145 | static s32 no_error_delay = 0; |
146 | s32 newErrorCode = 0; |
146 | s32 newErrorCode = 0; |
147 | UART_VersionInfo.HardwareError[0] = 0; |
147 | UART_VersionInfo.HardwareError[0] = 0; |
148 | 148 | ||
149 | if((I2C_CompassPort == I2C_INTERN_1 && CheckDelay(I2C1_Timeout)) || (I2C_CompassPort == I2C_EXTERN_0 && CheckDelay(I2C0_Timeout)) || (Compass_Heading < 0)) |
149 | if((I2C_CompassPort == I2C_INTERN_1 && CheckDelay(I2C1_Timeout)) || (I2C_CompassPort == I2C_EXTERN_0 && CheckDelay(I2C0_Timeout)) || (Compass_Heading < 0)) |
150 | 150 | ||
151 | DebugOut.StatusRed |= AMPEL_COMPASS; |
151 | DebugOut.StatusRed |= AMPEL_COMPASS; |
152 | else DebugOut.StatusRed &= ~AMPEL_COMPASS; // MK3Mag green status |
152 | else DebugOut.StatusRed &= ~AMPEL_COMPASS; // MK3Mag green status |
153 | 153 | ||
154 | if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.StatusRed |= AMPEL_BL; |
154 | if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.StatusRed |= AMPEL_BL; |
155 | else DebugOut.StatusRed &= ~AMPEL_BL; // BL-Ctrl green status |
155 | else DebugOut.StatusRed &= ~AMPEL_BL; // BL-Ctrl green status |
156 | 156 | ||
157 | if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.StatusRed |= AMPEL_NC; |
157 | if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.StatusRed |= AMPEL_NC; |
158 | else DebugOut.StatusRed &= ~AMPEL_NC; |
158 | else DebugOut.StatusRed &= ~AMPEL_NC; |
- | 159 | ||
- | 160 | if(I2C_CompassPort == I2C_EXTERN_0) LED_RED_OFF_T; |
|
159 | 161 | ||
160 | if((FCCalibActive || CompassCalState) && FC_Version.Hardware) |
162 | if((FCCalibActive || CompassCalState) && FC_Version.Hardware) |
161 | { |
163 | { |
162 | sprintf(ErrorMSG,"Calibrate... "); |
164 | sprintf(ErrorMSG,"Calibrate... "); |
163 | newErrorCode = 0; |
165 | newErrorCode = 0; |
164 | ErrorCode = 0; |
166 | ErrorCode = 0; |
165 | no_error_delay = 1; |
167 | no_error_delay = 1; |
166 | } |
168 | } |
167 | else if(CheckDelay(I2C1_Timeout) && (I2C_CompassPort == I2C_INTERN_1)) |
169 | else if(CheckDelay(I2C1_Timeout) && (I2C_CompassPort == I2C_INTERN_1)) |
168 | { |
170 | { |
169 | LED_RED_ON; |
171 | LED_RED_ON; |
170 | sprintf(ErrorMSG,"no compass communica"); |
172 | sprintf(ErrorMSG,"no compass communica"); |
171 | //Reset I2CBus |
173 | //Reset I2CBus |
172 | I2C1_Deinit(); |
174 | I2C1_Deinit(); |
173 | I2C1_Init(); |
175 | I2C1_Init(); |
174 | newErrorCode = 4; |
176 | newErrorCode = 4; |
175 | StopNavigation = 1; |
177 | StopNavigation = 1; |
176 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
178 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
177 | DebugOut.StatusRed |= AMPEL_COMPASS; |
179 | DebugOut.StatusRed |= AMPEL_COMPASS; |
178 | } |
180 | } |
179 | else if(CheckDelay(I2C0_Timeout) && (I2C_CompassPort == I2C_EXTERN_0)) |
181 | else if(CheckDelay(I2C0_Timeout) && (I2C_CompassPort == I2C_EXTERN_0)) |
180 | { |
182 | { |
181 | LED_RED_ON; |
183 | LED_RED_ON; |
- | 184 | LED_RED_ON_T; |
|
182 | sprintf(ErrorMSG,"no ext. compass "); |
185 | sprintf(ErrorMSG,"no ext. compass "); |
183 | //Reset I2CBus |
186 | //Reset I2CBus |
184 | I2C0_Deinit(); |
187 | I2C0_Deinit(); |
185 | I2C0_Init(); |
188 | I2C0_Init(); |
- | 189 | NCMAG_Update(1); |
|
186 | newErrorCode = 4; |
190 | newErrorCode = 33; |
187 | StopNavigation = 1; |
191 | StopNavigation = 1; |
188 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
192 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
189 | DebugOut.StatusRed |= AMPEL_COMPASS; |
193 | DebugOut.StatusRed |= AMPEL_COMPASS; |
190 | } |
194 | } |
191 | else |
195 | else |
192 | if(CheckDelay(SPI0_Timeout)) |
196 | if(CheckDelay(SPI0_Timeout)) |
193 | { |
197 | { |
194 | LED_RED_ON; |
198 | LED_RED_ON; |
195 | sprintf(ErrorMSG,"no FC communication "); |
199 | sprintf(ErrorMSG,"no FC communication "); |
196 | newErrorCode = 3; |
200 | newErrorCode = 3; |
197 | StopNavigation = 1; |
201 | StopNavigation = 1; |
198 | DebugOut.StatusGreen &= ~AMPEL_FC; // status of FC Present |
202 | DebugOut.StatusGreen &= ~AMPEL_FC; // status of FC Present |
199 | DebugOut.StatusGreen &= ~AMPEL_BL; // status of BL Present |
203 | DebugOut.StatusGreen &= ~AMPEL_BL; // status of BL Present |
200 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_SPI_RX; |
204 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_SPI_RX; |
201 | } |
205 | } |
202 | else if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
206 | else if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
203 | { |
207 | { |
204 | LED_RED_ON; |
208 | LED_RED_ON; |
205 | #ifndef FOLLOW_ME |
209 | #ifndef FOLLOW_ME |
206 | sprintf(ErrorMSG,"FC not compatible "); |
210 | sprintf(ErrorMSG,"FC not compatible "); |
207 | #else |
211 | #else |
208 | sprintf(ErrorMSG,"! FollowMe only ! "); |
212 | sprintf(ErrorMSG,"! FollowMe only ! "); |
209 | #endif |
213 | #endif |
210 | newErrorCode = 1; |
214 | newErrorCode = 1; |
211 | StopNavigation = 1; |
215 | StopNavigation = 1; |
212 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE; |
216 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE; |
213 | DebugOut.StatusRed |= AMPEL_NC; |
217 | DebugOut.StatusRed |= AMPEL_NC; |
214 | } |
218 | } |
215 | 219 | ||
216 | else if(FC.Error[0] & FC_ERROR0_GYRO_NICK) |
220 | else if(FC.Error[0] & FC_ERROR0_GYRO_NICK) |
217 | { |
221 | { |
218 | LED_RED_ON; |
222 | LED_RED_ON; |
219 | sprintf(ErrorMSG,"ERR: FC Nick Gyro"); |
223 | sprintf(ErrorMSG,"ERR: FC Nick Gyro"); |
220 | newErrorCode = 10; |
224 | newErrorCode = 10; |
221 | } |
225 | } |
222 | else if(FC.Error[0] & FC_ERROR0_GYRO_ROLL) |
226 | else if(FC.Error[0] & FC_ERROR0_GYRO_ROLL) |
223 | { |
227 | { |
224 | LED_RED_ON; |
228 | LED_RED_ON; |
225 | sprintf(ErrorMSG,"ERR: FC Roll Gyro"); |
229 | sprintf(ErrorMSG,"ERR: FC Roll Gyro"); |
226 | newErrorCode = 11; |
230 | newErrorCode = 11; |
227 | } |
231 | } |
228 | else if(FC.Error[0] & FC_ERROR0_GYRO_YAW) |
232 | else if(FC.Error[0] & FC_ERROR0_GYRO_YAW) |
229 | { |
233 | { |
230 | LED_RED_ON; |
234 | LED_RED_ON; |
231 | sprintf(ErrorMSG,"ERR: FC Yaw Gyro"); |
235 | sprintf(ErrorMSG,"ERR: FC Yaw Gyro"); |
232 | newErrorCode = 12; |
236 | newErrorCode = 12; |
233 | } |
237 | } |
234 | else if(FC.Error[0] & FC_ERROR0_ACC_NICK) |
238 | else if(FC.Error[0] & FC_ERROR0_ACC_NICK) |
235 | { |
239 | { |
236 | LED_RED_ON; |
240 | LED_RED_ON; |
237 | sprintf(ErrorMSG,"ERR: FC Nick ACC"); |
241 | sprintf(ErrorMSG,"ERR: FC Nick ACC"); |
238 | newErrorCode = 13; |
242 | newErrorCode = 13; |
239 | } |
243 | } |
240 | else if(FC.Error[0] & FC_ERROR0_ACC_ROLL) |
244 | else if(FC.Error[0] & FC_ERROR0_ACC_ROLL) |
241 | { |
245 | { |
242 | LED_RED_ON; |
246 | LED_RED_ON; |
243 | sprintf(ErrorMSG,"ERR: FC Roll ACC"); |
247 | sprintf(ErrorMSG,"ERR: FC Roll ACC"); |
244 | newErrorCode = 14; |
248 | newErrorCode = 14; |
245 | } |
249 | } |
246 | else if(FC.Error[0] & FC_ERROR0_ACC_TOP) |
250 | else if(FC.Error[0] & FC_ERROR0_ACC_TOP) |
247 | { |
251 | { |
248 | LED_RED_ON; |
252 | LED_RED_ON; |
249 | sprintf(ErrorMSG,"ERR:FC Z-ACC"); |
253 | sprintf(ErrorMSG,"ERR:FC Z-ACC"); |
250 | newErrorCode = 15; |
254 | newErrorCode = 15; |
251 | } |
255 | } |
252 | else if(NC_To_FC_Flags & NC_TO_FC_FLYING_RANGE) |
256 | else if(NC_To_FC_Flags & NC_TO_FC_FLYING_RANGE) |
253 | { |
257 | { |
254 | LED_RED_ON; |
258 | LED_RED_ON; |
255 | sprintf(ErrorMSG,"ERR:Flying range!"); |
259 | sprintf(ErrorMSG,"ERR:Flying range!"); |
256 | newErrorCode = 28; |
260 | newErrorCode = 28; |
257 | } |
261 | } |
258 | else if(FC.Error[0] & FC_ERROR0_PRESSURE) |
262 | else if(FC.Error[0] & FC_ERROR0_PRESSURE) |
259 | { |
263 | { |
260 | LED_RED_ON; |
264 | LED_RED_ON; |
261 | sprintf(ErrorMSG,"ERR:Pressure sensor"); |
265 | sprintf(ErrorMSG,"ERR:Pressure sensor"); |
262 | newErrorCode = 16; |
266 | newErrorCode = 16; |
263 | } |
267 | } |
264 | else if(FC.Error[1] & FC_ERROR1_I2C) |
268 | else if(FC.Error[1] & FC_ERROR1_I2C) |
265 | { |
269 | { |
266 | LED_RED_ON; |
270 | LED_RED_ON; |
267 | sprintf(ErrorMSG,"ERR:I2C FC to BL"); |
271 | sprintf(ErrorMSG,"ERR:I2C FC to BL"); |
268 | newErrorCode = 17; |
272 | newErrorCode = 17; |
269 | } |
273 | } |
270 | else if(FC.Error[1] & FC_ERROR1_BL_MISSING) |
274 | else if(FC.Error[1] & FC_ERROR1_BL_MISSING) |
271 | { |
275 | { |
272 | LED_RED_ON; |
276 | LED_RED_ON; |
273 | sprintf(ErrorMSG,"ERR: Bl Missing"); |
277 | sprintf(ErrorMSG,"ERR: Bl Missing"); |
274 | newErrorCode = 18; |
278 | newErrorCode = 18; |
275 | } |
279 | } |
276 | else if(FC.Error[1] & FC_ERROR1_MIXER) |
280 | else if(FC.Error[1] & FC_ERROR1_MIXER) |
277 | { |
281 | { |
278 | LED_RED_ON; |
282 | LED_RED_ON; |
279 | sprintf(ErrorMSG,"Mixer Error"); |
283 | sprintf(ErrorMSG,"Mixer Error"); |
280 | newErrorCode = 19; |
284 | newErrorCode = 19; |
281 | } |
285 | } |
282 | else if(CheckDelay(UBX_Timeout) && Parameter.GlobalConfig & FC_CFG_GPS_AKTIV) |
286 | else if(CheckDelay(UBX_Timeout) && Parameter.GlobalConfig & FC_CFG_GPS_AKTIV) |
283 | { |
287 | { |
284 | LED_RED_ON; |
288 | LED_RED_ON; |
285 | // if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected "); |
289 | // if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected "); |
286 | // else |
290 | // else |
287 | { |
291 | { |
288 | sprintf(ErrorMSG,"no GPS communication"); |
292 | sprintf(ErrorMSG,"no GPS communication"); |
289 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX; |
293 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX; |
290 | UART_VersionInfo.Flags &= ~NC_VERSION_FLAG_GPS_PRESENT; |
294 | UART_VersionInfo.Flags &= ~NC_VERSION_FLAG_GPS_PRESENT; |
291 | newErrorCode = 5; |
295 | newErrorCode = 5; |
292 | } |
296 | } |
293 | StopNavigation = 1; |
297 | StopNavigation = 1; |
294 | // UBX_Timeout = SetDelay(500); |
298 | // UBX_Timeout = SetDelay(500); |
295 | } |
299 | } |
296 | else if(Compass_Heading < 0 && NCMAG_Present && !NCMAG_IsCalibrated) |
300 | else if(Compass_Heading < 0 && NCMAG_Present && !NCMAG_IsCalibrated) |
297 | { |
301 | { |
298 | LED_RED_ON; |
302 | LED_RED_ON; |
299 | sprintf(ErrorMSG,"compass not calibr."); |
303 | sprintf(ErrorMSG,"compass not calibr."); |
300 | newErrorCode = 31; |
304 | newErrorCode = 31; |
301 | StopNavigation = 1; |
305 | StopNavigation = 1; |
302 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
306 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
303 | } |
307 | } |
304 | else if(Compass_Heading < 0) |
308 | else if(Compass_Heading < 0) |
305 | { |
309 | { |
306 | LED_RED_ON; |
310 | LED_RED_ON; |
307 | sprintf(ErrorMSG,"bad compass value "); |
311 | sprintf(ErrorMSG,"bad compass value "); |
308 | newErrorCode = 6; |
312 | newErrorCode = 6; |
309 | StopNavigation = 1; |
313 | StopNavigation = 1; |
310 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
314 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
311 | } |
315 | } |
312 | else if((FC.Error[1] & FC_ERROR1_SPI_RX)) |
316 | else if((FC.Error[1] & FC_ERROR1_SPI_RX)) |
313 | { |
317 | { |
314 | LED_RED_ON; |
318 | LED_RED_ON; |
315 | sprintf(ErrorMSG,"FC spi rx error "); |
319 | sprintf(ErrorMSG,"FC spi rx error "); |
316 | newErrorCode = 8; |
320 | newErrorCode = 8; |
317 | StopNavigation = 1; |
321 | StopNavigation = 1; |
318 | } |
322 | } |
319 | else if(FC.Error[0] & FC_ERROR0_CAREFREE) |
323 | else if(FC.Error[0] & FC_ERROR0_CAREFREE) |
320 | { |
324 | { |
321 | LED_RED_ON; |
325 | LED_RED_ON; |
322 | sprintf(ErrorMSG,"FC: Carefree Error"); |
326 | sprintf(ErrorMSG,"FC: Carefree Error"); |
323 | newErrorCode = 20; |
327 | newErrorCode = 20; |
324 | } |
328 | } |
325 | else if(FC.Error[1] & FC_ERROR1_PPM) |
329 | else if(FC.Error[1] & FC_ERROR1_PPM) |
326 | { |
330 | { |
327 | LED_RED_ON; |
331 | LED_RED_ON; |
328 | sprintf(ErrorMSG,"RC Signal lost "); |
332 | sprintf(ErrorMSG,"RC Signal lost "); |
329 | newErrorCode = 7; |
333 | newErrorCode = 7; |
330 | } |
334 | } |
331 | else if(ErrorGpsFixLost) |
335 | else if(ErrorGpsFixLost) |
332 | { |
336 | { |
333 | LED_RED_ON; |
337 | LED_RED_ON; |
334 | sprintf(ErrorMSG,"GPS Fix lost "); |
338 | sprintf(ErrorMSG,"GPS Fix lost "); |
335 | newErrorCode = 21; |
339 | newErrorCode = 21; |
336 | } |
340 | } |
337 | else if(ErrorDisturbedEarthMagnetField) |
341 | else if(ErrorDisturbedEarthMagnetField) |
338 | { |
342 | { |
339 | LED_RED_ON; |
343 | LED_RED_ON; |
340 | sprintf(ErrorMSG,"Magnet error "); |
344 | sprintf(ErrorMSG,"Magnet error "); |
341 | newErrorCode = 22; |
345 | newErrorCode = 22; |
342 | DebugOut.StatusRed |= AMPEL_COMPASS | AMPEL_NC; |
346 | DebugOut.StatusRed |= AMPEL_COMPASS | AMPEL_NC; |
343 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
347 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
344 | } |
348 | } |
345 | else if(((BL_MinOfMaxPWM == 40 && (FC.StatusFlags & FC_STATUS_FLY)) || BL_MinOfMaxPWM == 39) && !ErrorCode) |
349 | else if(((BL_MinOfMaxPWM == 40 && (FC.StatusFlags & FC_STATUS_FLY)) || BL_MinOfMaxPWM == 39) && !ErrorCode) |
346 | { |
350 | { |
347 | LED_RED_ON; |
351 | LED_RED_ON; |
348 | sprintf(ErrorMSG,"ERR:Motor restart "); |
352 | sprintf(ErrorMSG,"ERR:Motor restart "); |
349 | newErrorCode = 23; |
353 | newErrorCode = 23; |
350 | DebugOut.StatusRed |= AMPEL_BL; |
354 | DebugOut.StatusRed |= AMPEL_BL; |
351 | } |
355 | } |
352 | else if(BL_MinOfMaxPWM < 30 && !ErrorCode) |
356 | else if(BL_MinOfMaxPWM < 30 && !ErrorCode) |
353 | { |
357 | { |
354 | unsigned int i; |
358 | unsigned int i; |
355 | for(i = 0; i < 12; i++) if(Motor[i].MaxPWM == BL_MinOfMaxPWM) break; |
359 | for(i = 0; i < 12; i++) if(Motor[i].MaxPWM == BL_MinOfMaxPWM) break; |
356 | 360 | ||
357 | LED_RED_ON; |
361 | LED_RED_ON; |
358 | sprintf(ErrorMSG,"ERR:BL%2d Test:%2d ",i+1,BL_MinOfMaxPWM); |
362 | sprintf(ErrorMSG,"ERR:BL%2d Test:%2d ",i+1,BL_MinOfMaxPWM); |
359 | newErrorCode = 32; |
363 | newErrorCode = 32; |
360 | DebugOut.StatusRed |= AMPEL_BL; |
364 | DebugOut.StatusRed |= AMPEL_BL; |
361 | } |
365 | } |
362 | else if(BL_MinOfMaxPWM < 248 && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
366 | else if(BL_MinOfMaxPWM < 248 && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
363 | { |
367 | { |
364 | LED_RED_ON; |
368 | LED_RED_ON; |
365 | sprintf(ErrorMSG,"ERR:BL Limitation "); |
369 | sprintf(ErrorMSG,"ERR:BL Limitation "); |
366 | newErrorCode = 24; |
370 | newErrorCode = 24; |
367 | DebugOut.StatusRed |= AMPEL_BL; |
371 | DebugOut.StatusRed |= AMPEL_BL; |
368 | } |
372 | } |
369 | else if(NCFlags & NC_FLAG_RANGE_LIMIT && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
373 | else if(NCFlags & NC_FLAG_RANGE_LIMIT && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
370 | { |
374 | { |
371 | LED_RED_ON; |
375 | LED_RED_ON; |
372 | sprintf(ErrorMSG,"ERR:GPS range "); |
376 | sprintf(ErrorMSG,"ERR:GPS range "); |
373 | newErrorCode = 25; |
377 | newErrorCode = 25; |
374 | DebugOut.StatusRed |= AMPEL_NC; |
378 | DebugOut.StatusRed |= AMPEL_NC; |
375 | } |
379 | } |
376 | else if((!SD_SWITCH || (SDCardInfo.Valid == 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START && !(FC.StatusFlags & FC_STATUS_FLY)) |
380 | else if((!SD_SWITCH || (SDCardInfo.Valid == 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START && !(FC.StatusFlags & FC_STATUS_FLY)) |
377 | { |
381 | { |
378 | LED_RED_ON; |
382 | LED_RED_ON; |
379 | sprintf(ErrorMSG,"ERR:No SD-Card "); |
383 | sprintf(ErrorMSG,"ERR:No SD-Card "); |
380 | newErrorCode = 26; |
384 | newErrorCode = 26; |
381 | DebugOut.StatusRed |= AMPEL_NC; |
385 | DebugOut.StatusRed |= AMPEL_NC; |
382 | } |
386 | } |
383 | else if((SD_LoggingError || (SD_WatchDog < 2000 && SD_WatchDog != 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START) |
387 | else if((SD_LoggingError || (SD_WatchDog < 2000 && SD_WatchDog != 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START) |
384 | { |
388 | { |
385 | LED_RED_ON; |
389 | LED_RED_ON; |
386 | sprintf(ErrorMSG,"ERR:SD Logging abort"); |
390 | sprintf(ErrorMSG,"ERR:SD Logging abort"); |
387 | newErrorCode = 27; |
391 | newErrorCode = 27; |
388 | DebugOut.StatusRed |= AMPEL_NC; |
392 | DebugOut.StatusRed |= AMPEL_NC; |
389 | SD_LoggingError = 0; |
393 | SD_LoggingError = 0; |
390 | } |
394 | } |
391 | else if(((AbsoluteFlyingAltitude) && (NaviData.Altimeter / 20 >= AbsoluteFlyingAltitude)) && (FC.StatusFlags & FC_STATUS_FLY)) |
395 | else if(((AbsoluteFlyingAltitude) && (NaviData.Altimeter / 20 >= AbsoluteFlyingAltitude)) && (FC.StatusFlags & FC_STATUS_FLY)) |
392 | { |
396 | { |
393 | LED_RED_ON; |
397 | LED_RED_ON; |
394 | sprintf(ErrorMSG,"ERR:Max Altitude "); |
398 | sprintf(ErrorMSG,"ERR:Max Altitude "); |
395 | newErrorCode = 29; |
399 | newErrorCode = 29; |
396 | DebugOut.StatusRed |= AMPEL_NC; |
400 | DebugOut.StatusRed |= AMPEL_NC; |
397 | } |
401 | } |
398 | 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))) |
402 | 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))) |
399 | { |
403 | { |
400 | LED_RED_ON; |
404 | LED_RED_ON; |
401 | sprintf(ErrorMSG,"No GPS Fix "); |
405 | sprintf(ErrorMSG,"No GPS Fix "); |
402 | newErrorCode = 30; |
406 | newErrorCode = 30; |
403 | } |
407 | } |
404 | else // no error occured |
408 | else // no error occured |
405 | { |
409 | { |
406 | StopNavigation = 0; |
410 | StopNavigation = 0; |
407 | LED_RED_OFF; |
411 | LED_RED_OFF; |
408 | if(no_error_delay) { no_error_delay--; } |
412 | if(no_error_delay) { no_error_delay--; } |
409 | else |
413 | else |
410 | { |
414 | { |
411 | sprintf(ErrorMSG,"No Error "); |
415 | sprintf(ErrorMSG,"No Error "); |
412 | ErrorCode = 0; |
416 | ErrorCode = 0; |
413 | } |
417 | } |
414 | } |
418 | } |
415 | 419 | ||
416 | if(newErrorCode) |
420 | if(newErrorCode) |
417 | { |
421 | { |
418 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) no_error_delay = 8; // delay the errors if the motors are running |
422 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) no_error_delay = 8; // delay the errors if the motors are running |
419 | ErrorCode = newErrorCode; |
423 | ErrorCode = newErrorCode; |
420 | } |
424 | } |
421 | FC.Error[0] = 0; |
425 | FC.Error[0] = 0; |
422 | FC.Error[1] = 0; |
426 | FC.Error[1] = 0; |
423 | FC.Error[2] = 0; |
427 | FC.Error[2] = 0; |
424 | FC.Error[3] = 0; |
428 | FC.Error[3] = 0; |
425 | FC.Error[4] = 0; |
429 | FC.Error[4] = 0; |
426 | ErrorGpsFixLost = 0; |
430 | ErrorGpsFixLost = 0; |
427 | } |
431 | } |
428 | 432 | ||
429 | 433 | ||
430 | 434 | ||
431 | void Polling(void) |
435 | void Polling(void) |
432 | { |
436 | { |
433 | static u8 running = 0, oldFcFlags = 0, count5sec; |
437 | static u8 running = 0, oldFcFlags = 0, count5sec; |
434 | if(running) return; |
438 | if(running) return; |
435 | running = 1; |
439 | running = 1; |
436 | SPI0_UpdateBuffer(); // also calls the GPS-functions |
440 | SPI0_UpdateBuffer(); // also calls the GPS-functions |
437 | UART0_ProcessRxData(); // GPS process request |
441 | UART0_ProcessRxData(); // GPS process request |
438 | UART0_TransmitTxData(); // GPS send answer |
442 | UART0_TransmitTxData(); // GPS send answer |
439 | UART1_ProcessRxData(); // PC process request |
443 | UART1_ProcessRxData(); // PC process request |
440 | UART1_TransmitTxData(); // PC send answer |
444 | UART1_TransmitTxData(); // PC send answer |
441 | UART2_TransmitTxData(); // FC send answer |
445 | UART2_TransmitTxData(); // FC send answer |
442 | CalcHeadFree(); |
446 | CalcHeadFree(); |
443 | // ---------------- Error Check Timing ---------------------------- |
447 | // ---------------- Error Check Timing ---------------------------- |
444 | if(CheckDelay(TimerCheckError) || (FC.StatusFlags & FC_STATUS_START && !(oldFcFlags & FC_STATUS_START))) // Timer or FY wants to start |
448 | if(CheckDelay(TimerCheckError) || (FC.StatusFlags & FC_STATUS_START && !(oldFcFlags & FC_STATUS_START))) // Timer or FY wants to start |
445 | { |
449 | { |
446 | if(CheckDelay(TimerCheckError)) |
450 | if(CheckDelay(TimerCheckError)) |
447 | { |
451 | { |
448 | TimerCheckError = SetDelay(1000); |
452 | TimerCheckError = SetDelay(1000); |
449 | if(++count5sec == 5) |
453 | if(++count5sec == 5) |
450 | { |
454 | { |
451 | count5sec = 0; |
455 | count5sec = 0; |
452 | FreqGpsProcessedIn5Sec = CountGpsProcessedIn5Sec * 2; |
456 | FreqGpsProcessedIn5Sec = CountGpsProcessedIn5Sec * 2; |
453 | FreqNewGpsDataIn5Sec = CountNewGpsDataIn5Sec * 2; |
457 | FreqNewGpsDataIn5Sec = CountNewGpsDataIn5Sec * 2; |
454 | CountGpsProcessedIn5Sec = 0; |
458 | CountGpsProcessedIn5Sec = 0; |
455 | CountNewGpsDataIn5Sec = 0; |
459 | CountNewGpsDataIn5Sec = 0; |
456 | } |
460 | } |
457 | } |
461 | } |
458 | oldFcFlags = FC.StatusFlags; |
462 | oldFcFlags = FC.StatusFlags; |
459 | if(CheckDelay(SPI0_Timeout) && (DebugUART == UART1)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected |
463 | if(CheckDelay(SPI0_Timeout) && (DebugUART == UART1)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected |
460 | 464 | ||
461 | if(!CheckDelay(SPI0_Timeout) || (DebugUART == UART1)) CheckErrors(); |
465 | if(!CheckDelay(SPI0_Timeout) || (DebugUART == UART1)) CheckErrors(); |
462 | 466 | ||
463 | if(FC.StatusFlags & FC_STATUS_FLY) NaviData.FlyingTime++; // we want to count the battery-time |
467 | if(FC.StatusFlags & FC_STATUS_FLY) NaviData.FlyingTime++; // we want to count the battery-time |
464 | if(SerialLinkOkay) SerialLinkOkay--; |
468 | if(SerialLinkOkay) SerialLinkOkay--; |
465 | if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication |
469 | if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication |
466 | else NCFlags &= ~NC_FLAG_NOSERIALLINK; |
470 | else NCFlags &= ~NC_FLAG_NOSERIALLINK; |
467 | if(StopNavigation && (Parameter.NaviGpsModeControl >= 50) && (Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) BeepTime = 1000; |
471 | if(StopNavigation && (Parameter.NaviGpsModeControl >= 50) && (Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) BeepTime = 1000; |
468 | } |
472 | } |
469 | running = 0; |
473 | running = 0; |
470 | } |
474 | } |
471 | 475 | ||
472 | // the handler will be cyclic called by the timer 1 ISR |
476 | // the handler will be cyclic called by the timer 1 ISR |
473 | // used is for critical timing parts that normaly would handled |
477 | // used is for critical timing parts that normaly would handled |
474 | // within the main loop that could block longer at logging activities |
478 | // within the main loop that could block longer at logging activities |
475 | void EXTIT3_IRQHandler(void) |
479 | void EXTIT3_IRQHandler(void) |
476 | { |
480 | { |
477 | IENABLE; |
481 | IENABLE; |
478 | VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq |
482 | VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq |
479 | Compass_Update(); // update compass communication |
483 | Compass_Update(); // update compass communication |
480 | Analog_Update(); // get new ADC values |
484 | Analog_Update(); // get new ADC values |
481 | 485 | ||
482 | if(!PollingTimeout) |
486 | if(!PollingTimeout) |
483 | { |
487 | { |
484 | PollingTimeout = 5; |
488 | PollingTimeout = 5; |
485 | Polling(); |
489 | Polling(); |
486 | } |
490 | } |
487 | 491 | ||
488 | VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit |
492 | VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit |
489 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq |
493 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq |
490 | IDISABLE; |
494 | IDISABLE; |
491 | VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register |
495 | VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register |
492 | } |
496 | } |
493 | 497 | ||
494 | //---------------------------------------------------------------------------------------------------- |
498 | //---------------------------------------------------------------------------------------------------- |
495 | int main(void) |
499 | int main(void) |
496 | { |
500 | { |
497 | 501 | ||
498 | static u32 ftimer =0; |
502 | static u32 ftimer =0; |
499 | static u8 fstate = 0; |
503 | static u8 fstate = 0; |
500 | // static File_t* f = NULL; |
504 | // static File_t* f = NULL; |
501 | 505 | ||
502 | 506 | ||
503 | /* Configure the system clocks */ |
507 | /* Configure the system clocks */ |
504 | SCU_Config(); |
508 | SCU_Config(); |
505 | /* init VIC (Vectored Interrupt Controller) */ |
509 | /* init VIC (Vectored Interrupt Controller) */ |
506 | SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC |
510 | SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC |
507 | SCU_AHBPeriphReset(__VIC, DISABLE); // disable reset state for VIC |
511 | SCU_AHBPeriphReset(__VIC, DISABLE); // disable reset state for VIC |
508 | VIC_DeInit(); // deinitializes the VIC module registers to their default reset values. |
512 | VIC_DeInit(); // deinitializes the VIC module registers to their default reset values. |
509 | VIC_InitDefaultVectors(); |
513 | VIC_InitDefaultVectors(); |
510 | 514 | ||
511 | // initialize timer 1 for System Clock and delay rountines |
515 | // initialize timer 1 for System Clock and delay rountines |
512 | TIMER1_Init(); |
516 | TIMER1_Init(); |
513 | // initialize the LEDs (needs Timer 1) |
517 | // initialize the LEDs (needs Timer 1) |
514 | Led_Init(); |
518 | Led_Init(); |
515 | // initialize the debug UART1 |
519 | // initialize the debug UART1 |
516 | UART1_Init(); |
520 | UART1_Init(); |
517 | UART1_PutString("\r\n---------------------------------------------"); |
521 | UART1_PutString("\r\n---------------------------------------------"); |
518 | // initialize timer 2 for servo outputs |
522 | // initialize timer 2 for servo outputs |
519 | //TIMER2_Init(); |
523 | //TIMER2_Init(); |
520 | // initialize UART2 to FLIGHTCTRL |
524 | // initialize UART2 to FLIGHTCTRL |
521 | UART2_Init(); |
525 | UART2_Init(); |
522 | // initialize UART0 (to MKGPS or MK3MAG) |
526 | // initialize UART0 (to MKGPS or MK3MAG) |
523 | UART0_Init(); |
527 | UART0_Init(); |
524 | // initialize adc |
528 | // initialize adc |
525 | Analog_Init(); |
529 | Analog_Init(); |
526 | // initialize SPI0 to FC |
530 | // initialize SPI0 to FC |
527 | SPI0_Init(); |
531 | SPI0_Init(); |
528 | // initialize i2c busses (needs Timer 1) |
532 | // initialize i2c busses (needs Timer 1) |
529 | I2C0_Init(); |
533 | I2C0_Init(); |
530 | I2C1_Init(); |
534 | I2C1_Init(); |
531 | 535 | ||
532 | // initialize fat16 partition on sd card (needs Timer 1) |
536 | // initialize fat16 partition on sd card (needs Timer 1) |
533 | Fat16_Init(); |
537 | Fat16_Init(); |
534 | // initialize NC params |
538 | // initialize NC params |
535 | NCParams_Init(); |
539 | NCParams_Init(); |
536 | // initialize the settings |
540 | // initialize the settings |
537 | Settings_Init(); |
541 | Settings_Init(); |
538 | // initialize logging (needs settings) |
542 | // initialize logging (needs settings) |
539 | Logging_Init(); |
543 | Logging_Init(); |
540 | 544 | ||
541 | LED_GRN_ON; |
545 | LED_GRN_ON; |
542 | TimerCheckError = SetDelay(3000); |
546 | TimerCheckError = SetDelay(3000); |
543 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
547 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
544 | UART1_PutString("\n\r Version information:"); |
548 | UART1_PutString("\n\r Version information:"); |
545 | 549 | ||
546 | GetNaviCtrlVersion(); |
550 | GetNaviCtrlVersion(); |
547 | DebugOut.StatusGreen = AMPEL_NC | AMPEL_COMPASS; // NC and MK3Mag |
551 | DebugOut.StatusGreen = AMPEL_NC | AMPEL_COMPASS; // NC and MK3Mag |
548 | DebugOut.StatusRed = 0x00; |
552 | DebugOut.StatusRed = 0x00; |
549 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
553 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
550 | 554 | ||
551 | Compass_Init(); |
555 | Compass_Init(); |
552 | 556 | ||
553 | GPS_Init(); |
557 | GPS_Init(); |
554 | 558 | ||
555 | #ifdef FOLLOW_ME |
559 | #ifdef FOLLOW_ME |
556 | TransmitAlsoToFC = 1; |
560 | TransmitAlsoToFC = 1; |
557 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
561 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
558 | UART1_PutString("\n\r FOLLOW-ME Transmitter only!"); |
562 | UART1_PutString("\n\r FOLLOW-ME Transmitter only!"); |
559 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++\r\n\r\n"); |
563 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++\r\n\r\n"); |
560 | TransmitAlsoToFC = 0; |
564 | TransmitAlsoToFC = 0; |
561 | #else |
565 | #else |
562 | SPI0_GetFlightCtrlVersion(); |
566 | SPI0_GetFlightCtrlVersion(); |
563 | if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
567 | if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
564 | { |
568 | { |
565 | UART1_PutString("\n\r Flight-Ctrl not compatible\n\r"); |
569 | UART1_PutString("\n\r Flight-Ctrl not compatible\n\r"); |
566 | LED_RED_ON; |
570 | LED_RED_ON; |
567 | } |
571 | } |
568 | #endif |
572 | #endif |
569 | // ---------- Prepare the isr driven |
573 | // ---------- Prepare the isr driven |
570 | // set to absolute lowest priority |
574 | // set to absolute lowest priority |
571 | VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW); |
575 | VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW); |
572 | // enable interrupts |
576 | // enable interrupts |
573 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); |
577 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); |
574 | 578 | ||
575 | Debug_OK("START"); |
579 | Debug_OK("START"); |
576 | UART1_PutString("\r\n"); |
580 | UART1_PutString("\r\n"); |
577 | fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer |
581 | fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer |
578 | LED_GRN_ON; |
582 | LED_GRN_ON; |
579 | LED_RED_OFF; |
583 | LED_RED_OFF; |
580 | Settings_GetParamValue(PID_SEND_NMEA, &NMEA_Interval); |
584 | Settings_GetParamValue(PID_SEND_NMEA, &NMEA_Interval); |
581 | UART1_PutString("\r\n"); |
585 | UART1_PutString("\r\n"); |
582 | for (;;) // the endless main loop |
586 | for (;;) // the endless main loop |
583 | { |
587 | { |
584 | Polling(); |
588 | Polling(); |
585 | PollingTimeout = 15; |
589 | PollingTimeout = 15; |
586 | // ---------------- Logging --------------------------------------- |
590 | // ---------------- Logging --------------------------------------- |
587 | if(SD_WatchDog) |
591 | if(SD_WatchDog) |
588 | { |
592 | { |
589 | SD_WatchDog = 30000; |
593 | SD_WatchDog = 30000; |
590 | 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 |
594 | 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 |
591 | else if(FC.StatusFlags & FC_STATUS_START) SD_LoggingError = 100; |
595 | else if(FC.StatusFlags & FC_STATUS_START) SD_LoggingError = 100; |
592 | if(!SD_WatchDog) UART1_PutString("\n\rSD-Watchdog - Logging aborted\n\r"); |
596 | if(!SD_WatchDog) UART1_PutString("\n\rSD-Watchdog - Logging aborted\n\r"); |
593 | } |
597 | } |
594 | 598 | ||
595 | /* |
599 | /* |
596 | if(CheckDelay(ftimer)) |
600 | if(CheckDelay(ftimer)) |
597 | { |
601 | { |
598 | 602 | ||
599 | static s8 filename[35]; |
603 | static s8 filename[35]; |
600 | static u8 i = 0; |
604 | static u8 i = 0; |
601 | s8 dbgmsg[40]; |
605 | s8 dbgmsg[40]; |
602 | |
606 | |
603 | |
607 | |
604 | 608 | ||
605 | ftimer = SetDelay(100); |
609 | ftimer = SetDelay(100); |
606 | if(FC.Poti[3]>100 && fstate == 0) |
610 | if(FC.Poti[3]>100 && fstate == 0) |
607 | { |
611 | { |
608 | fstate = 1; |
612 | fstate = 1; |
609 | sprintf(filename, "/toast/toasta/toast%02i.txt",i++); |
613 | sprintf(filename, "/toast/toasta/toast%02i.txt",i++); |
610 | } |
614 | } |
611 | else if(FC.Poti[3]<100 && fstate == 2) |
615 | else if(FC.Poti[3]<100 && fstate == 2) |
612 | { |
616 | { |
613 | fstate = 3; |
617 | fstate = 3; |
614 | } |
618 | } |
615 | 619 | ||
616 | switch(fstate) |
620 | switch(fstate) |
617 | { |
621 | { |
618 | case 1: |
622 | case 1: |
619 | sprintf(dbgmsg,"\r\nStart writing file: %s", filename); |
623 | sprintf(dbgmsg,"\r\nStart writing file: %s", filename); |
620 | Debug(dbgmsg); |
624 | Debug(dbgmsg); |
621 | f = fopen_(filename, 'a'); |
625 | f = fopen_(filename, 'a'); |
622 | if(f== NULL) Fat16_Init(); |
626 | if(f== NULL) Fat16_Init(); |
623 | fstate = 2; |
627 | fstate = 2; |
624 | break; |
628 | break; |
625 | 629 | ||
626 | case 2: |
630 | case 2: |
627 | fputs_("\r\ntest edins sdv dsivbds iv dsivb disbv idsv bisd bv d suiv dsibsivbdis fbvisdöb visdbvisdb vidbfibds ibv", f); |
631 | fputs_("\r\ntest edins sdv dsivbds iv dsivb disbv idsv bisd bv d suiv dsibsivbdis fbvisdöb visdbvisdb vidbfibds ibv", f); |
628 | break; |
632 | break; |
629 | |
633 | |
630 | case 3: |
634 | case 3: |
631 | sprintf(dbgmsg,"\r\nClosing file: %s", filename); |
635 | sprintf(dbgmsg,"\r\nClosing file: %s", filename); |
632 | Debug(dbgmsg); |
636 | Debug(dbgmsg); |
633 | fclose_(f); |
637 | fclose_(f); |
634 | fstate = 0; |
638 | fstate = 0; |
635 | break; |
639 | break; |
636 | 640 | ||
637 | default: |
641 | default: |
638 | break; |
642 | break; |
639 | } |
643 | } |
640 | } |
644 | } |
641 | */ |
645 | */ |
642 | } |
646 | } |
643 | } |
647 | } |
644 | //DebugOut.Analog[16] |
648 | //DebugOut.Analog[16] |
645 | 649 |