Subversion Repositories NaviCtrl

Rev

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

Rev 196 Rev 245
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 / NON-COMMERCIAL USE ONLY
6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
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 oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
28
// + Die Portierung oder Nutzung 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 the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
43
// +   * porting the sources to other systems or using the software on other systems (except 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 <string.h>
60
#include "91x_lib.h"
60
#include "91x_lib.h"
61
#include "config.h"
61
#include "config.h"
62
#include "main.h"
62
#include "main.h"
63
#include "uart0.h"
63
#include "uart0.h"
64
#include "uart1.h"
64
#include "uart1.h"
65
#include "timer1.h"
65
#include "timer1.h"
66
#include "ubx.h"
66
#include "ubx.h"
67
#include "mkprotocol.h"
67
#include "mkprotocol.h"
68
 
68
 
69
 
69
 
70
//------------------------------------------------------------------------------------
70
//------------------------------------------------------------------------------------
71
// global variables
71
// global variables
72
 
72
 
73
MKOSD_VersionInfo_t MKOSD_VersionInfo;
73
MKOSD_VersionInfo_t MKOSD_VersionInfo;
74
 
74
 
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  200
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  200
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
 
89
 
90
u8 UART0_Request_VersionInfo    = FALSE;
90
u8 UART0_Request_VersionInfo    = FALSE;
91
u8 UART0_Request_NaviData               = FALSE;
91
u8 UART0_Request_NaviData               = FALSE;
92
u8 UART0_Request_ErrorMessage   = FALSE;
92
u8 UART0_Request_ErrorMessage   = FALSE;
93
u32 UART0_NaviData_Timer;
93
u32 UART0_NaviData_Timer;
94
u32 UART0_NaviData_Interval = 0;        // in ms
94
u32 UART0_NaviData_Interval = 0;        // in ms
95
 
95
 
96
//------------------------------------------------------------------------------------
96
//------------------------------------------------------------------------------------
97
// functions
97
// functions
98
 
98
 
99
/********************************************************/
99
/********************************************************/
-
 
100
/*              Configure uart 0                        */
-
 
101
/********************************************************/
-
 
102
void UART0_Configure(u16 Baudrate)
-
 
103
{
-
 
104
        UART_InitTypeDef UART_InitStructure;
-
 
105
 
-
 
106
        SCU_APBPeriphClockConfig(__UART0, ENABLE);  // Enable the UART0 Clock
-
 
107
 
-
 
108
        /* UART0 configured as follow:
-
 
109
          - Word Length = 8 Bits
-
 
110
          - One Stop Bit
-
 
111
          - No parity
-
 
112
          - BaudRate taken from function argument
-
 
113
          - Hardware flow control Disabled
-
 
114
          - Receive and transmit enabled
-
 
115
          - Receive and transmit FIFOs are Disabled
-
 
116
    */
-
 
117
        UART_StructInit(&UART_InitStructure);
-
 
118
    UART_InitStructure.UART_WordLength =                        UART_WordLength_8D;
-
 
119
    UART_InitStructure.UART_StopBits =                          UART_StopBits_1;
-
 
120
    UART_InitStructure.UART_Parity =                            UART_Parity_No ;
-
 
121
    UART_InitStructure.UART_BaudRate =                          Baudrate;
-
 
122
    UART_InitStructure.UART_HardwareFlowControl =       UART_HardwareFlowControl_None;
-
 
123
    UART_InitStructure.UART_Mode =                                      UART_Mode_Tx_Rx;
-
 
124
    UART_InitStructure.UART_FIFO =                                      UART_FIFO_Enable;
-
 
125
    UART_InitStructure.UART_TxFIFOLevel =                       UART_FIFOLevel_1_2;
-
 
126
    UART_InitStructure.UART_RxFIFOLevel =                       UART_FIFOLevel_1_2;
-
 
127
 
-
 
128
        UART_DeInit(UART0);     // reset uart 0 to default
-
 
129
    UART_Init(UART0, &UART_InitStructure);  // initialize uart 0
-
 
130
 
-
 
131
        // enable uart 0 interrupts selective
-
 
132
    UART_ITConfig(UART0, UART_IT_Receive | UART_IT_ReceiveTimeOut  /*| UART_IT_FrameError*/, ENABLE);
-
 
133
        UART_Cmd(UART0, ENABLE); // enable uart 0
-
 
134
        // configure the uart 0 interupt line
-
 
135
        VIC_Config(UART0_ITLine, VIC_IRQ, PRIORITY_UART0);
-
 
136
        // enable the uart 0 IRQ
-
 
137
        VIC_ITCmd(UART0_ITLine, ENABLE);
-
 
138
}
-
 
139
 
-
 
140
/********************************************************/
100
/*              Connect RXD & TXD to GPS                */
141
/*              Connect RXD & TXD to GPS                */
101
/********************************************************/
142
/********************************************************/
102
void UART0_Connect_to_MKGPS(void)
143
void UART0_Connect_to_MKGPS(u16 Baudrate)
103
{
144
{
104
        GPIO_InitTypeDef GPIO_InitStructure;
145
        GPIO_InitTypeDef GPIO_InitStructure;
105
 
146
 
106
        UART0_Muxer = UART0_UNDEF;
147
        UART0_Muxer = UART0_UNDEF;
107
 
148
 
108
        SCU_APBPeriphClockConfig(__GPIO6, ENABLE); // Enable the GPIO6 Clock
149
        SCU_APBPeriphClockConfig(__GPIO6, ENABLE); // Enable the GPIO6 Clock
109
        // unmap UART0 from Compass
150
        // unmap UART0 from Compass
110
        // set port pin 5.1 (serial data from compass) to input and disconnect from IP
151
        // set port pin 5.1 (serial data from compass) to input and disconnect from IP
111
        GPIO_StructInit(&GPIO_InitStructure);
152
        GPIO_StructInit(&GPIO_InitStructure);
112
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
153
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
113
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_1;
154
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_1;
114
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull ;
155
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull ;
115
    GPIO_InitStructure.GPIO_IPInputConnected =  GPIO_IPInputConnected_Disable;
156
    GPIO_InitStructure.GPIO_IPInputConnected =  GPIO_IPInputConnected_Disable;
116
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
157
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
117
    GPIO_Init(GPIO5, &GPIO_InitStructure);
158
    GPIO_Init(GPIO5, &GPIO_InitStructure);
118
        // set port pin 5.0 (serial data to compass) to input
159
        // set port pin 5.0 (serial data to compass) to input
119
        GPIO_StructInit(&GPIO_InitStructure);
160
        GPIO_StructInit(&GPIO_InitStructure);
120
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
161
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
121
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_0;
162
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_0;
122
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
163
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
123
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Disable;
164
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Disable;
124
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
165
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
125
    GPIO_Init(GPIO5, &GPIO_InitStructure);
166
    GPIO_Init(GPIO5, &GPIO_InitStructure);
126
        // map UART0 to GPS
167
        // map UART0 to GPS
127
        // set port pin 6.6 (serial data from gps) to input and connect to IP
168
        // set port pin 6.6 (serial data from gps) to input and connect to IP
128
        GPIO_StructInit(&GPIO_InitStructure);
169
        GPIO_StructInit(&GPIO_InitStructure);
129
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
170
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
130
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_6;
171
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_6;
131
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull ;
172
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull ;
132
    GPIO_InitStructure.GPIO_IPInputConnected =  GPIO_IPInputConnected_Enable;
173
    GPIO_InitStructure.GPIO_IPInputConnected =  GPIO_IPInputConnected_Enable;
133
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1; //UART0_RxD
174
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1; //UART0_RxD
134
    GPIO_Init(GPIO6, &GPIO_InitStructure);
175
    GPIO_Init(GPIO6, &GPIO_InitStructure);
135
        // set port pin 6.7 (serial data to gps) to output
176
        // set port pin 6.7 (serial data to gps) to output
136
        GPIO_StructInit(&GPIO_InitStructure);
177
        GPIO_StructInit(&GPIO_InitStructure);
137
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
178
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
138
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_7;
179
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_7;
139
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
180
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
140
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Enable;
181
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Enable;
141
    GPIO_InitStructure.GPIO_Alternate =         GPIO_OutputAlt3; //UART0_TX
182
    GPIO_InitStructure.GPIO_Alternate =         GPIO_OutputAlt3; //UART0_TX
142
    GPIO_Init(GPIO6, &GPIO_InitStructure);
183
    GPIO_Init(GPIO6, &GPIO_InitStructure);
-
 
184
        // configure the UART0
-
 
185
        UART0_Configure(Baudrate);
143
       
186
       
144
        UART0_Muxer = UART0_MKGPS;
187
        UART0_Muxer = UART0_MKGPS;
145
}
188
}
146
 
