Subversion Repositories NaviCtrl

Rev

Rev 1 | Rev 27 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ingob 1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
6
// + Nur für den privaten Gebrauch
7
// + FOR NON COMMERCIAL USE ONLY
8
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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. 
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
13
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
15
// + Verkauf von Luftbildaufnahmen, usw.
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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"
22
// + eindeutig als Ursprung verlinkt werden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
25
// + Benutzung auf eigene Gefahr
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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 
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
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
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 
39
// +     for non-commercial use (directly or indirectly)
40
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
41
// +     with our written permission
42
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
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
45
//
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
48
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
50
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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
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
56
// +  POSSIBILITY OF SUCH DAMAGE. 
57
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
58
const unsigned long _Main_Crystal = 25000;
59
 
60
#include "main.h"
24 StephanB 61
#include "kml.h"
1 ingob 62
 
63
u32 TimerCompassUpdate;
64
u32 TimerI2CReadDelay;
65
u32 TimerDebugDataDelay;
24 StephanB 66
u32 KmlAddPointDelay;
1 ingob 67
 
68
u8 BeepTime;
69
void Init_Undef(void);
70
u8 Parameter_UserParam1;
71
u8 Parameter_UserParam2;
72
u8 Parameter_UserParam3;
73
u8 Parameter_UserParam4;
74
u8 Parameter_UserParam5;
75
u8 Parameter_UserParam6;
76
u8 Parameter_UserParam7;
77
u8 Parameter_UserParam8;
78
s32 FC_StickNick;
79
s32 FC_StickRoll;
80
s32 FC_StickGier;
81
s32 FC_StickGas;
82
s32 FC_Poti1;
83
s32 FC_Poti2;
84
s32 FC_Poti3;
85
s32 FC_Poti4;
86
s32 SenderOkay = 0;
87
u8 text[20];
88
 
89
//----------------------------------------------------------------------------------------------------
90
void Leds_Init(void)
91
{
92
    GPIO_InitTypeDef GPIO_InitStructure;
93
 
94
        SCU_APBPeriphClockConfig(__GPIO6, ENABLE);      
95
    SCU_APBPeriphClockConfig(__GPIO5, ENABLE);  
96
 
97
        //GPIO_DeInit(GPIO5);
98
    GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
99
    GPIO_InitStructure.GPIO_Pin =               GPIO_Pin_6 | GPIO_Pin_7;
100
    GPIO_InitStructure.GPIO_Type =              GPIO_Type_PushPull ;
101
    GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1  ;
102
    GPIO_Init(GPIO5, &GPIO_InitStructure);
103
 
24 StephanB 104
        //SD_SWITCH
1 ingob 105
    GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
106
    GPIO_InitStructure.GPIO_Pin =               GPIO_Pin_3;
107
    GPIO_InitStructure.GPIO_Type =              GPIO_Type_PushPull;
108
    GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
109
    GPIO_Init(GPIO5, &GPIO_InitStructure);
110
 
111
}
112
  //
113
void OutputStartupData(void)
114
{
115
 
24 StephanB 116
   char tex[20];
1 ingob 117
   SerialPutString("\n\r--------------\n\r");
118
 
119
   sprintf(text,"NaviCtrl V%d.%d\n\r",  VersionInfo.Hauptversion,  VersionInfo.Nebenversion); SerialPutString(text);
120
 
121
 
122
}
123
 
