Rev 196 | Rev 247 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 196 | Rev 245 | ||
---|---|---|---|
Line 76... | Line 76... | ||
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; |
Line 79... | Line 79... | ||
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]; |
Line 83... | Line 83... | ||
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 |
Line 87... | Line 87... | ||
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; |
Line 95... | Line 95... | ||
95 | 95 | ||
96 | //------------------------------------------------------------------------------------ |
96 | //------------------------------------------------------------------------------------ |
Line 97... | Line 97... | ||
97 | // functions |
97 | // functions |
- | 98 | ||
- | 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 | } |
|
98 | 139 | ||
99 | /********************************************************/ |
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) |
Line 103... | Line 144... | ||
103 | { |
144 | { |
Line 138... | Line 179... | ||
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); |
|
Line 143... | Line 186... | ||
143 | 186 | ||
144 | UART0_Muxer = UART0_MKGPS; |
187 | UART0_Muxer = UART0_MKGPS; |
Line 145... | Line 188... | ||
145 | } |
188 | } |
146 | 189 | ||
147 | /********************************************************/ |
190 | /********************************************************/ |
148 | /* Connect RXD & TXD to MK3MAG */ |
191 | /* Connect RXD & TXD to MK3MAG */ |
149 | /********************************************************/ |
192 | /********************************************************/ |
- | 193 | void UART0_Connect_to_MK3MAG(void) |
|
- | 194 | { |
|
150 | void UART0_Connect_to_MK3MAG(void) |
195 | u16 Baudrate; |
Line 151... | Line 196... | ||
151 | { |
196 | |
Line 152... | Line 197... | ||
152 | GPIO_InitTypeDef GPIO_InitStructure; |
197 | GPIO_InitTypeDef GPIO_InitStructure; |
Line 187... | Line 232... | ||
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 | } |
Line 195... | Line 241... | ||
195 | 241 | ||
196 | /********************************************************/ |
242 | /********************************************************/ |
197 | /* Initialize UART0 */ |
243 | /* Initialize UART0 */ |
198 | /********************************************************/ |
244 | /********************************************************/ |
199 | void UART0_Init(void) |
245 | void UART0_Init(void) |
200 | { |
- | |
201 | UART_InitTypeDef UART_InitStructure; |
- | |
202 | 246 | { |
|
Line 203... | Line -... | ||
203 | 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 |
247 | UART1_PutString("\r\n UART0 init..."); |
Line 238... | Line 248... | ||
238 | VIC_ITCmd(UART0_ITLine, ENABLE); |
248 | |
239 | UART0_Connect_to_MKGPS(); |
249 | UART0_Connect_to_MKGPS(UART0_BAUD_RATE); |
Line 240... | Line 250... | ||
240 | 250 | ||
Line 277... | Line 287... | ||
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; |
Line 416... | Line 426... | ||
416 | 426 | ||
417 | MKOSD_VersionInfo.SWMajor = 0xFF; |
427 | MKOSD_VersionInfo.SWMajor = 0xFF; |
418 | MKOSD_VersionInfo.SWMinor = 0xFF; |
428 | MKOSD_VersionInfo.SWMinor = 0xFF; |
Line 419... | Line 429... | ||
419 | MKOSD_VersionInfo.SWPatch = 0xFF; |
429 | MKOSD_VersionInfo.SWPatch = 0xFF; |
420 | 430 | ||
Line 421... | Line 431... | ||
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; |
Line 436... | Line 446... | ||
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 | } |