Go to most recent revision | 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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
52 | #include "main.h" |
||
53 | |||
54 | unsigned char EEPromArray[E2END+1] EEMEM; |
||
173 | holgerb | 55 | unsigned char PlatinenVersion = 10; |
1 | ingob | 56 | |
57 | // -- Parametersatz aus EEPROM lesen --- |
||
683 | killagreg | 58 | // number [0..5] |
1 | ingob | 59 | void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
60 | { |
||
61 | if (number > 5) number = 5; |
||
62 | eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * number], length); |
||
63 | } |
||
64 | |||
65 | |||
66 | // -- Parametersatz ins EEPROM schreiben --- |
||
683 | killagreg | 67 | // number [0..5] |
1 | ingob | 68 | void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length) |
69 | { |
||
683 | killagreg | 70 | if(number > 5) number = 5; |
1 | ingob | 71 | eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * number], length); |
72 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number); // diesen Parametersatz als aktuell merken |
||
73 | } |
||
74 | |||
75 | unsigned char GetActiveParamSetNumber(void) |
||
76 | { |
||
173 | holgerb | 77 | unsigned char set; |
78 | set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]); |
||
683 | killagreg | 79 | if(set > 5) |
80 | { |
||
81 | set = 2; |
||
173 | holgerb | 82 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], set); // diesen Parametersatz als aktuell merken |
683 | killagreg | 83 | } |
173 | holgerb | 84 | return(set); |
1 | ingob | 85 | } |
86 | |||
87 | //############################################################################ |
||
88 | //Hauptprogramm |
||
89 | int main (void) |
||
90 | //############################################################################ |
||
91 | { |
||
92 | unsigned int timer; |
||
296 | holgerb | 93 | |
683 | killagreg | 94 | // disable interrupts global |
95 | cli(); |
||
96 | |||
97 | DDRB = 0x00; |
||
98 | PORTB = 0x00; |
||
99 | for(timer = 0; timer < 1000; timer++); // make delay |
||
173 | holgerb | 100 | if(PINB & 0x01) PlatinenVersion = 11; else PlatinenVersion = 10; |
683 | killagreg | 101 | DDRC = 0x81; // SCL & Speaker |
1 | ingob | 102 | PORTC = 0xff; // Pullup SDA |
103 | DDRB = 0x1B; // LEDs und Druckoffset |
||
104 | PORTB = 0x01; // LED_Rot |
||
105 | DDRD = 0x3E; // Speaker & TXD & J3 J4 J5 |
||
106 | DDRD |=0x80; // J7 |
||
683 | killagreg | 107 | |
1 | ingob | 108 | PORTD = 0xF7; // LED |
683 | killagreg | 109 | |
110 | |||
1 | ingob | 111 | MCUSR &=~(1<<WDRF); |
112 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
||
113 | WDTCSR = 0; |
||
114 | |||
683 | killagreg | 115 | BeepTime = 2000; |
1 | ingob | 116 | |
683 | killagreg | 117 | PPM_in[K_GAS] = 0; |
118 | StickGier = 0; |
||
119 | StickRoll = 0; |
||
120 | StickNick = 0; |
||
1 | ingob | 121 | |
122 | ROT_OFF; |
||
683 | killagreg | 123 | |
124 | TIMER0_Init(); |
||
125 | TIMER2_Init(); |
||
126 | USART0_Init(); |
||
127 | USART1_Init(); |
||
1 | ingob | 128 | rc_sum_init(); |
129 | ADC_Init(); |
||
130 | i2c_init(); |
||
683 | killagreg | 131 | //SPI_MasterInit(); |
132 | |||
133 | // enable interrupts global |
||
1 | ingob | 134 | sei(); |
135 | |||
136 | VersionInfo.Hauptversion = VERSION_HAUPTVERSION; |
||
137 | VersionInfo.Nebenversion = VERSION_NEBENVERSION; |
||
138 | VersionInfo.PCKompatibel = VERSION_KOMPATIBEL; |
||
683 | killagreg | 139 | |
296 | holgerb | 140 | printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",PlatinenVersion/10,PlatinenVersion%10, VERSION_HAUPTVERSION, VERSION_NEBENVERSION,VERSION_INDEX + 'a'); |
1 | ingob | 141 | printf("\n\r=============================="); |
142 | GRN_ON; |
||
143 | |||
604 | hbuss | 144 | #define EE_DATENREVISION 69 // wird angepasst, wenn sich die EEPROM-Daten geändert haben |
683 | killagreg | 145 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION) |
146 | { |
||
1 | ingob | 147 | printf("\n\rInit. EEPROM: Generiere Default-Parameter..."); |
148 | DefaultKonstanten1(); |
||
683 | killagreg | 149 | for (unsigned char i=0;i<6;i++) |
1 | ingob | 150 | { |
395 | hbuss | 151 | if(i==2) DefaultKonstanten2(); // Kamera |
152 | if(i==3) DefaultKonstanten3(); // Beginner |
||
153 | if(i>3) DefaultKonstanten2(); // Kamera |
||
1 | ingob | 154 | WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
683 | killagreg | 155 | } |
395 | hbuss | 156 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], 3); // default-Setting |
173 | holgerb | 157 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION); |
1 | ingob | 158 | } |
513 | hbuss | 159 | |
683 | killagreg | 160 | if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4) |
513 | hbuss | 161 | { |
162 | printf("\n\rACC nicht abgeglichen!"); |
||
163 | } |
||
683 | killagreg | 164 | |
1 | ingob | 165 | ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE); |
166 | printf("\n\rBenutze Parametersatz %d", GetActiveParamSetNumber()); |
||
167 | |||
683 | killagreg | 168 | |
1 | ingob | 169 | if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
683 | killagreg | 170 | { |
1 | ingob | 171 | printf("\n\rAbgleich Luftdrucksensor.."); |
683 | killagreg | 172 | timer = SetDelay(1000); |
1 | ingob | 173 | SucheLuftruckOffset(); |
174 | while (!CheckDelay(timer)); |
||
175 | printf("OK\n\r"); |
||
176 | } |
||
683 | killagreg | 177 | |
1 | ingob | 178 | SetNeutral(); |
179 | |||
180 | ROT_OFF; |
||
181 | |||
683 | killagreg | 182 | BeepTime = 2000; |
183 | ExternControl.Digital[0] = 0x55; |
||
184 | |||
185 | |||
1 | ingob | 186 | printf("\n\rSteuerung: "); |
187 | if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold"); |
||
188 | else printf("Neutral"); |
||
683 | killagreg | 189 | |
1 | ingob | 190 | printf("\n\n\r"); |
683 | killagreg | 191 | |
1 | ingob | 192 | LcdClear(); |
173 | holgerb | 193 | I2CTimeout = 5000; |
1 | ingob | 194 | while (1) |
195 | { |
||
604 | hbuss | 196 | if(UpdateMotor) // ReglerIntervall |
683 | killagreg | 197 | { |
597 | ingob | 198 | SPI_TransmitByte(); //# |
683 | killagreg | 199 | UpdateMotor=0; |
419 | hbuss | 200 | //PORTD |= 0x08; |
683 | killagreg | 201 | MotorRegler(); |
604 | hbuss | 202 | |
419 | hbuss | 203 | //PORTD &= ~0x08; |
1 | ingob | 204 | SendMotorData(); |
205 | ROT_OFF; |
||
683 | killagreg | 206 | if(PcZugriff) PcZugriff--; |
207 | else |
||
492 | hbuss | 208 | { |
683 | killagreg | 209 | DubWiseKeys[0] = 0; |
492 | hbuss | 210 | DubWiseKeys[1] = 0; |
595 | hbuss | 211 | ExternControl.Config = 0; |
492 | hbuss | 212 | ExternStickNick = 0; |
213 | ExternStickRoll = 0; |
||
214 | ExternStickGier = 0; |
||
215 | } |
||
1 | ingob | 216 | if(SenderOkay) SenderOkay--; |
173 | holgerb | 217 | if(!I2CTimeout) |
218 | { |
||
219 | I2CTimeout = 5; |
||
220 | i2c_reset(); |
||
683 | killagreg | 221 | if((BeepModulation == 0xFFFF) && MotorenEin) |
222 | { |
||
223 | BeepTime = 10000; // 1 second |
||
224 | BeepModulation = 0x0080; |
||
225 | } |
||
1 | ingob | 226 | } |
683 | killagreg | 227 | else |
1 | ingob | 228 | { |
173 | holgerb | 229 | I2CTimeout--; |
683 | killagreg | 230 | ROT_OFF; |
1 | ingob | 231 | } |
604 | hbuss | 232 | if(SIO_DEBUG && !UpdateMotor) |
1 | ingob | 233 | { |
234 | DatenUebertragung(); |
||
235 | BearbeiteRxDaten(); |
||
236 | } |
||
237 | else BearbeiteRxDaten(); |
||
173 | holgerb | 238 | if(CheckDelay(timer)) |
683 | killagreg | 239 | { |
173 | holgerb | 240 | if(UBat < EE_Parameter.UnterspannungsWarnung) |
683 | killagreg | 241 | { |
242 | if(BeepModulation == 0xFFFF) |
||
243 | { |
||
244 | BeepTime = 6000; // 0.6 seconds |
||
245 | BeepModulation = 0x0300; |
||
246 | } |
||
173 | holgerb | 247 | } |
597 | ingob | 248 | SPI_StartTransmitPacket();//# |
683 | killagreg | 249 | timer = SetDelay(100); |
250 | } |
||
623 | hbuss | 251 | //if(UpdateMotor) DebugOut.Analog[26]++; |
604 | hbuss | 252 | } |
1 | ingob | 253 | } |
254 | return (1); |
||
255 | } |
||
256 |