Subversion Repositories NaviCtrl

Rev

Rev 421 | Rev 432 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 421 Rev 426
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + www.MikroKopter.com
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
// + Software Nutzungsbedingungen (english version: see below)
7
// + Software Nutzungsbedingungen (english version: see below)
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
22
// + des Mitverschuldens offen.
22
// + des Mitverschuldens offen.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Software LICENSING TERMS
32
// + Software LICENSING TERMS
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
37
// + The Software may only be used with the Licensor's products.
37
// + The Software may only be used with the Licensor's products.
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
40
// + agreement shall be the property of the Licensor.
40
// + agreement shall be the property of the Licensor.
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
43
// + The customer shall be responsible for taking reasonable precautions
43
// + The customer shall be responsible for taking reasonable precautions
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
53
// + #### END OF LICENSING TERMS ####
53
// + #### END OF LICENSING TERMS ####
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
 
56
 
57
#include <string.h>
57
#include <string.h>
58
#include <math.h>
58
#include <math.h>
59
#include "91x_lib.h"
59
#include "91x_lib.h"
60
#include "led.h"
60
#include "led.h"
61
#include "gps.h"
61
#include "gps.h"
62
#include "uart1.h"
62
#include "uart1.h"
63
#include "spi_slave.h"
63
#include "spi_slave.h"
64
#include "compass.h"
64
#include "compass.h"
65
#include "timer1.h"
65
#include "timer1.h"
66
#include "timer2.h"
66
#include "timer2.h"
67
#include "config.h"
67
#include "config.h"
68
#include "main.h"
68
#include "main.h"
69
#include "compass.h"
69
#include "compass.h"
70
#include "params.h"
70
#include "params.h"
71
#include "stdlib.h"
71
#include "stdlib.h"
-
 
72
#include "settings.h"
72
 
73
 
73
#define SPI_RXSYNCBYTE1 0xAA
74
#define SPI_RXSYNCBYTE1 0xAA
74
#define SPI_RXSYNCBYTE2 0x83
75
#define SPI_RXSYNCBYTE2 0x83
75
#define SPI_TXSYNCBYTE1 0x81
76
#define SPI_TXSYNCBYTE1 0x81
76
#define SPI_TXSYNCBYTE2 0x55
77
#define SPI_TXSYNCBYTE2 0x55
77
 
78
 
78
//communication packets
79
//communication packets
79
FromFlightCtrl_t   FromFlightCtrl;
80
FromFlightCtrl_t   FromFlightCtrl;
80
ToFlightCtrl_t     ToFlightCtrl;
81
ToFlightCtrl_t     ToFlightCtrl;
81
#define SPI0_TIMEOUT     2500  //ms
82
#define SPI0_TIMEOUT     2500  //ms
82
volatile u32 SPI0_Timeout = 0;
83
volatile u32 SPI0_Timeout = 0;
83
u8 Logging_FCStatusFlags1 = 0,Logging_FCStatusFlags2 = 0;
84
u8 Logging_FCStatusFlags1 = 0,Logging_FCStatusFlags2 = 0;
84
u8 SpeakHoTT = 0;
85
u8 SpeakHoTT = 0;
85
 
86
 
86
// tx packet buffer
87
// tx packet buffer
87
#define SPI_TXBUFFER_LEN (2 + sizeof(ToFlightCtrl)) // 2 bytes at start are for synchronization
88
#define SPI_TXBUFFER_LEN (2 + sizeof(ToFlightCtrl)) // 2 bytes at start are for synchronization
88
volatile u8 SPI_TxBuffer[SPI_TXBUFFER_LEN + 10];
89
volatile u8 SPI_TxBuffer[SPI_TXBUFFER_LEN + 10];
89
volatile u8 SPI_TxBufferIndex = 0;
90
volatile u8 SPI_TxBufferIndex = 0;
90
u8 *Ptr_TxChksum = NULL ;  // pointer to checksum in TxBuffer
91
u8 *Ptr_TxChksum = NULL ;  // pointer to checksum in TxBuffer
91
 
92
 
92
// rx packet buffer
93
// rx packet buffer
93
#define SPI_RXBUFFER_LEN sizeof(FromFlightCtrl)
94
#define SPI_RXBUFFER_LEN sizeof(FromFlightCtrl)
94
volatile u8 SPI_RxBuffer[SPI_RXBUFFER_LEN+10];
95
volatile u8 SPI_RxBuffer[SPI_RXBUFFER_LEN+10];
95
volatile u8 SPI_RxBufferIndex = 0;
96
volatile u8 SPI_RxBufferIndex = 0;
96
volatile u8 SPI_RxBuffer_Request = 0;
97
volatile u8 SPI_RxBuffer_Request = 0;
97
#define SPI_COMMAND_INDEX 0
98
#define SPI_COMMAND_INDEX 0
98
 
99
 
99
s32 Kalman_K = 32;
100
s32 Kalman_K = 32;
100
s32 Kalman_MaxDrift = 5 * 16;
101
s32 Kalman_MaxDrift = 5 * 16;
101
s32 Kalman_MaxFusion = 64;
102
s32 Kalman_MaxFusion = 64;
102
s32 Kalman_Kompass = 32;
103
s32 Kalman_Kompass = 32;
103
s32 ToFcGpsZ = 0;
104
s32 ToFcGpsZ = 0;
104
u8 CompassCalState = 0;
105
u8 CompassCalState = 0;
105
 
106
 
106
u8 SPI_CommandSequence[] = { SPI_NCCMD_KALMAN, SPI_NCCMD_GPSINFO ,SPI_NCCMD_KALMAN, SPI_NCCMD_HOTT_INFO, SPI_NCCMD_KALMAN, SPI_MISC, SPI_NCCMD_KALMAN, SPI_NCCMD_VERSION };
107
u8 SPI_CommandSequence[] = { SPI_NCCMD_KALMAN, SPI_NCCMD_GPSINFO ,SPI_NCCMD_KALMAN, SPI_NCCMD_HOTT_INFO, SPI_NCCMD_KALMAN, SPI_MISC, SPI_NCCMD_KALMAN, SPI_NCCMD_VERSION };
107
u8 SPI_CommandCounter = 0;
108
u8 SPI_CommandCounter = 0;
108
s32 ToFC_Rotate_C = 64, ToFC_Rotate_S = 0;
109
s32 ToFC_Rotate_C = 64, ToFC_Rotate_S = 0;
109
s32 HeadFreeStartAngle = 0;
110
s32 HeadFreeStartAngle = 0;
110
s16 FC_WP_EventChannel = 0, LogFC_WP_EventChannel = 0; // gibt einen Schaltkanal an die FC weiter, wenn der Wegpunkt erreicht wurde
111
s16 FC_WP_EventChannel = 0, LogFC_WP_EventChannel = 0; // gibt einen Schaltkanal an die FC weiter, wenn der Wegpunkt erreicht wurde
111
u32 ToFC_AltitudeRate = 0;
112
u32 ToFC_AltitudeRate = 0;
112
s32 ToFC_AltitudeSetpoint = 0;
113
s32 ToFC_AltitudeSetpoint = 0;
113
u8  FromFC_VarioCharacter = ' ';
114
u8  FromFC_VarioCharacter = ' ';
114
u8 GPS_Aid_StickMultiplikator = 0;
115
u8 GPS_Aid_StickMultiplikator = 0;
115
u8 NC_GPS_ModeCharacter = ' ';
116
u8 NC_GPS_ModeCharacter = ' ';
116
u8 FCCalibActive = 0;
117
u8 FCCalibActive = 0;
117
u8 FC_is_Calibrated = 0;
118
u8 FC_is_Calibrated = 0;
118
Motor_t Motor[12];
119
Motor_t Motor[12];
119
u8 NC_To_FC_Flags = 0;
120
u8 NC_To_FC_Flags = 0;
120
u8 BL_MinOfMaxPWM;  // indication if all BL-controllers run on full power
121
u8 BL_MinOfMaxPWM;  // indication if all BL-controllers run on full power
121
u32 FC_I2C_ErrorConter;
122
u32 FC_I2C_ErrorConter;
122
SPI_Version_t FC_Version;
123
SPI_Version_t FC_Version;
123
s16 POI_KameraNick = 0;
124
s16 POI_KameraNick = 0;
124
 
125
 
