Subversion Repositories NaviCtrl

Rev

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

Rev 360 Rev 378
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 "uart1.h"
57
#include "uart1.h"
58
#include "analog.h"
58
#include "analog.h"
59
#include "timer1.h"
59
#include "timer1.h"
60
#include "config.h"
60
#include "config.h"
61
 
61
 
62
AnalogData_t AnalogData;
62
AnalogData_t AnalogData;
63
 
63
 
64
void ADC_IRQHandler(void)
64
void ADC_IRQHandler(void)
65
{
65
{
66
        IENABLE;
66
        IENABLE;
67
 
67
 
68
        if(ADC_GetFlagStatus(ADC_FLAG_ECV) == SET)
68
        if(ADC_GetFlagStatus(ADC_FLAG_ECV) == SET)
69
        {
69
        {
70
                ADC_ClearFlag(ADC_FLAG_ECV);
70
                ADC_ClearFlag(ADC_FLAG_ECV);
71
                AnalogData.Ch1 = ADC_GetConversionValue(ADC_Channel_1);
71
                AnalogData.Ch1 = ADC_GetConversionValue(ADC_Channel_1);
72
                AnalogData.Ch2 = ADC_GetConversionValue(ADC_Channel_2);
72
                AnalogData.Ch2 = ADC_GetConversionValue(ADC_Channel_2);
73
                AnalogData.Ch3 = ADC_GetConversionValue(ADC_Channel_3);
73
                AnalogData.Ch3 = ADC_GetConversionValue(ADC_Channel_3);
74
                AnalogData.Ch4 = ADC_GetConversionValue(ADC_Channel_4);
74
                AnalogData.Ch4 = ADC_GetConversionValue(ADC_Channel_4);
75
                AnalogData.Ch5 = ADC_GetConversionValue(ADC_Channel_5);
75
                AnalogData.Ch5 = ADC_GetConversionValue(ADC_Channel_5);
76
                AnalogData.Ch6 = ADC_GetConversionValue(ADC_Channel_6);
76
                AnalogData.Ch6 = ADC_GetConversionValue(ADC_Channel_6);
77
                AnalogData.Ch7 = ADC_GetConversionValue(ADC_Channel_7);
77
                AnalogData.Ch7 = ADC_GetConversionValue(ADC_Channel_7);
78
        }
78
        }
79
        IDISABLE;
79
        IDISABLE;
-
 
80
        VIC0->VAR = 0xFF; // write any value to VIC0 Vector address register
80
}
81
}
81
 
82
 
