Subversion Repositories NaviCtrl

Rev

Rev 360 | Rev 378 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 360 Rev 362
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + www.MikroKopter.com
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
// + Software Nutzungsbedingungen (english version: see below)
7
// + Software Nutzungsbedingungen (english version: see below)
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
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
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 
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.
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.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
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.
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
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.
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
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.
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
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 
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.
22
// + des Mitverschuldens offen.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
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.
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.
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
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.
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.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
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.
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.
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Software LICENSING TERMS
32
// + Software LICENSING TERMS
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
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 
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*.
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.
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
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
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.
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
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.
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
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
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
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
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.
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
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.
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
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.
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.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
53
// + #### END OF LICENSING TERMS ####
53
// + #### END OF LICENSING TERMS ####
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
#include "91x_lib.h"
56
#include "91x_lib.h"
57
#include "timer1.h"
57
#include "timer1.h"
58
#include "uart1.h"
58
#include "uart1.h"
59
#include "config.h"
59
#include "config.h"
-
 
60
#include "main.h"
60
 
61
 
61
u32 CountMilliseconds;
62
u32 CountMilliseconds;
62
DateTime_t SystemTime;
63
DateTime_t SystemTime;
63
 
64
 
64
//----------------------------------------------------------------------------------------------------
65
//----------------------------------------------------------------------------------------------------
65
void TIM1_IRQHandler(void)
66
void TIM1_IRQHandler(void)
66
{
67
{
67
        IENABLE;
68
        IENABLE;
68
 
69
 
69
        if(TIM_GetFlagStatus(TIM1, TIM_FLAG_OC1) == SET)
70
        if(TIM_GetFlagStatus(TIM1, TIM_FLAG_OC1) == SET)
70
        {
71
        {
71
                TIM_ClearFlag(TIM1, TIM_FLAG_OC1); // clear irq pending bit
72
                TIM_ClearFlag(TIM1, TIM_FLAG_OC1); // clear irq pending bit
72
                TIM1->OC1R += 200;    // Timerfreq is 200kHz, generate an interrupt every 1ms
73
                TIM1->OC1R += 200;    // Timerfreq is 200kHz, generate an interrupt every 1ms
73
                CountMilliseconds++;
74
                CountMilliseconds++;
74
               
-
 
-
 
75
        if(SD_WatchDog) SD_WatchDog--;
-
 
76
                if(MainWatchDog) MainWatchDog--;
75
                // generate SW Interrupt to make a regular timing 
77
                // generate SW Interrupt to make a regular timing 
76
                // independent from the mainloop at the lowest IRQ priority
78
                // independent from the mainloop at the lowest IRQ priority
77
                VIC_SWITCmd(EXTIT3_ITLine, ENABLE);    
79
                VIC_SWITCmd(EXTIT3_ITLine, ENABLE);    
78
        }
80
        }
79
 
81
 
80
        IDISABLE;
82
        IDISABLE;
81
}
83
}
82
 
84
 