125
//--------------------------------------------------------------
126
//--------------------------------------------------------------
126
void SSP0_IRQHandler(void)
127
void SSP0_IRQHandler(void)
127
{
128
{
128
        static u8 rxchksum = 0;
129
        static u8 rxchksum = 0;
129
        u8 rxdata;
130
        u8 rxdata;
130
 
131
 
131
        #define SPI_SYNC1       0
132
        #define SPI_SYNC1       0
132
        #define SPI_SYNC2       1
133
        #define SPI_SYNC2       1
133
        #define SPI_DATA        2
134
        #define SPI_DATA        2
134
        static u8 SPI_State = SPI_SYNC1;
135
        static u8 SPI_State = SPI_SYNC1;
135
        //IENABLE;
136
        //IENABLE;
136
 
137
 
137
        // clear pending bits
138
        // clear pending bits
138
        SSP_ClearITPendingBit(SSP0, SSP_IT_RxTimeOut);
139
        SSP_ClearITPendingBit(SSP0, SSP_IT_RxTimeOut);
139
        SSP_ClearITPendingBit(SSP0, SSP_IT_RxFifo);
140
        SSP_ClearITPendingBit(SSP0, SSP_IT_RxFifo);
140
 
141
 
141
        // while RxFIFO not empty
142
        // while RxFIFO not empty
142
        while(SSP_GetFlagStatus(SSP0, SSP_FLAG_RxFifoNotEmpty) == SET)
143
        while(SSP_GetFlagStatus(SSP0, SSP_FLAG_RxFifoNotEmpty) == SET)
143
        {
144
        {
144
                rxdata =  SSP0->DR; // catch the received byte
145
                rxdata =  SSP0->DR; // catch the received byte
145
                // Fill TxFIFO while its not full or end of packet is reached
146
                // Fill TxFIFO while its not full or end of packet is reached
146
                while (SSP_GetFlagStatus(SSP0, SSP_FLAG_TxFifoNotFull) == SET)
147
                while (SSP_GetFlagStatus(SSP0, SSP_FLAG_TxFifoNotFull) == SET)
147
                {
148
                {
148
                        if (SPI_TxBufferIndex  < SPI_TXBUFFER_LEN)   // still data to send ?
149
                        if (SPI_TxBufferIndex  < SPI_TXBUFFER_LEN)   // still data to send ?
149
                        {
150
                        {
150
                                SSP0->DR = SPI_TxBuffer[SPI_TxBufferIndex];       // send a byte
151
                                SSP0->DR = SPI_TxBuffer[SPI_TxBufferIndex];       // send a byte
151
                                *Ptr_TxChksum += SPI_TxBuffer[SPI_TxBufferIndex]; // update checksum
152
                                *Ptr_TxChksum += SPI_TxBuffer[SPI_TxBufferIndex]; // update checksum
152
                                if(SPIWatchDog == 0) *Ptr_TxChksum += 1; // disturbe this packet to stop the communication!
153
                                if(SPIWatchDog == 0) *Ptr_TxChksum += 1; // disturbe this packet to stop the communication!
153
                                SPI_TxBufferIndex++; // pointer to next byte
154
                                SPI_TxBufferIndex++; // pointer to next byte
154
                        }
155
                        }
155
                        else // end of packet is reached reset and copy data to tx buffer
156
                        else // end of packet is reached reset and copy data to tx buffer
156
                        {
157
                        {
157
                                SPI_TxBufferIndex = 0;  // reset buffer index
158
                                SPI_TxBufferIndex = 0;  // reset buffer index
158
                                ToFlightCtrl.Chksum = 0;  // initialize checksum
159
                                ToFlightCtrl.Chksum = 0;  // initialize checksum
159
                                ToFlightCtrl.BeepTime = BeepTime;  // set beeptime
160
                                ToFlightCtrl.BeepTime = BeepTime;  // set beeptime
160
                                BeepTime = 0; // reset local beeptime
161
                                BeepTime = 0; // reset local beeptime
161
                                // copy contents of ToFlightCtrl->SPI_TxBuffer
162
                                // copy contents of ToFlightCtrl->SPI_TxBuffer
162
                                memcpy((u8 *) &(SPI_TxBuffer[2]), (u8 *) &ToFlightCtrl, sizeof(ToFlightCtrl));
163
                                memcpy((u8 *) &(SPI_TxBuffer[2]), (u8 *) &ToFlightCtrl, sizeof(ToFlightCtrl));
163
                        }
164
                        }
164
                }
165
                }
165
                switch (SPI_State)
166
                switch (SPI_State)
166
                {
167
                {
167
                        case SPI_SYNC1:
168
                        case SPI_SYNC1:
168
                                SPI_RxBufferIndex = 0; // reset buffer index
169
                                SPI_RxBufferIndex = 0; // reset buffer index
169
                                rxchksum = rxdata;     // init checksum
170
                                rxchksum = rxdata;     // init checksum
170
                                if (rxdata == SPI_RXSYNCBYTE1)
171
                                if (rxdata == SPI_RXSYNCBYTE1)
171
                                {   // 1st syncbyte ok
172
                                {   // 1st syncbyte ok
172
                                        SPI_State = SPI_SYNC2;  // step to sync2
173
                                        SPI_State = SPI_SYNC2;  // step to sync2
173
                                }
174
                                }
174
                                break;
175
                                break;
175
                        case SPI_SYNC2:
176
                        case SPI_SYNC2:
176
                                if (rxdata == SPI_RXSYNCBYTE2)
177
                                if (rxdata == SPI_RXSYNCBYTE2)
177
                                {  // 2nd Syncbyte ok
178
                                {  // 2nd Syncbyte ok
178
                                        rxchksum += rxdata;
179
                                        rxchksum += rxdata;
179
                                        SPI_State = SPI_DATA;
180
                                        SPI_State = SPI_DATA;
180
                                }  // 2nd Syncbyte does not match
181
                                }  // 2nd Syncbyte does not match
181
                                else
182
                                else
182
                                {
183
                                {
183
                                        SPI_State  = SPI_SYNC1; //jump back to sync1
184
                                        SPI_State  = SPI_SYNC1; //jump back to sync1
184
                                }
185
                                }
185
                                break;
186
                                break;
186
                        case SPI_DATA:
187
                        case SPI_DATA:
187
                                SPI_RxBuffer[SPI_RxBufferIndex++]= rxdata; // copy databyte to rx buffer
188
                                SPI_RxBuffer[SPI_RxBufferIndex++]= rxdata; // copy databyte to rx buffer
188
                                if(SPI_RxBufferIndex >= SPI_RXBUFFER_LEN)  // end of packet is reached
189
                                if(SPI_RxBufferIndex >= SPI_RXBUFFER_LEN)  // end of packet is reached
189
                                {
190
                                {
190
                                        if (rxdata == rxchksum) // verify checksum byte
191
                                        if (rxdata == rxchksum) // verify checksum byte
191
                                        {
192
                                        {
192
                                                // copy SPI_RxBuffer -> FromFlightCtrl
193
                                                // copy SPI_RxBuffer -> FromFlightCtrl
193
                                                if(!SPI_RxBuffer_Request) // block writing to FromFlightCtrl on reading access
194
                                                if(!SPI_RxBuffer_Request) // block writing to FromFlightCtrl on reading access
194
                                                {
195
                                                {
195
                                                        memcpy((u8 *) &FromFlightCtrl, (u8 *) SPI_RxBuffer, sizeof(FromFlightCtrl));
196
                                                        memcpy((u8 *) &FromFlightCtrl, (u8 *) SPI_RxBuffer, sizeof(FromFlightCtrl));
196
                                                        SPI_RxBuffer_Request = 1;
197
                                                        SPI_RxBuffer_Request = 1;
197
                                                }
198
                                                }
198
                                                // reset timeout counter on good packet
199
                                                // reset timeout counter on good packet
199
                                                SPI0_Timeout = SetDelay(SPI0_TIMEOUT);
200
                                                SPI0_Timeout = SetDelay(SPI0_TIMEOUT);
200
                                                DebugOut.Analog[13]++;
201
                                                DebugOut.Analog[13]++;
201
                                        }
202
                                        }
202
                                        else // bad checksum byte
203
                                        else // bad checksum byte
203
                                        {
204
                                        {
204
                                                DebugOut.Analog[12]++; // increase SPI chksum error counter
205
                                                DebugOut.Analog[12]++; // increase SPI chksum error counter
205
                                        }
206
                                        }
206
                                        SPI_State  = SPI_SYNC1; // reset state
207
                                        SPI_State  = SPI_SYNC1; // reset state
207
                                }
208
                                }
208
                                else // end of packet not reached
209
                                else // end of packet not reached
209
                                {
210
                                {
210
                                        rxchksum += rxdata;      // update checksum
211
                                        rxchksum += rxdata;      // update checksum
211
                                }
212
                                }
212
                                break;
213
                                break;
213
                        default:
214
                        default:
214
                                SPI_State  = SPI_SYNC1;
215
                                SPI_State  = SPI_SYNC1;
215
                                break;
216
                                break;
216
                }
217
                }
217
        }
218
        }
218
 
219
 
219
//      IDISABLE;
220
//      IDISABLE;
220
        VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register
221
        VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register
221
}
222
}
222
 
223
 
223
//--------------------------------------------------------------
224
//--------------------------------------------------------------
224
void SPI0_Init(void)
225
void SPI0_Init(void)
225
{
226
{
226
        GPIO_InitTypeDef GPIO_InitStructure;
227
        GPIO_InitTypeDef GPIO_InitStructure;
227
        SSP_InitTypeDef   SSP_InitStructure;
228
        SSP_InitTypeDef   SSP_InitStructure;
228
 
229
 
229
        UART1_PutString("\r\n SPI init...");
230
        UART1_PutString("\r\n SPI init...");
230
 
231
 
231
        SCU_APBPeriphClockConfig(__GPIO2 ,ENABLE);
232
        SCU_APBPeriphClockConfig(__GPIO2 ,ENABLE);
232
        SCU_APBPeriphClockConfig(__SSP0 ,ENABLE);
233
        SCU_APBPeriphClockConfig(__SSP0 ,ENABLE);
233
 
234
 
234
        GPIO_DeInit(GPIO2);
235
        GPIO_DeInit(GPIO2);
235
        //SSP0_CLK, SSP0_MOSI, SSP0_NSS pins
236
        //SSP0_CLK, SSP0_MOSI, SSP0_NSS pins
236
        GPIO_StructInit(&GPIO_InitStructure);
237
        GPIO_StructInit(&GPIO_InitStructure);
237
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
238
        GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
238
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7;
239
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7;
239
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
240
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
240
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
241
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
241
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //SSP0_SCLK, SSP0_MOSI, SSP0_NSS
242
        GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //SSP0_SCLK, SSP0_MOSI, SSP0_NSS
242
        GPIO_Init (GPIO2, &GPIO_InitStructure);
243
        GPIO_Init (GPIO2, &GPIO_InitStructure);
243
 
244
 
244
        // SSP0_MISO pin GPIO2.6
245
        // SSP0_MISO pin GPIO2.6
245
        GPIO_StructInit(&GPIO_InitStructure);
246
        GPIO_StructInit(&GPIO_InitStructure);
246
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
247
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
247
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
248
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
248
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
249
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
249
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
250
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
250
        GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; //SSP0_MISO
251
        GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; //SSP0_MISO
251
        GPIO_Init (GPIO2, &GPIO_InitStructure);
252
        GPIO_Init (GPIO2, &GPIO_InitStructure);
252
 
253
 
253
        SSP_DeInit(SSP0);
254
        SSP_DeInit(SSP0);
254
        SSP_StructInit(&SSP_InitStructure);
255
        SSP_StructInit(&SSP_InitStructure);
255
        SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola;
256
        SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola;
256
        SSP_InitStructure.SSP_Mode = SSP_Mode_Slave;
257
        SSP_InitStructure.SSP_Mode = SSP_Mode_Slave;
257
        SSP_InitStructure.SSP_SlaveOutput = SSP_SlaveOutput_Enable;
258
        SSP_InitStructure.SSP_SlaveOutput = SSP_SlaveOutput_Enable;
258
        SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge;
259
        SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge;
259
        SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low;
260
        SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low;
260
        SSP_InitStructure.SSP_ClockRate = 0;
261
        SSP_InitStructure.SSP_ClockRate = 0;
261
 
262
 
262
        SSP_Init(SSP0, &SSP_InitStructure);
263
        SSP_Init(SSP0, &SSP_InitStructure);
263
        SSP_ITConfig(SSP0, SSP_IT_RxFifo | SSP_IT_RxTimeOut, ENABLE);
264
        SSP_ITConfig(SSP0, SSP_IT_RxFifo | SSP_IT_RxTimeOut, ENABLE);
264
        SSP_Cmd(SSP0, ENABLE);
265
        SSP_Cmd(SSP0, ENABLE);
265
        // initialize the syncbytes in the tx buffer
266
        // initialize the syncbytes in the tx buffer
266
        SPI_TxBuffer[0] = SPI_TXSYNCBYTE1;
267
        SPI_TxBuffer[0] = SPI_TXSYNCBYTE1;
267
        SPI_TxBuffer[1] = SPI_TXSYNCBYTE2;
268
        SPI_TxBuffer[1] = SPI_TXSYNCBYTE2;
268
        // set the pointer to the checksum byte in the tx buffer
269
        // set the pointer to the checksum byte in the tx buffer
269
        Ptr_TxChksum = (u8 *) &(((ToFlightCtrl_t *) &(SPI_TxBuffer[2]))->Chksum);
270
        Ptr_TxChksum = (u8 *) &(((ToFlightCtrl_t *) &(SPI_TxBuffer[2]))->Chksum);
270
 
271
 
271
        ToFlightCtrl.GPSStick.Nick = 0;
272
        ToFlightCtrl.GPSStick.Nick = 0;
272
        ToFlightCtrl.GPSStick.Roll = 0;
273
        ToFlightCtrl.GPSStick.Roll = 0;
273
//      ToFlightCtrl.GPSStick.Yaw = 0;
274
//      ToFlightCtrl.GPSStick.Yaw = 0;
274
 
275
 
275
        VIC_Config(SSP0_ITLine, VIC_IRQ, PRIORITY_SPI0);
276
        VIC_Config(SSP0_ITLine, VIC_IRQ, PRIORITY_SPI0);
276
        VIC_ITCmd(SSP0_ITLine, ENABLE);
277
        VIC_ITCmd(SSP0_ITLine, ENABLE);
277
 
278
 
278
        SPI0_Timeout = SetDelay(4*SPI0_TIMEOUT);
279
        SPI0_Timeout = SetDelay(4*SPI0_TIMEOUT);
279
 
280
 
280
        UART1_PutString("ok");
281
        UART1_PutString("ok");
281
}
282
}
282
 
