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