Subversion Repositories NaviCtrl

Rev

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

Rev 112 Rev 116
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
6
// + Nur für den privaten Gebrauch
6
// + Nur für den privaten Gebrauch
7
// + FOR NON COMMERCIAL USE ONLY
7
// + FOR NON COMMERCIAL USE ONLY
8
// + www.MikroKopter.com
8
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
13
// + bzgl. der Nutzungsbedingungen aufzunehmen.
13
// + bzgl. der Nutzungsbedingungen aufzunehmen.
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
15
// + Verkauf von Luftbildaufnahmen, usw.
15
// + Verkauf von Luftbildaufnahmen, usw.
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
22
// + eindeutig als Ursprung verlinkt werden
22
// + eindeutig als Ursprung verlinkt werden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
25
// + Benutzung auf eigene Gefahr
25
// + Benutzung auf eigene Gefahr
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
28
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
29
// + mit unserer Zustimmung zulässig
29
// + mit unserer Zustimmung zulässig
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
34
// + this list of conditions and the following disclaimer.
34
// + this list of conditions and the following disclaimer.
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
36
// +     from this software without specific prior written permission.
36
// +     from this software without specific prior written permission.
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
38
// +     for non-commercial use (directly or indirectly)
38
// +     for non-commercial use (directly or indirectly)
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
40
// +     with our written permission
40
// +     with our written permission
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
42
// +     clearly linked as origin
42
// +     clearly linked as origin
43
// +   * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed
43
// +   * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed
44
//
44
//
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55
// +  POSSIBILITY OF SUCH DAMAGE.
55
// +  POSSIBILITY OF SUCH DAMAGE.
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
#include <stdio.h>
57
#include <stdio.h>
58
#include <stdarg.h>
58
#include <stdarg.h>
-
 
59
#include <string.h>
59
#include "91x_lib.h"
60
#include "91x_lib.h"
60
#include "main.h"
61
#include "main.h"
61
#include "uart0.h"
62
#include "uart0.h"
62
#include "uart1.h"
63
#include "uart1.h"
63
#include "timer.h"
64
#include "timer.h"
64
#include "ubx.h"
65
#include "ubx.h"
65
#include "mkprotocol.h"
66
#include "mkprotocol.h"
66
 
-
 
67
u8 UART0_Request_VersionInfo    = FALSE;
-
 
68
u8 UART0_Request_NaviData               = FALSE;
-
 
69
u32 UART0_NaviData_Timer;
-
 
-
 
67
 
70
u32 UART0_NaviData_Interval = 0;        // in ms
68
 
71
//------------------------------------------------------------------------------------
69
//------------------------------------------------------------------------------------
72
// global variables
70
// global variables
-
 
71
 
-
 
72
MKOSD_VersionInfo_t MKOSD_VersionInfo;
73
 
73
 
74
#define UART0_BAUD_RATE 57600           //Baud Rate for the serial interfaces
74
#define UART0_BAUD_RATE 57600           //Baud Rate for the serial interfaces
75
// UART0 MUXER
75
// UART0 MUXER
76
UART0_MuxerState_t UART0_Muxer = UART0_UNDEF;
76
UART0_MuxerState_t UART0_Muxer = UART0_UNDEF;
77
u16 Uart0Baudrate = UART0_BAUD_RATE;
77
u16 Uart0Baudrate = UART0_BAUD_RATE;
78
u16 Uart0MK3MagBaudrate = UART0_BAUD_RATE;
78
u16 Uart0MK3MagBaudrate = UART0_BAUD_RATE;
79
 
79
 
80
// the tx buffer
80
// the tx buffer
81
#define UART0_TX_BUFFER_LEN  150
81
#define UART0_TX_BUFFER_LEN  150
82
u8 UART0_tbuffer[UART0_TX_BUFFER_LEN];
82
u8 UART0_tbuffer[UART0_TX_BUFFER_LEN];
83
Buffer_t UART0_tx_buffer;
83
Buffer_t UART0_tx_buffer;
84
 
84
 