283
 
283
 
284
 
284
//------------------------------------------------------
285
//------------------------------------------------------
285
void SPI0_UpdateBuffer(void)
286
void SPI0_UpdateBuffer(void)
286
{
287
{
287
        static u32 timeout = 0;
288
        static u32 timeout = 0;
288
        static u8 counter = 50,hott_index = 0, last_error_code = 0;
289
        static u8 counter = 50,hott_index = 0, last_error_code = 0, enable_injecting = 0;
289
        s16 tmp, last_wp_event = 0;
290
        static s16 last_wp_event = 0;
-
 
291
        s16 tmp;
290
        s32 i1,i2;
292
        s32 i1,i2;
291
       
293
       
292
    SPIWatchDog = 3500;    // stop communication to FC after this timeout
294
    SPIWatchDog = 3500;    // stop communication to FC after this timeout
293
        if(SPI_RxBuffer_Request)
295
        if(SPI_RxBuffer_Request)
294
        {
296
        {
295
                // avoid sending data via SPI during the update of the  ToFlightCtrl structure
297
                // avoid sending data via SPI during the update of the  ToFlightCtrl structure
296
                VIC_ITCmd(SSP0_ITLine, DISABLE); // disable SPI interrupt
298
                VIC_ITCmd(SSP0_ITLine, DISABLE); // disable SPI interrupt
297
                ToFlightCtrl.CompassHeading = Compass_Heading;
299
                ToFlightCtrl.CompassHeading = Compass_Heading;
298
                DebugOut.Analog[10] = ToFlightCtrl.CompassHeading;
300
                DebugOut.Analog[10] = ToFlightCtrl.CompassHeading;
299
                if(ToFlightCtrl.CompassHeading >= 0) ToFlightCtrl.CompassHeading = (360 + ToFlightCtrl.CompassHeading + FromFlightCtrl.GyroYaw / 12) % 360;
301
                if(ToFlightCtrl.CompassHeading >= 0) ToFlightCtrl.CompassHeading = (360 + ToFlightCtrl.CompassHeading + FromFlightCtrl.GyroYaw / 12) % 360;
300
                ToFlightCtrl.MagVecX = MagVector.X;
302
                ToFlightCtrl.MagVecX = MagVector.X;
301
                ToFlightCtrl.MagVecY = MagVector.Y;
303
                ToFlightCtrl.MagVecY = MagVector.Y;
302
                ToFlightCtrl.MagVecZ = MagVector.Z;
304
                ToFlightCtrl.MagVecZ = MagVector.Z;
303
//              ToFlightCtrl.NCStatus = 0;
305
//              ToFlightCtrl.NCStatus = 0;
304
                // cycle spi commands
306
                // cycle spi commands
-
 
307
                if(ErrorCode != last_error_code && enable_injecting)
-
 
308
                 {
305
                if(ErrorCode != last_error_code) ToFlightCtrl.Command = SPI_NCCMD_VERSION;
309
                  ToFlightCtrl.Command = SPI_NCCMD_VERSION;
-
 
310
                  last_error_code = ErrorCode;
-
 
311
                  enable_injecting = 0;
-
 
312
                 }
306
                else
313
                else
307
                if(FC_WP_EventChannel != last_wp_event) ToFlightCtrl.Command = SPI_NCCMD_GPSINFO;
314
                if(FC_WP_EventChannel != last_wp_event && enable_injecting)
-
 
315
                 {
-
 
316
                  ToFlightCtrl.Command = SPI_NCCMD_GPSINFO;
-
 
317
                  last_wp_event = FC_WP_EventChannel;
-
 
318
                  enable_injecting = 0;
-
 
319
                 }
308
                else
320
                else
309
                 {
321
                 {
310
                  ToFlightCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++];
322
                  ToFlightCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++];
311
                // restart command cycle at the end
323
                // restart command cycle at the end
312
                  if(SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0;
324
                  if(SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0;
-
 
325
                  if(ToFlightCtrl.Command == SPI_NCCMD_KALMAN) enable_injecting = 1;
313
                 }
326
                 }
314
                last_error_code = ErrorCode;
-
 
315
                last_wp_event = FC_WP_EventChannel;
-
 
316
 
327
 
317
#define FLAG_GPS_AID 0x01
328
#define FLAG_GPS_AID 0x01
318
                switch (ToFlightCtrl.Command)
329
                switch (ToFlightCtrl.Command)
319
                {
330
                {
320
                        case  SPI_NCCMD_KALMAN:  // wird am häufigsten betätigt
331
                        case  SPI_NCCMD_KALMAN:  // wird am häufigsten betätigt
321
                                ToFlightCtrl.Param.sByte[0] = (s8) Kalman_K;
332
                                ToFlightCtrl.Param.sByte[0] = (s8) Kalman_K;
322
                                ToFlightCtrl.Param.sByte[1] = (s8) Kalman_MaxFusion;
333
                                ToFlightCtrl.Param.sByte[1] = (s8) Kalman_MaxFusion;
323
                                ToFlightCtrl.Param.sByte[2] = (s8) Kalman_MaxDrift;
334
                                ToFlightCtrl.Param.sByte[2] = (s8) Kalman_MaxDrift;
324
                                ToFlightCtrl.Param.Byte[3]      = (u8) Kalman_Kompass;
335
                                ToFlightCtrl.Param.Byte[3]      = (u8) Kalman_Kompass;
325
                                ToFlightCtrl.Param.sByte[4] = (s8) ToFcGpsZ;
336
                                ToFlightCtrl.Param.sByte[4] = (s8) ToFcGpsZ;
326
                                ToFlightCtrl.Param.Byte[5] = (s8) ToFC_Rotate_C;
337
                                ToFlightCtrl.Param.Byte[5] = (s8) ToFC_Rotate_C;
327
                                ToFlightCtrl.Param.Byte[6] = (s8) ToFC_Rotate_S;
338
                                ToFlightCtrl.Param.Byte[6] = (s8) ToFC_Rotate_S;
328
                ToFlightCtrl.Param.Byte[7] = GPS_Aid_StickMultiplikator;
339
                ToFlightCtrl.Param.Byte[7] = GPS_Aid_StickMultiplikator;
329
                                if(CAM_Orientation.UpdateMask & CAM_UPDATE_AZIMUTH)
340
                                if(CAM_Orientation.UpdateMask & CAM_UPDATE_AZIMUTH)
330
                                {
341
                                {
331
                                        ToFlightCtrl.Param.sInt[4] = CAM_Orientation.Azimuth;
342
                                        ToFlightCtrl.Param.sInt[4] = CAM_Orientation.Azimuth;
332
                                        CAM_Orientation.UpdateMask &= ~CAM_UPDATE_AZIMUTH;
343
                                        CAM_Orientation.UpdateMask &= ~CAM_UPDATE_AZIMUTH;
333
                                }
344
                                }
334
                                else
345
                                else
335
                                {
346
                                {
336
                                        ToFlightCtrl.Param.sInt[4] = -1;
347
                                        ToFlightCtrl.Param.sInt[4] = -1;
337
                                }
348
                                }
338
 
349
 
339
                                if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_NEW_CAMERA_ELEVATION, &tmp))  // Elevation set via 'j' command
350
                                if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_NEW_CAMERA_ELEVATION, &tmp))  // Elevation set via 'j' command
340
                                {
351
                                {
341
                                        POI_KameraNick = tmp;
352
                                        POI_KameraNick = tmp;
342
                                }
353
                                }
343
                                else
354
                                else
344
                                {
355
                                {
345
                                        //if(FC.StatusFlags2 & FC_STATUS2_CAREFREE) // only, if carefree is active
356
                                        //if(FC.StatusFlags2 & FC_STATUS2_CAREFREE) // only, if carefree is active
346
                                        POI_KameraNick = CAM_Orientation.Elevation;
357
                                        POI_KameraNick = CAM_Orientation.Elevation;
347
                                        //else ToFlightCtrl.Param.sInt[5] = 0;
358
                                        //else ToFlightCtrl.Param.sInt[5] = 0;
348
                                }
359
                                }
349
                                ToFlightCtrl.Param.sInt[5] = POI_KameraNick;
360
                                ToFlightCtrl.Param.sInt[5] = POI_KameraNick;
350
                                break;
361
                                break;
351
 
362
 
352
                        case SPI_NCCMD_VERSION:
363
                        case SPI_NCCMD_VERSION:
353
                                //+++++++++++++++++++++++++++++++++++++++++++++++++++
364
                                //+++++++++++++++++++++++++++++++++++++++++++++++++++
354
                        //+ higher than the maximum allowed altitude
365
                        //+ higher than the maximum allowed altitude
355
                                //+++++++++++++++++++++++++++++++++++++++++++++++++++
366
                                //+++++++++++++++++++++++++++++++++++++++++++++++++++
356
                                ToFlightCtrl.Param.Byte[0] = VERSION_MAJOR;
367
                                ToFlightCtrl.Param.Byte[0] = VERSION_MAJOR;
357
                                ToFlightCtrl.Param.Byte[1] = VERSION_MINOR;
368
                                ToFlightCtrl.Param.Byte[1] = VERSION_MINOR;
358
                                ToFlightCtrl.Param.Byte[2] = VERSION_PATCH;
369
                                ToFlightCtrl.Param.Byte[2] = VERSION_PATCH;
359
                                ToFlightCtrl.Param.Byte[3] = FC_SPI_COMPATIBLE;
370
                                ToFlightCtrl.Param.Byte[3] = FC_SPI_COMPATIBLE;
360
                                ToFlightCtrl.Param.Byte[4] = Version_HW;
371
                                ToFlightCtrl.Param.Byte[4] = Version_HW;
361
                                ToFlightCtrl.Param.Byte[5] = DebugOut.StatusGreen;
372
                                ToFlightCtrl.Param.Byte[5] = DebugOut.StatusGreen;
362
                                ToFlightCtrl.Param.Byte[6] = DebugOut.StatusRed;
373
                                ToFlightCtrl.Param.Byte[6] = DebugOut.StatusRed;
363
                                ToFlightCtrl.Param.Byte[7] = ErrorCode;
374
                                ToFlightCtrl.Param.Byte[7] = ErrorCode;
364
                                ToFlightCtrl.Param.Byte[8] = NC_GPS_ModeCharacter;
375
                                ToFlightCtrl.Param.Byte[8] = NC_GPS_ModeCharacter;
365
                                ToFlightCtrl.Param.Byte[9] = SerialLinkOkay;
376
                                ToFlightCtrl.Param.Byte[9] = SerialLinkOkay;
366
                                ToFlightCtrl.Param.Byte[10] = NC_To_FC_Flags;
377
                                ToFlightCtrl.Param.Byte[10] = NC_To_FC_Flags;
367
                                if(AbsoluteFlyingAltitude > 255) ToFlightCtrl.Param.Byte[11] = 0; // then the limitation of the FC doesn't work
378
                                if(AbsoluteFlyingAltitude > 255) ToFlightCtrl.Param.Byte[11] = 0; // then the limitation of the FC doesn't work
368
                                else ToFlightCtrl.Param.Byte[11] = AbsoluteFlyingAltitude;
379
                                else ToFlightCtrl.Param.Byte[11] = AbsoluteFlyingAltitude;
369
                                break;
380
                                break;
370
                        case SPI_MISC:
381
                        case SPI_MISC:
371
                                ToFlightCtrl.Param.Byte[0] = EarthMagneticFieldFiltered/5;
382
                                ToFlightCtrl.Param.Byte[0] = EarthMagneticFieldFiltered/5;
372
                                ToFlightCtrl.Param.Byte[1] = EarthMagneticInclination;
383
                                ToFlightCtrl.Param.Byte[1] = EarthMagneticInclination;
373
                                ToFlightCtrl.Param.Byte[2] = EarthMagneticInclinationTheoretic;
384
                                ToFlightCtrl.Param.Byte[2] = EarthMagneticInclinationTheoretic;
374
                                ToFlightCtrl.Param.Byte[3] = SpeakHoTT;
385
                                ToFlightCtrl.Param.Byte[3] = SpeakHoTT;
375
                                ToFlightCtrl.Param.Byte[4] = NaviData.WaypointIndex; // index of current waypoints running from 0 to WaypointNumber-1
386
                                ToFlightCtrl.Param.Byte[4] = NaviData.WaypointIndex; // index of current waypoints running from 0 to WaypointNumber-1
376
                                ToFlightCtrl.Param.Byte[5] = NaviData.WaypointNumber; // number of stored waypoints
387
                                ToFlightCtrl.Param.Byte[5] = NaviData.WaypointNumber; // number of stored waypoints
377
                                ToFlightCtrl.Param.Int[3] =  NaviData.TargetPositionDeviation.Distance / 10;
388
                                ToFlightCtrl.Param.Int[3] =  NaviData.TargetPositionDeviation.Distance / 10;
378
                                ToFlightCtrl.Param.Byte[8] = NaviData.TargetHoldTime; // time in s to stay at the given target, counts down to 0 if target has been reached
389
                                ToFlightCtrl.Param.Byte[8] = NaviData.TargetHoldTime; // time in s to stay at the given target, counts down to 0 if target has been reached
379
                                ToFlightCtrl.Param.Byte[9] = 0;
390
                                ToFlightCtrl.Param.Byte[9] = 0;
380
                                ToFlightCtrl.Param.Byte[10] = 0;
391
                                ToFlightCtrl.Param.Byte[10] = 0;
381
                                ToFlightCtrl.Param.Byte[11] = 0;
392
                                ToFlightCtrl.Param.Byte[11] = 0;
382
//DebugOut.Analog[16] = SpeakHoTT;
-
 
383
                                SpeakHoTT = 0;
393
                                SpeakHoTT = 0;
384
                                break;
394
                                break;
385
 
395
 
386
                        case SPI_NCCMD_GPSINFO:
396
                        case SPI_NCCMD_GPSINFO:
387
                                ToFlightCtrl.Param.Byte[0] = GPSData.Flags;
397
                                ToFlightCtrl.Param.Byte[0] = GPSData.Flags;
388
                                ToFlightCtrl.Param.Byte[1] = GPSData.NumOfSats;
398
                                ToFlightCtrl.Param.Byte[1] = GPSData.NumOfSats;
389
                                ToFlightCtrl.Param.Byte[2] = GPSData.SatFix;
399
                                ToFlightCtrl.Param.Byte[2] = GPSData.SatFix;
390
                                ToFlightCtrl.Param.Byte[3] = GPSData.Speed_Ground / 100; // m/s
400
                                ToFlightCtrl.Param.Byte[3] = GPSData.Speed_Ground / 100; // m/s
391
                                ToFlightCtrl.Param.Int[2]  = NaviData.HomePositionDeviation.Distance; // dm   //4&5
401
                                ToFlightCtrl.Param.Int[2]  = NaviData.HomePositionDeviation.Distance; // dm   //4&5
392
                                ToFlightCtrl.Param.sInt[3] = NaviData.HomePositionDeviation.Bearing;  // deg  //6&7
402
                                ToFlightCtrl.Param.sInt[3] = NaviData.HomePositionDeviation.Bearing;  // deg  //6&7
393
                                if(FC_WP_EventChannel > 254) FC_WP_EventChannel = 254;
403
                                if(FC_WP_EventChannel > 254) FC_WP_EventChannel = 254;
394
                                if(FC_WP_EventChannel) LogFC_WP_EventChannel = FC_WP_EventChannel; // to make sure that it will be logged
404
                                if(FC_WP_EventChannel) LogFC_WP_EventChannel = FC_WP_EventChannel; // to make sure that it will be logged
395
                                ToFlightCtrl.Param.Byte[8] = (s8)(FC_WP_EventChannel - 127);
405
                                ToFlightCtrl.Param.Byte[8] = (s8)(FC_WP_EventChannel - 127);
396
                                FC_WP_EventChannel = 0; // the GPS-Routine will set it again
406
                                FC_WP_EventChannel = 0; // the GPS-Routine will set it again
397
                                if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_RATE, &tmp))
