Subversion Repositories NaviCtrl

Rev

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

Rev 533 Rev 540
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
//      if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected ");
281
//      if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected ");
282
//              else
282
//              else
283
                {
283
                {
284
                        sprintf(ErrorMSG,"no GPS communication");
284
                        sprintf(ErrorMSG,"no GPS communication");
285
                        UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX;
285
                        UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX;
286
                        UART_VersionInfo.Flags &= ~NC_VERSION_FLAG_GPS_PRESENT;
286
                        UART_VersionInfo.Flags &= ~NC_VERSION_FLAG_GPS_PRESENT;
287
                        newErrorCode = 5;
287
                        newErrorCode = 5;
288
                }
288
                }
289
                StopNavigation = 1;
289
                StopNavigation = 1;
290
//              UBX_Timeout = SetDelay(500);
290
//              UBX_Timeout = SetDelay(500);
291
        }
291
        }
292
        else if(Compass_Heading < 0 && NCMAG_Present && !NCMAG_IsCalibrated)
292
        else if(Compass_Heading < 0 && NCMAG_Present && !NCMAG_IsCalibrated)
293
        {
293
        {
294
                LED_RED_ON;
294
                LED_RED_ON;
295
                sprintf(ErrorMSG,"compass not calibr.");
295
                sprintf(ErrorMSG,"compass not calibr.");
296
                newErrorCode = 31;
296
                newErrorCode = 31;
297
                StopNavigation = 1;
297
                StopNavigation = 1;
298
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE;
298
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE;
299
        }
299
        }
300
        else if(Compass_Heading < 0)
300
        else if(Compass_Heading < 0)
301
        {
301
        {
302
                LED_RED_ON;
302
                LED_RED_ON;
303
                sprintf(ErrorMSG,"bad compass value ");
303
                sprintf(ErrorMSG,"bad compass value ");
304
                newErrorCode = 6;
304
                newErrorCode = 6;
305
                StopNavigation = 1;
305
                StopNavigation = 1;
306
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE;
306
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE;
307
        }
307
        }
308
        else if((FC.Error[1] &  FC_ERROR1_SPI_RX))
308
        else if((FC.Error[1] &  FC_ERROR1_SPI_RX))
309
        {
309
        {
310
                LED_RED_ON;
310
                LED_RED_ON;
311
                sprintf(ErrorMSG,"FC spi rx error ");
311
                sprintf(ErrorMSG,"FC spi rx error ");
312
                newErrorCode = 8;
312
                newErrorCode = 8;
313
                StopNavigation = 1;
313
                StopNavigation = 1;
314
        }
314
        }
315
        else if(FC.Error[0] &  FC_ERROR0_CAREFREE)
315
        else if(FC.Error[0] &  FC_ERROR0_CAREFREE)
316
        {
316
        {
317
                LED_RED_ON;
317
                LED_RED_ON;
318
                sprintf(ErrorMSG,"FC: Carefree Error");
318
                sprintf(ErrorMSG,"FC: Carefree Error");
319
                newErrorCode = 20;
319
                newErrorCode = 20;
320
        }
320
        }
321
        else if(FC.Error[1] &  FC_ERROR1_PPM)
321
        else if(FC.Error[1] &  FC_ERROR1_PPM)
322
        {
322
        {
323
                LED_RED_ON;
323
                LED_RED_ON;
324
                sprintf(ErrorMSG,"RC Signal lost ");
324
                sprintf(ErrorMSG,"RC Signal lost ");
325
                newErrorCode = 7;
325
                newErrorCode = 7;
326
        }
326
        }
327
        else if(ErrorGpsFixLost)
327
        else if(ErrorGpsFixLost)
328
        {
328
        {
329
                LED_RED_ON;
329
                LED_RED_ON;
330
                sprintf(ErrorMSG,"GPS Fix lost    ");
330
                sprintf(ErrorMSG,"GPS Fix lost    ");
331
                newErrorCode = 21;
331
                newErrorCode = 21;
332
        }
332
        }
333
        else if(ErrorDisturbedEarthMagnetField)
333
        else if(ErrorDisturbedEarthMagnetField)
334
        {
334
        {
335
                LED_RED_ON;
335
                LED_RED_ON;
336
                sprintf(ErrorMSG,"Magnet error    ");
336
                sprintf(ErrorMSG,"Magnet error    ");
337
                newErrorCode = 22;
337
                newErrorCode = 22;
338
                DebugOut.StatusRed |= AMPEL_COMPASS | AMPEL_NC;
338
                DebugOut.StatusRed |= AMPEL_COMPASS | AMPEL_NC;
339
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE;
339
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE;
340
        }
340
        }
