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