Rev 489 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
119 | killagreg | 1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
||
3 | /*#######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + www.MikroKopter.com |
||
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
360 | holgerb | 7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
||
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
||
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
||
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
||
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
||
119 | killagreg | 13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
360 | holgerb | 14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
||
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
||
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
||
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
||
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
||
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
||
22 | // + des Mitverschuldens offen. |
||
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
||
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
||
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
||
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
||
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
||
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
||
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
||
119 | killagreg | 31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
360 | holgerb | 32 | // + Software LICENSING TERMS |
119 | killagreg | 33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
360 | holgerb | 34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
||
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
||
37 | // + The Software may only be used with the Licensor's products. |
||
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
||
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
||
40 | // + agreement shall be the property of the Licensor. |
||
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
||
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
||
43 | // + The customer shall be responsible for taking reasonable precautions |
||
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
||
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
||
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
||
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
||
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
||
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
||
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
||
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
||
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
||
53 | // + #### END OF LICENSING TERMS #### |
||
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
||
119 | killagreg | 55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | #include "91x_lib.h" |
||
57 | #include "timer1.h" |
||
58 | #include "uart1.h" |
||
136 | killagreg | 59 | #include "config.h" |
362 | holgerb | 60 | #include "main.h" |
378 | holgerb | 61 | #include "led.h" |
119 | killagreg | 62 | |
63 | u32 CountMilliseconds; |
||
64 | DateTime_t SystemTime; |
||
679 | holgerb | 65 | /* |
66 | void CountInput(void) |
||
67 | { |
||
68 | static u8 p63 = 1, p64 = 0, p65 = 1; |
||
69 | if(!PIN6_3) { if(p63) DebugOut.Analog[]++; p63 = 0; } else p63 = 1; |
||
70 | if(!PIN6_4) { if(p64) DebugOut.Analog[]++; p64 = 0; } else p64 = 1; |
||
71 | if(!PIN6_5) { if(p65) DebugOut.Analog[]++; p65 = 0; } else p65 = 1; |
||
72 | } |
||
73 | */ |
||
119 | killagreg | 74 | |
75 | //---------------------------------------------------------------------------------------------------- |
||
76 | void TIM1_IRQHandler(void) |
||
77 | { |
||
378 | holgerb | 78 | // IENABLE; |
119 | killagreg | 79 | if(TIM_GetFlagStatus(TIM1, TIM_FLAG_OC1) == SET) |
80 | { |
||
154 | killagreg | 81 | TIM_ClearFlag(TIM1, TIM_FLAG_OC1); // clear irq pending bit |
119 | killagreg | 82 | TIM1->OC1R += 200; // Timerfreq is 200kHz, generate an interrupt every 1ms |
83 | CountMilliseconds++; |
||
362 | holgerb | 84 | if(SD_WatchDog) SD_WatchDog--; |
378 | holgerb | 85 | if(SPIWatchDog) SPIWatchDog--; |
86 | if(PollingTimeout) PollingTimeout--; |
||
679 | holgerb | 87 | //CountInput(); |
154 | killagreg | 88 | // generate SW Interrupt to make a regular timing |
195 | killagreg | 89 | // independent from the mainloop at the lowest IRQ priority |
489 | killagreg | 90 | VIC_SWITCmd(EXTIT3_ITLine, ENABLE); |
119 | killagreg | 91 | } |
378 | holgerb | 92 | // IDISABLE; |
93 | |||
94 | VIC0->VAR = 0xFF; // write any value to VIC0 Vector address register |
||
119 | killagreg | 95 | } |
96 | |||
97 | //---------------------------------------------------------------------------------------------------- |
||
98 | // 1ms Timer |
||
99 | //---------------------------------------------------------------------------------------------------- |
||
100 | void TIMER1_Init(void) |
||
101 | { |
||
102 | TIM_InitTypeDef TIM_InitStructure; |
||
103 | |||
120 | killagreg | 104 | UART1_PutString("\r\n Timer1 init..."); |
119 | killagreg | 105 | |
106 | #define TIM1_FREQ 200000 // 200kHz |
||
107 | // TimerOCR set in IntHandler |
||
108 | |||
109 | SCU_APBPeriphClockConfig(__TIM01, ENABLE); |
||
110 | |||
120 | killagreg | 111 | TIM_DeInit(TIM1); |
119 | killagreg | 112 | TIM_StructInit(&TIM_InitStructure); |
113 | TIM_InitStructure.TIM_Mode = TIM_OCM_CHANNEL_1; |
||
114 | TIM_InitStructure.TIM_OC1_Modes = TIM_TIMING; |
||
115 | TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB; |
||
116 | TIM_InitStructure.TIM_Prescaler = (SCU_GetPCLKFreqValue() * 1000) / TIM1_FREQ; // is only valid up to 48 MHz ! |
||
117 | TIM_Init (TIM1, &TIM_InitStructure); |
||
118 | |||
119 | TIM_ITConfig(TIM1, TIM_IT_OC1, ENABLE); |
||
120 | TIM_CounterCmd(TIM1, TIM_START); |
||
121 | |||
136 | killagreg | 122 | VIC_Config(TIM1_ITLine, VIC_IRQ, PRIORITY_TIMER1); |
119 | killagreg | 123 | VIC_ITCmd(TIM1_ITLine, ENABLE); |
124 | |||
125 | SystemTime.Year = 0; |
||
126 | SystemTime.Month = 0; |
||
127 | SystemTime.Day = 0; |
||
128 | SystemTime.Hour = 0; |
||
129 | SystemTime.Min = 0; |
||
130 | SystemTime.Sec = 0; |
||
131 | SystemTime.mSec = 0; |
||
132 | SystemTime.Valid = 0; |
||
133 | |||
134 | CountMilliseconds = 0; |
||
135 | |||
120 | killagreg | 136 | UART1_PutString("ok"); |
119 | killagreg | 137 | |
138 | } |
||
139 | |||
140 | // ----------------------------------------------------------------------- |
||
141 | u32 SetDelay (u32 t) |
||
142 | { |
||
143 | return(CountMilliseconds + t -1); |
||
144 | } |
||
145 | |||
146 | // ----------------------------------------------------------------------- |
||
147 | u8 CheckDelay(u32 t) |
||
148 | { |
||
149 | return(((t - CountMilliseconds)& 0x80000000) >> 27); |
||
150 | } |
||
151 | |||
152 | // ----------------------------------------------------------------------- |
||
153 | // this function calculates the time difference of t to the current time in ms |
||
154 | // if t < current time the delay is reportet as zero |
||
155 | u32 GetDelay(u32 t) |
||
156 | { |
||
157 | u32 delay = 0; |
||
158 | delay = t - CountMilliseconds; |
||
159 | if(delay & 0x80000000) delay = 0; // avoid negative delay values |
||
160 | return(delay); |
||
161 | } |
||
162 | |||
163 | // ----------------------------------------------------------------------- |
||
164 | void Delay_ms(u32 w) |
||
165 | { |
||
243 | killagreg | 166 | u32 akt; |
167 | akt = CountMilliseconds + w; |
||
168 | while(1) |
||
169 | { |
||
170 | if(akt<=CountMilliseconds) return; |
||
171 | } |
||
119 | killagreg | 172 | } |