Subversion Repositories NaviCtrl

Rev

Rev 141 | Rev 149 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 141 Rev 146
Line 74... Line 74...
74
#include "sdc.h"
74
#include "sdc.h"
75
#include "logging.h"
75
#include "logging.h"
76
#include "settings.h"
76
#include "settings.h"
77
#include "main.h"
77
#include "main.h"
Line 78... Line -...
78
 
-
 
79
u32 TimerCompassUpdate;
78
 
80
u32 TimerCheckError;
79
u32 TimerCheckError;
81
u32 ErrorCode = 0;
80
u32 ErrorCode = 0;
82
u16 BeepTime;
81
u16 BeepTime;
83
u8  NCFlags = 0;
82
u8  NCFlags = 0;
Line 123... Line 122...
123
}
122
}
Line 124... Line 123...
124
 
123
 
125
//----------------------------------------------------------------------------------------------------
124
//----------------------------------------------------------------------------------------------------
126
void CheckErrors(void)
125
void CheckErrors(void)
127
{
126
{
128
        if(!CheckSPIOkay)
127
        if(CheckDelay(SPI0_Timeout))
129
        {
128
        {
130
                LED_RED_ON;
129
                LED_RED_ON;
131
                sprintf(ErrorMSG,"no FC communication ");
130
                sprintf(ErrorMSG,"no FC communication ");
132
                ErrorCode = 3;
131
                ErrorCode = 3;
133
                StopNavigation = 1;
132
                StopNavigation = 1;
134
        }
133
        }
135
        else if(!CheckI2COkay)
134
        else if(CheckDelay(I2C1_Timeout))
136
        {
135
        {
137
                LED_RED_ON;
136
                LED_RED_ON;
138
                sprintf(ErrorMSG,"no MK3Mag communication ");
137
                sprintf(ErrorMSG,"no MK3Mag communication ");
139
                ErrorCode = 4;
138
                ErrorCode = 4;
Line 151... Line 150...
151
                sprintf(ErrorMSG,"MK3Mag not compatible ");
150
                sprintf(ErrorMSG,"MK3Mag not compatible ");
152
                LED_RED_ON;
151
                LED_RED_ON;
153
                ErrorCode = 2;
152
                ErrorCode = 2;
154
                StopNavigation = 1;
153
                StopNavigation = 1;
155
        }
154
        }
156
        else if(!CheckGPSOkay)
155
        else if(CheckDelay(UBX_Timeout))
157
        {
156
        {
158
                LED_RED_ON;
157
                LED_RED_ON;
159
                sprintf(ErrorMSG,"no GPS communication ");
158
                sprintf(ErrorMSG,"no GPS communication ");
160
                ErrorCode = 5;
159
                ErrorCode = 5;
161
                StopNavigation = 1;
160
                StopNavigation = 1;
Line 178... Line 177...
178
                sprintf(ErrorMSG,"No Error               ");
177
                sprintf(ErrorMSG,"No Error               ");
179
                ErrorCode = 0;
178
                ErrorCode = 0;
180
                StopNavigation = 0;
179
                StopNavigation = 0;
181
                LED_RED_OFF;
180
                LED_RED_OFF;
182
        }
181
        }
183
        CheckSPIOkay = 0;
-
 
184
        CheckGPSOkay = 0;
-
 
185
        CheckI2COkay = 0;
-
 
186
}
182
}
Line 187... Line 183...
187
 
183
 
Line 226... Line 222...
226
        // initialize the settings
222
        // initialize the settings
227
        Settings_Init();
223
        Settings_Init();
228
        // initialize logging (needs settings)
224
        // initialize logging (needs settings)
229
        Logging_Init();
225
        Logging_Init();
Line 230... Line -...
230
 
-
 
231
        TimerCompassUpdate = SetDelay(5);
226
 
232
        TimerCheckError = SetDelay(3000);
227
        TimerCheckError = SetDelay(3000);
233
        UART1_PutString("\r\n---------------------------------------------");
228
        UART1_PutString("\r\n---------------------------------------------");
Line 234... Line 229...
234
        UART1_PutString("\n\r Version information:");
229
        UART1_PutString("\n\r Version information:");
Line 235... Line 230...
235
 
230
 
236
        GetNaviCtrlVersion();
231
        GetNaviCtrlVersion();
237
       
232
       
238
        SPI0_GetFlightCtrlVersion();
-
 
239
        if(FC_Version.Compatible != FC_SPI_COMPATIBLE)
-
 
