Rev 1821 | Rev 1866 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1821 | Rev 1864 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
2 | // + Copyright (c) 04.2007 Holger Buss |
3 | // + Nur für den privaten Gebrauch |
3 | // + Nur für den privaten Gebrauch |
4 | // + www.MikroKopter.com |
4 | // + www.MikroKopter.com |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
6 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist. |
7 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist. |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
16 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
17 | // + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
17 | // + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
21 | // + Benutzung auf eigene Gefahr |
21 | // + Benutzung auf eigene Gefahr |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
25 | // + mit unserer Zustimmung zulässig |
25 | // + mit unserer Zustimmung zulässig |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
30 | // + this list of conditions and the following disclaimer. |
30 | // + this list of conditions and the following disclaimer. |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
31 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
32 | // + from this software without specific prior written permission. |
32 | // + from this software without specific prior written permission. |
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
34 | // + for non-commercial use (directly or indirectly) |
34 | // + for non-commercial use (directly or indirectly) |
35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
36 | // + with our written permission |
36 | // + with our written permission |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
38 | // + clearly linked as origin |
38 | // + clearly linked as origin |
39 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
39 | // + * porting to systems other than hardware from www.mikrokopter.de is not allowed |
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
40 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
46 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
47 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
48 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
48 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
49 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
50 | // + POSSIBILITY OF SUCH DAMAGE. |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | 52 | ||
53 | #include <avr/io.h> |
53 | #include <avr/io.h> |
54 | #include <avr/interrupt.h> |
54 | #include <avr/interrupt.h> |
55 | #include <avr/wdt.h> |
55 | #include <avr/wdt.h> |
56 | #include <avr/pgmspace.h> |
56 | #include <avr/pgmspace.h> |
57 | #include <stdarg.h> |
57 | #include <stdarg.h> |
58 | #include <string.h> |
58 | #include <string.h> |
59 | 59 | ||
60 | #include "eeprom.h" |
60 | #include "eeprom.h" |
61 | #include "menu.h" |
61 | #include "menu.h" |
62 | #include "timer0.h" |
62 | #include "timer0.h" |
63 | #include "uart0.h" |
63 | #include "uart0.h" |
64 | #include "attitude.h" |
- | |
65 | #include "rc.h" |
64 | #include "rc.h" |
66 | #include "externalControl.h" |
65 | #include "externalControl.h" |
67 | #include "output.h" |
66 | #include "output.h" |
- | 67 | #include "attitude.h" |
|
- | 68 | ||
68 | 69 | ||
69 | #ifdef USE_MK3MAG |
70 | #ifdef USE_MK3MAG |
70 | #include "mk3mag.h" |
71 | #include "mk3mag.h" |
71 | #endif |
72 | #endif |
72 | 73 | ||
73 | #define FC_ADDRESS 1 |
74 | #define FC_ADDRESS 1 |
74 | #define NC_ADDRESS 2 |
75 | #define NC_ADDRESS 2 |
75 | #define MK3MAG_ADDRESS 3 |
76 | #define MK3MAG_ADDRESS 3 |
76 | 77 | ||
77 | #define FALSE 0 |
78 | #define FALSE 0 |
78 | #define TRUE 1 |
79 | #define TRUE 1 |
79 | //int8_t test __attribute__ ((section (".noinit"))); |
80 | //int8_t test __attribute__ ((section (".noinit"))); |
80 | uint8_t request_VerInfo = FALSE; |
81 | uint8_t request_VerInfo = FALSE; |
81 | uint8_t request_ExternalControl = FALSE; |
82 | uint8_t request_ExternalControl = FALSE; |
82 | uint8_t request_Display = FALSE; |
83 | uint8_t request_Display = FALSE; |
83 | uint8_t request_Display1 = FALSE; |
84 | uint8_t request_Display1 = FALSE; |
84 | uint8_t request_DebugData = FALSE; |
85 | uint8_t request_DebugData = FALSE; |
85 | uint8_t request_Data3D = FALSE; |
86 | uint8_t request_Data3D = FALSE; |
86 | uint8_t request_DebugLabel = 255; |
87 | uint8_t request_DebugLabel = 255; |
87 | uint8_t request_PPMChannels = FALSE; |
88 | uint8_t request_PPMChannels = FALSE; |
88 | uint8_t request_MotorTest = FALSE; |
89 | uint8_t request_MotorTest = FALSE; |
89 | uint8_t request_variables = FALSE; |
90 | uint8_t request_variables = FALSE; |
90 | 91 | ||
91 | uint8_t DisplayLine = 0; |
92 | uint8_t DisplayLine = 0; |
92 | 93 | ||
93 | volatile uint8_t txd_buffer[TXD_BUFFER_LEN]; |
94 | volatile uint8_t txd_buffer[TXD_BUFFER_LEN]; |
94 | volatile uint8_t rxd_buffer_locked = FALSE; |
95 | volatile uint8_t rxd_buffer_locked = FALSE; |
95 | volatile uint8_t rxd_buffer[RXD_BUFFER_LEN]; |
96 | volatile uint8_t rxd_buffer[RXD_BUFFER_LEN]; |
96 | volatile uint8_t txd_complete = TRUE; |
97 | volatile uint8_t txd_complete = TRUE; |
97 | volatile uint8_t ReceivedBytes = 0; |
98 | volatile uint8_t ReceivedBytes = 0; |
98 | volatile uint8_t *pRxData = 0; |
99 | volatile uint8_t *pRxData = 0; |
99 | volatile uint8_t RxDataLen = 0; |
100 | volatile uint8_t RxDataLen = 0; |
100 | 101 | ||
101 | uint8_t motorTestActive = 0; |
102 | uint8_t motorTestActive = 0; |
102 | uint8_t motorTest[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
103 | uint8_t motorTest[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
103 | uint8_t ConfirmFrame; |
104 | uint8_t ConfirmFrame; |
104 | 105 | ||
105 | typedef struct { |
106 | typedef struct { |
106 | int16_t Heading; |
107 | int16_t Heading; |
107 | }__attribute__((packed)) Heading_t; |
108 | }__attribute__((packed)) Heading_t; |
108 | 109 | ||
109 | DebugOut_t DebugOut; |
110 | DebugOut_t DebugOut; |
110 | Data3D_t Data3D; |
111 | Data3D_t Data3D; |
111 | UART_VersionInfo_t UART_VersionInfo; |
112 | UART_VersionInfo_t UART_VersionInfo; |
112 | 113 | ||
113 | uint16_t DebugData_Timer; |
114 | uint16_t DebugData_Timer; |
114 | uint16_t Data3D_Timer; |
115 | uint16_t Data3D_Timer; |
115 | uint16_t DebugData_Interval = 500; // in 1ms |
116 | uint16_t DebugData_Interval = 500; // in 1ms |
116 | uint16_t Data3D_Interval = 0; // in 1ms |
117 | uint16_t Data3D_Interval = 0; // in 1ms |
117 | 118 | ||
118 | #ifdef USE_MK3MAG |
119 | #ifdef USE_MK3MAG |
119 | int16_t Compass_Timer; |
120 | int16_t Compass_Timer; |
120 | #endif |
121 | #endif |
121 | 122 | ||
122 | // keep lables in flash to save 512 bytes of sram space |
123 | // keep lables in flash to save 512 bytes of sram space |
123 | const prog_uint8_t ANALOG_LABEL[32][16] = { |
124 | const prog_uint8_t ANALOG_LABEL[32][16] = { |
124 | //1234567890123456 |
125 | //1234567890123456 |
125 | "AnglePitch ", //0 |
126 | "AnglePitch ", //0 |
126 | "AngleRoll ", |
127 | "AngleRoll ", |
127 | "AngleYaw ", |
128 | "AngleYaw ", |
128 | "GyroPitch(PID) ", |
129 | "GyroPitch(PID) ", |
129 | "GyroRoll(PID) ", |
130 | "GyroRoll(PID) ", |
130 | "GyroYaw ", //5 |
131 | "GyroYaw ", //5 |
131 | "GyroPitch(AC) ", |
132 | "GyroPitch(AC) ", |
132 | "GyroRoll(AC) ", |
133 | "GyroRoll(AC) ", |
133 | "GyroYaw(AC) ", |
134 | "GyroYaw(AC) ", |
134 | "AccPitch (angle)", |
135 | "AccPitch (angle)", |
135 | "AccRoll (angle) ", //10 |
136 | "AccRoll (angle) ", //10 |
136 | "UBat ", |
137 | "HIRES_GYRO_INTEG", |
137 | "Pitch Term ", |
138 | "Pitch Term ", |
138 | "Roll Term ", |
139 | "Roll Term ", |
139 | "Yaw Term ", |
140 | "Yaw Term ", |
140 | "Throttle Term ", //15 |
141 | "Throttle Term ", //15 |
- | 142 | "0th O Corr pitch", |
|
141 | "0th O Corr pitch", "0th O Corr roll ", |
143 | "0th O Corr roll ", |
142 | "DriftCompDelta P", |
144 | "DriftCompDelta P", |
143 | "DriftCompDelta R", |
145 | "DriftCompDelta R", |
144 | "ADPitchGyroOffs ", //20 |
146 | "ADPitchGyroOffs ", //20 |
- | 147 | "ADRollGyroOffs ", |
|
- | 148 | "M1 ", |
|
145 | "ADRollGyroOffs ", "M1 ", "M2 ", |
149 | "M2 ", |
146 | "M3 ", |
150 | "M3 ", |
147 | "M4 ", //25 |
151 | "M4 ", //25 |
- | 152 | "ControlYaw ", |
|
- | 153 | "Airpress. Range ", |
|
148 | "ControlYaw ", "Airpress. Range ", "DriftCompPitch ", |
154 | "DriftCompPitch ", |
- | 155 | "DriftCompRoll ", |
|
149 | "DriftCompRoll ", "AirpressFiltered", //30 |
156 | "AirpressFiltered", //30 |
150 | "AirpressADC " }; |
157 | "AirpressADC " }; |
151 | 158 | ||
152 | /****************************************************************/ |
159 | /****************************************************************/ |
153 | /* Initialization of the USART0 */ |
160 | /* Initialization of the USART0 */ |
154 | /****************************************************************/ |
161 | /****************************************************************/ |
155 | void usart0_Init(void) { |
162 | void usart0_Init(void) { |
156 | uint8_t sreg = SREG; |
163 | uint8_t sreg = SREG; |
157 | uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK / (8 * USART0_BAUD) - 1); |
164 | uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK / (8 * USART0_BAUD) - 1); |
158 | 165 | ||
159 | // disable all interrupts before configuration |
166 | // disable all interrupts before configuration |
160 | cli(); |
167 | cli(); |
161 | 168 | ||
162 | // disable RX-Interrupt |
169 | // disable RX-Interrupt |
163 | UCSR0B &= ~(1 << RXCIE0); |
170 | UCSR0B &= ~(1 << RXCIE0); |
164 | // disable TX-Interrupt |
171 | // disable TX-Interrupt |
165 | UCSR0B &= ~(1 << TXCIE0); |
172 | UCSR0B &= ~(1 << TXCIE0); |
166 | 173 | ||
167 | // set direction of RXD0 and TXD0 pins |
174 | // set direction of RXD0 and TXD0 pins |
168 | // set RXD0 (PD0) as an input pin |
175 | // set RXD0 (PD0) as an input pin |
169 | PORTD |= (1 << PORTD0); |
176 | PORTD |= (1 << PORTD0); |
170 | DDRD &= ~(1 << DDD0); |
177 | DDRD &= ~(1 << DDD0); |
171 | // set TXD0 (PD1) as an output pin |
178 | // set TXD0 (PD1) as an output pin |
172 | PORTD |= (1 << PORTD1); |
179 | PORTD |= (1 << PORTD1); |
173 | DDRD |= (1 << DDD1); |
180 | DDRD |= (1 << DDD1); |
174 | 181 | ||
175 | // USART0 Baud Rate Register |
182 | // USART0 Baud Rate Register |
176 | // set clock divider |
183 | // set clock divider |
177 | UBRR0H = (uint8_t) (ubrr >> 8); |
184 | UBRR0H = (uint8_t) (ubrr >> 8); |
178 | UBRR0L = (uint8_t) ubrr; |
185 | UBRR0L = (uint8_t) ubrr; |
179 | 186 | ||
180 | // USART0 Control and Status Register A, B, C |
187 | // USART0 Control and Status Register A, B, C |
181 | 188 | ||
182 | // enable double speed operation in |
189 | // enable double speed operation in |
183 | UCSR0A |= (1 << U2X0); |
190 | UCSR0A |= (1 << U2X0); |
184 | // enable receiver and transmitter in |
191 | // enable receiver and transmitter in |
185 | UCSR0B = (1 << TXEN0) | (1 << RXEN0); |
192 | UCSR0B = (1 << TXEN0) | (1 << RXEN0); |
186 | // set asynchronous mode |
193 | // set asynchronous mode |
187 | UCSR0C &= ~(1 << UMSEL01); |
194 | UCSR0C &= ~(1 << UMSEL01); |
188 | UCSR0C &= ~(1 << UMSEL00); |
195 | UCSR0C &= ~(1 << UMSEL00); |
189 | // no parity |
196 | // no parity |
190 | UCSR0C &= ~(1 << UPM01); |
197 | UCSR0C &= ~(1 << UPM01); |
191 | UCSR0C &= ~(1 << UPM00); |
198 | UCSR0C &= ~(1 << UPM00); |
192 | // 1 stop bit |
199 | // 1 stop bit |
193 | UCSR0C &= ~(1 << USBS0); |
200 | UCSR0C &= ~(1 << USBS0); |
194 | // 8-bit |
201 | // 8-bit |
195 | UCSR0B &= ~(1 << UCSZ02); |
202 | UCSR0B &= ~(1 << UCSZ02); |
196 | UCSR0C |= (1 << UCSZ01); |
203 | UCSR0C |= (1 << UCSZ01); |
197 | UCSR0C |= (1 << UCSZ00); |
204 | UCSR0C |= (1 << UCSZ00); |
198 | 205 | ||
199 | // flush receive buffer |
206 | // flush receive buffer |
200 | while (UCSR0A & (1 << RXC0)) |
207 | while (UCSR0A & (1 << RXC0)) |
201 | UDR0; |
208 | UDR0; |
202 | 209 | ||
203 | // enable interrupts at the end |
210 | // enable interrupts at the end |
204 | // enable RX-Interrupt |
211 | // enable RX-Interrupt |
205 | UCSR0B |= (1 << RXCIE0); |
212 | UCSR0B |= (1 << RXCIE0); |
206 | // enable TX-Interrupt |
213 | // enable TX-Interrupt |
207 | UCSR0B |= (1 << TXCIE0); |
214 | UCSR0B |= (1 << TXCIE0); |
208 | 215 | ||
209 | // initialize the debug timer |
216 | // initialize the debug timer |
210 | DebugData_Timer = SetDelay(DebugData_Interval); |
217 | DebugData_Timer = SetDelay(DebugData_Interval); |
211 | 218 | ||
212 | // unlock rxd_buffer |
219 | // unlock rxd_buffer |
213 | rxd_buffer_locked = FALSE; |
220 | rxd_buffer_locked = FALSE; |
214 | pRxData = 0; |
221 | pRxData = 0; |
215 | RxDataLen = 0; |
222 | RxDataLen = 0; |
216 | 223 | ||
217 | // no bytes to send |
224 | // no bytes to send |
218 | txd_complete = TRUE; |
225 | txd_complete = TRUE; |
219 | 226 | ||
220 | #ifdef USE_MK3MAG |
227 | #ifdef USE_MK3MAG |
221 | Compass_Timer = SetDelay(220); |
228 | Compass_Timer = SetDelay(220); |
222 | #endif |
229 | #endif |
223 | 230 | ||
224 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
231 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
225 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
232 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
226 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
233 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
227 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
234 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
228 | UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
235 | UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
229 | 236 | ||
230 | // restore global interrupt flags |
237 | // restore global interrupt flags |
231 | SREG = sreg; |
238 | SREG = sreg; |
232 | } |
239 | } |
233 | 240 | ||
234 | /****************************************************************/ |
241 | /****************************************************************/ |
235 | /* USART0 transmitter ISR */ |
242 | /* USART0 transmitter ISR */ |
236 | /****************************************************************/ |
243 | /****************************************************************/ |
237 | ISR(USART0_TX_vect) |
244 | ISR(USART0_TX_vect) |
238 | { |
245 | { |
239 | static uint16_t ptr_txd_buffer = 0; |
246 | static uint16_t ptr_txd_buffer = 0; |
240 | uint8_t tmp_tx; |
247 | uint8_t tmp_tx; |
241 | if (!txd_complete) { // transmission not completed |
248 | if (!txd_complete) { // transmission not completed |
242 | ptr_txd_buffer++; // die [0] wurde schon gesendet |
249 | ptr_txd_buffer++; // die [0] wurde schon gesendet |
243 | tmp_tx = txd_buffer[ptr_txd_buffer]; |
250 | tmp_tx = txd_buffer[ptr_txd_buffer]; |
244 | // if terminating character or end of txd buffer was reached |
251 | // if terminating character or end of txd buffer was reached |
245 | if ((tmp_tx == '\r') || (ptr_txd_buffer == TXD_BUFFER_LEN)) { |
252 | if ((tmp_tx == '\r') || (ptr_txd_buffer == TXD_BUFFER_LEN)) { |
246 | ptr_txd_buffer = 0; // reset txd pointer |
253 | ptr_txd_buffer = 0; // reset txd pointer |
247 | txd_complete = 1; // stop transmission |
254 | txd_complete = 1; // stop transmission |
248 | } |
255 | } |
249 | UDR0 = tmp_tx; // send current byte will trigger this ISR again |
256 | UDR0 = tmp_tx; // send current byte will trigger this ISR again |
250 | } |
257 | } |
251 | // transmission completed |
258 | // transmission completed |
252 | else |
259 | else |
253 | ptr_txd_buffer = 0; |
260 | ptr_txd_buffer = 0; |
254 | } |
261 | } |
255 | 262 | ||
256 | /****************************************************************/ |
263 | /****************************************************************/ |
257 | /* USART0 receiver ISR */ |
264 | /* USART0 receiver ISR */ |
258 | /****************************************************************/ |
265 | /****************************************************************/ |
259 | ISR(USART0_RX_vect) |
266 | ISR(USART0_RX_vect) |
260 | { |
267 | { |
261 | static uint16_t crc; |
268 | static uint16_t crc; |
262 | static uint8_t ptr_rxd_buffer = 0; |
269 | static uint8_t ptr_rxd_buffer = 0; |
263 | uint8_t crc1, crc2; |
270 | uint8_t crc1, crc2; |
264 | uint8_t c; |
271 | uint8_t c; |
265 | 272 | ||
266 | c = UDR0; // catch the received byte |
273 | c = UDR0; // catch the received byte |
267 | 274 | ||
268 | if (rxd_buffer_locked) |
275 | if (rxd_buffer_locked) |
269 | return; // if rxd buffer is locked immediately return |
276 | return; // if rxd buffer is locked immediately return |
270 | 277 | ||
271 | // the rxd buffer is unlocked |
278 | // the rxd buffer is unlocked |
272 | if ((ptr_rxd_buffer == 0) && (c == '#')) { // if rxd buffer is empty and syncronisation character is received |
279 | if ((ptr_rxd_buffer == 0) && (c == '#')) { // if rxd buffer is empty and syncronisation character is received |
273 | rxd_buffer[ptr_rxd_buffer++] = c; // copy 1st byte to buffer |
280 | rxd_buffer[ptr_rxd_buffer++] = c; // copy 1st byte to buffer |
274 | crc = c; // init crc |
281 | crc = c; // init crc |
275 | } |
282 | } |
276 | #if 0 |
283 | #if 0 |
277 | else if (ptr_rxd_buffer == 1) { // handle address |
284 | else if (ptr_rxd_buffer == 1) { // handle address |
278 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
285 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
279 | crc += c; // update crc |
286 | crc += c; // update crc |
280 | } |
287 | } |
281 | #endif |
288 | #endif |
282 | else if (ptr_rxd_buffer < RXD_BUFFER_LEN) { // collect incomming bytes |
289 | else if (ptr_rxd_buffer < RXD_BUFFER_LEN) { // collect incomming bytes |
283 | if (c != '\r') { // no termination character |
290 | if (c != '\r') { // no termination character |
284 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
291 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
285 | crc += c; // update crc |
292 | crc += c; // update crc |
286 | } else { // termination character was received |
293 | } else { // termination character was received |
287 | // the last 2 bytes are no subject for checksum calculation |
294 | // the last 2 bytes are no subject for checksum calculation |
288 | // they are the checksum itself |
295 | // they are the checksum itself |
289 | crc -= rxd_buffer[ptr_rxd_buffer - 2]; |
296 | crc -= rxd_buffer[ptr_rxd_buffer - 2]; |
290 | crc -= rxd_buffer[ptr_rxd_buffer - 1]; |
297 | crc -= rxd_buffer[ptr_rxd_buffer - 1]; |
291 | // calculate checksum from transmitted data |
298 | // calculate checksum from transmitted data |
292 | crc %= 4096; |
299 | crc %= 4096; |
293 | crc1 = '=' + crc / 64; |
300 | crc1 = '=' + crc / 64; |
294 | crc2 = '=' + crc % 64; |
301 | crc2 = '=' + crc % 64; |
295 | // compare checksum to transmitted checksum bytes |
302 | // compare checksum to transmitted checksum bytes |
296 | if ((crc1 == rxd_buffer[ptr_rxd_buffer - 2]) && (crc2 |
303 | if ((crc1 == rxd_buffer[ptr_rxd_buffer - 2]) && (crc2 |
297 | == rxd_buffer[ptr_rxd_buffer - 1])) { |
304 | == rxd_buffer[ptr_rxd_buffer - 1])) { |
298 | // checksum valid |
305 | // checksum valid |
299 | rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character |
306 | rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character |
300 | ReceivedBytes = ptr_rxd_buffer + 1;// store number of received bytes |
307 | ReceivedBytes = ptr_rxd_buffer + 1;// store number of received bytes |
301 | rxd_buffer_locked = TRUE; // lock the rxd buffer |
308 | rxd_buffer_locked = TRUE; // lock the rxd buffer |
302 | // if 2nd byte is an 'R' enable watchdog that will result in an reset |
309 | // if 2nd byte is an 'R' enable watchdog that will result in an reset |
303 | if (rxd_buffer[2] == 'R') { |
310 | if (rxd_buffer[2] == 'R') { |
304 | wdt_enable(WDTO_250MS); |
311 | wdt_enable(WDTO_250MS); |
305 | } // Reset-Commando |
312 | } // Reset-Commando |
306 | } else { // checksum invalid |
313 | } else { // checksum invalid |
307 | rxd_buffer_locked = FALSE; // unlock rxd buffer |
314 | rxd_buffer_locked = FALSE; // unlock rxd buffer |
308 | } |
315 | } |
309 | ptr_rxd_buffer = 0; // reset rxd buffer pointer |
316 | ptr_rxd_buffer = 0; // reset rxd buffer pointer |
310 | } |
317 | } |
311 | } else { // rxd buffer overrun |
318 | } else { // rxd buffer overrun |
312 | ptr_rxd_buffer = 0; // reset rxd buffer |
319 | ptr_rxd_buffer = 0; // reset rxd buffer |
313 | rxd_buffer_locked = FALSE; // unlock rxd buffer |
320 | rxd_buffer_locked = FALSE; // unlock rxd buffer |
314 | } |
321 | } |
315 | } |
322 | } |
316 | 323 | ||
317 | // -------------------------------------------------------------------------- |
324 | // -------------------------------------------------------------------------- |
318 | void AddCRC(uint16_t datalen) { |
325 | void AddCRC(uint16_t datalen) { |
319 | uint16_t tmpCRC = 0, i; |
326 | uint16_t tmpCRC = 0, i; |
320 | for (i = 0; i < datalen; i++) { |
327 | for (i = 0; i < datalen; i++) { |
321 | tmpCRC += txd_buffer[i]; |
328 | tmpCRC += txd_buffer[i]; |
322 | } |
329 | } |
323 | tmpCRC %= 4096; |
330 | tmpCRC %= 4096; |
324 | txd_buffer[i++] = '=' + tmpCRC / 64; |
331 | txd_buffer[i++] = '=' + tmpCRC / 64; |
325 | txd_buffer[i++] = '=' + tmpCRC % 64; |
332 | txd_buffer[i++] = '=' + tmpCRC % 64; |
326 | txd_buffer[i++] = '\r'; |
333 | txd_buffer[i++] = '\r'; |
327 | txd_complete = FALSE; |
334 | txd_complete = FALSE; |
328 | UDR0 = txd_buffer[0]; // initiates the transmittion (continued in the TXD ISR) |
335 | UDR0 = txd_buffer[0]; // initiates the transmittion (continued in the TXD ISR) |
329 | } |
336 | } |
330 | 337 | ||
331 | // -------------------------------------------------------------------------- |
338 | // -------------------------------------------------------------------------- |
332 | // application example: |
339 | // application example: |
333 | // SendOutData('A', FC_ADDRESS, 2, (uint8_t *)&request_DebugLabel, sizeof(request_DebugLabel), label, 16); |
340 | // SendOutData('A', FC_ADDRESS, 2, (uint8_t *)&request_DebugLabel, sizeof(request_DebugLabel), label, 16); |
334 | /* |
341 | /* |
335 | void SendOutData(uint8_t cmd, uint8_t addr, uint8_t numofbuffers, ...) { // uint8_t *pdata, uint8_t len, ... |
342 | void SendOutData(uint8_t cmd, uint8_t addr, uint8_t numofbuffers, ...) { // uint8_t *pdata, uint8_t len, ... |
336 | va_list ap; |
343 | va_list ap; |
337 | uint16_t txd_bufferIndex = 0; |
344 | uint16_t txd_bufferIndex = 0; |
338 | uint8_t *currentBuffer; |
345 | uint8_t *currentBuffer; |
339 | uint8_t currentBufferIndex; |
346 | uint8_t currentBufferIndex; |
340 | uint16_t lengthOfCurrentBuffer; |
347 | uint16_t lengthOfCurrentBuffer; |
341 | uint8_t shift = 0; |
348 | uint8_t shift = 0; |
342 | 349 | ||
343 | txd_buffer[txd_bufferIndex++] = '#'; // Start character |
350 | txd_buffer[txd_bufferIndex++] = '#'; // Start character |
344 | txd_buffer[txd_bufferIndex++] = 'a' + addr; // Address (a=0; b=1,...) |
351 | txd_buffer[txd_bufferIndex++] = 'a' + addr; // Address (a=0; b=1,...) |
345 | txd_buffer[txd_bufferIndex++] = cmd; // Command |
352 | txd_buffer[txd_bufferIndex++] = cmd; // Command |
346 | 353 | ||
347 | va_start(ap, numofbuffers); |
354 | va_start(ap, numofbuffers); |
348 | 355 | ||
349 | while(numofbuffers) { |
356 | while(numofbuffers) { |
350 | currentBuffer = va_arg(ap, uint8_t*); |
357 | currentBuffer = va_arg(ap, uint8_t*); |
351 | lengthOfCurrentBuffer = va_arg(ap, int); |
358 | lengthOfCurrentBuffer = va_arg(ap, int); |
352 | currentBufferIndex = 0; |
359 | currentBufferIndex = 0; |
353 | // Encode data: 3 bytes of data are encoded into 4 bytes, |
360 | // Encode data: 3 bytes of data are encoded into 4 bytes, |
354 | // where the 2 most significant bits are both 0. |
361 | // where the 2 most significant bits are both 0. |
355 | while(currentBufferIndex != lengthOfCurrentBuffer) { |
362 | while(currentBufferIndex != lengthOfCurrentBuffer) { |
356 | if (!shift) txd_buffer[txd_bufferIndex] = 0; |
363 | if (!shift) txd_buffer[txd_bufferIndex] = 0; |
357 | txd_buffer[txd_bufferIndex] |= currentBuffer[currentBufferIndex] >> (shift + 2); |
364 | txd_buffer[txd_bufferIndex] |= currentBuffer[currentBufferIndex] >> (shift + 2); |
358 | txd_buffer[++txd_bufferIndex] = (currentBuffer[currentBufferIndex] << (4 - shift)) & 0b00111111; |
365 | txd_buffer[++txd_bufferIndex] = (currentBuffer[currentBufferIndex] << (4 - shift)) & 0b00111111; |
359 | shift += 2; |
366 | shift += 2; |
360 | if (shift == 6) { shift=0; txd_bufferIndex++; } |
367 | if (shift == 6) { shift=0; txd_bufferIndex++; } |
361 | currentBufferIndex++; |
368 | currentBufferIndex++; |
362 | } |
369 | } |
363 | } |
370 | } |
364 | // If the number of data bytes was not divisible by 3, stuff |
371 | // If the number of data bytes was not divisible by 3, stuff |
365 | // with 0 pseudodata until length is again divisible by 3. |
372 | // with 0 pseudodata until length is again divisible by 3. |
366 | if (shift == 2) { |
373 | if (shift == 2) { |
367 | // We need to stuff with zero bytes at the end. |
374 | // We need to stuff with zero bytes at the end. |
368 | txd_buffer[txd_bufferIndex] &= 0b00110000; |
375 | txd_buffer[txd_bufferIndex] &= 0b00110000; |
369 | txd_buffer[++txd_bufferIndex] = 0; |
376 | txd_buffer[++txd_bufferIndex] = 0; |
370 | shift = 4; |
377 | shift = 4; |
371 | } |
378 | } |
372 | if (shift == 4) { |
379 | if (shift == 4) { |
373 | // We need to stuff with zero bytes at the end. |
380 | // We need to stuff with zero bytes at the end. |
374 | txd_buffer[txd_bufferIndex++] &= 0b00111100; |
381 | txd_buffer[txd_bufferIndex++] &= 0b00111100; |
375 | txd_buffer[txd_bufferIndex] = 0; |
382 | txd_buffer[txd_bufferIndex] = 0; |
376 | } |
383 | } |
377 | va_end(ap); |
384 | va_end(ap); |
378 | AddCRC(pt); // add checksum after data block and initates the transmission |
385 | AddCRC(pt); // add checksum after data block and initates the transmission |
379 | } |
386 | } |
380 | */ |
387 | */ |
381 | 388 | ||
382 | void SendOutData(uint8_t cmd, uint8_t addr, uint8_t numofbuffers, ...) { // uint8_t *pdata, uint8_t len, ... |
389 | void SendOutData(uint8_t cmd, uint8_t addr, uint8_t numofbuffers, ...) { // uint8_t *pdata, uint8_t len, ... |
383 | va_list ap; |
390 | va_list ap; |
384 | uint16_t pt = 0; |
391 | uint16_t pt = 0; |
385 | uint8_t a, b, c; |
392 | uint8_t a, b, c; |
386 | uint8_t ptr = 0; |
393 | uint8_t ptr = 0; |
387 | 394 | ||
388 | uint8_t *pdata = 0; |
395 | uint8_t *pdata = 0; |
389 | int len = 0; |
396 | int len = 0; |
390 | 397 | ||
391 | txd_buffer[pt++] = '#'; // Start character |
398 | txd_buffer[pt++] = '#'; // Start character |
392 | txd_buffer[pt++] = 'a' + addr; // Address (a=0; b=1,...) |
399 | txd_buffer[pt++] = 'a' + addr; // Address (a=0; b=1,...) |
393 | txd_buffer[pt++] = cmd; // Command |
400 | txd_buffer[pt++] = cmd; // Command |
394 | 401 | ||
395 | va_start(ap, numofbuffers); |
402 | va_start(ap, numofbuffers); |
396 | 403 | ||
397 | if (numofbuffers) { |
404 | if (numofbuffers) { |
398 | pdata = va_arg(ap, uint8_t*); |
405 | pdata = va_arg(ap, uint8_t*); |
399 | len = va_arg(ap, int); |
406 | len = va_arg(ap, int); |
400 | ptr = 0; |
407 | ptr = 0; |
401 | numofbuffers--; |
408 | numofbuffers--; |
402 | } |
409 | } |
403 | 410 | ||
404 | while (len) { |
411 | while (len) { |
405 | if (len) { |
412 | if (len) { |
406 | a = pdata[ptr++]; |
413 | a = pdata[ptr++]; |
407 | len--; |
414 | len--; |
408 | if ((!len) && numofbuffers) { |
415 | if ((!len) && numofbuffers) { |
409 | pdata = va_arg(ap, uint8_t*); |
416 | pdata = va_arg(ap, uint8_t*); |
410 | len = va_arg(ap, int); |
417 | len = va_arg(ap, int); |
411 | ptr = 0; |
418 | ptr = 0; |
412 | numofbuffers--; |
419 | numofbuffers--; |
413 | } |
420 | } |
414 | } else |
421 | } else |
415 | a = 0; |
422 | a = 0; |
416 | if (len) { |
423 | if (len) { |
417 | b = pdata[ptr++]; |
424 | b = pdata[ptr++]; |
418 | len--; |
425 | len--; |
419 | if ((!len) && numofbuffers) { |
426 | if ((!len) && numofbuffers) { |
420 | pdata = va_arg(ap, uint8_t*); |
427 | pdata = va_arg(ap, uint8_t*); |
421 | len = va_arg(ap, int); |
428 | len = va_arg(ap, int); |
422 | ptr = 0; |
429 | ptr = 0; |
423 | numofbuffers--; |
430 | numofbuffers--; |
424 | } |
431 | } |
425 | } else |
432 | } else |
426 | b = 0; |
433 | b = 0; |
427 | if (len) { |
434 | if (len) { |
428 | c = pdata[ptr++]; |
435 | c = pdata[ptr++]; |
429 | len--; |
436 | len--; |
430 | if ((!len) && numofbuffers) { |
437 | if ((!len) && numofbuffers) { |
431 | pdata = va_arg(ap, uint8_t*); |
438 | pdata = va_arg(ap, uint8_t*); |
432 | len = va_arg(ap, int); |
439 | len = va_arg(ap, int); |
433 | ptr = 0; |
440 | ptr = 0; |
434 | numofbuffers--; |
441 | numofbuffers--; |
435 | } |
442 | } |
436 | } else |
443 | } else |
437 | c = 0; |
444 | c = 0; |
438 | txd_buffer[pt++] = '=' + (a >> 2); |
445 | txd_buffer[pt++] = '=' + (a >> 2); |
439 | txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
446 | txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
440 | txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
447 | txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
441 | txd_buffer[pt++] = '=' + (c & 0x3f); |
448 | txd_buffer[pt++] = '=' + (c & 0x3f); |
442 | } |
449 | } |
443 | va_end(ap); |
450 | va_end(ap); |
444 | AddCRC(pt); // add checksum after data block and initates the transmission |
451 | AddCRC(pt); // add checksum after data block and initates the transmission |
445 | } |
452 | } |
446 | 453 | ||
447 | // -------------------------------------------------------------------------- |
454 | // -------------------------------------------------------------------------- |
448 | void Decode64(void) { |
455 | void Decode64(void) { |
449 | uint8_t a, b, c, d; |
456 | uint8_t a, b, c, d; |
450 | uint8_t x, y, z; |
457 | uint8_t x, y, z; |
451 | uint8_t ptrIn = 3; |
458 | uint8_t ptrIn = 3; |
452 | uint8_t ptrOut = 3; |
459 | uint8_t ptrOut = 3; |
453 | uint8_t len = ReceivedBytes - 6; |
460 | uint8_t len = ReceivedBytes - 6; |
454 | 461 | ||
455 | while (len) { |
462 | while (len) { |
456 | a = rxd_buffer[ptrIn++] - '='; |
463 | a = rxd_buffer[ptrIn++] - '='; |
457 | b = rxd_buffer[ptrIn++] - '='; |
464 | b = rxd_buffer[ptrIn++] - '='; |
458 | c = rxd_buffer[ptrIn++] - '='; |
465 | c = rxd_buffer[ptrIn++] - '='; |
459 | d = rxd_buffer[ptrIn++] - '='; |
466 | d = rxd_buffer[ptrIn++] - '='; |
460 | //if(ptrIn > ReceivedBytes - 3) break; |
467 | //if(ptrIn > ReceivedBytes - 3) break; |
461 | 468 | ||
462 | x = (a << 2) | (b >> 4); |
469 | x = (a << 2) | (b >> 4); |
463 | y = ((b & 0x0f) << 4) | (c >> 2); |
470 | y = ((b & 0x0f) << 4) | (c >> 2); |
464 | z = ((c & 0x03) << 6) | d; |
471 | z = ((c & 0x03) << 6) | d; |
465 | 472 | ||
466 | if (len--) |
473 | if (len--) |
467 | rxd_buffer[ptrOut++] = x; |
474 | rxd_buffer[ptrOut++] = x; |
468 | else |
475 | else |
469 | break; |
476 | break; |
470 | if (len--) |
477 | if (len--) |
471 | rxd_buffer[ptrOut++] = y; |
478 | rxd_buffer[ptrOut++] = y; |
472 | else |
479 | else |
473 | break; |
480 | break; |
474 | if (len--) |
481 | if (len--) |
475 | rxd_buffer[ptrOut++] = z; |
482 | rxd_buffer[ptrOut++] = z; |
476 | else |
483 | else |
477 | break; |
484 | break; |
478 | } |
485 | } |
479 | pRxData = &rxd_buffer[3]; |
486 | pRxData = &rxd_buffer[3]; |
480 | RxDataLen = ptrOut - 3; |
487 | RxDataLen = ptrOut - 3; |
481 | } |
488 | } |
482 | 489 | ||
483 | // -------------------------------------------------------------------------- |
490 | // -------------------------------------------------------------------------- |
484 | void usart0_ProcessRxData(void) { |
491 | void usart0_ProcessRxData(void) { |
485 | // We control the motorTestActive var from here: Count it down. |
492 | // We control the motorTestActive var from here: Count it down. |
486 | if (motorTestActive) |
493 | if (motorTestActive) |
487 | motorTestActive--; |
494 | motorTestActive--; |
488 | // if data in the rxd buffer are not locked immediately return |
495 | // if data in the rxd buffer are not locked immediately return |
489 | if (!rxd_buffer_locked) |
496 | if (!rxd_buffer_locked) |
490 | return; |
497 | return; |
491 | uint8_t tempchar1, tempchar2; |
498 | uint8_t tempchar1, tempchar2; |
492 | Decode64(); // decode data block in rxd_buffer |
499 | Decode64(); // decode data block in rxd_buffer |
493 | 500 | ||
494 | switch (rxd_buffer[1] - 'a') { |
501 | switch (rxd_buffer[1] - 'a') { |
495 | 502 | ||
496 | case FC_ADDRESS: |
503 | case FC_ADDRESS: |
497 | switch (rxd_buffer[2]) { |
504 | switch (rxd_buffer[2]) { |
498 | #ifdef USE_MK3MAG |
505 | #ifdef USE_MK3MAG |
499 | case 'K':// compass value |
506 | case 'K':// compass value |
500 | compassHeading = ((Heading_t *)pRxData)->Heading; |
507 | compassHeading = ((Heading_t *)pRxData)->Heading; |
501 | // compassOffCourse = ((540 + compassHeading - compassCourse) % 360) - 180; |
508 | // compassOffCourse = ((540 + compassHeading - compassCourse) % 360) - 180; |
502 | break; |
509 | break; |
503 | #endif |
510 | #endif |
504 | case 't': // motor test |
511 | case 't': // motor test |
505 | if (RxDataLen > 20) { |
512 | if (RxDataLen > 20) { |
506 | memcpy(&motorTest[0], (uint8_t*) pRxData, sizeof(motorTest)); |
513 | memcpy(&motorTest[0], (uint8_t*) pRxData, sizeof(motorTest)); |
507 | } else { |
514 | } else { |
508 | memcpy(&motorTest[0], (uint8_t*) pRxData, 4); |
515 | memcpy(&motorTest[0], (uint8_t*) pRxData, 4); |
509 | } |
516 | } |
510 | motorTestActive = 255; |
517 | motorTestActive = 255; |
511 | externalControlActive = 255; |
518 | externalControlActive = 255; |
512 | break; |
519 | break; |
513 | 520 | ||
514 | case 'n':// "Get Mixer Table |
521 | case 'n':// "Get Mixer Table |
515 | while (!txd_complete) |
522 | while (!txd_complete) |
516 | ; // wait for previous frame to be sent |
523 | ; // wait for previous frame to be sent |
517 | SendOutData('N', FC_ADDRESS, 1, (uint8_t *) &Mixer, sizeof(Mixer)); |
524 | SendOutData('N', FC_ADDRESS, 1, (uint8_t *) &Mixer, sizeof(Mixer)); |
518 | break; |
525 | break; |
519 | 526 | ||
520 | case 'm':// "Set Mixer Table |
527 | case 'm':// "Set Mixer Table |
521 | if (pRxData[0] == EEMIXER_REVISION) { |
528 | if (pRxData[0] == EEMIXER_REVISION) { |
522 | memcpy(&Mixer, (uint8_t*) pRxData, sizeof(Mixer)); |
529 | memcpy(&Mixer, (uint8_t*) pRxData, sizeof(Mixer)); |
523 | MixerTable_WriteToEEProm(); |
530 | MixerTable_WriteToEEProm(); |
524 | while (!txd_complete) |
531 | while (!txd_complete) |
525 | ; // wait for previous frame to be sent |
532 | ; // wait for previous frame to be sent |
526 | tempchar1 = 1; |
533 | tempchar1 = 1; |
527 | } else { |
534 | } else { |
528 | tempchar1 = 0; |
535 | tempchar1 = 0; |
529 | } |
536 | } |
530 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, 1); |
537 | SendOutData('M', FC_ADDRESS, 1, &tempchar1, 1); |
531 | break; |
538 | break; |
532 | 539 | ||
533 | case 'p': // get PPM channels |
540 | case 'p': // get PPM channels |
534 | request_PPMChannels = TRUE; |
541 | request_PPMChannels = TRUE; |
535 | break; |
542 | break; |
536 | 543 | ||
537 | case 'q':// request settings |
544 | case 'q':// request settings |
538 | if (pRxData[0] == 0xFF) { |
545 | if (pRxData[0] == 0xFF) { |
539 | pRxData[0] = GetParamByte(PID_ACTIVE_SET); |
546 | pRxData[0] = GetParamByte(PID_ACTIVE_SET); |
540 | } |
547 | } |
541 | // limit settings range |
548 | // limit settings range |
542 | if (pRxData[0] < 1) |
549 | if (pRxData[0] < 1) |
543 | pRxData[0] = 1; // limit to 1 |
550 | pRxData[0] = 1; // limit to 1 |
544 | else if (pRxData[0] > 5) |
551 | else if (pRxData[0] > 5) |
545 | pRxData[0] = 5; // limit to 5 |
552 | pRxData[0] = 5; // limit to 5 |
546 | // load requested parameter set |
553 | // load requested parameter set |
547 | ParamSet_ReadFromEEProm(pRxData[0]); |
554 | ParamSet_ReadFromEEProm(pRxData[0]); |
548 | tempchar1 = pRxData[0]; |
555 | tempchar1 = pRxData[0]; |
549 | tempchar2 = EEPARAM_REVISION; |
556 | tempchar2 = EEPARAM_REVISION; |
550 | while (!txd_complete) |
557 | while (!txd_complete) |
551 | ; // wait for previous frame to be sent |
558 | ; // wait for previous frame to be sent |
552 | SendOutData('Q', FC_ADDRESS, 3, &tempchar1, sizeof(tempchar1), |
559 | SendOutData('Q', FC_ADDRESS, 3, &tempchar1, sizeof(tempchar1), |
553 | &tempchar2, sizeof(tempchar2), (uint8_t *) &staticParams, |
560 | &tempchar2, sizeof(tempchar2), (uint8_t *) &staticParams, |
554 | sizeof(staticParams)); |
561 | sizeof(staticParams)); |
555 | break; |
562 | break; |
556 | 563 | ||
557 | case 's': // save settings |
564 | case 's': // save settings |
558 | if (!(MKFlags & MKFLAG_MOTOR_RUN)) // save settings only if motors are off |
565 | if (!(MKFlags & MKFLAG_MOTOR_RUN)) // save settings only if motors are off |
559 | { |
566 | { |
560 | if ((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] |
567 | if ((1 <= pRxData[0]) && (pRxData[0] <= 5) && (pRxData[1] |
561 | == EEPARAM_REVISION)) // check for setting to be in range and version of settings |
568 | == EEPARAM_REVISION)) // check for setting to be in range and version of settings |
562 | { |
569 | { |
563 | memcpy(&staticParams, (uint8_t*) &pRxData[2], sizeof(staticParams)); |
570 | memcpy(&staticParams, (uint8_t*) &pRxData[2], sizeof(staticParams)); |
564 | ParamSet_WriteToEEProm(pRxData[0]); |
571 | ParamSet_WriteToEEProm(pRxData[0]); |
565 | /* |
572 | /* |
566 | TODO: Remove this encapsulation breach |
573 | TODO: Remove this encapsulation breach |
567 | turnOver180Pitch = (int32_t) staticParams.AngleTurnOverPitch * 2500L; |
574 | turnOver180Pitch = (int32_t) staticParams.AngleTurnOverPitch * 2500L; |
568 | turnOver180Roll = (int32_t) staticParams.AngleTurnOverRoll * 2500L; |
575 | turnOver180Roll = (int32_t) staticParams.AngleTurnOverRoll * 2500L; |
569 | */ |
576 | */ |
570 | tempchar1 = getActiveParamSet(); |
577 | tempchar1 = getActiveParamSet(); |
571 | beepNumber(tempchar1); |
578 | beepNumber(tempchar1); |
572 | } else { |
579 | } else { |
573 | tempchar1 = 0; //indicate bad data |
580 | tempchar1 = 0; //indicate bad data |
574 | } |
581 | } |
575 | while (!txd_complete) |
582 | while (!txd_complete) |
576 | ; // wait for previous frame to be sent |
583 | ; // wait for previous frame to be sent |
577 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
584 | SendOutData('S', FC_ADDRESS, 1, &tempchar1, sizeof(tempchar1)); |
578 | } |
585 | } |
579 | break; |
586 | break; |
580 | 587 | ||
581 | default: |
588 | default: |
582 | //unsupported command received |
589 | //unsupported command received |
583 | break; |
590 | break; |
584 | } // case FC_ADDRESS: |
591 | } // case FC_ADDRESS: |
585 | 592 | ||
586 | default: // any Slave Address |
593 | default: // any Slave Address |
587 | switch (rxd_buffer[2]) { |
594 | switch (rxd_buffer[2]) { |
588 | case 'a':// request for labels of the analog debug outputs |
595 | case 'a':// request for labels of the analog debug outputs |
589 | request_DebugLabel = pRxData[0]; |
596 | request_DebugLabel = pRxData[0]; |
590 | if (request_DebugLabel > 31) |
597 | if (request_DebugLabel > 31) |
591 | request_DebugLabel = 31; |
598 | request_DebugLabel = 31; |
592 | externalControlActive = 255; |
599 | externalControlActive = 255; |
593 | break; |
600 | break; |
594 | 601 | ||
595 | case 'b': // submit extern control |
602 | case 'b': // submit extern control |
596 | memcpy(&externalControl, (uint8_t*) pRxData, sizeof(externalControl)); |
603 | memcpy(&externalControl, (uint8_t*) pRxData, sizeof(externalControl)); |
597 | ConfirmFrame = externalControl.frame; |
604 | ConfirmFrame = externalControl.frame; |
598 | externalControlActive = 255; |
605 | externalControlActive = 255; |
599 | break; |
606 | break; |
600 | 607 | ||
601 | case 'h':// request for display columns |
608 | case 'h':// request for display columns |
602 | externalControlActive = 255; |
609 | externalControlActive = 255; |
603 | RemoteKeys |= pRxData[0]; |
610 | RemoteKeys |= pRxData[0]; |
604 | if (RemoteKeys) |
611 | if (RemoteKeys) |
605 | DisplayLine = 0; |
612 | DisplayLine = 0; |
606 | request_Display = TRUE; |
613 | request_Display = TRUE; |
607 | break; |
614 | break; |
608 | 615 | ||
609 | case 'l':// request for display columns |
616 | case 'l':// request for display columns |
610 | externalControlActive = 255; |
617 | externalControlActive = 255; |
611 | MenuItem = pRxData[0]; |
618 | MenuItem = pRxData[0]; |
612 | request_Display1 = TRUE; |
619 | request_Display1 = TRUE; |
613 | break; |
620 | break; |
614 | 621 | ||
615 | case 'v': // request for version and board release |
622 | case 'v': // request for version and board release |
616 | request_VerInfo = TRUE; |
623 | request_VerInfo = TRUE; |
617 | break; |
624 | break; |
618 | 625 | ||
619 | case 'x': |
626 | case 'x': |
620 | request_variables = TRUE; |
627 | request_variables = TRUE; |
621 | break; |
628 | break; |
622 | 629 | ||
623 | case 'g':// get external control data |
630 | case 'g':// get external control data |
624 | request_ExternalControl = TRUE; |
631 | request_ExternalControl = TRUE; |
625 | break; |
632 | break; |
626 | 633 | ||
627 | case 'd': // request for the debug data |
634 | case 'd': // request for the debug data |
628 | DebugData_Interval = (uint16_t) pRxData[0] * 10; |
635 | DebugData_Interval = (uint16_t) pRxData[0] * 10; |
629 | if (DebugData_Interval > 0) |
636 | if (DebugData_Interval > 0) |
630 | request_DebugData = TRUE; |
637 | request_DebugData = TRUE; |
631 | break; |
638 | break; |
632 | 639 | ||
633 | case 'c': // request for the 3D data |
640 | case 'c': // request for the 3D data |
634 | Data3D_Interval = (uint16_t) pRxData[0] * 10; |
641 | Data3D_Interval = (uint16_t) pRxData[0] * 10; |
635 | if (Data3D_Interval > 0) |
642 | if (Data3D_Interval > 0) |
636 | request_Data3D = TRUE; |
643 | request_Data3D = TRUE; |
637 | break; |
644 | break; |
638 | 645 | ||
639 | default: |
646 | default: |
640 | //unsupported command received |
647 | //unsupported command received |
641 | break; |
648 | break; |
642 | } |
649 | } |
643 | break; // default: |
650 | break; // default: |
644 | } |
651 | } |
645 | // unlock the rxd buffer after processing |
652 | // unlock the rxd buffer after processing |
646 | pRxData = 0; |
653 | pRxData = 0; |
647 | RxDataLen = 0; |
654 | RxDataLen = 0; |
648 | rxd_buffer_locked = FALSE; |
655 | rxd_buffer_locked = FALSE; |
649 | } |
656 | } |
650 | 657 | ||
651 | /************************************************************************/ |
658 | /************************************************************************/ |
652 | /* Routine für die Serielle Ausgabe */ |
659 | /* Routine für die Serielle Ausgabe */ |
653 | /************************************************************************/ |
660 | /************************************************************************/ |
654 | int16_t uart_putchar(int8_t c) { |
661 | int16_t uart_putchar(int8_t c) { |
655 | if (c == '\n') |
662 | if (c == '\n') |
656 | uart_putchar('\r'); |
663 | uart_putchar('\r'); |
657 | // wait until previous character was send |
664 | // wait until previous character was send |
658 | loop_until_bit_is_set(UCSR0A, UDRE0); |
665 | loop_until_bit_is_set(UCSR0A, UDRE0); |
659 | // send character |
666 | // send character |
660 | UDR0 = c; |
667 | UDR0 = c; |
661 | return (0); |
668 | return (0); |
662 | } |
669 | } |
663 | 670 | ||
664 | //--------------------------------------------------------------------------------------------- |
671 | //--------------------------------------------------------------------------------------------- |
665 | void usart0_TransmitTxData(void) { |
672 | void usart0_TransmitTxData(void) { |
666 | if (!txd_complete) |
673 | if (!txd_complete) |
667 | return; |
674 | return; |
668 | 675 | ||
669 | if (request_VerInfo && txd_complete) { |
676 | if (request_VerInfo && txd_complete) { |
670 | SendOutData('V', FC_ADDRESS, 1, (uint8_t *) &UART_VersionInfo, |
677 | SendOutData('V', FC_ADDRESS, 1, (uint8_t *) &UART_VersionInfo, |
671 | sizeof(UART_VersionInfo)); |
678 | sizeof(UART_VersionInfo)); |
672 | request_VerInfo = FALSE; |
679 | request_VerInfo = FALSE; |
673 | } |
680 | } |
674 | 681 | ||
675 | if (request_Display && txd_complete) { |
682 | if (request_Display && txd_complete) { |
676 | LCD_PrintMenu(); |
683 | LCD_PrintMenu(); |
677 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), |
684 | SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), |
678 | &DisplayBuff[DisplayLine * 20], 20); |
685 | &DisplayBuff[DisplayLine * 20], 20); |
679 | DisplayLine++; |
686 | DisplayLine++; |
680 | if (DisplayLine >= 4) |
687 | if (DisplayLine >= 4) |
681 | DisplayLine = 0; |
688 | DisplayLine = 0; |
682 | request_Display = FALSE; |
689 | request_Display = FALSE; |
683 | } |
690 | } |
684 | 691 | ||
685 | if (request_Display1 && txd_complete) { |
692 | if (request_Display1 && txd_complete) { |
686 | LCD_PrintMenu(); |
693 | LCD_PrintMenu(); |
687 | SendOutData('L', FC_ADDRESS, 3, &MenuItem, sizeof(MenuItem), &MaxMenuItem, |
694 | SendOutData('L', FC_ADDRESS, 3, &MenuItem, sizeof(MenuItem), &MaxMenuItem, |
688 | sizeof(MaxMenuItem), DisplayBuff, sizeof(DisplayBuff)); |
695 | sizeof(MaxMenuItem), DisplayBuff, sizeof(DisplayBuff)); |
689 | request_Display1 = FALSE; |
696 | request_Display1 = FALSE; |
690 | } |
697 | } |
691 | 698 | ||
692 | if (request_DebugLabel != 0xFF) { // Texte für die Analogdaten |
699 | if (request_DebugLabel != 0xFF) { // Texte für die Analogdaten |
693 | uint8_t label[16]; // local sram buffer |
700 | uint8_t label[16]; // local sram buffer |
694 | memcpy_P(label, ANALOG_LABEL[request_DebugLabel], 16); // read lable from flash to sram buffer |
701 | memcpy_P(label, ANALOG_LABEL[request_DebugLabel], 16); // read lable from flash to sram buffer |
695 | SendOutData('A', FC_ADDRESS, 2, (uint8_t *) &request_DebugLabel, |
702 | SendOutData('A', FC_ADDRESS, 2, (uint8_t *) &request_DebugLabel, |
696 | sizeof(request_DebugLabel), label, 16); |
703 | sizeof(request_DebugLabel), label, 16); |
697 | request_DebugLabel = 0xFF; |
704 | request_DebugLabel = 0xFF; |
698 | } |
705 | } |
699 | 706 | ||
700 | if (ConfirmFrame && txd_complete) { // Datensatz ohne CRC bestätigen |
707 | if (ConfirmFrame && txd_complete) { // Datensatz ohne CRC bestätigen |
701 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*) &ConfirmFrame, |
708 | SendOutData('B', FC_ADDRESS, 1, (uint8_t*) &ConfirmFrame, |
702 | sizeof(ConfirmFrame)); |
709 | sizeof(ConfirmFrame)); |
703 | ConfirmFrame = 0; |
710 | ConfirmFrame = 0; |
704 | } |
711 | } |
705 | 712 | ||
706 | if (((DebugData_Interval && CheckDelay(DebugData_Timer)) || request_DebugData) |
713 | if (((DebugData_Interval && CheckDelay(DebugData_Timer)) || request_DebugData) |
707 | && txd_complete) { |
714 | && txd_complete) { |
708 | SendOutData('D', FC_ADDRESS, 1, (uint8_t *) &DebugOut, sizeof(DebugOut)); |
715 | SendOutData('D', FC_ADDRESS, 1, (uint8_t *) &DebugOut, sizeof(DebugOut)); |
709 | DebugData_Timer = SetDelay(DebugData_Interval); |
716 | DebugData_Timer = SetDelay(DebugData_Interval); |
710 | request_DebugData = FALSE; |
717 | request_DebugData = FALSE; |
711 | } |
718 | } |
712 | 719 | ||
713 | if (((Data3D_Interval && CheckDelay(Data3D_Timer)) || request_Data3D) |
720 | if (((Data3D_Interval && CheckDelay(Data3D_Timer)) || request_Data3D) |
714 | && txd_complete) { |
721 | && txd_complete) { |
715 | SendOutData('C', FC_ADDRESS, 1, (uint8_t *) &Data3D, sizeof(Data3D)); |
722 | SendOutData('C', FC_ADDRESS, 1, (uint8_t *) &Data3D, sizeof(Data3D)); |
716 | Data3D.AngleNick = (int16_t) ((10 * angle[PITCH]) |
723 | Data3D.AngleNick = (int16_t) ((10 * angle[PITCH]) |
717 | / GYRO_DEG_FACTOR_PITCHROLL); // convert to multiple of 0.1° |
724 | / GYRO_DEG_FACTOR_PITCHROLL); // convert to multiple of 0.1° |
718 | Data3D.AngleRoll = (int16_t) ((10 * angle[ROLL]) |
725 | Data3D.AngleRoll = (int16_t) ((10 * angle[ROLL]) |
719 | / GYRO_DEG_FACTOR_PITCHROLL); // convert to multiple of 0.1° |
726 | / GYRO_DEG_FACTOR_PITCHROLL); // convert to multiple of 0.1° |
720 | Data3D.Heading = (int16_t) ((10 * yawGyroHeading) / GYRO_DEG_FACTOR_YAW); // convert to multiple of 0.1° |
727 | Data3D.Heading = (int16_t) ((10 * yawGyroHeading) / GYRO_DEG_FACTOR_YAW); // convert to multiple of 0.1° |
721 | Data3D_Timer = SetDelay(Data3D_Interval); |
728 | Data3D_Timer = SetDelay(Data3D_Interval); |
722 | request_Data3D = FALSE; |
729 | request_Data3D = FALSE; |
723 | } |
730 | } |
724 | 731 | ||
725 | if (request_ExternalControl && txd_complete) { |
732 | if (request_ExternalControl && txd_complete) { |
726 | SendOutData('G', FC_ADDRESS, 1, (uint8_t *) &externalControl, |
733 | SendOutData('G', FC_ADDRESS, 1, (uint8_t *) &externalControl, |
727 | sizeof(externalControl)); |
734 | sizeof(externalControl)); |
728 | request_ExternalControl = FALSE; |
735 | request_ExternalControl = FALSE; |
729 | } |
736 | } |
730 | 737 | ||
731 | #ifdef USE_MK3MAG |
738 | #ifdef USE_MK3MAG |
732 | if((CheckDelay(Compass_Timer)) && txd_complete) { |
739 | if((CheckDelay(Compass_Timer)) && txd_complete) { |
733 | ToMk3Mag.Attitude[0] = (int16_t)((10 * angle[PITCH]) / GYRO_DEG_FACTOR_PITCHROLL); // approx. 0.1 deg |
740 | ToMk3Mag.Attitude[0] = (int16_t)((10 * angle[PITCH]) / GYRO_DEG_FACTOR_PITCHROLL); // approx. 0.1 deg |
734 | ToMk3Mag.Attitude[1] = (int16_t)((10 * angle[ROLL]) / GYRO_DEG_FACTOR_PITCHROLL); // approx. 0.1 deg |
741 | ToMk3Mag.Attitude[1] = (int16_t)((10 * angle[ROLL]) / GYRO_DEG_FACTOR_PITCHROLL); // approx. 0.1 deg |
735 | ToMk3Mag.UserParam[0] = dynamicParams.UserParams[0]; |
742 | ToMk3Mag.UserParam[0] = dynamicParams.UserParams[0]; |
736 | ToMk3Mag.UserParam[1] = dynamicParams.UserParams[1]; |
743 | ToMk3Mag.UserParam[1] = dynamicParams.UserParams[1]; |
737 | ToMk3Mag.CalState = compassCalState; |
744 | ToMk3Mag.CalState = compassCalState; |
738 | SendOutData('w', MK3MAG_ADDRESS, 1,(uint8_t *) &ToMk3Mag,sizeof(ToMk3Mag)); |
745 | SendOutData('w', MK3MAG_ADDRESS, 1,(uint8_t *) &ToMk3Mag,sizeof(ToMk3Mag)); |
739 | // the last state is 5 and should be send only once to avoid multiple flash writing |
746 | // the last state is 5 and should be send only once to avoid multiple flash writing |
740 | if(compassCalState > 4) compassCalState = 0; |
747 | if(compassCalState > 4) compassCalState = 0; |
741 | Compass_Timer = SetDelay(99); |
748 | Compass_Timer = SetDelay(99); |
742 | } |
749 | } |
743 | #endif |
750 | #endif |
744 | 751 | ||
745 | if (request_MotorTest && txd_complete) { |
752 | if (request_MotorTest && txd_complete) { |
746 | SendOutData('T', FC_ADDRESS, 0); |
753 | SendOutData('T', FC_ADDRESS, 0); |
747 | request_MotorTest = FALSE; |
754 | request_MotorTest = FALSE; |
748 | } |
755 | } |
749 | 756 | ||
750 | if (request_PPMChannels && txd_complete) { |
757 | if (request_PPMChannels && txd_complete) { |
751 | SendOutData('P', FC_ADDRESS, 1, (uint8_t *) &PPM_in, sizeof(PPM_in)); |
758 | SendOutData('P', FC_ADDRESS, 1, (uint8_t *) &PPM_in, sizeof(PPM_in)); |
752 | request_PPMChannels = FALSE; |
759 | request_PPMChannels = FALSE; |
753 | } |
760 | } |
754 | 761 | ||
755 | if (request_variables && txd_complete) { |
762 | if (request_variables && txd_complete) { |
756 | SendOutData('X', FC_ADDRESS, 1, (uint8_t *) &variables, sizeof(variables)); |
763 | SendOutData('X', FC_ADDRESS, 1, (uint8_t *) &variables, sizeof(variables)); |
757 | request_variables = FALSE; |
764 | request_variables = FALSE; |
758 | } |
765 | } |
759 | } |
766 | } |
760 | 767 |