Subversion Repositories NaviCtrl

Rev

Rev 482 | Rev 484 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 482 Rev 483
Line 60... Line 60...
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 "i2c0.h"
65
#include "i2c.h"        
66
#include "i2c1.h"       
66
#include "compass.h"
67
#include "compass.h"
67
#include "ncmag.h"
68
#include "ncmag.h"
68
#include "timer1.h"
69
#include "timer1.h"
69
#include "timer2.h"
70
#include "timer2.h"
70
#include "analog.h"
71
#include "analog.h"
Line 79... Line 80...
79
#include "debug.h"
80
#include "debug.h"
80
#include "eeprom.h"
81
#include "eeprom.h"
81
#include "ssc.h"
82
#include "ssc.h"
82
#include "sdc.h"
83
#include "sdc.h"
83
#include "uart1.h"
84
#include "uart1.h"
84
 
-
 
-
 
85
#include "ncmag.h"
Line 85... Line 86...
85
 
86
 
86
 
87
 
87
#ifdef FOLLOW_ME
88
#ifdef FOLLOW_ME
Line 143... Line 144...
143
{
144
{
144
    static s32 no_error_delay = 0;
145
    static s32 no_error_delay = 0;
145
        s32 newErrorCode = 0;
146
        s32 newErrorCode = 0;
146
        UART_VersionInfo.HardwareError[0] = 0;
147
        UART_VersionInfo.HardwareError[0] = 0;
Line 147... Line 148...
147
 
148
 
-
 
149
        if((I2C_CompassPort == I2C_INTERN_1 && CheckDelay(I2C1_Timeout)) || (I2C_CompassPort == I2C_EXTERN_0 && CheckDelay(I2C0_Timeout)) || (Compass_Heading < 0))
-
 
150
         
148
        if(CheckDelay(I2CBus(Compass_I2CPort)->Timeout) || (Compass_Heading < 0)) DebugOut.StatusRed |= AMPEL_COMPASS;
151
         DebugOut.StatusRed |= AMPEL_COMPASS;
Line 149... Line 152...
149
        else DebugOut.StatusRed &= ~AMPEL_COMPASS; // MK3Mag green status
152
        else DebugOut.StatusRed &= ~AMPEL_COMPASS; // MK3Mag green status
150
 
153
 
Line 151... Line 154...
151
        if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.StatusRed |= AMPEL_BL;
154
        if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.StatusRed |= AMPEL_BL;
152
        else DebugOut.StatusRed &= ~AMPEL_BL; // BL-Ctrl green status
155
        else DebugOut.StatusRed &= ~AMPEL_BL; // BL-Ctrl green status
Line -... Line 156...
-
 
156
 
-
 
157
        if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.StatusRed |= AMPEL_NC;
153
 
158
        else DebugOut.StatusRed &= ~AMPEL_NC;
154
        if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.StatusRed |= AMPEL_NC;
159
 
155
        else DebugOut.StatusRed &= ~AMPEL_NC;
160
//if(I2C_CompassPort == I2C_EXTERN_0) LED_RED_OFF_T;
156
 
161
 
157
    if((FCCalibActive || CompassCalState) && FC_Version.Hardware)
162
    if((FCCalibActive || CompassCalState) && FC_Version.Hardware)
158
    {
163
     {
159
                sprintf(ErrorMSG,"Calibrate... ");
164
                sprintf(ErrorMSG,"Calibrate... ");
160
                newErrorCode = 0;
165
                newErrorCode = 0;
161
                ErrorCode = 0;
166
                ErrorCode = 0;
162
                no_error_delay = 1;
167
                no_error_delay = 1;
163
        }
168
         }
164
        else if(CheckDelay(I2CBus(Compass_I2CPort)->Timeout))
169
        else if(CheckDelay(I2C1_Timeout) && (I2C_CompassPort == I2C_INTERN_1))
-
 
170
        {
165
        {
171
                LED_RED_ON;              
166
                LED_RED_ON;              
172
                sprintf(ErrorMSG,"no compass communica");
167
                sprintf(ErrorMSG,"no compass communica");
173
                //Reset I2CBus
168
                //Reset Compass communication
174
                I2C1_Deinit();
169
                Compass_Init();
175
                I2C1_Init();
170
                newErrorCode = 4;
176
                newErrorCode = 4;
-
 
177
                StopNavigation = 1;
-
 
178
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX;
-
 
179
                DebugOut.StatusRed |= AMPEL_COMPASS;
-
 
180
        }
-
 
181
        else if(CheckDelay(I2C0_Timeout) && (I2C_CompassPort == I2C_EXTERN_0))
-
 
182
        {
-
 
183
                LED_RED_ON;              
-
 
184
//LED_RED_ON_T;
-
 
185
                sprintf(ErrorMSG,"no ext. compass ");
-
 
186
                //Reset I2CBus
-
 
187
                I2C0_Deinit();
-
 
188
                I2C0_Init();
-
 
189
                NCMAG_Update(1);
-
 
190
                newErrorCode = 33;
-
 
191
                StopNavigation = 1;
171
                StopNavigation = 1;
192
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX;
172
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX;
193
                DebugOut.StatusRed |= AMPEL_COMPASS;
173
                DebugOut.StatusRed |= AMPEL_COMPASS;
194
        }
174
        }
195
        else
175
        else if(CheckDelay(SPI0_Timeout))
196
        if(CheckDelay(SPI0_Timeout))
176
        {
197
        {
Line 193... Line 214...
193
                newErrorCode = 1;
214
                newErrorCode = 1;
194
                StopNavigation = 1;
215
                StopNavigation = 1;
195
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE;
216
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE;
196
                DebugOut.StatusRed |= AMPEL_NC;
217
                DebugOut.StatusRed |= AMPEL_NC;
197
        }
218
        }
-
 
219
 
198
        else if(FC.Error[0] & FC_ERROR0_GYRO_NICK)
220
        else if(FC.Error[0] & FC_ERROR0_GYRO_NICK)
199
        {
221
        {
200
                LED_RED_ON;
222
                LED_RED_ON;
201
                sprintf(ErrorMSG,"ERR: FC Nick Gyro");
223
                sprintf(ErrorMSG,"ERR: FC Nick Gyro");
202
                newErrorCode = 10;
224
                newErrorCode = 10;
Line 331... Line 353...
331
                newErrorCode = 23;
353
         newErrorCode = 23;
332
                DebugOut.StatusRed |= AMPEL_BL;
354
         DebugOut.StatusRed |= AMPEL_BL;
333
        }
355
        }
334
        else if(BL_MinOfMaxPWM < 30 && !ErrorCode)
356
        else if(BL_MinOfMaxPWM < 30 && !ErrorCode)
335
        {
357
        {
336
                u16 i;
358
     unsigned int i;
337
                for(i = 0; i < 12; i++) if(Motor[i].MaxPWM == BL_MinOfMaxPWM) break;
359
         for(i = 0; i < 12; i++) if(Motor[i].MaxPWM == BL_MinOfMaxPWM) break;
-
 
360
 
338
                LED_RED_ON;
361
         LED_RED_ON;
339
                sprintf(ErrorMSG,"ERR:BL%2d Test:%2d ",i+1,BL_MinOfMaxPWM);
362
         sprintf(ErrorMSG,"ERR:BL%2d Test:%2d ",i+1,BL_MinOfMaxPWM);
340
                newErrorCode = 32;
363
         newErrorCode = 32;
341
                DebugOut.StatusRed |= AMPEL_BL;
364
         DebugOut.StatusRed |= AMPEL_BL;
342
        }
365
        }
Line 410... Line 433...
410
 
433
 
411
 
434
 
412
void Polling(void)
435
void Polling(void)
-
 
436
{
413
{
437
 static u8 running = 0, oldFcFlags = 0, count5sec;
414
 static u8 running = 0, oldFcFlags = 0, count5sec;
438
 static u32 old_ms = 0;
-
 
439
 if(running) return;
-
 
440
 running = 1;
-
 
441
   if(CountMilliseconds != old_ms)  // 1 ms
-
 
442
    {
-
 
443
                old_ms = CountMilliseconds;
-
 
444
                Compass_Update();               // update compass communication
-
 
445
                Analog_Update();                // get new ADC values
415
 if(running) return;
446
                CalcHeadFree();
416
 running = 1;
447
        }
417
                SPI0_UpdateBuffer();    // also calls the GPS-functions
448
                SPI0_UpdateBuffer();    // also calls the GPS-functions
418
                UART0_ProcessRxData();  // GPS process request
449
                UART0_ProcessRxData();  // GPS process request
419
                UART0_TransmitTxData(); // GPS send answer
450
                UART0_TransmitTxData(); // GPS send answer
420
                UART1_ProcessRxData();  // PC process request
451
                UART1_ProcessRxData();  // PC process request
421
                UART1_TransmitTxData(); // PC send answer
-
 
422
                UART2_TransmitTxData(); // FC send answer
452
                UART1_TransmitTxData(); // PC send answer
423
                CalcHeadFree();
453
                UART2_TransmitTxData(); // FC send answer
424
                // ---------------- Error Check Timing ----------------------------
454
                // ---------------- Error Check Timing ----------------------------
425
                if(CheckDelay(TimerCheckError) || (FC.StatusFlags & FC_STATUS_START && !(oldFcFlags & FC_STATUS_START))) // Timer or FY wants to start
455
                if(CheckDelay(TimerCheckError) || (FC.StatusFlags & FC_STATUS_START && !(oldFcFlags & FC_STATUS_START))) // Timer or FY wants to start
426
                {
456
                {
Line 451... Line 481...
451
}
481
}
Line 452... Line 482...
452
 
482
 
453
// the handler will be cyclic called by the timer 1 ISR
483
// the handler will be cyclic called by the timer 1 ISR
454
// used is for critical timing parts that normaly would handled
484
// used is for critical timing parts that normaly would handled
455
// within the main loop that could block longer at logging activities
485
// within the main loop that could block longer at logging activities
456
void EXTIT3_IRQHandler(void)
486
void EXTIT3_IRQHandler(void)  // 1ms - Takt
457
{
487
{
458
        IENABLE;
488
        IENABLE;
459
        VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq
489
        VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq
460
        Compass_Update();               // update compass communication
490
//      Compass_Update();               // update compass communication
461
        Analog_Update();                // get new ADC values
-
 
462
 
491
//      Analog_Update();                // get new ADC values
463
        if(!PollingTimeout)
492
        if(!PollingTimeout)
464
        {
493
        {
465
                PollingTimeout = 5;
494
                PollingTimeout = 5;
-
 
495
                Polling();
466
                Polling();
496
DebugOut.Analog[16]++;
Line 467... Line 497...
467
        }
497
        }
468
 
498
 
469
        VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit
499
        VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit
Line 474... Line 504...
474
 
504
 
475
//----------------------------------------------------------------------------------------------------
505
//----------------------------------------------------------------------------------------------------
476
int main(void)
506
int main(void)
Line 477... Line 507...
477
{
507
{
478
       
508
       
479
//      static u32 ftimer =0;
509
        static u32 ftimer =0;
Line 480... Line 510...
480
//      static u8 fstate = 0;
510
        static u8 fstate = 0;
481
//      static File_t* f = NULL;
511
//      static File_t* f = NULL;
Line 505... Line 535...
505
        // initialize adc
535
        // initialize adc
506
        Analog_Init();
536
        Analog_Init();
507
        // initialize SPI0 to FC
537
        // initialize SPI0 to FC
508
        SPI0_Init();
538
        SPI0_Init();
509
        // initialize i2c busses (needs Timer 1)
539
        // initialize i2c busses (needs Timer 1)
510
        I2CBus_Init(I2C0);
540
        I2C0_Init();
511
        I2CBus_Init(I2C1);
541
        I2C1_Init();
Line 512... Line 542...
512
 
542
 
513
        // initialize fat16 partition on sd card (needs Timer 1)
543
        // initialize fat16 partition on sd card (needs Timer 1)
514
        Fat16_Init();
544
        Fat16_Init();
515
        // initialize NC params
545
        // initialize NC params
Line 561... Line 591...
561
    Settings_GetParamValue(PID_SEND_NMEA, &NMEA_Interval);
591
    Settings_GetParamValue(PID_SEND_NMEA, &NMEA_Interval);
562
        UART1_PutString("\r\n");
592
        UART1_PutString("\r\n");
563
        for (;;) // the endless main loop
593
        for (;;) // the endless main loop
564
        {
594
        {
565
                Polling();
595
                Polling();
566
                PollingTimeout = 15;
596
                PollingTimeout = 10;
567
                // ---------------- Logging  ---------------------------------------
597
                // ---------------- Logging  ---------------------------------------
568
                if(SD_WatchDog)
598
                if(SD_WatchDog)
569
                {
599
                {
570
                        SD_WatchDog = 30000;
600
                        SD_WatchDog = 30000;
571
                        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
601
                        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