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

📄 pdiusbd12.c

📁 LPC2294 测试程序 YL_LPC229X_Test_Data的目录说明
💻 C
字号:
#include "def.h"
#include "config.h"
#include "board.h"
#include "utils.h"
#include "D12Def.h" 

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();		

	//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();
}

U8 D12_Check( void )
{
	USB_D12_ACTIVE ;

	if ( D12RdChipId() == 0x1210 )
	{
		printf( "PDIUSBD12 Found, Chip ID = 0x1210\n" ) ;
		return TRUE ;
	}

	return FALSE ;
}

/****************************************************************************
【功能说明】SRAM测试
****************************************************************************/
//int PDIUSBD12_Test( int argc , char* argv[] )
void PDIUSBD12_Test(void)
{
	U8 i;

	printf( "\nPDIUSBD12 TEST \n" ) ;

	if ( D12_Check() == TRUE )
	{
		printf( "Please connect USB Line from PC to the Board \n" ) ;
		printf( "Run LEDDEMO.EXE in the PC and Test \n" ) ;
		printf( "Press 'ESC' key to exit the test \n" ) ;

		if ( UsbInit() == 1 )		//STAUS_ERR
		{
			printf( "USB Device Initial is Error! \n" ) ;
	//		return FALSE ;
		}

		while ( getkey() != ESC_KEY )
		{
			i = UsbQueryInt();
			//if( i )    printf( "%x\n", i ) ;
			UsbIntProc( i );
		}

		D12SetMode( MyD12EpCfgOff , D12Pll24M );	//pull-up off
	//	return TRUE ;
	}
	else
	{
		printf( "No PDIUSBD12 Found\n" );
	//	return FALSE ;
	}
}

⌨️ 快捷键说明

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