Rev 351 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 351 | Rev 355 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
8 | // + www.MikroKopter.com |
8 | // + www.MikroKopter.com |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
22 | // + eindeutig als Ursprung verlinkt werden |
22 | // + eindeutig als Ursprung verlinkt werden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
25 | // + Benutzung auf eigene Gefahr |
25 | // + Benutzung auf eigene Gefahr |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
29 | // + mit unserer Zustimmung zulässig |
29 | // + mit unserer Zustimmung zulässig |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + Teile, die nicht eindeutig mit unserer Lizenzvereinbarung gekennzeichnet sind, unterliegen u.U. eigenen Vereinbarungen: |
31 | // + Teile, die nicht eindeutig mit unserer Lizenzvereinbarung gekennzeichnet sind, unterliegen u.U. eigenen Vereinbarungen: |
32 | // + z.B. Die Funktion printf_P() unterliegt ihrer eigenen Lizenz |
32 | // + z.B. Die Funktion printf_P() unterliegt ihrer eigenen Lizenz |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
34 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
35 | // + this list of conditions and the following disclaimer. |
35 | // + this list of conditions and the following disclaimer. |
36 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
36 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
37 | // + from this software without specific prior written permission. |
37 | // + from this software without specific prior written permission. |
38 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
38 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
39 | // + for non-commercial use (directly or indirectly) |
39 | // + for non-commercial use (directly or indirectly) |
40 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
40 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
41 | // + with our written permission |
41 | // + with our written permission |
42 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
42 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
43 | // + clearly linked as origin |
43 | // + clearly linked as origin |
44 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
44 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
45 | // |
45 | // |
46 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
46 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
47 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
47 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
48 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
48 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
49 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
49 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
50 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
50 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
51 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
51 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
52 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
52 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
53 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
53 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
54 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
54 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
55 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
55 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
56 | // + POSSIBILITY OF SUCH DAMAGE. |
56 | // + POSSIBILITY OF SUCH DAMAGE. |
57 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
57 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
58 | //#define MCLK96MHZ |
58 | //#define MCLK96MHZ |
59 | const unsigned long _Main_Crystal = 25000; |
59 | const unsigned long _Main_Crystal = 25000; |
60 | #include <stdio.h> |
60 | #include <stdio.h> |
61 | #include "91x_lib.h" |
61 | #include "91x_lib.h" |
62 | #include "led.h" |
62 | #include "led.h" |
63 | #include "uart0.h" |
63 | #include "uart0.h" |
64 | #include "uart1.h" |
64 | #include "uart1.h" |
65 | #include "uart2.h" |
65 | #include "uart2.h" |
66 | #include "gps.h" |
66 | #include "gps.h" |
67 | #include "i2c.h" |
67 | #include "i2c.h" |
68 | #include "compass.h" |
68 | #include "compass.h" |
69 | #include "timer1.h" |
69 | #include "timer1.h" |
70 | #include "timer2.h" |
70 | #include "timer2.h" |
71 | #include "analog.h" |
71 | #include "analog.h" |
72 | #include "spi_slave.h" |
72 | #include "spi_slave.h" |
73 | #include "fat16.h" |
73 | #include "fat16.h" |
74 | #include "usb.h" |
74 | #include "usb.h" |
75 | #include "sdc.h" |
75 | #include "sdc.h" |
76 | #include "logging.h" |
76 | #include "logging.h" |
77 | #include "params.h" |
77 | #include "params.h" |
78 | #include "settings.h" |
78 | #include "settings.h" |
79 | #include "config.h" |
79 | #include "config.h" |
80 | #include "main.h" |
80 | #include "main.h" |
81 | #include "debug.h" |
81 | #include "debug.h" |
82 | #include "eeprom.h" |
82 | #include "eeprom.h" |
83 | #include "ssc.h" |
83 | #include "ssc.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 | Param_t Parameter; |
97 | Param_t Parameter; |
98 | volatile FC_t FC; |
98 | volatile FC_t FC; |
99 | 99 | ||
100 | s8 ErrorMSG[25]; |
100 | s8 ErrorMSG[25]; |
101 | 101 | ||
102 | //---------------------------------------------------------------------------------------------------- |
102 | //---------------------------------------------------------------------------------------------------- |
103 | void SCU_Config(void) |
103 | void SCU_Config(void) |
104 | { |
104 | { |
105 | /* configure PLL and set it as master clock source */ |
105 | /* configure PLL and set it as master clock source */ |
106 | SCU_MCLKSourceConfig(SCU_MCLK_OSC); // set master clock source to external oscillator clock (25MHz) before diabling the PLL |
106 | SCU_MCLKSourceConfig(SCU_MCLK_OSC); // set master clock source to external oscillator clock (25MHz) before diabling the PLL |
107 | SCU_PLLCmd(DISABLE); // now disable the PLL |
107 | SCU_PLLCmd(DISABLE); // now disable the PLL |
108 | #ifdef MCLK96MHZ |
108 | #ifdef MCLK96MHZ |
109 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div2); // set BRCLK to MCLK/2 = 48MHz |
109 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div2); // set BRCLK to MCLK/2 = 48MHz |
110 | SCU_PCLKDivisorConfig(SCU_PCLK_Div4); // set PCLK (APB bus clock) divisor to 4 (half Reference Clock) |
110 | SCU_PCLKDivisorConfig(SCU_PCLK_Div4); // set PCLK (APB bus clock) divisor to 4 (half Reference Clock) |
111 | SCU_RCLKDivisorConfig(SCU_RCLK_Div2); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
111 | SCU_RCLKDivisorConfig(SCU_RCLK_Div2); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
112 | SCU_HCLKDivisorConfig(SCU_HCLK_Div2); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
112 | SCU_HCLKDivisorConfig(SCU_HCLK_Div2); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
113 | SCU_PLLFactorsConfig(192,25,2); // PLL = 96 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=2 |
113 | SCU_PLLFactorsConfig(192,25,2); // PLL = 96 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=2 |
114 | #else |
114 | #else |
115 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div1); // set BRCLK to MCLK = 48MHz |
115 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div1); // set BRCLK to MCLK = 48MHz |
116 | SCU_PCLKDivisorConfig(SCU_PCLK_Div2); // set PCLK (APB bus clock) divisor to 2 (half Reference Clock) |
116 | SCU_PCLKDivisorConfig(SCU_PCLK_Div2); // set PCLK (APB bus clock) divisor to 2 (half Reference Clock) |
117 | SCU_RCLKDivisorConfig(SCU_RCLK_Div1); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
117 | SCU_RCLKDivisorConfig(SCU_RCLK_Div1); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
118 | SCU_HCLKDivisorConfig(SCU_HCLK_Div1); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
118 | SCU_HCLKDivisorConfig(SCU_HCLK_Div1); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
119 | SCU_PLLFactorsConfig(192,25,3); // PLL = 48 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=3 |
119 | SCU_PLLFactorsConfig(192,25,3); // PLL = 48 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=3 |
120 | #endif |
120 | #endif |
121 | SCU_PLLCmd(ENABLE); // Enable PLL (is disabled by SCU_PLLFactorsConfig) |
121 | SCU_PLLCmd(ENABLE); // Enable PLL (is disabled by SCU_PLLFactorsConfig) |
122 | SCU_MCLKSourceConfig(SCU_MCLK_PLL); // set master clock source to PLL |
122 | SCU_MCLKSourceConfig(SCU_MCLK_PLL); // set master clock source to PLL |
123 | } |
123 | } |
124 | 124 | ||
125 | //---------------------------------------------------------------------------------------------------- |
125 | //---------------------------------------------------------------------------------------------------- |
126 | void GetNaviCtrlVersion(void) |
126 | void GetNaviCtrlVersion(void) |
127 | { |
127 | { |
128 | u8 msg[25]; |
128 | u8 msg[25]; |
129 | 129 | ||
130 | 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); |
130 | 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 | UART1_PutString(msg); |
131 | UART1_PutString(msg); |
132 | } |
132 | } |
133 | 133 | ||
134 | //---------------------------------------------------------------------------------------------------- |
134 | //---------------------------------------------------------------------------------------------------- |
135 | 135 | ||
136 | void CheckErrors(void) |
136 | void CheckErrors(void) |
137 | { |
137 | { |
138 | static s32 no_error_delay = 0; |
138 | static s32 no_error_delay = 0; |
139 | s32 newErrorCode = 0; |
139 | s32 newErrorCode = 0; |
140 | UART_VersionInfo.HardwareError[0] = 0; |
140 | UART_VersionInfo.HardwareError[0] = 0; |
141 | 141 | ||
142 | if(CheckDelay(I2C1_Timeout) || (Compass_Heading < 0)) DebugOut.StatusRed |= AMPEL_COMPASS; |
142 | if(CheckDelay(I2C1_Timeout) || (Compass_Heading < 0)) DebugOut.StatusRed |= AMPEL_COMPASS; |
143 | else DebugOut.StatusRed &= ~AMPEL_COMPASS; // MK3Mag green status |
143 | else DebugOut.StatusRed &= ~AMPEL_COMPASS; // MK3Mag green status |
144 | 144 | ||
145 | if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.StatusRed |= AMPEL_BL; |
145 | if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.StatusRed |= AMPEL_BL; |
146 | else DebugOut.StatusRed &= ~AMPEL_BL; // BL-Ctrl green status |
146 | else DebugOut.StatusRed &= ~AMPEL_BL; // BL-Ctrl green status |
147 | 147 | ||
148 | if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.StatusRed |= AMPEL_NC; |
148 | if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.StatusRed |= AMPEL_NC; |
149 | else DebugOut.StatusRed &= ~AMPEL_NC; |
149 | else DebugOut.StatusRed &= ~AMPEL_NC; |
150 | 150 | ||
151 | if(CheckDelay(SPI0_Timeout)) |
151 | if(CheckDelay(SPI0_Timeout)) |
152 | { |
152 | { |
153 | LED_RED_ON; |
153 | LED_RED_ON; |
154 | sprintf(ErrorMSG,"no FC communication "); |
154 | sprintf(ErrorMSG,"no FC communication "); |
155 | newErrorCode = 3; |
155 | newErrorCode = 3; |
156 | StopNavigation = 1; |
156 | StopNavigation = 1; |
157 | DebugOut.StatusGreen &= ~AMPEL_FC; // status of FC Present |
157 | DebugOut.StatusGreen &= ~AMPEL_FC; // status of FC Present |
158 | DebugOut.StatusGreen &= ~AMPEL_BL; // status of BL Present |
158 | DebugOut.StatusGreen &= ~AMPEL_BL; // status of BL Present |
159 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_SPI_RX; |
159 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_SPI_RX; |
160 | } |
160 | } |
161 | else if(CheckDelay(I2C1_Timeout)) |
161 | else if(CheckDelay(I2C1_Timeout)) |
162 | { |
162 | { |
163 | LED_RED_ON; |
163 | LED_RED_ON; |
164 | sprintf(ErrorMSG,"no compass communication "); |
164 | sprintf(ErrorMSG,"no compass communication "); |
165 | //Reset I2CBus |
165 | //Reset I2CBus |
166 | I2C1_Deinit(); |
166 | I2C1_Deinit(); |
167 | I2C1_Init(); |
167 | I2C1_Init(); |
168 | newErrorCode = 4; |
168 | newErrorCode = 4; |
169 | StopNavigation = 1; |
169 | StopNavigation = 1; |
170 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
170 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
171 | DebugOut.StatusRed |= AMPEL_COMPASS; |
171 | DebugOut.StatusRed |= AMPEL_COMPASS; |
172 | } |
172 | } |
173 | else if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
173 | else if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
174 | { |
174 | { |
175 | LED_RED_ON; |
175 | LED_RED_ON; |
176 | #ifndef FOLLOW_ME |
176 | #ifndef FOLLOW_ME |
177 | sprintf(ErrorMSG,"FC not compatible "); |
177 | sprintf(ErrorMSG,"FC not compatible "); |
178 | #else |
178 | #else |
179 | sprintf(ErrorMSG,"! FollowMe only ! "); |
179 | sprintf(ErrorMSG,"! FollowMe only ! "); |
180 | #endif |
180 | #endif |
181 | newErrorCode = 1; |
181 | newErrorCode = 1; |
182 | StopNavigation = 1; |
182 | StopNavigation = 1; |
183 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE; |
183 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE; |
184 | DebugOut.StatusRed |= AMPEL_NC; |
184 | DebugOut.StatusRed |= AMPEL_NC; |
185 | } |
185 | } |
186 | 186 | ||
187 | else if(FC.Error[0] & FC_ERROR0_GYRO_NICK) |
187 | else if(FC.Error[0] & FC_ERROR0_GYRO_NICK) |
188 | { |
188 | { |
189 | LED_RED_ON; |
189 | LED_RED_ON; |
190 | sprintf(ErrorMSG,"ERR: FC Nick Gyro"); |
190 | sprintf(ErrorMSG,"ERR: FC Nick Gyro"); |
191 | newErrorCode = 10; |
191 | newErrorCode = 10; |
192 | } |
192 | } |
193 | else if(FC.Error[0] & FC_ERROR0_GYRO_ROLL) |
193 | else if(FC.Error[0] & FC_ERROR0_GYRO_ROLL) |
194 | { |
194 | { |
195 | LED_RED_ON; |
195 | LED_RED_ON; |
196 | sprintf(ErrorMSG,"ERR: FC Roll Gyro"); |
196 | sprintf(ErrorMSG,"ERR: FC Roll Gyro"); |
197 | newErrorCode = 11; |
197 | newErrorCode = 11; |
198 | } |
198 | } |
199 | else if(FC.Error[0] & FC_ERROR0_GYRO_YAW) |
199 | else if(FC.Error[0] & FC_ERROR0_GYRO_YAW) |
200 | { |
200 | { |
201 | LED_RED_ON; |
201 | LED_RED_ON; |
202 | sprintf(ErrorMSG,"ERR: FC Yaw Gyro"); |
202 | sprintf(ErrorMSG,"ERR: FC Yaw Gyro"); |
203 | newErrorCode = 12; |
203 | newErrorCode = 12; |
204 | } |
204 | } |
205 | else if(FC.Error[0] & FC_ERROR0_ACC_NICK) |
205 | else if(FC.Error[0] & FC_ERROR0_ACC_NICK) |
206 | { |
206 | { |
207 | LED_RED_ON; |
207 | LED_RED_ON; |
208 | sprintf(ErrorMSG,"ERR: FC Nick ACC"); |
208 | sprintf(ErrorMSG,"ERR: FC Nick ACC"); |
209 | newErrorCode = 13; |
209 | newErrorCode = 13; |
210 | } |
210 | } |
211 | else if(FC.Error[0] & FC_ERROR0_ACC_ROLL) |
211 | else if(FC.Error[0] & FC_ERROR0_ACC_ROLL) |
212 | { |
212 | { |
213 | LED_RED_ON; |
213 | LED_RED_ON; |
214 | sprintf(ErrorMSG,"ERR: FC Roll ACC"); |
214 | sprintf(ErrorMSG,"ERR: FC Roll ACC"); |
215 | newErrorCode = 14; |
215 | newErrorCode = 14; |
216 | } |
216 | } |
217 | else if(FC.Error[0] & FC_ERROR0_ACC_TOP) |
217 | else if(FC.Error[0] & FC_ERROR0_ACC_TOP) |
218 | { |
218 | { |
219 | LED_RED_ON; |
219 | LED_RED_ON; |
220 | sprintf(ErrorMSG,"ERR:FC Z-ACC"); |
220 | sprintf(ErrorMSG,"ERR:FC Z-ACC"); |
221 | newErrorCode = 15; |
221 | newErrorCode = 15; |
222 | } |
222 | } |
223 | else if(NC_To_FC_Flags & NC_TO_FC_FLYING_RANGE) |
223 | else if(NC_To_FC_Flags & NC_TO_FC_FLYING_RANGE) |
224 | { |
224 | { |
225 | LED_RED_ON; |
225 | LED_RED_ON; |
226 | sprintf(ErrorMSG,"ERR:Flying range!"); |
226 | sprintf(ErrorMSG,"ERR:Flying range!"); |
227 | newErrorCode = 28; |
227 | newErrorCode = 28; |
228 | } |
228 | } |
229 | else if(FC.Error[0] & FC_ERROR0_PRESSURE) |
229 | else if(FC.Error[0] & FC_ERROR0_PRESSURE) |
230 | { |
230 | { |
231 | LED_RED_ON; |
231 | LED_RED_ON; |
232 | sprintf(ErrorMSG,"ERR:Pressure sensor"); |
232 | sprintf(ErrorMSG,"ERR:Pressure sensor"); |
233 | newErrorCode = 16; |
233 | newErrorCode = 16; |
234 | } |
234 | } |
235 | else if(FC.Error[1] & FC_ERROR1_I2C) |
235 | else if(FC.Error[1] & FC_ERROR1_I2C) |
236 | { |
236 | { |
237 | LED_RED_ON; |
237 | LED_RED_ON; |
238 | sprintf(ErrorMSG,"ERR:I2C FC to BL"); |
238 | sprintf(ErrorMSG,"ERR:I2C FC to BL"); |
239 | newErrorCode = 17; |
239 | newErrorCode = 17; |
240 | } |
240 | } |
241 | else if(FC.Error[1] & FC_ERROR1_BL_MISSING) |
241 | else if(FC.Error[1] & FC_ERROR1_BL_MISSING) |
242 | { |
242 | { |
243 | LED_RED_ON; |
243 | LED_RED_ON; |
244 | sprintf(ErrorMSG,"ERR: Bl Missing"); |
244 | sprintf(ErrorMSG,"ERR: Bl Missing"); |
245 | newErrorCode = 18; |
245 | newErrorCode = 18; |
246 | } |
246 | } |
247 | else if(FC.Error[1] & FC_ERROR1_MIXER) |
247 | else if(FC.Error[1] & FC_ERROR1_MIXER) |
248 | { |
248 | { |
249 | LED_RED_ON; |
249 | LED_RED_ON; |
250 | sprintf(ErrorMSG,"Mixer Error"); |
250 | sprintf(ErrorMSG,"Mixer Error"); |
251 | newErrorCode = 19; |
251 | newErrorCode = 19; |
252 | } |
252 | } |
253 | else if(CheckDelay(UBX_Timeout) && Parameter.GlobalConfig & FC_CFG_GPS_AKTIV) |
253 | else if(CheckDelay(UBX_Timeout) && Parameter.GlobalConfig & FC_CFG_GPS_AKTIV) |
254 | { |
254 | { |
255 | LED_RED_ON; |
255 | LED_RED_ON; |
256 | // if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected "); |
256 | // if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected "); |
257 | // else |
257 | // else |
258 | { |
258 | { |
259 | sprintf(ErrorMSG,"no GPS communication "); |
259 | sprintf(ErrorMSG,"no GPS communication "); |
260 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX; |
260 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX; |
261 | newErrorCode = 5; |
261 | newErrorCode = 5; |
262 | } |
262 | } |
263 | StopNavigation = 1; |
263 | StopNavigation = 1; |
264 | // UBX_Timeout = SetDelay(500); |
264 | // UBX_Timeout = SetDelay(500); |
265 | } |
265 | } |
266 | else if(Compass_Heading < 0) |
266 | else if(Compass_Heading < 0) |
267 | { |
267 | { |
268 | LED_RED_ON; |
268 | LED_RED_ON; |
269 | sprintf(ErrorMSG,"bad compass value "); |
269 | sprintf(ErrorMSG,"bad compass value "); |
270 | newErrorCode = 6; |
270 | newErrorCode = 6; |
271 | StopNavigation = 1; |
271 | StopNavigation = 1; |
272 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
272 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
273 | } |
273 | } |
274 | else if((FC.Error[1] & FC_ERROR1_SPI_RX)) |
274 | else if((FC.Error[1] & FC_ERROR1_SPI_RX)) |
275 | { |
275 | { |
276 | LED_RED_ON; |
276 | LED_RED_ON; |
277 | sprintf(ErrorMSG,"FC spi rx error "); |
277 | sprintf(ErrorMSG,"FC spi rx error "); |
278 | newErrorCode = 8; |
278 | newErrorCode = 8; |
279 | StopNavigation = 1; |
279 | StopNavigation = 1; |
280 | } |
280 | } |
281 | else if(FC.Error[0] & FC_ERROR0_CAREFREE) |
281 | else if(FC.Error[0] & FC_ERROR0_CAREFREE) |
282 | { |
282 | { |
283 | LED_RED_ON; |
283 | LED_RED_ON; |
284 | sprintf(ErrorMSG,"FC: Carefree Error"); |
284 | sprintf(ErrorMSG,"FC: Carefree Error"); |
285 | newErrorCode = 20; |
285 | newErrorCode = 20; |
286 | } |
286 | } |
287 | else if(FC.Error[1] & FC_ERROR1_PPM) |
287 | else if(FC.Error[1] & FC_ERROR1_PPM) |
288 | { |
288 | { |
289 | LED_RED_ON; |
289 | LED_RED_ON; |
290 | sprintf(ErrorMSG,"RC Signal lost "); |
290 | sprintf(ErrorMSG,"RC Signal lost "); |
291 | newErrorCode = 7; |
291 | newErrorCode = 7; |
292 | } |
292 | } |
293 | else if(ErrorGpsFixLost) |
293 | else if(ErrorGpsFixLost) |
294 | { |
294 | { |
295 | LED_RED_ON; |
295 | LED_RED_ON; |
296 | sprintf(ErrorMSG,"GPS Fix lost "); |
296 | sprintf(ErrorMSG,"GPS Fix lost "); |
297 | newErrorCode = 21; |
297 | newErrorCode = 21; |
298 | } |
298 | } |
299 | else if(ErrorDisturbedEarthMagnetField) |
299 | else if(ErrorDisturbedEarthMagnetField) |
300 | { |
300 | { |
301 | LED_RED_ON; |
301 | LED_RED_ON; |
302 | sprintf(ErrorMSG,"Magnet error "); |
302 | sprintf(ErrorMSG,"Magnet error "); |
303 | newErrorCode = 22; |
303 | newErrorCode = 22; |
304 | DebugOut.StatusRed |= AMPEL_COMPASS | AMPEL_NC; |
304 | DebugOut.StatusRed |= AMPEL_COMPASS | AMPEL_NC; |
305 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
305 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
306 | } |
306 | } |
307 | else if(BL_MinOfMaxPWM == 40 && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
307 | else if(BL_MinOfMaxPWM == 40 && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
308 | { |
308 | { |
309 | LED_RED_ON; |
309 | LED_RED_ON; |
310 | sprintf(ErrorMSG,"ERR:Motor restart "); |
310 | sprintf(ErrorMSG,"ERR:Motor restart "); |
311 | newErrorCode = 23; |
311 | newErrorCode = 23; |
312 | DebugOut.StatusRed |= AMPEL_BL; |
312 | DebugOut.StatusRed |= AMPEL_BL; |
313 | } |
313 | } |
314 | else if(BL_MinOfMaxPWM != 255 && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
314 | else if(BL_MinOfMaxPWM != 255 && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
315 | { |
315 | { |
316 | LED_RED_ON; |
316 | LED_RED_ON; |
317 | sprintf(ErrorMSG,"ERR:BL Limitation "); |
317 | sprintf(ErrorMSG,"ERR:BL Limitation "); |
318 | newErrorCode = 24; |
318 | newErrorCode = 24; |
319 | DebugOut.StatusRed |= AMPEL_BL; |
319 | DebugOut.StatusRed |= AMPEL_BL; |
320 | } |
320 | } |
321 | else if(NCFlags & NC_FLAG_RANGE_LIMIT && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
321 | else if(NCFlags & NC_FLAG_RANGE_LIMIT && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode) |
322 | { |
322 | { |
323 | LED_RED_ON; |
323 | LED_RED_ON; |
324 | sprintf(ErrorMSG,"ERR:GPS range "); |
324 | sprintf(ErrorMSG,"ERR:GPS range "); |
325 | newErrorCode = 25; |
325 | newErrorCode = 25; |
326 | DebugOut.StatusRed |= AMPEL_NC; |
326 | DebugOut.StatusRed |= AMPEL_NC; |
327 | } |
327 | } |
328 | else if(!SD_SWITCH && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START) |
328 | else if(!SD_SWITCH && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START) |
329 | { |
329 | { |
330 | LED_RED_ON; |
330 | LED_RED_ON; |
331 | sprintf(ErrorMSG,"ERR:No SD-Card "); |
331 | sprintf(ErrorMSG,"ERR:No SD-Card "); |
332 | newErrorCode = 26; |
332 | newErrorCode = 26; |
333 | DebugOut.StatusRed |= AMPEL_NC; |
333 | DebugOut.StatusRed |= AMPEL_NC; |
334 | } |
334 | } |
335 | else if(SD_LoggingError && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START) |
335 | else if(SD_LoggingError && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START) |
336 | { |
336 | { |
337 | LED_RED_ON; |
337 | LED_RED_ON; |
338 | sprintf(ErrorMSG,"ERR:SD Logging aborted"); |
338 | sprintf(ErrorMSG,"ERR:SD Logging aborted"); |
339 | newErrorCode = 27; |
339 | newErrorCode = 27; |
340 | DebugOut.StatusRed |= AMPEL_NC; |
340 | DebugOut.StatusRed |= AMPEL_NC; |
341 | SD_LoggingError = 0; |
341 | SD_LoggingError = 0; |
342 | } |
342 | } |
- | 343 | else if(((AbsoluteFlyingAltitude) && (NaviData.Altimeter / 20 >= AbsoluteFlyingAltitude)) && (FC.StatusFlags & FC_STATUS_FLY)) |
|
- | 344 | { |
|
- | 345 | LED_RED_ON; |
|
- | 346 | sprintf(ErrorMSG,"ERR:Max Altitude "); |
|
- | 347 | newErrorCode = 29; |
|
- | 348 | DebugOut.StatusRed |= AMPEL_NC; |
|
- | 349 | } |
|
343 | else // no error occured |
350 | else // no error occured |
344 | { |
351 | { |
345 | StopNavigation = 0; |
352 | StopNavigation = 0; |
346 | LED_RED_OFF; |
353 | LED_RED_OFF; |
347 | if(no_error_delay) { no_error_delay--; } |
354 | if(no_error_delay) { no_error_delay--; } |
348 | else |
355 | else |
349 | { |
356 | { |
350 | sprintf(ErrorMSG,"No Error "); |
357 | sprintf(ErrorMSG,"No Error "); |
351 | ErrorCode = 0; |
358 | ErrorCode = 0; |
352 | } |
359 | } |
353 | } |
360 | } |
354 | 361 | ||
355 | if(newErrorCode) |
362 | if(newErrorCode) |
356 | { |
363 | { |
357 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) no_error_delay = 8; // delay the errors if the motors are running |
364 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) no_error_delay = 8; // delay the errors if the motors are running |
358 | ErrorCode = newErrorCode; |
365 | ErrorCode = newErrorCode; |
359 | } |
366 | } |
360 | FC.Error[0] = 0; |
367 | FC.Error[0] = 0; |
361 | FC.Error[1] = 0; |
368 | FC.Error[1] = 0; |
362 | FC.Error[2] = 0; |
369 | FC.Error[2] = 0; |
363 | FC.Error[3] = 0; |
370 | FC.Error[3] = 0; |
364 | FC.Error[4] = 0; |
371 | FC.Error[4] = 0; |
365 | ErrorGpsFixLost = 0; |
372 | ErrorGpsFixLost = 0; |
366 | } |
373 | } |
367 | 374 | ||
368 | // the handler will be cyclic called by the timer 1 ISR |
375 | // the handler will be cyclic called by the timer 1 ISR |
369 | // used is for critical timing parts that normaly would handled |
376 | // used is for critical timing parts that normaly would handled |
370 | // within the main loop that could block longer at logging activities |
377 | // within the main loop that could block longer at logging activities |
371 | void EXTIT3_IRQHandler(void) |
378 | void EXTIT3_IRQHandler(void) |
372 | { |
379 | { |
373 | IENABLE; |
380 | IENABLE; |
374 | 381 | ||
375 | VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq |
382 | VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq |
376 | VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit |
383 | VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit |
377 | Compass_Update(); // update compass communication |
384 | Compass_Update(); // update compass communication |
378 | Analog_Update(); // get new ADC values |
385 | Analog_Update(); // get new ADC values |
379 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq |
386 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq |
380 | 387 | ||
381 | IDISABLE; |
388 | IDISABLE; |
382 | } |
389 | } |
383 | 390 | ||
384 | //---------------------------------------------------------------------------------------------------- |
391 | //---------------------------------------------------------------------------------------------------- |
385 | int main(void) |
392 | int main(void) |
386 | { |
393 | { |
387 | /* |
394 | /* |
388 | static u32 ftimer =0; |
395 | static u32 ftimer =0; |
389 | static u8 fstate = 0; |
396 | static u8 fstate = 0; |
390 | static File_t* f = NULL; |
397 | static File_t* f = NULL; |
391 | */ |
398 | */ |
392 | 399 | ||
393 | /* Configure the system clocks */ |
400 | /* Configure the system clocks */ |
394 | SCU_Config(); |
401 | SCU_Config(); |
395 | /* init VIC (Vectored Interrupt Controller) */ |
402 | /* init VIC (Vectored Interrupt Controller) */ |
396 | SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC |
403 | SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC |
397 | SCU_AHBPeriphReset(__VIC, DISABLE); // disable reset state for VIC |
404 | SCU_AHBPeriphReset(__VIC, DISABLE); // disable reset state for VIC |
398 | VIC_DeInit(); // deinitializes the VIC module registers to their default reset values. |
405 | VIC_DeInit(); // deinitializes the VIC module registers to their default reset values. |
399 | VIC_InitDefaultVectors(); |
406 | VIC_InitDefaultVectors(); |
400 | 407 | ||
401 | // initialize timer 1 for System Clock and delay rountines |
408 | // initialize timer 1 for System Clock and delay rountines |
402 | TIMER1_Init(); |
409 | TIMER1_Init(); |
403 | // initialize the LEDs (needs Timer 1) |
410 | // initialize the LEDs (needs Timer 1) |
404 | Led_Init(); |
411 | Led_Init(); |
405 | // initialize the debug UART1 |
412 | // initialize the debug UART1 |
406 | UART1_Init(); |
413 | UART1_Init(); |
407 | UART1_PutString("\r\n---------------------------------------------"); |
414 | UART1_PutString("\r\n---------------------------------------------"); |
408 | // initialize usb |
415 | // initialize usb |
409 | USB_ConfigInit(); |
416 | USB_ConfigInit(); |
410 | // initialize timer 2 for servo outputs |
417 | // initialize timer 2 for servo outputs |
411 | //TIMER2_Init(); |
418 | //TIMER2_Init(); |
412 | // initialize UART2 to FLIGHTCTRL |
419 | // initialize UART2 to FLIGHTCTRL |
413 | UART2_Init(); |
420 | UART2_Init(); |
414 | // initialize UART0 (to MKGPS or MK3MAG) |
421 | // initialize UART0 (to MKGPS or MK3MAG) |
415 | UART0_Init(); |
422 | UART0_Init(); |
416 | // initialize adc |
423 | // initialize adc |
417 | Analog_Init(); |
424 | Analog_Init(); |
418 | // initialize SPI0 to FC |
425 | // initialize SPI0 to FC |
419 | SPI0_Init(); |
426 | SPI0_Init(); |
420 | // initialize i2c bus (needs Timer 1) |
427 | // initialize i2c bus (needs Timer 1) |
421 | I2C1_Init(); |
428 | I2C1_Init(); |
422 | // initialize fat16 partition on sd card (needs Timer 1) |
429 | // initialize fat16 partition on sd card (needs Timer 1) |
423 | Fat16_Init(); |
430 | Fat16_Init(); |
424 | // initialize NC params |
431 | // initialize NC params |
425 | NCParams_Init(); |
432 | NCParams_Init(); |
426 | // initialize the settings |
433 | // initialize the settings |
427 | Settings_Init(); |
434 | Settings_Init(); |
428 | // initialize logging (needs settings) |
435 | // initialize logging (needs settings) |
429 | Logging_Init(); |
436 | Logging_Init(); |
430 | 437 | ||
431 | TimerCheckError = SetDelay(3000); |
438 | TimerCheckError = SetDelay(3000); |
432 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
439 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
433 | UART1_PutString("\n\r Version information:"); |
440 | UART1_PutString("\n\r Version information:"); |
434 | 441 | ||
435 | GetNaviCtrlVersion(); |
442 | GetNaviCtrlVersion(); |
436 | DebugOut.StatusGreen = AMPEL_NC | AMPEL_COMPASS; // NC and MK3Mag |
443 | DebugOut.StatusGreen = AMPEL_NC | AMPEL_COMPASS; // NC and MK3Mag |
437 | DebugOut.StatusRed = 0x00; |
444 | DebugOut.StatusRed = 0x00; |
438 | 445 | ||
439 | Compass_Init(); |
446 | Compass_Init(); |
440 | 447 | ||
441 | #ifdef FOLLOW_ME |
448 | #ifdef FOLLOW_ME |
442 | TransmitAlsoToFC = 1; |
449 | TransmitAlsoToFC = 1; |
443 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
450 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
444 | UART1_PutString("\n\r FOLLOW-ME Transmitter only!"); |
451 | UART1_PutString("\n\r FOLLOW-ME Transmitter only!"); |
445 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++\r\n\r\n"); |
452 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++\r\n\r\n"); |
446 | TransmitAlsoToFC = 0; |
453 | TransmitAlsoToFC = 0; |
447 | #else |
454 | #else |
448 | SPI0_GetFlightCtrlVersion(); |
455 | SPI0_GetFlightCtrlVersion(); |
449 | if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
456 | if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
450 | { |
457 | { |
451 | UART1_PutString("\n\r Flight-Ctrl not compatible"); |
458 | UART1_PutString("\n\r Flight-Ctrl not compatible"); |
452 | LED_RED_ON; |
459 | LED_RED_ON; |
453 | } |
460 | } |
454 | #endif |
461 | #endif |
455 | 462 | ||
456 | GPS_Init(); |
463 | GPS_Init(); |
457 | 464 | ||
458 | // ---------- Prepare the isr driven |
465 | // ---------- Prepare the isr driven |
459 | // set to absolute lowest priority |
466 | // set to absolute lowest priority |
460 | VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW); |
467 | VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW); |
461 | // enable interrupts |
468 | // enable interrupts |
462 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); |
469 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); |
463 | 470 | ||
464 | Debug_OK("START"); |
471 | Debug_OK("START"); |
465 | 472 | ||
466 | for (;;) // the endless main loop |
473 | for (;;) // the endless main loop |
467 | { |
474 | { |
468 | UART0_ProcessRxData(); // process request |
475 | UART0_ProcessRxData(); // process request |
469 | UART1_ProcessRxData(); // process request |
476 | UART1_ProcessRxData(); // process request |
470 | USB_ProcessRxData(); // process request |
477 | USB_ProcessRxData(); // process request |
471 | UART0_TransmitTxData(); // send answer |
478 | UART0_TransmitTxData(); // send answer |
472 | UART1_TransmitTxData(); // send answer |
479 | UART1_TransmitTxData(); // send answer |
473 | UART2_TransmitTxData(); // send answer |
480 | UART2_TransmitTxData(); // send answer |
474 | USB_TransmitTxData(); // send answer |
481 | USB_TransmitTxData(); // send answer |
475 | SPI0_UpdateBuffer(); // handle new SPI Data |
482 | SPI0_UpdateBuffer(); // handle new SPI Data |
476 | 483 | ||
477 | // ---------------- Error Check Timing ---------------------------- |
484 | // ---------------- Error Check Timing ---------------------------- |
478 | if(CheckDelay(TimerCheckError)) |
485 | if(CheckDelay(TimerCheckError)) |
479 | { |
486 | { |
480 | TimerCheckError = SetDelay(1000); |
487 | TimerCheckError = SetDelay(1000); |
481 | if(CheckDelay(SPI0_Timeout) && (DebugUART == UART1)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected |
488 | if(CheckDelay(SPI0_Timeout) && (DebugUART == UART1)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected |
482 | 489 | ||
483 | if(!CheckDelay(SPI0_Timeout) || (DebugUART == UART1)) CheckErrors(); |
490 | if(!CheckDelay(SPI0_Timeout) || (DebugUART == UART1)) CheckErrors(); |
484 | 491 | ||
485 | if(FC.StatusFlags & FC_STATUS_FLY) NaviData.FlyingTime++; // we want to count the battery-time |
492 | if(FC.StatusFlags & FC_STATUS_FLY) NaviData.FlyingTime++; // we want to count the battery-time |
486 | // else NaviData.FlyingTime = 0; // not the time per flight |
493 | // else NaviData.FlyingTime = 0; // not the time per flight |
487 | if(SerialLinkOkay) SerialLinkOkay--; |
494 | if(SerialLinkOkay) SerialLinkOkay--; |
488 | if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication |
495 | if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication |
489 | else NCFlags &= ~NC_FLAG_NOSERIALLINK; |
496 | else NCFlags &= ~NC_FLAG_NOSERIALLINK; |
490 | if(StopNavigation && (Parameter.NaviGpsModeControl >= 50) && (Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) BeepTime = 1000; |
497 | if(StopNavigation && (Parameter.NaviGpsModeControl >= 50) && (Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) BeepTime = 1000; |
491 | } |
498 | } |
492 | 499 | ||
493 | // ---------------- Logging --------------------------------------- |
500 | // ---------------- Logging --------------------------------------- |
494 | 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 |
501 | 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 |
495 | 502 | ||
496 | /* |
503 | /* |
497 | // test |
504 | // test |
498 | if(CheckDelay(ftimer)) |
505 | if(CheckDelay(ftimer)) |
499 | { |
506 | { |
500 | 507 | ||
501 | s8* filename = "test.txt"; |
508 | s8* filename = "test.txt"; |
502 | 509 | ||
503 | ftimer = SetDelay(100); |
510 | ftimer = SetDelay(100); |
504 | if(FC.Poti[3]>100 && fstate == 0) |
511 | if(FC.Poti[3]>100 && fstate == 0) |
505 | { |
512 | { |
506 | fstate = 1; |
513 | fstate = 1; |
507 | } |
514 | } |
508 | else if(FC.Poti[3]<100 && fstate == 2) |
515 | else if(FC.Poti[3]<100 && fstate == 2) |
509 | { |
516 | { |
510 | fstate = 3; |
517 | fstate = 3; |
511 | } |
518 | } |
512 | 519 | ||
513 | switch(fstate) |
520 | switch(fstate) |
514 | { |
521 | { |
515 | case 1: |
522 | case 1: |
516 | sprintf(text,"\r\nStart writing file: %s", filename); |
523 | sprintf(text,"\r\nStart writing file: %s", filename); |
517 | UART1_PutString(text); |
524 | UART1_PutString(text); |
518 | f = fopen_(filename, 'a'); |
525 | f = fopen_(filename, 'a'); |
519 | if(f== NULL) Fat16_Init(); |
526 | if(f== NULL) Fat16_Init(); |
520 | fstate = 2; |
527 | fstate = 2; |
521 | break; |
528 | break; |
522 | 529 | ||
523 | case 2: |
530 | case 2: |
524 | fputs_("\r\ntest edins sdv dsivbds iv dsivb disbv idsv bisd bv d suiv dsibsivbdis fbvisdöb visdbvisdb vidbfibds ibv", f); |
531 | fputs_("\r\ntest edins sdv dsivbds iv dsivb disbv idsv bisd bv d suiv dsibsivbdis fbvisdöb visdbvisdb vidbfibds ibv", f); |
525 | break; |
532 | break; |
526 | |
533 | |
527 | case 3: |
534 | case 3: |
528 | sprintf(text,"\r\nClosing file: %s", filename); |
535 | sprintf(text,"\r\nClosing file: %s", filename); |
529 | UART1_PutString(text); |
536 | UART1_PutString(text); |
530 | fclose_(f); |
537 | fclose_(f); |
531 | fstate = 0; |
538 | fstate = 0; |
532 | break; |
539 | break; |
533 | 540 | ||
534 | default: |
541 | default: |
535 | break; |
542 | break; |
536 | } |
543 | } |
537 | } |
544 | } |
538 | */ |
545 | */ |
539 | } |
546 | } |
540 | } |
547 | } |
541 | 548 | ||
542 | // DebugOut.Analog[] |
549 | // DebugOut.Analog[] |
543 | 550 |