Rev 329 | Rev 331 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 329 | Rev 330 | ||
---|---|---|---|
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 | 83 | ||
84 | #ifdef FOLLOW_ME |
84 | #ifdef FOLLOW_ME |
85 | u8 TransmitAlsoToFC = 0; |
85 | u8 TransmitAlsoToFC = 0; |
86 | #endif |
86 | #endif |
87 | u32 TimerCheckError; |
87 | u32 TimerCheckError; |
88 | u8 ErrorCode = 0; |
88 | u8 ErrorCode = 0; |
89 | u16 BeepTime; |
89 | u16 BeepTime; |
90 | u8 NCFlags = 0; |
90 | u8 NCFlags = 0; |
91 | s16 GeoMagDec = 0; // local magnetic declination in 0.1 deg |
91 | s16 GeoMagDec = 0; // local magnetic declination in 0.1 deg |
92 | u8 ErrorGpsFixLost = 0; |
92 | u8 ErrorGpsFixLost = 0; |
93 | 93 | ||
94 | u8 ClearFCStatusFlags = 0; |
94 | u8 ClearFCStatusFlags = 0; |
95 | u8 StopNavigation = 0; |
95 | u8 StopNavigation = 0; |
96 | Param_t Parameter; |
96 | Param_t Parameter; |
97 | volatile FC_t FC; |
97 | volatile FC_t FC; |
98 | 98 | ||
99 | s8 ErrorMSG[25]; |
99 | s8 ErrorMSG[25]; |
100 | 100 | ||
101 | //---------------------------------------------------------------------------------------------------- |
101 | //---------------------------------------------------------------------------------------------------- |
102 | void SCU_Config(void) |
102 | void SCU_Config(void) |
103 | { |
103 | { |
104 | /* configure PLL and set it as master clock source */ |
104 | /* configure PLL and set it as master clock source */ |
105 | SCU_MCLKSourceConfig(SCU_MCLK_OSC); // set master clock source to external oscillator clock (25MHz) before diabling the PLL |
105 | SCU_MCLKSourceConfig(SCU_MCLK_OSC); // set master clock source to external oscillator clock (25MHz) before diabling the PLL |
106 | SCU_PLLCmd(DISABLE); // now disable the PLL |
106 | SCU_PLLCmd(DISABLE); // now disable the PLL |
107 | #ifdef MCLK96MHZ |
107 | #ifdef MCLK96MHZ |
108 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div2); // set BRCLK to MCLK/2 = 48MHz |
108 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div2); // set BRCLK to MCLK/2 = 48MHz |
109 | SCU_PCLKDivisorConfig(SCU_PCLK_Div4); // set PCLK (APB bus clock) divisor to 4 (half Reference Clock) |
109 | SCU_PCLKDivisorConfig(SCU_PCLK_Div4); // set PCLK (APB bus clock) divisor to 4 (half Reference Clock) |
110 | SCU_RCLKDivisorConfig(SCU_RCLK_Div2); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
110 | SCU_RCLKDivisorConfig(SCU_RCLK_Div2); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
111 | SCU_HCLKDivisorConfig(SCU_HCLK_Div2); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
111 | SCU_HCLKDivisorConfig(SCU_HCLK_Div2); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
112 | SCU_PLLFactorsConfig(192,25,2); // PLL = 96 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=2 |
112 | SCU_PLLFactorsConfig(192,25,2); // PLL = 96 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=2 |
113 | #else |
113 | #else |
114 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div1); // set BRCLK to MCLK = 48MHz |
114 | SCU_BRCLKDivisorConfig(SCU_BRCLK_Div1); // set BRCLK to MCLK = 48MHz |
115 | SCU_PCLKDivisorConfig(SCU_PCLK_Div2); // set PCLK (APB bus clock) divisor to 2 (half Reference Clock) |
115 | SCU_PCLKDivisorConfig(SCU_PCLK_Div2); // set PCLK (APB bus clock) divisor to 2 (half Reference Clock) |
116 | SCU_RCLKDivisorConfig(SCU_RCLK_Div1); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
116 | SCU_RCLKDivisorConfig(SCU_RCLK_Div1); // set RCLK (Reference Clock) divisor to 1 (full PPL clock) |
117 | SCU_HCLKDivisorConfig(SCU_HCLK_Div1); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
117 | SCU_HCLKDivisorConfig(SCU_HCLK_Div1); // set HCLK (AHB bus clock) divisor to 1 (full Reference Clock) |
118 | SCU_PLLFactorsConfig(192,25,3); // PLL = 48 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=3 |
118 | SCU_PLLFactorsConfig(192,25,3); // PLL = 48 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=3 |
119 | #endif |
119 | #endif |
120 | SCU_PLLCmd(ENABLE); // Enable PLL (is disabled by SCU_PLLFactorsConfig) |
120 | SCU_PLLCmd(ENABLE); // Enable PLL (is disabled by SCU_PLLFactorsConfig) |
121 | SCU_MCLKSourceConfig(SCU_MCLK_PLL); // set master clock source to PLL |
121 | SCU_MCLKSourceConfig(SCU_MCLK_PLL); // set master clock source to PLL |
122 | } |
122 | } |
123 | 123 | ||
124 | //---------------------------------------------------------------------------------------------------- |
124 | //---------------------------------------------------------------------------------------------------- |
125 | void GetNaviCtrlVersion(void) |
125 | void GetNaviCtrlVersion(void) |
126 | { |
126 | { |
127 | u8 msg[25]; |
127 | u8 msg[25]; |
128 | 128 | ||
129 | 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); |
129 | 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 | UART1_PutString(msg); |
130 | UART1_PutString(msg); |
131 | } |
131 | } |
132 | 132 | ||
133 | //---------------------------------------------------------------------------------------------------- |
133 | //---------------------------------------------------------------------------------------------------- |
134 | 134 | ||
135 | void CheckErrors(void) |
135 | void CheckErrors(void) |
136 | { |
136 | { |
137 | static s32 no_error_delay = 0; |
137 | static s32 no_error_delay = 0; |
138 | s32 newErrorCode = 0; |
138 | s32 newErrorCode = 0; |
139 | UART_VersionInfo.HardwareError[0] = 0; |
139 | UART_VersionInfo.HardwareError[0] = 0; |
140 | 140 | ||
141 | if(CheckDelay(I2C1_Timeout) || (Compass_Heading < 0)) DebugOut.Status[1] |= 0x08; |
141 | if(CheckDelay(I2C1_Timeout) || (Compass_Heading < 0)) DebugOut.Status[1] |= 0x08; |
142 | else DebugOut.Status[1] &= ~0x08; // MK3Mag green status |
142 | else DebugOut.Status[1] &= ~0x08; // MK3Mag green status |
143 | 143 | ||
144 | if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.Status[1] |= 0x02; |
144 | if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.Status[1] |= 0x02; |
145 | else DebugOut.Status[1] &= ~0x02; // BL-Ctrl green status |
145 | else DebugOut.Status[1] &= ~0x02; // BL-Ctrl green status |
146 | 146 | ||
147 | if(CheckDelay(SPI0_Timeout)) |
147 | if(CheckDelay(SPI0_Timeout)) |
148 | { |
148 | { |
149 | LED_RED_ON; |
149 | LED_RED_ON; |
150 | sprintf(ErrorMSG,"no FC communication "); |
150 | sprintf(ErrorMSG,"no FC communication "); |
151 | newErrorCode = 3; |
151 | newErrorCode = 3; |
152 | StopNavigation = 1; |
152 | StopNavigation = 1; |
153 | DebugOut.Status[0] &= ~0x01; // status of FC Present |
153 | DebugOut.Status[0] &= ~0x01; // status of FC Present |
154 | DebugOut.Status[0] &= ~0x02; // status of BL Present |
154 | DebugOut.Status[0] &= ~0x02; // status of BL Present |
155 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_SPI_RX; |
155 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_SPI_RX; |
156 | } |
156 | } |
157 | else if(CheckDelay(I2C1_Timeout)) |
157 | else if(CheckDelay(I2C1_Timeout)) |
158 | { |
158 | { |
159 | LED_RED_ON; |
159 | LED_RED_ON; |
160 | sprintf(ErrorMSG,"no compass communication "); |
160 | sprintf(ErrorMSG,"no compass communication "); |
161 | //Reset I2CBus |
161 | //Reset I2CBus |
162 | I2C1_Deinit(); |
162 | I2C1_Deinit(); |
163 | I2C1_Init(); |
163 | I2C1_Init(); |
164 | newErrorCode = 4; |
164 | newErrorCode = 4; |
165 | StopNavigation = 1; |
165 | StopNavigation = 1; |
166 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
166 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
167 | DebugOut.Status[1] |= 0x08; |
167 | DebugOut.Status[1] |= 0x08; |
168 | } |
168 | } |
169 | else if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
169 | else if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
170 | { |
170 | { |
171 | LED_RED_ON; |
171 | LED_RED_ON; |
172 | #ifndef FOLLOW_ME |
172 | #ifndef FOLLOW_ME |
173 | sprintf(ErrorMSG,"FC not compatible "); |
173 | sprintf(ErrorMSG,"FC not compatible "); |
174 | #else |
174 | #else |
175 | sprintf(ErrorMSG,"! FollowMe only ! "); |
175 | sprintf(ErrorMSG,"! FollowMe only ! "); |
176 | #endif |
176 | #endif |
177 | newErrorCode = 1; |
177 | newErrorCode = 1; |
178 | StopNavigation = 1; |
178 | StopNavigation = 1; |
179 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE; |
179 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE; |
180 | } |
180 | } |
181 | 181 | ||
182 | else if(FC.Error[0] & FC_ERROR0_GYRO_NICK) |
182 | else if(FC.Error[0] & FC_ERROR0_GYRO_NICK) |
183 | { |
183 | { |
184 | LED_RED_ON; |
184 | LED_RED_ON; |
185 | sprintf(ErrorMSG,"ERR: FC Nick Gyro"); |
185 | sprintf(ErrorMSG,"ERR: FC Nick Gyro"); |
186 | newErrorCode = 10; |
186 | newErrorCode = 10; |
187 | } |
187 | } |
188 | else if(FC.Error[0] & FC_ERROR0_GYRO_ROLL) |
188 | else if(FC.Error[0] & FC_ERROR0_GYRO_ROLL) |
189 | { |
189 | { |
190 | LED_RED_ON; |
190 | LED_RED_ON; |
191 | sprintf(ErrorMSG,"ERR: FC Roll Gyro"); |
191 | sprintf(ErrorMSG,"ERR: FC Roll Gyro"); |
192 | newErrorCode = 11; |
192 | newErrorCode = 11; |
193 | } |
193 | } |
194 | else if(FC.Error[0] & FC_ERROR0_GYRO_YAW) |
194 | else if(FC.Error[0] & FC_ERROR0_GYRO_YAW) |
195 | { |
195 | { |
196 | LED_RED_ON; |
196 | LED_RED_ON; |
197 | sprintf(ErrorMSG,"ERR: FC Yaw Gyro"); |
197 | sprintf(ErrorMSG,"ERR: FC Yaw Gyro"); |
198 | newErrorCode = 12; |
198 | newErrorCode = 12; |
199 | } |
199 | } |
200 | else if(FC.Error[0] & FC_ERROR0_ACC_NICK) |
200 | else if(FC.Error[0] & FC_ERROR0_ACC_NICK) |
201 | { |
201 | { |
202 | LED_RED_ON; |
202 | LED_RED_ON; |
203 | sprintf(ErrorMSG,"ERR: FC Nick ACC"); |
203 | sprintf(ErrorMSG,"ERR: FC Nick ACC"); |
204 | newErrorCode = 13; |
204 | newErrorCode = 13; |
205 | } |
205 | } |
206 | else if(FC.Error[0] & FC_ERROR0_ACC_ROLL) |
206 | else if(FC.Error[0] & FC_ERROR0_ACC_ROLL) |
207 | { |
207 | { |
208 | LED_RED_ON; |
208 | LED_RED_ON; |
209 | sprintf(ErrorMSG,"ERR: FC Roll ACC"); |
209 | sprintf(ErrorMSG,"ERR: FC Roll ACC"); |
210 | newErrorCode = 14; |
210 | newErrorCode = 14; |
211 | } |
211 | } |
212 | else if(FC.Error[0] & FC_ERROR0_ACC_TOP) |
212 | else if(FC.Error[0] & FC_ERROR0_ACC_TOP) |
213 | { |
213 | { |
214 | LED_RED_ON; |
214 | LED_RED_ON; |
215 | sprintf(ErrorMSG,"ERR:FC Z-ACC"); |
215 | sprintf(ErrorMSG,"ERR:FC Z-ACC"); |
216 | newErrorCode = 15; |
216 | newErrorCode = 15; |
217 | } |
217 | } |
218 | else if(FC.Error[0] & FC_ERROR0_PRESSURE) |
218 | else if(FC.Error[0] & FC_ERROR0_PRESSURE) |
219 | { |
219 | { |
220 | LED_RED_ON; |
220 | LED_RED_ON; |
221 | sprintf(ErrorMSG,"ERR:Pressure sensor"); |
221 | sprintf(ErrorMSG,"ERR:Pressure sensor"); |
222 | newErrorCode = 16; |
222 | newErrorCode = 16; |
223 | } |
223 | } |
224 | else if(FC.Error[1] & FC_ERROR1_I2C) |
224 | else if(FC.Error[1] & FC_ERROR1_I2C) |
225 | { |
225 | { |
226 | LED_RED_ON; |
226 | LED_RED_ON; |
227 | sprintf(ErrorMSG,"ERR:I2C FC to BL"); |
227 | sprintf(ErrorMSG,"ERR:I2C FC to BL"); |
228 | newErrorCode = 17; |
228 | newErrorCode = 17; |
229 | } |
229 | } |
230 | else if(FC.Error[1] & FC_ERROR1_BL_MISSING) |
230 | else if(FC.Error[1] & FC_ERROR1_BL_MISSING) |
231 | { |
231 | { |
232 | LED_RED_ON; |
232 | LED_RED_ON; |
233 | sprintf(ErrorMSG,"ERR: Bl Missing"); |
233 | sprintf(ErrorMSG,"ERR: Bl Missing"); |
234 | newErrorCode = 18; |
234 | newErrorCode = 18; |
235 | } |
235 | } |
236 | else if(FC.Error[1] & FC_ERROR1_MIXER) |
236 | else if(FC.Error[1] & FC_ERROR1_MIXER) |
237 | { |
237 | { |
238 | LED_RED_ON; |
238 | LED_RED_ON; |
239 | sprintf(ErrorMSG,"Mixer Error"); |
239 | sprintf(ErrorMSG,"Mixer Error"); |
240 | newErrorCode = 19; |
240 | newErrorCode = 19; |
241 | } |
241 | } |
242 | else if(CheckDelay(UBX_Timeout)) |
242 | else if(CheckDelay(UBX_Timeout)) |
243 | { |
243 | { |
244 | LED_RED_ON; |
244 | LED_RED_ON; |
245 | if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected "); |
245 | if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected "); |
246 | else |
246 | else |
247 | { |
247 | { |
248 | sprintf(ErrorMSG,"no GPS communication "); |
248 | sprintf(ErrorMSG,"no GPS communication "); |
249 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX; |
249 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX; |
250 | newErrorCode = 5; |
250 | newErrorCode = 5; |
251 | } |
251 | } |
252 | StopNavigation = 1; |
252 | StopNavigation = 1; |
253 | // UBX_Timeout = SetDelay(500); |
253 | // UBX_Timeout = SetDelay(500); |
254 | } |
254 | } |
255 | else if(Compass_Heading < 0) |
255 | else if(Compass_Heading < 0) |
256 | { |
256 | { |
257 | LED_RED_ON; |
257 | LED_RED_ON; |
258 | sprintf(ErrorMSG,"bad compass value "); |
258 | sprintf(ErrorMSG,"bad compass value "); |
259 | newErrorCode = 6; |
259 | newErrorCode = 6; |
260 | StopNavigation = 1; |
260 | StopNavigation = 1; |
261 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
261 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
262 | } |
262 | } |
263 | else if((FC.Error[1] & FC_ERROR1_SPI_RX)) |
263 | else if((FC.Error[1] & FC_ERROR1_SPI_RX)) |
264 | { |
264 | { |
265 | LED_RED_ON; |
265 | LED_RED_ON; |
266 | sprintf(ErrorMSG,"FC spi rx error "); |
266 | sprintf(ErrorMSG,"FC spi rx error "); |
267 | newErrorCode = 8; |
267 | newErrorCode = 8; |
268 | StopNavigation = 1; |
268 | StopNavigation = 1; |
269 | } |
269 | } |
270 | else if(FC.Error[0] & FC_ERROR0_CAREFREE) |
270 | else if(FC.Error[0] & FC_ERROR0_CAREFREE) |
271 | { |
271 | { |
272 | LED_RED_ON; |
272 | LED_RED_ON; |
273 | sprintf(ErrorMSG,"FC: Carefree Error"); |
273 | sprintf(ErrorMSG,"FC: Carefree Error"); |
274 | newErrorCode = 20; |
274 | newErrorCode = 20; |
275 | } |
275 | } |
276 | else if(FC.Error[1] & FC_ERROR1_PPM) |
276 | else if(FC.Error[1] & FC_ERROR1_PPM) |
277 | { |
277 | { |
278 | LED_RED_ON; |
278 | LED_RED_ON; |
279 | sprintf(ErrorMSG,"RC Signal lost "); |
279 | sprintf(ErrorMSG,"RC Signal lost "); |
280 | newErrorCode = 7; |
280 | newErrorCode = 7; |
281 | } |
281 | } |
282 | else if(ErrorGpsFixLost) |
282 | else if(ErrorGpsFixLost) |
283 | { |
283 | { |
284 | LED_RED_ON; |
284 | LED_RED_ON; |
285 | sprintf(ErrorMSG,"GPS Fix lost "); |
285 | sprintf(ErrorMSG,"GPS Fix lost "); |
286 | newErrorCode = 21; |
286 | newErrorCode = 21; |
287 | } |
287 | } |
- | 288 | else if(ErrorDisturbedEarthMagnetField) |
|
- | 289 | { |
|
- | 290 | LED_RED_ON; |
|
- | 291 | sprintf(ErrorMSG,"Magnet error "); |
|
- | 292 | newErrorCode = 22; |
|
- | 293 | } |
|
288 | else // no error occured |
294 | else // no error occured |
289 | { |
295 | { |
290 | StopNavigation = 0; |
296 | StopNavigation = 0; |
291 | LED_RED_OFF; |
297 | LED_RED_OFF; |
292 | if(no_error_delay) { no_error_delay--; } |
298 | if(no_error_delay) { no_error_delay--; } |
293 | else |
299 | else |
294 | { |
300 | { |
295 | sprintf(ErrorMSG,"No Error "); |
301 | sprintf(ErrorMSG,"No Error "); |
296 | ErrorCode = 0; |
302 | ErrorCode = 0; |
297 | } |
303 | } |
298 | } |
304 | } |
299 | if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 0x04; |
305 | if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 0x04; |
300 | else DebugOut.Status[1] &= ~0x04; |
306 | else DebugOut.Status[1] &= ~0x04; |
301 | 307 | ||
302 | if(newErrorCode) |
308 | if(newErrorCode) |
303 | { |
309 | { |
304 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) no_error_delay = 5; // delay the errors if the motors are running |
310 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) no_error_delay = 5; // delay the errors if the motors are running |
305 | ErrorCode = newErrorCode; |
311 | ErrorCode = newErrorCode; |
306 | } |
312 | } |
307 | FC.Error[0] = 0; |
313 | FC.Error[0] = 0; |
308 | FC.Error[1] = 0; |
314 | FC.Error[1] = 0; |
309 | FC.Error[2] = 0; |
315 | FC.Error[2] = 0; |
310 | FC.Error[3] = 0; |
316 | FC.Error[3] = 0; |
311 | FC.Error[4] = 0; |
317 | FC.Error[4] = 0; |
312 | ErrorGpsFixLost = 0; |
318 | ErrorGpsFixLost = 0; |
313 | } |
319 | } |
314 | 320 | ||
315 | // the handler will be cyclic called by the timer 1 ISR |
321 | // the handler will be cyclic called by the timer 1 ISR |
316 | // used is for critical timing parts that normaly would handled |
322 | // used is for critical timing parts that normaly would handled |
317 | // within the main loop that could block longer at logging activities |
323 | // within the main loop that could block longer at logging activities |
318 | void EXTIT3_IRQHandler(void) |
324 | void EXTIT3_IRQHandler(void) |
319 | { |
325 | { |
320 | IENABLE; |
326 | IENABLE; |
321 | 327 | ||
322 | VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq |
328 | VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq |
323 | VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit |
329 | VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit |
324 | Compass_Update(); // update compass communication |
330 | Compass_Update(); // update compass communication |
325 | Analog_Update(); // get new ADC values |
331 | Analog_Update(); // get new ADC values |
326 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq |
332 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq |
327 | 333 | ||
328 | IDISABLE; |
334 | IDISABLE; |
329 | } |
335 | } |
330 | 336 | ||
331 | //---------------------------------------------------------------------------------------------------- |
337 | //---------------------------------------------------------------------------------------------------- |
332 | int main(void) |
338 | int main(void) |
333 | { |
339 | { |
334 | /* |
340 | /* |
335 | static u32 ftimer =0; |
341 | static u32 ftimer =0; |
336 | static u8 fstate = 0; |
342 | static u8 fstate = 0; |
337 | static File_t* f = NULL; |
343 | static File_t* f = NULL; |
338 | */ |
344 | */ |
339 | 345 | ||
340 | /* Configure the system clocks */ |
346 | /* Configure the system clocks */ |
341 | SCU_Config(); |
347 | SCU_Config(); |
342 | /* init VIC (Vectored Interrupt Controller) */ |
348 | /* init VIC (Vectored Interrupt Controller) */ |
343 | SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC |
349 | SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC |
344 | SCU_AHBPeriphReset(__VIC, DISABLE); // disable reset state for VIC |
350 | SCU_AHBPeriphReset(__VIC, DISABLE); // disable reset state for VIC |
345 | VIC_DeInit(); // deinitializes the VIC module registers to their default reset values. |
351 | VIC_DeInit(); // deinitializes the VIC module registers to their default reset values. |
346 | VIC_InitDefaultVectors(); |
352 | VIC_InitDefaultVectors(); |
347 | 353 | ||
348 | // initialize timer 1 for System Clock and delay rountines |
354 | // initialize timer 1 for System Clock and delay rountines |
349 | TIMER1_Init(); |
355 | TIMER1_Init(); |
350 | // initialize the LEDs (needs Timer 1) |
356 | // initialize the LEDs (needs Timer 1) |
351 | Led_Init(); |
357 | Led_Init(); |
352 | // initialize the debug UART1 |
358 | // initialize the debug UART1 |
353 | UART1_Init(); |
359 | UART1_Init(); |
354 | UART1_PutString("\r\n---------------------------------------------"); |
360 | UART1_PutString("\r\n---------------------------------------------"); |
355 | // initialize usb |
361 | // initialize usb |
356 | USB_ConfigInit(); |
362 | USB_ConfigInit(); |
357 | // initialize timer 2 for servo outputs |
363 | // initialize timer 2 for servo outputs |
358 | //TIMER2_Init(); |
364 | //TIMER2_Init(); |
359 | // initialize UART2 to FLIGHTCTRL |
365 | // initialize UART2 to FLIGHTCTRL |
360 | UART2_Init(); |
366 | UART2_Init(); |
361 | // initialize UART0 (to MKGPS or MK3MAG) |
367 | // initialize UART0 (to MKGPS or MK3MAG) |
362 | UART0_Init(); |
368 | UART0_Init(); |
363 | // initialize adc |
369 | // initialize adc |
364 | Analog_Init(); |
370 | Analog_Init(); |
365 | // initialize SPI0 to FC |
371 | // initialize SPI0 to FC |
366 | SPI0_Init(); |
372 | SPI0_Init(); |
367 | // initialize i2c bus (needs Timer 1) |
373 | // initialize i2c bus (needs Timer 1) |
368 | I2C1_Init(); |
374 | I2C1_Init(); |
369 | // initialize fat16 partition on sd card (needs Timer 1) |
375 | // initialize fat16 partition on sd card (needs Timer 1) |
370 | Fat16_Init(); |
376 | Fat16_Init(); |
371 | // initialize NC params |
377 | // initialize NC params |
372 | NCParams_Init(); |
378 | NCParams_Init(); |
373 | // initialize the settings |
379 | // initialize the settings |
374 | Settings_Init(); |
380 | Settings_Init(); |
375 | // initialize logging (needs settings) |
381 | // initialize logging (needs settings) |
376 | Logging_Init(); |
382 | Logging_Init(); |
377 | 383 | ||
378 | TimerCheckError = SetDelay(3000); |
384 | TimerCheckError = SetDelay(3000); |
379 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
385 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
380 | UART1_PutString("\n\r Version information:"); |
386 | UART1_PutString("\n\r Version information:"); |
381 | 387 | ||
382 | GetNaviCtrlVersion(); |
388 | GetNaviCtrlVersion(); |
383 | DebugOut.Status[0] = 0x04 | 0x08; // NC and MK3Mag |
389 | DebugOut.Status[0] = 0x04 | 0x08; // NC and MK3Mag |
384 | DebugOut.Status[1] = 0x00; |
390 | DebugOut.Status[1] = 0x00; |
385 | 391 | ||
386 | Compass_Init(); |
392 | Compass_Init(); |
387 | 393 | ||
388 | #ifdef FOLLOW_ME |
394 | #ifdef FOLLOW_ME |
389 | TransmitAlsoToFC = 1; |
395 | TransmitAlsoToFC = 1; |
390 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
396 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++"); |
391 | UART1_PutString("\n\r FOLLOW-ME Transmitter only!"); |
397 | UART1_PutString("\n\r FOLLOW-ME Transmitter only!"); |
392 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++\r\n\r\n"); |
398 | UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++\r\n\r\n"); |
393 | TransmitAlsoToFC = 0; |
399 | TransmitAlsoToFC = 0; |
394 | #else |
400 | #else |
395 | SPI0_GetFlightCtrlVersion(); |
401 | SPI0_GetFlightCtrlVersion(); |
396 | if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
402 | if(FC_Version.Compatible != FC_SPI_COMPATIBLE) |
397 | { |
403 | { |
398 | UART1_PutString("\n\r Flight-Ctrl not compatible"); |
404 | UART1_PutString("\n\r Flight-Ctrl not compatible"); |
399 | LED_RED_ON; |
405 | LED_RED_ON; |
400 | } |
406 | } |
401 | #endif |
407 | #endif |
402 | 408 | ||
403 | GPS_Init(); |
409 | GPS_Init(); |
404 | 410 | ||
405 | // ---------- Prepare the isr driven |
411 | // ---------- Prepare the isr driven |
406 | // set to absolute lowest priority |
412 | // set to absolute lowest priority |
407 | VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW); |
413 | VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW); |
408 | // enable interrupts |
414 | // enable interrupts |
409 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); |
415 | VIC_ITCmd(EXTIT3_ITLine, ENABLE); |
410 | 416 | ||
411 | Debug_OK("START"); |
417 | Debug_OK("START"); |
412 | 418 | ||
413 | for (;;) // the endless main loop |
419 | for (;;) // the endless main loop |
414 | { |
420 | { |
415 | UART0_ProcessRxData(); // process request |
421 | UART0_ProcessRxData(); // process request |
416 | UART1_ProcessRxData(); // process request |
422 | UART1_ProcessRxData(); // process request |
417 | USB_ProcessRxData(); // process request |
423 | USB_ProcessRxData(); // process request |
418 | UART0_TransmitTxData(); // send answer |
424 | UART0_TransmitTxData(); // send answer |
419 | UART1_TransmitTxData(); // send answer |
425 | UART1_TransmitTxData(); // send answer |
420 | UART2_TransmitTxData(); // send answer |
426 | UART2_TransmitTxData(); // send answer |
421 | USB_TransmitTxData(); // send answer |
427 | USB_TransmitTxData(); // send answer |
422 | SPI0_UpdateBuffer(); // handle new SPI Data |
428 | SPI0_UpdateBuffer(); // handle new SPI Data |
423 | 429 | ||
424 | // ---------------- Error Check Timing ---------------------------- |
430 | // ---------------- Error Check Timing ---------------------------- |
425 | if(CheckDelay(TimerCheckError)) |
431 | if(CheckDelay(TimerCheckError)) |
426 | { |
432 | { |
427 | TimerCheckError = SetDelay(1000); |
433 | TimerCheckError = SetDelay(1000); |
428 | if(CheckDelay(SPI0_Timeout) && (DebugUART == UART1)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected |
434 | if(CheckDelay(SPI0_Timeout) && (DebugUART == UART1)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected |
429 | 435 | ||
430 | if(!CheckDelay(SPI0_Timeout) || (DebugUART == UART1)) CheckErrors(); |
436 | if(!CheckDelay(SPI0_Timeout) || (DebugUART == UART1)) CheckErrors(); |
431 | 437 | ||
432 | if(FC.StatusFlags & FC_STATUS_FLY) NaviData.FlyingTime++; // we want to count the battery-time |
438 | if(FC.StatusFlags & FC_STATUS_FLY) NaviData.FlyingTime++; // we want to count the battery-time |
433 | // else NaviData.FlyingTime = 0; // not the time per flight |
439 | // else NaviData.FlyingTime = 0; // not the time per flight |
434 | if(SerialLinkOkay) SerialLinkOkay--; |
440 | if(SerialLinkOkay) SerialLinkOkay--; |
435 | if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication |
441 | if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication |
436 | else NCFlags &= ~NC_FLAG_NOSERIALLINK; |
442 | else NCFlags &= ~NC_FLAG_NOSERIALLINK; |
437 | if(StopNavigation && (Parameter.NaviGpsModeControl >= 50) && (Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) BeepTime = 1000; |
443 | if(StopNavigation && (Parameter.NaviGpsModeControl >= 50) && (Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) BeepTime = 1000; |
438 | } |
444 | } |
439 | 445 | ||
440 | // ---------------- Logging --------------------------------------- |
446 | // ---------------- Logging --------------------------------------- |
441 | 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 |
447 | 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 |
442 | 448 | ||
443 | /* |
449 | /* |
444 | // test |
450 | // test |
445 | if(CheckDelay(ftimer)) |
451 | if(CheckDelay(ftimer)) |
446 | { |
452 | { |
447 | 453 | ||
448 | s8* filename = "test.txt"; |
454 | s8* filename = "test.txt"; |
449 | 455 | ||
450 | ftimer = SetDelay(100); |
456 | ftimer = SetDelay(100); |
451 | if(FC.Poti[3]>100 && fstate == 0) |
457 | if(FC.Poti[3]>100 && fstate == 0) |
452 | { |
458 | { |
453 | fstate = 1; |
459 | fstate = 1; |
454 | } |
460 | } |
455 | else if(FC.Poti[3]<100 && fstate == 2) |
461 | else if(FC.Poti[3]<100 && fstate == 2) |
456 | { |
462 | { |
457 | fstate = 3; |
463 | fstate = 3; |
458 | } |
464 | } |
459 | 465 | ||
460 | switch(fstate) |
466 | switch(fstate) |
461 | { |
467 | { |
462 | case 1: |
468 | case 1: |
463 | sprintf(text,"\r\nStart writing file: %s", filename); |
469 | sprintf(text,"\r\nStart writing file: %s", filename); |
464 | UART1_PutString(text); |
470 | UART1_PutString(text); |
465 | f = fopen_(filename, 'a'); |
471 | f = fopen_(filename, 'a'); |
466 | if(f== NULL) Fat16_Init(); |
472 | if(f== NULL) Fat16_Init(); |
467 | fstate = 2; |
473 | fstate = 2; |
468 | break; |
474 | break; |
469 | 475 | ||
470 | case 2: |
476 | case 2: |
471 | fputs_("\r\ntest edins sdv dsivbds iv dsivb disbv idsv bisd bv d suiv dsibsivbdis fbvisdöb visdbvisdb vidbfibds ibv", f); |
477 | fputs_("\r\ntest edins sdv dsivbds iv dsivb disbv idsv bisd bv d suiv dsibsivbdis fbvisdöb visdbvisdb vidbfibds ibv", f); |
472 | break; |
478 | break; |
473 | |
479 | |
474 | case 3: |
480 | case 3: |
475 | sprintf(text,"\r\nClosing file: %s", filename); |
481 | sprintf(text,"\r\nClosing file: %s", filename); |
476 | UART1_PutString(text); |
482 | UART1_PutString(text); |
477 | fclose_(f); |
483 | fclose_(f); |
478 | fstate = 0; |
484 | fstate = 0; |
479 | break; |
485 | break; |
480 | 486 | ||
481 | default: |
487 | default: |
482 | break; |
488 | break; |
483 | } |
489 | } |
484 | } |
490 | } |
485 | */ |
491 | */ |
486 | } |
492 | } |
487 | } |
493 | } |
488 | 494 | ||
489 | 495 | ||
490 | 496 |