Subversion Repositories NaviCtrl

Rev

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

Rev 378 Rev 380
Line 78... Line 78...
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"
Line 83... Line 84...
83
 
84
 
84
#ifdef FOLLOW_ME
85
#ifdef FOLLOW_ME
85
u8 TransmitAlsoToFC = 0;
86
u8 TransmitAlsoToFC = 0;
86
#endif
87
#endif
Line 150... Line 151...
150
        if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.StatusRed |= AMPEL_NC;
151
        if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.StatusRed |= AMPEL_NC;
151
        else DebugOut.StatusRed &= ~AMPEL_NC;
152
        else DebugOut.StatusRed &= ~AMPEL_NC;
Line 152... Line 153...
152
 
153
 
153
        if(CheckDelay(SPI0_Timeout))
154
        if(CheckDelay(SPI0_Timeout))
154
        {
155
        {
155
                LED_RED_ON;
156
                LED_RED_ON;              
156
                sprintf(ErrorMSG,"no FC communication ");
157
                sprintf(ErrorMSG,"no FC communication ");
157
                newErrorCode = 3;
158
                newErrorCode = 3;
158
                StopNavigation = 1;
159
                StopNavigation = 1;
159
                DebugOut.StatusGreen &= ~AMPEL_FC; // status of FC Present
160
                DebugOut.StatusGreen &= ~AMPEL_FC; // status of FC Present
160
                DebugOut.StatusGreen &= ~AMPEL_BL; // status of BL Present
161
                DebugOut.StatusGreen &= ~AMPEL_BL; // status of BL Present
161
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_SPI_RX;
162
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_SPI_RX;
162
        }
163
        }
163
        else if(CheckDelay(I2C1_Timeout))
164
        else if(CheckDelay(I2C1_Timeout))
164
        {
165
        {
165
                LED_RED_ON;              
166
                LED_RED_ON;              
166
                sprintf(ErrorMSG,"no compass communication");
167
                sprintf(ErrorMSG,"no compass communica");
167
                //Reset I2CBus
168
                //Reset I2CBus
168
                I2C1_Deinit();
169
                I2C1_Deinit();
169
                I2C1_Init();
170
                I2C1_Init();
170
                newErrorCode = 4;
171
                newErrorCode = 4;
Line 228... Line 229...
228
                sprintf(ErrorMSG,"ERR:Flying range!");
229
                sprintf(ErrorMSG,"ERR:Flying range!");
229
                newErrorCode = 28;
230
                newErrorCode = 28;
230
        }
231
        }
231
        else if(FC.Error[0] & FC_ERROR0_PRESSURE)
232
        else if(FC.Error[0] & FC_ERROR0_PRESSURE)
232
        {
233
        {
233
                LED_RED_ON;
234
                LED_RED_ON;              
234
                sprintf(ErrorMSG,"ERR:Pressure sensor");
235
                sprintf(ErrorMSG,"ERR:Pressure sensor");
235
                newErrorCode = 16;
236
                newErrorCode = 16;
236
        }
237
        }
237
        else if(FC.Error[1] &  FC_ERROR1_I2C)
238
        else if(FC.Error[1] &  FC_ERROR1_I2C)