407
                                if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_RATE, &tmp))
398
                                {
408
                                {
399
                                        ToFlightCtrl.Param.Byte[9] = (u8)tmp;
409
                                        ToFlightCtrl.Param.Byte[9] = (u8)tmp;
400
                                }
410
                                }
401
                                else
411
                                else
402
                                {
412
                                {
403
                                        ToFlightCtrl.Param.Byte[9] = (u8)ToFC_AltitudeRate;
413
                                        ToFlightCtrl.Param.Byte[9] = (u8)ToFC_AltitudeRate;
404
                                }
414
                                }
405
                                if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_SETPOINT, &tmp))
415
                                if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_SETPOINT, &tmp))
406
                                {
416
                                {
407
                                        ToFlightCtrl.Param.sInt[5] = tmp;
417
                                        ToFlightCtrl.Param.sInt[5] = tmp;
408
                                }
418
                                }
409
                                else
419
                                else
410
                                {
420
                                {
411
                                        ToFlightCtrl.Param.sInt[5] = (s16)ToFC_AltitudeSetpoint;
421
                                        ToFlightCtrl.Param.sInt[5] = (s16)ToFC_AltitudeSetpoint;
412
                                }
422
                                }
413
                                break;
423
                                break;
414
                        case SPI_NCCMD_HOTT_INFO:
424
                        case SPI_NCCMD_HOTT_INFO:
415
                                switch(hott_index++)
425
                                switch(hott_index++)
416
                                {
426
                                {
417
                                case 0:
427
                                case 0:
418
                                        //Dezimalgrad            --> Grad mit Dezimalminuten     --> Grad, Minuten, Sekunden
428
                                        //Dezimalgrad            --> Grad mit Dezimalminuten     --> Grad, Minuten, Sekunden
419
                                        //53.285788 7.4847269    --> N53° 17.14728 E7° 29.08362  --> N53° 17' 8.837" E7° 29' 5.017" 
429
                                        //53.285788 7.4847269    --> N53° 17.14728 E7° 29.08362  --> N53° 17' 8.837" E7° 29' 5.017" 
420
                                        ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID;
430
                                        ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID;
421
                                        ToFlightCtrl.Param.Byte[0] = 3+3;       // index  +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
431
                                        ToFlightCtrl.Param.Byte[0] = 3+3;       // index  +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
422
                                        ToFlightCtrl.Param.Byte[1] = 9-1;       // how many
432
                                        ToFlightCtrl.Param.Byte[1] = 9-1;       // how many
423
                                        //-----------------------------
433
                                        //-----------------------------
424
                                        ToFlightCtrl.Param.Byte[2] = FromFlightCtrl.GyroHeading / 20;//NaviData.HomePositionDeviation.Bearing / 2; 
434
                                        ToFlightCtrl.Param.Byte[2] = FromFlightCtrl.GyroHeading / 20;//NaviData.HomePositionDeviation.Bearing / 2; 
425
                                        i1 = GPSData.Speed_Ground; // in cm/sec
435
                                        i1 = GPSData.Speed_Ground; // in cm/sec
426
                                        i1 *= 36;
436
                                        i1 *= 36;
427
                                        i1 /= 1000;
437
                                        i1 /= 1000;
428
                                        ToFlightCtrl.Param.Byte[3] = i1 % 256;
438
                                        ToFlightCtrl.Param.Byte[3] = i1 % 256;
429
                                        ToFlightCtrl.Param.Byte[4] = i1 / 256;
439
                                        ToFlightCtrl.Param.Byte[4] = i1 / 256;
430
                                        //-----------------------------
440
                                        //-----------------------------
431
                                        if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5]  = 1; // 1 = S
441
                                        if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5]  = 1; // 1 = S
