Subversion Repositories NaviCtrl

Rev

Rev 243 | 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"
119 killagreg 60
 
61
u32 CountMilliseconds;
62
DateTime_t SystemTime;
63
 
64
//----------------------------------------------------------------------------------------------------
65
void TIM1_IRQHandler(void)
66
{
195 killagreg 67
        IENABLE;
68
 
119 killagreg 69
        if(TIM_GetFlagStatus(TIM1, TIM_FLAG_OC1) == SET)
70
        {
154 killagreg 71
                TIM_ClearFlag(TIM1, TIM_FLAG_OC1); // clear irq pending bit
119 killagreg 72
                TIM1->OC1R += 200;    // Timerfreq is 200kHz, generate an interrupt every 1ms
73
                CountMilliseconds++;
146 killagreg 74
 
154 killagreg 75
                // generate SW Interrupt to make a regular timing 
195 killagreg 76
                // independent from the mainloop at the lowest IRQ priority
154 killagreg 77
                VIC_SWITCmd(EXTIT3_ITLine, ENABLE);    
119 killagreg 78
        }
195 killagreg 79
 
80
        IDISABLE;
119 killagreg 81
}
82
 
83
//----------------------------------------------------------------------------------------------------
84
// 1ms Timer
85
//----------------------------------------------------------------------------------------------------
86
void TIMER1_Init(void)
87
{
88
        TIM_InitTypeDef   TIM_InitStructure;
89
 
120 killagreg 90
        UART1_PutString("\r\n Timer1 init...");
119 killagreg 91
 
92
        #define TIM1_FREQ 200000 // 200kHz
93
        // TimerOCR set in IntHandler
94
 
95
        SCU_APBPeriphClockConfig(__TIM01, ENABLE);
96
 
120 killagreg 97
        TIM_DeInit(TIM1);
119 killagreg 98
        TIM_StructInit(&TIM_InitStructure);
99
        TIM_InitStructure.TIM_Mode = TIM_OCM_CHANNEL_1;
100
        TIM_InitStructure.TIM_OC1_Modes = TIM_TIMING;
101
        TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB;
102
        TIM_InitStructure.TIM_Prescaler = (SCU_GetPCLKFreqValue() * 1000) / TIM1_FREQ;  // is only valid up to 48 MHz !
103
        TIM_Init (TIM1, &TIM_InitStructure);
104
 
105
        TIM_ITConfig(TIM1, TIM_IT_OC1, ENABLE);
106
        TIM_CounterCmd(TIM1, TIM_START);
107
 
136 killagreg 108
        VIC_Config(TIM1_ITLine, VIC_IRQ, PRIORITY_TIMER1);
119 killagreg 109
        VIC_ITCmd(TIM1_ITLine, ENABLE);
110
 
111
        SystemTime.Year = 0;
112
        SystemTime.Month = 0;
113
        SystemTime.Day = 0;
114
        SystemTime.Hour = 0;
115
        SystemTime.Min = 0;
116
        SystemTime.Sec = 0;
117
        SystemTime.mSec = 0;
118
        SystemTime.Valid = 0;
119
 
120
        CountMilliseconds = 0;
121
 
120 killagreg 122
        UART1_PutString("ok");
119 killagreg 123
 
124
}
125
 
126
// -----------------------------------------------------------------------
127
u32 SetDelay (u32 t)
128
{
129
        return(CountMilliseconds + t -1);
130
}
131
 
132
// -----------------------------------------------------------------------
133
u8 CheckDelay(u32 t)
134
{
135
        return(((t - CountMilliseconds)& 0x80000000) >> 27);
136
}
137
 
138
// -----------------------------------------------------------------------
139
// this function calculates the time difference of t to the current time in ms
140
// if t < current time the delay is reportet as zero
141
u32 GetDelay(u32 t)
142
{
143
        u32 delay = 0;
144
        delay =  t - CountMilliseconds;
145
        if(delay & 0x80000000) delay = 0; // avoid negative delay values
146
        return(delay);
147
}
148
 
149
// -----------------------------------------------------------------------
150
void Delay_ms(u32 w)
151
{
243 killagreg 152
        u32 akt;
153
        akt = CountMilliseconds + w;
154
        while(1)
155
        {
156
                if(akt<=CountMilliseconds) return;
157
        }
119 killagreg 158
}