Subversion Repositories NaviCtrl

Rev

Rev 480 | Rev 483 | Go to most recent revision | Show entire file | Ignore 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 286... Line 264...
286
        else if(CheckDelay(UBX_Timeout) && Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)
264
        else if(CheckDelay(UBX_Timeout) && Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)
287
        {
265
        {
288
                LED_RED_ON;
266
                LED_RED_ON;
289
//      if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected ");
267
//      if(!(Parameter.GlobalConfig & FC_CFG_GPS_AKTIV)) sprintf(ErrorMSG,"GPS disconnected ");
290
//              else 
268
//              else 
291
                 {                                     
269
                {                                      
292
                  sprintf(ErrorMSG,"no GPS communication");
270
                        sprintf(ErrorMSG,"no GPS communication");
293
                  UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX;
271
                        UART_VersionInfo.HardwareError[0] |= NC_ERROR0_GPS_RX;
294
                  UART_VersionInfo.Flags &= ~NC_VERSION_FLAG_GPS_PRESENT;
272
                        UART_VersionInfo.Flags &= ~NC_VERSION_FLAG_GPS_PRESENT;
295
              newErrorCode = 5;
273
                        newErrorCode = 5;
296
                 }
274
                }
297
                StopNavigation = 1;
275
                StopNavigation = 1;
298
//              UBX_Timeout = SetDelay(500);
276
//              UBX_Timeout = SetDelay(500);
299
        }
277
        }
300
        else if(Compass_Heading < 0 && NCMAG_Present && !NCMAG_IsCalibrated)
278
        else if(Compass_Heading < 0 && NCMAG_Present && !NCMAG_IsCalibrated)
301
        {
279
        {
Line 332... Line 310...
332
                sprintf(ErrorMSG,"RC Signal lost ");
310
                sprintf(ErrorMSG,"RC Signal lost ");
333
                newErrorCode = 7;
311
                newErrorCode = 7;
334
        }
312
        }
335
        else if(ErrorGpsFixLost)
313
        else if(ErrorGpsFixLost)
336
        {
314
        {
337
         LED_RED_ON;
315
                LED_RED_ON;
338
         sprintf(ErrorMSG,"GPS Fix lost    ");
316
                sprintf(ErrorMSG,"GPS Fix lost    ");
339
         newErrorCode = 21;
317
                newErrorCode = 21;
340
        }
318
        }
341
        else if(ErrorDisturbedEarthMagnetField)
319
        else if(ErrorDisturbedEarthMagnetField)
342
        {
320
        {
343
         LED_RED_ON;
321
                LED_RED_ON;
344
         sprintf(ErrorMSG,"Magnet error    ");
322
                sprintf(ErrorMSG,"Magnet error    ");
345
         newErrorCode = 22;
323
                newErrorCode = 22;
346
         DebugOut.StatusRed |= AMPEL_COMPASS | AMPEL_NC;
324
                DebugOut.StatusRed |= AMPEL_COMPASS | AMPEL_NC;
347
         UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE;
325
                UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE;
348
        }
326
        }
349
        else if(((BL_MinOfMaxPWM == 40 && (FC.StatusFlags & FC_STATUS_FLY)) || BL_MinOfMaxPWM == 39) && !ErrorCode)
327
        else if(((BL_MinOfMaxPWM == 40 && (FC.StatusFlags & FC_STATUS_FLY)) || BL_MinOfMaxPWM == 39) && !ErrorCode)
