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

📄 test_d12.c

📁 该原码包含有wince 和 linux 的移植和应用原码
💻 C
字号:
#include "def.h"
#include "44b.h"
#include "utils.h"
#include "D12Def.h"


//extern char Uart_GetKey(void) ;

void D12SetEpStat(U8 Ep,U8 Stat)
{
	D12WrCmd(Ep+0x40);
	D12WrDat(Stat);
}

void D12SetAddr(U8 Addr)
{
	D12WrCmd(0xd0);
	D12WrDat(Addr);
}

void D12SetEp(U8 Val)
{
	D12WrCmd(0xd8);
	D12WrDat(Val);
}

void D12SetDma(U8 Dma)
{
	D12WrCmd(0xfb);
	D12WrDat(Dma);
}

void D12SetMode(U8 Val1, U8 Val2)
{
	D12WrCmd(0xf3);
	D12WrDat(Val1);
	D12WrDat(Val2);
}

void D12SendResume()
{
	D12WrCmd(0xf6);
}

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

U32 D12RdChipId()
{
	U32 tmp;
	
	D12WrCmd(0xfd);
	tmp = D12RdDat();
	tmp = tmp<<8|D12RdDat();		

	Uart_Printf( "Read chip id = 0x%x\n", tmp ) ;

	return tmp;	
}

U8 D12GetDma()
{
	D12WrCmd(0xfb);
	return D12RdCmd();
}

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

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

U8 D12RdInt()
{
	D12WrCmd(0xf4);
	return D12RdCmd();
}

void TestD12(void)
{
	U32 rPLLCON_save;
	U8 i;
	
	rPLLCON_save = rPLLCON;
	//rPLLCON = (40<<12)|(3<<4)|1;	//set CPU clock=48m

	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( 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");
	}
	
	rPLLCON = rPLLCON_save;
}

static char title[] = "USB Deivce实验";
static char tip[]   = "实验USB设备端芯片,启动后在PC上运行LEDDEMO程序可控制板上的LED,按ESC键返回";

//TestD12Item在prog_entry.c里被引用
TEST_PROGRAM_ITEM TestD12Item = {
				(TEST_PROGRAM)TestD12, 	//入口地址
				title, 					//显示名称
				tip, 					//帮助或提示信息,可为NULL
				1};						//使用printf,puts,putch等函数时在LCD上也显示输出字符(串)

⌨️ 快捷键说明

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