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