432
                                        else ToFlightCtrl.Param.Byte[5]  = 0; // 1 = S
442
                                        else ToFlightCtrl.Param.Byte[5]  = 0; // 1 = S
433
                                        i1 = abs(GPSData.Position.Latitude)/10000000L;
443
                                        i1 = abs(GPSData.Position.Latitude)/10000000L;
434
                                        i2 = abs(GPSData.Position.Latitude)%10000000L;
444
                                        i2 = abs(GPSData.Position.Latitude)%10000000L;
435
                                        if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;}
445
                                        if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;}
436
                                        i1 *= 100;
446
                                        i1 *= 100;
437
                                        i1 += i2 / 100000;
447
                                        i1 += i2 / 100000;
438
                                        i2  = i2 % 100000;
448
                                        i2  = i2 % 100000;
439
                                        i2 /= 10;
449
                                        i2 /= 10;
440
                                        ToFlightCtrl.Param.Byte[6]  = i1 % 256;
450
                                        ToFlightCtrl.Param.Byte[6]  = i1 % 256;
441
                                        ToFlightCtrl.Param.Byte[7]  = i1 / 256;
451
                                        ToFlightCtrl.Param.Byte[7]  = i1 / 256;
442
                                        ToFlightCtrl.Param.Byte[8]  = i2 % 256;
452
                                        ToFlightCtrl.Param.Byte[8]  = i2 % 256;
443
                                        ToFlightCtrl.Param.Byte[9]  = i2 / 256;
453
                                        ToFlightCtrl.Param.Byte[9]  = i2 / 256;
444
                                        break;
454
                                        break;
445
                                case 1:
455
                                case 1:
446
                                        ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID;
456
                                        ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID;
447
                                        ToFlightCtrl.Param.Byte[0] = 11+3;      // index          +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
457
                                        ToFlightCtrl.Param.Byte[0] = 11+3;      // index          +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
448
                                        ToFlightCtrl.Param.Byte[1] = 8-1;       // how many
458
                                        ToFlightCtrl.Param.Byte[1] = 8-1;       // how many
449
                                        //-----------------------------
459
                                        //-----------------------------
450
                                        if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2]  = 1; // 1 = E
460
                                        if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2]  = 1; // 1 = E
451
                                        else ToFlightCtrl.Param.Byte[2]  = 0; // 1 = S
461
                                        else ToFlightCtrl.Param.Byte[2]  = 0; // 1 = S
452
                                        i1 = abs(GPSData.Position.Longitude)/10000000L;
462
                                        i1 = abs(GPSData.Position.Longitude)/10000000L;
453
                                        i2 = abs(GPSData.Position.Longitude)%10000000L;
463
                                        i2 = abs(GPSData.Position.Longitude)%10000000L;
454
                                        if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;}
464
                                        if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;}
455
                                        i1 *= 100;
465
                                        i1 *= 100;
456
                                        i1 += i2 / 100000;
466
                                        i1 += i2 / 100000;
457
                                        i2  = i2 % 100000;
467
                                        i2  = i2 % 100000;
458
                                        i2 /= 10;
468
                                        i2 /= 10;
459
                                        ToFlightCtrl.Param.Byte[3]  = i1 % 256;
469
                                        ToFlightCtrl.Param.Byte[3]  = i1 % 256;
460
                                        ToFlightCtrl.Param.Byte[4]  = i1 / 256;
470
                                        ToFlightCtrl.Param.Byte[4]  = i1 / 256;
461
                                        ToFlightCtrl.Param.Byte[5]  = i2 % 256;
471
                                        ToFlightCtrl.Param.Byte[5]  = i2 % 256;
462
                                        ToFlightCtrl.Param.Byte[6]  = i2 / 256;
472
                                        ToFlightCtrl.Param.Byte[6]  = i2 / 256;
463
                                        //-----------------------------
473
                                        //-----------------------------
464
                                        i1 = NaviData.HomePositionDeviation.Distance / 10; // dann in m 
474
                                        i1 = NaviData.HomePositionDeviation.Distance / 10; // dann in m 
465
                                        ToFlightCtrl.Param.Byte[7]  = i1 % 256;
475
                                        ToFlightCtrl.Param.Byte[7]  = i1 % 256;
466
                                        ToFlightCtrl.Param.Byte[8]  = i1 / 256;
476
                                        ToFlightCtrl.Param.Byte[8]  = i1 / 256;
467
                                        break;
477
                                        break;
468
                                 case 2:
478
                                 case 2:
469
                                        ToFlightCtrl.Param.Byte[11] = HOTT_GENERAL_PACKET_ID;
479
                                        ToFlightCtrl.Param.Byte[11] = HOTT_GENERAL_PACKET_ID;
470
                                        ToFlightCtrl.Param.Byte[0] = 5+3;       // index   // +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
480
                                        ToFlightCtrl.Param.Byte[0] = 5+3;       // index   // +3, weil bei HoTT V4 3 Bytes eingeschoben wurden
471
                                        ToFlightCtrl.Param.Byte[1] = 2; // how many
481
                                        ToFlightCtrl.Param.Byte[1] = 2; // how many
472
                                        ToFlightCtrl.Param.Byte[2] = EarthMagneticField / (5 * 2);
482
                                        ToFlightCtrl.Param.Byte[2] = EarthMagneticField / (5 * 2);
473
                                        ToFlightCtrl.Param.Byte[3] = EarthMagneticInclination / 2;
483
                                        ToFlightCtrl.Param.Byte[3] = EarthMagneticInclination / 2;
474
                                        hott_index = 0;
484
                                        hott_index = 0;
475
                                        break;
485
                                        break;
476
                                 default:
486
                                 default:
477
                                        ToFlightCtrl.Param.Byte[0] = 255;
487
                                        ToFlightCtrl.Param.Byte[0] = 255;
478
                                        hott_index = 0;
488
                                        hott_index = 0;
479
                                        break;
489
                                        break;
480
                                }
490
                                }
481
                                break;
491
                                break;
482
                        default:
492
                        default:
483
                                break;
493
                                break;
484
// 0 = 0,1
494
// 0 = 0,1
485
// 1 = 2,3
495
// 1 = 2,3
486
// 2 = 4,5
496
// 2 = 4,5
487
// 3 = 6,7
497
// 3 = 6,7
488
// 4 = 8,9
498
// 4 = 8,9
489
// 5 = 10,11
499
// 5 = 10,11
490
                }
500
                }
491
                VIC_ITCmd(SSP0_ITLine, ENABLE);         // enable SPI interrupt
501
                VIC_ITCmd(SSP0_ITLine, ENABLE);         // enable SPI interrupt
492
                switch(FromFlightCtrl.Command)
502
                switch(FromFlightCtrl.Command)