85
// the rx buffer
85
// the rx buffer
86
#define UART0_RX_BUFFER_LEN  150
86
#define UART0_RX_BUFFER_LEN  150
87
u8 UART0_rbuffer[UART0_RX_BUFFER_LEN];
87
u8 UART0_rbuffer[UART0_RX_BUFFER_LEN];
88
Buffer_t UART0_rx_buffer;
88
Buffer_t UART0_rx_buffer;
-
 
89
 
-
 
90
u8 UART0_Request_VersionInfo    = FALSE;
-
 
91
u8 UART0_Request_NaviData               = FALSE;
-
 
92
u32 UART0_NaviData_Timer;
89
 
93
u32 UART0_NaviData_Interval = 0;        // in ms
90
 
94
 
91
//------------------------------------------------------------------------------------
95
//------------------------------------------------------------------------------------
92
// functions
96
// functions
93
 
97
 
94
/********************************************************/
98
/********************************************************/
95
/*              Connect RXD & TXD to GPS                */
99
/*              Connect RXD & TXD to GPS                */
96
/********************************************************/
100
/********************************************************/
97
void UART0_Connect_to_MKGPS(void)
101
void UART0_Connect_to_MKGPS(void)
98
{
102
{
99
        GPIO_InitTypeDef GPIO_InitStructure;
103
        GPIO_InitTypeDef GPIO_InitStructure;
100
 
104
 
101
        UART0_Muxer = UART0_UNDEF;
105
        UART0_Muxer = UART0_UNDEF;
102
 
106
 
103
        SCU_APBPeriphClockConfig(__GPIO6, ENABLE); // Enable the GPIO6 Clock
107
        SCU_APBPeriphClockConfig(__GPIO6, ENABLE); // Enable the GPIO6 Clock
104
        // unmap UART0 from Compass
108
        // unmap UART0 from Compass
105
        // set port pin 5.1 (serial data from compass) to input and disconnect from IP
109
        // set port pin 5.1 (serial data from compass) to input and disconnect from IP
106
        GPIO_StructInit(&GPIO_InitStructure);
110
        GPIO_StructInit(&GPIO_InitStructure);
107
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
111
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
108
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_1;
112
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_1;
109
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull ;
113
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull ;
110
    GPIO_InitStructure.GPIO_IPConnected =       GPIO_IPConnected_Disable;
114
    GPIO_InitStructure.GPIO_IPConnected =       GPIO_IPConnected_Disable;
111
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
115
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
112
    GPIO_Init(GPIO5, &GPIO_InitStructure);
116
    GPIO_Init(GPIO5, &GPIO_InitStructure);
113
        // set port pin 5.0 (serial data to compass) to input
117
        // set port pin 5.0 (serial data to compass) to input
114
        GPIO_StructInit(&GPIO_InitStructure);
118
        GPIO_StructInit(&GPIO_InitStructure);
115
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
119
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
116
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_0;
120
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_0;
117
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
121
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
118
        GPIO_InitStructure.GPIO_IPConnected =   GPIO_IPConnected_Disable;
122
        GPIO_InitStructure.GPIO_IPConnected =   GPIO_IPConnected_Disable;
119
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
123
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
120
    GPIO_Init(GPIO5, &GPIO_InitStructure);
124
    GPIO_Init(GPIO5, &GPIO_InitStructure);
121
        // map UART0 to GPS
125
        // map UART0 to GPS
122
        // set port pin 6.6 (serial data from gps) to input and connect to IP
126
        // set port pin 6.6 (serial data from gps) to input and connect to IP
123
        GPIO_StructInit(&GPIO_InitStructure);
127
        GPIO_StructInit(&GPIO_InitStructure);
124
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
128
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
125
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_6;
129
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_6;
126
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull ;
130
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull ;
127
    GPIO_InitStructure.GPIO_IPConnected =       GPIO_IPConnected_Enable;
131
    GPIO_InitStructure.GPIO_IPConnected =       GPIO_IPConnected_Enable;
128
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1; //UART0_RxD
132
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1; //UART0_RxD
129
    GPIO_Init(GPIO6, &GPIO_InitStructure);
133
    GPIO_Init(GPIO6, &GPIO_InitStructure);
130
        // set port pin 6.7 (serial data to gps) to output
134
        // set port pin 6.7 (serial data to gps) to output
131
        GPIO_StructInit(&GPIO_InitStructure);
135
        GPIO_StructInit(&GPIO_InitStructure);
132
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
136
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
133
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_7;
137
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_7;
134
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
138
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
135
        GPIO_InitStructure.GPIO_IPConnected =   GPIO_IPConnected_Enable;
139
        GPIO_InitStructure.GPIO_IPConnected =   GPIO_IPConnected_Enable;
136
    GPIO_InitStructure.GPIO_Alternate =         GPIO_OutputAlt3; //UART0_TX
140
    GPIO_InitStructure.GPIO_Alternate =         GPIO_OutputAlt3; //UART0_TX
137
    GPIO_Init(GPIO6, &GPIO_InitStructure);
141
    GPIO_Init(GPIO6, &GPIO_InitStructure);
138
       
142
       
139
        UART0_Muxer = UART0_MKGPS;
143
        UART0_Muxer = UART0_MKGPS;
140
}
144
}
141
 
