Subversion Repositories NaviCtrl

Rev

Rev 254 | Rev 256 | Go to most recent revision | 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"
242 killagreg 68
#include "compass.h"
119 killagreg 69
#include "timer1.h"
70
#include "timer2.h"
134 killagreg 71
#include "analog.h"
41 ingob 72
#include "spi_slave.h"
73
#include "fat16.h"
74
#include "usb.h"
75
#include "sdc.h"
82 killagreg 76
#include "logging.h"
156 killagreg 77
#include "params.h"
88 killagreg 78
#include "settings.h"
154 killagreg 79
#include "config.h"
1 ingob 80
#include "main.h"
250 ingob 81
#include "debug.h"
1 ingob 82
 
254 killagreg 83
#include "eeprom.h"
84
 
218 killagreg 85
u8 BoardRelease = 0;
41 ingob 86
u32 TimerCheckError;
234 killagreg 87
u8 ErrorCode = 0;
41 ingob 88
u16 BeepTime;
92 killagreg 89
u8  NCFlags = 0;
153 killagreg 90
s16 GeoMagDec = 0; // local magnetic declination in 0.1 deg
1 ingob 91
 
255 killagreg 92
u8 ClearFCStatusFlags = 0;
41 ingob 93
u8 StopNavigation = 0;
94
Param_t Parameter;
78 holgerb 95
volatile FC_t FC;
1 ingob 96
 
41 ingob 97
s8 ErrorMSG[25];
98
 
1 ingob 99
//----------------------------------------------------------------------------------------------------
41 ingob 100
void SCU_Config(void)
1 ingob 101
{
41 ingob 102
        /* configure PLL and set it as master clock source */
103
        SCU_MCLKSourceConfig(SCU_MCLK_OSC);             // set master clock source to external oscillator clock (25MHz) before diabling the PLL
104
        SCU_PLLCmd(DISABLE);                                    // now disable the PLL
105
        #ifdef MCLK96MHZ
106
        SCU_BRCLKDivisorConfig(SCU_BRCLK_Div2); // set BRCLK to MCLK/2 = 48MHz
107
        SCU_PCLKDivisorConfig(SCU_PCLK_Div4);   // set PCLK     (APB bus clock) divisor to 4 (half Reference Clock)
108
        SCU_RCLKDivisorConfig(SCU_RCLK_Div2);   // set RCLK     (Reference Clock) divisor to 1 (full PPL clock)
109
        SCU_HCLKDivisorConfig(SCU_HCLK_Div2);   // set HCLK     (AHB bus clock) divisor to 1 (full Reference Clock)
110
        SCU_PLLFactorsConfig(192,25,2);                 // PLL = 96 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=2
111
        #else
112
        SCU_BRCLKDivisorConfig(SCU_BRCLK_Div1); // set BRCLK to MCLK = 48MHz
113
        SCU_PCLKDivisorConfig(SCU_PCLK_Div2);   // set PCLK     (APB bus clock) divisor to 2 (half Reference Clock)
114
        SCU_RCLKDivisorConfig(SCU_RCLK_Div1);   // set RCLK     (Reference Clock) divisor to 1 (full PPL clock)
115
        SCU_HCLKDivisorConfig(SCU_HCLK_Div1);   // set HCLK     (AHB bus clock) divisor to 1 (full Reference Clock)
116
        SCU_PLLFactorsConfig(192,25,3);                 // PLL = 48 MHz, Feedback Divider N=192, Pre-Divider M=25, Post-Divider P=3
117
        #endif
118
        SCU_PLLCmd(ENABLE);                                     // Enable PLL (is disabled by SCU_PLLFactorsConfig)
119
        SCU_MCLKSourceConfig(SCU_MCLK_PLL);     // set master clock source to PLL
120
}
1 ingob 121
 
41 ingob 122
//----------------------------------------------------------------------------------------------------
123
void GetNaviCtrlVersion(void)
1 ingob 124
{
41 ingob 125
        u8 msg[25];
1 ingob 126
 
41 ingob 127
        sprintf(msg,"\n\r NaviCtrl V%d.%d%c",  VERSION_MAJOR,  VERSION_MINOR, 'a'+ VERSION_PATCH);
110 killagreg 128
        UART1_PutString(msg);
1 ingob 129
}
130
 
