Subversion Repositories NaviCtrl

Rev

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

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