145
 
142
/********************************************************/
146
/********************************************************/
143
/*              Connect RXD & TXD to MK3MAG             */
147
/*              Connect RXD & TXD to MK3MAG             */
144
/********************************************************/
148
/********************************************************/
145
void UART0_Connect_to_MK3MAG(void)
149
void UART0_Connect_to_MK3MAG(void)
146
{
150
{
147
        GPIO_InitTypeDef GPIO_InitStructure;
151
        GPIO_InitTypeDef GPIO_InitStructure;
148
 
152
 
149
        UART0_Muxer = UART0_UNDEF;
153
        UART0_Muxer = UART0_UNDEF;
150
 
154
 
151
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE);
155
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE);
152
        // unmap UART0 from GPS
156
        // unmap UART0 from GPS
153
        // set port pin 6.6 (serial data from gps) to input and disconnect from IP
157
        // set port pin 6.6 (serial data from gps) to input and disconnect from IP
154
        GPIO_StructInit(&GPIO_InitStructure);
158
        GPIO_StructInit(&GPIO_InitStructure);
155
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
159
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
156
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_6;
160
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_6;
157
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
161
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
158
    GPIO_InitStructure.GPIO_IPConnected =       GPIO_IPConnected_Disable;
162
    GPIO_InitStructure.GPIO_IPConnected =       GPIO_IPConnected_Disable;
159
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
163
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
160
    GPIO_Init(GPIO6, &GPIO_InitStructure);
164
    GPIO_Init(GPIO6, &GPIO_InitStructure);
161
        // set port pin 6.7 (serial data to gps) to input
165
        // set port pin 6.7 (serial data to gps) to input
162
        GPIO_StructInit(&GPIO_InitStructure);
166
        GPIO_StructInit(&GPIO_InitStructure);
163
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
167
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
164
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_7;
168
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_7;
165
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
169
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
166
        GPIO_InitStructure.GPIO_IPConnected =   GPIO_IPConnected_Disable;
170
        GPIO_InitStructure.GPIO_IPConnected =   GPIO_IPConnected_Disable;
167
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
171
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
168
    GPIO_Init(GPIO6, &GPIO_InitStructure);
172
    GPIO_Init(GPIO6, &GPIO_InitStructure);
169
 
173
 
170
        // map UART0 to Compass
174
        // map UART0 to Compass
171
        // set port pin 5.1 (serial data from compass) to input and connect to IP
175
        // set port pin 5.1 (serial data from compass) to input and connect to IP
172
        GPIO_StructInit(&GPIO_InitStructure);
176
        GPIO_StructInit(&GPIO_InitStructure);
173
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
177
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
174
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_1;
178
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_1;
175
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull ;
179
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull ;
176
    GPIO_InitStructure.GPIO_IPConnected =       GPIO_IPConnected_Enable;
180
    GPIO_InitStructure.GPIO_IPConnected =       GPIO_IPConnected_Enable;
177
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1; //UART0_RxD
181
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1; //UART0_RxD
178
    GPIO_Init(GPIO5, &GPIO_InitStructure);
