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