131
//----------------------------------------------------------------------------------------------------
231 holgerb 132
#define ERROR_FC_COMMUNICATION          0x01
133
#define ERROR_MK3_COMMUNICATION         0x02
134
#define ERROR_FC_INCOMPATIBLE           0x04
135
#define ERROR_MK3_INCOMPATIBLE          0x08
136
#define ERROR_GPS_COMMUNICATION         0x10
137
#define ERROR_COMPASS_VALUE                     0x20
138
//----------------------------------------------------------------------------------------------------
139
 
41 ingob 140
void CheckErrors(void)
141
{
232 killagreg 142
        UART_VersionInfo.HardwareError[0] = 0;
231 holgerb 143
 
254 killagreg 144
        if(/*(MK3MAG_Version.Compatible != MK3MAG_I2C_COMPATIBLE) ||*/ CheckDelay(I2C1_Timeout) || (Compass_Heading < 0)) DebugOut.Status[1] |= 0x08;
232 killagreg 145
        else DebugOut.Status[1] &= ~0x08; // MK3Mag green status
231 holgerb 146
 
255 killagreg 147
        if((FC.Error[1] & FC_ERROR1_I2C) || (FC.Error[1] & FC_ERROR1_BL_MISSING)) DebugOut.Status[1] |= 0x02;
232 killagreg 148
        else DebugOut.Status[1] &= ~0x02; // BL-Ctrl green status
149
 
146 killagreg 150
        if(CheckDelay(SPI0_Timeout))
41 ingob 151
        {
152
                LED_RED_ON;
153
                sprintf(ErrorMSG,"no FC communication ");
154
                ErrorCode = 3;
155
                StopNavigation = 1;
231 holgerb 156
                DebugOut.Status[0] &= ~0x01; // status of FC Present
232 killagreg 157
                DebugOut.Status[0] &= ~0x02; // status of BL Present
231 holgerb 158
                UART_VersionInfo.HardwareError[0] |= ERROR_FC_COMMUNICATION;
41 ingob 159
        }
229 holgerb 160
        else if(CheckDelay(I2C1_Timeout))
41 ingob 161
        {
162
                LED_RED_ON;
163
                sprintf(ErrorMSG,"no MK3Mag communication ");
149 killagreg 164
                //Reset I2CBus
165
                I2C1_Deinit();
166
                I2C1_Init();
41 ingob 167
                ErrorCode = 4;
168
                StopNavigation = 1;
231 holgerb 169
                UART_VersionInfo.HardwareError[0] |= ERROR_MK3_COMMUNICATION;
232 killagreg 170
                DebugOut.Status[1] |= 0x08;
41 ingob 171
        }
172
        else if(FC_Version.Compatible != FC_SPI_COMPATIBLE)
173
        {
174
                LED_RED_ON;
175
                sprintf(ErrorMSG,"FC not compatible ");
176
                ErrorCode = 1;
177
                StopNavigation = 1;
231 holgerb 178
                UART_VersionInfo.HardwareError[0] |= ERROR_FC_INCOMPATIBLE;
41 ingob 179
        }
231 holgerb 180
 
255 killagreg 181
        else if(FC.Error[0] & FC_ERROR0_GYRO_NICK)
231 holgerb 182
        {
183
                LED_RED_ON;
184
                sprintf(ErrorMSG,"ERR: FC Nick Gyro");
185
                ErrorCode = 10;
232 killagreg 186
        }
255 killagreg 187
        else if(FC.Error[0] & FC_ERROR0_GYRO_ROLL)
231 holgerb 188
        {
189
                LED_RED_ON;
190
                sprintf(ErrorMSG,"ERR: FC Roll Gyro");
191
                ErrorCode = 11;
232 killagreg 192
        }
255 killagreg 193
        else if(FC.Error[0] & FC_ERROR0_GYRO_YAW)
231 holgerb 194
        {
195
                LED_RED_ON;
196
                sprintf(ErrorMSG,"ERR: FC Yaw Gyro");
197
                ErrorCode = 12;
232 killagreg 198
        }
255 killagreg 199
        else if(FC.Error[0] & FC_ERROR0_ACC_NICK)
231 holgerb 200
        {
201
                LED_RED_ON;
202
                sprintf(ErrorMSG,"ERR: FC Nick ACC");
203
                ErrorCode = 13;
232 killagreg 204
        }
255 killagreg 205
        else if(FC.Error[0] & FC_ERROR0_ACC_ROLL)
231 holgerb 206
        {
207
                LED_RED_ON;
208
                sprintf(ErrorMSG,"ERR: FC Roll ACC");
209
                ErrorCode = 14;
232 killagreg 210
        }
255 killagreg 211
        else if(FC.Error[0] & FC_ERROR0_ACC_TOP)
231 holgerb 212
        {
213
                LED_RED_ON;
214
                sprintf(ErrorMSG,"ERR: FC Z-ACC");
215
                ErrorCode = 15;
232 killagreg 216
        }
255 killagreg 217
        else if(FC.Error[0] & FC_ERROR0_PRESSURE)
231 holgerb 218
        {
219
                LED_RED_ON;
220
                sprintf(ErrorMSG,"ERR: Pressure sensor");
221
                ErrorCode = 16;
232 killagreg 222
        }
255 killagreg 223
        else if(FC.Error[1] &  FC_ERROR1_I2C)
231 holgerb 224
        {
225
                LED_RED_ON;
226
                sprintf(ErrorMSG,"ERR: FC I2C");
227
                ErrorCode = 17;
232 killagreg 228
        }
255 killagreg 229
        else if(FC.Error[1] &  FC_ERROR1_BL_MISSING)
231 holgerb 230
        {
231
                LED_RED_ON;
232
                sprintf(ErrorMSG,"ERR: Bl Missing");
233
                ErrorCode = 18;
232 killagreg 234
        }
255 killagreg 235
        else if(FC.Error[1] &  FC_ERROR1_MIXER)
231 holgerb 236
        {
237
                LED_RED_ON;
238
                sprintf(ErrorMSG,"Mixer Error");
239
                ErrorCode = 19;
232 killagreg 240
        }
242 killagreg 241
/*      else if(MK3MAG_Version.Compatible != MK3MAG_I2C_COMPATIBLE)
41 ingob 242
        {
243
                sprintf(ErrorMSG,"MK3Mag not compatible ");
244
                LED_RED_ON;
245
                ErrorCode = 2;
246
                StopNavigation = 1;
231 holgerb 247
                UART_VersionInfo.HardwareError[0] |= ERROR_MK3_INCOMPATIBLE;
242 killagreg 248
        } */
146 killagreg 249
        else if(CheckDelay(UBX_Timeout))
41 ingob 250
        {
251
                LED_RED_ON;
252
                sprintf(ErrorMSG,"no GPS communication ");
253
                ErrorCode = 5;
254
                StopNavigation = 1;
231 holgerb 255
                UART_VersionInfo.HardwareError[0] |= ERROR_GPS_COMMUNICATION;
41 ingob 256
        }
254 killagreg 257
        else if(Compass_Heading < 0)
41 ingob 258
        {
259
                LED_RED_ON;
260
                sprintf(ErrorMSG,"bad compass value ");
261
                ErrorCode = 6;
262
                StopNavigation = 1;
231 holgerb 263
                UART_VersionInfo.HardwareError[0] |= ERROR_COMPASS_VALUE;
41 ingob 264
        }
255 killagreg 265
        else if((FC.Error[1] &  FC_ERROR1_SPI_RX))
199 killagreg 266
        {
267
                LED_RED_ON;
268
                sprintf(ErrorMSG,"FC spi rx error ");
269
                ErrorCode = 8;
213 killagreg 270
                StopNavigation = 1;
199 killagreg 271
        }
255 killagreg 272
        else if(FC.Error[0] &  FC_ERROR0_CAREFREE)
231 holgerb 273
        {
274
                LED_RED_ON;
275
                sprintf(ErrorMSG,"FC: Carefree Error");
276
                ErrorCode = 20;
232 killagreg 277
        }
255 killagreg 278
        else if(FC.Error[1] &  FC_ERROR1_PPM)
41 ingob 279
        {
280
                LED_RED_ON;
281
                sprintf(ErrorMSG,"RC Signal lost ");
282
                ErrorCode = 7;
283
        }
284
        else // no error occured
285
        {
286
                sprintf(ErrorMSG,"No Error               ");
287
                ErrorCode = 0;
288
                StopNavigation = 0;
289
                LED_RED_OFF;
290
        }
232 killagreg 291
        if(UART_VersionInfo.HardwareError[0] || UART_VersionInfo.HardwareError[1]) DebugOut.Status[1] |= 0x04;
292
        else DebugOut.Status[1] &= ~0x04;
41 ingob 293
}
24 StephanB 294
 