189
 
147
/********************************************************/
190
/********************************************************/
148
/*              Connect RXD & TXD to MK3MAG             */
191
/*              Connect RXD & TXD to MK3MAG             */
149
/********************************************************/
192
/********************************************************/
150
void UART0_Connect_to_MK3MAG(void)
193
void UART0_Connect_to_MK3MAG(void)
151
{
194
{
-
 
195
        u16 Baudrate;
-
 
196
 
152
        GPIO_InitTypeDef GPIO_InitStructure;
197
        GPIO_InitTypeDef GPIO_InitStructure;
153
 
198
 
154
        UART0_Muxer = UART0_UNDEF;
199
        UART0_Muxer = UART0_UNDEF;
155
 
200
 
156
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE);
201
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE);
157
        // unmap UART0 from GPS
202
        // unmap UART0 from GPS
158
        // set port pin 6.6 (serial data from gps) to input and disconnect from IP
203
        // set port pin 6.6 (serial data from gps) to input and disconnect from IP
159
        GPIO_StructInit(&GPIO_InitStructure);
204
        GPIO_StructInit(&GPIO_InitStructure);
160
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
205
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
161
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_6;
206
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_6;
162
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
207
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
163
    GPIO_InitStructure.GPIO_IPInputConnected =  GPIO_IPInputConnected_Disable;
208
    GPIO_InitStructure.GPIO_IPInputConnected =  GPIO_IPInputConnected_Disable;
164
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
209
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
165
    GPIO_Init(GPIO6, &GPIO_InitStructure);
210
    GPIO_Init(GPIO6, &GPIO_InitStructure);
166
        // set port pin 6.7 (serial data to gps) to input
211
        // set port pin 6.7 (serial data to gps) to input
167
        GPIO_StructInit(&GPIO_InitStructure);
212
        GPIO_StructInit(&GPIO_InitStructure);
168
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
213
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
169
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_7;
214
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_7;
170
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
215
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
171
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Disable;
216
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Disable;
172
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
217
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
173
    GPIO_Init(GPIO6, &GPIO_InitStructure);
218
    GPIO_Init(GPIO6, &GPIO_InitStructure);
174
 
219
 
175
        // map UART0 to Compass
220
        // map UART0 to Compass
176
        // set port pin 5.1 (serial data from compass) to input and connect to IP
221
        // set port pin 5.1 (serial data from compass) to input and connect to IP
177
        GPIO_StructInit(&GPIO_InitStructure);
222
        GPIO_StructInit(&GPIO_InitStructure);
178
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
223
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
179
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_1;
224
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_1;
180
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull ;
225
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull ;
181
    GPIO_InitStructure.GPIO_IPInputConnected =  GPIO_IPInputConnected_Enable;
226
    GPIO_InitStructure.GPIO_IPInputConnected =  GPIO_IPInputConnected_Enable;
182
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1; //UART0_RxD
227
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1; //UART0_RxD
183
    GPIO_Init(GPIO5, &GPIO_InitStructure);
228
    GPIO_Init(GPIO5, &GPIO_InitStructure);
184
        // set port pin 5.0 (serial data to compass) to output
229
        // set port pin 5.0 (serial data to compass) to output
185
        GPIO_StructInit(&GPIO_InitStructure);
230
        GPIO_StructInit(&GPIO_InitStructure);
186
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
231
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
187
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_0;
232
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_0;
188
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
233
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
189
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Enable;
234
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Enable;
190
    GPIO_InitStructure.GPIO_Alternate =         GPIO_OutputAlt3; //UART0_TX
235
    GPIO_InitStructure.GPIO_Alternate =         GPIO_OutputAlt3; //UART0_TX
191
    GPIO_Init(GPIO5, &GPIO_InitStructure);
236
    GPIO_Init(GPIO5, &GPIO_InitStructure);
192
 
-
 
-
 
237
        Baudrate = UART0_BAUD_RATE + ((UART0_BAUD_RATE * 2)/100);   // MK3Mag baudrate is a little bit higher...
-
 
238
        UART0_Configure(Baudrate);
193
        UART0_Muxer = UART0_MK3MAG;
239
        UART0_Muxer = UART0_MK3MAG;
