Rev 362 | Rev 369 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 362 | Rev 368 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | // + Software Nutzungsbedingungen (english version: see below) |
7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
22 | // + des Mitverschuldens offen. |
22 | // + des Mitverschuldens offen. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Software LICENSING TERMS |
32 | // + Software LICENSING TERMS |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
37 | // + The Software may only be used with the Licensor's products. |
37 | // + The Software may only be used with the Licensor's products. |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
40 | // + agreement shall be the property of the Licensor. |
40 | // + agreement shall be the property of the Licensor. |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
43 | // + The customer shall be responsible for taking reasonable precautions |
43 | // + The customer shall be responsible for taking reasonable precautions |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
53 | // + #### END OF LICENSING TERMS #### |
53 | // + #### END OF LICENSING TERMS #### |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | //#define MCLK96MHZ |
56 | //#define MCLK96MHZ |
57 | const unsigned long _Main_Crystal = 25000; |
57 | const unsigned long _Main_Crystal = 25000; |
58 | #include <stdio.h> |
58 | #include <stdio.h> |
59 | #include "91x_lib.h" |
59 | #include "91x_lib.h" |
60 | #include "led.h" |
60 | #include "led.h" |
61 | #include "uart0.h" |
61 | #include "uart0.h" |
62 | #include "uart1.h" |
62 | #include "uart1.h" |
63 | #include "uart2.h" |
63 | #include "uart2.h" |
64 | #include "gps.h" |
64 | #include "gps.h" |
65 | #include "i2c.h" |
65 | #include "i2c.h" |
66 | #include "compass.h" |
66 | #include "compass.h" |
67 | #include "timer1.h" |
67 | #include "timer1.h" |
68 | #include "timer2.h" |
68 | #include "timer2.h" |
69 | #include "analog.h" |
69 | #include "analog.h" |
70 | #include "spi_slave.h" |
70 | #include "spi_slave.h" |
71 | #include "fat16.h" |
71 | #include "fat16.h" |
72 | #include "usb.h" |
72 | #include "usb.h" |
73 | #include "sdc.h" |
73 | #include "sdc.h" |
74 | #include "logging.h" |
74 | #include "logging.h" |
75 | #include "params.h" |
75 | #include "params.h" |
76 | #include "settings.h" |
76 | #include "settings.h" |
77 | #include "config.h" |
77 | #include "config.h" |
78 | #include "main.h" |
78 | #include "main.h" |
79 | #include "debug.h" |
79 | #include "debug.h" |
80 | #include "eeprom.h" |
80 | #include "eeprom.h" |
81 | #include "ssc.h" |
81 | #include "ssc.h" |
82 | #include "sdc.h" |
82 | #include "sdc.h" |
83 | 83 | ||
84 | #ifdef FOLLOW_ME |
84 | #ifdef FOLLOW_ME |
85 | u8 TransmitAlsoToFC = 0; |
85 | u8 TransmitAlsoToFC = 0; |
86 | #endif |
86 | #endif |
87 | u32 TimerCheckError; |
87 | u32 TimerCheckError; |
88 | u8 ErrorCode = 0; |
88 | u8 ErrorCode = 0; |
89 | u16 BeepTime; |
89 | u16 BeepTime; |
90 | u8 NCFlags = 0; |
90 | u8 NCFlags = 0; |
91 | s16 GeoMagDec = 0; // local magnetic declination in 0.1 deg |
91 | s16 GeoMagDec = 0; // local magnetic declination in 0.1 deg |
92 | u8 ErrorGpsFixLost = 0; |
92 | u8 ErrorGpsFixLost = 0; |
93 | 93 | ||
94 | u8 ClearFCStatusFlags = 0; |
94 | u8 ClearFCStatusFlags = 0; |
95 | u8 StopNavigation = 0; |
95 | u8 StopNavigation = 0; |
96 | Param_t Parameter; |
96 | Param_t Parameter; |
97 | volatile FC_t FC; |
97 | volatile FC_t FC; |
98 | volatile u32 MainWatchDog = 15000; // stop Navigation if this goes to zero |
98 | volatile u32 MainWatchDog = 15000; // stop Navigation if this goes to zero |
99 | volatile u32 SD_WatchDog = 15000; // stop Logging if this goes to zero |
99 | volatile u32 SD_WatchDog = 15000; // stop Logging if this goes to zero |
100 | 100 | ||
101 | s8 ErrorMSG[25]; |
101 | s8 ErrorMSG[25]; |
102 | 102 | ||
103 | //---------------------------------------------------------------------------------------------------- |
103 | //---------------------------------------------------------------------------------------------------- |
104 | void SCU_Config(void) |
104 | void SCU_Config(void) |
105 | { |
105 | { |
106 | /* configure PLL and set it as master clock source */ |
106 | /* configure PLL and set it as master clock source */ |
107 | SCU_MCLKSourceConfig(SCU_MCLK_OSC); // set master clock source to external oscillator clock (25MHz) before diabling the PLL |
107 | SCU_MCLKSourceConfig(SCU_MCLK_OSC); // set master clock source to external oscillator clock (25MHz) before diabling the PLL |
108 | SCU_PLLCmd(DISABLE); // now disable the PLL |
108 | SCU_PLLCmd(DISABLE); // now disable the PLL |
109 | #ifdef MCLK96MHZ |
109 | #ifdef MCLK96MHZ |
110 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div2); // set BRCLK to MCLK/2 = 48MHz |
110 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div2); // set BRCLK to MCLK/2 = 48MHz |
111 | SCU_PCLKDivisorConfig(SCU_PCLK_Div4); // set PCLK (APB bus clock) divisor to 4 (half Reference Clock) |
111 | SCU_PCLKDivisorConfig(SCU_PCLK_Div4); // set PCLK (APB bus clock) divisor to 4 (half Reference Clock) |
112 | SCU_RCLKDivisorConfig(SCU_RCLK_Div2); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
112 | SCU_RCLKDivisorConfig(SCU_RCLK_Div2); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
113 | SCU_HCLKDivisorConfig(SCU_HCLK_Div2); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
113 | SCU_HCLKDivisorConfig(SCU_HCLK_Div2); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
114 | SCU_PLLFactorsConfig(192,25,2); // PLL = 96 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=2 |
114 | SCU_PLLFactorsConfig(192,25,2); // PLL = 96 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=2 |
115 | #else |
115 | #else |
116 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div1); // set BRCLK to MCLK = 48MHz |
116 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div1); // set BRCLK to MCLK = 48MHz |
117 | SCU_PCLKDivisorConfig(SCU_PCLK_Div2); // set PCLK (APB bus clock) divisor to 2 (half Reference Clock) |
117 | SCU_PCLKDivisorConfig(SCU_PCLK_Div2); // set PCLK (APB bus clock) divisor to 2 (half Reference Clock) |
118 | SCU_RCLKDivisorConfig(SCU_RCLK_Div1); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
118 | SCU_RCLKDivisorConfig(SCU_RCLK_Div1); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
119 | SCU_HCLKDivisorConfig(SCU_HCLK_Div1); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
119 | SCU_HCLKDivisorConfig(SCU_HCLK_Div1); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
120 | SCU_PLLFactorsConfig(192,25,3); // PLL = 48 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=3 |
120 | SCU_PLLFactorsConfig(192,25,3); // PLL = 48 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=3 |
121 | #endif |
121 | #endif |
122 | SCU_PLLCmd(ENABLE); // Enable PLL (is disabled by SCU_PLLFactorsConfig) |
122 | SCU_PLLCmd(ENABLE); // Enable PLL (is disabled by SCU_PLLFactorsConfig) |
123 | SCU_MCLKSourceConfig(SCU_MCLK_PLL); // set master clock source to PLL |
123 | SCU_MCLKSourceConfig(SCU_MCLK_PLL); // set master clock source to PLL |
124 | } |
124 | } |
125 | 125 | ||
126 | //---------------------------------------------------------------------------------------------------- |
126 | //---------------------------------------------------------------------------------------------------- |
127 | void GetNaviCtrlVersion(void) |
127 | void GetNaviCtrlVersion(void) |
128 | { |
128 | { |
129 | u8 msg[25]; |
129 | u8 msg[25]; |
130 | 130 | ||
131 | sprintf(msg,"\n\r NaviCtrl HW: V%d.%d SW: V%d.%d%c", Version_HW/10, Version_HW%10, VERSION_MAJOR, VERSION_MINOR, 'a'+ VERSION_PATCH); |
131 | sprintf(msg,"\n\r NaviCtrl HW: V%d.%d SW: V%d.%d%c", Version_HW/10, Version_HW%10, VERSION_MAJOR, VERSION_MINOR, 'a'+ VERSION_PATCH); |
132 | UART1_PutString(msg); |
132 | UART1_PutString(msg); |
133 | } |
133 | } |
134 | 134 | ||
135 | //---------------------------------------------------------------------------------------------------- |
135 | //---------------------------------------------------------------------------------------------------- |
136 | 136 | ||
137 | void CheckErrors(void) |
137 | void CheckErrors(void) |
138 | { |
138 | { |
139 | static s32 no_error_delay = 0; |
139 | static s32 no_error_delay = 0; |
140 | s32 newErrorCode = 0; |
140 | s32 newErrorCode = 0; |
141 | UART_VersionInfo.HardwareError[0] = 0; |
141 | UART_VersionInfo.HardwareError[0] = 0; |
142 | 142 | ||
143 | if(CheckDelay(I2C1_Timeout) || (Compass_Heading < 0)) DebugOut.StatusRed |= AMPEL_COMPASS; |
143 | if(CheckDelay(I2C1_Timeout) || (Compass_Heading < 0)) DebugOut.StatusRed |= AMPEL_COMPASS; |
144 | else DebugOut.StatusRed &= ~AMPEL_COMPASS; // MK3Mag green status |
144 | else DebugOut.StatusRed &= ~AMPEL_COMPASS; // MK3Mag green status |
145 | 145 | ||
146 | if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.StatusRed |= AMPEL_BL; |
146 | if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.StatusRed |= AMPEL_BL; |
147 | else DebugOut.StatusRed &= ~AMPEL_BL; // BL-Ctrl green status |
147 | else DebugOut.StatusRed &= ~AMPEL_BL; // BL-Ctrl green status |
148 | 148 | ||
149 | if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.StatusRed |= AMPEL_NC; |
149 | if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.StatusRed |= AMPEL_NC; |
150 | else DebugOut.StatusRed &= ~AMPEL_NC; |
150 | else DebugOut.StatusRed &= ~AMPEL_NC; |
151 | 151 | ||
152 | if(CheckDelay(SPI0_Timeout)) |
152 | if(CheckDelay(SPI0_Timeout)) |
153 | { |
153 | { |
154 | LED_RED_ON; |
154 | LED_RED_ON; |
155 | sprintf(ErrorMSG,"no FC communication "); |
155 | sprintf(ErrorMSG,"no FC communication "); |
156 | newErrorCode = 3; |
156 | newErrorCode = 3; |
157 | StopNavigation = 1; |
157 | StopNavigation = 1; |
158 | DebugOut.StatusGreen &= ~AMPEL_FC; // status of FC Present |
158 | DebugOut.StatusGreen &= ~AMPEL_FC; // status of FC Present |
159 | DebugOut.StatusGreen &= ~AMPEL_BL; // status of BL Present |
159 | DebugOut.StatusGreen &= ~AMPEL_BL; // status of BL Present |
160 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_SPI_RX; |
160 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_SPI_RX; |
161 | } |
161 | } |
162 | else if(CheckDelay(I2C1_Timeout)) |
162 | else if(CheckDelay(I2C1_Timeout)) |
163 | { |
163 | { |
164 | LED_RED_ON; |
164 | LED_RED_ON; |
165 | sprintf(ErrorMSG,"no compass communication "); |
165 | sprintf(ErrorMSG,"no compass communication"); |
166 | //Reset I2CBus |
166 | //Reset I2CBus |
167 | I2C1_Deinit(); |
167 | I2C1_Deinit(); |
168 | I2C1_Init(); |
168 | I2C1_Init(); |
169 | newErrorCode = 4; |
169 | newErrorCode = 4; |
170 | StopNavigation = 1; |
170 | StopNavigation = 1; |
171 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
171 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
172 | DebugOut.StatusRed |= AMPEL_COMPASS; |
172 | DebugOut.StatusRed |= AMPEL_COMPASS; |
173 | } |
173 | } |
174 | else if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
174 | else if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
175 | { |
175 | { |
176 | LED_RED_ON; |
176 | LED_RED_ON; |
177 | #ifndef FOLLOW_ME |
177 | #ifndef FOLLOW_ME |
178 | sprintf(ErrorMSG,"FC not compatible "); |
178 | sprintf(ErrorMSG,"FC not compatible "); |
179 | #else |
179 | #else |
180 | sprintf(ErrorMSG,"! FollowMe only ! "); |
180 | sprintf(ErrorMSG,"! FollowMe only ! "); |
181 | #endif |
181 | #endif |
182 | newErrorCode = 1; |
182 | newErrorCode = 1; |
183 | StopNavigation = 1; |
183 | StopNavigation = 1; |
184 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE; |
184 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE; |
185 | DebugOut.StatusRed |= AMPEL_NC; |
185 | DebugOut.StatusRed |= AMPEL_NC; |
186 | } |
186 | } |
187 | 187 | ||
188 | else if(FC.Error[0] & FC_ERROR0_GYRO_NICK) |
188 | else if(FC.Error[0] & FC_ERROR0_GYRO_NICK) |
189 | { |
189 | { |
190 | LED_RED_ON; |
190 | LED_RED_ON; |
191 | sprintf(ErrorMSG,"ERR: FC Nick Gyro"); |
191 | sprintf(ErrorMSG,"ERR: FC Nick Gyro"); |
192 | newErrorCode = 10; |
192 | newErrorCode = 10; |
193 | } |
193 | } |
194 | else if(FC.Error[0] & FC_ERROR0_GYRO_ROLL) |
194 | else if(FC.Error[0] & FC_ERROR0_GYRO_ROLL) |
195 | { |
195 | { |
196 | LED_RED_ON; |
196 | LED_RED_ON; |
197 | sprintf(ErrorMSG,"ERR: FC Roll Gyro"); |
197 | sprintf(ErrorMSG,"ERR: FC Roll Gyro"); |
198 | newErrorCode = 11; |
198 | newErrorCode = 11; |
199 | } |
199 | } |
200 | else if(FC.Error[0] & FC_ERROR0_GYRO_YAW) |
200 | else if(FC.Error[0] & FC_ERROR0_GYRO_YAW) |
201 | { |
201 | { |
202 | LED_RED_ON; |
202 | LED_RED_ON; |
203 | sprintf(ErrorMSG,"ERR: FC Yaw Gyro"); |
203 | sprintf(ErrorMSG,"ERR: FC Yaw Gyro"); |
204 | newErrorCode = 12; |
204 | newErrorCode = 12; |
205 | } |
205 | } |
206 | else if(FC.Error[0] & FC_ERROR0_ACC_NICK) |
206 | else if(FC.Error[0] & FC_ERROR0_ACC_NICK) |
207 | { |
207 | { |
208 | LED_RED_ON; |
208 | LED_RED_ON; |
209 | sprintf(ErrorMSG,"ERR: FC Nick ACC"); |
209 | sprintf(ErrorMSG,"ERR: FC Nick ACC"); |
210 | newErrorCode = 13; |
210 | newErrorCode = 13; |
211 | } |
211 | } |
212 | else if(FC.Error[0] & FC_ERROR0_ACC_ROLL) |
212 | else if(FC.Error[0] & FC_ERROR0_ACC_ROLL) |
213 | { |
213 | { |
214 | LED_RED_ON; |
214 | LED_RED_ON; |
215 | sprintf(ErrorMSG,"ERR: FC Roll ACC"); |
215 | sprintf(ErrorMSG,"ERR: FC Roll ACC"); |
216 | newErrorCode = 14; |
216 | newErrorCode = 14; |
217 | } |
217 | } |
218 | else if(FC.Error[0] & FC_ERROR0_ACC_TOP) |
218 | else if(FC.Error[0] & FC_ERROR0_ACC_TOP) |
219 | { |
219 | { |
220 | LED_RED_ON; |
220 | LED_RED_ON; |
221 | sprintf(ErrorMSG,"ERR:FC Z-ACC"); |
221 | sprintf(ErrorMSG,"ERR:FC Z-ACC"); |
222 | newErrorCode = 15; |
222 | newErrorCode = 15; |
223 | } |
223 | } |
224 | else if(NC_To_FC_Flags & NC_TO_FC_FLYING_RANGE) |
224 | else if(NC_To_FC_Flags & NC_TO_FC_FLYING_RANGE) |
225 | { |
225 | { |
226 | LED_RED_ON; |
226 | LED_RED_ON; |
227 | sprintf(ErrorMSG,"ERR:Flying range!"); |
227 | sprintf(ErrorMSG,"ERR:Flying range!"); |
228 | newErrorCode = 28; |
228 | newErrorCode = 28; |
229 | } |
229 | } |
230 | else if(FC.Error[0] & FC_ERROR0_PRESSURE) |
230 | else if(FC.Error[0] & FC_ERROR0_PRESSURE) |
231 | { |
231 | { |
232 | LED_RED_ON; |
232 | LED_RED_ON; |
233 | sprintf(ErrorMSG,"ERR:Pressure sensor"); |
233 | sprintf(ErrorMSG,"ERR:Pressure sensor"); |
234 | newErrorCode = 16; |
234 | newErrorCode = 16; |
235 | } |
235 | } |
236 | else if(FC.Error[1] & FC_ERROR1_I2C) |
236 | else if(FC.Error[1] & FC_ERROR1_I2C) |
237 | { |
237 | { |
238 | LED_RED_ON; |
238 | LED_RED_ON; |
239 | sprintf(ErrorMSG,"ERR:I2C FC to BL"); |
239 | sprintf(ErrorMSG,"ERR:I2C FC to BL"); |
240 | newErrorCode = 17; |
240 | newErrorCode = 17; |
241 | } |
241 | } |
242 | else if(FC.Error[1] & FC_ERROR1_BL_MISSING) |
242 | else if(FC.Error[1] & FC_ERROR1_BL_MISSING) |
243 | { |
243 | { |
244 | LED_RED_ON; |
244 | LED_RED_ON; |
245 | sprintf(ErrorMSG,"ERR: Bl Missing"); |
245 | sprintf(ErrorMSG,"ERR: Bl Missing"); |
246 | newErrorCode = 18; |
246 | newErrorCode = 18; |
247 | } |
247 | } |
248 | else if(FC.Error[1] & FC_ERROR1_MIXER) |
248 | else if(FC.Error[1] & FC_ERROR1_MIXER) |
249 | { |
249 | { |
250 | LED_RED_ON; |
250 | LED_RED_ON; |
251 | sprintf(ErrorMSG,"Mixer Error"); |
251 | sprintf(ErrorMSG,"Mixer Error"); |
252 | newErrorCode = 19; |
252 | newErrorCode = 19; |
253 | } |
253 | } |
254 | else if(CheckDelay(UBX_Timeout) && Parameter.GlobalConfig & FC_CFG_GPS_AKTIV) |
254 | else if(CheckDelay(UBX_Timeout) && Parameter.GlobalConfig & FC_CFG_GPS_AKTIV) |
255 | { |
255 | { |
256 | LED_RED_ON; |
256 | LED_RED_ON; |
257 | // if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected "); |
257 | // if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected "); |
258 | // else |
258 | // else |
259 | { |
259 | { |
260 | sprintf(ErrorMSG,"no GPS communication "); |
260 | sprintf(ErrorMSG,"no GPS communication "); |
261 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX; |
261 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX; |
262 | newErrorCode = 5; |
262 | newErrorCode = 5; |
263 | } |
263 | } |
264 | StopNavigation = 1; |
264 | StopNavigation = 1; |
265 | // UBX_Timeout = SetDelay(500); |
265 | // UBX_Timeout = SetDelay(500); |
266 | } |
266 | } |
267 | else if(Compass_Heading < 0) |
267 | else if(Compass_Heading < 0) |
268 | { |
268 | { |
269 | LED_RED_ON; |
269 | LED_RED_ON; |
270 | sprintf(ErrorMSG,"bad compass value "); |
270 | sprintf(ErrorMSG,"bad compass value "); |
271 | newErrorCode = 6; |
271 | newErrorCode = 6; |
272 | StopNavigation = 1; |
272 | StopNavigation = 1; |
273 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
273 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
274 | } |
274 | } |
275 | else if((FC.Error[1] & FC_ERROR1_SPI_RX)) |
275 | else if((FC.Error[1] & FC_ERROR1_SPI_RX)) |
276 | { |
276 | { |
277 | LED_RED_ON; |
277 | LED_RED_ON; |
278 | sprintf(ErrorMSG,"FC spi rx error "); |
278 | sprintf(ErrorMSG,"FC spi rx error "); |
279 | newErrorCode = 8; |
279 | newErrorCode = 8; |
280 | StopNavigation = 1; |
280 | StopNavigation = 1; |
281 | } |
281 | } |
282 | else if(FC.Error[0] & FC_ERROR0_CAREFREE) |
282 | else if(FC.Error[0] & FC_ERROR0_CAREFREE) |
283 | { |
283 | { |
284 | LED_RED_ON; |
284 | LED_RED_ON; |
285 | sprintf(ErrorMSG,"FC: Carefree Error"); |
285 | sprintf(ErrorMSG,"FC: Carefree Error"); |
286 | newErrorCode = 20; |
286 | newErrorCode = 20; |
287 | } |
287 | } |
288 | else if(FC.Error[1] & FC_ERROR1_PPM) |
288 | else if(FC.Error[1] & FC_ERROR1_PPM) |
289 | { |
289 | { |
290 | LED_RED_ON; |
290 | LED_RED_ON; |
291 | sprintf(ErrorMSG,"RC Signal lost "); |
291 | sprintf(ErrorMSG,"RC Signal lost "); |
292 | newErrorCode = 7; |
292 | newErrorCode = 7; |
293 | } |
293 | } |
294 | else if(ErrorGpsFixLost) |
294 | else if(ErrorGpsFixLost) |
295 | { |
295 | { |
296 | LED_RED_ON; |
296 | LED_RED_ON; |
297 | sprintf(ErrorMSG,"GPS Fix lost "); |
297 | sprintf(ErrorMSG,"GPS Fix lost "); |
298 | newErrorCode = 21; |
298 | newErrorCode = 21; |
299 | } |
299 | } |
300 | else if(ErrorDisturbedEarthMagnetField) |
300 | else if(ErrorDisturbedEarthMagnetField) |
301 | { |
301 | { |
302 | LED_RED_ON; |
302 | LED_RED_ON; |
303 | sprintf(ErrorMSG,"Magnet error "); |
303 | sprintf(ErrorMSG,"Magnet error "); |
304 | newErrorCode = 22; |
304 | newErrorCode = 22; |
305 | DebugOut.StatusRed |= AMPEL_COMPASS | AMPEL_NC; |
305 | DebugOut.StatusRed |= AMPEL_COMPASS | AMPEL_NC; |
306 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
306 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
307 | } |
307 | } |
308 | else if(BL_MinOfMaxPWM == 40 && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
308 | else if(BL_MinOfMaxPWM == 40 && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
309 | { |
309 | { |
310 | LED_RED_ON; |
310 | LED_RED_ON; |
311 | sprintf(ErrorMSG,"ERR:Motor restart "); |
311 | sprintf(ErrorMSG,"ERR:Motor restart "); |
312 | newErrorCode = 23; |
312 | newErrorCode = 23; |
313 | DebugOut.StatusRed |= AMPEL_BL; |
313 | DebugOut.StatusRed |= AMPEL_BL; |
314 | } |
314 | } |
315 | else if(BL_MinOfMaxPWM != 255 && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
315 | else if(BL_MinOfMaxPWM != 255 && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
316 | { |
316 | { |
317 | LED_RED_ON; |
317 | LED_RED_ON; |
318 | sprintf(ErrorMSG,"ERR:BL Limitation "); |
318 | sprintf(ErrorMSG,"ERR:BL Limitation "); |
319 | newErrorCode = 24; |
319 | newErrorCode = 24; |
320 | DebugOut.StatusRed |= AMPEL_BL; |
320 | DebugOut.StatusRed |= AMPEL_BL; |
321 | } |
321 | } |
322 | else if(NCFlags & NC_FLAG_RANGE_LIMIT && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
322 | else if(NCFlags & NC_FLAG_RANGE_LIMIT && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
323 | { |
323 | { |
324 | LED_RED_ON; |
324 | LED_RED_ON; |
325 | sprintf(ErrorMSG,"ERR:GPS range "); |
325 | sprintf(ErrorMSG,"ERR:GPS range "); |
326 | newErrorCode = 25; |
326 | newErrorCode = 25; |
327 | DebugOut.StatusRed |= AMPEL_NC; |
327 | DebugOut.StatusRed |= AMPEL_NC; |
328 | } |
328 | } |
329 | else if(!SD_SWITCH && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START) |
329 | else if(!SD_SWITCH && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START) |
330 | { |
330 | { |
331 | LED_RED_ON; |
331 | LED_RED_ON; |
332 | sprintf(ErrorMSG,"ERR:No SD-Card "); |
332 | sprintf(ErrorMSG,"ERR:No SD-Card "); |
333 | newErrorCode = 26; |
333 | newErrorCode = 26; |
334 | DebugOut.StatusRed |= AMPEL_NC; |
334 | DebugOut.StatusRed |= AMPEL_NC; |
335 | } |
335 | } |
336 | else if((SD_LoggingError || (SD_WatchDog == 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START ) |
336 | else if((SD_LoggingError || (SD_WatchDog == 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START ) |
337 | { |
337 | { |
338 | LED_RED_ON; |
338 | LED_RED_ON; |
339 | sprintf(ErrorMSG,"ERR:SD Logging aborted"); |
339 | sprintf(ErrorMSG,"ERR:SD Logging aborted"); |
340 | newErrorCode = 27; |
340 | newErrorCode = 27; |
341 | DebugOut.StatusRed |= AMPEL_NC; |
341 | DebugOut.StatusRed |= AMPEL_NC; |
342 | SD_LoggingError = 0; |
342 | SD_LoggingError = 0; |
343 | } |
343 | } |
344 | else if(((AbsoluteFlyingAltitude) && (NaviData.Altimeter / 20 >= AbsoluteFlyingAltitude)) && (FC.StatusFlags & FC_STATUS_FLY)) |
344 | else if(((AbsoluteFlyingAltitude) && (NaviData.Altimeter / 20 >= AbsoluteFlyingAltitude)) && (FC.StatusFlags & FC_STATUS_FLY)) |
345 | { |
345 | { |
346 | LED_RED_ON; |
346 | LED_RED_ON; |
347 | sprintf(ErrorMSG,"ERR:Max Altitude "); |
347 | sprintf(ErrorMSG,"ERR:Max Altitude "); |
348 | newErrorCode = 29; |
348 | newErrorCode = 29; |
349 | DebugOut.StatusRed |= AMPEL_NC; |
349 | DebugOut.StatusRed |= AMPEL_NC; |
350 | } |
350 | } |
351 | else // no error occured |
351 | else // no error occured |
352 | { |
352 | { |
353 | StopNavigation = 0; |
353 | StopNavigation = 0; |
354 | LED_RED_OFF; |
354 | LED_RED_OFF; |
355 | if(no_error_delay) { no_error_delay--; } |
355 | if(no_error_delay) { no_error_delay--; } |
356 | else |
356 | else |
357 | { |
357 | { |
358 | sprintf(ErrorMSG,"No Error "); |
358 | sprintf(ErrorMSG,"No Error "); |
359 | ErrorCode = 0; |
359 | ErrorCode = 0; |
360 | } |
360 | } |
361 | } |
361 | } |
362 | 362 | ||
363 | if(newErrorCode) |
363 | if(newErrorCode) |
364 | { |
364 | { |
365 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) no_error_delay = 8; // delay the errors if the motors are running |
365 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) no_error_delay = 8; // delay the errors if the motors are running |
366 | ErrorCode = newErrorCode; |
366 | ErrorCode = newErrorCode; |
367 | } |
367 | } |
368 | FC.Error[0] = 0; |
368 | FC.Error[0] = 0; |
369 | FC.Error[1] = 0; |
369 | FC.Error[1] = 0; |
370 | FC.Error[2] = 0; |
370 | FC.Error[2] = 0; |
371 | FC.Error[3] = 0; |
371 | FC.Error[3] = 0; |
372 | FC.Error[4] = 0; |
372 | FC.Error[4] = 0; |
373 | ErrorGpsFixLost = 0; |
373 | ErrorGpsFixLost = 0; |
374 | } |
374 | } |
375 | 375 | ||
376 | // the handler will be cyclic called by the timer 1 ISR |
376 | // the handler will be cyclic called by the timer 1 ISR |
377 | // used is for critical timing parts that normaly would handled |
377 | // used is for critical timing parts that normaly would handled |
378 | // within the main loop that could block longer at logging activities |
378 | // within the main loop that could block longer at logging activities |
379 | void EXTIT3_IRQHandler(void) |
379 | void EXTIT3_IRQHandler(void) |
380 | { |
380 | { |
381 | IENABLE; |
381 | IENABLE; |
382 | 382 | ||
383 | VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq |
383 | VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq |
384 | VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit |
384 | VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit |
385 | Compass_Update(); // update compass communication |
385 | Compass_Update(); // update compass communication |
386 | Analog_Update(); // get new ADC values |
386 | Analog_Update(); // get new ADC values |
387 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq |
387 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq |
388 | 388 | ||
389 | IDISABLE; |
389 | IDISABLE; |
390 | } |
390 | } |
391 | 391 | ||
392 | //---------------------------------------------------------------------------------------------------- |
392 | //---------------------------------------------------------------------------------------------------- |
393 | int main(void) |
393 | int main(void) |
394 | { |
394 | { |
395 | /* |
395 | /* |
396 | static u32 ftimer =0; |
396 | static u32 ftimer =0; |
397 | static u8 fstate = 0; |
397 | static u8 fstate = 0; |
398 | static File_t* f = NULL; |
398 | static File_t* f = NULL; |
399 | */ |
399 | */ |
400 | 400 | ||
401 | /* Configure the system clocks */ |
401 | /* Configure the system clocks */ |
402 | SCU_Config(); |
402 | SCU_Config(); |
403 | /* init VIC (Vectored Interrupt Controller) */ |
403 | /* init VIC (Vectored Interrupt Controller) */ |
404 | SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC |
404 | SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC |
405 | SCU_AHBPeriphReset(__VIC, DISABLE); // disable reset state for VIC |
405 | SCU_AHBPeriphReset(__VIC, DISABLE); // disable reset state for VIC |
406 | VIC_DeInit(); // deinitializes the VIC module registers to their default reset values. |
406 | VIC_DeInit(); // deinitializes the VIC module registers to their default reset values. |
407 | VIC_InitDefaultVectors(); |
407 | VIC_InitDefaultVectors(); |
408 | 408 | ||
409 | // initialize timer 1 for System Clock and delay rountines |
409 | // initialize timer 1 for System Clock and delay rountines |
410 | TIMER1_Init(); |
410 | TIMER1_Init(); |
411 | // initialize the LEDs (needs Timer 1) |
411 | // initialize the LEDs (needs Timer 1) |
412 | Led_Init(); |
412 | Led_Init(); |
413 | // initialize the debug UART1 |
413 | // initialize the debug UART1 |
414 | UART1_Init(); |
414 | UART1_Init(); |
415 | UART1_PutString("\r\n---------------------------------------------"); |
415 | UART1_PutString("\r\n---------------------------------------------"); |
416 | // initialize usb |
416 | // initialize usb |
417 | USB_ConfigInit(); |
417 | USB_ConfigInit(); |
418 | // initialize timer 2 for servo outputs |
418 | // initialize timer 2 for servo outputs |
419 | //TIMER2_Init(); |
419 | //TIMER2_Init(); |
420 | // initialize UART2 to FLIGHTCTRL |
420 | // initialize UART2 to FLIGHTCTRL |
421 | UART2_Init(); |
421 | UART2_Init(); |
422 | // initialize UART0 (to MKGPS or MK3MAG) |
422 | // initialize UART0 (to MKGPS or MK3MAG) |
423 | UART0_Init(); |
423 | UART0_Init(); |
424 | // initialize adc |
424 | // initialize adc |
425 | Analog_Init(); |
425 | Analog_Init(); |
426 | // initialize SPI0 to FC |
426 | // initialize SPI0 to FC |
427 | SPI0_Init(); |
427 | SPI0_Init(); |
428 | // initialize i2c bus (needs Timer 1) |
428 | // initialize i2c bus (needs Timer 1) |
429 | I2C1_Init(); |
429 | I2C1_Init(); |
430 | // initialize fat16 partition on sd card (needs Timer 1) |
430 | // initialize fat16 partition on sd card (needs Timer 1) |
431 | Fat16_Init(); |
431 | Fat16_Init(); |
432 | // initialize NC params |
432 | // initialize NC params |
433 | NCParams_Init(); |
433 | NCParams_Init(); |
434 | // initialize the settings |
434 | // initialize the settings |
435 | Settings_Init(); |
435 | Settings_Init(); |
436 | // initialize logging (needs settings) |
436 | // initialize logging (needs settings) |
437 | Logging_Init(); |
437 | Logging_Init(); |
438 | 438 | ||
439 | LED_GRN_ON; |
439 | LED_GRN_ON; |
440 | TimerCheckError = SetDelay(3000); |
440 | TimerCheckError = SetDelay(3000); |
441 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
441 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
442 | UART1_PutString("\n\r Version information:"); |
442 | UART1_PutString("\n\r Version information:"); |
443 | 443 | ||
444 | GetNaviCtrlVersion(); |
444 | GetNaviCtrlVersion(); |
445 | DebugOut.StatusGreen = AMPEL_NC | AMPEL_COMPASS; // NC and MK3Mag |
445 | DebugOut.StatusGreen = AMPEL_NC | AMPEL_COMPASS; // NC and MK3Mag |
446 | DebugOut.StatusRed = 0x00; |
446 | DebugOut.StatusRed = 0x00; |
447 | 447 | ||
448 | Compass_Init(); |
448 | Compass_Init(); |
449 | 449 | ||
450 | #ifdef FOLLOW_ME |
450 | #ifdef FOLLOW_ME |
451 | TransmitAlsoToFC = 1; |
451 | TransmitAlsoToFC = 1; |
452 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
452 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
453 | UART1_PutString("\n\r FOLLOW-ME Transmitter only!"); |
453 | UART1_PutString("\n\r FOLLOW-ME Transmitter only!"); |
454 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++\r\n\r\n"); |
454 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++\r\n\r\n"); |
455 | TransmitAlsoToFC = 0; |
455 | TransmitAlsoToFC = 0; |
456 | #else |
456 | #else |
457 | SPI0_GetFlightCtrlVersion(); |
457 | SPI0_GetFlightCtrlVersion(); |
458 | if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
458 | if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
459 | { |
459 | { |
460 | UART1_PutString("\n\r Flight-Ctrl not compatible"); |
460 | UART1_PutString("\n\r Flight-Ctrl not compatible"); |
461 | LED_RED_ON; |
461 | LED_RED_ON; |
462 | } |
462 | } |
463 | #endif |
463 | #endif |
464 | GPS_Init(); |
464 | GPS_Init(); |
465 | // ---------- Prepare the isr driven |
465 | // ---------- Prepare the isr driven |
466 | // set to absolute lowest priority |
466 | // set to absolute lowest priority |
467 | VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW); |
467 | VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW); |
468 | // enable interrupts |
468 | // enable interrupts |
469 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); |
469 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); |
470 | 470 | ||
471 | Debug_OK("START"); |
471 | Debug_OK("START"); |
472 | UART1_PutString("\r\n"); |
472 | UART1_PutString("\r\n"); |
473 | 473 | ||
474 | for (;;) // the endless main loop |
474 | for (;;) // the endless main loop |
475 | { |
475 | { |
476 | MainWatchDog = 3500; // stop communication to FC after this timeout |
476 | MainWatchDog = 3500; // stop communication to FC after this timeout |
477 | UART0_ProcessRxData(); // process request |
477 | UART0_ProcessRxData(); // process request |
478 | UART1_ProcessRxData(); // process request |
478 | UART1_ProcessRxData(); // process request |
479 | USB_ProcessRxData(); // process request |
479 | USB_ProcessRxData(); // process request |
480 | UART0_TransmitTxData(); // send answer |
480 | UART0_TransmitTxData(); // send answer |
481 | UART1_TransmitTxData(); // send answer |
481 | UART1_TransmitTxData(); // send answer |
482 | UART2_TransmitTxData(); // send answer |
482 | UART2_TransmitTxData(); // send answer |
483 | USB_TransmitTxData(); // send answer |
483 | USB_TransmitTxData(); // send answer |
484 | SPI0_UpdateBuffer(); // handle new SPI Data |
484 | SPI0_UpdateBuffer(); // handle new SPI Data |
485 | 485 | ||
486 | // ---------------- Error Check Timing ---------------------------- |
486 | // ---------------- Error Check Timing ---------------------------- |
487 | if(CheckDelay(TimerCheckError)) |
487 | if(CheckDelay(TimerCheckError)) |
488 | { |
488 | { |
489 | TimerCheckError = SetDelay(1000); |
489 | TimerCheckError = SetDelay(1000); |
490 | if(CheckDelay(SPI0_Timeout) && (DebugUART == UART1)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected |
490 | if(CheckDelay(SPI0_Timeout) && (DebugUART == UART1)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected |
491 | 491 | ||
492 | if(!CheckDelay(SPI0_Timeout) || (DebugUART == UART1)) CheckErrors(); |
492 | if(!CheckDelay(SPI0_Timeout) || (DebugUART == UART1)) CheckErrors(); |
493 | 493 | ||
494 | if(FC.StatusFlags & FC_STATUS_FLY) NaviData.FlyingTime++; // we want to count the battery-time |
494 | if(FC.StatusFlags & FC_STATUS_FLY) NaviData.FlyingTime++; // we want to count the battery-time |
495 | // else NaviData.FlyingTime = 0; // not the time per flight |
495 | // else NaviData.FlyingTime = 0; // not the time per flight |
496 | if(SerialLinkOkay) SerialLinkOkay--; |
496 | if(SerialLinkOkay) SerialLinkOkay--; |
497 | if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication |
497 | if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication |
498 | else NCFlags &= ~NC_FLAG_NOSERIALLINK; |
498 | else NCFlags &= ~NC_FLAG_NOSERIALLINK; |
499 | if(StopNavigation && (Parameter.NaviGpsModeControl >= 50) && (Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) BeepTime = 1000; |
499 | if(StopNavigation && (Parameter.NaviGpsModeControl >= 50) && (Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) BeepTime = 1000; |
500 | } |
500 | } |
501 | // ---------------- Logging --------------------------------------- |
501 | // ---------------- Logging --------------------------------------- |
502 | if(SD_WatchDog) |
502 | if(SD_WatchDog) |
503 | { |
503 | { |
504 | SD_WatchDog = 3000; |
504 | SD_WatchDog = 3000; |
505 | 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 |
505 | 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 |
506 | else if(FC.StatusFlags & FC_STATUS_START) SD_LoggingError = 100; |
506 | else if(FC.StatusFlags & FC_STATUS_START) SD_LoggingError = 100; |
507 | if(!SD_WatchDog) UART1_PutString("\n\rSD-Watchdog - Logging aborted\n\r"); |
507 | if(!SD_WatchDog) UART1_PutString("\n\rSD-Watchdog - Logging aborted\n\r"); |
508 | } |
508 | } |
509 | /* |
509 | /* |
510 | // test |
510 | // test |
511 | if(CheckDelay(ftimer)) |
511 | if(CheckDelay(ftimer)) |
512 | { |
512 | { |
513 | 513 | ||
514 | s8* filename = "test.txt"; |
514 | s8* filename = "test.txt"; |
515 | 515 | ||
516 | ftimer = SetDelay(100); |
516 | ftimer = SetDelay(100); |
517 | if(FC.Poti[3]>100 && fstate == 0) |
517 | if(FC.Poti[3]>100 && fstate == 0) |
518 | { |
518 | { |
519 | fstate = 1; |
519 | fstate = 1; |
520 | } |
520 | } |
521 | else if(FC.Poti[3]<100 && fstate == 2) |
521 | else if(FC.Poti[3]<100 && fstate == 2) |
522 | { |
522 | { |
523 | fstate = 3; |
523 | fstate = 3; |
524 | } |
524 | } |
525 | 525 | ||
526 | switch(fstate) |
526 | switch(fstate) |
527 | { |
527 | { |
528 | case 1: |
528 | case 1: |
529 | sprintf(text,"\r\nStart writing file: %s", filename); |
529 | sprintf(text,"\r\nStart writing file: %s", filename); |
530 | UART1_PutString(text); |
530 | UART1_PutString(text); |
531 | f = fopen_(filename, 'a'); |
531 | f = fopen_(filename, 'a'); |
532 | if(f== NULL) Fat16_Init(); |
532 | if(f== NULL) Fat16_Init(); |
533 | fstate = 2; |
533 | fstate = 2; |
534 | break; |
534 | break; |
535 | 535 | ||
536 | case 2: |
536 | case 2: |
537 | fputs_("\r\ntest edins sdv dsivbds iv dsivb disbv idsv bisd bv d suiv dsibsivbdis fbvisdöb visdbvisdb vidbfibds ibv", f); |
537 | fputs_("\r\ntest edins sdv dsivbds iv dsivb disbv idsv bisd bv d suiv dsibsivbdis fbvisdöb visdbvisdb vidbfibds ibv", f); |
538 | break; |
538 | break; |
539 | |
539 | |
540 | case 3: |
540 | case 3: |
541 | sprintf(text,"\r\nClosing file: %s", filename); |
541 | sprintf(text,"\r\nClosing file: %s", filename); |
542 | UART1_PutString(text); |
542 | UART1_PutString(text); |
543 | fclose_(f); |
543 | fclose_(f); |
544 | fstate = 0; |
544 | fstate = 0; |
545 | break; |
545 | break; |
546 | 546 | ||
547 | default: |
547 | default: |
548 | break; |
548 | break; |
549 | } |
549 | } |
550 | } |
550 | } |
551 | */ |
551 | */ |
552 | } |
552 | } |
553 | } |
553 | } |
554 | 554 | ||
555 | // DebugOut.Analog[] |
555 | // DebugOut.Analog[] |
556 | 556 |