493
                {
503
                {
494
                        case SPI_FCCMD_USER:
504
                        case SPI_FCCMD_USER:
495
                                Parameter.User1 = FromFlightCtrl.Param.Byte[0];
505
                                Parameter.User1 = FromFlightCtrl.Param.Byte[0];
496
                                Parameter.User2 = FromFlightCtrl.Param.Byte[1];
506
                                Parameter.User2 = FromFlightCtrl.Param.Byte[1];
497
                                Parameter.User3 = FromFlightCtrl.Param.Byte[2];
507
                                Parameter.User3 = FromFlightCtrl.Param.Byte[2];
498
                                Parameter.User4 = FromFlightCtrl.Param.Byte[3];
508
                                Parameter.User4 = FromFlightCtrl.Param.Byte[3];
499
                                Parameter.User5 = FromFlightCtrl.Param.Byte[4];
509
                                Parameter.User5 = FromFlightCtrl.Param.Byte[4];
500
                                Parameter.User6 = FromFlightCtrl.Param.Byte[5];
510
                                Parameter.User6 = FromFlightCtrl.Param.Byte[5];
501
                                Parameter.User7 = FromFlightCtrl.Param.Byte[6];
511
                                Parameter.User7 = FromFlightCtrl.Param.Byte[6];
502
                                Parameter.User8 = FromFlightCtrl.Param.Byte[7];
512
                                Parameter.User8 = FromFlightCtrl.Param.Byte[7];
503
                                if(ClearFCStatusFlags)
513
                                if(ClearFCStatusFlags)
504
                                {
514
                                {
505
                                        FC.StatusFlags = 0;
515
                                        FC.StatusFlags = 0;
506
                                        ClearFCStatusFlags = 0;
516
                                        ClearFCStatusFlags = 0;
507
                                }
517
                                }
508
                                FC.StatusFlags |= FromFlightCtrl.Param.Byte[8];
518
                                FC.StatusFlags |= FromFlightCtrl.Param.Byte[8];
509
                                if(FC.StatusFlags & FC_STATUS_CALIBRATE && !FCCalibActive)
519
                                if(FC.StatusFlags & FC_STATUS_CALIBRATE && !FCCalibActive)
510
                                {
520
                                {
511
                                        HeadFreeStartAngle = Compass_Heading * 10;
521
                                        HeadFreeStartAngle = Compass_Heading * 10;
512
                                        Compass_Init();
522
                                        Compass_Init();
513
                                        FCCalibActive = 10;
523
                                        FCCalibActive = 10;
514
                                        FC_is_Calibrated = 0;
524
                                        FC_is_Calibrated = 0;
515
                                }
525
                                }
516
                                else
526
                                else
517
                                {
527
                                {
518
                                        if(FCCalibActive) if(--FCCalibActive == 0) FC_is_Calibrated = 1;
528
                                        if(FCCalibActive) if(--FCCalibActive == 0) FC_is_Calibrated = 1;
519
                                }
529
                                }
520
                                if(FC.StatusFlags & FC_STATUS_START)
530
                                if(FC.StatusFlags & FC_STATUS_START)
521
                             {
531
                             {
522
                                   if(Compass_Heading != -1) HeadFreeStartAngle = Compass_Heading * 10; else
532
                                   if(Compass_Heading != -1) HeadFreeStartAngle = Compass_Heading * 10; else
523
                                   HeadFreeStartAngle = FromFlightCtrl.GyroHeading;
533
                                   HeadFreeStartAngle = FromFlightCtrl.GyroHeading;
524
                                 }
534
                                 }
525
 
535
 
526
                                 if((Parameter.ExtraConfig & CFG_TEACHABLE_CAREFREE))
536
                                 if((Parameter.ExtraConfig & CFG_TEACHABLE_CAREFREE))
527
                                  {
537
                                  {
528
                                   if(!(FC.StatusFlags2 & FC_STATUS2_CAREFREE)) // CF ist jetzt ausgeschaltet -> neue Richtung lernen
538
                                   if(!(FC.StatusFlags2 & FC_STATUS2_CAREFREE)) // CF ist jetzt ausgeschaltet -> neue Richtung lernen
529
                                    {
539
                                    {
530
                                         if((NaviData.HomePositionDeviation.Distance > 200) && (NCFlags & NC_FLAG_GPS_OK))       // nur bei ausreichender Distance -> 20m
540
                                         if((NaviData.HomePositionDeviation.Distance > 200) && (NCFlags & NC_FLAG_GPS_OK))       // nur bei ausreichender Distance -> 20m
531
                                         {
541
                                         {
532
                                          HeadFreeStartAngle = (10 * NaviData.HomePositionDeviation.Bearing + 1800 + 3600 -  Parameter.OrientationAngle * 150) % 3600; // in 0.1°
542
                                          HeadFreeStartAngle = (10 * NaviData.HomePositionDeviation.Bearing + 1800 + 3600 -  Parameter.OrientationAngle * 150) % 3600; // in 0.1°
533
                                         }
543
                                         }
534
                                         else                                                                                            // Ansonsten die aktuelle Richtung übernehmen
544
                                         else                                                                                            // Ansonsten die aktuelle Richtung übernehmen
535
                                          HeadFreeStartAngle = (3600 + FromFlightCtrl.GyroHeading /*+ Parameter.OrientationAngle * 150*/) % 3600; // in 0.1°      
545
                                          HeadFreeStartAngle = (3600 + FromFlightCtrl.GyroHeading /*+ Parameter.OrientationAngle * 150*/) % 3600; // in 0.1°      
536
                                        }
546
                                        }
537
                                }
547
                                }
538
 
548
 
539
                                Parameter.ActiveSetting = FromFlightCtrl.Param.Byte[9];
549
                                Parameter.ActiveSetting = FromFlightCtrl.Param.Byte[9];
540
                                DebugOut.Analog[5] = FC.StatusFlags;
550
                                DebugOut.Analog[5] = FC.StatusFlags;
541
                                NaviData.FCStatusFlags = FC.StatusFlags;
551
                                NaviData.FCStatusFlags = FC.StatusFlags;
542
                                FC.StatusFlags2 = FromFlightCtrl.Param.Byte[11];
552
                                FC.StatusFlags2 = FromFlightCtrl.Param.Byte[11];
543
                                NaviData.FCStatusFlags2 = (NaviData.FCStatusFlags2 & (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE)) | (FC.StatusFlags2 & (0xff - (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE)));
553
                                NaviData.FCStatusFlags2 = (NaviData.FCStatusFlags2 & (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE)) | (FC.StatusFlags2 & (0xff - (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE)));
544
 
554
 
545
                                if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT1_ACTIVE;
555
                                if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT1_ACTIVE;
546
                                else
556
                                else
547
                                if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE;
557
                                if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE;
548
 
558
 
549
                                if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT2_ACTIVE;
559
                                if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT2_ACTIVE;
550
                                else
560
                                else
551
                                if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE;
561
                                if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE;
552
 
562
 
553
                                Logging_FCStatusFlags1 |= FC.StatusFlags;
563
                                Logging_FCStatusFlags1 |= FC.StatusFlags;
554
                                Logging_FCStatusFlags2 |= FC.StatusFlags2;
564
                                Logging_FCStatusFlags2 |= FC.StatusFlags2;
555
                                Parameter.ComingHomeAltitude = FromFlightCtrl.Param.Byte[10];
565
                                Parameter.ComingHomeAltitude = FromFlightCtrl.Param.Byte[10];
556
                                break;
566
                                break;
557
 
567
 
558
                        case SPI_FCCMD_ACCU:
568
                        case SPI_FCCMD_ACCU:
559
                                FC.BAT_Current = FromFlightCtrl.Param.Int[0];
569
                                FC.BAT_Current = FromFlightCtrl.Param.Int[0];
560
                                FC.BAT_UsedCapacity = FromFlightCtrl.Param.Int[1];
570
                                FC.BAT_UsedCapacity = FromFlightCtrl.Param.Int[1];
561
                                FC.BAT_Voltage = FromFlightCtrl.Param.Byte[4];
571
                                FC.BAT_Voltage = FromFlightCtrl.Param.Byte[4];
562
                                Parameter.LowVoltageWarning = FromFlightCtrl.Param.Byte[5];
572
                                Parameter.LowVoltageWarning = FromFlightCtrl.Param.Byte[5];
563
                                FromFC_VarioCharacter = FromFlightCtrl.Param.Byte[6];
573
                                FromFC_VarioCharacter = FromFlightCtrl.Param.Byte[6];
564
                                Motor[FromFlightCtrl.Param.Byte[7]].MaxPWM = FromFlightCtrl.Param.Byte[8];
574
                                Motor[FromFlightCtrl.Param.Byte[7]].MaxPWM = FromFlightCtrl.Param.Byte[8];
565
                                Motor[FromFlightCtrl.Param.Byte[7]].State = FromFlightCtrl.Param.Byte[9];
575
                                Motor[FromFlightCtrl.Param.Byte[7]].State = FromFlightCtrl.Param.Byte[9];
566
                                Motor[FromFlightCtrl.Param.Byte[7]].Temperature = FromFlightCtrl.Param.Byte[10];
576
                                Motor[FromFlightCtrl.Param.Byte[7]].Temperature = FromFlightCtrl.Param.Byte[10];
567
                                Motor[FromFlightCtrl.Param.Byte[7]].Current = FromFlightCtrl.Param.Byte[11];
577
                                Motor[FromFlightCtrl.Param.Byte[7]].Current = FromFlightCtrl.Param.Byte[11];
568
                                if(FromFC_VarioCharacter == '+' || FromFC_VarioCharacter == '-') // manual setpoint clears the NC-Parameter command
578
                                if(FromFC_VarioCharacter == '+' || FromFC_VarioCharacter == '-') // manual setpoint clears the NC-Parameter command
569
                                 {
579
                                 {
570
                                  NCParams_ClearValue(NCPARAMS_ALTITUDE_RATE);
580
                                  NCParams_ClearValue(NCPARAMS_ALTITUDE_RATE);
571
                                 }
581
                                 }
572
                                NaviData.UBat = FC.BAT_Voltage;
582
                                NaviData.UBat = FC.BAT_Voltage;
573
                                NaviData.Current = FC.BAT_Current;
583
                                NaviData.Current = FC.BAT_Current;
574
                                NaviData.UsedCapacity = FC.BAT_UsedCapacity;
584
                                NaviData.UsedCapacity = FC.BAT_UsedCapacity;
575
                                break;
585
                                break;
576
 
-
 
577
#define CHK_POTI(b,a) { if(a < 248) b = a; else b = FC.Poti[255 - a]; }
-
 
578
#define CHK_POTI_MM(b,a,min,max) {CHK_POTI(b,a); LIMIT_MIN_MAX(b, min, max); }
-
 
579
 
-
 
580
                        case SPI_FCCMD_PARAMETER1:
586
                        case SPI_FCCMD_PARAMETER1:
581
                                CHK_POTI_MM(Parameter.NaviGpsModeControl,FromFlightCtrl.Param.Byte[0],0,255);
587
                                CHK_POTI_MM(Parameter.NaviGpsModeControl,FromFlightCtrl.Param.Byte[0],0,255);
582
                                CHK_POTI_MM(Parameter.NaviGpsGain,FromFlightCtrl.Param.Byte[1],0,255);
588
                                CHK_POTI_MM(Parameter.NaviGpsGain,FromFlightCtrl.Param.Byte[1],0,255);
583
                                CHK_POTI_MM(Parameter.NaviGpsP,FromFlightCtrl.Param.Byte[2],0,255);
589
                                CHK_POTI_MM(Parameter.NaviGpsP,FromFlightCtrl.Param.Byte[2],0,255);
584
                                CHK_POTI_MM(Parameter.NaviGpsI,FromFlightCtrl.Param.Byte[3],0,255);
590
                                CHK_POTI_MM(Parameter.NaviGpsI,FromFlightCtrl.Param.Byte[3],0,255);
585
                                CHK_POTI_MM(Parameter.NaviGpsD,FromFlightCtrl.Param.Byte[4],0,255);
591
                                CHK_POTI_MM(Parameter.NaviGpsD,FromFlightCtrl.Param.Byte[4],0,255);
586
                                CHK_POTI_MM(Parameter.NaviGpsACC,FromFlightCtrl.Param.Byte[5],0,255);
592
                                CHK_POTI_MM(Parameter.NaviGpsACC,FromFlightCtrl.Param.Byte[5],0,255);
587
                                Parameter.NaviGpsMinSat = FromFlightCtrl.Param.Byte[6];
593
                                Parameter.NaviGpsMinSat = FromFlightCtrl.Param.Byte[6];
588
                                Parameter.NaviStickThreshold = FromFlightCtrl.Param.Byte[7];
594
                                Parameter.NaviStickThreshold = FromFlightCtrl.Param.Byte[7];
589
                                CHK_POTI_MM(Parameter.NaviOperatingRadius,FromFlightCtrl.Param.Byte[8],0,255);
595
                                CHK_POTI_MM(Parameter.NaviOperatingRadius,FromFlightCtrl.Param.Byte[8],0,255);
590
                                CHK_POTI_MM(Parameter.NaviWindCorrection,FromFlightCtrl.Param.Byte[9],0,255);
596
                                CHK_POTI_MM(Parameter.NaviWindCorrection,FromFlightCtrl.Param.Byte[9],0,255);
591
                                CHK_POTI_MM(Parameter.NaviAccCompensation,FromFlightCtrl.Param.Byte[10],0,255);
597
                                CHK_POTI_MM(Parameter.NaviAccCompensation,FromFlightCtrl.Param.Byte[10],0,255);
592
                                CHK_POTI_MM(Parameter.NaviAngleLimitation,FromFlightCtrl.Param.Byte[11],0,255);
598
                                CHK_POTI_MM(Parameter.NaviAngleLimitation,FromFlightCtrl.Param.Byte[11],0,255);
593
                                break;
599
                                break;
594
                        case SPI_FCCMD_PARAMETER2:
600
                        case SPI_FCCMD_PARAMETER2:
595
                                CHK_POTI_MM(Parameter.NaviOut1Parameter,FromFlightCtrl.Param.Byte[0],0,255);
601
                                CHK_POTI_MM(Parameter.NaviOut1Parameter,FromFlightCtrl.Param.Byte[0],0,255);
596
                                break;
602
                                break;
597
                        case SPI_FCCMD_STICK:
603
                        case SPI_FCCMD_STICK:
598
                                FC.StickGas     = FromFlightCtrl.Param.sByte[0];
604
                                FC.StickGas     = FromFlightCtrl.Param.sByte[0];
599
                                FC.StickYaw     = FromFlightCtrl.Param.sByte[1];
605
                                FC.StickYaw     = FromFlightCtrl.Param.sByte[1];
600
                                FC.StickRoll    = FromFlightCtrl.Param.sByte[2];
606
                                FC.StickRoll    = FromFlightCtrl.Param.sByte[2];
601
                                FC.StickNick    = FromFlightCtrl.Param.sByte[3];
607
                                FC.StickNick    = FromFlightCtrl.Param.sByte[3];
602
                                FC.Poti[0]              = FromFlightCtrl.Param.Byte[4];
608
                                FC.Poti[0]              = FromFlightCtrl.Param.Byte[4];
603
                                FC.Poti[1]              = FromFlightCtrl.Param.Byte[5];
609
                                FC.Poti[1]              = FromFlightCtrl.Param.Byte[5];
604
                                FC.Poti[2]              = FromFlightCtrl.Param.Byte[6];
610
                                FC.Poti[2]              = FromFlightCtrl.Param.Byte[6];
605
                                FC.Poti[3]              = FromFlightCtrl.Param.Byte[7];
611
                                FC.Poti[3]              = FromFlightCtrl.Param.Byte[7];
606
                                FC.Poti[4]              = FromFlightCtrl.Param.Byte[8];
612
                                FC.Poti[4]              = FromFlightCtrl.Param.Byte[8];
607
                                FC.Poti[5]              = FromFlightCtrl.Param.Byte[9];
613
                                FC.Poti[5]              = FromFlightCtrl.Param.Byte[9];
608
                                FC.Poti[6]              = FromFlightCtrl.Param.Byte[10];
614
                                FC.Poti[6]              = FromFlightCtrl.Param.Byte[10];
609
                                FC.Poti[7]              = FromFlightCtrl.Param.Byte[11];
615
                                FC.Poti[7]              = FromFlightCtrl.Param.Byte[11];
-
 
616
                            CHK_POTI_MM(WaypointAcceleration,WaypointAccelerationSetting,0,255); // that could be a Poti-Value
610
                                break;
617
                                break;
611
 
618
 
612
                        case SPI_FCCMD_MISC:
619
                        case SPI_FCCMD_MISC:
613
                                if(CompassCalState != FromFlightCtrl.Param.Byte[0])
620
                                if(CompassCalState != FromFlightCtrl.Param.Byte[0])
614
                                {       // put only new CompassCalState into queue to send via I2C
621
                                {       // put only new CompassCalState into queue to send via I2C
615
//                                      if(FromFlightCtrl.Param.Byte[0] == CompassCalState+1 || FromFlightCtrl.Param.Byte[0] == 0) 
622
//                                      if(FromFlightCtrl.Param.Byte[0] == CompassCalState+1 || FromFlightCtrl.Param.Byte[0] == 0) 
616
                                         {
623
                                         {
617
                                           CompassCalState = FromFlightCtrl.Param.Byte[0];
624
                                           CompassCalState = FromFlightCtrl.Param.Byte[0];
618
                                           Compass_SetCalState(CompassCalState);
625
                                           Compass_SetCalState(CompassCalState);
619
                                         }
626
                                         }
620
//                                       else CompassCalState = 0;
627
//                                       else CompassCalState = 0;
621
                                }
628
                                }
622
                                Parameter.NaviPH_LoginTime = FromFlightCtrl.Param.Byte[1];
629
                                Parameter.NaviPH_LoginTime = FromFlightCtrl.Param.Byte[1];
623
                                NaviData.Variometer = (NaviData.Variometer + 2 * (FromFlightCtrl.Param.sInt[1] - NaviData.Altimeter)) / 2; // provisorisch
630
                                NaviData.Variometer = (NaviData.Variometer + 2 * (FromFlightCtrl.Param.sInt[1] - NaviData.Altimeter)) / 2; // provisorisch
624
                                NaviData.Altimeter = FromFlightCtrl.Param.sInt[1]; // in 5cm
631
                                NaviData.Altimeter = FromFlightCtrl.Param.sInt[1]; // in 5cm
625
                                NaviData.SetpointAltitude = FromFlightCtrl.Param.sInt[2]; // in 5cm
632
                                NaviData.SetpointAltitude = FromFlightCtrl.Param.sInt[2]; // in 5cm
626
                                CHK_POTI_MM(Parameter.NaviGpsPLimit,FromFlightCtrl.Param.Byte[6],0,255);
633
                                CHK_POTI_MM(Parameter.NaviGpsPLimit,FromFlightCtrl.Param.Byte[6],0,255);
627
                                CHK_POTI_MM(Parameter.NaviGpsILimit,FromFlightCtrl.Param.Byte[7],0,255);
634
                                CHK_POTI_MM(Parameter.NaviGpsILimit,FromFlightCtrl.Param.Byte[7],0,255);
628
                                CHK_POTI_MM(Parameter.NaviGpsDLimit,FromFlightCtrl.Param.Byte[8],0,255);
635
                                CHK_POTI_MM(Parameter.NaviGpsDLimit,FromFlightCtrl.Param.Byte[8],0,255);
629
                                FC.RC_Quality   = FromFlightCtrl.Param.Byte[9];
636
                                FC.RC_Quality   = FromFlightCtrl.Param.Byte[9];
630
                                FC.RC_RSSI              = FromFlightCtrl.Param.Byte[10];
637
                                FC.RC_RSSI              = FromFlightCtrl.Param.Byte[10];
631
                                if(!FC.RC_RSSI) NaviData.RC_Quality = FC.RC_Quality; else NaviData.RC_Quality = FC.RC_RSSI;
638
                                if(!FC.RC_RSSI) NaviData.RC_Quality = FC.RC_Quality; else NaviData.RC_Quality = FC.RC_RSSI;
632
//                              NaviData.RC_RSSI = FC.RC_RSSI;
639
//                              NaviData.RC_RSSI = FC.RC_RSSI;
633
                                NaviData.Gas    = (FC.BAT_Voltage * (u32) FromFlightCtrl.Param.Byte[11]) / (u32) Parameter.LowVoltageWarning;
640
                                NaviData.Gas    = (FC.BAT_Voltage * (u32) FromFlightCtrl.Param.Byte[11]) / (u32) Parameter.LowVoltageWarning;
634
                                break;
641
                                break;
635
 
642
 
636
                        case SPI_FCCMD_SERVOS:
643
                        case SPI_FCCMD_SERVOS:
637
                                ServoParams.Refresh             = FromFlightCtrl.Param.Byte[0];
644
                                ServoParams.Refresh             = FromFlightCtrl.Param.Byte[0];
638
                                ServoParams.CompInvert  = FromFlightCtrl.Param.Byte[1];
645
                                ServoParams.CompInvert  = FromFlightCtrl.Param.Byte[1];
639
                                ServoParams.NickControl = FromFlightCtrl.Param.Byte[2];
646
                                ServoParams.NickControl = FromFlightCtrl.Param.Byte[2];
640
                                ServoParams.NickComp    = FromFlightCtrl.Param.Byte[3];
647
                                ServoParams.NickComp    = FromFlightCtrl.Param.Byte[3];
641
                                ServoParams.NickMin             = FromFlightCtrl.Param.Byte[4];
648
                                ServoParams.NickMin             = FromFlightCtrl.Param.Byte[4];
642
                                ServoParams.NickMax             = FromFlightCtrl.Param.Byte[5];
649
                                ServoParams.NickMax             = FromFlightCtrl.Param.Byte[5];
643
                                ServoParams.RollControl = FromFlightCtrl.Param.Byte[6];
650
                                ServoParams.RollControl = FromFlightCtrl.Param.Byte[6];
644
                                ServoParams.RollComp    = FromFlightCtrl.Param.Byte[7];
651
                                ServoParams.RollComp    = FromFlightCtrl.Param.Byte[7];
645
                                ServoParams.RollMin             = FromFlightCtrl.Param.Byte[8];
652
                                ServoParams.RollMin             = FromFlightCtrl.Param.Byte[8];
646
                                ServoParams.RollMax             = FromFlightCtrl.Param.Byte[9];
653
                                ServoParams.RollMax             = FromFlightCtrl.Param.Byte[9];
647
                                BL_MinOfMaxPWM = FromFlightCtrl.Param.Byte[10];
654
                                BL_MinOfMaxPWM = FromFlightCtrl.Param.Byte[10];
648
                                FC_I2C_ErrorConter = FromFlightCtrl.Param.Byte[11];
655
                                FC_I2C_ErrorConter = FromFlightCtrl.Param.Byte[11];
649
                                break;
656
                                break;
650
 
657
 
651
                        case SPI_FCCMD_VERSION:
658
                        case SPI_FCCMD_VERSION:
652
                                FC_Version.Major                = FromFlightCtrl.Param.Byte[0];
659
                                FC_Version.Major                = FromFlightCtrl.Param.Byte[0];
653
                                FC_Version.Minor                = FromFlightCtrl.Param.Byte[1];
660
                                FC_Version.Minor                = FromFlightCtrl.Param.Byte[1];
654
                                FC_Version.Patch                = FromFlightCtrl.Param.Byte[2];
661
                                FC_Version.Patch                = FromFlightCtrl.Param.Byte[2];
655
                                FC_Version.Compatible   = FromFlightCtrl.Param.Byte[3];
662
                                FC_Version.Compatible   = FromFlightCtrl.Param.Byte[3];
656
                                FC_Version.Hardware             = FromFlightCtrl.Param.Byte[4];
663
                                FC_Version.Hardware             = FromFlightCtrl.Param.Byte[4];
657
                                FC.Error[0]                     |= FromFlightCtrl.Param.Byte[5];
664
                                FC.Error[0]                     |= FromFlightCtrl.Param.Byte[5];
658
                                FC.Error[1]                     |= FromFlightCtrl.Param.Byte[6];
665
                                FC.Error[1]                     |= FromFlightCtrl.Param.Byte[6];
659
                                FC.Error[2]                     |= FromFlightCtrl.Param.Byte[7];
666
                                FC.Error[2]                     |= FromFlightCtrl.Param.Byte[7];
660
                                Parameter.GlobalConfig = FromFlightCtrl.Param.Byte[8];
667
                                Parameter.GlobalConfig = FromFlightCtrl.Param.Byte[8];
661
                                Parameter.ExtraConfig = FromFlightCtrl.Param.Byte[9];
668
                                Parameter.ExtraConfig = FromFlightCtrl.Param.Byte[9];
662
                                Parameter.OrientationAngle = FromFlightCtrl.Param.Byte[10];
669
                                Parameter.OrientationAngle = FromFlightCtrl.Param.Byte[10];
663
                                Parameter.GlobalConfig3 = FromFlightCtrl.Param.Byte[11];
670
                                Parameter.GlobalConfig3 = FromFlightCtrl.Param.Byte[11];
664
                                DebugOut.StatusGreen |= AMPEL_FC; // status of FC Present
671
                                DebugOut.StatusGreen |= AMPEL_FC; // status of FC Present
665
                                DebugOut.StatusGreen |= AMPEL_BL; // status of BL Present
672
                                DebugOut.StatusGreen |= AMPEL_BL; // status of BL Present
666
                                if(FC.Error[0] || FC.Error[1] || FC.Error[2] || FC.Error[3] || FC.Error[4]) DebugOut.StatusRed |= AMPEL_FC;
673
                                if(FC.Error[0] || FC.Error[1] || FC.Error[2] || FC.Error[3] || FC.Error[4]) DebugOut.StatusRed |= AMPEL_FC;
667
                                else DebugOut.StatusRed &= ~AMPEL_FC;
674
                                else DebugOut.StatusRed &= ~AMPEL_FC;
668
                                break;
675
                                break;
669
                        default:
676
                        default:
670
                                break;
677
                                break;
671
                }
678
                }
672
 
679
 
673
                DebugOut.Analog[0] = FromFlightCtrl.AngleNick;
680
                DebugOut.Analog[0] = FromFlightCtrl.AngleNick;
674
                DebugOut.Analog[1] = FromFlightCtrl.AngleRoll;
681
                DebugOut.Analog[1] = FromFlightCtrl.AngleRoll;
675
                DebugOut.Analog[2] = FromFlightCtrl.AccNick;
682
                DebugOut.Analog[2] = FromFlightCtrl.AccNick;
676
                DebugOut.Analog[3] = FromFlightCtrl.AccRoll;
683
                DebugOut.Analog[3] = FromFlightCtrl.AccRoll;
677
                DebugOut.Analog[11] = FromFlightCtrl.GyroHeading/10;// in deg
684
                DebugOut.Analog[11] = FromFlightCtrl.GyroHeading/10;// in deg
678
                Data3D.AngleNick = FromFlightCtrl.AngleNick;            // in 0.1 deg
685
                Data3D.AngleNick = FromFlightCtrl.AngleNick;            // in 0.1 deg
679
                Data3D.AngleRoll = FromFlightCtrl.AngleRoll;            // in 0.1 deg
686
                Data3D.AngleRoll = FromFlightCtrl.AngleRoll;            // in 0.1 deg
