Rev 153 | Rev 155 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 153 | Rev 154 | ||
---|---|---|---|
Line 96... | Line 96... | ||
96 | u8 UART1_ConfirmFrame = 0; |
96 | u8 UART1_ConfirmFrame = 0; |
Line 97... | Line 97... | ||
97 | 97 | ||
Line 98... | Line 98... | ||
98 | UART_TypeDef *DebugUART = UART1; |
98 | UART_TypeDef *DebugUART = UART1; |
99 | 99 | ||
100 | // the primary rx fifo |
100 | // the primary rx fifo |
101 | #define UART1_RX_FIFO_LEN 512 |
101 | #define UART1_RX_FIFO_LEN 1024 |
Line 102... | Line 102... | ||
102 | u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN]; |
102 | u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN]; |
103 | fifo_t UART1_rx_fifo; |
103 | fifo_t UART1_rx_fifo; |
Line 318... | Line 318... | ||
318 | } |
318 | } |
319 | } |
319 | } |
320 | else // DebugUART == UART1 (normal operation) |
320 | else // DebugUART == UART1 (normal operation) |
321 | { |
321 | { |
322 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
322 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
323 | { // some byes in the fifo and rxd buffer not locked |
323 | { // some byes in the hardware fifo |
324 | // get byte from hardware fifo |
324 | // get byte from hardware fifo |
325 | c = UART_ReceiveData(UART1); |
325 | c = UART_ReceiveData(UART1); |
326 | // put into the software fifo |
326 | // put into the software fifo |
327 | if(!fifo_put(&UART1_rx_fifo, c)) |
327 | if(!fifo_put(&UART1_rx_fifo, c)) |
328 | { // fifo overflow |
328 | { // fifo overflow |
329 | fifo_purge(&UART1_rx_fifo); // flush the whole buffer |
329 | fifo_purge(&UART1_rx_fifo); // flush the whole buffer |
330 | } |
330 | } |
331 | } // some byes in the fifo and rxd buffer not locked |
331 | } // EOF while some byes in the hardware fifo |
- | 332 | // if rx buffer is not locked |
|
- | 333 | if(UART1_rx_buffer.Locked == FALSE) |
|
- | 334 | { //collect data from primary rx fifo |
|
- | 335 | while(fifo_get(&UART1_rx_fifo, &c)) |
|
- | 336 | { // break if complete frame is collected |
|
- | 337 | if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break; |
|
- | 338 | } |
|
- | 339 | } |
|
332 | } // eof DebugUart = UART1 |
340 | } // eof DebugUart = UART1 |
333 | } |
341 | } |
334 | } |
342 | } |
Line 335... | Line 343... | ||
335 | 343 | ||
336 | /**************************************************************/ |
344 | /**************************************************************/ |
337 | /* Process incomming data from debug uart */ |
345 | /* Process incomming data from debug uart */ |
338 | /**************************************************************/ |
346 | /**************************************************************/ |
339 | void UART1_ProcessRxData(void) |
347 | void UART1_ProcessRxData(void) |
340 | { |
- | |
341 | u8 c; |
- | |
342 | 348 | { |
|
343 | // return on forwarding uart |
- | |
344 | if(DebugUART != UART1) return; |
- | |
345 | - | ||
346 | // collect data from primary rx fifo |
- | |
347 | while(fifo_get(&UART1_rx_fifo, &c)) |
- | |
348 | { // break if complete frame is collected |
- | |
349 | if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break; |
- | |
350 | } |
- | |
351 | // if data in the rxd buffer are not locked immediately return |
349 | // return on forwarding uart or unlocked rx buffer |
Line 352... | Line 350... | ||
352 | if(UART1_rx_buffer.Locked == FALSE) return; |
350 | if((DebugUART != UART1) || (UART1_rx_buffer.Locked == FALSE)) return; |
353 | 351 | ||
Line 354... | Line 352... | ||
354 | Waypoint_t * pWaypoint = NULL; |
352 | Waypoint_t * pWaypoint = NULL; |
Line 558... | Line 556... | ||
558 | { |
556 | { |
559 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request |
557 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request |
560 | Echo = 0; // reset echo value |
558 | Echo = 0; // reset echo value |
561 | UART1_Request_Echo = FALSE; |
559 | UART1_Request_Echo = FALSE; |
562 | } |
560 | } |
- | 561 | else if(UART1_Request_NewWaypoint && (UART1_tx_buffer.Locked == FALSE)) |
|
- | 562 | { |
|
- | 563 | u8 WPNumber = WPList_GetCount(); |
|
- | 564 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
|
- | 565 | UART1_Request_NewWaypoint = FALSE; |
|
- | 566 | } |
|
- | 567 | else if((UART1_Request_ReadWaypoint != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
|
- | 568 | { |
|
- | 569 | u8 WPNumber = WPList_GetCount(); |
|
- | 570 | if (UART1_Request_ReadWaypoint < WPNumber) |
|
- | 571 | { |
|
- | 572 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &WPNumber, 1, &UART1_Request_ReadWaypoint, 1, WPList_GetAt(UART1_Request_ReadWaypoint), sizeof(Waypoint_t)); |
|
- | 573 | } |
|
- | 574 | else |
|
- | 575 | { |
|
- | 576 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
|
- | 577 | } |
|
- | 578 | UART1_Request_ReadWaypoint = 0xFF; |
|
- | 579 | } |
|
- | 580 | else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
|
- | 581 | { |
|
- | 582 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16); |
|
- | 583 | UART1_Request_DebugLabel = 0xFF; |
|
- | 584 | } |
|
563 | else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE)) |
585 | else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE)) |
564 | { |
586 | { |
565 | NaviData.Errorcode = ErrorCode; |
587 | NaviData.Errorcode = ErrorCode; |
566 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
588 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
567 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval); |
589 | UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval); |
Line 577... | Line 599... | ||
577 | { |
599 | { |
578 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
600 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
579 | UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval); |
601 | UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval); |
580 | UART1_Request_Data3D = FALSE; |
602 | UART1_Request_Data3D = FALSE; |
581 | } |
603 | } |
582 | else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
- | |
583 | { |
- | |
584 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16); |
- | |
585 | UART1_Request_DebugLabel = 0xFF; |
- | |
586 | } |
- | |
587 | else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
604 | else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE)) |
588 | { |
605 | { |
589 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame)); |
606 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame)); |
590 | UART1_ConfirmFrame = 0; |
607 | UART1_ConfirmFrame = 0; |
591 | } |
608 | } |
Line 631... | Line 648... | ||
631 | FollowMe.reserve[2] = 0; // reserve |
648 | FollowMe.reserve[2] = 0; // reserve |
632 | FollowMe.reserve[3] = 0; // reserve |
649 | FollowMe.reserve[3] = 0; // reserve |
633 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
650 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
634 | UART1_Request_SendFollowMe = FALSE; |
651 | UART1_Request_SendFollowMe = FALSE; |
635 | } |
652 | } |
636 | else if(UART1_Request_NewWaypoint && (UART1_tx_buffer.Locked == FALSE)) |
- | |
637 | { |
- | |
638 | u8 WPNumber = WPList_GetCount(); |
- | |
639 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
- | |
640 | UART1_Request_NewWaypoint = FALSE; |
- | |
641 | } |
- | |
642 | else if((UART1_Request_ReadWaypoint != 0xFF) && (UART1_tx_buffer.Locked == FALSE)) |
- | |
643 | { |
- | |
644 | u8 WPNumber = WPList_GetCount(); |
- | |
645 | if (UART1_Request_ReadWaypoint < WPNumber) |
- | |
646 | { |
- | |
647 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &WPNumber, 1, &UART1_Request_ReadWaypoint, 1, WPList_GetAt(UART1_Request_ReadWaypoint), sizeof(Waypoint_t)); |
- | |
648 | } |
- | |
649 | else |
- | |
650 | { |
- | |
651 | MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
- | |
652 | } |
- | |
653 | UART1_Request_ReadWaypoint = 0xFF; |
- | |
654 | } |
- | |
655 | UART1_Transmit(); // output pending bytes in tx buffer |
653 | UART1_Transmit(); // output pending bytes in tx buffer |
656 | } |
654 | } |