341
        else if(((ErrorCheck_BL_MinOfMaxPWM == 40 && (TimeSinceMotorStart > 3))  || (ErrorCheck_BL_MinOfMaxPWM == 39)) && !ErrorCode)
341
        else if(((ErrorCheck_BL_MinOfMaxPWM == 40 && (TimeSinceMotorStart > 3))  || (ErrorCheck_BL_MinOfMaxPWM == 39)) && !ErrorCode)
342
        {
342
        {
343
                LED_RED_ON;
343
                LED_RED_ON;
344
                sprintf(ErrorMSG,"ERR:Motor restart  ");
344
                sprintf(ErrorMSG,"ERR:Motor restart  ");
345
                newErrorCode = 23;
345
                newErrorCode = 23;
346
                DebugOut.StatusRed |= AMPEL_BL;
346
                DebugOut.StatusRed |= AMPEL_BL;
347
        }
347
        }
348
        else if(BL_MinOfMaxPWM < 30 && !ErrorCode)
348
        else if(BL_MinOfMaxPWM < 30 && !ErrorCode)
349
        {
349
        {
350
                u16 i;
350
                u16 i;
351
                for(i = 0; i < 12; i++) if(Motor[i].MaxPWM == BL_MinOfMaxPWM) break;
351
                for(i = 0; i < 12; i++) if(Motor[i].MaxPWM == BL_MinOfMaxPWM) break;
352
                LED_RED_ON;
352
                LED_RED_ON;
353
                sprintf(ErrorMSG,"ERR:BL%2d Test:%2d ",i+1,BL_MinOfMaxPWM);
353
                sprintf(ErrorMSG,"ERR:BL%2d Test:%2d ",i+1,BL_MinOfMaxPWM);
354
                newErrorCode = 32;
354
                newErrorCode = 32;
355
                DebugOut.StatusRed |= AMPEL_BL;
355
                DebugOut.StatusRed |= AMPEL_BL;
356
        }
356
        }
357
        else if(ErrorCheck_BL_MinOfMaxPWM < 248 && (TimeSinceMotorStart > 3) && !ErrorCode)
357
        else if(ErrorCheck_BL_MinOfMaxPWM < 248 && (TimeSinceMotorStart > 3) && !ErrorCode)
358
        {
358
        {
359
                LED_RED_ON;
359
                LED_RED_ON;
360
                sprintf(ErrorMSG,"ERR:BL Limitation   ");
360
                sprintf(ErrorMSG,"ERR:BL Limitation   ");
361
                newErrorCode = 24;
361
                newErrorCode = 24;
362
                DebugOut.StatusRed |= AMPEL_BL;
362
                DebugOut.StatusRed |= AMPEL_BL;
363
        }
363
        }
364
        else if((NCFlags & NC_FLAG_RANGE_LIMIT) && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode)
364
        else if((NCFlags & NC_FLAG_RANGE_LIMIT) && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode)
365
        {
365
        {
366
                LED_RED_ON;
366
                LED_RED_ON;
367
                sprintf(ErrorMSG,"ERR:GPS WP range ");
367
                sprintf(ErrorMSG,"ERR:GPS WP range ");
368
                newErrorCode = 25;
368
                newErrorCode = 25;
369
                DebugOut.StatusRed |= AMPEL_NC;
369
                DebugOut.StatusRed |= AMPEL_NC;
370
        }
370
        }
