Subversion Repositories NaviCtrl

Rev

Rev 238 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ingob 1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
171 ingob 6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
1 ingob 7
// + FOR NON COMMERCIAL USE ONLY
8
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 ingob 10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
13
// + bzgl. der Nutzungsbedingungen aufzunehmen.
1 ingob 14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
15
// + Verkauf von Luftbildaufnahmen, usw.
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 ingob 17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
1 ingob 18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
22
// + eindeutig als Ursprung verlinkt werden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
25
// + Benutzung auf eigene Gefahr
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171 ingob 28
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
1 ingob 29
// + mit unserer Zustimmung zulässig
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Teile, die nicht eindeutig mit unserer Lizenzvereinbarung gekennzeichnet sind, unterliegen u.U. eigenen Vereinbarungen:
41 ingob 32
// + z.B. Die Funktion printf_P() unterliegt ihrer eigenen Lizenz
1 ingob 33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 ingob 34
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
1 ingob 35
// + this list of conditions and the following disclaimer.
36
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
37
// +     from this software without specific prior written permission.
41 ingob 38
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
1 ingob 39
// +     for non-commercial use (directly or indirectly)
41 ingob 40
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
1 ingob 41
// +     with our written permission
41 ingob 42
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
43
// +     clearly linked as origin
171 ingob 44
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
1 ingob 45
//
46
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
47
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
50
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
52
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 ingob 56
// +  POSSIBILITY OF SUCH DAMAGE.
1 ingob 57
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 ingob 58
//#define MCLK96MHZ
1 ingob 59
const unsigned long _Main_Crystal = 25000;
41 ingob 60
#include <stdio.h>
61
#include "91x_lib.h"
62
#include "led.h"
63
#include "uart0.h"
64
#include "uart1.h"
65
#include "uart2.h"
215 killagreg 66
#include "gps.h"
41 ingob 67
#include "i2c.h"
119 killagreg 68
#include "timer1.h"
69
#include "timer2.h"
134 killagreg 70
#include "analog.h"
41 ingob 71
#include "spi_slave.h"
72
#include "fat16.h"
73
#include "usb.h"
74
#include "sdc.h"
82 killagreg 75
#include "logging.h"
156 killagreg 76
#include "params.h"
88 killagreg 77
#include "settings.h"
154 killagreg 78
#include "config.h"
1 ingob 79
#include "main.h"
80
 
218 killagreg 81
u8 BoardRelease = 0;
41 ingob 82
u32 TimerCheckError;
234 killagreg 83
u8 ErrorCode = 0;
41 ingob 84
u16 BeepTime;
92 killagreg 85
u8  NCFlags = 0;
153 killagreg 86
s16 GeoMagDec = 0; // local magnetic declination in 0.1 deg
1 ingob 87
 
199 killagreg 88
u8 ClearFCFlags = 0;
41 ingob 89
u8 StopNavigation = 0;
90
Param_t Parameter;
78 holgerb 91
volatile FC_t FC;
1 ingob 92
 
41 ingob 93
s8 ErrorMSG[25];
94
 
1 ingob 95
//----------------------------------------------------------------------------------------------------
41 ingob 96
void SCU_Config(void)
1 ingob 97
{
41 ingob 98
        /* configure PLL and set it as master clock source */
99
        SCU_MCLKSourceConfig(SCU_MCLK_OSC);             // set master clock source to external oscillator clock (25MHz) before diabling the PLL
100
        SCU_PLLCmd(DISABLE);                                    // now disable the PLL
101
        #ifdef MCLK96MHZ
102
        SCU_BRCLKDivisorConfig(SCU_BRCLK_Div2); // set BRCLK to MCLK/2 = 48MHz
103
        SCU_PCLKDivisorConfig(SCU_PCLK_Div4);   // set PCLK     (APB bus clock) divisor to 4 (half Reference Clock)
104
        SCU_RCLKDivisorConfig(SCU_RCLK_Div2);   // set RCLK     (Reference Clock) divisor to 1 (full PPL clock)
105
        SCU_HCLKDivisorConfig(SCU_HCLK_Div2);   // set HCLK     (AHB bus clock) divisor to 1 (full Reference Clock)
106
        SCU_PLLFactorsConfig(192,25,2);                 // PLL = 96 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=2
107
        #else
108
        SCU_BRCLKDivisorConfig(SCU_BRCLK_Div1); // set BRCLK to MCLK = 48MHz
109
        SCU_PCLKDivisorConfig(SCU_PCLK_Div2);   // set PCLK     (APB bus clock) divisor to 2 (half Reference Clock)
110
        SCU_RCLKDivisorConfig(SCU_RCLK_Div1);   // set RCLK     (Reference Clock) divisor to 1 (full PPL clock)
111
        SCU_HCLKDivisorConfig(SCU_HCLK_Div1);   // set HCLK     (AHB bus clock) divisor to 1 (full Reference Clock)
112
        SCU_PLLFactorsConfig(192,25,3);                 // PLL = 48 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=3
113
        #endif
114
        SCU_PLLCmd(ENABLE);                                     // Enable PLL (is disabled by SCU_PLLFactorsConfig)
115
        SCU_MCLKSourceConfig(SCU_MCLK_PLL);     // set master clock source to PLL
116
}
1 ingob 117
 