182
    GPIO_Init(GPIO5, &GPIO_InitStructure);
179
        // set port pin 5.0 (serial data to compass) to output
183
        // set port pin 5.0 (serial data to compass) to output
180
        GPIO_StructInit(&GPIO_InitStructure);
184
        GPIO_StructInit(&GPIO_InitStructure);
181
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
185
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
182
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_0;
186
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_0;
183
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
187
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
184
        GPIO_InitStructure.GPIO_IPConnected =   GPIO_IPConnected_Enable;
188
        GPIO_InitStructure.GPIO_IPConnected =   GPIO_IPConnected_Enable;
185
    GPIO_InitStructure.GPIO_Alternate =         GPIO_OutputAlt3; //UART0_TX
189
    GPIO_InitStructure.GPIO_Alternate =         GPIO_OutputAlt3; //UART0_TX
186
    GPIO_Init(GPIO5, &GPIO_InitStructure);
190
    GPIO_Init(GPIO5, &GPIO_InitStructure);
187
 
191
 
188
        UART0_Muxer = UART0_MK3MAG;
192
        UART0_Muxer = UART0_MK3MAG;
189
}
193
}
190
 
194
 
191
/********************************************************/
195
/********************************************************/
192
/*                  Initialize UART0                    */
196
/*                  Initialize UART0                    */
193
/********************************************************/
197
/********************************************************/
194
void UART0_Init(void)
198
void UART0_Init(void)
195
{
199
{
196
    UART_InitTypeDef UART_InitStructure;
200
    UART_InitTypeDef UART_InitStructure;
197
       
201
       
198
        UART1_PutString("\r\n UART0 init...");
202
        UART1_PutString("\r\n UART0 init...");
199
 
203
 
200
        SCU_APBPeriphClockConfig(__UART0, ENABLE);  // Enable the UART0 Clock
204
        SCU_APBPeriphClockConfig(__UART0, ENABLE);  // Enable the UART0 Clock
201
 
205
 
202
        Uart0Baudrate = UART0_BAUD_RATE + ((UART0_BAUD_RATE * 2)/100);   // MK3Mag baudrate is a litlle bit higher...
206
        Uart0Baudrate = UART0_BAUD_RATE + ((UART0_BAUD_RATE * 2)/100);   // MK3Mag baudrate is a litlle bit higher...
203
 
207
 
204
        /* UART0 configured as follow:
208
        /* UART0 configured as follow:
205
          - Word Length = 8 Bits
209
          - Word Length = 8 Bits
206
          - One Stop Bit
210
          - One Stop Bit
207
          - No parity
211
          - No parity
208
          - BaudRate = 57600 baud
212
          - BaudRate = 57600 baud
209
          - Hardware flow control Disabled
213
          - Hardware flow control Disabled
210
          - Receive and transmit enabled
214
          - Receive and transmit enabled
211
          - Receive and transmit FIFOs are Disabled
215
          - Receive and transmit FIFOs are Disabled
212
    */
216
    */
213
        UART_StructInit(&UART_InitStructure);
217
        UART_StructInit(&UART_InitStructure);
214
    UART_InitStructure.UART_WordLength =                        UART_WordLength_8D;
218
    UART_InitStructure.UART_WordLength =                        UART_WordLength_8D;
215
    UART_InitStructure.UART_StopBits =                          UART_StopBits_1;
219
    UART_InitStructure.UART_StopBits =                          UART_StopBits_1;
216
    UART_InitStructure.UART_Parity =                            UART_Parity_No ;
220
    UART_InitStructure.UART_Parity =                            UART_Parity_No ;
217
    UART_InitStructure.UART_BaudRate =                          Uart0Baudrate;
221
    UART_InitStructure.UART_BaudRate =                          Uart0Baudrate;
218
    UART_InitStructure.UART_HardwareFlowControl =       UART_HardwareFlowControl_None;
222
    UART_InitStructure.UART_HardwareFlowControl =       UART_HardwareFlowControl_None;
219
    UART_InitStructure.UART_Mode =                                      UART_Mode_Tx_Rx;
223
    UART_InitStructure.UART_Mode =                                      UART_Mode_Tx_Rx;
220
    UART_InitStructure.UART_FIFO =                                      UART_FIFO_Enable;
224
    UART_InitStructure.UART_FIFO =                                      UART_FIFO_Enable;
221
    UART_InitStructure.UART_TxFIFOLevel =                       UART_FIFOLevel_1_2;
225
    UART_InitStructure.UART_TxFIFOLevel =                       UART_FIFOLevel_1_2;
222
    UART_InitStructure.UART_RxFIFOLevel =                       UART_FIFOLevel_1_2;
226
    UART_InitStructure.UART_RxFIFOLevel =                       UART_FIFOLevel_1_2;
223
 
227
 
224
        UART_DeInit(UART0);     // reset uart 0 to default
228
        UART_DeInit(UART0);     // reset uart 0 to default
225
    UART_Init(UART0, &UART_InitStructure);  // initialize uart 0
229
    UART_Init(UART0, &UART_InitStructure);  // initialize uart 0
226
 
230
 
227
        // enable uart 0 interrupts selective
231
        // enable uart 0 interrupts selective
228
    UART_ITConfig(UART0, UART_IT_Receive | UART_IT_ReceiveTimeOut  /*| UART_IT_FrameError*/, ENABLE);
232
    UART_ITConfig(UART0, UART_IT_Receive | UART_IT_ReceiveTimeOut  /*| UART_IT_FrameError*/, ENABLE);
229
        UART_Cmd(UART0, ENABLE); // enable uart 0
233
        UART_Cmd(UART0, ENABLE); // enable uart 0
230
        // configure the uart 0 interupt line as an IRQ with priority 10 (0 is highest)
234
        // configure the uart 0 interupt line as an IRQ with priority 10 (0 is highest)
231
        VIC_Config(UART0_ITLine, VIC_IRQ, 10);
235
        VIC_Config(UART0_ITLine, VIC_IRQ, 10);
232
        // enable the uart 0 IRQ
236
        // enable the uart 0 IRQ
233
        VIC_ITCmd(UART0_ITLine, ENABLE);
237
        VIC_ITCmd(UART0_ITLine, ENABLE);
234
        UART0_Connect_to_MKGPS();
238
        UART0_Connect_to_MKGPS();
235
 
239
 
236
        // initialize txd buffer
240
        // initialize txd buffer
237
        Buffer_Init(&UART0_tx_buffer, UART0_tbuffer, UART0_TX_BUFFER_LEN);
241
        Buffer_Init(&UART0_tx_buffer, UART0_tbuffer, UART0_TX_BUFFER_LEN);
238
       
242
       
239
        // initialize rxd buffer
243
        // initialize rxd buffer
240
        Buffer_Init(&UART0_rx_buffer, UART0_rbuffer, UART0_RX_BUFFER_LEN);
244
        Buffer_Init(&UART0_rx_buffer, UART0_rbuffer, UART0_RX_BUFFER_LEN);
241
 
245
 
242
        UART1_PutString("ok");
246
        UART1_PutString("ok");
243
}
247
}
244
 
