Subversion Repositories NaviCtrl

Rev

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

Rev 27 Rev 39
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
6
// + Nur für den privaten Gebrauch
6
// + Nur für den privaten Gebrauch
7
// + FOR NON COMMERCIAL USE ONLY
7
// + FOR NON COMMERCIAL USE ONLY
8
// + www.MikroKopter.com
8
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
13
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
13
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
15
// + Verkauf von Luftbildaufnahmen, usw.
15
// + Verkauf von Luftbildaufnahmen, usw.
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
22
// + eindeutig als Ursprung verlinkt werden
22
// + eindeutig als Ursprung verlinkt werden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
25
// + Benutzung auf eigene Gefahr
25
// + Benutzung auf eigene Gefahr
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
28
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
29
// + mit unserer Zustimmung zulässig
29
// + mit unserer Zustimmung zulässig
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Teile, die nicht eindeutig mit unserer Lizenzvereinbarung gekennzeichnet sind, unterliegen u.U. eigenen Vereinbarungen:
31
// + Teile, die nicht eindeutig mit unserer Lizenzvereinbarung gekennzeichnet sind, unterliegen u.U. eigenen Vereinbarungen:
32
// + z.B. Die Funktion printf_P() unterliegt ihrer eigenen Lizenz 
32
// + z.B. Die Funktion printf_P() unterliegt ihrer eigenen Lizenz 
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
34
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
35
// + this list of conditions and the following disclaimer.
35
// + this list of conditions and the following disclaimer.
36
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
36
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
37
// +     from this software without specific prior written permission.
37
// +     from this software without specific prior written permission.
38
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted 
38
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted 
39
// +     for non-commercial use (directly or indirectly)
39
// +     for non-commercial use (directly or indirectly)
40
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
40
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
41
// +     with our written permission
41
// +     with our written permission
42
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
42
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
43
// +     clearly linked as origin 
43
// +     clearly linked as origin 
44
// +   * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed
44
// +   * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed
45
//
45
//
46
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
46
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
47
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
49
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
50
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
52
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
56
// +  POSSIBILITY OF SUCH DAMAGE. 
56
// +  POSSIBILITY OF SUCH DAMAGE. 
57
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
58
const unsigned long _Main_Crystal = 25000;
58
const unsigned long _Main_Crystal = 25000;
59
 
59
 
60
#include "main.h"
60
#include "main.h"
61
#include "kml.h"
61
#include "kml.h"
62
 
62
 
63
u32 TimerCompassUpdate;
63
u32 TimerCompassUpdate;
64
u32 TimerI2CReadDelay;
64
u32 TimerI2CReadDelay;
65
u32 TimerDebugDataDelay;
65
u32 TimerDebugDataDelay;
66
u32 KmlAddPointDelay;
66
u32 KmlAddPointDelay;
67
 
67
 