41 ingob 118
//----------------------------------------------------------------------------------------------------
119
void GetNaviCtrlVersion(void)
1 ingob 120
{
41 ingob 121
        u8 msg[25];
1 ingob 122
 
41 ingob 123
        sprintf(msg,"\n\r NaviCtrl V%d.%d%c",  VERSION_MAJOR,  VERSION_MINOR, 'a'+ VERSION_PATCH);
110 killagreg 124
        UART1_PutString(msg);
1 ingob 125
}
126
 
127
//----------------------------------------------------------------------------------------------------
231 holgerb 128
#define DEFEKT_G_NICK           0x01
129
#define DEFEKT_G_ROLL           0x02
130
#define DEFEKT_G_GIER           0x04
131
#define DEFEKT_A_NICK           0x08
132
#define DEFEKT_A_ROLL           0x10
133
#define DEFEKT_A_Z              0x20
134
#define DEFEKT_PRESSURE         0x40
135
#define DEFEKT_CAREFREE_ERR 0x80
136
 
137
#define DEFEKT_I2C              0x01
138
#define DEFEKT_BL_MISSING       0x02
139
#define DEFEKT_SPI_RX_ERR       0x04
140
#define DEFEKT_PPM_ERR          0x08
141
#define DEFEKT_MIXER_ERR    0x10
142
//----------------------------------------------------------------------------------------------------
143
#define ERROR_FC_COMMUNICATION          0x01
144
#define ERROR_MK3_COMMUNICATION         0x02
145
#define ERROR_FC_INCOMPATIBLE           0x04
146
#define ERROR_MK3_INCOMPATIBLE          0x08
147
#define ERROR_GPS_COMMUNICATION         0x10
148
#define ERROR_COMPASS_VALUE                     0x20
149
//----------------------------------------------------------------------------------------------------
150
 
