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