350
        {
328
        {
351
         LED_RED_ON;
329
                LED_RED_ON;
352
         sprintf(ErrorMSG,"ERR:Motor restart  ");
330
                sprintf(ErrorMSG,"ERR:Motor restart  ");
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
        }
366
        else if(BL_MinOfMaxPWM < 248 && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode)
343
        else if(BL_MinOfMaxPWM < 248 && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode)
367
        {
344
        {
368
         LED_RED_ON;
345
                LED_RED_ON;
369
         sprintf(ErrorMSG,"ERR:BL Limitation   ");
346
                sprintf(ErrorMSG,"ERR:BL Limitation   ");
370
         newErrorCode = 24;
347
                newErrorCode = 24;
371
         DebugOut.StatusRed |= AMPEL_BL;
348
                DebugOut.StatusRed |= AMPEL_BL;
372
        }
349
        }
373
        else if(NCFlags & NC_FLAG_RANGE_LIMIT && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode)
350
        else if(NCFlags & NC_FLAG_RANGE_LIMIT && (FC.StatusFlags & FC_STATUS_FLY) && !ErrorCode)
374
        {
351
        {
375
         LED_RED_ON;
352
                LED_RED_ON;
376
         sprintf(ErrorMSG,"ERR:GPS range  ");
353
                sprintf(ErrorMSG,"ERR:GPS range  ");
377
         newErrorCode = 25;
354
                newErrorCode = 25;
378
         DebugOut.StatusRed |= AMPEL_NC;
355
                DebugOut.StatusRed |= AMPEL_NC;
379
        }
356
        }
380
        else if((!SD_SWITCH || (SDCardInfo.Valid == 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START && !(FC.StatusFlags & FC_STATUS_FLY))
357
        else if((!SD_SWITCH || (SDCardInfo.Valid == 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START && !(FC.StatusFlags & FC_STATUS_FLY))
381
        {
358
        {
382
         LED_RED_ON;
359
                LED_RED_ON;
383
         sprintf(ErrorMSG,"ERR:No SD-Card  ");
360
                sprintf(ErrorMSG,"ERR:No SD-Card  ");
384
         newErrorCode = 26;
361
                newErrorCode = 26;
385
         DebugOut.StatusRed |= AMPEL_NC;
362
                DebugOut.StatusRed |= AMPEL_NC;
386
        }
363
        }
387
        else if((SD_LoggingError || (SD_WatchDog < 2000 && SD_WatchDog != 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START)
364
        else if((SD_LoggingError || (SD_WatchDog < 2000 && SD_WatchDog != 0)) && Parameter.GlobalConfig3 & CFG3_NO_SDCARD_NO_START)
388
        {
365
        {
389
         LED_RED_ON;       
366
                LED_RED_ON;        
390
         sprintf(ErrorMSG,"ERR:SD Logging abort");
367
                sprintf(ErrorMSG,"ERR:SD Logging abort");
391
         newErrorCode = 27;
368
                newErrorCode = 27;
392
         DebugOut.StatusRed |= AMPEL_NC;
369
                DebugOut.StatusRed |= AMPEL_NC;
393
         SD_LoggingError = 0;
370
                SD_LoggingError = 0;
394
        }
371
        }
395
        else if(((AbsoluteFlyingAltitude) && (NaviData.Altimeter / 20 >= AbsoluteFlyingAltitude)) && (FC.StatusFlags & FC_STATUS_FLY))
372
        else if(((AbsoluteFlyingAltitude) && (NaviData.Altimeter / 20 >= AbsoluteFlyingAltitude)) && (FC.StatusFlags & FC_STATUS_FLY))
396
        {
373
        {
397
         LED_RED_ON;
374
                LED_RED_ON;
398
         sprintf(ErrorMSG,"ERR:Max Altitude ");
375
                sprintf(ErrorMSG,"ERR:Max Altitude ");
399
         newErrorCode = 29;
376
                newErrorCode = 29;
400
         DebugOut.StatusRed |= AMPEL_NC;
377
                DebugOut.StatusRed |= AMPEL_NC;
401
        }
378
        }
402
        else if(Parameter.GlobalConfig3 & CFG3_NO_GPSFIX_NO_START && !(NCFlags & NC_FLAG_GPS_OK) && ((FC.StatusFlags & (FC_STATUS_START | FC_STATUS_MOTOR_RUN)) || (FC.StickGas < -50 && FC.StickYaw < -50)))
379
        else if(Parameter.GlobalConfig3 & CFG3_NO_GPSFIX_NO_START && !(NCFlags & NC_FLAG_GPS_OK) && ((FC.StatusFlags & (FC_STATUS_START | FC_STATUS_MOTOR_RUN)) || (FC.StickGas < -50 && FC.StickYaw < -50)))
403
        {                                                                                                                                                  
380
        {                                                                                                                                                  
404
         LED_RED_ON;
381
                LED_RED_ON;
405
         sprintf(ErrorMSG,"No GPS Fix      ");
382
                sprintf(ErrorMSG,"No GPS Fix      ");
406
         newErrorCode = 30;
383
                newErrorCode = 30;
407
        }
384
        }
408
        else // no error occured
385
        else // no error occured
409
        {
386
        {
410
                StopNavigation = 0;
387
                StopNavigation = 0;
411
                LED_RED_OFF;
388
                LED_RED_OFF;
412
                if(no_error_delay) { no_error_delay--;  }
389
                if(no_error_delay) { no_error_delay--;  }
413
                else
390
                else
414
                 {                                     
391
                {                                      
415
                  sprintf(ErrorMSG,"No Error            ");
392
                        sprintf(ErrorMSG,"No Error            ");
416
                  ErrorCode = 0;
393
                        ErrorCode = 0;
417
                 }
394
                }
418
        }
395
        }
Line 419... Line 396...
419
 
396
 
420
    if(newErrorCode)
397
    if(newErrorCode)
421
         {
398
         {
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