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