154 killagreg 295
// the handler will be cyclic called by the timer 1 ISR
213 killagreg 296
// used is for critical timing parts that normaly would handled
154 killagreg 297
// within the main loop that could block longer at logging activities
298
void EXTIT3_IRQHandler(void)
299
{
195 killagreg 300
        IENABLE;
301
 
154 killagreg 302
        VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq
195 killagreg 303
        VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit
242 killagreg 304
        Compass_UpdateHeading();        // update compass communication
154 killagreg 305
        Analog_Update();                // get new ADC values
195 killagreg 306
        VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq
154 killagreg 307
 
195 killagreg 308
        IDISABLE;
154 killagreg 309
}
310
 
41 ingob 311
//----------------------------------------------------------------------------------------------------
312
int main(void)
313
{
314
        /* Configure the system clocks */
315
        SCU_Config();
316
        /* init VIC (Vectored Interrupt Controller)     */
317
        SCU_AHBPeriphClockConfig(__VIC,ENABLE); // enable AHB bus clock for VIC
318
        SCU_AHBPeriphReset(__VIC, DISABLE);             // disable reset state for VIC
319
        VIC_DeInit();                                                   // deinitializes the VIC module registers to their default reset values.
196 killagreg 320
        VIC_InitDefaultVectors();
321
 
119 killagreg 322
        // initialize timer 1 for System Clock and delay rountines
41 ingob 323
        TIMER1_Init();
324
        // initialize the LEDs (needs Timer 1)
325
        Led_Init();
326
        // initialize the debug UART1
327
        UART1_Init();
110 killagreg 328
        UART1_PutString("\r\n---------------------------------------------");
120 killagreg 329
        // initialize timer 2 for servo outputs
180 killagreg 330
        //TIMER2_Init();
41 ingob 331
        // initialize UART2 to FLIGHTCTRL
332
        UART2_Init();
333
        // initialize UART0 (to MKGPS or MK3MAG)
334
        UART0_Init();
134 killagreg 335
        // initialize adc
336
        Analog_Init();
41 ingob 337
        // initialize usb
254 killagreg 338
        USB_ConfigInit();
41 ingob 339
        // initialize SPI0 to FC
340
        SPI0_Init();
242 killagreg 341
        // initialize i2c bus (needs Timer 1)
41 ingob 342
        I2C1_Init();
247 killagreg 343
        // initialize fat16 partition on sd card (needs Timer 1)
41 ingob 344
        Fat16_Init();
156 killagreg 345
        // initialize NC params
346
        NCParams_Init();
88 killagreg 347
        // initialize the settings
348
        Settings_Init();
92 killagreg 349
        // initialize logging (needs settings)
82 killagreg 350
        Logging_Init();
1 ingob 351
 
41 ingob 352
        TimerCheckError = SetDelay(3000);
175 holgerb 353
        UART1_PutString("\r\n++++++++++++++++++++++++++++++++++++++++++");
110 killagreg 354
        UART1_PutString("\n\r Version information:");
116 killagreg 355
 
41 ingob 356
        GetNaviCtrlVersion();
231 holgerb 357
        DebugOut.Status[0] = 0x04 | 0x08; // NC and MK3Mag
358
        DebugOut.Status[1] = 0x00;
149 killagreg 359
 
242 killagreg 360
        Compass_Init();
361
 
150 killagreg 362
        SPI0_GetFlightCtrlVersion();
363
        if(FC_Version.Compatible != FC_SPI_COMPATIBLE)
41 ingob 364
        {
150 killagreg 365
                UART1_PutString("\n\r Flight-Ctrl not compatible");
41 ingob 366
                LED_RED_ON;
367
        }
1 ingob 368
 
247 killagreg 369
        GPS_Init();    
116 killagreg 370
 
254 killagreg 371
        /*{
372
        u8 i;
373
        u8 text[20];
374
        u8 mesg[10];
375
        UART1_PutString("\r\nFill\r\n");
376
        for(i=0;i<20;i++)
377
        {
378
                text[i] = 0xAA;
379
                sprintf(mesg,"%02X ", text[i]);
380
                UART1_PutString(mesg);
381
        }
382
 
383
        sprintf(mesg, "\r\nEERead = %d\r\n", EEPROM_ReadBlock(50, text, 18));
384
        UART1_PutString(mesg);
385
        for(i=0;i<20;i++)
386
        {
387
                sprintf(mesg,"%02X ", text[i]);
388
                UART1_PutString(mesg);
389
                text[i] = i;
390
        }
391
        UART1_PutString("\r\nFill\r\n");
392
        for(i=0;i<20;i++)
393
        {
394
                sprintf(mesg,"%02X ", text[i]);
395
                UART1_PutString(mesg);
396
        }
397
        sprintf(mesg, "\r\nEEWrite = %d\r\n", EEPROM_WriteBlock(0, text, 18));
398
        UART1_PutString(mesg);
399
        for(i=0;i<20;i++)
400
        {
401
                sprintf(mesg,"%02X ", text[i]);
402
                UART1_PutString(mesg);
403
                text[i]=0xAA;
404
        }
405
        UART1_PutString("\r\nFill\r\n");
406
        for(i=0;i<20;i++)
407
        {
408
                sprintf(mesg,"%02X ", text[i]);
409
                UART1_PutString(mesg);
410
        }
411
        sprintf(mesg, "\r\nEERead = %d\r\n", EEPROM_ReadBlock(0, text, 18));
412
        UART1_PutString(mesg);
413
        for(i=0;i<20;i++)
414
        {
415
                sprintf(mesg,"%02X ", text[i]);
416
                UART1_PutString(mesg);
417
        }
418
        }*/
419
 
213 killagreg 420
        // ---------- Prepare the isr driven
154 killagreg 421
        // set to absolute lowest priority
422
    VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW);
