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

📄 speed365.c

📁 南京沁恒电子有限公司USB通用设备接口芯片资料
💻 C
字号:
/*  该程序用于测试CH365的读写速度
  CH365的I/O和MEM读写速度是完全相同的,计算机程序是以字节,字(16位),双字(32位)为单位读写,而实际上CH365总是将其转换为字节读写,
  所以速度由以下几个因素决定:
    CH365读写脉冲的宽度,可以是30nS到240nS,由CH365读写速度控制寄存器位3-位0决定,也就是CH365输出RD和WR的低电平的宽度,
    CH365读写脉冲之间的间隔,也就是CH365输出RD和WR的高电平的宽度,分为两种:
         一种是两次操作之间的间隔,也就是计算机程序发出的两次读写操作之间的间隔,通常为300nS以上,与计算机本身硬件有关(最小能到240nS),
         另一种是单次操作之间的间隔,也就是CH365将字或双字转换为多个字节之间的间隔,可以是30nS或60nS,由CH365读写速度控制寄存器位4决定,
  1.最快的速度情形是:(设置CH365读写速度控制寄存器为0x00)
        读写脉冲宽度为30nS,单次操作之间的间隔为30nS,
        计算机程序以双字(32位)为单位进行读写操作,实测速度可以达到7.5MB,理论值=4*1000/(300nS+30nS*4+30nS*3),乘4是因为双字操作,
        在这种情形下外部电路的速度必须在25nS之内才能可靠工作,例如:25nS的高速双口RAM,或者是CPLD/FPGA可编程器件
  2.较快的速度情形是:(设置CH365读写速度控制寄存器为0x12)
        读写脉冲宽度为60nS,单次操作之间的间隔为60nS,
        计算机程序以双字(32位)为单位进行读写操作,实测速度可以达到5.3MB,理论值=4*1000/(300nS+60nS*4+60nS*3),乘4是因为双字操作,
        在这种情形下外部电路的速度必须在55nS之内才能可靠工作,例如:35nS-55nS的双口RAM,或者是CPLD/FPGA可编程器件,大多数TTL接口电路等
  3.最慢的速度情形是:(设置CH365读写速度控制寄存器为0x07)
        读写脉冲宽度为240nS,由于总是以字节为单位读写,所以单次操作之间的间隔没有用到,可以设为30nS,
        计算机程序以字节(8位)为单位进行读写操作,实测速度可以达到1.7MB,理论值=1*1000/(300nS+240nS*1),字节操作,
        在这种情形下外部电路的速度可以在230nS之内,例如:各种RAM,各种ROM,各种FLASH,各种TTL接口电路,CH421,CMOS工艺8255A/8155A/8253A等
*/

/* VC5.0编译 */

#include	<windows.h>
#include	<stdlib.h>
#include	<stdio.h>
#include	<conio.h>
//#include	<setupapi.h>
#include	<winioctl.h>
#include	"CH365DLL.H"
 
mPCH365_IO_REG	 mIoBase;		       // I/O基址
mPCH365_MEM_REG  mMemBase;             //存储器基地址
int  Device_Number=0;                  //选择设备号

void TestSpeed( ULONG  mode, PUCHAR str )
{
	ULONG	i, time;
	double  speed;
	UCHAR	Buffer[0x8000];
    printf( "*** call CH365mAccessBlock, %s\n", str );
	time=GetTickCount();
	for ( i = 0; i < 512 ; i ++ ) {
		if ( CH365mAccessBlock( Device_Number,mode,0,Buffer,0x8000 ) == FALSE ) { printf( " ERROR " ); break; }
	}
	time = (ULONG)(GetTickCount()) - time;
	speed=1000;
	if ( time !=0 ) speed=speed*0x8000*512/time;
	else speed=9999999;
	printf( "*** Speed = %7.1f Bytes/Sec, total=%ld bytes, time=%ld mS\n", speed, 0x8000*512, time);
}

void	main()
{
    printf("*****Copyright (C) W.ch 2004.08 ");
// 需要使用DLL则需要先加载
	printf( "*** Load DLL: CH365DLL.DLL \n" );
	if ( LoadLibrary( "CH365DLL.DLL" ) == NULL ) return;         // 加载DLL失败,可能未安装到系统中
//选择打开365设备
//OPEN DEVICE   使能存储器和禁止中断
	printf( "*** CH365mOpenDevice: I/O port, Memory\n" );
	if ( CH365mOpenDevice(Device_Number, TRUE, FALSE ) == INVALID_HANDLE_VALUE ) return;
// 通过DLL来调用系统自动分配的I/O基地址
    printf( "*** CH365mGetIoBaseAddr " );
	if ( CH365mGetIoBaseAddr( Device_Number,&mIoBase ) == FALSE ) printf( " ERROR " );
	printf( "= %08X \n", mIoBase );
// 通过DLL来调用系统自动分配的存储器基地址
    printf( "***CH365mGetMemBaseAddr ");
    if (CH365mGetMemBaseAddr(Device_Number,&mMemBase) ==FALSE) printf("ERROR");
    printf("=%08X\n",mMemBase);
// 显示LED
    printf( "*** CH365mSetA15_A8: data=0x00 \n" );
    if ( CH365mSetA15_A8(Device_Number, 0 ) == FALSE ) printf( " ERROR " );

    printf( "*** Default CH365 speed is 240nS/30nS, access pulse width is 240nS, \n" );
    printf( "*** To modify call: CH365mWriteIoByte(index, &mIoBase->mCh365Speed, value) \n" );

    printf( "*** Step1: Set 30nS/30nS, value = 0x00, for fast CPLD/FPGA or DualPortSRAM \n" );
    if ( CH365mWriteIoByte(Device_Number, &mIoBase -> mCh365Speed, 0x00 ) == FALSE ) printf( " ERROR " );
	TestSpeed( mFuncReadIoDword, "mFuncReadIoDword: Read I/O, DWORD" );
	TestSpeed( mFuncReadMemDword, "mFuncReadMemDword: Read Mem, DWORD" );
	TestSpeed( mFuncReadIoByte, "mFuncReadIoByte: Read I/O, BYTE" );
	TestSpeed( mFuncReadMemByte, "mFuncReadMemByte: Read Mem, BYTE" );
    printf( "Press any key to continue\n" );
    if ( getch() != 0x1B ) {
	    printf( "*** Step2: Set 60nS/60nS, value = 0x12, for CPLD/FPGA or DualPortSRAM\n" );
	    if ( CH365mWriteIoByte(Device_Number, &mIoBase -> mCh365Speed, 0x12 ) == FALSE ) printf( " ERROR " );
		TestSpeed( mFuncReadIoDword, "mFuncReadIoDword" );
		TestSpeed( mFuncReadMemDword, "mFuncReadMemDword" );
		TestSpeed( mFuncReadIoByte, "mFuncReadIoByte" );
		TestSpeed( mFuncReadMemByte, "mFuncReadMemByte" );
		TestSpeed( mFuncReadMemDword, "mFuncWriteMemDword: Write Mem, DWORD" );
	    printf( "*** Step3: Set 210nS/60nS, value = 0x17, only for access by Byte unit \n" );
	 	if ( CH365mWriteIoByte(Device_Number, &mIoBase -> mCh365Speed, 0x17 ) == FALSE ) printf( " ERROR " );
		TestSpeed( mFuncReadIoByte, "mFuncReadIoByte" );
		TestSpeed( mFuncReadMemByte, "mFuncReadMemByte" );
	    printf( "*** Step4: Set default: 240nS/30nS, value = 0x07, only for access by Byte unit \n" );
	    printf( "*** CH365mWriteIoByte( index, &mIoBase->mCh365Speed, 0x07 ) \n" );
	    if ( CH365mWriteIoByte(Device_Number, &mIoBase -> mCh365Speed, 0x07 ) == FALSE ) printf( " ERROR " );
	}
// 关闭LED
    printf( "*** CH365mSetA15_A8: data=0x80 \n" );
    if ( CH365mSetA15_A8(Device_Number, 0x80 ) == FALSE ) printf( " ERROR " );
	printf( "*** CH365mCloseDevice \n" );
    CH365mCloseDevice(Device_Number);
    getch( );
}

⌨️ 快捷键说明

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