Subversion Repositories NaviCtrl

Rev

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