Subversion Repositories NaviCtrl

Rev

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

Rev 480 Rev 482
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"
-
 
66
#include "i2c1.h"       
65
#include "i2c.h"        
67
#include "compass.h"
66
#include "compass.h"
68
#include "ncmag.h"
67
#include "ncmag.h"
69
#include "timer1.h"
68
#include "timer1.h"
70
#include "timer2.h"
69
#include "timer2.h"
71
#include "analog.h"
70
#include "analog.h"
Line 80... Line 79...
80
#include "debug.h"
79
#include "debug.h"
81
#include "eeprom.h"
80
#include "eeprom.h"
82
#include "ssc.h"
81
#include "ssc.h"
83
#include "sdc.h"
82
#include "sdc.h"
84
#include "uart1.h"
83
#include "uart1.h"
85
#include "ncmag.h"
-
 
-
 
84
 
Line 86... Line 85...
86
 
85
 
87
 
86
 
88
#ifdef FOLLOW_ME
87
#ifdef FOLLOW_ME
Line 144... Line 143...
144
{
143
{
145
    static s32 no_error_delay = 0;
144
    static s32 no_error_delay = 0;
146
        s32 newErrorCode = 0;
145
        s32 newErrorCode = 0;
147
        UART_VersionInfo.HardwareError[0] = 0;
146
        UART_VersionInfo.HardwareError[0] = 0;
Line 148... Line 147...
148
 
147
 
149
        if((I2C_CompassPort == I2C_INTERN_1 && CheckDelay(I2C1_Timeout)) || (I2C_CompassPort == I2C_EXTERN_0 && CheckDelay(I2C0_Timeout)) || (Compass_Heading < 0))
-
 
150
         
-
 
151
         DebugOut.StatusRed |= AMPEL_COMPASS;
148
        if(CheckDelay(I2CBus(Compass_I2CPort)->Timeout) || (Compass_Heading < 0)) DebugOut.StatusRed |= AMPEL_COMPASS;
Line 152... Line 149...
152
        else DebugOut.StatusRed &= ~AMPEL_COMPASS; // MK3Mag green status
149
        else DebugOut.StatusRed &= ~AMPEL_COMPASS; // MK3Mag green status
153
 
150
 
Line 154... Line 151...
154
        if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.StatusRed |= AMPEL_BL;
151
        if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.StatusRed |= AMPEL_BL;
155
        else DebugOut.StatusRed &= ~AMPEL_BL; // BL-Ctrl green status
152
        else DebugOut.StatusRed &= ~AMPEL_BL; // BL-Ctrl green status
Line 156... Line -...
156
 
-
 
157
        if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.StatusRed |= AMPEL_NC;
-
 
158
        else DebugOut.StatusRed &= ~AMPEL_NC;
153
 
159
 
154
        if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.StatusRed |= AMPEL_NC;
160
if(I2C_CompassPort == I2C_EXTERN_0) LED_RED_OFF_T;
155
        else DebugOut.StatusRed &= ~AMPEL_NC;
161
 
156
 
162
    if((FCCalibActive || CompassCalState) && FC_Version.Hardware)
157
    if((FCCalibActive || CompassCalState) && FC_Version.Hardware)
163
     {
158
    {
164
                sprintf(ErrorMSG,"Calibrate... ");
159
                sprintf(ErrorMSG,"Calibrate... ");
165
                newErrorCode = 0;
160
                newErrorCode = 0;
166
                ErrorCode = 0;
161
                ErrorCode = 0;
167
                no_error_delay = 1;
162
                no_error_delay = 1;
168
         }
163
        }
169
        else if(CheckDelay(I2C1_Timeout) && (I2C_CompassPort == I2C_INTERN_1))
164
        else if(CheckDelay(I2CBus(Compass_I2CPort)->Timeout))
170
        {
-
 
171
                LED_RED_ON;              
165
        {
172
                sprintf(ErrorMSG,"no compass communica");
166
                LED_RED_ON;              
173
                //Reset I2CBus
167
                sprintf(ErrorMSG,"no compass communica");
174
                I2C1_Deinit();
168
                //Reset Compass communication
175
                I2C1_Init();
169
                Compass_Init();
176
                newErrorCode = 4;
170
                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;
-
 
192
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX;
171
                StopNavigation = 1;
193
                DebugOut.StatusRed |= AMPEL_COMPASS;
172
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX;
194
        }
173
                DebugOut.StatusRed |= AMPEL_COMPASS;
195
        else
174
        }
196
        if(CheckDelay(SPI0_Timeout))
175
        else if(CheckDelay(SPI0_Timeout))
197
        {
176
        {
Line 214... Line 193...
214
                newErrorCode = 1;
193
                newErrorCode = 1;
215
                StopNavigation = 1;
194
                StopNavigation = 1;
216
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE;
195
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE;
217
                DebugOut.StatusRed |= AMPEL_NC;
196
                DebugOut.StatusRed |= AMPEL_NC;
218
        }
197
        }
219
 
-
 
220
        else if(FC.Error[0] & FC_ERROR0_GYRO_NICK)
198
        else if(FC.Error[0] & FC_ERROR0_GYRO_NICK)
221
        {
199
        {
222
                LED_RED_ON;
200
                LED_RED_ON;
223
                sprintf(ErrorMSG,"ERR: FC Nick Gyro");
201
                sprintf(ErrorMSG,"ERR: FC Nick Gyro");
224
                newErrorCode = 10;
202
                newErrorCode = 10;
Line 353... Line 331...
353
         newErrorCode = 23;
331
                newErrorCode = 23;
354
         DebugOut.StatusRed |= AMPEL_BL;
332
                DebugOut.StatusRed |= AMPEL_BL;
355
        }
333
        }
356
        else if(BL_MinOfMaxPWM < 30 && !ErrorCode)
334
        else if(BL_MinOfMaxPWM < 30 && !ErrorCode)
357
        {
335
        {
358
     unsigned int i;
336
                u16 i;
359
         for(i = 0; i < 12; i++) if(Motor[i].MaxPWM == BL_MinOfMaxPWM) break;
337
                for(i = 0; i < 12; i++) if(Motor[i].MaxPWM == BL_MinOfMaxPWM) break;
360
 
-
 
361
         LED_RED_ON;
338
                LED_RED_ON;
362
         sprintf(ErrorMSG,"ERR:BL%2d Test:%2d ",i+1,BL_MinOfMaxPWM);
339
                sprintf(ErrorMSG,"ERR:BL%2d Test:%2d ",i+1,BL_MinOfMaxPWM);
363
         newErrorCode = 32;
340
                newErrorCode = 32;
364
         DebugOut.StatusRed |= AMPEL_BL;
341
                DebugOut.StatusRed |= AMPEL_BL;
365
        }
342
        }
Line 497... Line 474...
497
 
474
 
498
//----------------------------------------------------------------------------------------------------
475
//----------------------------------------------------------------------------------------------------
499
int main(void)
476
int main(void)
Line 500... Line 477...
500
{
477
{
501
       
478
       
502
        static u32 ftimer =0;
479
//      static u32 ftimer =0;
Line 503... Line 480...
503
        static u8 fstate = 0;
480
//      static u8 fstate = 0;
504
//      static File_t* f = NULL;
481
//      static File_t* f = NULL;
Line 528... Line 505...
528
        // initialize adc
505
        // initialize adc
529
        Analog_Init();
506
        Analog_Init();
530
        // initialize SPI0 to FC
507
        // initialize SPI0 to FC
531
        SPI0_Init();
508
        SPI0_Init();
532
        // initialize i2c busses (needs Timer 1)
509
        // initialize i2c busses (needs Timer 1)
533
        I2C0_Init();
510
        I2CBus_Init(I2C0);
534
        I2C1_Init();
511
        I2CBus_Init(I2C1);
Line 535... Line 512...
535
 
512
 
536
        // initialize fat16 partition on sd card (needs Timer 1)
513
        // initialize fat16 partition on sd card (needs Timer 1)
537
        Fat16_Init();
514
        Fat16_Init();
538
        // initialize NC params
515
        // initialize NC params