⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_otg_dev.c

📁 三星 S3C2460 USB OTG监控代码
💻 C
字号:

/*******************************************************************************
* File Name    : usb_otg_dev.c
* Description  : S3C2460A USB OTG Interface Function Test Code
* Author       : Haksoo Kim
* Dept         : Mobile solution, AP
* Created Date : 2005.06.02
* Version      : 1.0
* History
*   R1.0 (2005.06.02): First Release
********************************************************************************/

#include <stdlib.h>
#include <string.h>
#include "option.h"

#include "2460addr.h"
#include "2460lib.h"
#include "2460slib.h"

#include "def.h"
#include "usb_otg.h"
#include "otg_xvr_isp1301.h"

#include "PLL.h"

uint8 save_rGPKCON, save_rGPKDAT, save_rGPKUP;


volatile short USB_OTG_INT_Exit =0;


//	Functional Sub-Routines
void USBOTG_Port_Init(void)
{
	//Push PCM GPIO port configuration
	save_rGPKDAT=rGPKDAT;
	save_rGPKCON=rGPKCON; 
	save_rGPKUP=rGPKPU;
	
	//----------------------------------------------------------------------------------------
	//PORT K GROUP (USB OTG)
	//Ports  :  GPK7            GPK6          GPK5          GPK4    	    GPK3           GPK2           GPK1           GPK0 
	//Signal : TXDNI           TXDNO       TXDPI         TXDPO       INT              RCV            TXSE0          TXEN               
	//Binary :  10,               10,              10,              10,           10,               10,               10,              10    
	//----------------------------------------------------------------------------------------
	
	rGPKCON = rGPKCON & ~(0xffff) | 0xaaaa;   //GPK[15:0] => USB OTG
	rGPKPU  = rGPKPU  & ~(0xff)  | 0xff;    //The pull up function is disabled GPK[15:0] 
}

void USBOTG_Port_Return(void)
{
	//Pop PCM GPIO port configuration
	rGPKCON=save_rGPKCON; 
	rGPKDAT=save_rGPKDAT;
	rGPKPU=save_rGPKUP;
}

void GPK_Set(void)
{
	//Push PCM GPIO port configuration
	save_rGPKDAT=rGPKDAT;
	save_rGPKCON=rGPKCON; 
	save_rGPKUP=rGPKPU;
	
	//----------------------------------------------------------------------------------------
	//PORT K GROUP (USB OTG)
	//Ports  :  GPK7            GPK6          GPK5          GPK4    	    GPK3           GPK2           GPK1           GPK0 
	//Signal : TXDNI           TXDNO       TXDPI         TXDPO       INT              RCV            TXSE0          TXEN               
	//Binary :  10,               01,              10,              01,           10,               10,               10,              01    
	//----------------------------------------------------------------------------------------
	
	rGPKCON = rGPKCON & ~(0xffff) | 0x99a9;   
	rGPKPU  = rGPKPU  & ~(0xff)  | 0xff;    
	rGPKDAT = 0x1;
}

void USB_OTG_Device_Init(void)
{

	DEV_CONFIG = 0x0000012b; 	//device mode, csr done, self powered, full speed
	DEV_INT_EN = 0x000003ff;		
	GL_EP_INT_EN = 0xffffffff;
	THR_REG = 0x00100008;
	OutEP_RX_FIFO_SIZE = 0x00000020;
	IN_EP0_FIFO_SIZE = 0x00000020;
	Out_EP0_CON = 0x00000008;
	OTG_MAC_EP0 = 0x02000000;	
	DEV_CONFIG |= (1<<6);
       

	printf("\nDEV_CONFIG: 		0x%8x",DEV_CONFIG);
	printf("\nDEV_INT_EN: 		0x%8x",DEV_INT_EN);
	printf("\nGL_EP_INT_EN: 		0x%8x",GL_EP_INT_EN);
	printf("\nTHR_REG: 		0x%8x",THR_REG);
	printf("\nOutEP_RX_FIFO_SIZE: 	0x%8x",OutEP_RX_FIFO_SIZE);
	printf("\nIN_EP0_FIFO_SIZE: 	0x%8x",IN_EP0_FIFO_SIZE);
	printf("\nOut_EP0_CON: 		0x%8x",Out_EP0_CON);
	printf("\nOTG_MAC_EP0: 		0x%8x",OTG_MAC_EP0);
       
}

void USBOTG_Clock_Init(void)
{
	//khs:removed, rCLKSRCCON	|=	(1<<5); //Select UPLL clock source as External clock source
	//khs:added, 
	rCLKSRCCON	|=	(1<<12);	// Get USB clk source from MPLL
	
	rCLKDIVCON	=	rCLKDIVCON | (1<<12);	// USB 48 Div on
	//khs:removed, SetUPLL( U_MDIV, U_PDIV, U_SDIV);
}
/*
void ISP1301_IIC_Write(uint32 slvAddr,uint32 addr,uint8 data)
{ 
	uint32 temp;

	apOTG_TLI_DEV_G->i2cReg = 1<<31|0<<30 |0<<29|1<<28|slvAddr <<16|addr<<8 |data<<0; 
	//apOTG_TLI_DEV_G->i2cReg &= ~(1<<31);	
	apOTG_TLI_DEV_G->devIntr |= OTG_DEV_I2C_INTR;
	
	temp = apOTG_TLI_DEV_G->i2cReg;

}
*/
/*
uint8 ISP1301_IIC_Read(uint8 slvAddr, uint8 regAddr)
{
	uint8 Read_Data;
	uint32 DEV_INT_Value=0;

	apOTG_TLI_DEV_G->devIntr |= OTG_DEV_I2C_INTR;
	rINTMSK |= (BIT_USB);  
    rINTSUBMSK |= (BIT_SUB_OTG); 		
	
	apOTG_TLI_DEV_G->devIntrMask |= OTG_DEV_I2C_INTR; 
	
	apOTG_TLI_DEV_G->i2cReg = 1<<31|1<<30 |1<<28|slvAddr <<16|regAddr<<8; 

	Delay(100);
	
	while((DEV_INT_Value & OTG_DEV_I2C_INTR) != OTG_DEV_I2C_INTR)
	{
		DEV_INT_Value = apOTG_TLI_DEV_G->devIntr;
	}	

	Read_Data = (uint8)apOTG_TLI_DEV_G->i2cReg;

	apOTG_TLI_DEV_G->devIntr |= OTG_DEV_I2C_INTR;
	apOTG_TLI_DEV_G->i2cReg &= ~(1<<31);

	apOTG_TLI_DEV_G->devIntrMask &= ~OTG_DEV_I2C_INTR; 
	
	rINTMSK&=~(BIT_USB);  
    rINTSUBMSK&=~(BIT_SUB_OTG); 
	
    return  Read_Data;
}
*/


void ISP1301_IIC_Write(uint32 slvAddr,uint32 addr,uint8 data)
{ 

	apOTG_TLI_DEV_G->i2cReg = 1<<31|0<<30 |0<<29|1<<28|slvAddr <<16|addr<<8 |data<<0; 

	Delay(100);
	
	while((apOTG_TLI_DEV_G->i2cReg & (1<<31)) == (1<<31));

}

uint8 ISP1301_IIC_Read(uint8 slvAddr, uint8 regAddr)
{
	uint8 Read_Data;

		
	apOTG_TLI_DEV_G->i2cReg = 1<<31|1<<30 |1<<28|slvAddr <<16|regAddr<<8; 

	Delay(100);
	
	while((apOTG_TLI_DEV_G->i2cReg & (1<<31)) == (1<<31));

	Read_Data = (uint8)apOTG_TLI_DEV_G->i2cReg;

    return  Read_Data;
}

void ISP1301_Init_DeviceMode(void)
{

	/*
	// set the direction of DAT/VP and SE0/VM
	ISP1301_IIC_Write(OTG_XVR_ISP1301_ADDR,ISP1301_MODE_CTRL2_CLR,0xff);
	*/
	
	// enable ID_FLOAT/SESS_VLD/VBUS_VLD low/high interrupt
	ISP1301_IIC_Write(OTG_XVR_ISP1301_ADDR,ISP1301_INT_EN_LOW_SET,0x2B);
	ISP1301_IIC_Write(OTG_XVR_ISP1301_ADDR,ISP1301_INT_EN_HIGH_SET,0x2B);
	ISP1301_IIC_Write(OTG_XVR_ISP1301_ADDR,ISP1301_INT_LATCH_SET,0x2B);
	
	// enable pull-up register
	//ISP1301_IIC_Write(OTG_XVR_ISP1301_ADDR,ISP1301_OTG_CTRL_SET,0x01);
}

void ISP1301_IIC_FullRead(void)
{
	int key,i;
	
	printf("\n****************************************************************\n");
	printf("If you want to read OTG transceiver registers, press 'y/Y' key\n");
	printf("  otherwise press any key\n");
	
	key=getchar();
	printf("\n");
	if((key=='y')||(key=='Y')){
		printf("==============================\n");
		printf("Reg. Addr.	Reg. Data\n");
		printf("------------------------------\n");	

		for(i=0x0; i<0x16; i++)
			printf("0x%02x		0x%02x \n", i, ISP1301_IIC_Read(0x2c, i));
	}
	printf("****************************************************************\n");
	
	return;
}

///////////////////////////////////////////////////////////////////////////////////////// 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -