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