195 killagreg 423
        // enable interrupts
154 killagreg 424
    VIC_ITCmd(EXTIT3_ITLine, ENABLE);
244 killagreg 425
 
250 ingob 426
        Debug_OK("START");
427
 
254 killagreg 428
 
154 killagreg 429
        for (;;) // the endless main loop
41 ingob 430
        {
155 killagreg 431
                UART0_ProcessRxData();  // process request
432
                UART1_ProcessRxData();  // process request
254 killagreg 433
                USB_ProcessRxData();    // process request
154 killagreg 434
                UART0_TransmitTxData(); // send answer
146 killagreg 435
                UART1_TransmitTxData(); // send answer
190 killagreg 436
                UART2_TransmitTxData(); // send answer
254 killagreg 437
                USB_TransmitTxData();   // send answer
155 killagreg 438
                SPI0_UpdateBuffer();    // handle new SPI Data
41 ingob 439
                // ---------------- Error Check Timing ----------------------------
440
                if(CheckDelay(TimerCheckError))
1 ingob 441
                {
114 killagreg 442
                        TimerCheckError = SetDelay(1000);
215 killagreg 443
                        if(CheckDelay(SPI0_Timeout)) GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); // process the GPS data even if the FC is not connected
41 ingob 444
                        CheckErrors();
255 killagreg 445
                        if(FC.StatusFlags & FC_STATUS_FLY) NaviData.FlyingTime++; // we want to count the battery-time
146 killagreg 446
//                      else NaviData.FlyingTime = 0; // not the time per flight
92 killagreg 447
                        if(SerialLinkOkay) SerialLinkOkay--;
448
                        if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication
449
                        else NCFlags &= ~NC_FLAG_NOSERIALLINK;
228 holgerb 450
                        if(StopNavigation && (Parameter.NaviGpsModeControl >=  50)) BeepTime = 1000;
1 ingob 451
                }
82 killagreg 452
                // ---------------- Logging  ---------------------------------------
146 killagreg 453
                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 454
        }
1 ingob 455
}
456
 
24 StephanB 457