238
        {
239
        {
Line 255... Line 256...
255
        else if(CheckDelay(UBX_Timeout) && Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)
256
        else if(CheckDelay(UBX_Timeout) && Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)
256
        {
257
        {
257
                LED_RED_ON;
258
                LED_RED_ON;
258
//      if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected ");
259
//      if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected ");
259
//              else 
260
//              else 
260
                 {
261
                 {                                     
261
                  sprintf(ErrorMSG,"no GPS communication ");
262
                  sprintf(ErrorMSG,"no GPS communication");
262
                  UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX;
263
                  UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX;
263
              newErrorCode = 5;
264
              newErrorCode = 5;
264
                 }
265
                 }
265
                StopNavigation = 1;
266
                StopNavigation = 1;
266
//              UBX_Timeout = SetDelay(500);
267
//              UBX_Timeout = SetDelay(500);
Line 335... Line 336...
335
         DebugOut.StatusRed |= AMPEL_NC;
336
         DebugOut.StatusRed |= AMPEL_NC;
336
        }
337
        }
337
        else if((SD_LoggingError || (SD_WatchDog == 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START )
338
        else if((SD_LoggingError || (SD_WatchDog == 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START )
338
        {
339
        {
339
         LED_RED_ON;       
340
         LED_RED_ON;       
340
         sprintf(ErrorMSG,"ERR:SD Logging aborted");
341
         sprintf(ErrorMSG,"ERR:SD Logging abort");
341
         newErrorCode = 27;
342
         newErrorCode = 27;
342
         DebugOut.StatusRed |= AMPEL_NC;
343
         DebugOut.StatusRed |= AMPEL_NC;
343
         SD_LoggingError = 0;
344
         SD_LoggingError = 0;
344
        }
345
        }
345
        else if(((AbsoluteFlyingAltitude) && (NaviData.Altimeter / 20 >= AbsoluteFlyingAltitude)) && (FC.StatusFlags & FC_STATUS_FLY))
346
        else if(((AbsoluteFlyingAltitude) && (NaviData.Altimeter / 20 >= AbsoluteFlyingAltitude)) && (FC.StatusFlags & FC_STATUS_FLY))
Line 353... Line 354...
353
        {
354
        {
354
                StopNavigation = 0;
355
                StopNavigation = 0;
355
                LED_RED_OFF;
356
                LED_RED_OFF;
356
                if(no_error_delay) { no_error_delay--;  }
357
                if(no_error_delay) { no_error_delay--;  }
357
                else
358
                else
358
                 {
359
                 {                                     
359
                  sprintf(ErrorMSG,"No Error               ");
360
                  sprintf(ErrorMSG,"No Error            ");
360
                  ErrorCode = 0;
361
                  ErrorCode = 0;
361
                 }
362
                 }
362
        }
363
        }
Line 363... Line 364...
363
 
364
 
Line 372... Line 373...
372
 FC.Error[3] = 0;
373
 FC.Error[3] = 0;
373
 FC.Error[4] = 0;
374
 FC.Error[4] = 0;
374
 ErrorGpsFixLost = 0;
375
 ErrorGpsFixLost = 0;
375
}
376
}
Line 376... Line -...
376
 
-
 
377
// the handler will be cyclic called by the timer 1 ISR
-
 
378
// used is for critical timing parts that normaly would handled
-
 
Line 379... Line 377...
379
// within the main loop that could block longer at logging activities
377
 
380
 
378
 
381
 
379
 
382
void Polling(void)
380
void Polling(void)
383
{
381
{
384
 static u8 running = 0;
-
 
385
 if(running) return;
-
 
386
 running = 1;
382
 static u8 running = 0;
387
LED_GRN_OFF;
383
 if(running) return;
388
// PollingTimeout = 20;
384
 running = 1;
-
 
385
                SPI0_UpdateBuffer();    // also calls the GPS-functions
389
                SPI0_UpdateBuffer();    // also calls the GPS-functions
386
                UART0_ProcessRxData();  // GPS process request
390
                UART0_ProcessRxData();  // GPS process request
387
                UART0_TransmitTxData(); // GPS send answer
391
                UART0_TransmitTxData(); // GPS send answer
388
                UART1_ProcessRxData();  // PC process request
-
 
389
                UART1_TransmitTxData(); // PC send answer
-
 
390
                UART2_TransmitTxData(); // FC send answer
392
                UART1_TransmitTxData(); // PC send answer
391
                CalcHeadFree();
-
 
392
                // ---------------- Error Check Timing ----------------------------
-
 
393
                if(CheckDelay(TimerCheckError))
-
 
394
                {
-
 
395
                        TimerCheckError = SetDelay(1000);
-
 
396
                        if(CheckDelay(SPI0_Timeout) && (DebugUART == UART1)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected
-
 
397
       
-
 
398
                        if(!CheckDelay(SPI0_Timeout) || (DebugUART == UART1)) CheckErrors();
-
 
399
               
-
 
400
                        if(FC.StatusFlags & FC_STATUS_FLY) NaviData.FlyingTime++; // we want to count the battery-time
-
 
401
//                      else NaviData.FlyingTime = 0; // not the time per flight
-
 
402
                        if(SerialLinkOkay) SerialLinkOkay--;
-
 
403
                        if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication
393
                UART2_TransmitTxData(); // FC send answer
404
                        else NCFlags &= ~NC_FLAG_NOSERIALLINK;
394
                CalcHeadFree();
405
                        if(StopNavigation && (Parameter.NaviGpsModeControl >=  50) && (Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) BeepTime = 1000;
Line 395... Line -...
395
LED_GRN_ON;
-
 
-
 
406
                }
-
 
407
 running = 0;
-
 
408
}
396
 running = 0;
409
 
397
}
410
// the handler will be cyclic called by the timer 1 ISR
398
 
411
// used is for critical timing parts that normaly would handled
399
 
412
// within the main loop that could block longer at logging activities
400
void EXTIT3_IRQHandler(void)
413
void EXTIT3_IRQHandler(void)
401
{
414
{
Line 402... Line 415...
402
        IENABLE;
415
        IENABLE;
403
        VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq
416
        VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq
404
        Compass_Update();               // update compass communication
417
        Compass_Update();               // update compass communication
405
        Analog_Update();                // get new ADC values
418
        Analog_Update();                // get new ADC values
406
 
419
 
Line 407... Line 420...
407
 if(!PollingTimeout)
420
        if(!PollingTimeout)
408
  {
421
        {
409
   PollingTimeout = 3;
422
                PollingTimeout = 5;
410
   Polling();
423
                Polling();
Line 495... Line 508...
495
        // enable interrupts
508
        // enable interrupts
496
    VIC_ITCmd(EXTIT3_ITLine, ENABLE);
509
    VIC_ITCmd(EXTIT3_ITLine, ENABLE);
Line 497... Line 510...
497
 
510
 
498
        Debug_OK("START");
511
        Debug_OK("START");
-
 
512
        UART1_PutString("\r\n");
499
        UART1_PutString("\r\n");
513
        fifo_purge(&UART1_rx_fifo); // flush the whole fifo init buffer
500
 
514
        LED_GRN_ON;
501
Polling();
515
        LED_RED_OFF;
502
        for (;;) // the endless main loop
516
        for (;;) // the endless main loop
503
        {
517
        {
504
            Polling();
518
            Polling();
505
                PollingTimeout = 15;
-
 
506
DebugOut.Analog[17] = CountMilliseconds;
-
 
507
                UART1_ProcessRxData();  // PC process request
-
 
508
//              UART1_TransmitTxData(); // PC send answer
-
 
509
 
-
 
510
                // ---------------- Error Check Timing ----------------------------
-
 
511
                if(CheckDelay(TimerCheckError))
-
 
512
                {
-
 
513
                        TimerCheckError = SetDelay(1000);
-
 
514
                        if(CheckDelay(SPI0_Timeout) && (DebugUART == UART1)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected
-
 
515
       
-
 
516
                        if(!CheckDelay(SPI0_Timeout) || (DebugUART == UART1)) CheckErrors();
-
 
517
               
-
 
518
                        if(FC.StatusFlags & FC_STATUS_FLY) NaviData.FlyingTime++; // we want to count the battery-time
-
 
519
//                      else NaviData.FlyingTime = 0; // not the time per flight
-
 
520
                        if(SerialLinkOkay) SerialLinkOkay--;
-
 
521
                        if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication
-
 
522
                        else NCFlags &= ~NC_FLAG_NOSERIALLINK;
-
 
523
                        if(StopNavigation && (Parameter.NaviGpsModeControl >=  50) && (Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) BeepTime = 1000;
-
 
524
                }
519
                PollingTimeout = 15;
525
                // ---------------- Logging  ---------------------------------------
-
 
526
 
-
 
527
 
520
                // ---------------- Logging  ---------------------------------------
528
                if(SD_WatchDog)
521
                if(SD_WatchDog)
529
                 {
522
                 {
530
                  SD_WatchDog = 10000;
523
                  SD_WatchDog = 30000;
531
                  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
524
                  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
532
                  else if(FC.StatusFlags & FC_STATUS_START) SD_LoggingError = 100;
525
                  else if(FC.StatusFlags & FC_STATUS_START) SD_LoggingError = 100;
533
                  if(!SD_WatchDog) UART1_PutString("\n\rSD-Watchdog - Logging aborted\n\r");
526
                  if(!SD_WatchDog) UART1_PutString("\n\rSD-Watchdog - Logging aborted\n\r");
534
                 }
-
 
535
 
527
                 }
536
                /*
528
                /*
537
                // test
529
               
538
                if(CheckDelay(ftimer))
530
                if(CheckDelay(ftimer))
Line 539... Line 531...
539
                {
531
                {