/*
 *  Copyright 2008 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 */

/*
 *  UART Test
 *
 */

#include "C6747_uart.h"
#define send485enable GPIO_SET_DATA45|=0x00000002                //0x00000008
#define resive485enable GPIO_CLR_DATA45|=0x00000002                //0x00000008
Uint8 char8[20]={"Please enter char:"};
Uint8 uart_rx1=0;
Uint8 uart_tx1;
/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  uart_test( )                                                            *
 *      Simple UART loopback test.                                          *
 *      Will write then read back the byte sent to the RS232 connector.     *
 *                                                                          *
 * ------------------------------------------------------------------------ */

Int16 Wuart_test(Int16 NUM)
{

      Uint16 i;
    UART_Handle uart2;

    /* Open Uart Handle */
    uart2 = C6747_UART_open( NUM, 9600 );
    send485enable;
    for(i=0;i<19;i++)
	{ while( C6747_UART_xmtReady( uart2 ) );  //µÈ´ý·¢ËÍÍê±Ï
     C6747_UART_putChar(uart2,char8[i]);}

    /* UART Test */
   while(1)
    {
        /* uart_tx */
       resive485enable;
       while( C6747_UART_rcvReady( uart2 ) );  // Wait for uart_rx ready
      

        C6747_UART_getChar( uart2, &uart_rx1 ); 
                     
        uart_tx1=uart_rx1;

		send485enable; 
		while( C6747_UART_xmtReady( uart2 ) );  // Wait for uart_tx ready
	    C6747_UART_putChar( uart2, uart_tx1 );    // Write 1 byte  		 
        for(i=0;i<20000;i++);

    }  

  
}