680
                Data3D.Heading   = FromFlightCtrl.GyroHeading;          // in 0.1 deg
687
                Data3D.Heading   = FromFlightCtrl.GyroHeading;          // in 0.1 deg
681
                // every time we got new data from the FC via SPI call the navigation routine
688
                // every time we got new data from the FC via SPI call the navigation routine
682
                // and update GPSStick that are returned to FC
689
                // and update GPSStick that are returned to FC
683
                SPI_RxBuffer_Request = 0;
690
                SPI_RxBuffer_Request = 0;
684
 
691
 
685
 
692
 
686
/*
693
/*
687
//+++++++++++++++++++++++++++++++++++++++++++++++++++
694
//+++++++++++++++++++++++++++++++++++++++++++++++++++
688
*/
695
*/
689
//+++++++++++++++++++++++++++++++++++++++++++++++++++
696
//+++++++++++++++++++++++++++++++++++++++++++++++++++
690
// in SPI Einkommentieren, falls der Flug simultert werden soll
697
// in SPI Einkommentieren, falls der Flug simultert werden soll
691
/*
698
/*
692
if(Parameter.User8 < 100) FC.StatusFlags = 0;
699
if(Parameter.User8 < 100) FC.StatusFlags = 0;
693
else
700
else
694
if(Parameter.User8 < 150) FC.StatusFlags = FC_STATUS_START;
701
if(Parameter.User8 < 150) FC.StatusFlags = FC_STATUS_START;
695
else FC.StatusFlags = FC_STATUS_FLY | FC_STATUS_MOTOR_RUN;
702
else FC.StatusFlags = FC_STATUS_FLY | FC_STATUS_MOTOR_RUN;
696
BL_MinOfMaxPWM = 255;
703
BL_MinOfMaxPWM = 255;
697
NaviData.FCStatusFlags = FC.StatusFlags;
704
NaviData.FCStatusFlags = FC.StatusFlags;
698
*/
705
*/
699
//+++++++++++++++++++++++++++++++++++++++++++++++++++
706
//+++++++++++++++++++++++++++++++++++++++++++++++++++
700
 
707
 
701
 
708
 
702
                GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick));
709
                GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick));
703
                ClearFCStatusFlags = 1;
710
                ClearFCStatusFlags = 1;
704
                if(counter)
711
                if(counter)
705
                {
712
                {
706
                        counter--;                                       // count down to enable servo
713
                        counter--;                                       // count down to enable servo
707
                        if(!counter) TIMER2_Init();  // enable Servo Output
714
                        if(!counter) TIMER2_Init();  // enable Servo Output
708
                }
715
                }
709
                timeout = SetDelay(80); // 80 ms, new data are send every 20 ms
716
                timeout = SetDelay(80); // 80 ms, new data are send every 20 ms
710
 
717
 
711
        }       // EOF if(SPI_RxBuffer_Request)
718
        }       // EOF if(SPI_RxBuffer_Request)
712
        else // no new SPI data
719
        else // no new SPI data
713
        {
720
        {
714
                if(CheckDelay(timeout) && (counter == 0))
721
                if(CheckDelay(timeout) && (counter == 0))
715
                {
722
                {
716
                        TIMER2_Deinit();  // disable Servo Output
723
                        TIMER2_Deinit();  // disable Servo Output
717
                        counter = 50;     // reset counter for enabling Servo Output
724
                        counter = 50;     // reset counter for enabling Servo Output
718
                }
725
                }
719
        }
726
        }
720
}
727
}
721
 
728
 
722
//------------------------------------------------------
729
//------------------------------------------------------
723
void SPI0_GetFlightCtrlVersion(void)
730
void SPI0_GetFlightCtrlVersion(void)
724
{
731
{
725
        u32 timeout;
732
        u32 timeout;
726
        u8 repeat;
733
        u8 repeat;
727
        u8 msg[64];
734
        u8 msg[64];
728
 
735
 
729
        UART1_PutString("\r\n Looking for FlightControl");
736
        UART1_PutString("\r\n Looking for FlightControl");
730
        FC_Version.Major = 0xFF;
737
        FC_Version.Major = 0xFF;
731
        FC_Version.Minor = 0xFF;
738
        FC_Version.Minor = 0xFF;
732
        FC_Version.Patch = 0xFF;
739
        FC_Version.Patch = 0xFF;
733
        FC_Version.Compatible = 0xFF;
740
        FC_Version.Compatible = 0xFF;
734
 
741
 
735
        // polling FC version info
742
        // polling FC version info
736
        repeat = 0;
743
        repeat = 0;
737
        do
744
        do
738
        {
745
        {
739
                timeout = SetDelay(250);
746
                timeout = SetDelay(250);
740
                do
747
                do
741
                {
748
                {
742
                        SPI0_UpdateBuffer();
749
                        SPI0_UpdateBuffer();
743
                        if (FC_Version.Major != 0xFF)  break;
750
                        if (FC_Version.Major != 0xFF)  break;
744
                }while (!CheckDelay(timeout));
751
                }while (!CheckDelay(timeout));
745
                UART1_PutString(".");
752
                UART1_PutString(".");
746
                repeat++;
753
                repeat++;
747
                FCCalibActive = 1;
754
                FCCalibActive = 1;
748
        }while((FC_Version.Major == 0xFF) && (repeat < 40)); // 40*250ms = 10s
755
        }while((FC_Version.Major == 0xFF) && (repeat < 40)); // 40*250ms = 10s
749
        // if we got it
756
        // if we got it
750
        if (FC_Version.Major != 0xFF)
757
        if (FC_Version.Major != 0xFF)
751
        {
758
        {
752
                sprintf(msg, " FC V%d.%d%c HW:%d.%d", FC_Version.Major, FC_Version.Minor, 'a'+FC_Version.Patch, FC_Version.Hardware/10,FC_Version.Hardware%10);
759
                sprintf(msg, " FC V%d.%d%c HW:%d.%d", FC_Version.Major, FC_Version.Minor, 'a'+FC_Version.Patch, FC_Version.Hardware/10,FC_Version.Hardware%10);
753
                UART1_PutString(msg);
760
                UART1_PutString(msg);
754
        }
761
        }
755
        else UART1_PutString("\n\r not found!");
762
        else UART1_PutString("\n\r not found!");
756
}
763
}
757
 
764
 
758
 
765
 
759
 
766