Subversion Repositories NaviCtrl

Rev

Rev 348 | Rev 351 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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