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