41 ingob 151
void CheckErrors(void)
152
{
232 killagreg 153
        UART_VersionInfo.HardwareError[0] = 0;
231 holgerb 154
 
232 killagreg 155
        if((MK3MAG_Version.Compatible != MK3MAG_I2C_COMPATIBLE) || CheckDelay(I2C1_Timeout) || (I2C_Heading.Heading < 0)) DebugOut.Status[1] |= 0x08;
156
        else DebugOut.Status[1] &= ~0x08; // MK3Mag green status
231 holgerb 157
 
232 killagreg 158
        if((FC_ErrorCode[1] & DEFEKT_I2C) || (FC_ErrorCode[1] & DEFEKT_BL_MISSING)) DebugOut.Status[1] |= 0x02;
159
        else DebugOut.Status[1] &= ~0x02; // BL-Ctrl green status
160
 
146 killagreg 161
        if(CheckDelay(SPI0_Timeout))
41 ingob 162
        {
163
                LED_RED_ON;
164
                sprintf(ErrorMSG,"no FC communication ");
165
                ErrorCode = 3;
166
                StopNavigation = 1;
231 holgerb 167
                DebugOut.Status[0] &= ~0x01; // status of FC Present
232 killagreg 168
                DebugOut.Status[0] &= ~0x02; // status of BL Present
231 holgerb 169
                UART_VersionInfo.HardwareError[0] |= ERROR_FC_COMMUNICATION;
41 ingob 170
        }
229 holgerb 171
        else if(CheckDelay(I2C1_Timeout))
41 ingob 172
        {
173
                LED_RED_ON;
174
                sprintf(ErrorMSG,"no MK3Mag communication ");
149 killagreg 175
                //Reset I2CBus
176
                I2C1_Deinit();
177
                I2C1_Init();
41 ingob 178
                ErrorCode = 4;
179
                StopNavigation = 1;
231 holgerb 180
                UART_VersionInfo.HardwareError[0] |= ERROR_MK3_COMMUNICATION;
232 killagreg 181
                DebugOut.Status[1] |= 0x08;
41 ingob 182
        }
183
        else if(FC_Version.Compatible != FC_SPI_COMPATIBLE)
184
        {
185
                LED_RED_ON;
186
                sprintf(ErrorMSG,"FC not compatible ");
187
                ErrorCode = 1;
188
                StopNavigation = 1;
231 holgerb 189
                UART_VersionInfo.HardwareError[0] |= ERROR_FC_INCOMPATIBLE;
41 ingob 190
        }
231 holgerb 191
 
192
        else if(FC_ErrorCode[0] & DEFEKT_G_NICK)
193
        {
194
                LED_RED_ON;
195
                sprintf(ErrorMSG,"ERR: FC Nick Gyro");
196
                ErrorCode = 10;
232 killagreg 197
        }
231 holgerb 198
        else if(FC_ErrorCode[0] & DEFEKT_G_ROLL)
199
        {
200
                LED_RED_ON;
201
                sprintf(ErrorMSG,"ERR: FC Roll Gyro");
202
                ErrorCode = 11;
232 killagreg 203
        }
231 holgerb 204
        else if(FC_ErrorCode[0] & DEFEKT_G_GIER)
205
        {
206
                LED_RED_ON;
207
                sprintf(ErrorMSG,"ERR: FC Yaw Gyro");
208
                ErrorCode = 12;
232 killagreg 209
        }
231 holgerb 210
        else if(FC_ErrorCode[0] & DEFEKT_A_NICK)
211
        {
212
                LED_RED_ON;
213
                sprintf(ErrorMSG,"ERR: FC Nick ACC");
214
                ErrorCode = 13;
232 killagreg 215
        }
231 holgerb 216
        else if(FC_ErrorCode[0] & DEFEKT_A_ROLL)
217
        {
218
                LED_RED_ON;
219
                sprintf(ErrorMSG,"ERR: FC Roll ACC");
220
                ErrorCode = 14;
232 killagreg 221
        }
231 holgerb 222
        else if(FC_ErrorCode[0] & DEFEKT_A_Z)
223
        {
224
                LED_RED_ON;
225
                sprintf(ErrorMSG,"ERR: FC Z-ACC");
226
                ErrorCode = 15;
232 killagreg 227
        }
231 holgerb 228
        else if(FC_ErrorCode[0] & DEFEKT_PRESSURE)
229
        {
230
                LED_RED_ON;
231
                sprintf(ErrorMSG,"ERR: Pressure sensor");
232
                ErrorCode = 16;
232 killagreg 233
        }
231 holgerb 234
        else if(FC_ErrorCode[1] & DEFEKT_I2C)
235
        {
236
                LED_RED_ON;
237
                sprintf(ErrorMSG,"ERR: FC I2C");
238
                ErrorCode = 17;
232 killagreg 239
        }
231 holgerb 240
        else if(FC_ErrorCode[1] & DEFEKT_BL_MISSING)
241
        {
242
                LED_RED_ON;
243
                sprintf(ErrorMSG,"ERR: Bl Missing");
244
                ErrorCode = 18;
232 killagreg 245
        }
231 holgerb 246
        else if(FC_ErrorCode[1] & DEFEKT_MIXER_ERR)
247
        {
248
                LED_RED_ON;
249
                sprintf(ErrorMSG,"Mixer Error");
250
                ErrorCode = 19;
232 killagreg 251
        }
41 ingob 252
        else if(MK3MAG_Version.Compatible != MK3MAG_I2C_COMPATIBLE)
253
        {
254
                sprintf(ErrorMSG,"MK3Mag not compatible ");
255
                LED_RED_ON;
256
                ErrorCode = 2;
257
                StopNavigation = 1;
231 holgerb 258
                UART_VersionInfo.HardwareError[0] |= ERROR_MK3_INCOMPATIBLE;
41 ingob 259
        }
146 killagreg 260
        else if(CheckDelay(UBX_Timeout))
41 ingob 261
        {
262
                LED_RED_ON;
263
                sprintf(ErrorMSG,"no GPS communication ");
264
                ErrorCode = 5;
265
                StopNavigation = 1;
231 holgerb 266
                UART_VersionInfo.HardwareError[0] |= ERROR_GPS_COMMUNICATION;
41 ingob 267
        }
268
        else if(I2C_Heading.Heading < 0)
269
        {
270
                LED_RED_ON;
271
                sprintf(ErrorMSG,"bad compass value ");
272
                ErrorCode = 6;
273
                StopNavigation = 1;
231 holgerb 274
                UART_VersionInfo.HardwareError[0] |= ERROR_COMPASS_VALUE;
41 ingob 275
        }
199 killagreg 276
        else if(FC.Flags & FCFLAG_SPI_RX_ERR)
277
        {
278
                LED_RED_ON;
279
                sprintf(ErrorMSG,"FC spi rx error ");
280
                ErrorCode = 8;
213 killagreg 281
                StopNavigation = 1;
199 killagreg 282
        }
231 holgerb 283
        else if(FC_ErrorCode[0] & DEFEKT_CAREFREE_ERR)
284
        {
285
                LED_RED_ON;
286
                sprintf(ErrorMSG,"FC: Carefree Error");
287
                ErrorCode = 20;
232 killagreg 288
        }
41 ingob 289
        else if(FC.RC_Quality < 100)
290
        {
291
                LED_RED_ON;
292
                sprintf(ErrorMSG,"RC Signal lost ");
293
                ErrorCode = 7;
294
        }
295
        else // no error occured
296
        {
297
                sprintf(ErrorMSG,"No Error               ");
298
                ErrorCode = 0;
299
                StopNavigation = 0;
300
                LED_RED_OFF;
301
        }
232 killagreg 302
        if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 0x04;
303
        else DebugOut.Status[1] &= ~0x04;
41 ingob 304
}
24 StephanB 305
 
