Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
||
3 | // + Nur für den privaten Gebrauch |
||
4 | // + www.MikroKopter.com |
||
5 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
683 | killagreg | 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. |
||
8 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
||
9 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
||
1 | ingob | 10 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
11 | // + Verkauf von Luftbildaufnahmen, usw. |
||
12 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
683 | killagreg | 13 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
1 | ingob | 14 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
15 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
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" |
||
18 | // + eindeutig als Ursprung verlinkt und genannt werden |
||
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
20 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
21 | // + Benutzung auf eigene Gefahr |
||
22 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
683 | killagreg | 24 | // + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
1 | ingob | 25 | // + mit unserer Zustimmung zulässig |
26 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
27 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
28 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
683 | killagreg | 29 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
1 | ingob | 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 |
||
32 | // + from this software without specific prior written permission. |
||
683 | killagreg | 33 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet |
1 | ingob | 34 | // + for non-commercial use (directly or indirectly) |
683 | killagreg | 35 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
1 | ingob | 36 | // + with our written permission |
683 | killagreg | 37 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
38 | // + clearly linked as origin |
||
1 | ingob | 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" |
||
41 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
42 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
43 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
44 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
45 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
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 |
||
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 |
||
683 | killagreg | 50 | // + POSSIBILITY OF SUCH DAMAGE. |
1 | ingob | 51 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
687 | killagreg | 52 | #include <avr/boot.h> |
53 | |||
54 | #include <avr/io.h> |
||
55 | #include <avr/interrupt.h> |
||
56 | |||
1 | ingob | 57 | #include "main.h" |
685 | killagreg | 58 | #include "timer0.h" |
59 | #include "timer2.h" |
||
60 | #include "uart.h" |
||
61 | #include "uart1.h" |
||
62 | #include "menu.h" |
||
63 | #include "fc.h" |
||
64 | #include "rc.h" |
||
65 | #include "analog.h" |
||
66 | #include "printf_P.h" |
||
67 | #include "spi.h" |
||
68 | #include "twimaster.h" |
||
69 | #include "eeprom.h" |
||
70 | #include "_Settings.h" |
||
1 | ingob | 71 | |
72 | |||
687 | killagreg | 73 | |
685 | killagreg | 74 | uint8_t BoardRelease = 10; |
75 | |||
1 | ingob | 76 | |
77 | //############################################################################ |
||
78 | //Hauptprogramm |
||
79 | int main (void) |
||
80 | //############################################################################ |
||
81 | { |
||
82 | unsigned int timer; |
||
296 | holgerb | 83 | |
683 | killagreg | 84 | // disable interrupts global |
85 | cli(); |
||
86 | |||
87 | DDRB = 0x00; |
||
88 | PORTB = 0x00; |
||
89 | for(timer = 0; timer < 1000; timer++); // make delay |
||
685 | killagreg | 90 | |
91 | |||
92 | if(PINB & 0x01) BoardRelease = 11; |
||
93 | else BoardRelease = 10; |
||
94 | |||
683 | killagreg | 95 | DDRC = 0x81; // SCL & Speaker |
1 | ingob | 96 | PORTC = 0xff; // Pullup SDA |
97 | DDRB = 0x1B; // LEDs und Druckoffset |
||
98 | PORTB = 0x01; // LED_Rot |
||
99 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
||
100 | DDRD |=0x80; // J7 |
||
683 | killagreg | 101 | |
1 | ingob | 102 | PORTD = 0xF7; // LED |
683 | killagreg | 103 | |
104 | |||
1 | ingob | 105 | MCUSR &=~(1<<WDRF); |
106 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
||
107 | WDTCSR = 0; |
||
108 | |||
683 | killagreg | 109 | BeepTime = 2000; |
1 | ingob | 110 | |
690 | killagreg | 111 | PPM_in[CH_GAS] = 0; |
683 | killagreg | 112 | StickGier = 0; |
113 | StickRoll = 0; |
||
114 | StickNick = 0; |
||
1 | ingob | 115 | |
116 | ROT_OFF; |
||
683 | killagreg | 117 | |
118 | TIMER0_Init(); |
||
119 | TIMER2_Init(); |
||
120 | USART0_Init(); |
||
121 | USART1_Init(); |
||
1 | ingob | 122 | rc_sum_init(); |
123 | ADC_Init(); |
||
124 | i2c_init(); |
||
683 | killagreg | 125 | //SPI_MasterInit(); |
126 | |||
127 | // enable interrupts global |
||
1 | ingob | 128 | sei(); |
129 | |||
130 | VersionInfo.Hauptversion = VERSION_HAUPTVERSION; |
||
131 | VersionInfo.Nebenversion = VERSION_NEBENVERSION; |
||
132 | VersionInfo.PCKompatibel = VERSION_KOMPATIBEL; |
||
683 | killagreg | 133 | |
685 | killagreg | 134 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",BoardRelease/10,BoardRelease%10, VERSION_HAUPTVERSION, VERSION_NEBENVERSION,VERSION_INDEX + 'a'); |
1 | ingob | 135 | printf("\n\r=============================="); |
136 | GRN_ON; |
||
137 | |||
687 | killagreg | 138 | // Parameter set handling |
139 | ParamSet_Init(); |
||
513 | hbuss | 140 | |
687 | killagreg | 141 | if(GetParamByte(PID_ACC_NICK) > 4) |
513 | hbuss | 142 | { |
143 | printf("\n\rACC nicht abgeglichen!"); |
||
144 | } |
||
683 | killagreg | 145 | |
1 | ingob | 146 | |
690 | killagreg | 147 | if(ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL) |
683 | killagreg | 148 | { |
1 | ingob | 149 | printf("\n\rAbgleich Luftdrucksensor.."); |
683 | killagreg | 150 | timer = SetDelay(1000); |
1 | ingob | 151 | SucheLuftruckOffset(); |
152 | while (!CheckDelay(timer)); |
||
153 | printf("OK\n\r"); |
||
154 | } |
||
683 | killagreg | 155 | |
1 | ingob | 156 | SetNeutral(); |
157 | |||
158 | ROT_OFF; |
||
159 | |||
683 | killagreg | 160 | BeepTime = 2000; |
161 | ExternControl.Digital[0] = 0x55; |
||
162 | |||
163 | |||
1 | ingob | 164 | printf("\n\rSteuerung: "); |
687 | killagreg | 165 | if (ParamSet.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
1 | ingob | 166 | else printf("Neutral"); |
683 | killagreg | 167 | |
1 | ingob | 168 | printf("\n\n\r"); |
683 | killagreg | 169 | |
685 | killagreg | 170 | LCD_Clear(); |
173 | holgerb | 171 | I2CTimeout = 5000; |
1 | ingob | 172 | while (1) |
173 | { |
||
604 | hbuss | 174 | if(UpdateMotor) // ReglerIntervall |
683 | killagreg | 175 | { |
597 | ingob | 176 | SPI_TransmitByte(); //# |
683 | killagreg | 177 | UpdateMotor=0; |
419 | hbuss | 178 | //PORTD |= 0x08; |
683 | killagreg | 179 | MotorRegler(); |
604 | hbuss | 180 | |
419 | hbuss | 181 | //PORTD &= ~0x08; |
1 | ingob | 182 | SendMotorData(); |
183 | ROT_OFF; |
||
683 | killagreg | 184 | if(PcZugriff) PcZugriff--; |
185 | else |
||
492 | hbuss | 186 | { |
683 | killagreg | 187 | DubWiseKeys[0] = 0; |
492 | hbuss | 188 | DubWiseKeys[1] = 0; |
595 | hbuss | 189 | ExternControl.Config = 0; |
492 | hbuss | 190 | ExternStickNick = 0; |
191 | ExternStickRoll = 0; |
||
192 | ExternStickGier = 0; |
||
193 | } |
||
688 | killagreg | 194 | if(SenderOkay) SenderOkay--; |
195 | if(!I2CTimeout) |
||
173 | holgerb | 196 | { |
197 | I2CTimeout = 5; |
||
198 | i2c_reset(); |
||
683 | killagreg | 199 | if((BeepModulation == 0xFFFF) && MotorenEin) |
200 | { |
||
201 | BeepTime = 10000; // 1 second |
||
202 | BeepModulation = 0x0080; |
||
203 | } |
||
1 | ingob | 204 | } |
683 | killagreg | 205 | else |
1 | ingob | 206 | { |
173 | holgerb | 207 | I2CTimeout--; |
683 | killagreg | 208 | ROT_OFF; |
1 | ingob | 209 | } |
604 | hbuss | 210 | if(SIO_DEBUG && !UpdateMotor) |
1 | ingob | 211 | { |
212 | DatenUebertragung(); |
||
213 | BearbeiteRxDaten(); |
||
214 | } |
||
215 | else BearbeiteRxDaten(); |
||
173 | holgerb | 216 | if(CheckDelay(timer)) |
683 | killagreg | 217 | { |
690 | killagreg | 218 | if(UBat < ParamSet.LowVoltageWarning) |
683 | killagreg | 219 | { |
220 | if(BeepModulation == 0xFFFF) |
||
221 | { |
||
222 | BeepTime = 6000; // 0.6 seconds |
||
223 | BeepModulation = 0x0300; |
||
224 | } |
||
173 | holgerb | 225 | } |
597 | ingob | 226 | SPI_StartTransmitPacket();//# |
683 | killagreg | 227 | timer = SetDelay(100); |
228 | } |
||
623 | hbuss | 229 | //if(UpdateMotor) DebugOut.Analog[26]++; |
604 | hbuss | 230 | } |
1 | ingob | 231 | } |
232 | return (1); |
||
233 | } |
||
234 |