68
u8 BeepTime;
68
u8 BeepTime;
69
void Init_Undef(void);
69
void Init_Undef(void);
70
u8 Parameter_UserParam1;
70
u8 Parameter_UserParam1;
71
u8 Parameter_UserParam2;
71
u8 Parameter_UserParam2;
72
u8 Parameter_UserParam3;
72
u8 Parameter_UserParam3;
73
u8 Parameter_UserParam4;
73
u8 Parameter_UserParam4;
74
u8 Parameter_UserParam5;
74
u8 Parameter_UserParam5;
75
u8 Parameter_UserParam6;
75
u8 Parameter_UserParam6;
76
u8 Parameter_UserParam7;
76
u8 Parameter_UserParam7;
77
u8 Parameter_UserParam8;
77
u8 Parameter_UserParam8;
78
//++++++++++++++++++++++++++++++++++++++++++++++++++
78
//++++++++++++++++++++++++++++++++++++++++++++++++++
79
s32 FC_StickNick;
79
s32 FC_StickNick;
80
s32 FC_StickRoll;
80
s32 FC_StickRoll;
81
s32 FC_StickGier;
81
s32 FC_StickGier;
82
s32 FC_StickGas;
82
s32 FC_StickGas;
83
s32 FC_Poti1;
83
s32 FC_Poti1;
84
s32 FC_Poti2;
84
s32 FC_Poti2;
85
s32 FC_Poti3;
85
s32 FC_Poti3;
86
s32 FC_Poti4;
86
s32 FC_Poti4;
87
//++++++++++++++++++++++++++++++++++++++++++++++++++
87
//++++++++++++++++++++++++++++++++++++++++++++++++++
88
s32 SenderOkay = 0;
88
s32 SenderOkay = 0;
89
s32 UBat = 0;
89
s32 UBat = 0;
90
s32 UndervoltageLevel = 0;
90
s32 UndervoltageLevel = 0;
91
s32 ActiveSetting = 1;
91
s32 ActiveSetting = 1;
92
//++++++++++++++++++++++++++++++++++++++++++++++++++
92
//++++++++++++++++++++++++++++++++++++++++++++++++++
93
s32 Parameter_NaviGpsModeControl = 128;
93
s32 Parameter_NaviGpsModeControl = 128;
94
s32 Parameter_NaviGpsGain = 0;
94
s32 Parameter_NaviGpsGain = 0;
95
s32 Parameter_NaviGpsP = 90;
95
s32 Parameter_NaviGpsP = 90;
96
s32 Parameter_NaviGpsI = 0;
96
s32 Parameter_NaviGpsI = 0;
97
s32 Parameter_NaviGpsD = 90;
97
s32 Parameter_NaviGpsD = 90;
98
s32 Parameter_NaviGpsACC = 0;
98
s32 Parameter_NaviGpsACC = 0;
99
s32 Parameter_NaviGpsMinSat = 3;
99
s32 Parameter_NaviGpsMinSat = 3;
100
s32 Parameter_NaviStickThreshold = 8;
100
s32 Parameter_NaviStickThreshold = 8;
101
s32 Parameter_RadiusAlert = 15;
101
s32 Parameter_RadiusAlert = 15;
102
//++++++++++++++++++++++++++++++++++++++++++++++++++
102
//++++++++++++++++++++++++++++++++++++++++++++++++++
103
#define FLAG_MOTOR_RUN  1
103
#define FLAG_MOTOR_RUN  1
104
#define FLAG_FLY        2
104
#define FLAG_FLY        2
105
#define FLAG_CALIBRATE  4
105
#define FLAG_CALIBRATE  4
106
#define FLAG_START      8
106
#define FLAG_START      8
107
u32 MikroKopterFlags;
107
u32 MikroKopterFlags;
108
u32 ClearFlags = 1;
108
u32 ClearFlags = 1;
109
//++++++++++++++++++++++++++++++++++++++++++++++++++
109
//++++++++++++++++++++++++++++++++++++++++++++++++++
110
u8 text[20];
110
u8 text[20];
111
 
111
 
112
//----------------------------------------------------------------------------------------------------
112
//----------------------------------------------------------------------------------------------------
113
void Leds_Init(void)
113
void Leds_Init(void)
114
{
114
{
115
    GPIO_InitTypeDef GPIO_InitStructure;
115
    GPIO_InitTypeDef GPIO_InitStructure;
116
 
116
 
117
        SCU_APBPeriphClockConfig(__GPIO6, ENABLE);      
117
        SCU_APBPeriphClockConfig(__GPIO6, ENABLE);      
118
    SCU_APBPeriphClockConfig(__GPIO5, ENABLE);  
118
    SCU_APBPeriphClockConfig(__GPIO5, ENABLE);  
119
   
119
   
120
        //GPIO_DeInit(GPIO5);
120
        //GPIO_DeInit(GPIO5);
121
    GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
121
    GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
122
    GPIO_InitStructure.GPIO_Pin =               GPIO_Pin_6 | GPIO_Pin_7;
122
    GPIO_InitStructure.GPIO_Pin =               GPIO_Pin_6 | GPIO_Pin_7;
123
    GPIO_InitStructure.GPIO_Type =              GPIO_Type_PushPull ;
123
    GPIO_InitStructure.GPIO_Type =              GPIO_Type_PushPull ;
124
    GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1  ;
124
    GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1  ;
125
    GPIO_Init(GPIO5, &GPIO_InitStructure);
125
    GPIO_Init(GPIO5, &GPIO_InitStructure);
126
 
126
 
127
        //SD_SWITCH
127
        //SD_SWITCH
128
    GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
128
    GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
129
    GPIO_InitStructure.GPIO_Pin =               GPIO_Pin_3;
129
    GPIO_InitStructure.GPIO_Pin =               GPIO_Pin_3;
130
    GPIO_InitStructure.GPIO_Type =              GPIO_Type_PushPull;
130
    GPIO_InitStructure.GPIO_Type =              GPIO_Type_PushPull;
131
    GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
131
    GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
132
    GPIO_Init(GPIO5, &GPIO_InitStructure);
132
    GPIO_Init(GPIO5, &GPIO_InitStructure);
133
 
133
 
134
}
134
}
135
  //