371
        else if((!SD_SWITCH || (SDCardInfo.Valid == 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START && !(FC.StatusFlags & FC_STATUS_FLY))
371
        else if((!SD_SWITCH || (SDCardInfo.Valid == 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START && !(FC.StatusFlags & FC_STATUS_FLY))
372
        {
372
        {
373
                LED_RED_ON;
373
                LED_RED_ON;
374
                sprintf(ErrorMSG,"ERR:No SD-Card  ");
374
                sprintf(ErrorMSG,"ERR:No SD-Card  ");
375
                newErrorCode = 26;
375
                newErrorCode = 26;
376
                DebugOut.StatusRed |= AMPEL_NC;
376
                DebugOut.StatusRed |= AMPEL_NC;
377
        }
377
        }
378
        else if((SD_LoggingError || (SD_WatchDog < 2000 && SD_WatchDog != 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START)
378
        else if((SD_LoggingError || (SD_WatchDog < 2000 && SD_WatchDog != 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START)
379
        {
379
        {
380
                LED_RED_ON;
380
                LED_RED_ON;
381
                sprintf(ErrorMSG,"ERR:SD Logging abort");
381
                sprintf(ErrorMSG,"ERR:SD Logging abort");
382
                newErrorCode = 27;
382
                newErrorCode = 27;
383
                DebugOut.StatusRed |= AMPEL_NC;
383
                DebugOut.StatusRed |= AMPEL_NC;
384
                SD_LoggingError = 0;
384
                SD_LoggingError = 0;
385
        }
385
        }
386
        else if(((AbsoluteFlyingAltitude) && (NaviData.Altimeter / 20 >= AbsoluteFlyingAltitude)) && (FC.StatusFlags & FC_STATUS_FLY))
386
        else if(((AbsoluteFlyingAltitude) && (NaviData.Altimeter / 20 >= AbsoluteFlyingAltitude)) && (FC.StatusFlags & FC_STATUS_FLY))
387
        {
387
        {
388
                LED_RED_ON;
388
                LED_RED_ON;
389
                sprintf(ErrorMSG,"ERR:Max Altitude ");
389
                sprintf(ErrorMSG,"ERR:Max Altitude ");
390
                newErrorCode = 29;
390
                newErrorCode = 29;
391
                DebugOut.StatusRed |= AMPEL_NC;
391
                DebugOut.StatusRed |= AMPEL_NC;
392
        }
392
        }
393
        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)))
393
        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)))
394
        {
394
        {
395
                LED_RED_ON;
395
                LED_RED_ON;
396
                sprintf(ErrorMSG,"No GPS Fix      ");
396
                sprintf(ErrorMSG,"No GPS Fix      ");
397
                newErrorCode = 30;
397
                newErrorCode = 30;
398
        }
398
        }
399
        else // no error occured
399
        else // no error occured
400
        {
400
        {
401
                StopNavigation = 0;
401
                StopNavigation = 0;
402
                LED_RED_OFF;
402
                LED_RED_OFF;
403
                if(no_error_delay) { no_error_delay--;  }
403
                if(no_error_delay) { no_error_delay--;  }
404
                else
404
                else
405
                {
405
                {
406
                        sprintf(ErrorMSG,"No Error            ");
406
                        sprintf(ErrorMSG,"No Error            ");
407
                        ErrorCode = 0;
407
                        ErrorCode = 0;
408
                }
408
                }
409
        }
409
        }
410
 
410
 
411
    if(newErrorCode)
411
    if(newErrorCode)
412
         {
412
         {
413
          if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) no_error_delay = 8; // delay the errors if the motors are running
413
          if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) no_error_delay = 8; // delay the errors if the motors are running
414
          ErrorCode = newErrorCode;
414
          ErrorCode = newErrorCode;
415
         }
415
         }
416
 FC.Error[0] = 0;
416
 FC.Error[0] = 0;
417
 FC.Error[1] = 0;
417
 FC.Error[1] = 0;
418
 FC.Error[2] = 0;
418
 FC.Error[2] = 0;
419
 FC.Error[3] = 0;
419
 FC.Error[3] = 0;
420
 FC.Error[4] = 0;
420
 FC.Error[4] = 0;
421
 ErrorGpsFixLost = 0;
421
 ErrorGpsFixLost = 0;
422
 ErrorCheck_BL_MinOfMaxPWM = BL_MinOfMaxPWM;
422
 ErrorCheck_BL_MinOfMaxPWM = BL_MinOfMaxPWM;
423
}
423
}
424
 
424
 
425
 
425
 
426
 
426
 