248
 
245
/********************************************************/
249
/********************************************************/
246
/*            UART0 Interrupt Handler                   */
250
/*            UART0 Interrupt Handler                   */
247
/********************************************************/
251
/********************************************************/
248
void UART0_IRQHandler(void)
252
void UART0_IRQHandler(void)
249
{
253
{
250
        u8 c;
254
        u8 c;
251
        // if receive irq or receive timeout irq has occured
255
        // if receive irq or receive timeout irq has occured
252
        if((UART_GetITStatus(UART0, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART0, UART_IT_ReceiveTimeOut) != RESET) )
256
        if((UART_GetITStatus(UART0, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART0, UART_IT_ReceiveTimeOut) != RESET) )
253
        {
257
        {
254
                UART_ClearITPendingBit(UART0, UART_IT_Receive);                 // clear receive interrupt flag
258
                UART_ClearITPendingBit(UART0, UART_IT_Receive);                 // clear receive interrupt flag
255
                UART_ClearITPendingBit(UART0, UART_IT_ReceiveTimeOut);  // clear receive timeout interrupt flag
259
                UART_ClearITPendingBit(UART0, UART_IT_ReceiveTimeOut);  // clear receive timeout interrupt flag
256
 
260
 
257
                // if debug UART is UART0
261
                // if debug UART is UART0
258
                if (DebugUART == UART0)
262
                if (DebugUART == UART0)
259
                {       // forward received data to the UART1 tx buffer
263
                {       // forward received data to the UART1 tx buffer
260
                        while(UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET)
264
                        while(UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET)
261
                        {
265
                        {
262
                                // wait for space in the tx buffer of the UART1
266
                                // wait for space in the tx buffer of the UART1
263
                                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {};
267
                                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {};
264
                                // move the byte from the rx buffer of UART0 to the tx buffer of UART1
268
                                // move the byte from the rx buffer of UART0 to the tx buffer of UART1
265
                                UART_SendData(UART1, UART_ReceiveData(UART0));
269
                                UART_SendData(UART1, UART_ReceiveData(UART0));
266
                        }
270
                        }
267
                }
271
                }
268
                else // UART0 is not the DebugUART (normal operation)
272
                else // UART0 is not the DebugUART (normal operation)
269
                {
273
                {
270
                        // repeat until no byte is in the RxFIFO
274
                        // repeat until no byte is in the RxFIFO
271
                        while (UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET)
275
                        while (UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET)
272
                        {  
276
                        {  
273
                                c = UART_ReceiveData(UART0); // get byte from rx fifo
277
                                c = UART_ReceiveData(UART0); // get byte from rx fifo
274
                                switch(UART0_Muxer)
278
                                switch(UART0_Muxer)
275
                                {
279
                                {
276
                                        case UART0_MKGPS:
280
                                        case UART0_MKGPS:
277
                                                UBX_Parser(c); // if connected to GPS forward byte to ubx parser
281
                                                UBX_Parser(c); // if connected to GPS forward byte to ubx parser
278
                                                MKProtocol_CollectSerialFrame(&UART0_rx_buffer, c);     // ckeck for MK-Frames also
282
                                                MKProtocol_CollectSerialFrame(&UART0_rx_buffer, c);     // ckeck for MK-Frames also
279
                                                break;
283
                                                break;
280
                                        case UART0_MK3MAG:
284
                                        case UART0_MK3MAG:
281
                                                // ignore any byte send from MK3MAG
285
                                                // ignore any byte send from MK3MAG
282
                                                break;
286
                                                break;
283
                                        case UART0_UNDEF:
287
                                        case UART0_UNDEF:
284
                                        default:
288
                                        default:
285
                                                // ignore the byte from unknown source
289
                                                // ignore the byte from unknown source
286
                                                break;
290
                                                break;
287
                                } // eof switch(UART0_Muxer)
291
                                } // eof switch(UART0_Muxer)
288
                        } // eof while
292
                        } // eof while
289
                }  // eof UART0 is not the DebugUART
293
                }  // eof UART0 is not the DebugUART
290
        } // eof receive irq or receive timeout irq
294
        } // eof receive irq or receive timeout irq
291
}
295
}
292
 