154 killagreg 306
// the handler will be cyclic called by the timer 1 ISR
213 killagreg 307
// used is for critical timing parts that normaly would handled
154 killagreg 308
// within the main loop that could block longer at logging activities
309
void EXTIT3_IRQHandler(void)
310
{
195 killagreg 311
        IENABLE;
312
 
154 killagreg 313
        VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq
195 killagreg 314
        VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit
213 killagreg 315
        I2C1_UpdateCompass();   // update compass communication
154 killagreg 316
        Analog_Update();                // get new ADC values
195 killagreg 317
        VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq
154 killagreg 318
 
195 killagreg 319
        IDISABLE;
154 killagreg 320
}
321
 
41 ingob 322
//----------------------------------------------------------------------------------------------------
323
int main(void)
324
{
325
        /* Configure the system clocks */
326
        SCU_Config();
327
        /* init VIC (Vectored Interrupt Controller)     */
328
        SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC
329
        SCU_AHBPeriphReset(__VIC, DISABLE);             // disable reset state for VIC
330
        VIC_DeInit();                                                   // deinitializes the VIC module registers to their default reset values.
196 killagreg 331
        VIC_InitDefaultVectors();
332
 
119 killagreg 333
        // initialize timer 1 for System Clock and delay rountines
41 ingob 334
        TIMER1_Init();
335
        // initialize the LEDs (needs Timer 1)
336
        Led_Init();
337
        // initialize the debug UART1
338
        UART1_Init();
110 killagreg 339
        UART1_PutString("\r\n---------------------------------------------");
120 killagreg 340
        // initialize timer 2 for servo outputs
180 killagreg 341
        //TIMER2_Init();
41 ingob 342
        // initialize UART2 to FLIGHTCTRL
343
        UART2_Init();
344
        // initialize UART0 (to MKGPS or MK3MAG)
345
        UART0_Init();
134 killagreg 346
        // initialize adc
347
        Analog_Init();
41 ingob 348
        // initialize usb
141 killagreg 349
        //USB_ConfigInit();
41 ingob 350
        // initialize SPI0 to FC
351
        SPI0_Init();
352
        // initialize i2c bus to MK3MAG (needs Timer 1)
228 holgerb 353
        I2C_Heading.Heading = -1;
41 ingob 354
        I2C1_Init();
355
        // initialize the gps position controller (needs Timer 1)
356
        Fat16_Init();
156 killagreg 357
        // initialize NC params
358
        NCParams_Init();
88 killagreg 359
        // initialize the settings
360
        Settings_Init();
92 killagreg 361
        // initialize logging (needs settings)
82 killagreg 362
        Logging_Init();
1 ingob 363
 
41 ingob 364
        TimerCheckError = SetDelay(3000);
175 holgerb 365
        UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++");
110 killagreg 366
        UART1_PutString("\n\r Version information:");
116 killagreg 367
 
41 ingob 368
        GetNaviCtrlVersion();
231 holgerb 369
        DebugOut.Status[0] = 0x04 | 0x08; // NC and MK3Mag
370
        DebugOut.Status[1] = 0x00;
149 killagreg 371
 
150 killagreg 372
        I2C1_GetMK3MagVersion();
373
        if(MK3MAG_Version.Compatible != MK3MAG_I2C_COMPATIBLE)
41 ingob 374
        {
150 killagreg 375
                UART1_PutString("\n\r MK3Mag not compatible");
41 ingob 376
                LED_RED_ON;
377
        }
78 holgerb 378
 
150 killagreg 379
        SPI0_GetFlightCtrlVersion();
380
        if(FC_Version.Compatible != FC_SPI_COMPATIBLE)
41 ingob 381
        {
150 killagreg 382
                UART1_PutString("\n\r Flight-Ctrl not compatible");
41 ingob 383
                LED_RED_ON;
384
        }
1 ingob 385
 
116 killagreg 386
        UART0_GetMKOSDVersion();
387
 
175 holgerb 388
        GPS_Init();
389
        // initialize fat16 partition on sd card (needs Timer 1)
213 killagreg 390
 
391
        // ---------- Prepare the isr driven
154 killagreg 392
        // set to absolute lowest priority
393
    VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW);
