Subversion Repositories NaviCtrl

Rev

Rev 690 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 690 Rev 693
Line 80... Line 80...
80
 
80
 
81
 
81
 
82
//communication packets
82
//communication packets
-
 
83
FromFlightCtrl_t   FromFlightCtrl;
83
FromFlightCtrl_t   FromFlightCtrl;
84
ToFlightCtrl_t     ToFlightCtrl;
84
ToFlightCtrl_t     ToFlightCtrl;
85
paramset_t EE_Parameter;
85
#define SPI0_TIMEOUT     2500  //ms
86
#define SPI0_TIMEOUT     2500  //ms
86
volatile u32 SPI0_Timeout = 0;
87
volatile u32 SPI0_Timeout = 0;
87
u8 Logging_FCStatusFlags1 = 0,Logging_FCStatusFlags2 = 0;
88
u8 Logging_FCStatusFlags1 = 0,Logging_FCStatusFlags2 = 0;
Line 105... Line 106...
105
s32 Kalman_MaxDrift = 5 * 16;
106
s32 Kalman_MaxDrift = 5 * 16;
106
s32 Kalman_MaxFusion = 64;
107
s32 Kalman_MaxFusion = 64;
107
s32 Kalman_Kompass = 32;
108
s32 Kalman_Kompass = 32;
108
s32 ToFcGpsZ = 0;
109
s32 ToFcGpsZ = 0;
109
u8 CompassCalState = 0;
110
u8 CompassCalState = 0;
-
 
111
u8 RequestConfigFromFC = 1;
Line 110... Line 112...
110
 
112
 