296
 
293
/**************************************************************/
297
/**************************************************************/
294
/* Process incomming data from debug uart                     */
298
/* Process incomming data from debug uart                     */
295
/**************************************************************/
299
/**************************************************************/
296
void UART0_ProcessRxData(void)
300
void UART0_ProcessRxData(void)
297
{
301
{
298
        SerialMsg_t SerialMsg;
302
        SerialMsg_t SerialMsg;
299
        // if data in the rxd buffer are not locked immediately return
303
        // if data in the rxd buffer are not locked immediately return
300
        if((UART0_rx_buffer.Locked == FALSE) || (DebugUART == UART0) ) return;
304
        if((UART0_rx_buffer.Locked == FALSE) || (DebugUART == UART0) ) return;
301
       
305
       
302
        MKProtocol_DecodeSerialFrame(&UART0_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
306
        MKProtocol_DecodeSerialFrame(&UART0_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
303
 
307
 
304
        switch(SerialMsg.Address) // check for Slave Address
308
        switch(SerialMsg.Address) // check for Slave Address
305
        {
309
        {
-
 
310
                case MKOSD_ADDRESS: // answers from the MKOSD
-
 
311
                        switch(SerialMsg.CmdID)
-
 
312
                        {
-
 
313
                                case 'V':
-
 
314
                                        memcpy(&MKOSD_VersionInfo, SerialMsg.pData, sizeof(MKOSD_VersionInfo)); // copy echo pattern
-
 
315
                                        break;
-
 
316
                                default:
-
 
317
                                        break;
-
 
318
                        } // case MKOSD_ADDRESS 
-
 
319
                        break;
-
 
320
 
306
                case NC_ADDRESS:  // own Slave Address
321
                case NC_ADDRESS:  // own Slave Address
307
                switch(SerialMsg.CmdID)
322
                        switch(SerialMsg.CmdID)
308
                {
323
                        {
309
                        default:
324
                                default:
310
                                break;
325
                                        break;
311
                } // case NC_ADDRESS
326
                        } // case NC_ADDRESS
312
                // "break;" is missing here to fall thru to the common commands
327
                        // "break;" is missing here to fall thru to the common commands
313
 
328
 
314
                default:  // and any other Slave Address
-
 
315
 
329
                default:  // and any other Slave Address
316
                switch(SerialMsg.CmdID) // check CmdID
330
                        switch(SerialMsg.CmdID) // check CmdID
317
                {
331
                        {
318
                        case 'o': // request for navigation information
332
                                case 'o': // request for navigation information
319
                                UART0_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
333
                                        UART0_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
320
                                if(UART0_NaviData_Interval > 0) UART0_Request_NaviData = TRUE;
334
                                        if(UART0_NaviData_Interval > 0) UART0_Request_NaviData = TRUE;
321
                                break;
335
                                        break;
322
 
336
       
323
                        case 'v': // request for version info
337
                                case 'v': // request for version info
324
                                UART0_Request_VersionInfo = TRUE;
338
                                        UART0_Request_VersionInfo = TRUE;
325
                                break;
339
                                        break;
326
                        default:
340
                                default:
327
                                // unsupported command recieved
341
                                        // unsupported command recieved
328
                                break;
342
                                        break;
329
                }
343
                        }
330
                break; // default:
344
                        break; // default:
331
        }
345
        }
332
        Buffer_Clear(&UART0_rx_buffer);
346
        Buffer_Clear(&UART0_rx_buffer);
333
}
347
}
334
 
348
 
335
/**************************************************************/
349
/**************************************************************/
336
/*         Transmit tx buffer via uart0                       */
350
/*         Transmit tx buffer via uart0                       */
337
/**************************************************************/
351
/**************************************************************/
338
void UART0_Transmit(void)
352
void UART0_Transmit(void)
339
{
353
{
340
        u8 tmp_tx;
354
        u8 tmp_tx;
341
        if(DebugUART == UART0) return; // no data output if debug uart is rederected to UART0
355
        if(DebugUART == UART0) return; // no data output if debug uart is rederected to UART0
342
        // if something has to be send and the txd fifo is not full
356
        // if something has to be send and the txd fifo is not full
343
        if((UART0_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOFull) == RESET))
357
        if((UART0_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOFull) == RESET))
344
        {
358
        {
345
                tmp_tx = UART0_tx_buffer.pData[UART0_tx_buffer.Position++]; // read next byte from txd buffer
359
                tmp_tx = UART0_tx_buffer.pData[UART0_tx_buffer.Position++]; // read next byte from txd buffer
346
                UART_SendData(UART0, tmp_tx); // put character to txd fifo
360
                UART_SendData(UART0, tmp_tx); // put character to txd fifo
347
                // if terminating character or end of txd buffer reached
361
                // if terminating character or end of txd buffer reached
348
                if((tmp_tx == '\r') || (UART0_tx_buffer.Position == UART0_tx_buffer.Size))
362
                if((tmp_tx == '\r') || (UART0_tx_buffer.Position == UART0_tx_buffer.Size))
349
                {
363
                {
350
                        Buffer_Clear(&UART0_tx_buffer);
364
                        Buffer_Clear(&UART0_tx_buffer);
351
                }
365
                }
352
        }
366
        }
353
}
367
}
354
 