427
u8 Polling(void)
427
u8 Polling(void)
428
{
428
{
429
        static u8 running = 0, oldFcFlags = 0, count5sec;
429
        static u8 running = 0, oldFcFlags = 0, count5sec;
430
        static u32 old_ms = 0;
430
        static u32 old_ms = 0;
431
 
431
 
432
        if(running) {/*DebugOut.Analog[]++;*/ return(1);};
432
        if(running) {/*DebugOut.Analog[]++;*/ return(1);};
433
        running = 1;
433
        running = 1;
434
 
434
 
435
        if(CountMilliseconds != old_ms)  // 1 ms
435
        if(CountMilliseconds != old_ms)  // 1 ms
436
        {
436
        {
437
                old_ms = CountMilliseconds;
437
                old_ms = CountMilliseconds;
438
                Compass_Update();               // update compass communication
438
                Compass_Update();               // update compass communication
439
                Analog_Update();                // get new ADC values
439
                Analog_Update();                // get new ADC values
440
                CalcHeadFree();
440
                CalcHeadFree();
441
        }
441
        }
442
 
442
 
443
        SPI0_UpdateBuffer();    // also calls the GPS-functions
443
        SPI0_UpdateBuffer();    // also calls the GPS-functions
444
        UART0_ProcessRxData();  // GPS process request
444
        UART0_ProcessRxData();  // GPS process request
445
        UART0_TransmitTxData(); // GPS send answer
445
        UART0_TransmitTxData(); // GPS send answer
446
        UART1_ProcessRxData();  // PC process request
446
        UART1_ProcessRxData();  // PC process request
447
        UART1_TransmitTxData(); // PC send answer
447
        UART1_TransmitTxData(); // PC send answer
448
        UART2_TransmitTxData(); // FC send answer
448
        UART2_TransmitTxData(); // FC send answer
449
 
449
 
450
        if(!(FC.StatusFlags & FC_STATUS_MOTOR_RUN)) TimeSinceMotorStart = 0;
450
        if(!(FC.StatusFlags & FC_STATUS_MOTOR_RUN)) TimeSinceMotorStart = 0;
451
 
451
 
452
        // ---------------- Error Check Timing ----------------------------
452
        // ---------------- Error Check Timing ----------------------------
453
        if(CheckDelay(TimerCheckError) || (FC.StatusFlags & FC_STATUS_START && !(oldFcFlags & FC_STATUS_START))) // Timer or FY wants to start
453
        if(CheckDelay(TimerCheckError) || (FC.StatusFlags & FC_STATUS_START && !(oldFcFlags & FC_STATUS_START))) // Timer or FY wants to start
454
        {
454
        {
455
                if(CheckDelay(TimerCheckError))
455
                if(CheckDelay(TimerCheckError))
456
                {
456
                {
457
                        TimerCheckError = SetDelay(1000);
457
                        TimerCheckError = SetDelay(1000);
458
                        if(CompassValueErrorCount) CompassValueErrorCount--;
458
                        if(CompassValueErrorCount) CompassValueErrorCount--;
459
                        if(++count5sec == 5)
459
                        if(++count5sec == 5)
460
                        {
460
                        {
461
                                count5sec = 0;
461
                                count5sec = 0;
462
                                FreqGpsProcessedIn5Sec = CountGpsProcessedIn5Sec * 2;
462
                                FreqGpsProcessedIn5Sec = CountGpsProcessedIn5Sec * 2;
463
                                FreqNewGpsDataIn5Sec = CountNewGpsDataIn5Sec * 2;
463
                                FreqNewGpsDataIn5Sec = CountNewGpsDataIn5Sec * 2;
464
                                CountGpsProcessedIn5Sec = 0;
464
                                CountGpsProcessedIn5Sec = 0;
465
                                CountNewGpsDataIn5Sec = 0;
465
                                CountNewGpsDataIn5Sec = 0;
466
                        }
466
                        }
467
                }
467
                }
468
                oldFcFlags = FC.StatusFlags;
468
                oldFcFlags = FC.StatusFlags;
469
                if(CheckDelay(SPI0_Timeout) && (DebugUART == UART1)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected
469
                if(CheckDelay(SPI0_Timeout) && (DebugUART == UART1)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected
470
 
470
 
471
                if(!CheckDelay(SPI0_Timeout) || (DebugUART == UART1)) CheckErrors();
471
                if(!CheckDelay(SPI0_Timeout) || (DebugUART == UART1)) CheckErrors();
472
 
472
 
473
                if(FC.StatusFlags & FC_STATUS_FLY)
473
                if(FC.StatusFlags & FC_STATUS_FLY)
474
                 {
474
                 {
475
                  NaviData.FlyingTime++; // we want to count the battery-time
475
                  NaviData.FlyingTime++; // we want to count the battery-time
476
                  TimeSinceMotorStart++;
476
                  TimeSinceMotorStart++;
477
                 }
477
                 }
478
               
478
               
479
                if(SerialLinkOkay) SerialLinkOkay--;
479
                if(SerialLinkOkay) SerialLinkOkay--;
480
                if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication
480
                if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication
481
                else NCFlags &= ~NC_FLAG_NOSERIALLINK;
481
                else NCFlags &= ~NC_FLAG_NOSERIALLINK;
482
                if(StopNavigation && (Parameter.NaviGpsModeControl >=  50) && (Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) BeepTime = 1000;
482
                if(StopNavigation && (Parameter.NaviGpsModeControl >=  50) && (Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) BeepTime = 1000;
483
        }
483
        }
484
        running = 0;
484
        running = 0;
485
//      if(!PollingTimeout) DebugOut.Analog[17]++;
485
//      if(!PollingTimeout) DebugOut.Analog[17]++;
486
        return(0);
486
        return(0);
487
}
487
}
488
 
488
 
489
// the handler will be cyclic called by the timer 1 ISR
489
// the handler will be cyclic called by the timer 1 ISR
490
// used is for critical timing parts that normaly would handled
490
// used is for critical timing parts that normaly would handled
491
// within the main loop that could block longer at logging activities
491
// within the main loop that could block longer at logging activities
492
void EXTIT3_IRQHandler(void)  // 1ms - Takt
492
void EXTIT3_IRQHandler(void)  // 1ms - Takt
493
{
493
{
494
        IENABLE;
494
        IENABLE;
495
        VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq
495
        VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq
496
 
496
 
497
        if(PollingTimeout == 0)
497
        if(PollingTimeout == 0)
498
        {
498
        {
499
                PollingTimeout = 5;
499
                PollingTimeout = 5;
500
                //if(Polling() == 0) DebugOut.Analog[]++;
500
                //if(Polling() == 0) DebugOut.Analog[]++;
501
                Polling();
501
                Polling();
502
        }
502
        }
503
 
503
 
504
        VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit
504
        VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit
505
        VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq
505
        VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq
506
        IDISABLE;
506
        IDISABLE;
507
        VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register
507
        VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register
508
}
508
}
509
 
509
 
510
//----------------------------------------------------------------------------------------------------
510
//----------------------------------------------------------------------------------------------------
511
int main(void)
511
int main(void)
512
{
512
{
513
 
513
 
514
//      static u32 ftimer =0;
514
//      static u32 ftimer =0;
515
//      static u8 fstate = 0;
515
//      static u8 fstate = 0;
516
//      static File_t* f = NULL;
516
//      static File_t* f = NULL;
517
 
517
 
518
 
518
 
519
        /* Configure the system clocks */
519
        /* Configure the system clocks */
520
        SCU_Config();
520
        SCU_Config();
521
        /* init VIC (Vectored Interrupt Controller)     */
521
        /* init VIC (Vectored Interrupt Controller)     */
522
        SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC
522
        SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC
523
        SCU_AHBPeriphReset(__VIC, DISABLE);             // disable reset state for VIC
523
        SCU_AHBPeriphReset(__VIC, DISABLE);             // disable reset state for VIC
524
        VIC_DeInit();                                                   // deinitializes the VIC module registers to their default reset values.
524
        VIC_DeInit();                                                   // deinitializes the VIC module registers to their default reset values.
525
        VIC_InitDefaultVectors();
525
        VIC_InitDefaultVectors();
526
 
526
 
527
        // initialize timer 1 for System Clock and delay rountines
527
        // initialize timer 1 for System Clock and delay rountines
528
        TIMER1_Init();
528
        TIMER1_Init();
529
        // initialize the LEDs (needs Timer 1)
529
        // initialize the LEDs (needs Timer 1)
530
        Led_Init();
530
        Led_Init();
531
        // initialize the debug UART1
531
        // initialize the debug UART1
532
        UART1_Init();
532
        UART1_Init();
533
        UART1_PutString("\r\n---------------------------------------------");
533
        UART1_PutString("\r\n---------------------------------------------");
534
        // initialize timer 2 for servo outputs
534
        // initialize timer 2 for servo outputs
535
        //TIMER2_Init();
535
        //TIMER2_Init();
536
        // initialize UART2 to FLIGHTCTRL
536
        // initialize UART2 to FLIGHTCTRL
537
        UART2_Init();
537
        UART2_Init();
538
        // initialize UART0 (to MKGPS or MK3MAG)
538
        // initialize UART0 (to MKGPS or MK3MAG)
539
        UART0_Init();
539
        UART0_Init();
540
        // initialize adc
540
        // initialize adc
541
        Analog_Init();
541
        Analog_Init();
542
        // initialize SPI0 to FC
542
        // initialize SPI0 to FC
543
        SPI0_Init();
543
        SPI0_Init();
544
        // initialize i2c busses (needs Timer 1)
544
        // initialize i2c busses (needs Timer 1)
545
        I2CBus_Init(I2C0);
545
        I2CBus_Init(I2C0);
546
        I2CBus_Init(I2C1);
546
        I2CBus_Init(I2C1);
547
        // initialize fat16 partition on sd card (needs Timer 1)
547
        // initialize fat16 partition on sd card (needs Timer 1)
548
        Fat16_Init();
548
        Fat16_Init();
549
        // initialize NC params
549
        // initialize NC params
550
        NCParams_Init();
550
        NCParams_Init();
551
        // initialize the settings
551
        // initialize the settings
552
        Settings_Init();
552
        Settings_Init();
553
        // initialize logging (needs settings)
553
        // initialize logging (needs settings)
554
        Logging_Init();
554
        Logging_Init();
555
 
555
 
556
        LED_GRN_ON;
556
        LED_GRN_ON;
557
        TimerCheckError = SetDelay(3000);
557
        TimerCheckError = SetDelay(3000);
558
        UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++");
558
        UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++");
559
        UART1_PutString("\n\r Version information:");
559
        UART1_PutString("\n\r Version information:");
560
 
560
 
561
        GetNaviCtrlVersion();
561
        GetNaviCtrlVersion();
562
        DebugOut.StatusGreen = AMPEL_NC | AMPEL_COMPASS; // NC and MK3Mag
562
        DebugOut.StatusGreen = AMPEL_NC | AMPEL_COMPASS; // NC and MK3Mag
563
        DebugOut.StatusRed = 0x00;
563
        DebugOut.StatusRed = 0x00;
564
        UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++");
564
        UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++");
565
 
565
 
566
        Compass_Init();
566
        Compass_Init();
567
 
567
 
568
        GPS_Init();
568
        GPS_Init();
569
 
569
 
570
 
570
 
571
#ifdef FOLLOW_ME
571
#ifdef FOLLOW_ME
572
        TransmitAlsoToFC = 1;
572
        TransmitAlsoToFC = 1;
573
        UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++");
573
        UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++");
574
        UART1_PutString("\n\r FOLLOW-ME Transmitter only!");
574
        UART1_PutString("\n\r FOLLOW-ME Transmitter only!");
575
        UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++\r\n\r\n");
575
        UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++\r\n\r\n");
576
        TransmitAlsoToFC = 0;
576
        TransmitAlsoToFC = 0;
577
#else
577
#else
578
        SPI0_GetFlightCtrlVersion();
578
        SPI0_GetFlightCtrlVersion();
579
        if(FC_Version.Compatible != FC_SPI_COMPATIBLE)
579
        if(FC_Version.Compatible != FC_SPI_COMPATIBLE)
580
        {
580
        {
581
                UART1_PutString("\n\r Flight-Ctrl not compatible\n\r");
581
                UART1_PutString("\n\r Flight-Ctrl not compatible\n\r");
582
                LED_RED_ON;
582
                LED_RED_ON;
583
        }
583
        }
584
#endif
584
#endif
585
 
585
 
586
        // ---------- Prepare the isr driven
586
        // ---------- Prepare the isr driven
587
        // set to absolute lowest priority
587
        // set to absolute lowest priority
588
    VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW);
588
    VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW);
589
        // enable interrupts
589
        // enable interrupts
590
    VIC_ITCmd(EXTIT3_ITLine, ENABLE);
590
    VIC_ITCmd(EXTIT3_ITLine, ENABLE);
591
 
591
 
592
        Debug_OK("START");
592
        Debug_OK("START");
593
        UART1_PutString("\r\n");
593
        UART1_PutString("\r\n");
594
        fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer
594
        fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer
595
        LED_GRN_ON;
595
        LED_GRN_ON;
596
        LED_RED_OFF;
596
        LED_RED_OFF;
597
    Settings_GetParamValue(PID_SEND_NMEA,(u16 *) &NMEA_Interval);
597
    Settings_GetParamValue(PID_SEND_NMEA,(u16 *) &NMEA_Interval);
598
        UART1_PutString("\r\n");
598
        UART1_PutString("\r\n");
599
 
599
 
600
        CompassValueErrorCount = 0;
600
        CompassValueErrorCount = 0;
601
        I2CBus(Compass_I2CPort)->Timeout = SetDelay(3000);
601
        I2CBus(Compass_I2CPort)->Timeout = SetDelay(3000);
602
// ++++++++++++++++++++++++++++++++++++++++++++++
602
// ++++++++++++++++++++++++++++++++++++++++++++++
603
        for (;;) // the endless main loop
603
        for (;;) // the endless main loop
604
        {
604
        {
605
                PollingTimeout = 5;
605
                PollingTimeout = 5;
606
                Polling();
606
                Polling();
607
// ++++++++++++++++++++++++++++++++++++++++++++++
607
// ++++++++++++++++++++++++++++++++++++++++++++++
608
                if(FromFC_LoadWP_List)
608
                if(FromFC_LoadWP_List)
609
                {
609
                {
610
                   WPL_Store.Index = (FromFC_LoadWP_List & ~0x80);
610
                   WPL_Store.Index = (FromFC_LoadWP_List & ~0x80);
611
                   if(WPL_Store.Index <= ToFC_MaxWpListIndex)
611
                   if(WPL_Store.Index <= ToFC_MaxWpListIndex)
612
                   {
612
                   {
613
                                if(PointList_ReadFromFile(&WPL_Store) == WPL_OK)
613
                                if(PointList_ReadFromFile(&WPL_Store) == WPL_OK)
614
                                {
614
                                {
615
                                        if(FromFC_LoadWP_List & 0x80)// -> load relative
615
                                        if(FromFC_LoadWP_List & 0x80)// -> load relative
616
                                        {
616
                                        {
-
 
617
                                         u32 angle;
-
 
618
                                         angle = (360 + GyroCompassCorrected/10 + Parameter.OrientationAngle * 15) % 360;
617
                                                if(NCFlags & NC_FLAG_FREE || NaviData.TargetPositionDeviation.Distance > 7*10)
619
                                                if(NCFlags & NC_FLAG_FREE || NaviData.TargetPositionDeviation.Distance > 7*10)
618
                                        {  // take actual position
620
                                        {  // take actual position
619
                                                if(!PointList_Move(1,&(GPSData.Position),NaviData.CompassHeading))      PointList_Clear();      // try to move wp-list so that 1st entry matches the current position 
621
                                                if(!PointList_Move(1,&(GPSData.Position),angle)) PointList_Clear();     // try to move wp-list so that 1st entry matches the current position 
620
                                                }
622
                                                }
621
                                        else
623
                                        else
622
                                                {  // take last target position
624
                                                {  // take last target position
623
                                                if(!PointList_Move(1, &(NaviData.TargetPosition),NaviData.CompassHeading))      PointList_Clear();      // try to move wp-list so that 1st entry matches the current position 
625
                                                if(!PointList_Move(1, &(NaviData.TargetPosition),angle)) PointList_Clear();     // try to move wp-list so that 1st entry matches the current position 
624
                                                }
626
                                                }
625
                                        }
627
                                        }
626
                                        if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
628
                                        if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
627
                                        GPS_pWaypoint = PointList_WPBegin(); // updates POI index
629
                                        GPS_pWaypoint = PointList_WPBegin(); // updates POI index
628
                                        SpeakWaypointRached = 1;        // Speak once when the last Point is reached
630
                                        SpeakWaypointRached = 1;        // Speak once when the last Point is reached
629
                                        SpeakNextWaypoint = 1;          // Speak once as soon as the Points are active
631
                                        SpeakNextWaypoint = 1;          // Speak once as soon as the Points are active
630
                                        NCFlags &= ~NC_FLAG_TARGET_REACHED;
632
                                        NCFlags &= ~NC_FLAG_TARGET_REACHED;
631
                                        BeepTime = 150;
633
                                        BeepTime = 150;
632
                                }
634
                                }
633
                        }
635
                        }
634
                        FromFC_LoadWP_List = 0;
636
                        FromFC_LoadWP_List = 0;
635
                }
637
                }
636
// ++++++++++++++++++++++++++++++++++++++++++++++
638
// ++++++++++++++++++++++++++++++++++++++++++++++
637
                if(FromFC_Save_SinglePoint)
639
                if(FromFC_Save_SinglePoint)
638
                {
640
                {
639
                        WPL_Store.Index = FromFC_Save_SinglePoint;
641
                        WPL_Store.Index = FromFC_Save_SinglePoint;
640
                        if(WPL_Store.Index <= ToFC_MaxWpListIndex) if(PointList_SaveSinglePoint(&WPL_Store) == WPL_OK) BeepTime = 150;
642
                        if(WPL_Store.Index <= ToFC_MaxWpListIndex) if(PointList_SaveSinglePoint(&WPL_Store) == WPL_OK) BeepTime = 150;
641
                        FromFC_Save_SinglePoint = 0;
643
                        FromFC_Save_SinglePoint = 0;
642
                }
644
                }
643
// ++++++++++++++++++++++++++++++++++++++++++++++
645
// ++++++++++++++++++++++++++++++++++++++++++++++
644
                if(FromFC_Load_SinglePoint)
646
                if(FromFC_Load_SinglePoint)
645
                {
647
                {
646
                   WPL_Store.Index = FromFC_Load_SinglePoint;
648
                   WPL_Store.Index = FromFC_Load_SinglePoint;
647
                   if(WPL_Store.Index <= ToFC_MaxWpListIndex)
649
                   if(WPL_Store.Index <= ToFC_MaxWpListIndex)
648
                   {
650
                   {
649
                        if(PointList_LoadSinglePoint(&WPL_Store) == WPL_OK)
651
                        if(PointList_LoadSinglePoint(&WPL_Store) == WPL_OK)
650
                        {
652
                        {
651
                                if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
653
                                if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
652
                                GPS_pWaypoint = PointList_WPBegin(); // updates POI index
654
                                GPS_pWaypoint = PointList_WPBegin(); // updates POI index
653
                                SpeakWaypointRached = 1;        // Speak once when the last Point is reached
655
                                SpeakWaypointRached = 1;        // Speak once when the last Point is reached
654
                                SpeakNextWaypoint = 1;          // Speak once as soon as the Points are active
656
                                SpeakNextWaypoint = 1;          // Speak once as soon as the Points are active
655
                                NCFlags &= ~NC_FLAG_TARGET_REACHED;
657
                                NCFlags &= ~NC_FLAG_TARGET_REACHED;
656
                                BeepTime = 150;
658
                                BeepTime = 150;
657
                        }
659
                        }
658
                   }
660
                   }
659
                        FromFC_Load_SinglePoint = 0;
661
                        FromFC_Load_SinglePoint = 0;
660
                }
662
                }
661
// ++++++++++++++++++++++++++++++++++++++++++++++
663
// ++++++++++++++++++++++++++++++++++++++++++++++
662
                // ---------------- Logging  ---------------------------------------
664
                // ---------------- Logging  ---------------------------------------
663
                if(SD_WatchDog)
665
                if(SD_WatchDog)
664
                {
666
                {
665
                        SD_WatchDog = 30000;
667
                        SD_WatchDog = 30000;
666
                        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
668
                        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
667
                        else
669
                        else
668
                        {
670
                        {
669
                         ToFC_MaxWpListIndex = 0;
671
                         ToFC_MaxWpListIndex = 0;
670
                         if(FC.StatusFlags & FC_STATUS_START) SD_LoggingError = 100;
672
                         if(FC.StatusFlags & FC_STATUS_START) SD_LoggingError = 100;
671
                        }
673
                        }
672
                        if(!SD_WatchDog) UART1_PutString("\n\rSD-Watchdog - Logging aborted\n\r");
674
                        if(!SD_WatchDog) UART1_PutString("\n\rSD-Watchdog - Logging aborted\n\r");
673
                }
675
                }
674
 
676
 
675
/*
677
/*
676
                if(CheckDelay(ftimer))
678
                if(CheckDelay(ftimer))
677
                {
679
                {
678
 
680
 
679
                        static s8 filename[35];
681
                        static s8 filename[35];
680
                        static u8 i = 0;
682
                        static u8 i = 0;
681
                        s8 dbgmsg[40];
683
                        s8 dbgmsg[40];
682
 
684
 
683
 
685
 
684
 
686
 
685
                        ftimer = SetDelay(100);
687
                        ftimer = SetDelay(100);
686
                        if(FC.Poti[3]>100 && fstate == 0)
688
                        if(FC.Poti[3]>100 && fstate == 0)
687
                        {
689
                        {
688
                                fstate = 1;
690
                                fstate = 1;
689
                                sprintf(filename, "/toast/toasta/toast%02i.txt",i++);
691
                                sprintf(filename, "/toast/toasta/toast%02i.txt",i++);
690
                        }
692
                        }
691
                        else if(FC.Poti[3]<100 && fstate == 2)
693
                        else if(FC.Poti[3]<100 && fstate == 2)
692
                        {
694
                        {
693
                                fstate = 3;
695
                                fstate = 3;
694
                        }
696
                        }
695
 
697
 
696
                        switch(fstate)
698
                        switch(fstate)
697
                        {
699
                        {
698
                                case 1:
700
                                case 1:
699
                                        sprintf(dbgmsg,"\r\nStart writing file: %s", filename);
701
                                        sprintf(dbgmsg,"\r\nStart writing file: %s", filename);
700
                                        Debug(dbgmsg);
702
                                        Debug(dbgmsg);
701
                                        f = fopen_(filename, 'a');
703
                                        f = fopen_(filename, 'a');
702
                                        if(f== NULL) Fat16_Init();
704
                                        if(f== NULL) Fat16_Init();
703
                                        fstate = 2;
705
                                        fstate = 2;
704
                                        break;
706
                                        break;
705
 
707
 
706
                                case 2:
708
                                case 2:
707
                                        fputs_("\r\ntest edins sdv dsivbds iv dsivb disbv idsv bisd bv d suiv dsibsivbdis fbvisdöb visdbvisdb vidbfibds ibv", f);
709
                                        fputs_("\r\ntest edins sdv dsivbds iv dsivb disbv idsv bisd bv d suiv dsibsivbdis fbvisdöb visdbvisdb vidbfibds ibv", f);
708
                                        break;
710
                                        break;
709
 
711
 
710
                                case 3:
712
                                case 3:
711
                                        sprintf(dbgmsg,"\r\nClosing file: %s", filename);
713
                                        sprintf(dbgmsg,"\r\nClosing file: %s", filename);
712
                                        Debug(dbgmsg);
714
                                        Debug(dbgmsg);
713
                                        fclose_(f);
715
                                        fclose_(f);
714
                                        fstate = 0;
716
                                        fstate = 0;
715
                                        break;
717
                                        break;
716
 
718
 
717
                                default:
719
                                default:
718
                                        break;
720
                                        break;
719
                        }
721
                        }
720
                }
722
                }
721
*/
723
*/
722
        }
724
        }
723
}
725
}
724
//DebugOut.Analog[]
726
//DebugOut.Analog[]
725
 
727