195 killagreg 394
        // enable interrupts
154 killagreg 395
    VIC_ITCmd(EXTIT3_ITLine, ENABLE);
396
        for (;;) // the endless main loop
41 ingob 397
        {
155 killagreg 398
                UART0_ProcessRxData();  // process request
399
                UART1_ProcessRxData();  // process request
400
                USB_ProcessRxData();    // process request
154 killagreg 401
                UART0_TransmitTxData(); // send answer
146 killagreg 402
                UART1_TransmitTxData(); // send answer
190 killagreg 403
                UART2_TransmitTxData(); // send answer
112 killagreg 404
                USB_TransmitTxData();   // send answer
405
 
155 killagreg 406
                SPI0_UpdateBuffer();    // handle new SPI Data
41 ingob 407
                // ---------------- Error Check Timing ----------------------------
408
                if(CheckDelay(TimerCheckError))
1 ingob 409
                {
114 killagreg 410
                        TimerCheckError = SetDelay(1000);
215 killagreg 411
                        if(CheckDelay(SPI0_Timeout)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected
41 ingob 412
                        CheckErrors();
199 killagreg 413
                        if(FC.Flags & FCFLAG_FLY) NaviData.FlyingTime++; // we want to count the battery-time
146 killagreg 414
//                      else NaviData.FlyingTime = 0; // not the time per flight
92 killagreg 415
                        if(SerialLinkOkay) SerialLinkOkay--;
416
                        if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication
417
                        else NCFlags &= ~NC_FLAG_NOSERIALLINK;
228 holgerb 418
                        if(StopNavigation && (Parameter.NaviGpsModeControl >=  50)) BeepTime = 1000;
1 ingob 419
                }
82 killagreg 420
                // ---------------- Logging  ---------------------------------------
146 killagreg 421
                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
24 StephanB 422
        }
1 ingob 423
}
424
 
24 StephanB 425