194
}
240
}
195
 
241
 
196
/********************************************************/
242
/********************************************************/
197
/*                  Initialize UART0                    */
243
/*                  Initialize UART0                    */
198
/********************************************************/
244
/********************************************************/
199
void UART0_Init(void)
245
void UART0_Init(void)
200
{
246
{
201
    UART_InitTypeDef UART_InitStructure;
-
 
202
       
-
 
203
        UART1_PutString("\r\n UART0 init...");
247
        UART1_PutString("\r\n UART0 init...");
204
 
-
 
205
        SCU_APBPeriphClockConfig(__UART0, ENABLE);  // Enable the UART0 Clock
-
 
206
 
-
 
207
        Uart0Baudrate = UART0_BAUD_RATE + ((UART0_BAUD_RATE * 2)/100);   // MK3Mag baudrate is a litlle bit higher...
-
 
208
 
-
 
209
        /* UART0 configured as follow:
-
 
210
          - Word Length = 8 Bits
-
 
211
          - One Stop Bit
-
 
212
          - No parity
-
 
213
          - BaudRate = 57600 baud
-
 
214
          - Hardware flow control Disabled
-
 
215
          - Receive and transmit enabled
-
 
216
          - Receive and transmit FIFOs are Disabled
-
 
217
    */
-
 
218
        UART_StructInit(&UART_InitStructure);
-
 
219
    UART_InitStructure.UART_WordLength =                        UART_WordLength_8D;
-
 
220
    UART_InitStructure.UART_StopBits =                          UART_StopBits_1;
-
 
221
    UART_InitStructure.UART_Parity =                            UART_Parity_No ;
-
 
222
    UART_InitStructure.UART_BaudRate =                          Uart0Baudrate;
-
 
223
    UART_InitStructure.UART_HardwareFlowControl =       UART_HardwareFlowControl_None;
-
 
224
    UART_InitStructure.UART_Mode =                                      UART_Mode_Tx_Rx;
-
 
225
    UART_InitStructure.UART_FIFO =                                      UART_FIFO_Enable;
-
 
226
    UART_InitStructure.UART_TxFIFOLevel =                       UART_FIFOLevel_1_2;
-
 
227
    UART_InitStructure.UART_RxFIFOLevel =                       UART_FIFOLevel_1_2;
-
 
228
 
-
 
229
        UART_DeInit(UART0);     // reset uart 0 to default
-
 
230
    UART_Init(UART0, &UART_InitStructure);  // initialize uart 0
-
 
231
 
-
 
232
        // enable uart 0 interrupts selective
-
 
233
    UART_ITConfig(UART0, UART_IT_Receive | UART_IT_ReceiveTimeOut  /*| UART_IT_FrameError*/, ENABLE);
-
 
234
        UART_Cmd(UART0, ENABLE); // enable uart 0
-
 
235
        // configure the uart 0 interupt line
-
 
236
        VIC_Config(UART0_ITLine, VIC_IRQ, PRIORITY_UART0);
-
 
237
        // enable the uart 0 IRQ
-
 
238
        VIC_ITCmd(UART0_ITLine, ENABLE);
248
 
239
        UART0_Connect_to_MKGPS();
249
        UART0_Connect_to_MKGPS(UART0_BAUD_RATE);
240
 
250
 
241
        // initialize txd buffer
251
        // initialize txd buffer
242
        Buffer_Init(&UART0_tx_buffer, UART0_tbuffer, UART0_TX_BUFFER_LEN);
252
        Buffer_Init(&UART0_tx_buffer, UART0_tbuffer, UART0_TX_BUFFER_LEN);
243
       
253
       
244
        // initialize rxd buffer
254
        // initialize rxd buffer
245
        Buffer_Init(&UART0_rx_buffer, UART0_rbuffer, UART0_RX_BUFFER_LEN);
255
        Buffer_Init(&UART0_rx_buffer, UART0_rbuffer, UART0_RX_BUFFER_LEN);
246
 
256
 
247
        UART1_PutString("ok");
257
        UART1_PutString("ok");
248
}
258
}
249
 
259
 
250
/********************************************************/
260
/********************************************************/
251
/*            UART0 Interrupt Handler                   */
261
/*            UART0 Interrupt Handler                   */
252
/********************************************************/
262
/********************************************************/
253
void UART0_IRQHandler(void)
263
void UART0_IRQHandler(void)
254
{
264
{
255
        u8 c;
265
        u8 c;
256
        // if receive irq (FIFO is over trigger level) or receive timeout irq (FIFO is not empty for longer times) has occured
266
        // if receive irq (FIFO is over trigger level) or receive timeout irq (FIFO is not empty for longer times) has occured
257
        if((UART_GetITStatus(UART0, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART0, UART_IT_ReceiveTimeOut) != RESET) )
267
        if((UART_GetITStatus(UART0, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART0, UART_IT_ReceiveTimeOut) != RESET) )
258
        {
268
        {
259
                UART_ClearITPendingBit(UART0, UART_IT_Receive);                 // clear receive interrupt flag
269
                UART_ClearITPendingBit(UART0, UART_IT_Receive);                 // clear receive interrupt flag
260
                UART_ClearITPendingBit(UART0, UART_IT_ReceiveTimeOut);  // clear receive timeout interrupt flag
270
                UART_ClearITPendingBit(UART0, UART_IT_ReceiveTimeOut);  // clear receive timeout interrupt flag
261
 
271
 
262
                // if debug UART is UART0
272
                // if debug UART is UART0
263
                if (DebugUART == UART0)
273
                if (DebugUART == UART0)
264
                {       // forward received data to the UART1 tx buffer
274
                {       // forward received data to the UART1 tx buffer
265
                        while(UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET)
275
                        while(UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET)
266
                        {
276
                        {
267
                                // wait for space in the tx buffer of the UART1
277
                                // wait for space in the tx buffer of the UART1
268
                                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {};
278
                                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {};
269
                                // move the byte from the rx buffer of UART0 to the tx buffer of UART1
279
                                // move the byte from the rx buffer of UART0 to the tx buffer of UART1
270
                                UART_SendData(UART1, UART_ReceiveData(UART0));
280
                                UART_SendData(UART1, UART_ReceiveData(UART0));
271
                        }
281
                        }
272
                }
282
                }
273
                else // UART0 is not the DebugUART (normal operation)
283
                else // UART0 is not the DebugUART (normal operation)
274
                {
284
                {
275
                        // repeat until no byte is in the RxFIFO
285
                        // repeat until no byte is in the RxFIFO
276
                        while (UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET)
286
                        while (UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET)
277
                        {  
287
                        {  
278
                                c = UART_ReceiveData(UART0); // get byte from rx fifo
288
                                c = UART_ReceiveData(UART0); // get byte from rx fifo
279
                                switch(UART0_Muxer)
289
                                switch(UART0_Muxer)
280
                                {
290
                                {
281
                                        case UART0_MKGPS:
291
                                        case UART0_MKGPS:
282
                                                UBX_Parser(c); // if connected to GPS forward byte to ubx parser
292
                                                UBX_RxParser(c); // if connected to GPS forward byte to ubx parser
283
                                                MKProtocol_CollectSerialFrame(&UART0_rx_buffer, c);     // ckeck for MK-Frames also
293
                                                MKProtocol_CollectSerialFrame(&UART0_rx_buffer, c);     // ckeck for MK-Frames also
284
                                                break;
294
                                                break;
285
                                        case UART0_MK3MAG:
295
                                        case UART0_MK3MAG:
286
                                                // ignore any byte send from MK3MAG
296
                                                // ignore any byte send from MK3MAG
287
                                                break;
297
                                                break;
288
                                        case UART0_UNDEF:
298
                                        case UART0_UNDEF:
289
                                        default:
299
                                        default:
290
                                                // ignore the byte from unknown source
300
                                                // ignore the byte from unknown source
291
                                                break;
301
                                                break;
292
                                } // eof switch(UART0_Muxer)
302
                                } // eof switch(UART0_Muxer)
293
                        } // eof while
303
                        } // eof while
294
                }  // eof UART0 is not the DebugUART
304
                }  // eof UART0 is not the DebugUART
295
        } // eof receive irq or receive timeout irq
305
        } // eof receive irq or receive timeout irq
296
}
306
}
297
 
307
 
298
/**************************************************************/
308
/**************************************************************/
299
/* Process incomming data from debug uart                     */
309
/* Process incomming data from debug uart                     */
300
/**************************************************************/
310
/**************************************************************/
301
void UART0_ProcessRxData(void)
311
void UART0_ProcessRxData(void)
302
{
312
{
303
        SerialMsg_t SerialMsg;
313
        SerialMsg_t SerialMsg;
304
        // if data in the rxd buffer are not locked immediately return
314
        // if data in the rxd buffer are not locked immediately return
305
        if((UART0_rx_buffer.Locked == FALSE) || (DebugUART == UART0) ) return;
315
        if((UART0_rx_buffer.Locked == FALSE) || (DebugUART == UART0) ) return;
306
 
316
 
307
        MKProtocol_DecodeSerialFrameHeader(&UART0_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer  
317
        MKProtocol_DecodeSerialFrameHeader(&UART0_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer  
308
        MKProtocol_DecodeSerialFrameData(&UART0_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
318
        MKProtocol_DecodeSerialFrameData(&UART0_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
309
 
319
 
310
        switch(SerialMsg.Address) // check for Slave Address
320
        switch(SerialMsg.Address) // check for Slave Address
311
        {
321
        {
312
                case MKOSD_ADDRESS: // answers from the MKOSD
322
                case MKOSD_ADDRESS: // answers from the MKOSD
313
                        switch(SerialMsg.CmdID)
323
                        switch(SerialMsg.CmdID)
314
                        {
324
                        {
315
                                case 'V':
325
                                case 'V':
316
                                        memcpy(&MKOSD_VersionInfo, SerialMsg.pData, sizeof(MKOSD_VersionInfo)); // copy echo pattern
326
                                        memcpy(&MKOSD_VersionInfo, SerialMsg.pData, sizeof(MKOSD_VersionInfo)); // copy echo pattern
317
                                        break;
327
                                        break;
318
                                default:
328
                                default:
319
                                        break;
329
                                        break;
320
                        } // case MKOSD_ADDRESS 
330
                        } // case MKOSD_ADDRESS 
321
                        break;
331
                        break;
322
 
332
 
323
                case NC_ADDRESS:  // own Slave Address
333
                case NC_ADDRESS:  // own Slave Address
324
                        switch(SerialMsg.CmdID)
334
                        switch(SerialMsg.CmdID)
325
                        {
335
                        {
326
                                case 'e': // request for the text of the error status
336
                                case 'e': // request for the text of the error status
327
                                        UART0_Request_ErrorMessage = TRUE;
337
                                        UART0_Request_ErrorMessage = TRUE;
328
                                        break;
338
                                        break;
329
                                case 'o': // request for navigation information
339
                                case 'o': // request for navigation information
330
                                        UART0_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
340
                                        UART0_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
331
                                        if(UART0_NaviData_Interval > 0) UART0_Request_NaviData = TRUE;
341
                                        if(UART0_NaviData_Interval > 0) UART0_Request_NaviData = TRUE;
332
                                        break;
342
                                        break;
333
                                default:
343
                                default:
334
                                        break;
344
                                        break;
335
                        } // case NC_ADDRESS
345
                        } // case NC_ADDRESS
336
                        // "break;" is missing here to fall thru to the common commands
346
                        // "break;" is missing here to fall thru to the common commands
337
 
347
 
338
                default:  // and any other Slave Address
348
                default:  // and any other Slave Address
339
                        switch(SerialMsg.CmdID) // check CmdID
349
                        switch(SerialMsg.CmdID) // check CmdID
340
                        {
350
                        {
341
                                case 'v': // request for version info
351
                                case 'v': // request for version info
342
                                        UART0_Request_VersionInfo = TRUE;
352
                                        UART0_Request_VersionInfo = TRUE;
343
                                        break;
353
                                        break;
344
                                default:
354
                                default:
345
                                        // unsupported command recieved
355
                                        // unsupported command recieved
346
                                        break;
356
                                        break;
347
                        }
357
                        }
348
                        break; // default:
358
                        break; // default:
349
        }
359
        }
350
        Buffer_Clear(&UART0_rx_buffer);
360
        Buffer_Clear(&UART0_rx_buffer);
351
}
361
}
352
 
362
 
353
/**************************************************************/
363
/**************************************************************/
354
/*         Transmit tx buffer via uart0                       */
364
/*         Transmit tx buffer via uart0                       */
355
/**************************************************************/
365
/**************************************************************/
356
void UART0_Transmit(void)
366
void UART0_Transmit(void)
357
{
367
{
358
        u8 tmp_tx;
368
        u8 tmp_tx;
359
 
369
 
360
        IENABLE;
370
        IENABLE;
361
 
371
 
362
        if(DebugUART == UART0) return; // no data output if debug uart is rederected to UART0
372
        if(DebugUART == UART0) return; // no data output if debug uart is rederected to UART0
363
        // if something has to be send and the txd fifo is not full
373
        // if something has to be send and the txd fifo is not full
364
        if((UART0_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOFull) == RESET))
374
        if((UART0_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOFull) == RESET))
365
        {
375
        {
366
                tmp_tx = UART0_tx_buffer.pData[UART0_tx_buffer.Position++]; // read next byte from txd buffer
376
                tmp_tx = UART0_tx_buffer.pData[UART0_tx_buffer.Position++]; // read next byte from txd buffer
367
                UART_SendData(UART0, tmp_tx); // put character to txd fifo
377
                UART_SendData(UART0, tmp_tx); // put character to txd fifo
368
                // if terminating character or end of txd buffer reached
378
                // if terminating character or end of txd buffer reached
369
                if((tmp_tx == '\r') || (UART0_tx_buffer.Position == UART0_tx_buffer.Size))
379
                if((tmp_tx == '\r') || (UART0_tx_buffer.Position == UART0_tx_buffer.Size))
370
                {
380
                {
371
                        Buffer_Clear(&UART0_tx_buffer);
381
                        Buffer_Clear(&UART0_tx_buffer);
372
                }
382
                }
373
        }
383
        }
374
 
384
 
375
        IDISABLE;
385
        IDISABLE;
376
}
386
}
377
 
387
 
378
 
388
 
379
/**************************************************************/
389
/**************************************************************/
380
/* Send the answers to incomming commands at the uart0        */
390
/* Send the answers to incomming commands at the uart0        */
381
/**************************************************************/
391
/**************************************************************/
382
void UART0_TransmitTxData(void)
392
void UART0_TransmitTxData(void)
383
{
393
{
384
        if(DebugUART == UART0) return;
394
        if(DebugUART == UART0) return;
385
        UART0_Transmit(); // output pending bytes in tx buffer
395
        UART0_Transmit(); // output pending bytes in tx buffer
386
        if(UART0_tx_buffer.Locked == TRUE) return;
396
        if(UART0_tx_buffer.Locked == TRUE) return;
387
 
397
 
388
        else if(UART0_Request_ErrorMessage && (UART0_tx_buffer.Locked == FALSE))
398
        else if(UART0_Request_ErrorMessage && (UART0_tx_buffer.Locked == FALSE))
389
        {
399
        {
390
                MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
400
                MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
391
                UART0_Request_ErrorMessage = FALSE;
401
                UART0_Request_ErrorMessage = FALSE;
392
        }
402
        }
393
        else if(UART0_Request_VersionInfo && (UART0_tx_buffer.Locked == FALSE))
403
        else if(UART0_Request_VersionInfo && (UART0_tx_buffer.Locked == FALSE))
394
        {
404
        {
395
                MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
405
                MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
396
                UART0_Request_VersionInfo = FALSE;
406
                UART0_Request_VersionInfo = FALSE;
397
        }
407
        }
398
        else if(( ((UART0_NaviData_Interval >0) && CheckDelay(UART0_NaviData_Timer) ) || UART0_Request_NaviData) && (UART0_tx_buffer.Locked == FALSE))
408
        else if(( ((UART0_NaviData_Interval >0) && CheckDelay(UART0_NaviData_Timer) ) || UART0_Request_NaviData) && (UART0_tx_buffer.Locked == FALSE))
399
        {
409
        {
400
                NaviData.Errorcode = ErrorCode;
410
                NaviData.Errorcode = ErrorCode;
401
                MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData));
411
                MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData));
402
                UART0_NaviData_Timer = SetDelay(UART0_NaviData_Interval);
412
                UART0_NaviData_Timer = SetDelay(UART0_NaviData_Interval);
403
                UART0_Request_NaviData = FALSE;
413
                UART0_Request_NaviData = FALSE;
404
        }      
414
        }      
405
        UART0_Transmit(); // output pending bytes in tx buffer
415
        UART0_Transmit(); // output pending bytes in tx buffer
406
}
416
}
407
 
417
 
408
 
418
 
409
/**************************************************************/
419
/**************************************************************/
410
/* Get the version of the MKOSD                               */
420
/* Get the version of the MKOSD                               */
411
/**************************************************************/
421
/**************************************************************/
412
void UART0_GetMKOSDVersion(void)
422
void UART0_GetMKOSDVersion(void)
413
{
423
{
414
        u32 timeout;
424
        u32 timeout;
415
        u8 msg[64];
425
        u8 msg[64];
416
 
426
 
417
        MKOSD_VersionInfo.SWMajor = 0xFF;
427
        MKOSD_VersionInfo.SWMajor = 0xFF;
418
        MKOSD_VersionInfo.SWMinor = 0xFF;
428
        MKOSD_VersionInfo.SWMinor = 0xFF;
419
        MKOSD_VersionInfo.SWPatch = 0xFF;
429
        MKOSD_VersionInfo.SWPatch = 0xFF;
420
 
430
 
421
        if(UART0_Muxer != UART0_MKGPS) UART0_Connect_to_MKGPS();
431
        if(UART0_Muxer != UART0_MKGPS) UART0_Connect_to_MKGPS(UART0_BAUD_RATE);
422
        while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer;
432
        while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer;
423
 
433
 
424
        MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'v', MKOSD_ADDRESS, 0); // request for version info
434
        MKProtocol_CreateSerialFrame(&UART0_tx_buffer, 'v', MKOSD_ADDRESS, 0); // request for version info
425
        while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer;
435
        while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer;
426
       
436
       
427
        timeout = SetDelay(500);
437
        timeout = SetDelay(500);
428
        do
438
        do
429
        {
439
        {
430
                UART0_ProcessRxData();
440
                UART0_ProcessRxData();
431
                if(MKOSD_VersionInfo.SWMajor != 0xFF) break;
441
                if(MKOSD_VersionInfo.SWMajor != 0xFF) break;
432
        }while(!CheckDelay(timeout));
442
        }while(!CheckDelay(timeout));
433
       
443
       
434
        if(MKOSD_VersionInfo.SWMajor != 0xFF)
444
        if(MKOSD_VersionInfo.SWMajor != 0xFF)
435
        {
445
        {
436
                sprintf(msg, "\n\r MK-OSD V%d.%d%c", MKOSD_VersionInfo.SWMajor, MKOSD_VersionInfo.SWMinor, 'a'+MKOSD_VersionInfo.SWPatch);
446
                sprintf(msg, "\n\r MK-OSD V%d.%d%c", MKOSD_VersionInfo.SWMajor, MKOSD_VersionInfo.SWMinor, 'a'+MKOSD_VersionInfo.SWPatch);
437
                UART1_PutString(msg);
447
                UART1_PutString(msg);
438
        }
448
        }
439
        //else UART1_PutString("\n\r No version information from MK-OSD.");     
449
        //else UART1_PutString("\n\r No version information from MK-OSD.");     
440
}
450
}
-
 
