Rev 1964 | Rev 1975 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1964 | Rev 1969 | ||
---|---|---|---|
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 example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
35 | // + Commercial use (for example: 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/boot.h> |
53 | #include <avr/boot.h> |
54 | #include <avr/io.h> |
54 | #include <avr/io.h> |
55 | #include <avr/interrupt.h> |
55 | #include <avr/interrupt.h> |
56 | #include <util/delay.h> |
56 | #include <util/delay.h> |
57 | 57 | ||
58 | #include "timer0.h" |
58 | #include "timer0.h" |
59 | #include "timer2.h" |
59 | #include "timer2.h" |
60 | #include "uart0.h" |
60 | #include "uart0.h" |
61 | #include "uart1.h" |
61 | #include "uart1.h" |
62 | #include "output.h" |
62 | #include "output.h" |
63 | #include "menu.h" |
63 | #include "menu.h" |
64 | #include "attitude.h" |
64 | #include "attitude.h" |
65 | #include "flight.h" |
65 | #include "flight.h" |
66 | #include "rc.h" |
66 | #include "rc.h" |
67 | #include "analog.h" |
67 | #include "analog.h" |
68 | #include "configuration.h" |
68 | #include "configuration.h" |
69 | #include "printf_P.h" |
69 | #include "printf_P.h" |
70 | #include "twimaster.h" |
70 | #include "twimaster.h" |
- | 71 | #include "controlMixer.h" |
|
71 | #ifdef USE_NAVICTRL |
72 | #ifdef USE_NAVICTRL |
72 | #include "spi.h" |
73 | #include "spi.h" |
73 | #endif |
74 | #endif |
74 | #ifdef USE_MK3MAG |
75 | #ifdef USE_MK3MAG |
75 | #include "mk3mag.h" |
76 | #include "mk3mag.h" |
76 | #endif |
77 | #endif |
77 | #include "eeprom.h" |
78 | #include "eeprom.h" |
78 | 79 | ||
79 | int16_t main(void) { |
80 | int16_t main(void) { |
80 | uint16_t timer; |
81 | uint16_t timer; |
81 | 82 | ||
82 | // disable interrupts global |
83 | // disable interrupts global |
83 | cli(); |
84 | cli(); |
84 | 85 | ||
85 | // analyze hardware environment |
86 | // analyze hardware environment |
86 | CPUType = getCPUType(); |
87 | CPUType = getCPUType(); |
87 | boardRelease = getBoardRelease(); |
88 | boardRelease = getBoardRelease(); |
88 | 89 | ||
89 | // disable watchdog |
90 | // disable watchdog |
90 | MCUSR &= ~(1 << WDRF); |
91 | MCUSR &= ~(1 << WDRF); |
91 | WDTCSR |= (1 << WDCE) | (1 << WDE); |
92 | WDTCSR |= (1 << WDCE) | (1 << WDE); |
92 | WDTCSR = 0; |
93 | WDTCSR = 0; |
- | 94 | ||
- | 95 | // This is strange: It should NOT be necessarty to do. But the call of the same, |
|
- | 96 | // in channelMap_readOrDefault (if eeprom read fails) just sets all to 0,0,0,.... |
|
- | 97 | channelMap_default(); |
|
93 | 98 | ||
94 | // initalize modules |
99 | // initalize modules |
95 | output_init(); |
100 | output_init(); |
96 | timer0_init(); |
101 | timer0_init(); |
97 | timer2_init(); |
102 | timer2_init(); |
98 | usart0_Init(); |
103 | usart0_Init(); |
99 | if (CPUType == ATMEGA644P);// usart1_Init(); |
104 | if (CPUType == ATMEGA644P);// usart1_Init(); |
100 | RC_Init(); |
105 | RC_Init(); |
101 | analog_init(); |
106 | analog_init(); |
102 | I2C_init(); |
107 | I2C_init(); |
103 | #ifdef USE_NAVICTRL |
108 | #ifdef USE_NAVICTRL |
104 | SPI_MasterInit(); |
109 | SPI_MasterInit(); |
105 | #endif |
110 | #endif |
106 | #ifdef USE_MK3MAG |
111 | #ifdef USE_MK3MAG |
107 | MK3MAG_Init(); |
112 | MK3MAG_Init(); |
108 | #endif |
113 | #endif |
- | 114 | ||
- | 115 | // Parameter Set handling |
|
- | 116 | channelMap_readOrDefault(); |
|
- | 117 | mixerMatrix_readOrDefault(); |
|
- | 118 | paramSet_readOrDefault(); |
|
109 | 119 | ||
110 | // enable interrupts global |
120 | // enable interrupts global |
111 | sei(); |
121 | sei(); |
112 | 122 | ||
113 | printf("\n\r==================================="); |
123 | printf("\n\r==================================="); |
114 | printf("\n\rFlightControl"); |
124 | printf("\n\rFlightControl"); |
115 | printf("\n\rHardware: Custom"); |
125 | printf("\n\rHardware: Custom"); |
116 | printf("\n\r CPU: Atmega644"); |
126 | printf("\n\r CPU: Atmega644"); |
117 | if (CPUType == ATMEGA644P) |
127 | if (CPUType == ATMEGA644P) |
118 | printf("p"); |
128 | printf("p"); |
119 | printf("\n\rSoftware: V%d.%d%c",VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a'); |
129 | printf("\n\rSoftware: V%d.%d%c",VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a'); |
120 | printf("\n\r==================================="); |
130 | printf("\n\r==================================="); |
121 | - | ||
122 | // Parameter Set handling |
- | |
123 | channelMap_readOrDefault(); |
- | |
124 | mixerMatrix_readOrDefault(); |
- | |
125 | paramSet_readOrDefault(); |
- | |
126 | 131 | ||
127 | // Wait for a short time (otherwise the RC channel check won't work below) |
132 | // Wait for a short time (otherwise the RC channel check won't work below) |
128 | // timer = SetDelay(500); |
133 | // timer = SetDelay(500); |
129 | // while(!CheckDelay(timer)); |
134 | // while(!CheckDelay(timer)); |
130 | 135 | ||
131 | // Instead, while away the time by flashing the 2 outputs: |
136 | // Instead, while away the time by flashing the 2 outputs: |
132 | // First J16, then J17. Makes it easier to see which is which. |
137 | // First J16, then J17. Makes it easier to see which is which. |
133 | timer = setDelay(200); |
138 | timer = setDelay(200); |
134 | outputSet(0,1); |
139 | outputSet(0,1); |
135 | GRN_OFF; |
140 | GRN_OFF; |
136 | RED_ON; |
141 | RED_ON; |
137 | while (!checkDelay(timer)) |
142 | while (!checkDelay(timer)) |
138 | ; |
143 | ; |
139 | 144 | ||
140 | timer = setDelay(200); |
145 | timer = setDelay(200); |
141 | outputSet(0,0); |
146 | outputSet(0,0); |
142 | outputSet(1,1); |
147 | outputSet(1,1); |
143 | RED_OFF; |
148 | RED_OFF; |
144 | GRN_ON; |
149 | GRN_ON; |
145 | while (!checkDelay(timer)) |
150 | while (!checkDelay(timer)) |
146 | ; |
151 | ; |
147 | 152 | ||
148 | timer = setDelay(200); |
153 | timer = setDelay(200); |
149 | while (!checkDelay(timer)) |
154 | while (!checkDelay(timer)) |
150 | ; |
155 | ; |
151 | outputSet(1,0); |
156 | outputSet(1,0); |
152 | GRN_OFF; |
157 | GRN_OFF; |
153 | 158 | ||
154 | twi_diagnostics(); |
159 | twi_diagnostics(); |
155 | 160 | ||
156 | printf("\n\r==================================="); |
161 | printf("\n\r==================================="); |
157 | 162 | ||
158 | #ifdef USE_NAVICTRL |
163 | #ifdef USE_NAVICTRL |
159 | printf("\n\rSupport for NaviCtrl"); |
164 | printf("\n\rSupport for NaviCtrl"); |
160 | #ifdef USE_RC_DSL |
165 | #ifdef USE_RC_DSL |
161 | printf("\r\nSupport for DSL RC at 2nd UART"); |
166 | printf("\r\nSupport for DSL RC at 2nd UART"); |
162 | #endif |
167 | #endif |
163 | #ifdef USE_RC_SPECTRUM |
168 | #ifdef USE_RC_SPECTRUM |
164 | printf("\r\nSupport for SPECTRUM RC at 2nd UART"); |
169 | printf("\r\nSupport for SPECTRUM RC at 2nd UART"); |
165 | #endif |
170 | #endif |
166 | #endif |
171 | #endif |
167 | 172 | ||
168 | #ifdef USE_MK3MAG |
173 | #ifdef USE_MK3MAG |
169 | printf("\n\rSupport for MK3MAG Compass"); |
174 | printf("\n\rSupport for MK3MAG Compass"); |
170 | #endif |
175 | #endif |
171 | 176 | ||
172 | #if (defined (USE_MK3MAG)) |
177 | #if (defined (USE_MK3MAG)) |
173 | if(CPUType == ATMEGA644P) printf("\n\r2 UART"); |
178 | if(CPUType == ATMEGA644P) printf("\n\r2 UART"); |
174 | else printf("\n\r1 UART"); |
179 | else printf("\n\r1 UART"); |
175 | #endif |
180 | #endif |
176 | 181 | ||
177 | controlMixer_setNeutral(); |
182 | controlMixer_setNeutral(); |
178 | 183 | ||
179 | // Cal. attitude sensors and reset integrals. |
184 | // Cal. attitude sensors and reset integrals. |
180 | attitude_setNeutral(); |
185 | attitude_setNeutral(); |
181 | 186 | ||
182 | Servo_On(); |
187 | Servo_On(); |
183 | 188 | ||
184 | // Init flight parameters |
189 | // Init flight parameters |
185 | flight_setNeutral(); |
190 | flight_setNeutral(); |
186 | 191 | ||
187 | beep(2000); |
192 | beep(2000); |
188 | 193 | ||
189 | printf("\n\rControl: "); |
194 | printf("\n\rControl: "); |
190 | if (staticParams.bitConfig & CFG_HEADING_HOLD) |
195 | if (staticParams.bitConfig & CFG_HEADING_HOLD) |
191 | printf("HeadingHold"); |
196 | printf("HeadingHold"); |
192 | else printf("Neutral (ACC-Mode)"); |
197 | else printf("Neutral (ACC-Mode)"); |
193 | 198 | ||
194 | printf("\n\n\r"); |
199 | printf("\n\n\r"); |
195 | 200 | ||
196 | LCD_Clear(); |
201 | LCD_Clear(); |
197 | 202 | ||
198 | I2CTimeout = 5000; |
203 | I2CTimeout = 5000; |
199 | 204 | ||
200 | while (1) { |
205 | while (1) { |
201 | if (runFlightControl) { // control interval |
206 | if (runFlightControl) { // control interval |
202 | runFlightControl = 0; // reset Flag, is enabled every 2 ms by ISR of timer0 |
207 | runFlightControl = 0; // reset Flag, is enabled every 2 ms by ISR of timer0 |
203 | if (!analogDataReady) { |
208 | if (!analogDataReady) { |
204 | debugOut.digital[0] |= DEBUG_MAINLOOP_TIMER; |
209 | debugOut.digital[0] |= DEBUG_MAINLOOP_TIMER; |
205 | } else { |
210 | } else { |
206 | debugOut.digital[0] &= ~DEBUG_MAINLOOP_TIMER; |
211 | debugOut.digital[0] &= ~DEBUG_MAINLOOP_TIMER; |
207 | 212 | ||
208 | J4HIGH; |
213 | J4HIGH; |
209 | flight_control(); |
214 | flight_control(); |
210 | J4LOW; |
215 | J4LOW; |
211 | 216 | ||
212 | if (!--I2CTimeout || missingMotor) { // try to reset the i2c if motor is missing or timeout |
217 | if (!--I2CTimeout || missingMotor) { // try to reset the i2c if motor is missing or timeout |
213 | if (!I2CTimeout) { |
218 | if (!I2CTimeout) { |
214 | I2C_Reset(); |
219 | I2C_Reset(); |
215 | I2CTimeout = 5; |
220 | I2CTimeout = 5; |
216 | } |
221 | } |
217 | } |
222 | } |
218 | 223 | ||
219 | // Allow Serial Data Transmit if motors must not updated or motors are not running |
224 | // Allow Serial Data Transmit if motors must not updated or motors are not running |
220 | if (!runFlightControl || !(MKFlags & MKFLAG_MOTOR_RUN)) { |
225 | if (!runFlightControl || !(MKFlags & MKFLAG_MOTOR_RUN)) { |
221 | usart0_TransmitTxData(); |
226 | usart0_TransmitTxData(); |
222 | } |
227 | } |
223 | 228 | ||
224 | usart0_ProcessRxData(); |
229 | usart0_ProcessRxData(); |
225 | 230 | ||
226 | if (checkDelay(timer)) { |
231 | if (checkDelay(timer)) { |
227 | if (UBat <= UBAT_AT_5V) { |
232 | if (UBat <= UBAT_AT_5V) { |
228 | // Do nothing. The voltage on the input side of the regulator is <5V; |
233 | // Do nothing. The voltage on the input side of the regulator is <5V; |
229 | // we must be running off USB power. Keep it quiet. |
234 | // we must be running off USB power. Keep it quiet. |
230 | } else if (UBat < staticParams.batteryVoltageWarning) { |
235 | } else if (UBat < staticParams.batteryVoltageWarning) { |
231 | beepBatteryAlarm(); |
236 | beepBatteryAlarm(); |
232 | } |
237 | } |
233 | 238 | ||
234 | #ifdef USE_NAVICTRL |
239 | #ifdef USE_NAVICTRL |
235 | SPI_StartTransmitPacket(); |
240 | SPI_StartTransmitPacket(); |
236 | SendSPI = 4; |
241 | SendSPI = 4; |
237 | #endif |
242 | #endif |
238 | timer = setDelay(20); // every 20 ms |
243 | timer = setDelay(20); // every 20 ms |
239 | } |
244 | } |
240 | output_update(); |
245 | output_update(); |
241 | } |
246 | } |
242 | 247 | ||
243 | #ifdef USE_NAVICTRL |
248 | #ifdef USE_NAVICTRL |
244 | if(!SendSPI) { |
249 | if(!SendSPI) { |
245 | // SendSPI is decremented in timer0.c with a rate of 9.765 kHz. |
250 | // SendSPI is decremented in timer0.c with a rate of 9.765 kHz. |
246 | // within the SPI_TransmitByte() routine the value is set to 4. |
251 | // within the SPI_TransmitByte() routine the value is set to 4. |
247 | // I.e. the SPI_TransmitByte() is called at a rate of 9.765 kHz/4= 2441.25 Hz, |
252 | // I.e. the SPI_TransmitByte() is called at a rate of 9.765 kHz/4= 2441.25 Hz, |
248 | // and therefore the time of transmission of a complete spi-packet (32 bytes) is 32*4/9.765 kHz = 13.1 ms. |
253 | // and therefore the time of transmission of a complete spi-packet (32 bytes) is 32*4/9.765 kHz = 13.1 ms. |
249 | SPI_TransmitByte(); |
254 | SPI_TransmitByte(); |
250 | } |
255 | } |
251 | #endif |
256 | #endif |
252 | } |
257 | } |
253 | } |
258 | } |
254 | return (1); |
259 | return (1); |
255 | } |
260 | } |
256 | 261 |