111
u8 SPI_CommandSequence[] = {    SPI_NCCMD_KALMAN, SPI_NCCMD_GPSINFO, SPI_SERIAL_CH,  // Achtung: SPI_SERIAL_CH darf nicht am Ende des Arrays stehen     (wird gescipped)
113
u8 SPI_CommandSequence[] = {    SPI_NCCMD_KALMAN, SPI_NCCMD_GPSINFO, SPI_SERIAL_CH,  // Achtung: SPI_SERIAL_CH darf nicht am Ende des Arrays stehen     (wird gescipped)
112
                                                                SPI_NCCMD_KALMAN, SPI_NCCMD_HOTT_INFO,
114
                                                                SPI_NCCMD_KALMAN, SPI_NCCMD_HOTT_INFO,
113
                                                                SPI_NCCMD_KALMAN, SPI_MISC,
115
                                                                SPI_NCCMD_KALMAN, SPI_MISC,
Line 163... Line 165...
163
        // clear pending bits
165
        // clear pending bits
164
        SSP_ClearITPendingBit(SSP0, SSP_IT_RxTimeOut);
166
        SSP_ClearITPendingBit(SSP0, SSP_IT_RxTimeOut);
165
        SSP_ClearITPendingBit(SSP0, SSP_IT_RxFifo);
167
        SSP_ClearITPendingBit(SSP0, SSP_IT_RxFifo);
Line 166... Line 168...
166
 
168
 
167
        // while RxFIFO not empty
-
 
168
DebugOut.Analog[18] = 0;
169
        // while RxFIFO not empty
169
        while(SSP_GetFlagStatus(SSP0, SSP_FLAG_RxFifoNotEmpty) == SET)
170
        while(SSP_GetFlagStatus(SSP0, SSP_FLAG_RxFifoNotEmpty) == SET)
170
        {
171
        {
171
                rxdata =  SSP0->DR; // catch the received byte
172
                rxdata =  SSP0->DR; // catch the received byte
172
                switch (SPI_State)
173
                switch (SPI_State)
Line 182... Line 183...
182
                                        memcpy((u8 *) &(SPI_TxBuffer[2]), (u8 *) &ToFlightCtrl, sizeof(ToFlightCtrl));
183
                                        memcpy((u8 *) &(SPI_TxBuffer[2]), (u8 *) &ToFlightCtrl, sizeof(ToFlightCtrl));
183
                                        SPI_TxBuffer[0] = SPI_NCSYNCBYTE1;
184
                                        SPI_TxBuffer[0] = SPI_NCSYNCBYTE1;
184
                                        SPI_TxBuffer[1] = SPI_NCSYNCBYTE2;
185
                                        SPI_TxBuffer[1] = SPI_NCSYNCBYTE2;
185
                                        SPI_Tx_Datasize = sizeof(ToFlightCtrl) + 2;     // +2 weil die Syncbytes nicht in dem Block stehen
186
                                        SPI_Tx_Datasize = sizeof(ToFlightCtrl) + 2;     // +2 weil die Syncbytes nicht in dem Block stehen
186
                                        Ptr_TxChksum = (u8 *) &(((ToFlightCtrl_t *) &(SPI_TxBuffer[2]))->Chksum);
187
                                        Ptr_TxChksum = (u8 *) &(((ToFlightCtrl_t *) &(SPI_TxBuffer[2]))->Chksum);
187
DebugOut.Analog[16]++;
-
 
188
                                }
188
                                }
189
                                else
189
                                else
190
                                if (rxdata == SPI_FCSYNCBYTE_HB1)
190
                                if (rxdata == SPI_FCSYNCBYTE_HB1)
191
                                {   // 1st syncbyte ok
191
                                {   // 1st syncbyte ok
192
                                        SPI_State = SPI_SYNC_HB;  // step to syncHB
192
                                        SPI_State = SPI_SYNC_HB;  // step to syncHB
193
                                        SPI_RxBuffer[SPI_RxBufferIndex++]= rxdata; // sync1
193
                                        SPI_RxBuffer[SPI_RxBufferIndex++]= rxdata; // sync1
194
                                        HugeBlockToFC.Sync1 = SPI_NCSYNCBYTE1;
194
                                        HugeBlockToFC.Sync1 = SPI_NCSYNCBYTE1;
195
                                        HugeBlockToFC.Sync2 = SPI_NCSYNCBYTE_HB2;
195
                                        HugeBlockToFC.Sync2 = SPI_NCSYNCBYTE_HB2;
196
                                        HugeBlockToFC.Chksum = 0;
196
                                        HugeBlockToFC.Chksum = 0;
197
                                        memcpy((u8 *) &(SPI_TxBuffer[0]), (u8 *) &HugeBlockToFC, sizeof(HugeBlockToFC));
197
                                        memcpy((u8 *) &(SPI_TxBuffer[0]), (u8 *) &HugeBlockToFC, sizeof(HugeBlockToFC));
198
HugeBlockToFC.Data[239]++;
-
 
199
                                        SPI_Tx_Datasize = sizeof(HugeBlockToFC);
198
                                        SPI_Tx_Datasize = sizeof(HugeBlockToFC);
200
                                        Ptr_TxChksum = (u8 *) &(((str_HugeBlockToFC *) &(SPI_TxBuffer[0]))->Chksum);
199
                                        Ptr_TxChksum = (u8 *) &(((str_HugeBlockToFC *) &(SPI_TxBuffer[0]))->Chksum);
201
                                        *Ptr_TxChksum = 0;
200
                                        *Ptr_TxChksum = 0;
202
DebugOut.Analog[17]++;
-
 
203
                                }
201
                                }
204
                                break;
202
                                break;
205
                        case SPI_SYNC2:
203
                        case SPI_SYNC2:
206
                                if (rxdata == SPI_FCSYNCBYTE2)
204
                                if (rxdata == SPI_FCSYNCBYTE2)
207
                                {  // 2nd Syncbyte ok
205
                                {  // 2nd Syncbyte ok
Line 257... Line 255...
257
                                if(SPI_RxBufferIndex >= sizeof(HugeBlockFromFC))  // end of packet is reached
255
                                if(SPI_RxBufferIndex >= sizeof(HugeBlockFromFC))  // end of packet is reached
258
                                {
256
                                {
259
                                        if (rxdata == rxchksum) // verify checksum byte
257
                                        if (rxdata == rxchksum) // verify checksum byte
260
                                        {
258
                                        {
261
                                                // copy SPI_RxBuffer -> FromFlightCtrl
259
                                                // copy SPI_RxBuffer -> FromFlightCtrl
262
//DebugOut.Analog[17]++;
-
 
263
                                                if(!SPI_RxBuffer_Request) // block writing to FromFlightCtrl on reading access
-
 
264
                                                {
-
 
265
                                                        memcpy((u8 *) &HugeBlockFromFC, (u8 *) SPI_RxBuffer, sizeof(HugeBlockFromFC));
260
                                                memcpy((u8 *) &HugeBlockFromFC, (u8 *) SPI_RxBuffer, sizeof(HugeBlockFromFC));
266
//                                                      SPI_RxBuffer_Request = 1;
-
 
267
                                                }
-
 
268
//DebugOut.Analog[18] = HugeBlockFromFC.Data[239];
-
 
269
                                                // reset timeout counter on good packet
261
                                                // reset timeout counter on good packet
270
                                                SPI0_Timeout = SetDelay(SPI0_TIMEOUT);
262
                                                SPI0_Timeout = SetDelay(SPI0_TIMEOUT);
271
//                                              DebugOut.Analog[13]++;
-
 
272
                                        }
263
                                        }
273
                                        else // bad checksum byte
264
                                        else // bad checksum byte
274
                                        {
265
                                        {
275
                                                DebugOut.Analog[12]++; // increase SPI chksum error counter
266
                                                DebugOut.Analog[12]++; // increase SPI chksum error counter
276
                                        }
267
                                        }
Line 289... Line 280...
289
// + Ouput Data
280
// + Ouput Data
290
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
281
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
291
                // Fill TxFIFO while its not full or end of packet is reached
282
                // Fill TxFIFO while its not full or end of packet is reached
292
                while((SSP_GetFlagStatus(SSP0, SSP_FLAG_TxFifoNotFull) == SET) && (SPI_TxBufferIndex  < SPI_Tx_Datasize))
283
                while((SSP_GetFlagStatus(SSP0, SSP_FLAG_TxFifoNotFull) == SET) && (SPI_TxBufferIndex  < SPI_Tx_Datasize))
293
                {
284
                {
294
DebugOut.Analog[18]++;
-
 
295
                        SSP0->DR = SPI_TxBuffer[SPI_TxBufferIndex];       // send a byte
285
                        SSP0->DR = SPI_TxBuffer[SPI_TxBufferIndex];       // send a byte
296
                        *Ptr_TxChksum += SPI_TxBuffer[SPI_TxBufferIndex]; // update checksum
286
                        *Ptr_TxChksum += SPI_TxBuffer[SPI_TxBufferIndex]; // update checksum
297
                        if(SPIWatchDog == 0) *Ptr_TxChksum += 1; // disturbe this packet to stop the communication!
287
                        if(SPIWatchDog == 0) *Ptr_TxChksum += 1; // disturbe this packet to stop the communication!
298
                        SPI_TxBufferIndex++; // pointer to next byte
288
                        SPI_TxBufferIndex++; // pointer to next byte
299
                }
289
                }
Line 356... Line 346...
356
 
346
 
357
        VIC_Config(SSP0_ITLine, VIC_IRQ, PRIORITY_SPI0);
347
        VIC_Config(SSP0_ITLine, VIC_IRQ, PRIORITY_SPI0);
Line 358... Line 348...
358
        VIC_ITCmd(SSP0_ITLine, ENABLE);
348
        VIC_ITCmd(SSP0_ITLine, ENABLE);
359
 
-
 
-
 
349
 
-
 
350
        SPI0_Timeout = SetDelay(4*SPI0_TIMEOUT);
360
        SPI0_Timeout = SetDelay(4*SPI0_TIMEOUT);
351
        EE_Parameter.Revision = 0;
361
 
352
        sprintf(EE_Parameter.Name,"???\0");
Line 362... Line 353...
362
        UART1_PutString("ok");
353
        UART1_PutString("ok");
Line 489... Line 480...
489
                                ToFlightCtrl.Param.Byte[7] = ErrorCode;                          // muss in SPI_NCCMD_VERSION bleiben! (siehe oben)
480
                                ToFlightCtrl.Param.Byte[7] = ErrorCode;                          // muss in SPI_NCCMD_VERSION bleiben! (siehe oben)
490
                                ToFlightCtrl.Param.Byte[8] = NC_GPS_ModeCharacter;
481
                                ToFlightCtrl.Param.Byte[8] = NC_GPS_ModeCharacter;
491
                                ToFlightCtrl.Param.Byte[9] = SerialLinkOkay;
482
                                ToFlightCtrl.Param.Byte[9] = SerialLinkOkay;
492
                                ToFlightCtrl.Param.Byte[10] = NC_To_FC_Flags;
483
                                ToFlightCtrl.Param.Byte[10] = NC_To_FC_Flags;
493
                                ToFlightCtrl.Param.Byte[11] = SpeakHoTT;
484
                                ToFlightCtrl.Param.Byte[11] = SpeakHoTT;
-
 
485
                                ToFlightCtrl.Param.Byte[12] = RequestConfigFromFC & 0x01;
494
                                SpeakHoTT = 0;
486
                                SpeakHoTT = 0;
495
//                              if(AbsoluteFlyingAltitude > 255) ToFlightCtrl.Param.Byte[11] = 0; // then the limitation of the FC doesn't work
487
//                              if(AbsoluteFlyingAltitude > 255) ToFlightCtrl.Param.Byte[11] = 0; // then the limitation of the FC doesn't work
496
//                              else ToFlightCtrl.Param.Byte[11] = AbsoluteFlyingAltitude;
488
//                              else ToFlightCtrl.Param.Byte[11] = AbsoluteFlyingAltitude;
497
                                break;
489
                                break;
498
                        case SPI_MISC:
490
                        case SPI_MISC: