SEEDDM642_UART_Handle SEEDDM642_UART_open(Int16 devid,
Int16 baudrate,
SEEDDM642_UART_Config *config)
{
SEEDDM642_UART_Handle hUart;
Int16 dl;
/* Assign handle */
hUart = devid;
/* Set registers based on config structure */
/*设置MCR*/
SEEDDM642_UART_rset(hUart, SEEDDM642_UART_MCR,config -> regs[3]);
/*将EFR寄存器的第4位关闭*///静止TL16C752B增强功能
SEEDDM642_UART_rset(hUart, SEEDDM642_UART_EFR, dl);
/*设置串口的MCR*/
SEEDDM642_UART_rset(hUart, SEEDDM642_UART_MCR, config -> regs[3]);
/*设置串口的IER*/// 0X9008 0001 处置0
SEEDDM642_UART_rset(hUart, SEEDDM642_UART_IER, config -> regs[0]);
/*设置串口的FCR*/
SEEDDM642_UART_rset(hUart, SEEDDM642_UART_FCR, config -> regs[1]);
/*设置串口的LCR*/
SEEDDM642_UART_rset(hUart, SEEDDM642_UART_LCR, config -> regs[2]);
/* Set up baud divisor clock,设置波待率 */
dl = SEEDDM642_UART_rget(hUart, SEEDDM642_UART_MCR);
if((dl & 0x80)==0x80)
{
baudrate = (baudrate/4);
}
SEEDDM642_UART_rset(hUart, SEEDDM642_UART_DLL, baudrate & 0xff);
dl = SEEDDM642_UART_rget(hUart, SEEDDM642_UART_DLL);
SEEDDM642_UART_rset(hUart, SEEDDM642_UART_DLH, (baudrate >> 8) & 0xff);
dl = SEEDDM642_UART_rget(hUart, SEEDDM642_UART_DLH);
/* Clear any outstanding receive characters,清空接收寄存器 */
SEEDDM642_UART_rget(hUart, SEEDDM642_UART_RBR);
returnhUart;
}