Rev 44 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 44 | Rev 171 | ||
---|---|---|---|
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 / 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 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 this software (or part of it) to systems (other than 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 "91x_lib.h" |
57 | #include "91x_lib.h" |
58 | #include "uart1.h" |
58 | #include "uart1.h" |
59 | #include "ubx.h" |
59 | #include "ubx.h" |
60 | #include <stdio.h> |
60 | #include <stdio.h> |
61 | 61 | ||
62 | //------------------------------------------------------------------------------------ |
62 | //------------------------------------------------------------------------------------ |
63 | // global variables |
63 | // global variables |
64 | 64 | ||
65 | 65 | ||
66 | // UART0 MUXER |
66 | // UART0 MUXER |
67 | typedef enum |
67 | typedef enum |
68 | { |
68 | { |
69 | UART0_UNDEF, |
69 | UART0_UNDEF, |
70 | UART0_MK3MAG, |
70 | UART0_MK3MAG, |
71 | UART0_MKGPS |
71 | UART0_MKGPS |
72 | } UART0_MuxerState_t; |
72 | } UART0_MuxerState_t; |
73 | 73 | ||
74 | UART0_MuxerState_t UART0_Muxer = UART0_UNDEF; |
74 | UART0_MuxerState_t UART0_Muxer = UART0_UNDEF; |
75 | u16 Uart0Baudrate = BAUD_RATE; |
75 | u16 Uart0Baudrate = BAUD_RATE; |
76 | u16 Uart0MK3MagBaudrate = BAUD_RATE; |
76 | u16 Uart0MK3MagBaudrate = BAUD_RATE; |
77 | 77 | ||
78 | //------------------------------------------------------------------------------------ |
78 | //------------------------------------------------------------------------------------ |
79 | // functions |
79 | // functions |
80 | 80 | ||
81 | /********************************************************/ |
81 | /********************************************************/ |
82 | /* Connect RXD & TXD to GPS */ |
82 | /* Connect RXD & TXD to GPS */ |
83 | /********************************************************/ |
83 | /********************************************************/ |
84 | void UART0_Connect_to_MKGPS(void) |
84 | void UART0_Connect_to_MKGPS(void) |
85 | { |
85 | { |
86 | GPIO_InitTypeDef GPIO_InitStructure; |
86 | GPIO_InitTypeDef GPIO_InitStructure; |
87 | 87 | ||
88 | UART0_Muxer = UART0_UNDEF; |
88 | UART0_Muxer = UART0_UNDEF; |
89 | 89 | ||
90 | SCU_APBPeriphClockConfig(__GPIO6, ENABLE); // Enable the GPIO6 Clock |
90 | SCU_APBPeriphClockConfig(__GPIO6, ENABLE); // Enable the GPIO6 Clock |
91 | // unmap UART0 from Compass |
91 | // unmap UART0 from Compass |
92 | // set port pin 5.1 (serial data from compass) to input and disconnect from IP |
92 | // set port pin 5.1 (serial data from compass) to input and disconnect from IP |
93 | GPIO_StructInit(&GPIO_InitStructure); |
93 | GPIO_StructInit(&GPIO_InitStructure); |
94 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
94 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
95 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
95 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
96 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
96 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
97 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
97 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
98 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
98 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
99 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
99 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
100 | // set port pin 5.0 (serial data to compass) to input |
100 | // set port pin 5.0 (serial data to compass) to input |
101 | GPIO_StructInit(&GPIO_InitStructure); |
101 | GPIO_StructInit(&GPIO_InitStructure); |
102 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
102 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
103 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
103 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
104 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
104 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
105 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
105 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
106 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
106 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
107 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
107 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
108 | // map UART0 to GPS |
108 | // map UART0 to GPS |
109 | // set port pin 6.6 (serial data from gps) to input and connect to IP |
109 | // set port pin 6.6 (serial data from gps) to input and connect to IP |
110 | GPIO_StructInit(&GPIO_InitStructure); |
110 | GPIO_StructInit(&GPIO_InitStructure); |
111 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
111 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
112 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
112 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
113 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
113 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
114 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
114 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
115 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //UART0_RxD |
115 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //UART0_RxD |
116 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
116 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
117 | // set port pin 6.7 (serial data to gps) to output |
117 | // set port pin 6.7 (serial data to gps) to output |
118 | GPIO_StructInit(&GPIO_InitStructure); |
118 | GPIO_StructInit(&GPIO_InitStructure); |
119 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
119 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
120 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
120 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
121 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
121 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
122 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
122 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
123 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3; //UART0_TX |
123 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3; //UART0_TX |
124 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
124 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
125 | 125 | ||
126 | UART0_Muxer = UART0_MKGPS; |
126 | UART0_Muxer = UART0_MKGPS; |
127 | } |
127 | } |
128 | 128 | ||
129 | /********************************************************/ |
129 | /********************************************************/ |
130 | /* Connect RXD & TXD to MK3MAG */ |
130 | /* Connect RXD & TXD to MK3MAG */ |
131 | /********************************************************/ |
131 | /********************************************************/ |
132 | void UART0_Connect_to_MK3MAG(void) |
132 | void UART0_Connect_to_MK3MAG(void) |
133 | { |
133 | { |
134 | GPIO_InitTypeDef GPIO_InitStructure; |
134 | GPIO_InitTypeDef GPIO_InitStructure; |
135 | 135 | ||
136 | UART0_Muxer = UART0_UNDEF; |
136 | UART0_Muxer = UART0_UNDEF; |
137 | 137 | ||
138 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); |
138 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); |
139 | // unmap UART0 from GPS |
139 | // unmap UART0 from GPS |
140 | // set port pin 6.6 (serial data from gps) to input and disconnect from IP |
140 | // set port pin 6.6 (serial data from gps) to input and disconnect from IP |
141 | GPIO_StructInit(&GPIO_InitStructure); |
141 | GPIO_StructInit(&GPIO_InitStructure); |
142 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
142 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
143 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
143 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
144 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
144 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
145 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
145 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
146 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
146 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
147 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
147 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
148 | // set port pin 6.7 (serial data to gps) to input |
148 | // set port pin 6.7 (serial data to gps) to input |
149 | GPIO_StructInit(&GPIO_InitStructure); |
149 | GPIO_StructInit(&GPIO_InitStructure); |
150 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
150 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
151 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
151 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
152 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
152 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
153 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
153 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
154 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
154 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
155 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
155 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
156 | 156 | ||
157 | // map UART0 to Compass |
157 | // map UART0 to Compass |
158 | // set port pin 5.1 (serial data from compass) to input and connect to IP |
158 | // set port pin 5.1 (serial data from compass) to input and connect to IP |
159 | GPIO_StructInit(&GPIO_InitStructure); |
159 | GPIO_StructInit(&GPIO_InitStructure); |
160 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
160 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
161 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
161 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
162 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
162 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
163 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
163 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
164 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //UART0_RxD |
164 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; //UART0_RxD |
165 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
165 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
166 | // set port pin 5.0 (serial data to compass) to output |
166 | // set port pin 5.0 (serial data to compass) to output |
167 | GPIO_StructInit(&GPIO_InitStructure); |
167 | GPIO_StructInit(&GPIO_InitStructure); |
168 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
168 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
169 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
169 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
170 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
170 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
171 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
171 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
172 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3; //UART0_TX |
172 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3; //UART0_TX |
173 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
173 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
174 | 174 | ||
175 | UART0_Muxer = UART0_MK3MAG; |
175 | UART0_Muxer = UART0_MK3MAG; |
176 | } |
176 | } |
177 | 177 | ||
178 | /********************************************************/ |
178 | /********************************************************/ |
179 | /* Initialize UART0 */ |
179 | /* Initialize UART0 */ |
180 | /********************************************************/ |
180 | /********************************************************/ |
181 | void UART0_Init(void) |
181 | void UART0_Init(void) |
182 | { |
182 | { |
183 | UART_InitTypeDef UART_InitStructure; |
183 | UART_InitTypeDef UART_InitStructure; |
184 | 184 | ||
185 | SerialPutString("\r\n UART0 init..."); |
185 | SerialPutString("\r\n UART0 init..."); |
186 | 186 | ||
187 | SCU_APBPeriphClockConfig(__UART0, ENABLE); // Enable the UART0 Clock |
187 | SCU_APBPeriphClockConfig(__UART0, ENABLE); // Enable the UART0 Clock |
188 | 188 | ||
189 | Uart0Baudrate = BAUD_RATE + ((BAUD_RATE * 2)/100); // MK3Mag baudrate is a litlle bit higher... |
189 | Uart0Baudrate = BAUD_RATE + ((BAUD_RATE * 2)/100); // MK3Mag baudrate is a litlle bit higher... |
190 | 190 | ||
191 | /* UART0 configured as follow: |
191 | /* UART0 configured as follow: |
192 | - Word Length = 8 Bits |
192 | - Word Length = 8 Bits |
193 | - One Stop Bit |
193 | - One Stop Bit |
194 | - No parity |
194 | - No parity |
195 | - BaudRate = 57600 baud |
195 | - BaudRate = 57600 baud |
196 | - Hardware flow control Disabled |
196 | - Hardware flow control Disabled |
197 | - Receive and transmit enabled |
197 | - Receive and transmit enabled |
198 | - Receive and transmit FIFOs are Disabled |
198 | - Receive and transmit FIFOs are Disabled |
199 | */ |
199 | */ |
200 | UART_StructInit(&UART_InitStructure); |
200 | UART_StructInit(&UART_InitStructure); |
201 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
201 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
202 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
202 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
203 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
203 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
204 | UART_InitStructure.UART_BaudRate = Uart0Baudrate; |
204 | UART_InitStructure.UART_BaudRate = Uart0Baudrate; |
205 | UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
205 | UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
206 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
206 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
207 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
207 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
208 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
208 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
209 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
209 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
210 | 210 | ||
211 | UART_DeInit(UART0); // reset uart 0 to default |
211 | UART_DeInit(UART0); // reset uart 0 to default |
212 | UART_Init(UART0, &UART_InitStructure); // initialize uart 0 |
212 | UART_Init(UART0, &UART_InitStructure); // initialize uart 0 |
213 | 213 | ||
214 | // enable uart 0 interrupts selective |
214 | // enable uart 0 interrupts selective |
215 | UART_ITConfig(UART0, UART_IT_Receive | UART_IT_ReceiveTimeOut /*| UART_IT_FrameError*/, ENABLE); |
215 | UART_ITConfig(UART0, UART_IT_Receive | UART_IT_ReceiveTimeOut /*| UART_IT_FrameError*/, ENABLE); |
216 | UART_Cmd(UART0, ENABLE); // enable uart 0 |
216 | UART_Cmd(UART0, ENABLE); // enable uart 0 |
217 | // configure the uart 0 interupt line as an IRQ with priority 10 (0 is highest) |
217 | // configure the uart 0 interupt line as an IRQ with priority 10 (0 is highest) |
218 | VIC_Config(UART0_ITLine, VIC_IRQ, 10); |
218 | VIC_Config(UART0_ITLine, VIC_IRQ, 10); |
219 | // enable the uart 0 IRQ |
219 | // enable the uart 0 IRQ |
220 | VIC_ITCmd(UART0_ITLine, ENABLE); |
220 | VIC_ITCmd(UART0_ITLine, ENABLE); |
221 | UART0_Connect_to_MKGPS(); |
221 | UART0_Connect_to_MKGPS(); |
222 | SerialPutString("ok"); |
222 | SerialPutString("ok"); |
223 | } |
223 | } |
224 | 224 | ||
225 | /********************************************************/ |
225 | /********************************************************/ |
226 | /* UART0 Interrupt Handler */ |
226 | /* UART0 Interrupt Handler */ |
227 | /********************************************************/ |
227 | /********************************************************/ |
228 | void UART0_IRQHandler(void) |
228 | void UART0_IRQHandler(void) |
229 | { |
229 | { |
230 | u8 c; |
230 | u8 c; |
231 | /* |
231 | /* |
232 | static u8 frame_error_cnt = 0; |
232 | static u8 frame_error_cnt = 0; |
233 | |
233 | |
234 | // use frame error to adjust baudrate for MK3MAG |
234 | // use frame error to adjust baudrate for MK3MAG |
235 | if((UART_GetITStatus(UART0, UART_IT_FrameError) == SET)) |
235 | if((UART_GetITStatus(UART0, UART_IT_FrameError) == SET)) |
236 | { |
236 | { |
237 | u8 msg[20]; |
237 | u8 msg[20]; |
238 | frame_error_cnt++; |
238 | frame_error_cnt++; |
239 | |
239 | |
240 | if (frame_error_cnt == 200) |
240 | if (frame_error_cnt == 200) |
241 | { |
241 | { |
242 | frame_error_cnt = 0; |
242 | frame_error_cnt = 0; |
243 | VIC_ITCmd(UART0_ITLine, DISABLE); |
243 | VIC_ITCmd(UART0_ITLine, DISABLE); |
244 | |
244 | |
245 | Uart0MK3MagBaudrate +=100; |
245 | Uart0MK3MagBaudrate +=100; |
246 | if (Uart0MK3MagBaudrate > (BAUD_RATE+1000)) Uart0MK3MagBaudrate = BAUD_RATE; |
246 | if (Uart0MK3MagBaudrate > (BAUD_RATE+1000)) Uart0MK3MagBaudrate = BAUD_RATE; |
247 | |
247 | |
248 | Uart0Baudrate = Uart0MK3MagBaudrate; |
248 | Uart0Baudrate = Uart0MK3MagBaudrate; |
249 | |
249 | |
250 | SerialPutString(" adjusting UART0 baudrate to"); |
250 | SerialPutString(" adjusting UART0 baudrate to"); |
251 | sprintf(msg, " %d baud...", Uart0MK3MagBaudrate); SerialPutString(msg); |
251 | sprintf(msg, " %d baud...", Uart0MK3MagBaudrate); SerialPutString(msg); |
252 | |
252 | |
253 | while(UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET) |
253 | while(UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET) |
254 | { |
254 | { |
255 | c = UART_ReceiveData(UART0); |
255 | c = UART_ReceiveData(UART0); |
256 | } |
256 | } |
257 | |
257 | |
258 | UART_ClearITPendingBit(UART0, UART_IT_FrameError); // clear frame error interrupt flag |
258 | UART_ClearITPendingBit(UART0, UART_IT_FrameError); // clear frame error interrupt flag |
259 | |
259 | |
260 | UART0_Init(); |
260 | UART0_Init(); |
261 | return; |
261 | return; |
262 | } |
262 | } |
263 | |
263 | |
264 | }*/ |
264 | }*/ |
265 | // if receive irq or receive timeout irq has occured |
265 | // if receive irq or receive timeout irq has occured |
266 | if((UART_GetITStatus(UART0, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART0, UART_IT_ReceiveTimeOut) != RESET) ) |
266 | if((UART_GetITStatus(UART0, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART0, UART_IT_ReceiveTimeOut) != RESET) ) |
267 | { |
267 | { |
268 | UART_ClearITPendingBit(UART0, UART_IT_Receive); // clear receive interrupt flag |
268 | UART_ClearITPendingBit(UART0, UART_IT_Receive); // clear receive interrupt flag |
269 | UART_ClearITPendingBit(UART0, UART_IT_ReceiveTimeOut); // clear receive timeout interrupt flag |
269 | UART_ClearITPendingBit(UART0, UART_IT_ReceiveTimeOut); // clear receive timeout interrupt flag |
270 | 270 | ||
271 | // if debug UART is UART0 |
271 | // if debug UART is UART0 |
272 | if (DebugUART == UART0) |
272 | if (DebugUART == UART0) |
273 | { // forward received data to the UART1 tx buffer |
273 | { // forward received data to the UART1 tx buffer |
274 | while(UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET) |
274 | while(UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET) |
275 | { |
275 | { |
276 | // wait for space in the tx buffer of the UART1 |
276 | // wait for space in the tx buffer of the UART1 |
277 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {}; |
277 | while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {}; |
278 | // move the byte from the rx buffer of UART0 to the tx buffer of UART1 |
278 | // move the byte from the rx buffer of UART0 to the tx buffer of UART1 |
279 | UART_SendData(UART1, UART_ReceiveData(UART0)); |
279 | UART_SendData(UART1, UART_ReceiveData(UART0)); |
280 | } |
280 | } |
281 | } |
281 | } |
282 | else // UART0 is not the DebugUART (normal operation) |
282 | else // UART0 is not the DebugUART (normal operation) |
283 | { |
283 | { |
284 | // repeat until no byte is in the RxFIFO |
284 | // repeat until no byte is in the RxFIFO |
285 | while (UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET) |
285 | while (UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET) |
286 | { |
286 | { |
287 | c = UART_ReceiveData(UART0); // get byte from rx fifo |
287 | c = UART_ReceiveData(UART0); // get byte from rx fifo |
288 | switch(UART0_Muxer) |
288 | switch(UART0_Muxer) |
289 | { |
289 | { |
290 | case UART0_MKGPS: |
290 | case UART0_MKGPS: |
291 | UBX_Parser(c); // if connected to GPS forward byte to ubx parser |
291 | UBX_Parser(c); // if connected to GPS forward byte to ubx parser |
292 | break; |
292 | break; |
293 | case UART0_MK3MAG: |
293 | case UART0_MK3MAG: |
294 | // ignore any byte send from MK3MAG |
294 | // ignore any byte send from MK3MAG |
295 | break; |
295 | break; |
296 | case UART0_UNDEF: |
296 | case UART0_UNDEF: |
297 | default: |
297 | default: |
298 | // ignore the byte from unknown source |
298 | // ignore the byte from unknown source |
299 | break; |
299 | break; |
300 | } // eof switch(UART0_Muxer) |
300 | } // eof switch(UART0_Muxer) |
301 | } // eof while |
301 | } // eof while |
302 | } // eof UART0 is not the DebugUART |
302 | } // eof UART0 is not the DebugUART |
303 | } // eof receive irq or receive timeout irq |
303 | } // eof receive irq or receive timeout irq |
304 | } |
304 | } |
305 | 305 |