368
 
355
 
369
 
356
/**************************************************************/
370
/**************************************************************/
357
/* Send the answers to incomming commands at the uart0        */
371
/* Send the answers to incomming commands at the uart0        */
358
/**************************************************************/
372
/**************************************************************/
359
void UART0_TransmitTxData(void)
373
void UART0_TransmitTxData(void)
360
{
374
{
361
        if(DebugUART == UART0) return;
375
        if(DebugUART == UART0) return;
362
        UART0_Transmit(); // output pending bytes in tx buffer
376
        UART0_Transmit(); // output pending bytes in tx buffer
363
        if(UART0_tx_buffer.Locked == TRUE) return;
377
        if(UART0_tx_buffer.Locked == TRUE) return;
-
 
378
 
-
 
379
 
-
 
380
        if(UART0_Request_VersionInfo && (UART0_tx_buffer.Locked == FALSE))
-
 
381
        {
-
 
382
                MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
-
 
383
                UART0_Request_VersionInfo = FALSE;
364
 
384
        }
365
        if(( (UART0_NaviData_Interval && CheckDelay(UART0_NaviData_Timer) ) || UART0_Request_NaviData) && (UART0_tx_buffer.Locked == FALSE))
385
        if(( (UART0_NaviData_Interval && CheckDelay(UART0_NaviData_Timer) ) || UART0_Request_NaviData) && (UART0_tx_buffer.Locked == FALSE))
366
        {
386
        {
367
                NaviData.Errorcode = ErrorCode;
387
                NaviData.Errorcode = ErrorCode;
368
                MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData));
388
                MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData));