82
void Analog_Init(void)
83
void Analog_Init(void)
83
{
84
{
84
        ADC_InitTypeDef   ADC_InitStructure;
85
        ADC_InitTypeDef   ADC_InitStructure;
85
 
86
 
86
        UART1_PutString("\r\n ADC init...");
87
        UART1_PutString("\r\n ADC init...");
87
 
88
 
88
        SCU_APBPeriphClockConfig(__GPIO4, ENABLE); // Enable the GPIO4 Clock
89
        SCU_APBPeriphClockConfig(__GPIO4, ENABLE); // Enable the GPIO4 Clock
89
 
90
 
90
        ADC_DeInit(); // reset register to default values
91
        ADC_DeInit(); // reset register to default values
91
 
92
 
92
        // configure port 4 pins as analog inputs
93
        // configure port 4 pins as analog inputs
93
        GPIO_ANAPinConfig(GPIO_ANAChannel1, ENABLE);
94
        GPIO_ANAPinConfig(GPIO_ANAChannel1, ENABLE);
94
        GPIO_ANAPinConfig(GPIO_ANAChannel2, ENABLE);
95
        GPIO_ANAPinConfig(GPIO_ANAChannel2, ENABLE);
95
        GPIO_ANAPinConfig(GPIO_ANAChannel3, ENABLE);
96
        GPIO_ANAPinConfig(GPIO_ANAChannel3, ENABLE);
96
        GPIO_ANAPinConfig(GPIO_ANAChannel4, ENABLE);
97
        GPIO_ANAPinConfig(GPIO_ANAChannel4, ENABLE);
97
        GPIO_ANAPinConfig(GPIO_ANAChannel5, ENABLE);
98
        GPIO_ANAPinConfig(GPIO_ANAChannel5, ENABLE);
98
        GPIO_ANAPinConfig(GPIO_ANAChannel6, ENABLE);
99
        GPIO_ANAPinConfig(GPIO_ANAChannel6, ENABLE);
99
        GPIO_ANAPinConfig(GPIO_ANAChannel7, ENABLE);
100
        GPIO_ANAPinConfig(GPIO_ANAChannel7, ENABLE);
100
 
101
 
101
        ADC_Cmd(ENABLE); // power on the ADC
102
        ADC_Cmd(ENABLE); // power on the ADC
102
        ADC_StandbyModeCmd(DISABLE); // disable Standby Mode
103
        ADC_StandbyModeCmd(DISABLE); // disable Standby Mode
103
        ADC_StructInit(&ADC_InitStructure);
104
        ADC_StructInit(&ADC_InitStructure);
104
        ADC_InitStructure.ADC_Channel_1_Mode = ADC_NoThreshold_Conversion;
105
        ADC_InitStructure.ADC_Channel_1_Mode = ADC_NoThreshold_Conversion;
105
        ADC_InitStructure.ADC_Channel_2_Mode = ADC_NoThreshold_Conversion;
106
        ADC_InitStructure.ADC_Channel_2_Mode = ADC_NoThreshold_Conversion;
106
        ADC_InitStructure.ADC_Channel_3_Mode = ADC_NoThreshold_Conversion;
107
        ADC_InitStructure.ADC_Channel_3_Mode = ADC_NoThreshold_Conversion;
107
        ADC_InitStructure.ADC_Channel_4_Mode = ADC_NoThreshold_Conversion;
108
        ADC_InitStructure.ADC_Channel_4_Mode = ADC_NoThreshold_Conversion;
108
        ADC_InitStructure.ADC_Channel_5_Mode = ADC_NoThreshold_Conversion;
109
        ADC_InitStructure.ADC_Channel_5_Mode = ADC_NoThreshold_Conversion;
109
        ADC_InitStructure.ADC_Channel_6_Mode = ADC_NoThreshold_Conversion;
110
        ADC_InitStructure.ADC_Channel_6_Mode = ADC_NoThreshold_Conversion;
110
        ADC_InitStructure.ADC_Channel_7_Mode = ADC_NoThreshold_Conversion;
111
        ADC_InitStructure.ADC_Channel_7_Mode = ADC_NoThreshold_Conversion;
111
        ADC_InitStructure.ADC_Select_Channel = ADC_Channel_1;
112
        ADC_InitStructure.ADC_Select_Channel = ADC_Channel_1;
112
        ADC_InitStructure.ADC_Scan_Mode = ENABLE; // convert all selected channels
113
        ADC_InitStructure.ADC_Scan_Mode = ENABLE; // convert all selected channels
113
        ADC_InitStructure.ADC_Conversion_Mode = ADC_Single_Mode;
114
        ADC_InitStructure.ADC_Conversion_Mode = ADC_Single_Mode;
114
        ADC_Init(&ADC_InitStructure);
115
        ADC_Init(&ADC_InitStructure);
115
 
116
 
116
        ADC_PrescalerConfig(255);  // PCLK/255  (24MHz/255 = 94.1kHZ )
117
        ADC_PrescalerConfig(255);  // PCLK/255  (24MHz/255 = 94.1kHZ )
117
        ADC_ITConfig(ADC_IT_ECV, ENABLE); // enable end of conversion IRQ
118
        ADC_ITConfig(ADC_IT_ECV, ENABLE); // enable end of conversion IRQ
118
 
119
 
119
        VIC_Config(ADC_ITLine, VIC_IRQ, PRIORITY_ADC);
120
        VIC_Config(ADC_ITLine, VIC_IRQ, PRIORITY_ADC);
-
 
121
 
-
 
122
 
120
        VIC_ITCmd(ADC_ITLine, ENABLE);
123
        VIC_ITCmd(ADC_ITLine, ENABLE);
121
 
124
 
122
        UART1_PutString("ok");
125
        UART1_PutString("ok");
123
}
126
}
124
 
127
 
125
void Analog_Deinit(void)
128
void Analog_Deinit(void)
126
{
129
{
127
        VIC_ITCmd(ADC_ITLine, DISABLE);
130
        VIC_ITCmd(ADC_ITLine, DISABLE);
128
        ADC_ConversionCmd(ADC_Conversion_Stop);
131
        ADC_ConversionCmd(ADC_Conversion_Stop);
129
        ADC_ITConfig(ADC_IT_ECV, DISABLE); // disable end of conversion IRQ
132
        ADC_ITConfig(ADC_IT_ECV, DISABLE); // disable end of conversion IRQ
130
        ADC_Cmd(DISABLE); // power down the ADC
133
        ADC_Cmd(DISABLE); // power down the ADC
131
        ADC_DeInit(); // reset register to default values
134
        ADC_DeInit(); // reset register to default values
132
}
135
}
133
 
136
 
134
void Analog_Update(void)
137
void Analog_Update(void)
135
{
138
{
136
        static u32 AnalogTimer = 0;
139
        static u32 AnalogTimer = 0;
137
 
140
 
138
        if(CheckDelay(AnalogTimer))
141
        if(CheckDelay(AnalogTimer))
139
        {
142
        {
140
                AnalogTimer = SetDelay(25);
143
                AnalogTimer = SetDelay(25);
141
                ADC_ConversionCmd(ADC_Conversion_Start);
144
                ADC_ConversionCmd(ADC_Conversion_Start);
142
        }
145
        }
143
}
146
}
144
 
147