240
        {
233
        SPI0_GetFlightCtrlVersion();
241
                //sprintf(ErrorMSG,"\r\n %d <-> %d", FlightCtrlVersion.NaviCompatible, FC_SPI_COMPATIBLE);
234
        if(FC_Version.Compatible != FC_SPI_COMPATIBLE)
242
                //UART1_PutString(ErrorMSG);
235
        {
Line 243... Line 236...
243
                UART1_PutString("\n\r Flight-Ctrl not compatible");
236
                UART1_PutString("\n\r Flight-Ctrl not compatible");
Line 256... Line 249...
256
        UART1_PutString("\r\n---------------------------------------------\r\n\r\n");
249
        UART1_PutString("\r\n---------------------------------------------\r\n\r\n");
Line 257... Line 250...
257
 
250
 
258
        for (;;)
251
        for (;;)
259
        {
252
        {
260
                UART1_ProcessRxData();  // process request
253
                UART1_ProcessRxData();  // process request
Line 261... Line 254...
261
                UART1_TransmitTxData();         // send answer
254
                UART1_TransmitTxData(); // send answer
262
 
255
 
Line 263... Line 256...
263
                UART0_ProcessRxData();  // process request
256
                UART0_ProcessRxData();  // process request
264
                UART0_TransmitTxData();         // send answer
257
                UART0_TransmitTxData(); // send answer
Line 265... Line 258...
265
 
258
 
266
                USB_ProcessRxData();    // process request
-
 
267
                USB_TransmitTxData();   // send answer
-
 
268
 
259
                USB_ProcessRxData();    // process request
269
                SPI0_UpdateBuffer();
-
 
270
                // ------------------------- I2C Timing --------------------------------
-
 
271
                if(I2C_State != I2C_OFF)
-
 
272
                {
-
 
273
                        if (CheckDelay(TimerCompassUpdate))
-
 
274
                        {
-
 
275
                                // check for hanging I2C bus
-
 
276
                                if(CheckDelay(I2C1_Timeout))
-
 
277
                                {       // reset I2C
-
 
278
                                        UART1_PutString("\n\rCommunication-Error: MK3Mag\n\r");
-
 
279
                                        I2C1_Deinit();
-
 
280
                                        I2C1_Init();
-
 
281
                                }
-
 
282
                                else
-
 
283
                                {       // check for incomming compass calibration request
-
 
284
                                        // update CalByte from spi input queue
-
 
285
                                        fifo_get(&CompassCalcStateFiFo, (u8 *)&(I2C_WriteCal.CalByte));
-
 
286
                                        // send new calstate
-
 
287
                                        if(I2C_ReadCal.CalByte != I2C_WriteCal.CalByte)
-
 
288
                                        {
-
 
289
                                                I2C1_SendCommand(I2C_CMD_WRITE_CAL);
260
                USB_TransmitTxData();   // send answer
290
                                        }
-
 
291
                                        else // request current heading
-
 
292
                                        {
-
 
293
                                                I2C1_SendCommand(I2C_CMD_READ_HEADING);
-
 
294
                                        }
-
 
295
                                        TimerCompassUpdate = SetDelay(25);    // every 25 ms
-
 
296
                                }
-
 
Line 297... Line 261...
297
                                // update ADC readings
261
 
298
                                ADC_ConversionCmd(ADC_Conversion_Start);
262
                SPI0_UpdateBuffer();    // handle new SPI Data
299
                        }
263
 
300
                }
264
                //I2C1_UpdateCompass(); moved to Timer1 ISR
301
 
265
 
302
                // ---------------- Error Check Timing ----------------------------
266
                // ---------------- Error Check Timing ----------------------------
303
                if(CheckDelay(TimerCheckError))
267
                if(CheckDelay(TimerCheckError))
304
                {
268
                {
305
                        TimerCheckError = SetDelay(1000);
269
                        TimerCheckError = SetDelay(1000);
306
                        if(!CheckSPIOkay) GPS_Navigation(); // process the GPS data even if the FC is not connected
270
                        if(CheckDelay(SPI0_Timeout)) GPS_Navigation(); // process the GPS data even if the FC is not connected
307
                        CheckErrors();
271
                        CheckErrors();
308
                        if(FC.MKFlags & MKFLAG_FLY) NaviData.FlyingTime++; // we want to count the battery-time
272
                        if(FC.MKFlags & MKFLAG_FLY) NaviData.FlyingTime++; // we want to count the battery-time
309
//                      else NaviData.FlyingTime = 0;
273
//                      else NaviData.FlyingTime = 0; // not the time per flight
310
                        UART1_Request_SendFollowMe = TRUE;
274
                        UART1_Request_SendFollowMe = TRUE;
-
 
275
                        if(SerialLinkOkay) SerialLinkOkay--;
-
 
276
                        if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication
311
                        if(SerialLinkOkay) SerialLinkOkay--;
277
                        else NCFlags &= ~NC_FLAG_NOSERIALLINK;
312
                        if(SerialLinkOkay < 250 - 5) NCFlags |= NC_FLAG_NOSERIALLINK; // 5 seconds timeout for serial communication
278
                }
313
                        else NCFlags &= ~NC_FLAG_NOSERIALLINK;
279
                // ---------------- Logging  ---------------------------------------