135
  //
136
void OutputStartupData(void)
136
void OutputStartupData(void)
137
{
137
{
138
   
138
   
139
   char tex[20];
139
   char tex[20];
140
   SerialPutString("\n\r--------------\n\r");
140
   SerialPutString("\n\r--------------\n\r");
141
   
141
   
142
   sprintf(text,"NaviCtrl V%d.%d\n\r",  VersionInfo.Hauptversion,  VersionInfo.Nebenversion); SerialPutString(text);
142
   sprintf(text,"NaviCtrl V%d.%d\n\r",  VersionInfo.Hauptversion,  VersionInfo.Nebenversion); SerialPutString(text);
143
 
143
 
144
 
144
 
145
}
145
}
146
 
146
 
147
//----------------------------------------------------------------------------------------------------
147
//----------------------------------------------------------------------------------------------------
148
int main(void)
148
int main(void)
149
{
149
{
150
   static u8 oldCompassCalState = 0;
150
   static u8 oldCompassCalState = 0;
151
 
151
 
152
 
152
 
153
   static u8 kml_state = 0;
153
   static u8 kml_state = 0;
154
   u8 kml_cnt = 0;
154
   u8 kml_cnt = 0;
155
   KML_Document_t       mydocument;
155
   KML_Document_t       mydocument;
156
   File *file1;
156
   File *file1;
157
 
157
 
158
   
158
   
159
   u8 str[80];
159
   u8 str[80];
160
 
160
 
161
 
161
 
162
   KML_DocumentInit(&mydocument);                                       // Initialise the new kml-document for further use.     
162
   KML_DocumentInit(&mydocument);                                       // Initialise the new kml-document for further use.     
163
 
163
 
164
 
164
 
165
  // SCU_MCLKSourceConfig(SCU_MCLK_OSC);
165
  // SCU_MCLKSourceConfig(SCU_MCLK_OSC);
166
  // SCU_PCLKDivisorConfig(SCU_PCLK_Div2);
166
  // SCU_PCLKDivisorConfig(SCU_PCLK_Div2);
167
  // SCU_MCLKSourceConfig(SCU_MCLK_PLL);
167
  // SCU_MCLKSourceConfig(SCU_MCLK_PLL);
168
 
168
 
169
 
169
 
170
   SCU_MCLKSourceConfig(SCU_MCLK_OSC);
170
   SCU_MCLKSourceConfig(SCU_MCLK_OSC);
171
   SCU_PLLCmd(DISABLE); // PLL aus 
171
   SCU_PLLCmd(DISABLE); // PLL aus 
172
   SCU_RCLKDivisorConfig(SCU_RCLK_Div1);
172
   SCU_RCLKDivisorConfig(SCU_RCLK_Div1);
173
   SCU_HCLKDivisorConfig(SCU_HCLK_Div1);
173
   SCU_HCLKDivisorConfig(SCU_HCLK_Div1);
174
   SCU_PCLKDivisorConfig(SCU_PCLK_Div2);
174
   SCU_PCLKDivisorConfig(SCU_PCLK_Div2);
175
  // SCU_FMICLKDivisorConfig(SCU_FMICLK_Div1);
175
  // SCU_FMICLKDivisorConfig(SCU_FMICLK_Div1);
176
  // FMI_Config(FMI_READ_WAIT_STATE_3,FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE, FMI_LVD_ENABLE,FMI_FREQ_HIGH);
176
  // FMI_Config(FMI_READ_WAIT_STATE_3,FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE, FMI_LVD_ENABLE,FMI_FREQ_HIGH);
177
   SCU_PLLFactorsConfig(192,25,3); // PLL = 48 MHz 
177
   SCU_PLLFactorsConfig(192,25,3); // PLL = 48 MHz 
178
 
178
 
179
   SCU_PLLCmd(ENABLE); // PLL Enabled 
179
   SCU_PLLCmd(ENABLE); // PLL Enabled 
180
 
180
 
181
   SCU_MCLKSourceConfig(SCU_MCLK_PLL); // MCLK = PLL 
181
   SCU_MCLKSourceConfig(SCU_MCLK_PLL); // MCLK = PLL 
182
 
182
 
183
       
183
       
184
   VersionInfo.Hauptversion = VERSION_HAUPTVERSION;
184
   VersionInfo.Hauptversion = VERSION_HAUPTVERSION;
185
   VersionInfo.Nebenversion = VERSION_NEBENVERSION;
185
   VersionInfo.Nebenversion = VERSION_NEBENVERSION;
186
   VersionInfo.PCKompatibel = VERSION_KOMPATIBEL;
186
   VersionInfo.PCKompatibel = VERSION_KOMPATIBEL;
187
 
187
 
188
   SCU_AHBPeriphClockConfig(__VIC,ENABLE);
188
   SCU_AHBPeriphClockConfig(__VIC,ENABLE);
189
   SCU_AHBPeriphReset(__VIC,DISABLE);
189
   SCU_AHBPeriphReset(__VIC,DISABLE);
190
   VIC_DeInit();
190
   VIC_DeInit();
191
   
191
   
192
   InitInterrupt();
192
   InitInterrupt();
193
   
193
   
194
   Leds_Init();
194
   Leds_Init();
195
   Debug_UART1_Init();
195
   Debug_UART1_Init();
196
   OutputStartupData();
196
   OutputStartupData();
197
 
197
 
198
   GPS_UART0_Init();
198
   GPS_UART0_Init();
199
   USB_ConfigInit();
199
   USB_ConfigInit();
200
 
200
 
201
 
201
 
202
   SPI0_Init();
202
   SPI0_Init();
203
   
203
   
204
   
204
   
205
 
205
 
206
   TIMER1_Init();
206
   TIMER1_Init();
207
   I2C1_Init();
207
   I2C1_Init();
208
   
208
   
209
   I2C_Version.Hauptversion = 0xff;
209
   I2C_Version.Hauptversion = 0xff;
210
 
210
 
211
   SendI2C_Command(I2C_CMD_VERSION);
211
   SendI2C_Command(I2C_CMD_VERSION);
212
 
212
 
213
   TimerCompassUpdate = SetDelay(50);
213
   TimerCompassUpdate = SetDelay(50);
214
   while (!CheckDelay(TimerCompassUpdate));
214
   while (!CheckDelay(TimerCompassUpdate));
215
   
215
   
216
   TimerCompassUpdate = SetDelay(5);
216
   TimerCompassUpdate = SetDelay(5);
217
   TimerI2CReadDelay = SetDelay(5);
217
   TimerI2CReadDelay = SetDelay(5);
218
 
218
 
219
   KmlAddPointDelay = SetDelay(250);
219
   KmlAddPointDelay = SetDelay(250);
220
 
220
 
221
 
221
 
222
   SerialPutString("\r\n---------------------------------------------");
222
   SerialPutString("\r\n---------------------------------------------");
223
 
223
 
224
 
224
 
225
//   ReadSetting(1); 
225
//   ReadSetting(1); 
226
   SerialPutString("\r\n---------------------------------------------\r\n\r\n");
226
   SerialPutString("\r\n---------------------------------------------\r\n\r\n");
227
   
227
   
228
   InitFat16();
228
   InitFat16();
229
   
229
   
230
 
230
 
231
   for (;;)
231
   for (;;)
232
   {
232
   {
233
    if(NeuerDatensatzEmpfangen)
233
    if(NeuerDatensatzEmpfangen)
234
          {
234
          {
235
                 BearbeiteRxDaten();
235
                 BearbeiteRxDaten();
236
             DatenUebertragung();
236
             DatenUebertragung();
237
//               if (GPIO_ReadBit(GPIO5, GPIO_Pin_3)) SerialPutString("keine SD\n\r");    else SerialPutString("SD eingesteckt!\n\r");
237
//               if (GPIO_ReadBit(GPIO5, GPIO_Pin_3)) SerialPutString("keine SD\n\r");    else SerialPutString("SD eingesteckt!\n\r");
238
   
238
   
239
      }
239
      }
240
         
240
         
241
       
241
       
242
          UpdateSPI_Buffer();
242
          UpdateSPI_Buffer();
243
          SPI_CheckSlaveSelect();
243
          SPI_CheckSlaveSelect();
244
          UART1_Transmit();
244
          UART1_Transmit();
245
   
245
   
246
   // ----------- I2C Timing -------------------------
246
   // ----------- I2C Timing -------------------------
247
          if (CheckDelay(TimerCompassUpdate))
247
          if (CheckDelay(TimerCompassUpdate))
248
          {
248
          {
249
                if(oldCompassCalState != CompassCalState)
249
                if(oldCompassCalState != CompassCalState)
250
                  {
250
                  {
251
                    oldCompassCalState = CompassCalState;
251
                    oldCompassCalState = CompassCalState;
252
                    TimerCompassUpdate = SetDelay(25);
252
                    TimerCompassUpdate = SetDelay(25);
253
            SendI2C_Command(I2C_CMD_WRITE_CAL);
253
            SendI2C_Command(I2C_CMD_WRITE_CAL);
254
                  }
254
                  }
255
                  else
255
                  else
256
                  {
256
                  {
257
                   GPIO_ToggleBit(GPIO5, GPIO_Pin_6);
257
                   GPIO_ToggleBit(GPIO5, GPIO_Pin_6);
258
                   GPIO_ToggleBit(GPIO5, GPIO_Pin_7);
258
                   GPIO_ToggleBit(GPIO5, GPIO_Pin_7);
259
               TimerCompassUpdate = SetDelay(25);
259
               TimerCompassUpdate = SetDelay(25);
260
           SendI2C_Command(I2C_CMD_READ_HEADING);
260
           SendI2C_Command(I2C_CMD_READ_HEADING);
261
                  }
261
                  }
262
               
262
               
263
           }
263
           }
264
 
264
 
265
          if (CheckDelay(TimerI2CReadDelay))
265
          if (CheckDelay(TimerI2CReadDelay))
266
          {
266
          {
267
            if (I2C_ReadRequest)
267
            if (I2C_ReadRequest)
268
                {
268
                {
269
                  I2C_ReadRequest= 0;
269
                  I2C_ReadRequest= 0;
270
                 
270
                 
271
                  I2C_Direction = I2C_MODE_RECEIVER;
271
                  I2C_Direction = I2C_MODE_RECEIVER;
272
                  I2C_GenerateStart(I2C1, ENABLE);
272
                  I2C_GenerateStart(I2C1, ENABLE);
273
                }
273
                }
274
                TimerI2CReadDelay = SetDelay(1000);
274
                TimerI2CReadDelay = SetDelay(1000);
275
          }
275
          }
276
 
276
 
277
          if (CheckDelay(TimerDebugDataDelay))
277
          if (CheckDelay(TimerDebugDataDelay))
278
          {  SendGPSPosAnforderung = 1;
278
          {  SendGPSPosAnforderung = 1;
279
         DatenUebertragung();
279
         DatenUebertragung();
280
 
280
 
281
             TimerDebugDataDelay = SetDelay(500);
281
             TimerDebugDataDelay = SetDelay(500);
282
          }
282
          }
283
 
283
 
284
 
284
 
285
   // ----------- KML Timing -------------------------
285
   // ----------- KML Timing -------------------------
286
          if(CheckDelay(KmlAddPointDelay))
286
          if(CheckDelay(KmlAddPointDelay) && 0)
287
          {
287
          {
288
                KmlAddPointDelay = SetDelay(500);
288
                KmlAddPointDelay = SetDelay(500);
289
                switch(kml_state)
289
                switch(kml_state)
290
                {
290
                {
291
                        case 0:
291
                        case 0:
292
                                if((GPS_Data.Flags & GPS_FIX) && (GPS_Data.Used_Sat >= GPS_SAT_MIN))
292
                                if((GPS_Data.Flags & GPS_FIX) && (GPS_Data.Used_Sat >= GPS_SAT_MIN))
293
                                {
293
                                {
294
                                        if(str_Volume.state == INITIALIZED)                                                                                     // has the volume and filesystem been initialized?
294
                                        if(str_Volume.state == INITIALIZED)                                                                                     // has the volume and filesystem been initialized?
295
                                        {
295
                                        {
296
                                                if(KML_DocumentOpen("flight01.kml",&mydocument))                                                // create a new kml-document on the memorycard.
296
                                                if(KML_DocumentOpen("flight01.kml",&mydocument))                                                // create a new kml-document on the memorycard.
297
                                                {
297
                                                {
298
                                                        SerialPutString("\r\nopening kml-file\r\nadding data");
298
                                                        SerialPutString("\r\nopening kml-file\r\nadding data");
299
                                                        kml_state = 1;
299
                                                        kml_state = 1;
300
                                                }
300
                                                }
301
                                        }
301
                                        }
302
                                        else
302
                                        else
303
                                        {
303
                                        {
304
                                                InitFat16();
304
                                                InitFat16();
305
                                                if(str_Volume.state != INITIALIZED) KmlAddPointDelay = SetDelay(5000);  // try again in 5 sek
305
                                                if(str_Volume.state != INITIALIZED) KmlAddPointDelay = SetDelay(5000);  // try again in 5 sek
306
                                        }
306
                                        }
307
                                }
307
                                }
308
                        break;                                                                                                                                                          // document.state will be changed to DOC_OPENED automatic.
308
                        break;                                                                                                                                                          // document.state will be changed to DOC_OPENED automatic.
309
       
309
       
310
                        case 1:                                                                                                                                                         // linestring opened, so datapoint (gps_coordinates) can be added to the document.
310
                        case 1:                                                                                                                                                         // linestring opened, so datapoint (gps_coordinates) can be added to the document.
311
                                if(kml_cnt++ < 20)                                                                                                                              // add 10 datapoints to the document.
311
                                if(kml_cnt++ < 20)                                                                                                                              // add 10 datapoints to the document.
312
                                {
312
                                {
313
                                        KML_LoggGPSCoordinates(GPS_Data,&mydocument);
313
                                        KML_LoggGPSCoordinates(GPS_Data,&mydocument);
314
                                }
314
                                }
315
                                else                                                                                                                                                    // after the datapoints have been written to the document close the document.
315
                                else                                                                                                                                                    // after the datapoints have been written to the document close the document.
316
                                {
316
                                {
317
                                        KML_DocumentClose(&mydocument);                                                
317
                                        KML_DocumentClose(&mydocument);                                                
318
                                        SerialPutString("\r\nfile closed");
318
                                        SerialPutString("\r\nfile closed");
319
                                        kml_state = 2;
319
                                        kml_state = 2;
320
                                }
320
                                }
321
                        break;
321
                        break;
322
 
322
 
323
                        default:                                                                                                                                                        // all data has been written to card. open new document to add new data.
323
                        default:                                                                                                                                                        // all data has been written to card. open new document to add new data.
324
                }
324
                }
325
          }
325
          }
326
        }
326
        }
327
}
327
}
328
 
328
 
329
 
329
 
330
 
330
 
331
 
331