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