83
//----------------------------------------------------------------------------------------------------
85
//----------------------------------------------------------------------------------------------------
84
// 1ms Timer
86
// 1ms Timer
85
//----------------------------------------------------------------------------------------------------
87
//----------------------------------------------------------------------------------------------------
86
void TIMER1_Init(void)
88
void TIMER1_Init(void)
87
{
89
{
88
        TIM_InitTypeDef   TIM_InitStructure;
90
        TIM_InitTypeDef   TIM_InitStructure;
89
 
91
 
90
        UART1_PutString("\r\n Timer1 init...");
92
        UART1_PutString("\r\n Timer1 init...");
91
 
93
 
92
        #define TIM1_FREQ 200000 // 200kHz
94
        #define TIM1_FREQ 200000 // 200kHz
93
        // TimerOCR set in IntHandler
95
        // TimerOCR set in IntHandler
94
 
96
 
95
        SCU_APBPeriphClockConfig(__TIM01, ENABLE);
97
        SCU_APBPeriphClockConfig(__TIM01, ENABLE);
96
 
98
 
97
        TIM_DeInit(TIM1);
99
        TIM_DeInit(TIM1);
98
        TIM_StructInit(&TIM_InitStructure);
100
        TIM_StructInit(&TIM_InitStructure);
99
        TIM_InitStructure.TIM_Mode = TIM_OCM_CHANNEL_1;
101
        TIM_InitStructure.TIM_Mode = TIM_OCM_CHANNEL_1;
100
        TIM_InitStructure.TIM_OC1_Modes = TIM_TIMING;
102
        TIM_InitStructure.TIM_OC1_Modes = TIM_TIMING;
101
        TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB;
103
        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 !
104
        TIM_InitStructure.TIM_Prescaler = (SCU_GetPCLKFreqValue() * 1000) / TIM1_FREQ;  // is only valid up to 48 MHz !
103
        TIM_Init (TIM1, &TIM_InitStructure);
105
        TIM_Init (TIM1, &TIM_InitStructure);
104
 
106
 
105
        TIM_ITConfig(TIM1, TIM_IT_OC1, ENABLE);
107
        TIM_ITConfig(TIM1, TIM_IT_OC1, ENABLE);
106
        TIM_CounterCmd(TIM1, TIM_START);
108
        TIM_CounterCmd(TIM1, TIM_START);
107
 
109
 
108
        VIC_Config(TIM1_ITLine, VIC_IRQ, PRIORITY_TIMER1);
110
        VIC_Config(TIM1_ITLine, VIC_IRQ, PRIORITY_TIMER1);
109
        VIC_ITCmd(TIM1_ITLine, ENABLE);
111
        VIC_ITCmd(TIM1_ITLine, ENABLE);
110
 
112
 
111
        SystemTime.Year = 0;
113
        SystemTime.Year = 0;
112
        SystemTime.Month = 0;
114
        SystemTime.Month = 0;
113
        SystemTime.Day = 0;
115
        SystemTime.Day = 0;
114
        SystemTime.Hour = 0;
116
        SystemTime.Hour = 0;
115
        SystemTime.Min = 0;
117
        SystemTime.Min = 0;
116
        SystemTime.Sec = 0;
118
        SystemTime.Sec = 0;
117
        SystemTime.mSec = 0;
119
        SystemTime.mSec = 0;
118
        SystemTime.Valid = 0;
120
        SystemTime.Valid = 0;
119
 
121
 
120
        CountMilliseconds = 0;
122
        CountMilliseconds = 0;
121
 
123
 
122
        UART1_PutString("ok");
124
        UART1_PutString("ok");
123
 
125
 
124
}
126
}
125
 
127
 
126
// -----------------------------------------------------------------------
128
// -----------------------------------------------------------------------
127
u32 SetDelay (u32 t)
129
u32 SetDelay (u32 t)
128
{
130
{
129
        return(CountMilliseconds + t -1);
131
        return(CountMilliseconds + t -1);
130
}
132
}
131
 
133
 
132
// -----------------------------------------------------------------------
134
// -----------------------------------------------------------------------
133
u8 CheckDelay(u32 t)
135
u8 CheckDelay(u32 t)
134
{
136
{
135
        return(((t - CountMilliseconds)& 0x80000000) >> 27);
137
        return(((t - CountMilliseconds)& 0x80000000) >> 27);
136
}
138
}
137
 
139
 
138
// -----------------------------------------------------------------------
140
// -----------------------------------------------------------------------
139
// this function calculates the time difference of t to the current time in ms
141
// 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
142
// if t < current time the delay is reportet as zero
141
u32 GetDelay(u32 t)
143
u32 GetDelay(u32 t)
142
{
144
{
143
        u32 delay = 0;
145
        u32 delay = 0;
144
        delay =  t - CountMilliseconds;
146
        delay =  t - CountMilliseconds;
145
        if(delay & 0x80000000) delay = 0; // avoid negative delay values
147
        if(delay & 0x80000000) delay = 0; // avoid negative delay values
146
        return(delay);
148
        return(delay);
147
}
149
}
148
 
150
 
149
// -----------------------------------------------------------------------
151
// -----------------------------------------------------------------------
150
void Delay_ms(u32 w)
152
void Delay_ms(u32 w)
151
{
153
{
152
        u32 akt;
154
        u32 akt;
153
        akt = CountMilliseconds + w;
155
        akt = CountMilliseconds + w;
154
        while(1)
156
        while(1)
155
        {
157
        {
156
                if(akt<=CountMilliseconds) return;
158
                if(akt<=CountMilliseconds) return;
157
        }
159
        }
158
}
160
}
159
 
161