Rev 488 | Rev 490 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 488 | Rev 489 | ||
---|---|---|---|
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 | - | ||
Line 157... | Line 153... | ||
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 | ||
162 | if(CheckDelay(I2C1_Timeout) && (I2C_CompassPort == I2C_INTERN_1)) |
- | |
163 | { |
158 | if(CheckDelay(I2CBus(Compass_I2CPort)->Timeout)) |
164 | LED_RED_ON; |
159 | { |
165 | sprintf(ErrorMSG,"no compass communica"); |
160 | LED_RED_ON; |
166 | //Reset I2CBus |
161 | sprintf(ErrorMSG,"no compass communica"); |
167 | I2C1_Deinit(); |
162 | //Reset Compass communication |
168 | I2C1_Init(); |
163 | Compass_Init(); |
169 | newErrorCode = 4; |
- | |
170 | StopNavigation = 1; |
- | |
171 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
- | |
172 | DebugOut.StatusRed |= AMPEL_COMPASS; |
- | |
173 | } |
- | |
174 | else if(CheckDelay(I2C0_Timeout) && (I2C_CompassPort == I2C_EXTERN_0)) |
- | |
175 | { |
- | |
176 | LED_RED_ON; |
- | |
177 | //LED_RED_ON_T; |
- | |
178 | sprintf(ErrorMSG,"no ext. compass "); |
- | |
179 | //Reset I2CBus |
- | |
180 | I2C0_Deinit(); |
- | |
181 | I2C0_Init(); |
- | |
182 | NCMAG_Update(1); |
- | |
183 | newErrorCode = 33; |
164 | newErrorCode = 4; |
184 | StopNavigation = 1; |
165 | StopNavigation = 1; |
185 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
166 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_RX; |
186 | DebugOut.StatusRed |= AMPEL_COMPASS; |
167 | DebugOut.StatusRed |= AMPEL_COMPASS; |
187 | } |
168 | } |
188 | else if(CompassValueErrorCount > 30) |
169 | else if(CompassValueErrorCount > 30) |
189 | { |
170 | { |
190 | LED_RED_ON; |
- | |
191 | sprintf(ErrorMSG,"compass sensor error"); |
- | |
192 | newErrorCode = 34; |
- | |
193 | StopNavigation = 1; |
171 | LED_RED_ON; |
194 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
- | |
195 | if(I2C_CompassPort == I2C_INTERN_1) |
- | |
196 | { |
- | |
197 | I2C1_Deinit(); |
- | |
198 | I2C1_Init(); |
- | |
199 | } |
- | |
200 | else |
172 | sprintf(ErrorMSG,"compass sensor error"); |
201 | { |
- | |
202 | I2C0_Deinit(); |
173 | newErrorCode = 34; |
203 | I2C0_Init(); |
174 | StopNavigation = 1; |
204 | } |
175 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_COMPASS_VALUE; |
205 | } |
176 | Compass_Init(); |
206 | else |
177 | } |
207 | if((FCCalibActive || CompassCalState) && FC_Version.Hardware) |
178 | else if((FCCalibActive || CompassCalState) && FC_Version.Hardware) |
208 | { |
179 | { |
209 | sprintf(ErrorMSG,"Calibrate... "); |
- | |
210 | newErrorCode = 0; |
180 | sprintf(ErrorMSG,"Calibrate... "); |
211 | ErrorCode = 0; |
181 | newErrorCode = 0; |
212 | no_error_delay = 1; |
182 | ErrorCode = 0; |
213 | } |
183 | no_error_delay = 1; |
214 | else |
184 | } |
215 | if(CheckDelay(SPI0_Timeout)) |
185 | else if(CheckDelay(SPI0_Timeout)) |
Line 233... | Line 203... | ||
233 | newErrorCode = 1; |
203 | newErrorCode = 1; |
234 | StopNavigation = 1; |
204 | StopNavigation = 1; |
235 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE; |
205 | UART_VersionInfo.HardwareError[0] |= NC_ERROR0_FC_INCOMPATIBLE; |
236 | DebugOut.StatusRed |= AMPEL_NC; |
206 | DebugOut.StatusRed |= AMPEL_NC; |
237 | } |
207 | } |
238 | - | ||
239 | else if(FC.Error[0] & FC_ERROR0_GYRO_NICK) |
208 | else if(FC.Error[0] & FC_ERROR0_GYRO_NICK) |
240 | { |
209 | { |
241 | LED_RED_ON; |
210 | LED_RED_ON; |
242 | sprintf(ErrorMSG,"ERR: FC Nick Gyro"); |
211 | sprintf(ErrorMSG,"ERR: FC Nick Gyro"); |
243 | newErrorCode = 10; |
212 | newErrorCode = 10; |
Line 372... | Line 341... | ||
372 | newErrorCode = 23; |
341 | newErrorCode = 23; |
373 | DebugOut.StatusRed |= AMPEL_BL; |
342 | DebugOut.StatusRed |= AMPEL_BL; |
374 | } |
343 | } |
375 | else if(BL_MinOfMaxPWM < 30 && !ErrorCode) |
344 | else if(BL_MinOfMaxPWM < 30 && !ErrorCode) |
376 | { |
345 | { |
377 | unsigned int i; |
346 | u16 i; |
378 | for(i = 0; i < 12; i++) if(Motor[i].MaxPWM == BL_MinOfMaxPWM) break; |
347 | for(i = 0; i < 12; i++) if(Motor[i].MaxPWM == BL_MinOfMaxPWM) break; |
379 | - | ||
380 | LED_RED_ON; |
348 | LED_RED_ON; |
381 | sprintf(ErrorMSG,"ERR:BL%2d Test:%2d ",i+1,BL_MinOfMaxPWM); |
349 | sprintf(ErrorMSG,"ERR:BL%2d Test:%2d ",i+1,BL_MinOfMaxPWM); |
382 | newErrorCode = 32; |
350 | newErrorCode = 32; |
383 | DebugOut.StatusRed |= AMPEL_BL; |
351 | DebugOut.StatusRed |= AMPEL_BL; |
384 | } |
352 | } |
Line 453... | Line 421... | ||
453 | 421 | ||
454 | u8 Polling(void) |
422 | u8 Polling(void) |
455 | { |
423 | { |
456 | static u8 running = 0, oldFcFlags = 0, count5sec; |
424 | static u8 running = 0, oldFcFlags = 0, count5sec; |
- | 425 | static u32 old_ms = 0; |
|
457 | static u32 old_ms = 0; |
426 | |
458 | if(running) {/*DebugOut.Analog[18]++;*/ return(1);}; |
427 | if(running) {/*DebugOut.Analog[18]++;*/ return(1);}; |
- | 428 | running = 1; |
|
459 | running = 1; |
429 | |
460 | if(CountMilliseconds != old_ms) // 1 ms |
430 | if(CountMilliseconds != old_ms) // 1 ms |
461 | { |
431 | { |
462 | old_ms = CountMilliseconds; |
432 | old_ms = CountMilliseconds; |
463 | Compass_Update(); // update compass communication |
433 | Compass_Update(); // update compass communication |
464 | Analog_Update(); // get new ADC values |
434 | Analog_Update(); // get new ADC values |
465 | CalcHeadFree(); |
435 | CalcHeadFree(); |
- | 436 | } |
|
466 | } |
437 | |
467 | SPI0_UpdateBuffer(); // also calls the GPS-functions |
438 | SPI0_UpdateBuffer(); // also calls the GPS-functions |
468 | UART0_ProcessRxData(); // GPS process request |
439 | UART0_ProcessRxData(); // GPS process request |
469 | UART0_TransmitTxData(); // GPS send answer |
440 | UART0_TransmitTxData(); // GPS send answer |
470 | UART1_ProcessRxData(); // PC process request |
441 | UART1_ProcessRxData(); // PC process request |
471 | UART1_TransmitTxData(); // PC send answer |
442 | UART1_TransmitTxData(); // PC send answer |
472 | UART2_TransmitTxData(); // FC send answer |
- | |
Line 473... | Line 443... | ||
473 | // ---------------- Error Check Timing ---------------------------- |
443 | UART2_TransmitTxData(); // FC send answer |
474 | 444 | ||
475 | //DebugOut.Analog[16] = CompassValueErrorCount; |
445 | // ---------------- Error Check Timing ---------------------------- |
476 | if(CheckDelay(TimerCheckError) || (FC.StatusFlags & FC_STATUS_START && !(oldFcFlags & FC_STATUS_START))) // Timer or FY wants to start |
446 | if(CheckDelay(TimerCheckError) || (FC.StatusFlags & FC_STATUS_START && !(oldFcFlags & FC_STATUS_START))) // Timer or FY wants to start |
477 | { |
447 | { |
478 | if(CheckDelay(TimerCheckError)) |
448 | if(CheckDelay(TimerCheckError)) |
Line 511... | Line 481... | ||
511 | { |
481 | { |
512 | IENABLE; |
482 | IENABLE; |
513 | VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq |
483 | VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq |
514 | // Compass_Update(); // update compass communication |
484 | //Compass_Update(); // update compass communication |
515 | // Analog_Update(); // get new ADC values |
485 | //Analog_Update(); // get new ADC values |
- | 486 | ||
516 | if(PollingTimeout == 0) |
487 | if(PollingTimeout == 0) |
517 | { |
488 | { |
518 | PollingTimeout = 5; |
489 | PollingTimeout = 5; |
519 | // if(Polling() == 0) DebugOut.Analog[16]++; |
490 | //if(Polling() == 0) DebugOut.Analog[16]++; |
520 | Polling(); |
491 | Polling(); |
Line 528... | Line 499... | ||
528 | 499 | ||
529 | //---------------------------------------------------------------------------------------------------- |
500 | //---------------------------------------------------------------------------------------------------- |
530 | int main(void) |
501 | int main(void) |
Line 531... | Line 502... | ||
531 | { |
502 | { |
532 | 503 | ||
533 | static u32 ftimer =0; |
504 | // static u32 ftimer =0; |
Line 534... | Line 505... | ||
534 | static u8 fstate = 0; |
505 | // static u8 fstate = 0; |
535 | // static File_t* f = NULL; |
506 | // static File_t* f = NULL; |
Line 559... | Line 530... | ||
559 | // initialize adc |
530 | // initialize adc |
560 | Analog_Init(); |
531 | Analog_Init(); |
561 | // initialize SPI0 to FC |
532 | // initialize SPI0 to FC |
562 | SPI0_Init(); |
533 | SPI0_Init(); |
563 | // initialize i2c busses (needs Timer 1) |
534 | // initialize i2c busses (needs Timer 1) |
564 | I2C0_Init(); |
535 | I2CBus_Init(I2C0); |
565 | I2C1_Init(); |
536 | I2CBus_Init(I2C1); |
Line 566... | Line 537... | ||
566 | 537 | ||
567 | // initialize fat16 partition on sd card (needs Timer 1) |
538 | // initialize fat16 partition on sd card (needs Timer 1) |
568 | Fat16_Init(); |
539 | Fat16_Init(); |
569 | // initialize NC params |
540 | // initialize NC params |
Line 617... | Line 588... | ||
617 | CompassValueErrorCount = 0; |
588 | CompassValueErrorCount = 0; |
618 | for (;;) // the endless main loop |
589 | for (;;) // the endless main loop |
619 | { |
590 | { |
620 | PollingTimeout = 5; |
591 | PollingTimeout = 5; |
621 | Polling(); |
592 | Polling(); |
622 | // ---------------- Logging --------------------------------------- |
- | |
Line -... | Line 593... | ||
- | 593 | ||
623 | 594 | // ---------------- Logging --------------------------------------- |
|
624 | if(SD_WatchDog) |
595 | if(SD_WatchDog) |
625 | { |
596 | { |
626 | SD_WatchDog = 30000; |
597 | SD_WatchDog = 30000; |
627 | 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 |
598 | 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 |
628 | else if(FC.StatusFlags & FC_STATUS_START) SD_LoggingError = 100; |
599 | else if(FC.StatusFlags & FC_STATUS_START) SD_LoggingError = 100; |
629 | if(!SD_WatchDog) UART1_PutString("\n\rSD-Watchdog - Logging aborted\n\r"); |
600 | if(!SD_WatchDog) UART1_PutString("\n\rSD-Watchdog - Logging aborted\n\r"); |
- | 601 | } |
|
630 | } |
602 | |
631 | /* |
603 | /* |
632 | if(CheckDelay(ftimer)) |
604 | if(CheckDelay(ftimer)) |
Line 633... | Line 605... | ||
633 | { |
605 | { |