Subversion Repositories NaviCtrl

Rev

Rev 77 | Rev 79 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 77 Rev 78
Line 75... Line 75...
75
 
75
 
76
 
76
 
77
typedef enum
77
typedef enum
-
 
78
{
78
{
79
        LOGFILE_IDLE,
79
        LOGFILE_IDLE,
80
        LOGFILE_START,
80
        LOGFILE_CLOSED,
81
        LOGFILE_CLOSED,
81
        LOGFILE_OPENED,
82
        LOGFILE_OPENED,
Line 89... Line 90...
89
u16 BeepTime;
90
u16 BeepTime;
Line 90... Line 91...
90
 
91
 
91
u8 ClearMKFlags = 0;
92
u8 ClearMKFlags = 0;
92
u8 StopNavigation = 0;
93
u8 StopNavigation = 0;
93
Param_t Parameter;
94
Param_t Parameter;
Line 94... Line 95...
94
FC_t FC;
95
volatile FC_t FC;
Line 95... Line 96...
95
 
96
 
96
s8 ErrorMSG[25];
97
s8 ErrorMSG[25];
Line 220... Line 221...
220
 
221
 
221
 
222
 
222
//----------------------------------------------------------------------------------------------------
223
//----------------------------------------------------------------------------------------------------
223
int main(void)
-
 
224
{
224
int main(void)
-
 
225
{
225
        volatile logfilestate_t logfilestate = LOGFILE_IDLE;
226
        KML_Document_t gpslogfile;
226
        KML_Document_t gpslogfile;
-
 
227
        s8* gpslogfilename = NULL;
227
    logfilestate_t logfilestate = LOGFILE_IDLE;
228
 
228
        s8* gpslogfilename = NULL;
229
        /* Configure the system clocks */
-
 
230
        SCU_Config();
229
        /* Configure the system clocks */
231
 
-
 
232
        KML_DocumentInit(&gpslogfile);                  // Initialize the new kml-document for further use.
230
        SCU_Config();
233
 
231
        KML_DocumentInit(&gpslogfile);                  // Initialize the new kml-document for further use.
234
        /* init VIC (Vectored Interrupt Controller)     */
232
        /* init VIC (Vectored Interrupt Controller)     */
235
        SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC
233
        SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC
236
        SCU_AHBPeriphReset(__VIC, DISABLE);             // disable reset state for VIC
234
        SCU_AHBPeriphReset(__VIC, DISABLE);             // disable reset state for VIC
Line 242... Line 240...
242
        // initialize the LEDs (needs Timer 1)
240
        // initialize the LEDs (needs Timer 1)
243
        Led_Init();
241
        Led_Init();
244
        // initialize the debug UART1
242
        // initialize the debug UART1
245
        UART1_Init();
243
        UART1_Init();
246
        SerialPutString("\r\n---------------------------------------------");
244
        SerialPutString("\r\n---------------------------------------------");
247
 
-
 
248
        // initialize UART2 to FLIGHTCTRL
245
        // initialize UART2 to FLIGHTCTRL
249
        UART2_Init();
246
        UART2_Init();
250
        // initialize UART0 (to MKGPS or MK3MAG)
247
        // initialize UART0 (to MKGPS or MK3MAG)
251
        UART0_Init();
248
        UART0_Init();
252
        // initialize usb
249
        // initialize usb
Line 258... Line 255...
258
        // initialize the gps position controller (needs Timer 1)
255
        // initialize the gps position controller (needs Timer 1)
259
        GPS_Init();
256
        GPS_Init();
260
        // initialize fat16 partition on sd card (needs Timer 1)
257
        // initialize fat16 partition on sd card (needs Timer 1)
261
        Fat16_Init();
258
        Fat16_Init();
Line 262... Line -...
262
 
-
 
263
 
259
 
264
        TimerCompassUpdate = SetDelay(5);
260
        TimerCompassUpdate = SetDelay(5);
265
        TimerKmlAddPointDelay = SetDelay(250);
261
        TimerKmlAddPointDelay = SetDelay(250);
266
        TimerCheckError = SetDelay(3000);
-
 
267
 
262
        TimerCheckError = SetDelay(3000);
268
        SerialPutString("\r\n---------------------------------------------");
263
        SerialPutString("\r\n---------------------------------------------");
269
        SerialPutString("\n\r Version information:");
264
        SerialPutString("\n\r Version information:");
270
        GetNaviCtrlVersion();
265
        GetNaviCtrlVersion();
271
        SPI0_GetFlightCtrlVersion();
266
        SPI0_GetFlightCtrlVersion();
Line 274... Line 269...
274
                //sprintf(ErrorMSG,"\r\n %d <-> %d", FlightCtrlVersion.NaviCompatible, FC_SPI_COMPATIBLE);
269
                //sprintf(ErrorMSG,"\r\n %d <-> %d", FlightCtrlVersion.NaviCompatible, FC_SPI_COMPATIBLE);
275
                //SerialPutString(ErrorMSG);
270
                //SerialPutString(ErrorMSG);
276
                SerialPutString("\n\r Flight-Ctrl not compatible");
271
                SerialPutString("\n\r Flight-Ctrl not compatible");
277
                LED_RED_ON;
272
                LED_RED_ON;
278
        }
273
        }
-
 
274
 
279
        I2C1_GetMK3MagVersion();
275
        I2C1_GetMK3MagVersion();
280
        if(MK3MAG_Version.Compatible != MK3MAG_I2C_COMPATIBLE)
276
        if(MK3MAG_Version.Compatible != MK3MAG_I2C_COMPATIBLE)
281
        {
277
        {
282
                SerialPutString("\n\r MK3Mag not compatible");
278
                SerialPutString("\n\r MK3Mag not compatible");
283
                LED_RED_ON;
279
                LED_RED_ON;
284
        }
280
        }
Line 285... Line 281...
285
 
281
 
286
        /*
282
        /*
287
        ReadSetting(1);
283
        ReadSetting(1);
288
        */
284
        */
Line 289... Line 285...
289
        SerialPutString("\r\n---------------------------------------------\r\n\r\n");
285
        SerialPutString("\r\n---------------------------------------------\r\n\r\n ");
290
 
286
 
291
        for (;;)
287
        for (;;)
292
        {
288
        {
Line 343... Line 339...
343
                }
339
                }
344
                // ---------------- KML Timing ------------------------------------
340
                // ---------------- KML Timing ------------------------------------
345
                if(CheckDelay(TimerKmlAddPointDelay))
341
                if(CheckDelay(TimerKmlAddPointDelay))
346
                {
342
                {
347
                        TimerKmlAddPointDelay = SetDelay(500); // every 500 ms
343
                        TimerKmlAddPointDelay = SetDelay(500); // every 500 ms
-
 
344
 
348
                        if(FC.MKFlags & MKFLAG_FLY) // model is flying
345
                        if(FC.MKFlags & MKFLAG_MOTOR_RUN)
349
                        {
346
                        {
350
                                switch(logfilestate)
347
                                switch(logfilestate)
351
                                {
348
                                {
352
                                        case LOGFILE_IDLE:
349
                                        case LOGFILE_IDLE:
353
                                        case LOGFILE_CLOSED:
350
                                        case LOGFILE_CLOSED:
-
 
351
                                                if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D) && (FC.MKFlags & MKFLAG_FLY))
-
 
352
                                                   logfilestate = LOGFILE_START;
-
 
353
                                            break;
-
 
354
                                        case LOGFILE_START:
354
                                                // find unused logfile name
355
                                                // find unused logfile name
355
                                                do
356
                                                do
356
                                                {        // try to generate a new logfile name
357
                                                {        // try to generate a new logfile name
357
                                                         gpslogfilename = GenerateGPSLogFileName();
358
                                                         gpslogfilename = GenerateGPSLogFileName();
358
                                                }while((gpslogfilename != NULL) && fexist_(gpslogfilename));
359
                                                }while((gpslogfilename != NULL) && fexist_(gpslogfilename));
Line 386... Line 387...
386
                                                        {       // error logging data
387
                                                        {       // error logging data
387
                                                                SerialPutString("\r\nError Logging GPS data\r\n");
388
                                                                SerialPutString("\r\nError Logging GPS data\r\n");
388
                                                                KML_DocumentClose(&gpslogfile);
389
                                                                KML_DocumentClose(&gpslogfile);
389
                                                                logfilestate = LOGFILE_ERROR;
390
                                                                logfilestate = LOGFILE_ERROR;
390
                                                        }
391
                                                        }
391
                                                        else DebugOut.Analog[26]++;
392
                                                        else DebugOut.Analog[26]++;     // count SD-Logs
392
                                                }      
393
                                                }      
393
                                                break;
394
                                                break;
Line 394... Line 395...
394
 
395
 
395
                                        case LOGFILE_ERROR:
396
                                        case LOGFILE_ERROR: