Rev 23 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 23 | 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 "main.h" |
57 | #include "main.h" |
58 | 58 | ||
59 | u8 NewGPSDataAvail = 0; |
59 | u8 NewGPSDataAvail = 0; |
60 | u8 NewPCTargetGPSPosition = 0; |
60 | u8 NewPCTargetGPSPosition = 0; |
61 | u8 GPS_RxBuffer[GPS_RX_SIZE]; |
61 | u8 GPS_RxBuffer[GPS_RX_SIZE]; |
62 | 62 | ||
63 | struct str_ubx_nav_sol *GPS_DataSol; |
63 | struct str_ubx_nav_sol *GPS_DataSol; |
64 | struct str_ubx_nav_posllh *GPS_DataPosllh; |
64 | struct str_ubx_nav_posllh *GPS_DataPosllh; |
65 | struct str_ubx_nav_velned *GPS_DataVelned; |
65 | struct str_ubx_nav_velned *GPS_DataVelned; |
66 | struct str_ubx_nav_posutm *GPS_DataPosutm; |
66 | struct str_ubx_nav_posutm *GPS_DataPosutm; |
67 | struct str_gps_nav_data GPS_Data; |
67 | struct str_gps_nav_data GPS_Data; |
68 | 68 | ||
69 | 69 | ||
70 | // ----------------------------- GPS - Receive ------------------------------------ |
70 | // ----------------------------- GPS - Receive ------------------------------------ |
71 | // --- Connect RXD & TXD to GPS --- |
71 | // --- Connect RXD & TXD to GPS --- |
72 | void Connect_UART0_to_GPS(void) |
72 | void Connect_UART0_to_GPS(void) |
73 | { |
73 | { |
74 | GPIO_InitTypeDef GPIO_InitStructure; |
74 | GPIO_InitTypeDef GPIO_InitStructure; |
75 | 75 | ||
76 | SCU_APBPeriphClockConfig(__GPIO6, ENABLE); |
76 | SCU_APBPeriphClockConfig(__GPIO6, ENABLE); |
77 | 77 | ||
78 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
78 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
79 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
79 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
80 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
80 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
81 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
81 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
82 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
82 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
83 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
83 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
84 | 84 | ||
85 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
85 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
86 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
86 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
87 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
87 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
88 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
88 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
89 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
89 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
90 | 90 | ||
91 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
91 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
92 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
92 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; |
93 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
93 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
94 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
94 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
95 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
95 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
96 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
96 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
97 | 97 | ||
98 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
98 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
99 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
99 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
100 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
100 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
101 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3 ; |
101 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3 ; |
102 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
102 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
103 | } |
103 | } |
104 | //----------------------------------------------- |
104 | //----------------------------------------------- |
105 | void Connect_UART0_to_Compass(void) |
105 | void Connect_UART0_to_Compass(void) |
106 | { |
106 | { |
107 | GPIO_InitTypeDef GPIO_InitStructure; |
107 | GPIO_InitTypeDef GPIO_InitStructure; |
108 | 108 | ||
109 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); |
109 | SCU_APBPeriphClockConfig(__GPIO5, ENABLE); |
110 | // GPS off |
110 | // GPS off |
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_Disable; |
114 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
115 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
115 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
116 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
116 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
117 | 117 | ||
118 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
118 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
119 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
119 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; |
120 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
120 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
121 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
121 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
122 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
122 | GPIO_Init(GPIO6, &GPIO_InitStructure); |
123 | 123 | ||
124 | // map UART0 to Compass |
124 | // map UART0 to Compass |
125 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
125 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
126 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
126 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
127 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
127 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
128 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
128 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
129 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
129 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; |
130 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
130 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
131 | 131 | ||
132 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
132 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
133 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
133 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; |
134 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
134 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
135 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3 ; |
135 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3 ; |
136 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
136 | GPIO_Init(GPIO5, &GPIO_InitStructure); |
137 | } |
137 | } |
138 | 138 | ||
139 | 139 | ||
140 | // --------------------------- UART0 Init ------------------------------------ |
140 | // --------------------------- UART0 Init ------------------------------------ |
141 | void GPS_UART0_Init (void) |
141 | void GPS_UART0_Init (void) |
142 | { |
142 | { |
143 | UART_InitTypeDef UART_InitStructure; |
143 | UART_InitTypeDef UART_InitStructure; |
144 | 144 | ||
145 | SerialPutString("GPS init..."); |
145 | SerialPutString("GPS init..."); |
146 | 146 | ||
147 | SCU_APBPeriphClockConfig(__UART0, ENABLE); // Enable the UART1 Clock |
147 | SCU_APBPeriphClockConfig(__UART0, ENABLE); // Enable the UART1 Clock |
148 | 148 | ||
149 | Connect_UART0_to_GPS(); |
149 | Connect_UART0_to_GPS(); |
150 | 150 | ||
151 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
151 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
152 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
152 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
153 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
153 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
154 | UART_InitStructure.UART_BaudRate = BAUD_RATE; |
154 | UART_InitStructure.UART_BaudRate = BAUD_RATE; |
155 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
155 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
156 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
156 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
157 | //UART_InitStructure.UART_FIFO = UART_FIFO_Disable; |
157 | //UART_InitStructure.UART_FIFO = UART_FIFO_Disable; |
158 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
158 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
159 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
159 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
160 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
160 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
161 | 161 | ||
162 | UART_DeInit(UART0); |
162 | UART_DeInit(UART0); |
163 | UART_Init(UART0, &UART_InitStructure); |
163 | UART_Init(UART0, &UART_InitStructure); |
164 | 164 | ||
165 | VIC_Config(UART0_ITLine, VIC_IRQ, 10); |
165 | VIC_Config(UART0_ITLine, VIC_IRQ, 10); |
166 | VIC_ITCmd(UART0_ITLine, ENABLE); |
166 | VIC_ITCmd(UART0_ITLine, ENABLE); |
167 | 167 | ||
168 | UART_ITConfig(UART0, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
168 | UART_ITConfig(UART0, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
169 | UART_Cmd(UART0, ENABLE); |
169 | UART_Cmd(UART0, ENABLE); |
170 | 170 | ||
171 | GPS_Init(); |
171 | GPS_Init(); |
172 | 172 | ||
173 | SerialPutString("ok\n\r"); |
173 | SerialPutString("ok\n\r"); |
174 | } |
174 | } |
175 | 175 | ||
176 | // ----------------------------- GPS - Receive ------------------------------------ |
176 | // ----------------------------- GPS - Receive ------------------------------------ |
177 | void UART0_IRQHandler(void) |
177 | void UART0_IRQHandler(void) |
178 | { |
178 | { |
179 | u8 sioTmp = 0; |
179 | u8 sioTmp = 0; |
180 | static u8 uartState = 0, gps_buf_ptr = 0; |
180 | static u8 uartState = 0, gps_buf_ptr = 0; |
181 | 181 | ||
182 | 182 | ||
183 | GPIO_ToggleBit(GPIO5, GPIO_Pin_6); |
183 | GPIO_ToggleBit(GPIO5, GPIO_Pin_6); |
184 | if (DebugUART == UART0) |
184 | if (DebugUART == UART0) |
185 | { |
185 | { |
186 | while (UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET) |
186 | while (UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET) |
187 | UART_SendData(UART1, UART_ReceiveData(UART0)); |
187 | UART_SendData(UART1, UART_ReceiveData(UART0)); |
188 | 188 | ||
189 | UART_ClearITPendingBit(UART0, UART_IT_Receive); |
189 | UART_ClearITPendingBit(UART0, UART_IT_Receive); |
190 | UART_ClearITPendingBit(UART0, UART_IT_ReceiveTimeOut); |
190 | UART_ClearITPendingBit(UART0, UART_IT_ReceiveTimeOut); |
191 | 191 | ||
192 | } |
192 | } |
193 | else |
193 | else |
194 | if((UART_GetITStatus(UART0, UART_IT_Receive) != RESET)|| (UART_GetITStatus(UART0, UART_IT_ReceiveTimeOut) != RESET) ) |
194 | if((UART_GetITStatus(UART0, UART_IT_Receive) != RESET)|| (UART_GetITStatus(UART0, UART_IT_ReceiveTimeOut) != RESET) ) |
195 | { |
195 | { |
196 | UART_ClearITPendingBit(UART0, UART_IT_Receive); |
196 | UART_ClearITPendingBit(UART0, UART_IT_Receive); |
197 | UART_ClearITPendingBit(UART0, UART_IT_ReceiveTimeOut); |
197 | UART_ClearITPendingBit(UART0, UART_IT_ReceiveTimeOut); |
198 | 198 | ||
199 | while ((UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET) && NewGPSDataAvail == 0) |
199 | while ((UART_GetFlagStatus(UART0, UART_FLAG_RxFIFOEmpty) != SET) && NewGPSDataAvail == 0) |
200 | { |
200 | { |
201 | 201 | ||
202 | sioTmp = UART_ReceiveData(UART0); |
202 | sioTmp = UART_ReceiveData(UART0); |
203 | 203 | ||
204 | 204 | ||
205 | switch (uartState) |
205 | switch (uartState) |
206 | { |
206 | { |
207 | case 0: if(sioTmp == 0xB5) { GPS_RxBuffer[4]=0; uartState = 1; } // GPS-UBX Startzeichen |
207 | case 0: if(sioTmp == 0xB5) { GPS_RxBuffer[4]=0; uartState = 1; } // GPS-UBX Startzeichen |
208 | gps_buf_ptr = 0; |
208 | gps_buf_ptr = 0; |
209 | GPS_RxBuffer[gps_buf_ptr++] = sioTmp; |
209 | GPS_RxBuffer[gps_buf_ptr++] = sioTmp; |
210 | break; |
210 | break; |
211 | 211 | ||
212 | case 1: |
212 | case 1: |
213 | if(gps_buf_ptr == 1 && sioTmp != 0x62) { uartState = 0; break;}; // andere Meldung unterdrücken |
213 | if(gps_buf_ptr == 1 && sioTmp != 0x62) { uartState = 0; break;}; // andere Meldung unterdrücken |
214 | if(gps_buf_ptr == 2 && sioTmp != 0x01) { uartState = 0; break;}; // andere Meldung unterdrücken |
214 | if(gps_buf_ptr == 2 && sioTmp != 0x01) { uartState = 0; break;}; // andere Meldung unterdrücken |
215 | if(gps_buf_ptr == 3 && sioTmp != 0x02 && sioTmp != 0x06 && sioTmp != 0x12 && sioTmp != 0x08) { uartState = 0; break;}; // andere Meldung unterdrücken |
215 | if(gps_buf_ptr == 3 && sioTmp != 0x02 && sioTmp != 0x06 && sioTmp != 0x12 && sioTmp != 0x08) { uartState = 0; break;}; // andere Meldung unterdrücken |
216 | 216 | ||
217 | GPS_RxBuffer[gps_buf_ptr] = sioTmp; |
217 | GPS_RxBuffer[gps_buf_ptr] = sioTmp; |
218 | 218 | ||
219 | if(gps_buf_ptr < (GPS_RxBuffer[4]+6)) gps_buf_ptr++; |
219 | if(gps_buf_ptr < (GPS_RxBuffer[4]+6)) gps_buf_ptr++; |
220 | else |
220 | else |
221 | { |
221 | { |
222 | if(GPS_RxBuffer[3] == 0x06) // NAV SOL |
222 | if(GPS_RxBuffer[3] == 0x06) // NAV SOL |
223 | { |
223 | { |
224 | GPS_DataSol = (struct str_ubx_nav_sol *) GPS_RxBuffer; |
224 | GPS_DataSol = (struct str_ubx_nav_sol *) GPS_RxBuffer; |
225 | GPS_Data.Flags = GPS_DataSol->Flags; |
225 | GPS_Data.Flags = GPS_DataSol->Flags; |
226 | GPS_Data.Used_Sat = GPS_DataSol->Number_SV; |
226 | GPS_Data.Used_Sat = GPS_DataSol->Number_SV; |
227 | GPS_Data.GPS_week = GPS_DataSol->GPS_week; |
227 | GPS_Data.GPS_week = GPS_DataSol->GPS_week; |
228 | } |
228 | } |
229 | else if(GPS_RxBuffer[3] == 0x12) //NAV VELNED |
229 | else if(GPS_RxBuffer[3] == 0x12) //NAV VELNED |
230 | { |
230 | { |
231 | GPS_DataVelned = (struct str_ubx_nav_velned *) GPS_RxBuffer; |
231 | GPS_DataVelned = (struct str_ubx_nav_velned *) GPS_RxBuffer; |
232 | GPS_Data.N_Speed = GPS_DataVelned->N_Speed; |
232 | GPS_Data.N_Speed = GPS_DataVelned->N_Speed; |
233 | GPS_Data.E_Speed = GPS_DataVelned->E_Speed; |
233 | GPS_Data.E_Speed = GPS_DataVelned->E_Speed; |
234 | GPS_Data.DownSpeed = GPS_DataVelned->DownSpeed; |
234 | GPS_Data.DownSpeed = GPS_DataVelned->DownSpeed; |
235 | 235 | ||
236 | GPS_Data.SpeedAccuracy = GPS_DataVelned->SpeedAccuracy; |
236 | GPS_Data.SpeedAccuracy = GPS_DataVelned->SpeedAccuracy; |
237 | NewGPSDataAvail = 1; |
237 | NewGPSDataAvail = 1; |
238 | } |
238 | } |
239 | else if(GPS_RxBuffer[3] == 0x02) // NAV POSLLH |
239 | else if(GPS_RxBuffer[3] == 0x02) // NAV POSLLH |
240 | { |
240 | { |
241 | GPS_DataPosllh = (struct str_ubx_nav_posllh *) GPS_RxBuffer; |
241 | GPS_DataPosllh = (struct str_ubx_nav_posllh *) GPS_RxBuffer; |
242 | GPS_Data.Longitude = GPS_DataPosllh->Longitude; |
242 | GPS_Data.Longitude = GPS_DataPosllh->Longitude; |
243 | GPS_Data.Latitude = GPS_DataPosllh->Latitude; |
243 | GPS_Data.Latitude = GPS_DataPosllh->Latitude; |
244 | GPS_Data.Height = GPS_DataPosllh->Height; |
244 | GPS_Data.Height = GPS_DataPosllh->Height; |
245 | GPS_Data.HeightSL = GPS_DataPosllh->HeightSL; |
245 | GPS_Data.HeightSL = GPS_DataPosllh->HeightSL; |
246 | GPS_Data.GPS_time = GPS_DataPosllh->GPS_time; |
246 | GPS_Data.GPS_time = GPS_DataPosllh->GPS_time; |
247 | GPS_Data.HorizontalAccuracy = GPS_DataPosllh->HorizontalAccuracy; |
247 | GPS_Data.HorizontalAccuracy = GPS_DataPosllh->HorizontalAccuracy; |
248 | GPS_Data.VerticalAccuracy = GPS_DataPosllh->VerticalAccuracy; |
248 | GPS_Data.VerticalAccuracy = GPS_DataPosllh->VerticalAccuracy; |
249 | } |
249 | } |
250 | else if(GPS_RxBuffer[3] == 0x08) // NAV POSUTM |
250 | else if(GPS_RxBuffer[3] == 0x08) // NAV POSUTM |
251 | { |
251 | { |
252 | GPS_DataPosutm = (struct str_ubx_nav_posutm *) GPS_RxBuffer; |
252 | GPS_DataPosutm = (struct str_ubx_nav_posutm *) GPS_RxBuffer; |
253 | GPS_Data.North = GPS_DataPosutm->North; |
253 | GPS_Data.North = GPS_DataPosutm->North; |
254 | GPS_Data.East = GPS_DataPosutm->East; |
254 | GPS_Data.East = GPS_DataPosutm->East; |
255 | GPS_Data.Altitude = GPS_DataPosutm->Altitude; |
255 | GPS_Data.Altitude = GPS_DataPosutm->Altitude; |
256 | } |
256 | } |
257 | uartState = 0; |
257 | uartState = 0; |
258 | } |
258 | } |
259 | break; |
259 | break; |
260 | } |
260 | } |
261 | } |
261 | } |
262 | 262 | ||
263 | } |
263 | } |
264 | } |
264 | } |
265 | 265 |