451
 
-
 
452
 
-
 
453
/**************************************************************/
-
 
454
/* Send a configuration message to the UBLOX device           */
-
 
455
/**************************************************************/
-
 
456
u8 UART0_UBXSendCFGMsg(u8 Id, u8* pData, u16 Len)
-
 
457
{
-
 
458
        u32 timeout;
-
 
459
        u8 retval = 0;
-
 
460
        // check for connection to GPS
-
 
461
        if(UART0_Muxer != UART0_MKGPS) return(retval);
-
 
462
        // free the acknowledge buffer
-
 
463
        UbxAck.Status = INVALID;
-
 
464
        while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer;
-
 
465
        UBX_CreateMsg(&UART0_tx_buffer, UBX_CLASS_CFG, Id, pData, Len);  // build ubx message frame
-
 
466
        while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer;
-
 
467
        // check for acknowledge
-
 
468
        timeout = SetDelay(500);
-
 
469
        do
-
 
470
        {
-
 
471
                if(UbxAck.Status == NEWDATA) break;
-
 
472
        }while(!CheckDelay(timeout));
-
 
473
        if(UbxAck.Status == NEWDATA)
-
 
474
        {
-
 
475
                if((UbxAck.clsID == UBX_CLASS_CFG) && (UbxAck.msgID == Id)) retval = UbxAck.Ack;
-
 
476
        }
-
 
477
        UbxAck.Status = INVALID;
-
 
478
        return(retval);
-
 
479
}
441
 
480