Rev 420 | Rev 426 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 420 | Rev 421 | ||
---|---|---|---|
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 | 72 | ||
73 | #define SPI_RXSYNCBYTE1 0xAA |
73 | #define SPI_RXSYNCBYTE1 0xAA |
74 | #define SPI_RXSYNCBYTE2 0x83 |
74 | #define SPI_RXSYNCBYTE2 0x83 |
75 | #define SPI_TXSYNCBYTE1 0x81 |
75 | #define SPI_TXSYNCBYTE1 0x81 |
76 | #define SPI_TXSYNCBYTE2 0x55 |
76 | #define SPI_TXSYNCBYTE2 0x55 |
77 | 77 | ||
78 | //communication packets |
78 | //communication packets |
79 | FromFlightCtrl_t FromFlightCtrl; |
79 | FromFlightCtrl_t FromFlightCtrl; |
80 | ToFlightCtrl_t ToFlightCtrl; |
80 | ToFlightCtrl_t ToFlightCtrl; |
81 | #define SPI0_TIMEOUT 2500 //ms |
81 | #define SPI0_TIMEOUT 2500 //ms |
82 | volatile u32 SPI0_Timeout = 0; |
82 | volatile u32 SPI0_Timeout = 0; |
83 | u8 Logging_FCStatusFlags1 = 0,Logging_FCStatusFlags2 = 0; |
83 | u8 Logging_FCStatusFlags1 = 0,Logging_FCStatusFlags2 = 0; |
84 | u8 SpeakHoTT = 0; |
84 | u8 SpeakHoTT = 0; |
85 | 85 | ||
86 | // tx packet buffer |
86 | // tx packet buffer |
87 | #define SPI_TXBUFFER_LEN (2 + sizeof(ToFlightCtrl)) // 2 bytes at start are for synchronization |
87 | #define SPI_TXBUFFER_LEN (2 + sizeof(ToFlightCtrl)) // 2 bytes at start are for synchronization |
88 | volatile u8 SPI_TxBuffer[SPI_TXBUFFER_LEN + 10]; |
88 | volatile u8 SPI_TxBuffer[SPI_TXBUFFER_LEN + 10]; |
89 | volatile u8 SPI_TxBufferIndex = 0; |
89 | volatile u8 SPI_TxBufferIndex = 0; |
90 | u8 *Ptr_TxChksum = NULL ; // pointer to checksum in TxBuffer |
90 | u8 *Ptr_TxChksum = NULL ; // pointer to checksum in TxBuffer |
91 | 91 | ||
92 | // rx packet buffer |
92 | // rx packet buffer |
93 | #define SPI_RXBUFFER_LEN sizeof(FromFlightCtrl) |
93 | #define SPI_RXBUFFER_LEN sizeof(FromFlightCtrl) |
94 | volatile u8 SPI_RxBuffer[SPI_RXBUFFER_LEN+10]; |
94 | volatile u8 SPI_RxBuffer[SPI_RXBUFFER_LEN+10]; |
95 | volatile u8 SPI_RxBufferIndex = 0; |
95 | volatile u8 SPI_RxBufferIndex = 0; |
96 | volatile u8 SPI_RxBuffer_Request = 0; |
96 | volatile u8 SPI_RxBuffer_Request = 0; |
97 | #define SPI_COMMAND_INDEX 0 |
97 | #define SPI_COMMAND_INDEX 0 |
98 | 98 | ||
99 | s32 Kalman_K = 32; |
99 | s32 Kalman_K = 32; |
100 | s32 Kalman_MaxDrift = 5 * 16; |
100 | s32 Kalman_MaxDrift = 5 * 16; |
101 | s32 Kalman_MaxFusion = 64; |
101 | s32 Kalman_MaxFusion = 64; |
102 | s32 Kalman_Kompass = 32; |
102 | s32 Kalman_Kompass = 32; |
103 | s32 ToFcGpsZ = 0; |
103 | s32 ToFcGpsZ = 0; |
104 | u8 CompassCalState = 0; |
104 | u8 CompassCalState = 0; |
105 | 105 | ||
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 }; |
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_CommandCounter = 0; |
107 | u8 SPI_CommandCounter = 0; |
108 | s32 ToFC_Rotate_C = 64, ToFC_Rotate_S = 0; |
108 | s32 ToFC_Rotate_C = 64, ToFC_Rotate_S = 0; |
109 | s32 HeadFreeStartAngle = 0; |
109 | s32 HeadFreeStartAngle = 0; |
110 | s16 FC_WP_EventChannel = 0; // gibt einen Schaltkanal an die FC weiter, wenn der Wegpunkt erreicht wurde |
110 | 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; |
111 | u32 ToFC_AltitudeRate = 0; |
112 | s32 ToFC_AltitudeSetpoint = 0; |
112 | s32 ToFC_AltitudeSetpoint = 0; |
113 | u8 FromFC_VarioCharacter = ' '; |
113 | u8 FromFC_VarioCharacter = ' '; |
114 | u8 GPS_Aid_StickMultiplikator = 0; |
114 | u8 GPS_Aid_StickMultiplikator = 0; |
115 | u8 NC_GPS_ModeCharacter = ' '; |
115 | u8 NC_GPS_ModeCharacter = ' '; |
116 | u8 FCCalibActive = 0; |
116 | u8 FCCalibActive = 0; |
117 | u8 FC_is_Calibrated = 0; |
117 | u8 FC_is_Calibrated = 0; |
118 | Motor_t Motor[12]; |
118 | Motor_t Motor[12]; |
119 | u8 NC_To_FC_Flags = 0; |
119 | u8 NC_To_FC_Flags = 0; |
120 | u8 BL_MinOfMaxPWM; // indication if all BL-controllers run on full power |
120 | u8 BL_MinOfMaxPWM; // indication if all BL-controllers run on full power |
121 | u32 FC_I2C_ErrorConter; |
121 | u32 FC_I2C_ErrorConter; |
122 | SPI_Version_t FC_Version; |
122 | SPI_Version_t FC_Version; |
123 | s16 POI_KameraNick = 0; |
123 | s16 POI_KameraNick = 0; |
124 | 124 | ||
125 | //-------------------------------------------------------------- |
125 | //-------------------------------------------------------------- |
126 | void SSP0_IRQHandler(void) |
126 | void SSP0_IRQHandler(void) |
127 | { |
127 | { |
128 | static u8 rxchksum = 0; |
128 | static u8 rxchksum = 0; |
129 | u8 rxdata; |
129 | u8 rxdata; |
130 | 130 | ||
131 | #define SPI_SYNC1 0 |
131 | #define SPI_SYNC1 0 |
132 | #define SPI_SYNC2 1 |
132 | #define SPI_SYNC2 1 |
133 | #define SPI_DATA 2 |
133 | #define SPI_DATA 2 |
134 | static u8 SPI_State = SPI_SYNC1; |
134 | static u8 SPI_State = SPI_SYNC1; |
135 | //IENABLE; |
135 | //IENABLE; |
136 | 136 | ||
137 | // clear pending bits |
137 | // clear pending bits |
138 | SSP_ClearITPendingBit(SSP0, SSP_IT_RxTimeOut); |
138 | SSP_ClearITPendingBit(SSP0, SSP_IT_RxTimeOut); |
139 | SSP_ClearITPendingBit(SSP0, SSP_IT_RxFifo); |
139 | SSP_ClearITPendingBit(SSP0, SSP_IT_RxFifo); |
140 | 140 | ||
141 | // while RxFIFO not empty |
141 | // while RxFIFO not empty |
142 | while(SSP_GetFlagStatus(SSP0, SSP_FLAG_RxFifoNotEmpty) == SET) |
142 | while(SSP_GetFlagStatus(SSP0, SSP_FLAG_RxFifoNotEmpty) == SET) |
143 | { |
143 | { |
144 | rxdata = SSP0->DR; // catch the received byte |
144 | rxdata = SSP0->DR; // catch the received byte |
145 | // Fill TxFIFO while its not full or end of packet is reached |
145 | // Fill TxFIFO while its not full or end of packet is reached |
146 | while (SSP_GetFlagStatus(SSP0, SSP_FLAG_TxFifoNotFull) == SET) |
146 | while (SSP_GetFlagStatus(SSP0, SSP_FLAG_TxFifoNotFull) == SET) |
147 | { |
147 | { |
148 | if (SPI_TxBufferIndex < SPI_TXBUFFER_LEN) // still data to send ? |
148 | if (SPI_TxBufferIndex < SPI_TXBUFFER_LEN) // still data to send ? |
149 | { |
149 | { |
150 | SSP0->DR = SPI_TxBuffer[SPI_TxBufferIndex]; // send a byte |
150 | SSP0->DR = SPI_TxBuffer[SPI_TxBufferIndex]; // send a byte |
151 | *Ptr_TxChksum += SPI_TxBuffer[SPI_TxBufferIndex]; // update checksum |
151 | *Ptr_TxChksum += SPI_TxBuffer[SPI_TxBufferIndex]; // update checksum |
152 | if(SPIWatchDog == 0) *Ptr_TxChksum += 1; // disturbe this packet to stop the communication! |
152 | if(SPIWatchDog == 0) *Ptr_TxChksum += 1; // disturbe this packet to stop the communication! |
153 | SPI_TxBufferIndex++; // pointer to next byte |
153 | SPI_TxBufferIndex++; // pointer to next byte |
154 | } |
154 | } |
155 | else // end of packet is reached reset and copy data to tx buffer |
155 | else // end of packet is reached reset and copy data to tx buffer |
156 | { |
156 | { |
157 | SPI_TxBufferIndex = 0; // reset buffer index |
157 | SPI_TxBufferIndex = 0; // reset buffer index |
158 | ToFlightCtrl.Chksum = 0; // initialize checksum |
158 | ToFlightCtrl.Chksum = 0; // initialize checksum |
159 | ToFlightCtrl.BeepTime = BeepTime; // set beeptime |
159 | ToFlightCtrl.BeepTime = BeepTime; // set beeptime |
160 | BeepTime = 0; // reset local beeptime |
160 | BeepTime = 0; // reset local beeptime |
161 | // copy contents of ToFlightCtrl->SPI_TxBuffer |
161 | // copy contents of ToFlightCtrl->SPI_TxBuffer |
162 | memcpy((u8 *) &(SPI_TxBuffer[2]), (u8 *) &ToFlightCtrl, sizeof(ToFlightCtrl)); |
162 | memcpy((u8 *) &(SPI_TxBuffer[2]), (u8 *) &ToFlightCtrl, sizeof(ToFlightCtrl)); |
163 | } |
163 | } |
164 | } |
164 | } |
165 | switch (SPI_State) |
165 | switch (SPI_State) |
166 | { |
166 | { |
167 | case SPI_SYNC1: |
167 | case SPI_SYNC1: |
168 | SPI_RxBufferIndex = 0; // reset buffer index |
168 | SPI_RxBufferIndex = 0; // reset buffer index |
169 | rxchksum = rxdata; // init checksum |
169 | rxchksum = rxdata; // init checksum |
170 | if (rxdata == SPI_RXSYNCBYTE1) |
170 | if (rxdata == SPI_RXSYNCBYTE1) |
171 | { // 1st syncbyte ok |
171 | { // 1st syncbyte ok |
172 | SPI_State = SPI_SYNC2; // step to sync2 |
172 | SPI_State = SPI_SYNC2; // step to sync2 |
173 | } |
173 | } |
174 | break; |
174 | break; |
175 | case SPI_SYNC2: |
175 | case SPI_SYNC2: |
176 | if (rxdata == SPI_RXSYNCBYTE2) |
176 | if (rxdata == SPI_RXSYNCBYTE2) |
177 | { // 2nd Syncbyte ok |
177 | { // 2nd Syncbyte ok |
178 | rxchksum += rxdata; |
178 | rxchksum += rxdata; |
179 | SPI_State = SPI_DATA; |
179 | SPI_State = SPI_DATA; |
180 | } // 2nd Syncbyte does not match |
180 | } // 2nd Syncbyte does not match |
181 | else |
181 | else |
182 | { |
182 | { |
183 | SPI_State = SPI_SYNC1; //jump back to sync1 |
183 | SPI_State = SPI_SYNC1; //jump back to sync1 |
184 | } |
184 | } |
185 | break; |
185 | break; |
186 | case SPI_DATA: |
186 | case SPI_DATA: |
187 | SPI_RxBuffer[SPI_RxBufferIndex++]= rxdata; // copy databyte to rx buffer |
187 | SPI_RxBuffer[SPI_RxBufferIndex++]= rxdata; // copy databyte to rx buffer |
188 | if(SPI_RxBufferIndex >= SPI_RXBUFFER_LEN) // end of packet is reached |
188 | if(SPI_RxBufferIndex >= SPI_RXBUFFER_LEN) // end of packet is reached |
189 | { |
189 | { |
190 | if (rxdata == rxchksum) // verify checksum byte |
190 | if (rxdata == rxchksum) // verify checksum byte |
191 | { |
191 | { |
192 | // copy SPI_RxBuffer -> FromFlightCtrl |
192 | // copy SPI_RxBuffer -> FromFlightCtrl |
193 | if(!SPI_RxBuffer_Request) // block writing to FromFlightCtrl on reading access |
193 | if(!SPI_RxBuffer_Request) // block writing to FromFlightCtrl on reading access |
194 | { |
194 | { |
195 | memcpy((u8 *) &FromFlightCtrl, (u8 *) SPI_RxBuffer, sizeof(FromFlightCtrl)); |
195 | memcpy((u8 *) &FromFlightCtrl, (u8 *) SPI_RxBuffer, sizeof(FromFlightCtrl)); |
196 | SPI_RxBuffer_Request = 1; |
196 | SPI_RxBuffer_Request = 1; |
197 | } |
197 | } |
198 | // reset timeout counter on good packet |
198 | // reset timeout counter on good packet |
199 | SPI0_Timeout = SetDelay(SPI0_TIMEOUT); |
199 | SPI0_Timeout = SetDelay(SPI0_TIMEOUT); |
200 | DebugOut.Analog[13]++; |
200 | DebugOut.Analog[13]++; |
201 | } |
201 | } |
202 | else // bad checksum byte |
202 | else // bad checksum byte |
203 | { |
203 | { |
204 | DebugOut.Analog[12]++; // increase SPI chksum error counter |
204 | DebugOut.Analog[12]++; // increase SPI chksum error counter |
205 | } |
205 | } |
206 | SPI_State = SPI_SYNC1; // reset state |
206 | SPI_State = SPI_SYNC1; // reset state |
207 | } |
207 | } |
208 | else // end of packet not reached |
208 | else // end of packet not reached |
209 | { |
209 | { |
210 | rxchksum += rxdata; // update checksum |
210 | rxchksum += rxdata; // update checksum |
211 | } |
211 | } |
212 | break; |
212 | break; |
213 | default: |
213 | default: |
214 | SPI_State = SPI_SYNC1; |
214 | SPI_State = SPI_SYNC1; |
215 | break; |
215 | break; |
216 | } |
216 | } |
217 | } |
217 | } |
218 | 218 | ||
219 | // IDISABLE; |
219 | // IDISABLE; |
220 | VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register |
220 | VIC1->VAR = 0xFF; // write any value to VIC0 Vector address register |
221 | } |
221 | } |
222 | 222 | ||
223 | //-------------------------------------------------------------- |
223 | //-------------------------------------------------------------- |
224 | void SPI0_Init(void) |
224 | void SPI0_Init(void) |
225 | { |
225 | { |
226 | GPIO_InitTypeDef GPIO_InitStructure; |
226 | GPIO_InitTypeDef GPIO_InitStructure; |
227 | SSP_InitTypeDef SSP_InitStructure; |
227 | SSP_InitTypeDef SSP_InitStructure; |
228 | 228 | ||
229 | UART1_PutString("\r\n SPI init..."); |
229 | UART1_PutString("\r\n SPI init..."); |
230 | 230 | ||
231 | SCU_APBPeriphClockConfig(__GPIO2 ,ENABLE); |
231 | SCU_APBPeriphClockConfig(__GPIO2 ,ENABLE); |
232 | SCU_APBPeriphClockConfig(__SSP0 ,ENABLE); |
232 | SCU_APBPeriphClockConfig(__SSP0 ,ENABLE); |
233 | 233 | ||
234 | GPIO_DeInit(GPIO2); |
234 | GPIO_DeInit(GPIO2); |
235 | //SSP0_CLK, SSP0_MOSI, SSP0_NSS pins |
235 | //SSP0_CLK, SSP0_MOSI, SSP0_NSS pins |
236 | GPIO_StructInit(&GPIO_InitStructure); |
236 | GPIO_StructInit(&GPIO_InitStructure); |
237 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
237 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
238 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7; |
238 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7; |
239 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
239 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
240 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
240 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
241 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //SSP0_SCLK, SSP0_MOSI, SSP0_NSS |
241 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //SSP0_SCLK, SSP0_MOSI, SSP0_NSS |
242 | GPIO_Init (GPIO2, &GPIO_InitStructure); |
242 | GPIO_Init (GPIO2, &GPIO_InitStructure); |
243 | 243 | ||
244 | // SSP0_MISO pin GPIO2.6 |
244 | // SSP0_MISO pin GPIO2.6 |
245 | GPIO_StructInit(&GPIO_InitStructure); |
245 | GPIO_StructInit(&GPIO_InitStructure); |
246 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
246 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
247 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
247 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
248 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
248 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
249 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
249 | GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; |
250 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; //SSP0_MISO |
250 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; //SSP0_MISO |
251 | GPIO_Init (GPIO2, &GPIO_InitStructure); |
251 | GPIO_Init (GPIO2, &GPIO_InitStructure); |
252 | 252 | ||
253 | SSP_DeInit(SSP0); |
253 | SSP_DeInit(SSP0); |
254 | SSP_StructInit(&SSP_InitStructure); |
254 | SSP_StructInit(&SSP_InitStructure); |
255 | SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola; |
255 | SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola; |
256 | SSP_InitStructure.SSP_Mode = SSP_Mode_Slave; |
256 | SSP_InitStructure.SSP_Mode = SSP_Mode_Slave; |
257 | SSP_InitStructure.SSP_SlaveOutput = SSP_SlaveOutput_Enable; |
257 | SSP_InitStructure.SSP_SlaveOutput = SSP_SlaveOutput_Enable; |
258 | SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge; |
258 | SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge; |
259 | SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low; |
259 | SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low; |
260 | SSP_InitStructure.SSP_ClockRate = 0; |
260 | SSP_InitStructure.SSP_ClockRate = 0; |
261 | 261 | ||
262 | SSP_Init(SSP0, &SSP_InitStructure); |
262 | SSP_Init(SSP0, &SSP_InitStructure); |
263 | SSP_ITConfig(SSP0, SSP_IT_RxFifo | SSP_IT_RxTimeOut, ENABLE); |
263 | SSP_ITConfig(SSP0, SSP_IT_RxFifo | SSP_IT_RxTimeOut, ENABLE); |
264 | SSP_Cmd(SSP0, ENABLE); |
264 | SSP_Cmd(SSP0, ENABLE); |
265 | // initialize the syncbytes in the tx buffer |
265 | // initialize the syncbytes in the tx buffer |
266 | SPI_TxBuffer[0] = SPI_TXSYNCBYTE1; |
266 | SPI_TxBuffer[0] = SPI_TXSYNCBYTE1; |
267 | SPI_TxBuffer[1] = SPI_TXSYNCBYTE2; |
267 | SPI_TxBuffer[1] = SPI_TXSYNCBYTE2; |
268 | // set the pointer to the checksum byte in the tx buffer |
268 | // set the pointer to the checksum byte in the tx buffer |
269 | Ptr_TxChksum = (u8 *) &(((ToFlightCtrl_t *) &(SPI_TxBuffer[2]))->Chksum); |
269 | Ptr_TxChksum = (u8 *) &(((ToFlightCtrl_t *) &(SPI_TxBuffer[2]))->Chksum); |
270 | 270 | ||
271 | ToFlightCtrl.GPSStick.Nick = 0; |
271 | ToFlightCtrl.GPSStick.Nick = 0; |
272 | ToFlightCtrl.GPSStick.Roll = 0; |
272 | ToFlightCtrl.GPSStick.Roll = 0; |
273 | // ToFlightCtrl.GPSStick.Yaw = 0; |
273 | // ToFlightCtrl.GPSStick.Yaw = 0; |
274 | 274 | ||
275 | VIC_Config(SSP0_ITLine, VIC_IRQ, PRIORITY_SPI0); |
275 | VIC_Config(SSP0_ITLine, VIC_IRQ, PRIORITY_SPI0); |
276 | VIC_ITCmd(SSP0_ITLine, ENABLE); |
276 | VIC_ITCmd(SSP0_ITLine, ENABLE); |
277 | 277 | ||
278 | SPI0_Timeout = SetDelay(4*SPI0_TIMEOUT); |
278 | SPI0_Timeout = SetDelay(4*SPI0_TIMEOUT); |
279 | 279 | ||
280 | UART1_PutString("ok"); |
280 | UART1_PutString("ok"); |
281 | } |
281 | } |
282 | 282 | ||
283 | 283 | ||
284 | //------------------------------------------------------ |
284 | //------------------------------------------------------ |
285 | void SPI0_UpdateBuffer(void) |
285 | void SPI0_UpdateBuffer(void) |
286 | { |
286 | { |
287 | static u32 timeout = 0; |
287 | static u32 timeout = 0; |
288 | static u8 counter = 50,hott_index = 0, last_error_code = 0; |
288 | static u8 counter = 50,hott_index = 0, last_error_code = 0; |
289 | s16 tmp, last_wp_event = 0; |
289 | s16 tmp, last_wp_event = 0; |
290 | s32 i1,i2; |
290 | s32 i1,i2; |
291 | 291 | ||
292 | SPIWatchDog = 3500; // stop communication to FC after this timeout |
292 | SPIWatchDog = 3500; // stop communication to FC after this timeout |
293 | if(SPI_RxBuffer_Request) |
293 | if(SPI_RxBuffer_Request) |
294 | { |
294 | { |
295 | // avoid sending data via SPI during the update of the ToFlightCtrl structure |
295 | // avoid sending data via SPI during the update of the ToFlightCtrl structure |
296 | VIC_ITCmd(SSP0_ITLine, DISABLE); // disable SPI interrupt |
296 | VIC_ITCmd(SSP0_ITLine, DISABLE); // disable SPI interrupt |
297 | ToFlightCtrl.CompassHeading = Compass_Heading; |
297 | ToFlightCtrl.CompassHeading = Compass_Heading; |
298 | DebugOut.Analog[10] = ToFlightCtrl.CompassHeading; |
298 | DebugOut.Analog[10] = ToFlightCtrl.CompassHeading; |
299 | if(ToFlightCtrl.CompassHeading >= 0) ToFlightCtrl.CompassHeading = (360 + ToFlightCtrl.CompassHeading + FromFlightCtrl.GyroYaw / 12) % 360; |
299 | if(ToFlightCtrl.CompassHeading >= 0) ToFlightCtrl.CompassHeading = (360 + ToFlightCtrl.CompassHeading + FromFlightCtrl.GyroYaw / 12) % 360; |
300 | ToFlightCtrl.MagVecX = MagVector.X; |
300 | ToFlightCtrl.MagVecX = MagVector.X; |
301 | ToFlightCtrl.MagVecY = MagVector.Y; |
301 | ToFlightCtrl.MagVecY = MagVector.Y; |
302 | ToFlightCtrl.MagVecZ = MagVector.Z; |
302 | ToFlightCtrl.MagVecZ = MagVector.Z; |
303 | // ToFlightCtrl.NCStatus = 0; |
303 | // ToFlightCtrl.NCStatus = 0; |
304 | // cycle spi commands |
304 | // cycle spi commands |
305 | if(ErrorCode != last_error_code) ToFlightCtrl.Command = SPI_NCCMD_VERSION; |
305 | if(ErrorCode != last_error_code) ToFlightCtrl.Command = SPI_NCCMD_VERSION; |
306 | else |
306 | else |
307 | if(FC_WP_EventChannel != last_wp_event) ToFlightCtrl.Command = SPI_NCCMD_GPSINFO; |
307 | if(FC_WP_EventChannel != last_wp_event) ToFlightCtrl.Command = SPI_NCCMD_GPSINFO; |
308 | else |
308 | else |
309 | { |
309 | { |
310 | ToFlightCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
310 | ToFlightCtrl.Command = SPI_CommandSequence[SPI_CommandCounter++]; |
311 | // restart command cycle at the end |
311 | // restart command cycle at the end |
312 | if(SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
312 | if(SPI_CommandCounter >= sizeof(SPI_CommandSequence)) SPI_CommandCounter = 0; |
313 | } |
313 | } |
314 | last_error_code = ErrorCode; |
314 | last_error_code = ErrorCode; |
315 | last_wp_event = FC_WP_EventChannel; |
315 | last_wp_event = FC_WP_EventChannel; |
316 | 316 | ||
317 | #define FLAG_GPS_AID 0x01 |
317 | #define FLAG_GPS_AID 0x01 |
318 | switch (ToFlightCtrl.Command) |
318 | switch (ToFlightCtrl.Command) |
319 | { |
319 | { |
320 | case SPI_NCCMD_KALMAN: // wird am häufigsten betätigt |
320 | case SPI_NCCMD_KALMAN: // wird am häufigsten betätigt |
321 | ToFlightCtrl.Param.sByte[0] = (s8) Kalman_K; |
321 | ToFlightCtrl.Param.sByte[0] = (s8) Kalman_K; |
322 | ToFlightCtrl.Param.sByte[1] = (s8) Kalman_MaxFusion; |
322 | ToFlightCtrl.Param.sByte[1] = (s8) Kalman_MaxFusion; |
323 | ToFlightCtrl.Param.sByte[2] = (s8) Kalman_MaxDrift; |
323 | ToFlightCtrl.Param.sByte[2] = (s8) Kalman_MaxDrift; |
324 | ToFlightCtrl.Param.Byte[3] = (u8) Kalman_Kompass; |
324 | ToFlightCtrl.Param.Byte[3] = (u8) Kalman_Kompass; |
325 | ToFlightCtrl.Param.sByte[4] = (s8) ToFcGpsZ; |
325 | ToFlightCtrl.Param.sByte[4] = (s8) ToFcGpsZ; |
326 | ToFlightCtrl.Param.Byte[5] = (s8) ToFC_Rotate_C; |
326 | ToFlightCtrl.Param.Byte[5] = (s8) ToFC_Rotate_C; |
327 | ToFlightCtrl.Param.Byte[6] = (s8) ToFC_Rotate_S; |
327 | ToFlightCtrl.Param.Byte[6] = (s8) ToFC_Rotate_S; |
328 | ToFlightCtrl.Param.Byte[7] = GPS_Aid_StickMultiplikator; |
328 | ToFlightCtrl.Param.Byte[7] = GPS_Aid_StickMultiplikator; |
329 | if(CAM_Orientation.UpdateMask & CAM_UPDATE_AZIMUTH) |
329 | if(CAM_Orientation.UpdateMask & CAM_UPDATE_AZIMUTH) |
330 | { |
330 | { |
331 | ToFlightCtrl.Param.sInt[4] = CAM_Orientation.Azimuth; |
331 | ToFlightCtrl.Param.sInt[4] = CAM_Orientation.Azimuth; |
332 | CAM_Orientation.UpdateMask &= ~CAM_UPDATE_AZIMUTH; |
332 | CAM_Orientation.UpdateMask &= ~CAM_UPDATE_AZIMUTH; |
333 | } |
333 | } |
334 | else |
334 | else |
335 | { |
335 | { |
336 | ToFlightCtrl.Param.sInt[4] = -1; |
336 | ToFlightCtrl.Param.sInt[4] = -1; |
337 | } |
337 | } |
338 | 338 | ||
339 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_NEW_CAMERA_ELEVATION, &tmp)) // Elevation set via 'j' command |
339 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_NEW_CAMERA_ELEVATION, &tmp)) // Elevation set via 'j' command |
340 | { |
340 | { |
341 | POI_KameraNick = tmp; |
341 | POI_KameraNick = tmp; |
342 | } |
342 | } |
343 | else |
343 | else |
344 | { |
344 | { |
345 | //if(FC.StatusFlags2 & FC_STATUS2_CAREFREE) // only, if carefree is active |
345 | //if(FC.StatusFlags2 & FC_STATUS2_CAREFREE) // only, if carefree is active |
346 | POI_KameraNick = CAM_Orientation.Elevation; |
346 | POI_KameraNick = CAM_Orientation.Elevation; |
347 | //else ToFlightCtrl.Param.sInt[5] = 0; |
347 | //else ToFlightCtrl.Param.sInt[5] = 0; |
348 | } |
348 | } |
349 | ToFlightCtrl.Param.sInt[5] = POI_KameraNick; |
349 | ToFlightCtrl.Param.sInt[5] = POI_KameraNick; |
350 | break; |
350 | break; |
351 | 351 | ||
352 | case SPI_NCCMD_VERSION: |
352 | case SPI_NCCMD_VERSION: |
353 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
353 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
354 | //+ higher than the maximum allowed altitude |
354 | //+ higher than the maximum allowed altitude |
355 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
355 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
356 | ToFlightCtrl.Param.Byte[0] = VERSION_MAJOR; |
356 | ToFlightCtrl.Param.Byte[0] = VERSION_MAJOR; |
357 | ToFlightCtrl.Param.Byte[1] = VERSION_MINOR; |
357 | ToFlightCtrl.Param.Byte[1] = VERSION_MINOR; |
358 | ToFlightCtrl.Param.Byte[2] = VERSION_PATCH; |
358 | ToFlightCtrl.Param.Byte[2] = VERSION_PATCH; |
359 | ToFlightCtrl.Param.Byte[3] = FC_SPI_COMPATIBLE; |
359 | ToFlightCtrl.Param.Byte[3] = FC_SPI_COMPATIBLE; |
360 | ToFlightCtrl.Param.Byte[4] = Version_HW; |
360 | ToFlightCtrl.Param.Byte[4] = Version_HW; |
361 | ToFlightCtrl.Param.Byte[5] = DebugOut.StatusGreen; |
361 | ToFlightCtrl.Param.Byte[5] = DebugOut.StatusGreen; |
362 | ToFlightCtrl.Param.Byte[6] = DebugOut.StatusRed; |
362 | ToFlightCtrl.Param.Byte[6] = DebugOut.StatusRed; |
363 | ToFlightCtrl.Param.Byte[7] = ErrorCode; |
363 | ToFlightCtrl.Param.Byte[7] = ErrorCode; |
364 | ToFlightCtrl.Param.Byte[8] = NC_GPS_ModeCharacter; |
364 | ToFlightCtrl.Param.Byte[8] = NC_GPS_ModeCharacter; |
365 | ToFlightCtrl.Param.Byte[9] = SerialLinkOkay; |
365 | ToFlightCtrl.Param.Byte[9] = SerialLinkOkay; |
366 | ToFlightCtrl.Param.Byte[10] = NC_To_FC_Flags; |
366 | 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 |
367 | if(AbsoluteFlyingAltitude > 255) ToFlightCtrl.Param.Byte[11] = 0; // then the limitation of the FC doesn't work |
368 | else ToFlightCtrl.Param.Byte[11] = AbsoluteFlyingAltitude; |
368 | else ToFlightCtrl.Param.Byte[11] = AbsoluteFlyingAltitude; |
369 | break; |
369 | break; |
370 | case SPI_MISC: |
370 | case SPI_MISC: |
371 | ToFlightCtrl.Param.Byte[0] = EarthMagneticFieldFiltered/5; |
371 | ToFlightCtrl.Param.Byte[0] = EarthMagneticFieldFiltered/5; |
372 | ToFlightCtrl.Param.Byte[1] = EarthMagneticInclination; |
372 | ToFlightCtrl.Param.Byte[1] = EarthMagneticInclination; |
373 | ToFlightCtrl.Param.Byte[2] = EarthMagneticInclinationTheoretic; |
373 | ToFlightCtrl.Param.Byte[2] = EarthMagneticInclinationTheoretic; |
374 | ToFlightCtrl.Param.Byte[3] = SpeakHoTT; |
374 | ToFlightCtrl.Param.Byte[3] = SpeakHoTT; |
375 | ToFlightCtrl.Param.Byte[4] = NaviData.WaypointIndex; // index of current waypoints running from 0 to WaypointNumber-1 |
375 | 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 |
376 | ToFlightCtrl.Param.Byte[5] = NaviData.WaypointNumber; // number of stored waypoints |
377 | ToFlightCtrl.Param.Int[3] = NaviData.TargetPositionDeviation.Distance / 10; |
377 | 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 |
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 |
379 | ToFlightCtrl.Param.Byte[9] = 0; |
379 | ToFlightCtrl.Param.Byte[9] = 0; |
380 | ToFlightCtrl.Param.Byte[10] = 0; |
380 | ToFlightCtrl.Param.Byte[10] = 0; |
381 | ToFlightCtrl.Param.Byte[11] = 0; |
381 | ToFlightCtrl.Param.Byte[11] = 0; |
382 | //DebugOut.Analog[16] = SpeakHoTT; |
382 | //DebugOut.Analog[16] = SpeakHoTT; |
383 | SpeakHoTT = 0; |
383 | SpeakHoTT = 0; |
384 | break; |
384 | break; |
385 | 385 | ||
386 | case SPI_NCCMD_GPSINFO: |
386 | case SPI_NCCMD_GPSINFO: |
387 | ToFlightCtrl.Param.Byte[0] = GPSData.Flags; |
387 | ToFlightCtrl.Param.Byte[0] = GPSData.Flags; |
388 | ToFlightCtrl.Param.Byte[1] = GPSData.NumOfSats; |
388 | ToFlightCtrl.Param.Byte[1] = GPSData.NumOfSats; |
389 | ToFlightCtrl.Param.Byte[2] = GPSData.SatFix; |
389 | ToFlightCtrl.Param.Byte[2] = GPSData.SatFix; |
390 | ToFlightCtrl.Param.Byte[3] = GPSData.Speed_Ground / 100; // m/s |
390 | ToFlightCtrl.Param.Byte[3] = GPSData.Speed_Ground / 100; // m/s |
391 | ToFlightCtrl.Param.Int[2] = NaviData.HomePositionDeviation.Distance; // dm //4&5 |
391 | ToFlightCtrl.Param.Int[2] = NaviData.HomePositionDeviation.Distance; // dm //4&5 |
392 | ToFlightCtrl.Param.sInt[3] = NaviData.HomePositionDeviation.Bearing; // deg //6&7 |
392 | ToFlightCtrl.Param.sInt[3] = NaviData.HomePositionDeviation.Bearing; // deg //6&7 |
393 | if(FC_WP_EventChannel > 254) FC_WP_EventChannel = 254; |
393 | 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 |
|
394 | ToFlightCtrl.Param.Byte[8] = (s8)(FC_WP_EventChannel - 127); |
395 | ToFlightCtrl.Param.Byte[8] = (s8)(FC_WP_EventChannel - 127); |
395 | FC_WP_EventChannel = 0; // the GPS-Routine will set it again |
396 | FC_WP_EventChannel = 0; // the GPS-Routine will set it again |
396 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_RATE, &tmp)) |
397 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_RATE, &tmp)) |
397 | { |
398 | { |
398 | ToFlightCtrl.Param.Byte[9] = (u8)tmp; |
399 | ToFlightCtrl.Param.Byte[9] = (u8)tmp; |
399 | } |
400 | } |
400 | else |
401 | else |
401 | { |
402 | { |
402 | ToFlightCtrl.Param.Byte[9] = (u8)ToFC_AltitudeRate; |
403 | ToFlightCtrl.Param.Byte[9] = (u8)ToFC_AltitudeRate; |
403 | } |
404 | } |
404 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_SETPOINT, &tmp)) |
405 | if(NCRARAM_STATE_VALID == NCParams_GetValue(NCPARAMS_ALTITUDE_SETPOINT, &tmp)) |
405 | { |
406 | { |
406 | ToFlightCtrl.Param.sInt[5] = tmp; |
407 | ToFlightCtrl.Param.sInt[5] = tmp; |
407 | } |
408 | } |
408 | else |
409 | else |
409 | { |
410 | { |
410 | ToFlightCtrl.Param.sInt[5] = (s16)ToFC_AltitudeSetpoint; |
411 | ToFlightCtrl.Param.sInt[5] = (s16)ToFC_AltitudeSetpoint; |
411 | } |
412 | } |
412 | break; |
413 | break; |
413 | case SPI_NCCMD_HOTT_INFO: |
414 | case SPI_NCCMD_HOTT_INFO: |
414 | switch(hott_index++) |
415 | switch(hott_index++) |
415 | { |
416 | { |
416 | case 0: |
417 | case 0: |
417 | //Dezimalgrad --> Grad mit Dezimalminuten --> Grad, Minuten, Sekunden |
418 | //Dezimalgrad --> Grad mit Dezimalminuten --> Grad, Minuten, Sekunden |
418 | //53.285788 7.4847269 --> N53° 17.14728 E7° 29.08362 --> N53° 17' 8.837" E7° 29' 5.017" |
419 | //53.285788 7.4847269 --> N53° 17.14728 E7° 29.08362 --> N53° 17' 8.837" E7° 29' 5.017" |
419 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
420 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
420 | ToFlightCtrl.Param.Byte[0] = 3+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
421 | ToFlightCtrl.Param.Byte[0] = 3+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
421 | ToFlightCtrl.Param.Byte[1] = 9-1; // how many |
422 | ToFlightCtrl.Param.Byte[1] = 9-1; // how many |
422 | //----------------------------- |
423 | //----------------------------- |
423 | ToFlightCtrl.Param.Byte[2] = FromFlightCtrl.GyroHeading / 20;//NaviData.HomePositionDeviation.Bearing / 2; |
424 | ToFlightCtrl.Param.Byte[2] = FromFlightCtrl.GyroHeading / 20;//NaviData.HomePositionDeviation.Bearing / 2; |
424 | i1 = GPSData.Speed_Ground; // in cm/sec |
425 | i1 = GPSData.Speed_Ground; // in cm/sec |
425 | i1 *= 36; |
426 | i1 *= 36; |
426 | i1 /= 1000; |
427 | i1 /= 1000; |
427 | ToFlightCtrl.Param.Byte[3] = i1 % 256; |
428 | ToFlightCtrl.Param.Byte[3] = i1 % 256; |
428 | ToFlightCtrl.Param.Byte[4] = i1 / 256; |
429 | ToFlightCtrl.Param.Byte[4] = i1 / 256; |
429 | //----------------------------- |
430 | //----------------------------- |
430 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 1; // 1 = S |
431 | if(GPSData.Position.Latitude < 0) ToFlightCtrl.Param.Byte[5] = 1; // 1 = S |
431 | else ToFlightCtrl.Param.Byte[5] = 0; // 1 = S |
432 | else ToFlightCtrl.Param.Byte[5] = 0; // 1 = S |
432 | i1 = abs(GPSData.Position.Latitude)/10000000L; |
433 | i1 = abs(GPSData.Position.Latitude)/10000000L; |
433 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
434 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
434 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
435 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
435 | i1 *= 100; |
436 | i1 *= 100; |
436 | i1 += i2 / 100000; |
437 | i1 += i2 / 100000; |
437 | i2 = i2 % 100000; |
438 | i2 = i2 % 100000; |
438 | i2 /= 10; |
439 | i2 /= 10; |
439 | ToFlightCtrl.Param.Byte[6] = i1 % 256; |
440 | ToFlightCtrl.Param.Byte[6] = i1 % 256; |
440 | ToFlightCtrl.Param.Byte[7] = i1 / 256; |
441 | ToFlightCtrl.Param.Byte[7] = i1 / 256; |
441 | ToFlightCtrl.Param.Byte[8] = i2 % 256; |
442 | ToFlightCtrl.Param.Byte[8] = i2 % 256; |
442 | ToFlightCtrl.Param.Byte[9] = i2 / 256; |
443 | ToFlightCtrl.Param.Byte[9] = i2 / 256; |
443 | break; |
444 | break; |
444 | case 1: |
445 | case 1: |
445 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
446 | ToFlightCtrl.Param.Byte[11] = HOTT_GPS_PACKET_ID; |
446 | ToFlightCtrl.Param.Byte[0] = 11+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
447 | ToFlightCtrl.Param.Byte[0] = 11+3; // index +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
447 | ToFlightCtrl.Param.Byte[1] = 8-1; // how many |
448 | ToFlightCtrl.Param.Byte[1] = 8-1; // how many |
448 | //----------------------------- |
449 | //----------------------------- |
449 | if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2] = 1; // 1 = E |
450 | if(GPSData.Position.Longitude < 0) ToFlightCtrl.Param.Byte[2] = 1; // 1 = E |
450 | else ToFlightCtrl.Param.Byte[2] = 0; // 1 = S |
451 | else ToFlightCtrl.Param.Byte[2] = 0; // 1 = S |
451 | i1 = abs(GPSData.Position.Longitude)/10000000L; |
452 | i1 = abs(GPSData.Position.Longitude)/10000000L; |
452 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
453 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
453 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
454 | if(!(NCFlags & NC_FLAG_GPS_OK)) {i1 = 0; i2 = 0;} |
454 | i1 *= 100; |
455 | i1 *= 100; |
455 | i1 += i2 / 100000; |
456 | i1 += i2 / 100000; |
456 | i2 = i2 % 100000; |
457 | i2 = i2 % 100000; |
457 | i2 /= 10; |
458 | i2 /= 10; |
458 | ToFlightCtrl.Param.Byte[3] = i1 % 256; |
459 | ToFlightCtrl.Param.Byte[3] = i1 % 256; |
459 | ToFlightCtrl.Param.Byte[4] = i1 / 256; |
460 | ToFlightCtrl.Param.Byte[4] = i1 / 256; |
460 | ToFlightCtrl.Param.Byte[5] = i2 % 256; |
461 | ToFlightCtrl.Param.Byte[5] = i2 % 256; |
461 | ToFlightCtrl.Param.Byte[6] = i2 / 256; |
462 | ToFlightCtrl.Param.Byte[6] = i2 / 256; |
462 | //----------------------------- |
463 | //----------------------------- |
463 | i1 = NaviData.HomePositionDeviation.Distance / 10; // dann in m |
464 | i1 = NaviData.HomePositionDeviation.Distance / 10; // dann in m |
464 | ToFlightCtrl.Param.Byte[7] = i1 % 256; |
465 | ToFlightCtrl.Param.Byte[7] = i1 % 256; |
465 | ToFlightCtrl.Param.Byte[8] = i1 / 256; |
466 | ToFlightCtrl.Param.Byte[8] = i1 / 256; |
466 | break; |
467 | break; |
467 | case 2: |
468 | case 2: |
468 | ToFlightCtrl.Param.Byte[11] = HOTT_GENERAL_PACKET_ID; |
469 | ToFlightCtrl.Param.Byte[11] = HOTT_GENERAL_PACKET_ID; |
469 | ToFlightCtrl.Param.Byte[0] = 5+3; // index // +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
470 | ToFlightCtrl.Param.Byte[0] = 5+3; // index // +3, weil bei HoTT V4 3 Bytes eingeschoben wurden |
470 | ToFlightCtrl.Param.Byte[1] = 2; // how many |
471 | ToFlightCtrl.Param.Byte[1] = 2; // how many |
471 | ToFlightCtrl.Param.Byte[2] = EarthMagneticField / (5 * 2); |
472 | ToFlightCtrl.Param.Byte[2] = EarthMagneticField / (5 * 2); |
472 | ToFlightCtrl.Param.Byte[3] = EarthMagneticInclination / 2; |
473 | ToFlightCtrl.Param.Byte[3] = EarthMagneticInclination / 2; |
473 | hott_index = 0; |
474 | hott_index = 0; |
474 | break; |
475 | break; |
475 | default: |
476 | default: |
476 | ToFlightCtrl.Param.Byte[0] = 255; |
477 | ToFlightCtrl.Param.Byte[0] = 255; |
477 | hott_index = 0; |
478 | hott_index = 0; |
478 | break; |
479 | break; |
479 | } |
480 | } |
480 | break; |
481 | break; |
481 | default: |
482 | default: |
482 | break; |
483 | break; |
483 | // 0 = 0,1 |
484 | // 0 = 0,1 |
484 | // 1 = 2,3 |
485 | // 1 = 2,3 |
485 | // 2 = 4,5 |
486 | // 2 = 4,5 |
486 | // 3 = 6,7 |
487 | // 3 = 6,7 |
487 | // 4 = 8,9 |
488 | // 4 = 8,9 |
488 | // 5 = 10,11 |
489 | // 5 = 10,11 |
489 | } |
490 | } |
490 | VIC_ITCmd(SSP0_ITLine, ENABLE); // enable SPI interrupt |
491 | VIC_ITCmd(SSP0_ITLine, ENABLE); // enable SPI interrupt |
491 | switch(FromFlightCtrl.Command) |
492 | switch(FromFlightCtrl.Command) |
492 | { |
493 | { |
493 | case SPI_FCCMD_USER: |
494 | case SPI_FCCMD_USER: |
494 | Parameter.User1 = FromFlightCtrl.Param.Byte[0]; |
495 | Parameter.User1 = FromFlightCtrl.Param.Byte[0]; |
495 | Parameter.User2 = FromFlightCtrl.Param.Byte[1]; |
496 | Parameter.User2 = FromFlightCtrl.Param.Byte[1]; |
496 | Parameter.User3 = FromFlightCtrl.Param.Byte[2]; |
497 | Parameter.User3 = FromFlightCtrl.Param.Byte[2]; |
497 | Parameter.User4 = FromFlightCtrl.Param.Byte[3]; |
498 | Parameter.User4 = FromFlightCtrl.Param.Byte[3]; |
498 | Parameter.User5 = FromFlightCtrl.Param.Byte[4]; |
499 | Parameter.User5 = FromFlightCtrl.Param.Byte[4]; |
499 | Parameter.User6 = FromFlightCtrl.Param.Byte[5]; |
500 | Parameter.User6 = FromFlightCtrl.Param.Byte[5]; |
500 | Parameter.User7 = FromFlightCtrl.Param.Byte[6]; |
501 | Parameter.User7 = FromFlightCtrl.Param.Byte[6]; |
501 | Parameter.User8 = FromFlightCtrl.Param.Byte[7]; |
502 | Parameter.User8 = FromFlightCtrl.Param.Byte[7]; |
502 | if(ClearFCStatusFlags) |
503 | if(ClearFCStatusFlags) |
503 | { |
504 | { |
504 | FC.StatusFlags = 0; |
505 | FC.StatusFlags = 0; |
505 | ClearFCStatusFlags = 0; |
506 | ClearFCStatusFlags = 0; |
506 | } |
507 | } |
507 | FC.StatusFlags |= FromFlightCtrl.Param.Byte[8]; |
508 | FC.StatusFlags |= FromFlightCtrl.Param.Byte[8]; |
508 | if(FC.StatusFlags & FC_STATUS_CALIBRATE && !FCCalibActive) |
509 | if(FC.StatusFlags & FC_STATUS_CALIBRATE && !FCCalibActive) |
509 | { |
510 | { |
510 | HeadFreeStartAngle = Compass_Heading * 10; |
511 | HeadFreeStartAngle = Compass_Heading * 10; |
511 | Compass_Init(); |
512 | Compass_Init(); |
512 | FCCalibActive = 10; |
513 | FCCalibActive = 10; |
513 | FC_is_Calibrated = 0; |
514 | FC_is_Calibrated = 0; |
514 | } |
515 | } |
515 | else |
516 | else |
516 | { |
517 | { |
517 | if(FCCalibActive) if(--FCCalibActive == 0) FC_is_Calibrated = 1; |
518 | if(FCCalibActive) if(--FCCalibActive == 0) FC_is_Calibrated = 1; |
518 | } |
519 | } |
519 | if(FC.StatusFlags & FC_STATUS_START) |
520 | if(FC.StatusFlags & FC_STATUS_START) |
520 | { |
521 | { |
521 | if(Compass_Heading != -1) HeadFreeStartAngle = Compass_Heading * 10; else |
522 | if(Compass_Heading != -1) HeadFreeStartAngle = Compass_Heading * 10; else |
522 | HeadFreeStartAngle = FromFlightCtrl.GyroHeading; |
523 | HeadFreeStartAngle = FromFlightCtrl.GyroHeading; |
523 | } |
524 | } |
524 | 525 | ||
525 | if((Parameter.ExtraConfig & CFG_TEACHABLE_CAREFREE)) |
526 | if((Parameter.ExtraConfig & CFG_TEACHABLE_CAREFREE)) |
526 | { |
527 | { |
527 | if(!(FC.StatusFlags2 & FC_STATUS2_CAREFREE)) // CF ist jetzt ausgeschaltet -> neue Richtung lernen |
528 | if(!(FC.StatusFlags2 & FC_STATUS2_CAREFREE)) // CF ist jetzt ausgeschaltet -> neue Richtung lernen |
528 | { |
529 | { |
529 | if((NaviData.HomePositionDeviation.Distance > 200) && (NCFlags & NC_FLAG_GPS_OK)) // nur bei ausreichender Distance -> 20m |
530 | if((NaviData.HomePositionDeviation.Distance > 200) && (NCFlags & NC_FLAG_GPS_OK)) // nur bei ausreichender Distance -> 20m |
530 | { |
531 | { |
531 | HeadFreeStartAngle = (10 * NaviData.HomePositionDeviation.Bearing + 1800 + 3600 - Parameter.OrientationAngle * 150) % 3600; // in 0.1° |
532 | HeadFreeStartAngle = (10 * NaviData.HomePositionDeviation.Bearing + 1800 + 3600 - Parameter.OrientationAngle * 150) % 3600; // in 0.1° |
532 | } |
533 | } |
533 | else // Ansonsten die aktuelle Richtung übernehmen |
534 | else // Ansonsten die aktuelle Richtung übernehmen |
534 | HeadFreeStartAngle = (3600 + FromFlightCtrl.GyroHeading /*+ Parameter.OrientationAngle * 150*/) % 3600; // in 0.1° |
535 | HeadFreeStartAngle = (3600 + FromFlightCtrl.GyroHeading /*+ Parameter.OrientationAngle * 150*/) % 3600; // in 0.1° |
535 | } |
536 | } |
536 | } |
537 | } |
537 | 538 | ||
538 | Parameter.ActiveSetting = FromFlightCtrl.Param.Byte[9]; |
539 | Parameter.ActiveSetting = FromFlightCtrl.Param.Byte[9]; |
539 | DebugOut.Analog[5] = FC.StatusFlags; |
540 | DebugOut.Analog[5] = FC.StatusFlags; |
540 | NaviData.FCStatusFlags = FC.StatusFlags; |
541 | NaviData.FCStatusFlags = FC.StatusFlags; |
541 | FC.StatusFlags2 = FromFlightCtrl.Param.Byte[11]; |
542 | FC.StatusFlags2 = FromFlightCtrl.Param.Byte[11]; |
542 | NaviData.FCStatusFlags2 = (NaviData.FCStatusFlags2 & (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE)) | (FC.StatusFlags2 & (0xff - (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE))); |
543 | NaviData.FCStatusFlags2 = (NaviData.FCStatusFlags2 & (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE)) | (FC.StatusFlags2 & (0xff - (FC_STATUS2_OUT1_ACTIVE | FC_STATUS2_OUT2_ACTIVE))); |
543 | 544 | ||
544 | if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT1_ACTIVE; |
545 | if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT1_ACTIVE; |
545 | else |
546 | else |
546 | if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE; |
547 | if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE; |
547 | 548 | ||
548 | if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT2_ACTIVE; |
549 | if((!(LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && (FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 |= FC_STATUS2_OUT2_ACTIVE; |
549 | else |
550 | else |
550 | if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE; |
551 | if(((LastTransmittedFCStatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) && !(FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) NaviData.FCStatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE; |
551 | 552 | ||
552 | Logging_FCStatusFlags1 |= FC.StatusFlags; |
553 | Logging_FCStatusFlags1 |= FC.StatusFlags; |
553 | Logging_FCStatusFlags2 |= FC.StatusFlags2; |
554 | Logging_FCStatusFlags2 |= FC.StatusFlags2; |
554 | Parameter.ComingHomeAltitude = FromFlightCtrl.Param.Byte[10]; |
555 | Parameter.ComingHomeAltitude = FromFlightCtrl.Param.Byte[10]; |
555 | break; |
556 | break; |
556 | 557 | ||
557 | case SPI_FCCMD_ACCU: |
558 | case SPI_FCCMD_ACCU: |
558 | FC.BAT_Current = FromFlightCtrl.Param.Int[0]; |
559 | FC.BAT_Current = FromFlightCtrl.Param.Int[0]; |
559 | FC.BAT_UsedCapacity = FromFlightCtrl.Param.Int[1]; |
560 | FC.BAT_UsedCapacity = FromFlightCtrl.Param.Int[1]; |
560 | FC.BAT_Voltage = FromFlightCtrl.Param.Byte[4]; |
561 | FC.BAT_Voltage = FromFlightCtrl.Param.Byte[4]; |
561 | Parameter.LowVoltageWarning = FromFlightCtrl.Param.Byte[5]; |
562 | Parameter.LowVoltageWarning = FromFlightCtrl.Param.Byte[5]; |
562 | FromFC_VarioCharacter = FromFlightCtrl.Param.Byte[6]; |
563 | FromFC_VarioCharacter = FromFlightCtrl.Param.Byte[6]; |
563 | Motor[FromFlightCtrl.Param.Byte[7]].MaxPWM = FromFlightCtrl.Param.Byte[8]; |
564 | Motor[FromFlightCtrl.Param.Byte[7]].MaxPWM = FromFlightCtrl.Param.Byte[8]; |
564 | Motor[FromFlightCtrl.Param.Byte[7]].State = FromFlightCtrl.Param.Byte[9]; |
565 | Motor[FromFlightCtrl.Param.Byte[7]].State = FromFlightCtrl.Param.Byte[9]; |
565 | Motor[FromFlightCtrl.Param.Byte[7]].Temperature = FromFlightCtrl.Param.Byte[10]; |
566 | Motor[FromFlightCtrl.Param.Byte[7]].Temperature = FromFlightCtrl.Param.Byte[10]; |
566 | Motor[FromFlightCtrl.Param.Byte[7]].Current = FromFlightCtrl.Param.Byte[11]; |
567 | Motor[FromFlightCtrl.Param.Byte[7]].Current = FromFlightCtrl.Param.Byte[11]; |
567 | if(FromFC_VarioCharacter == '+' || FromFC_VarioCharacter == '-') // manual setpoint clears the NC-Parameter command |
568 | if(FromFC_VarioCharacter == '+' || FromFC_VarioCharacter == '-') // manual setpoint clears the NC-Parameter command |
568 | { |
569 | { |
569 | NCParams_ClearValue(NCPARAMS_ALTITUDE_RATE); |
570 | NCParams_ClearValue(NCPARAMS_ALTITUDE_RATE); |
570 | } |
571 | } |
571 | NaviData.UBat = FC.BAT_Voltage; |
572 | NaviData.UBat = FC.BAT_Voltage; |
572 | NaviData.Current = FC.BAT_Current; |
573 | NaviData.Current = FC.BAT_Current; |
573 | NaviData.UsedCapacity = FC.BAT_UsedCapacity; |
574 | NaviData.UsedCapacity = FC.BAT_UsedCapacity; |
574 | break; |
575 | break; |
575 | 576 | ||
576 | #define CHK_POTI(b,a) { if(a < 248) b = a; else b = FC.Poti[255 - a]; } |
577 | #define CHK_POTI(b,a) { if(a < 248) b = a; else b = FC.Poti[255 - a]; } |
577 | #define CHK_POTI_MM(b,a,min,max) {CHK_POTI(b,a); LIMIT_MIN_MAX(b, min, max); } |
578 | #define CHK_POTI_MM(b,a,min,max) {CHK_POTI(b,a); LIMIT_MIN_MAX(b, min, max); } |
578 | 579 | ||
579 | case SPI_FCCMD_PARAMETER1: |
580 | case SPI_FCCMD_PARAMETER1: |
580 | CHK_POTI_MM(Parameter.NaviGpsModeControl,FromFlightCtrl.Param.Byte[0],0,255); |
581 | CHK_POTI_MM(Parameter.NaviGpsModeControl,FromFlightCtrl.Param.Byte[0],0,255); |
581 | CHK_POTI_MM(Parameter.NaviGpsGain,FromFlightCtrl.Param.Byte[1],0,255); |
582 | CHK_POTI_MM(Parameter.NaviGpsGain,FromFlightCtrl.Param.Byte[1],0,255); |
582 | CHK_POTI_MM(Parameter.NaviGpsP,FromFlightCtrl.Param.Byte[2],0,255); |
583 | CHK_POTI_MM(Parameter.NaviGpsP,FromFlightCtrl.Param.Byte[2],0,255); |
583 | CHK_POTI_MM(Parameter.NaviGpsI,FromFlightCtrl.Param.Byte[3],0,255); |
584 | CHK_POTI_MM(Parameter.NaviGpsI,FromFlightCtrl.Param.Byte[3],0,255); |
584 | CHK_POTI_MM(Parameter.NaviGpsD,FromFlightCtrl.Param.Byte[4],0,255); |
585 | CHK_POTI_MM(Parameter.NaviGpsD,FromFlightCtrl.Param.Byte[4],0,255); |
585 | CHK_POTI_MM(Parameter.NaviGpsACC,FromFlightCtrl.Param.Byte[5],0,255); |
586 | CHK_POTI_MM(Parameter.NaviGpsACC,FromFlightCtrl.Param.Byte[5],0,255); |
586 | Parameter.NaviGpsMinSat = FromFlightCtrl.Param.Byte[6]; |
587 | Parameter.NaviGpsMinSat = FromFlightCtrl.Param.Byte[6]; |
587 | Parameter.NaviStickThreshold = FromFlightCtrl.Param.Byte[7]; |
588 | Parameter.NaviStickThreshold = FromFlightCtrl.Param.Byte[7]; |
588 | CHK_POTI_MM(Parameter.NaviOperatingRadius,FromFlightCtrl.Param.Byte[8],0,255); |
589 | CHK_POTI_MM(Parameter.NaviOperatingRadius,FromFlightCtrl.Param.Byte[8],0,255); |
589 | CHK_POTI_MM(Parameter.NaviWindCorrection,FromFlightCtrl.Param.Byte[9],0,255); |
590 | CHK_POTI_MM(Parameter.NaviWindCorrection,FromFlightCtrl.Param.Byte[9],0,255); |
590 | CHK_POTI_MM(Parameter.NaviAccCompensation,FromFlightCtrl.Param.Byte[10],0,255); |
591 | CHK_POTI_MM(Parameter.NaviAccCompensation,FromFlightCtrl.Param.Byte[10],0,255); |
591 | CHK_POTI_MM(Parameter.NaviAngleLimitation,FromFlightCtrl.Param.Byte[11],0,255); |
592 | CHK_POTI_MM(Parameter.NaviAngleLimitation,FromFlightCtrl.Param.Byte[11],0,255); |
592 | break; |
593 | break; |
593 | case SPI_FCCMD_PARAMETER2: |
594 | case SPI_FCCMD_PARAMETER2: |
594 | CHK_POTI_MM(Parameter.NaviOut1Parameter,FromFlightCtrl.Param.Byte[0],0,255); |
595 | CHK_POTI_MM(Parameter.NaviOut1Parameter,FromFlightCtrl.Param.Byte[0],0,255); |
595 | break; |
596 | break; |
596 | case SPI_FCCMD_STICK: |
597 | case SPI_FCCMD_STICK: |
597 | FC.StickGas = FromFlightCtrl.Param.sByte[0]; |
598 | FC.StickGas = FromFlightCtrl.Param.sByte[0]; |
598 | FC.StickYaw = FromFlightCtrl.Param.sByte[1]; |
599 | FC.StickYaw = FromFlightCtrl.Param.sByte[1]; |
599 | FC.StickRoll = FromFlightCtrl.Param.sByte[2]; |
600 | FC.StickRoll = FromFlightCtrl.Param.sByte[2]; |
600 | FC.StickNick = FromFlightCtrl.Param.sByte[3]; |
601 | FC.StickNick = FromFlightCtrl.Param.sByte[3]; |
601 | FC.Poti[0] = FromFlightCtrl.Param.Byte[4]; |
602 | FC.Poti[0] = FromFlightCtrl.Param.Byte[4]; |
602 | FC.Poti[1] = FromFlightCtrl.Param.Byte[5]; |
603 | FC.Poti[1] = FromFlightCtrl.Param.Byte[5]; |
603 | FC.Poti[2] = FromFlightCtrl.Param.Byte[6]; |
604 | FC.Poti[2] = FromFlightCtrl.Param.Byte[6]; |
604 | FC.Poti[3] = FromFlightCtrl.Param.Byte[7]; |
605 | FC.Poti[3] = FromFlightCtrl.Param.Byte[7]; |
605 | FC.Poti[4] = FromFlightCtrl.Param.Byte[8]; |
606 | FC.Poti[4] = FromFlightCtrl.Param.Byte[8]; |
606 | FC.Poti[5] = FromFlightCtrl.Param.Byte[9]; |
607 | FC.Poti[5] = FromFlightCtrl.Param.Byte[9]; |
607 | FC.Poti[6] = FromFlightCtrl.Param.Byte[10]; |
608 | FC.Poti[6] = FromFlightCtrl.Param.Byte[10]; |
608 | FC.Poti[7] = FromFlightCtrl.Param.Byte[11]; |
609 | FC.Poti[7] = FromFlightCtrl.Param.Byte[11]; |
609 | break; |
610 | break; |
610 | 611 | ||
611 | case SPI_FCCMD_MISC: |
612 | case SPI_FCCMD_MISC: |
612 | if(CompassCalState != FromFlightCtrl.Param.Byte[0]) |
613 | if(CompassCalState != FromFlightCtrl.Param.Byte[0]) |
613 | { // put only new CompassCalState into queue to send via I2C |
614 | { // put only new CompassCalState into queue to send via I2C |
614 | // if(FromFlightCtrl.Param.Byte[0] == CompassCalState+1 || FromFlightCtrl.Param.Byte[0] == 0) |
615 | // if(FromFlightCtrl.Param.Byte[0] == CompassCalState+1 || FromFlightCtrl.Param.Byte[0] == 0) |
615 | { |
616 | { |
616 | CompassCalState = FromFlightCtrl.Param.Byte[0]; |
617 | CompassCalState = FromFlightCtrl.Param.Byte[0]; |
617 | Compass_SetCalState(CompassCalState); |
618 | Compass_SetCalState(CompassCalState); |
618 | } |
619 | } |
619 | // else CompassCalState = 0; |
620 | // else CompassCalState = 0; |
620 | } |
621 | } |
621 | Parameter.NaviPH_LoginTime = FromFlightCtrl.Param.Byte[1]; |
622 | Parameter.NaviPH_LoginTime = FromFlightCtrl.Param.Byte[1]; |
622 | NaviData.Variometer = (NaviData.Variometer + 2 * (FromFlightCtrl.Param.sInt[1] - NaviData.Altimeter)) / 2; // provisorisch |
623 | NaviData.Variometer = (NaviData.Variometer + 2 * (FromFlightCtrl.Param.sInt[1] - NaviData.Altimeter)) / 2; // provisorisch |
623 | NaviData.Altimeter = FromFlightCtrl.Param.sInt[1]; // in 5cm |
624 | NaviData.Altimeter = FromFlightCtrl.Param.sInt[1]; // in 5cm |
624 | NaviData.SetpointAltitude = FromFlightCtrl.Param.sInt[2]; // in 5cm |
625 | NaviData.SetpointAltitude = FromFlightCtrl.Param.sInt[2]; // in 5cm |
625 | CHK_POTI_MM(Parameter.NaviGpsPLimit,FromFlightCtrl.Param.Byte[6],0,255); |
626 | CHK_POTI_MM(Parameter.NaviGpsPLimit,FromFlightCtrl.Param.Byte[6],0,255); |
626 | CHK_POTI_MM(Parameter.NaviGpsILimit,FromFlightCtrl.Param.Byte[7],0,255); |
627 | CHK_POTI_MM(Parameter.NaviGpsILimit,FromFlightCtrl.Param.Byte[7],0,255); |
627 | CHK_POTI_MM(Parameter.NaviGpsDLimit,FromFlightCtrl.Param.Byte[8],0,255); |
628 | CHK_POTI_MM(Parameter.NaviGpsDLimit,FromFlightCtrl.Param.Byte[8],0,255); |
628 | FC.RC_Quality = FromFlightCtrl.Param.Byte[9]; |
629 | FC.RC_Quality = FromFlightCtrl.Param.Byte[9]; |
629 | FC.RC_RSSI = FromFlightCtrl.Param.Byte[10]; |
630 | FC.RC_RSSI = FromFlightCtrl.Param.Byte[10]; |
630 | if(!FC.RC_RSSI) NaviData.RC_Quality = FC.RC_Quality; else NaviData.RC_Quality = FC.RC_RSSI; |
631 | if(!FC.RC_RSSI) NaviData.RC_Quality = FC.RC_Quality; else NaviData.RC_Quality = FC.RC_RSSI; |
631 | // NaviData.RC_RSSI = FC.RC_RSSI; |
632 | // NaviData.RC_RSSI = FC.RC_RSSI; |
632 | NaviData.Gas = (FC.BAT_Voltage * (u32) FromFlightCtrl.Param.Byte[11]) / (u32) Parameter.LowVoltageWarning; |
633 | NaviData.Gas = (FC.BAT_Voltage * (u32) FromFlightCtrl.Param.Byte[11]) / (u32) Parameter.LowVoltageWarning; |
633 | break; |
634 | break; |
634 | 635 | ||
635 | case SPI_FCCMD_SERVOS: |
636 | case SPI_FCCMD_SERVOS: |
636 | ServoParams.Refresh = FromFlightCtrl.Param.Byte[0]; |
637 | ServoParams.Refresh = FromFlightCtrl.Param.Byte[0]; |
637 | ServoParams.CompInvert = FromFlightCtrl.Param.Byte[1]; |
638 | ServoParams.CompInvert = FromFlightCtrl.Param.Byte[1]; |
638 | ServoParams.NickControl = FromFlightCtrl.Param.Byte[2]; |
639 | ServoParams.NickControl = FromFlightCtrl.Param.Byte[2]; |
639 | ServoParams.NickComp = FromFlightCtrl.Param.Byte[3]; |
640 | ServoParams.NickComp = FromFlightCtrl.Param.Byte[3]; |
640 | ServoParams.NickMin = FromFlightCtrl.Param.Byte[4]; |
641 | ServoParams.NickMin = FromFlightCtrl.Param.Byte[4]; |
641 | ServoParams.NickMax = FromFlightCtrl.Param.Byte[5]; |
642 | ServoParams.NickMax = FromFlightCtrl.Param.Byte[5]; |
642 | ServoParams.RollControl = FromFlightCtrl.Param.Byte[6]; |
643 | ServoParams.RollControl = FromFlightCtrl.Param.Byte[6]; |
643 | ServoParams.RollComp = FromFlightCtrl.Param.Byte[7]; |
644 | ServoParams.RollComp = FromFlightCtrl.Param.Byte[7]; |
644 | ServoParams.RollMin = FromFlightCtrl.Param.Byte[8]; |
645 | ServoParams.RollMin = FromFlightCtrl.Param.Byte[8]; |
645 | ServoParams.RollMax = FromFlightCtrl.Param.Byte[9]; |
646 | ServoParams.RollMax = FromFlightCtrl.Param.Byte[9]; |
646 | BL_MinOfMaxPWM = FromFlightCtrl.Param.Byte[10]; |
647 | BL_MinOfMaxPWM = FromFlightCtrl.Param.Byte[10]; |
647 | FC_I2C_ErrorConter = FromFlightCtrl.Param.Byte[11]; |
648 | FC_I2C_ErrorConter = FromFlightCtrl.Param.Byte[11]; |
648 | break; |
649 | break; |
649 | 650 | ||
650 | case SPI_FCCMD_VERSION: |
651 | case SPI_FCCMD_VERSION: |
651 | FC_Version.Major = FromFlightCtrl.Param.Byte[0]; |
652 | FC_Version.Major = FromFlightCtrl.Param.Byte[0]; |
652 | FC_Version.Minor = FromFlightCtrl.Param.Byte[1]; |
653 | FC_Version.Minor = FromFlightCtrl.Param.Byte[1]; |
653 | FC_Version.Patch = FromFlightCtrl.Param.Byte[2]; |
654 | FC_Version.Patch = FromFlightCtrl.Param.Byte[2]; |
654 | FC_Version.Compatible = FromFlightCtrl.Param.Byte[3]; |
655 | FC_Version.Compatible = FromFlightCtrl.Param.Byte[3]; |
655 | FC_Version.Hardware = FromFlightCtrl.Param.Byte[4]; |
656 | FC_Version.Hardware = FromFlightCtrl.Param.Byte[4]; |
656 | FC.Error[0] |= FromFlightCtrl.Param.Byte[5]; |
657 | FC.Error[0] |= FromFlightCtrl.Param.Byte[5]; |
657 | FC.Error[1] |= FromFlightCtrl.Param.Byte[6]; |
658 | FC.Error[1] |= FromFlightCtrl.Param.Byte[6]; |
658 | FC.Error[2] |= FromFlightCtrl.Param.Byte[7]; |
659 | FC.Error[2] |= FromFlightCtrl.Param.Byte[7]; |
659 | Parameter.GlobalConfig = FromFlightCtrl.Param.Byte[8]; |
660 | Parameter.GlobalConfig = FromFlightCtrl.Param.Byte[8]; |
660 | Parameter.ExtraConfig = FromFlightCtrl.Param.Byte[9]; |
661 | Parameter.ExtraConfig = FromFlightCtrl.Param.Byte[9]; |
661 | Parameter.OrientationAngle = FromFlightCtrl.Param.Byte[10]; |
662 | Parameter.OrientationAngle = FromFlightCtrl.Param.Byte[10]; |
662 | Parameter.GlobalConfig3 = FromFlightCtrl.Param.Byte[11]; |
663 | Parameter.GlobalConfig3 = FromFlightCtrl.Param.Byte[11]; |
663 | DebugOut.StatusGreen |= AMPEL_FC; // status of FC Present |
664 | DebugOut.StatusGreen |= AMPEL_FC; // status of FC Present |
664 | DebugOut.StatusGreen |= AMPEL_BL; // status of BL Present |
665 | DebugOut.StatusGreen |= AMPEL_BL; // status of BL Present |
665 | if(FC.Error[0] || FC.Error[1] || FC.Error[2] || FC.Error[3] || FC.Error[4]) DebugOut.StatusRed |= AMPEL_FC; |
666 | if(FC.Error[0] || FC.Error[1] || FC.Error[2] || FC.Error[3] || FC.Error[4]) DebugOut.StatusRed |= AMPEL_FC; |
666 | else DebugOut.StatusRed &= ~AMPEL_FC; |
667 | else DebugOut.StatusRed &= ~AMPEL_FC; |
667 | break; |
668 | break; |
668 | default: |
669 | default: |
669 | break; |
670 | break; |
670 | } |
671 | } |
671 | 672 | ||
672 | DebugOut.Analog[0] = FromFlightCtrl.AngleNick; |
673 | DebugOut.Analog[0] = FromFlightCtrl.AngleNick; |
673 | DebugOut.Analog[1] = FromFlightCtrl.AngleRoll; |
674 | DebugOut.Analog[1] = FromFlightCtrl.AngleRoll; |
674 | DebugOut.Analog[2] = FromFlightCtrl.AccNick; |
675 | DebugOut.Analog[2] = FromFlightCtrl.AccNick; |
675 | DebugOut.Analog[3] = FromFlightCtrl.AccRoll; |
676 | DebugOut.Analog[3] = FromFlightCtrl.AccRoll; |
676 | DebugOut.Analog[11] = FromFlightCtrl.GyroHeading/10;// in deg |
677 | DebugOut.Analog[11] = FromFlightCtrl.GyroHeading/10;// in deg |
677 | Data3D.AngleNick = FromFlightCtrl.AngleNick; // in 0.1 deg |
678 | Data3D.AngleNick = FromFlightCtrl.AngleNick; // in 0.1 deg |
678 | Data3D.AngleRoll = FromFlightCtrl.AngleRoll; // in 0.1 deg |
679 | Data3D.AngleRoll = FromFlightCtrl.AngleRoll; // in 0.1 deg |
679 | Data3D.Heading = FromFlightCtrl.GyroHeading; // in 0.1 deg |
680 | Data3D.Heading = FromFlightCtrl.GyroHeading; // in 0.1 deg |
680 | // every time we got new data from the FC via SPI call the navigation routine |
681 | // every time we got new data from the FC via SPI call the navigation routine |
681 | // and update GPSStick that are returned to FC |
682 | // and update GPSStick that are returned to FC |
682 | SPI_RxBuffer_Request = 0; |
683 | SPI_RxBuffer_Request = 0; |
683 | 684 | ||
684 | 685 | ||
685 | /* |
686 | /* |
686 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
687 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
687 | */ |
688 | */ |
688 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
689 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
689 | // in SPI Einkommentieren, falls der Flug simultert werden soll |
690 | // in SPI Einkommentieren, falls der Flug simultert werden soll |
690 | /* |
691 | /* |
691 | if(Parameter.User8 < 100) FC.StatusFlags = 0; |
692 | if(Parameter.User8 < 100) FC.StatusFlags = 0; |
692 | else |
693 | else |
693 | if(Parameter.User8 < 150) FC.StatusFlags = FC_STATUS_START; |
694 | if(Parameter.User8 < 150) FC.StatusFlags = FC_STATUS_START; |
694 | else FC.StatusFlags = FC_STATUS_FLY | FC_STATUS_MOTOR_RUN; |
695 | else FC.StatusFlags = FC_STATUS_FLY | FC_STATUS_MOTOR_RUN; |
695 | BL_MinOfMaxPWM = 255; |
696 | BL_MinOfMaxPWM = 255; |
696 | NaviData.FCStatusFlags = FC.StatusFlags; |
697 | NaviData.FCStatusFlags = FC.StatusFlags; |
697 | */ |
698 | */ |
698 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
699 | //+++++++++++++++++++++++++++++++++++++++++++++++++++ |
699 | 700 | ||
700 | 701 | ||
701 | GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); |
702 | GPS_Navigation(&GPSData, &(ToFlightCtrl.GPSStick)); |
702 | ClearFCStatusFlags = 1; |
703 | ClearFCStatusFlags = 1; |
703 | if(counter) |
704 | if(counter) |
704 | { |
705 | { |
705 | counter--; // count down to enable servo |
706 | counter--; // count down to enable servo |
706 | if(!counter) TIMER2_Init(); // enable Servo Output |
707 | if(!counter) TIMER2_Init(); // enable Servo Output |
707 | } |
708 | } |
708 | timeout = SetDelay(80); // 80 ms, new data are send every 20 ms |
709 | timeout = SetDelay(80); // 80 ms, new data are send every 20 ms |
709 | 710 | ||
710 | } // EOF if(SPI_RxBuffer_Request) |
711 | } // EOF if(SPI_RxBuffer_Request) |
711 | else // no new SPI data |
712 | else // no new SPI data |
712 | { |
713 | { |
713 | if(CheckDelay(timeout) && (counter == 0)) |
714 | if(CheckDelay(timeout) && (counter == 0)) |
714 | { |
715 | { |
715 | TIMER2_Deinit(); // disable Servo Output |
716 | TIMER2_Deinit(); // disable Servo Output |
716 | counter = 50; // reset counter for enabling Servo Output |
717 | counter = 50; // reset counter for enabling Servo Output |
717 | } |
718 | } |
718 | } |
719 | } |
719 | } |
720 | } |
720 | 721 | ||
721 | //------------------------------------------------------ |
722 | //------------------------------------------------------ |
722 | void SPI0_GetFlightCtrlVersion(void) |
723 | void SPI0_GetFlightCtrlVersion(void) |
723 | { |
724 | { |
724 | u32 timeout; |
725 | u32 timeout; |
725 | u8 repeat; |
726 | u8 repeat; |
726 | u8 msg[64]; |
727 | u8 msg[64]; |
727 | 728 | ||
728 | UART1_PutString("\r\n Looking for FlightControl"); |
729 | UART1_PutString("\r\n Looking for FlightControl"); |
729 | FC_Version.Major = 0xFF; |
730 | FC_Version.Major = 0xFF; |
730 | FC_Version.Minor = 0xFF; |
731 | FC_Version.Minor = 0xFF; |
731 | FC_Version.Patch = 0xFF; |
732 | FC_Version.Patch = 0xFF; |
732 | FC_Version.Compatible = 0xFF; |
733 | FC_Version.Compatible = 0xFF; |
733 | 734 | ||
734 | // polling FC version info |
735 | // polling FC version info |
735 | repeat = 0; |
736 | repeat = 0; |
736 | do |
737 | do |
737 | { |
738 | { |
738 | timeout = SetDelay(250); |
739 | timeout = SetDelay(250); |
739 | do |
740 | do |
740 | { |
741 | { |
741 | SPI0_UpdateBuffer(); |
742 | SPI0_UpdateBuffer(); |
742 | if (FC_Version.Major != 0xFF) break; |
743 | if (FC_Version.Major != 0xFF) break; |
743 | }while (!CheckDelay(timeout)); |
744 | }while (!CheckDelay(timeout)); |
744 | UART1_PutString("."); |
745 | UART1_PutString("."); |
745 | repeat++; |
746 | repeat++; |
746 | FCCalibActive = 1; |
747 | FCCalibActive = 1; |
747 | }while((FC_Version.Major == 0xFF) && (repeat < 40)); // 40*250ms = 10s |
748 | }while((FC_Version.Major == 0xFF) && (repeat < 40)); // 40*250ms = 10s |
748 | // if we got it |
749 | // if we got it |
749 | if (FC_Version.Major != 0xFF) |
750 | if (FC_Version.Major != 0xFF) |
750 | { |
751 | { |
751 | 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); |
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); |
752 | UART1_PutString(msg); |
753 | UART1_PutString(msg); |
753 | } |
754 | } |
754 | else UART1_PutString("\n\r not found!"); |
755 | else UART1_PutString("\n\r not found!"); |
755 | } |
756 | } |
756 | 757 | ||
757 | 758 | ||
758 | 759 |