Subversion Repositories NaviCtrl

Rev

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

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