124
//----------------------------------------------------------------------------------------------------
125
int main(void)
126
{
127
   static u8 oldCompassCalState = 0;
128
 
24 StephanB 129
 
130
   static u8 kml_state = 0;
131
   u8 kml_cnt = 0;
132
   KML_Document_t       mydocument;
133
   File *file1;
134
 
135
 
136
   u8 str[80];
137
 
138
 
139
   KML_DocumentInit(&mydocument);                                       // Initialise the new kml-document for further use.     
140
 
141
 
1 ingob 142
  // SCU_MCLKSourceConfig(SCU_MCLK_OSC);
143
  // SCU_PCLKDivisorConfig(SCU_PCLK_Div2);
144
  // SCU_MCLKSourceConfig(SCU_MCLK_PLL);
145
 
146
 
147
   SCU_MCLKSourceConfig(SCU_MCLK_OSC);
148
   SCU_PLLCmd(DISABLE); // PLL aus 
149
   SCU_RCLKDivisorConfig(SCU_RCLK_Div1);
150
   SCU_HCLKDivisorConfig(SCU_HCLK_Div1);
151
   SCU_PCLKDivisorConfig(SCU_PCLK_Div2);
152
  // SCU_FMICLKDivisorConfig(SCU_FMICLK_Div1);
153
  // FMI_Config(FMI_READ_WAIT_STATE_3,FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE, FMI_LVD_ENABLE,FMI_FREQ_HIGH);
154
   SCU_PLLFactorsConfig(192,25,3); // PLL = 48 MHz 
155
 
156
   SCU_PLLCmd(ENABLE); // PLL Enabled 
157
 
158
   SCU_MCLKSourceConfig(SCU_MCLK_PLL); // MCLK = PLL 
159
 
160
 
161
   VersionInfo.Hauptversion = VERSION_HAUPTVERSION;
162
   VersionInfo.Nebenversion = VERSION_NEBENVERSION;
163
   VersionInfo.PCKompatibel = VERSION_KOMPATIBEL;
164
 
165
   SCU_AHBPeriphClockConfig(__VIC,ENABLE);
166
   SCU_AHBPeriphReset(__VIC,DISABLE);
167
   VIC_DeInit();
168
 
169
   InitInterrupt();
170
 
171
   Leds_Init();
172
   Debug_UART1_Init();
173
   OutputStartupData();
174
 
175
   GPS_UART0_Init();
176
   USB_ConfigInit();
177
 
178
 
179
   SPI0_Init();
180
 
181
 
182
 
183
   TIMER1_Init();
184
   I2C1_Init();
185
 
186
   I2C_Version.Hauptversion = 0xff;
187
 
188
   SendI2C_Command(I2C_CMD_VERSION);
189
 
190
   TimerCompassUpdate = SetDelay(50);
191
   while (!CheckDelay(TimerCompassUpdate));
192
 
193
   TimerCompassUpdate = SetDelay(5);
194
   TimerI2CReadDelay = SetDelay(5);
195
 
24 StephanB 196
   KmlAddPointDelay = SetDelay(250);
197
 
198
 
199
   SerialPutString("\r\n---------------------------------------------");
200
 
201
 
202
//   ReadSetting(1); 
203
   SerialPutString("\r\n---------------------------------------------\r\n\r\n");
204
 
1 ingob 205
   InitFat16();
24 StephanB 206
 
1 ingob 207
 
208
   for (;;)
209
   {
210
    if(NeuerDatensatzEmpfangen)
211
          {
212
                 BearbeiteRxDaten();
213
             DatenUebertragung();
214
//               if (GPIO_ReadBit(GPIO5, GPIO_Pin_3)) SerialPutString("keine SD\n\r");    else SerialPutString("SD eingesteckt!\n\r");
215
 
216
      }
217
 
218
 
219
          UpdateSPI_Buffer();
220
          SPI_CheckSlaveSelect();
221
          UART1_Transmit();
222
 
223
   // ----------- I2C Timing -------------------------
224
          if (CheckDelay(TimerCompassUpdate))
225
          {
226
                if(oldCompassCalState != CompassCalState)
227
                  {
228
                    oldCompassCalState = CompassCalState;
229
                    TimerCompassUpdate = SetDelay(25);
230
            SendI2C_Command(I2C_CMD_WRITE_CAL);
231
                  }
232
                  else
233
                  {
234
                   GPIO_ToggleBit(GPIO5, GPIO_Pin_6);
235
                   GPIO_ToggleBit(GPIO5, GPIO_Pin_7);
236
               TimerCompassUpdate = SetDelay(25);
237
           SendI2C_Command(I2C_CMD_READ_HEADING);
238
                  }
239
 
240
           }
241
 
242
          if (CheckDelay(TimerI2CReadDelay))
243
          {
244
            if (I2C_ReadRequest)
245
                {
246
                  I2C_ReadRequest= 0;
247
 
248
                  I2C_Direction = I2C_MODE_RECEIVER;
249
                  I2C_GenerateStart(I2C1, ENABLE);
250
                }
251
                TimerI2CReadDelay = SetDelay(1000);
252
          }
253
 
254
          if (CheckDelay(TimerDebugDataDelay))
255
          {  SendGPSPosAnforderung = 1;
256
         DatenUebertragung();
257
 
258
             TimerDebugDataDelay = SetDelay(500);
259
          }
24 StephanB 260
 
261
 
262
   // ----------- KML Timing -------------------------
263
          if(CheckDelay(KmlAddPointDelay))
264
          {
265
                KmlAddPointDelay = SetDelay(500);
266
 
267
                switch(kml_state)
268
                {
269
                        case 0:
270
                                if((GPS_Data.Flags & GPS_FIX) && (GPS_Data.Used_Sat >= GPS_SAT_MIN))
271
                                {
272
                                        if(str_Volume.state == INITIALIZED)                                                                                     // has the volume and filesystem been initialized?
273
                                        {
274
                                                if(KML_DocumentOpen("flight01.kml",&mydocument))                                                // create a new kml-document on the memorycard.
275
                                                {
276
                                                        SerialPutString("\r\nopening kml-file\r\nadding data");
277
                                                        kml_state = 1;
278
                                                }
279
                                        }
280
                                        else
281
                                        {
282
                                                InitFat16();
283
                                        }
284
                                }
285
                        break;                                                                                                                                                          // document.state will be changed to DOC_OPENED automatic.
286
 
287
                        case 1:                                                                                                                                                         // linestring opened, so datapoint (gps_coordinates) can be added to the document.
288
                                if(kml_cnt++ < 20)                                                                                                                              // add 10 datapoints to the document.
289
                                {
290
                                        KML_LoggGPSCoordinates(GPS_Data,&mydocument);
291
                                }
292
                                else                                                                                                                                                    // after the datapoints have been written to the document close the document.
293
                                {
294
                                        KML_DocumentClose(&mydocument);                                                
295
                                        SerialPutString("\r\nfile closed");
296
                                        kml_state = 2;
297
                                }
298
                        break;
299
 
300
                        default:                                                                                                                                                        // all data has been written to card. open new document to add new data.
301
                }
302
          }
303
        }
1 ingob 304
}
305
 
24 StephanB 306
 
307