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

📄 d12op.c

📁 三星 44B0 USB device实验
💻 C
字号:
#include "def.h"
#include "D12Def.h"

extern char Uart_GetKey(void) ;
extern void Uart_Printf(char *fmt,...);

void D12SetEpStat(U8 Ep,U8 Stat)
{
	D12Cmd = Ep+0x40;	
	D12Dat = Stat;
}

void D12SetAddr(U8 Addr)
{
	D12Cmd = 0xd0;
	D12Dat = Addr;
}

void D12SetEp(U8 Val)
{
	D12Cmd = 0xd8;
	D12Dat = Val;
}

void D12SetDma(U8 Dma)
{
	D12Cmd = 0xfb;
	D12Dat = Dma;
}

void D12SetMode(U8 Val1, U8 Val2)
{
	D12Cmd = 0xf3;
	D12Dat = Val1;
	D12Dat = Val2;
}

void D12SendResume()
{
	D12Cmd = 0xf6;
}

void D12AckEp(U8 Ep)
{
	D12Cmd = Ep;
	D12Cmd = 0xf1;
	if(!Ep)
		D12Cmd = 0xf2;		
}

U32 D12RdChipId()
{
	U32 tmp;
	
	D12Cmd = 0xfd;
	tmp = D12Dat;
	tmp = tmp<<8|D12Dat;		
	return tmp;	
}

U8 D12GetDma()
{
	D12Cmd = 0xfb;
	return D12Cmd;
}

U8 D12RdEp(U8 Ep,U8 buf[],U8 cnt)
{
	U8 tmp;
	
	D12SelEp(Ep);
	if(D12Cmd&1)
	{
		D12Cmd = 0xf0;
		tmp = D12Cmd;
		tmp = D12Cmd;
		if(tmp<cnt)
			cnt = tmp;
		tmp = cnt;
		while(cnt)
		{
			*buf++ = D12Cmd;
			cnt--;
		}
		D12Cmd = 0xf2;
		return tmp;	
	}
	else
		return 0;		
}

void D12WrEp(U8 Ep, U8 buf[], U8 cnt)
{
	while(1)
	{
		D12SelEp(Ep);
		if(!(D12Cmd&1))
			break;
	}
	D12Cmd = 0xf0;
	D12Dat = 0;
	D12Dat = cnt;
	while(cnt)
	{
		D12Dat = *buf++;
		cnt--;
	}
	D12Cmd = 0xfa;
}

U8 D12RdInt()
{
	D12Cmd = 0xf4;
	return D12Cmd;
}

void D12Main(void)
{
	U8 i;

	Uart_Printf( "\nPDIUSBD12 TEST \n" ) ;
	
	if(UsbRdChipId()==0x1210)
	{	
		Uart_Printf("Pdiusbd12 Found, chip id = 0x1210\n");
		Uart_Printf( "Please connect USB Line from PC to the Board \n" ) ;
		Uart_Printf( "run LEDDEMO.EXE in the PC and Test \n" ) ;
		
		if( UsbInit() == 1 )		//STAUS_ERR
		{	
			Uart_Printf( "USB Device Initial is Error! \n" ) ;
			return ;
		}
		
		while( Uart_GetKey()!=ESC_KEY )
		{
			i = UsbQueryInt();                      
			//if(i)    Uart_Printf("%x\n", i);
			UsbIntProc(i);	
		}
		
		D12SetMode(MyD12EpCfgOff, D12Pll24M);	//pull-up off
	}
	else
	{
		Uart_Printf("No Pdiusbd12 Found\n");
	}
}

⌨️ 快捷键说明

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