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