369
                UART0_NaviData_Timer = SetDelay(UART0_NaviData_Interval);
389
                UART0_NaviData_Timer = SetDelay(UART0_NaviData_Interval);
370
                UART0_Request_NaviData = FALSE;
390
                UART0_Request_NaviData = FALSE;
371
        }      
391
        }      
372
        UART0_Transmit(); // output pending bytes in tx buffer
392
        UART0_Transmit(); // output pending bytes in tx buffer
373
}
393
}
-
 
394
 
-
 
395
 
-
 
396
/**************************************************************/
-
 
397
/* Get the version of the MKOSD                               */
-
 
398
/**************************************************************/
-
 
399
void UART0_GetMKOSDVersion(void)
-
 
400
{
-
 
401
        u32 timeout;
-
 
402
        u8 msg[64];
-
 
403
 
-
 
404
        MKOSD_VersionInfo.SWMajor = 0xFF;
-
 
405
        MKOSD_VersionInfo.SWMinor = 0xFF;
-
 
406
        MKOSD_VersionInfo.SWPatch = 0xFF;
-
 
407
 
-
 
408
        if(UART0_Muxer != UART0_MKGPS) UART0_Connect_to_MKGPS();
-
 
409
        while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer;
-
 
410
 
-
 
411
        MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'v', MKOSD_ADDRESS, 0); // request for version info
-
 
412
        while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer;
-
 
413
       
-
 
414
        timeout = SetDelay(500);
-
 
415
        do
-
 
416
        {
-
 
417
                UART0_ProcessRxData();
-
 
418
                if(MKOSD_VersionInfo.SWMajor != 0xFF) break;
-
 
419
        }while(!CheckDelay(timeout));
-
 
420
       
-
 
421
        if(MKOSD_VersionInfo.SWMajor != 0xFF)
-
 
422
        {
-
 
423
                sprintf(msg, "\n\r MK-OSD V%d.%d%c", MKOSD_VersionInfo.SWMajor, MKOSD_VersionInfo.SWMinor, 'a'+MKOSD_VersionInfo.SWPatch);
-
 
424
                UART1_PutString(msg);
-
 
425
        }
-
 
426
        //else UART1_PutString("\n\r No version information from MK-OSD.");     
-
 
427
}
374
 
428