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