📄 davincievm_uart.c
字号:
/*
* Copyright 2005 by Spectrum Digital Incorporated.
* All rights reserved. Property of Spectrum Digital Incorporated.
*
* Not for distribution.
*/
/*
* UART implementation
*
*/
#include "davincievm_uart.h"
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_UART_open( id, baudrate ) *
* *
* ------------------------------------------------------------------------ */
UART_Handle DAVINCIEVM_UART_open( Uint16 id, Uint32 baudrate )
{
#ifdef ARM_SIDE
CSL_Status status;
CSL_UartHwSetup uart_hwsetup;
uart_hwsetup.flowControl = CSL_UART_AUTOFLOW_DISABLE;
uart_hwsetup.fifoEnable = CSL_UART_FIFO_ENABLE;
uart_hwsetup.loopEnable = CSL_UART_LOOP_DISABLE;
uart_hwsetup.emuConfig = CSL_UART_EMU_RUN;
uart_hwsetup.interruptEnable = CSL_UART_INTR_ENALL;
uart_hwsetup.setupBaud.moduleClock = 27000000;
uart_hwsetup.setupBaud.baudrate = baudrate;
uart_hwsetup.setupLine.charLen = CSL_UART_CHARLEN_8;
uart_hwsetup.setupLine.numStopBits = CSL_UART_NUMSTOP_1;
uart_hwsetup.setupLine.parityCtrl = 0;
uart_hwsetup.setupFifo.trigLevel = CSL_UART_RXTRIGLEVEL_1;
uart_hwsetup.setupFifo.dmaMode = CSL_UART_DMA_DISABLE;
uart_hwsetup.extendSetup = 0;
CSL_uartInit( 0 );
uart_handle = CSL_uartOpen( &uart_obj, id, 0, &status );
status |= CSL_uartHwControl( uart_handle, CSL_UART_CMD_RESET, 0 );
status |= CSL_uartHwControl( uart_handle, CSL_UART_CMD_ENABLE, 0 );
status |= CSL_uartHwSetup( uart_handle, &uart_hwsetup );
if ( status != CSL_SOK )
return ( UART_Handle )-1;
else
return uart_handle;
#elif DSP_SIDE
Uint16 divisor = 27000000 / baudrate; // = UART clk / ( baudrate * 16 )
// = 27000000 / ( 19200 * 16 )
// = 88
// = 27000000 / ( 115200 * 16 )
// = 14
UART0_PWREMU_MGMT = 0x0000; // Reset UART TX & RX components
DAVINCIEVM_wait( 100 );
UART0_DLL = ( divisor & 0xff ); // Set baud rate
UART0_DLH = ( ( divisor >> 8 ) & 0xff );
UART0_FCR = 0x0007; // Clear UART TX & RX FIFOs
UART0_FCR = 0x0001; // Enable TX & RX FIFOs 1-byte length
UART0_IER = 0x0007; // Enable interrupts
UART0_LCR = 0x0003; // 8-bit words, 1 STOP bit generated, No Parity, No Stick paritiy, No Break control
UART0_MCR = 0x0000; // RTS & CTS disabled, Loopback mode disabled, autoflow disabled
UART0_PWREMU_MGMT = 0x6001; // Emulation Free, Enable TX & RX componenets
if ( ( UART0_IIR & 0xC0 ) == 0xC0 ) // CHeck for enabled FIFOs and FIFOEN bit
return id;
else
return ( UART_Handle )-1;
#endif
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_UART_close( uart_handle ) *
* *
* ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_UART_close( UART_Handle uart_handle )
{
#ifdef ARM_SIDE
CSL_uartClose( uart_handle );
return 0;
#elif DSP_SIDE
return 0;
#endif
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_UART_xmtReady( uart_handle ) *
* *
* ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_UART_xmtReady( UART_Handle uart_handle )
{
Uint8 iir_status = ( UART0_IIR >> 1 ) & 0x0E;
if ( iir_status == 0 ) // Check for No Interrupts
return 0;
else if ( iir_status == 1 ) // Check for Current TX emptying
return 1;
else // Everything else
return 2;
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_UART_putChar( uart_handle, data ) *
* *
* ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_UART_putChar( UART_Handle uart_handle, Uint8 data )
{
#ifdef ARM_SIDE
CSL_uartHwControl( uart_handle, CSL_UART_CMD_WRITEBYTE, &data );
return 0;
#elif DSP_SIDE
UART0_THR = data;
return 0;
#endif
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_UART_rcvReady( uart_handle ) *
* *
* ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_UART_rcvReady( UART_Handle uart_handle )
{
Uint8 iir_status = ( UART0_IIR >> 1 ) & 0x0E;
if ( iir_status == 2 ) // Check for Data Ready
return 0;
else if ( iir_status == 0 ) // Check for No Interrupts
return 1;
else // Everything else
return 2;
}
/* ------------------------------------------------------------------------ *
* *
* DAVINCIEVM_UART_getChar( uart_handle, data ) *
* *
* ------------------------------------------------------------------------ */
Int16 DAVINCIEVM_UART_getChar( UART_Handle uart_handle, Uint8* data )
{
#ifdef ARM_SIDE
CSL_uartHwControl( ( CSL_UartHandle )uart_handle, CSL_UART_CMD_READBYTE, data );
return 0;
#elif DSP_SIDE
*data = UART0_THR;
return 0;
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -