1、整理反射内存卡资料整理一、反射内存卡基本特征 型号:vmipci-5565-110001板载内存128MB ,地址空间:0x0 0x7FFFFFF24k FIFOs3Transmission Mode=Multimode4No Conformal Coating保形角涂料二、中断式通信流程图1 中断式通信流程图2.1 特点:一、发送方和接收方通过事件进行同步,CPU占用少;二、发送方可以向多个指定的接收方发送数据,即1对多方式;也可以实现广播方式。2.2 注意事项:1.当接收方调用RFM2gWaitForEvent函数后,将挂起当前线程。直到有事件发生或等待超时才能恢复,因此接收部分的代码应采
2、用多线程编程;2.RFM2gSendEvent需要指定接收设备的NodeID,该参数由板卡上的跳线决定(Each RFM2g device on an RFM2g network is uniquely identified by its node ID, which is manually set by jumpers on the device when the RFM2g network is installed. The driver determines the node ID when the device is initialized)。本机的NodeID可以通过API RFM2
3、gNodeID获取;如果采取广播方式,则参数NodeID应指定为宏定义RFM2G_NODE_ALL;3.数据读写有两种方式:直接读写和内存映射。直接读写的相关函数有:RFM2gRead和RFM2gWrite。内存映射的相关函数有:RFMUserMemory和RFMUnMapUserMemory。后者将板载内存按页(page)映射到程序的内存空间,对映射内存的操作将直接反应到板载内存上。按照手册的解释:使用内存映射后,数据的传输将使用PIO方式,不使用DMA方式。而直接读写函数的数据传输将尽可能采取DMA方式。三、代码3.1收发一体的通信代码(摘自例程rfm2g_send.c,为便于理解,去掉了
4、其中的错误处理代码):#include rfm2g_windows.h /屏蔽在Vs2005中编译时的警告#include rfm2g_api.h /rfm API#define BUFFER_SIZE 256 /缓冲区大小 256byte#define OFFSET_1 0x1000 /写数据起始位置 4k #define OFFSET_2 0x2000 /读数据起始位置 8k#define TIMEOUT 60000 /超时时间 60s#define DEVICE_PREFIX .rfm2g /win系统的PCI设备名前缀RFM2G_STATUS result; / RFM2g API 调
5、用的返回值,成功为RFM2G_SUCCESS RFM2G_CHAR device40; / 完整的设备名由前缀和设备编号组成RFM2GHANDLE Handle = 0; /设备操作句柄,由RFM2gOpen返回/构造设备名,如.rfm2g1 sprintf(device, %s%d, DEVICE_PREFIX, numDevice);/打开设备result = RFM2gOpen( device, &Handle );/使网络中断可用。默认情况下,反射内存网的中断是不可用的,RFM2gEnableEvent函数使得接收设备可以响应网络中断。如果发送方不需响应中断,则不必调用该函数resul
6、t = RFM2gEnableEvent( Handle, RFM2GEVENT_INTR2 );/将数据写入反射内存卡的板载内存。result = RFM2gWrite( Handle, OFFSET_1, (void *)outbuffer, BUFFER_SIZE*4 );/*在板载内存的有效范围之内,从第二个参数指定起始地址开始写入数据。写入的长度按字节计算。字长换算法则:1 byte= 1 RFM2G_UINT81 word= 1 RFM2G_UINT16= 2* RFM2G_UINT81 long word= 1 RFM2G_UINT32= 4* RFM2G_UINT8*/发网络中
7、断result = RFM2gSendEvent( Handle, otherNodeId, RFM2GEVENT_INTR1, 0);/等待中断RFM2GEVENTINFO EventInfo; EventInfo.Event = RFM2GEVENT_INTR2; /等待的网络中断类型EventInfo.Timeout = TIMEOUT; /等待多久即超时result = RFM2gWaitForEvent( Handle, &EventInfo );/调用后程序挂起/读数据.与RFM2gWrite函数类似,需要事先分配读取缓冲和指定读取数据的长度result = RFM2gRead(
8、Handle, OFFSET_2, (void *)inbuffer, BUFFER_SIZE*4);/关闭设备 RFM2gClose( &Handle );/通用错误处理if( result != RFM2G_SUCCESS ) printf(Error: %sn, RFM2gErrorMsg(result) ); RFM2gClose( &Handle ); return(result);3.2 测试用代码段3.2.1 获取板卡配置信息 RFM2G_STATUS Status; RFM2GCONFIG Config; /* Get the board Configuration */ St
9、atus = RFM2gGetConfig( Handle, &Config ); if( Status != RFM2G_SUCCESS ) printf( Could not get the board Configuration.n ); printf( Error: %s.nn, RFM2gErrorMsg(Status); return(-1); /* Print board configuration */ printf ( Driver Part Number %sn, Config.Name); printf ( Driver Version %sn, Config.Drive
10、rVersion); printf ( Device Name %sn, Config.Device); printf ( Board Instance %dn, Config.Unit); printf ( Board ID 0x%02Xn, Config.BoardId); printf ( Node ID 0x%02Xn, Config.NodeId); printf ( Installed Memory %ud (0x%08X)n, Config.MemorySize, Config.MemorySize); printf ( Memory Offset: ); switch (Con
11、fig.Lcsr1 & 0x0030000 ) case 0x00000000: printf (0x00000000n); break; case 0x00010000: printf (0x04000000n); break; case 0x00020000: printf (0x08000000n); break; case 0x00030000: printf (0x0c000000n); break; default: /* S/W Error */ printf(n); printf ( Board Revision 0x%02Xn, Config.BoardRevision);
12、printf ( PLX Revision 0x%02Xn, Config.PlxRevision); /* Display Board Configuration */ printf ( Config.Lcsr1 0x%08xn, Config.Lcsr1); printf(RFM2g Configuration:n); if (Config.Lcsr1 & 0x01000000) printf ( Rogue Master 0 Enabledn); if (Config.Lcsr1 & 0x02000000) printf ( Rogue Master 1 Enabledn); if (C
13、onfig.Lcsr1 & 0x04000000) printf ( Redundant Moden); else printf ( Fast Moden); if (Config.Lcsr1 & 0x08000000) printf ( Local Bus Parity Enabledn); if (Config.Lcsr1 & 0x10000000) printf ( Loopback Enabledn); if (Config.Lcsr1 & 0x20000000) printf ( Dark-on-Dark Enabledn); if (Config.Lcsr1 & 0x4000000
14、0) printf ( Transmitter Disabledn); /* PCI Configuration Info */ printf(RFM2g PCI Configuration:n); printf ( bus 0x%02xn, Config.PciConfig.bus); printf ( function 0x%02xn, Config.PciConfig.function); printf ( type 0x%04xn, Config.PciConfig.type); printf ( devfn 0x%08xn, Config.PciConfig.devfn); prin
15、tf ( revision 0x%02xn, Config.PciConfig.revision); printf ( rfm2gOrBase 0x%08xn, Config.PciConfig.rfm2gOrBase); printf ( rfm2gOrWindowSize 0x%08xn, Config.PciConfig.rfm2gOrWindowSize); printf ( rfm2gOrRegSize 0x%08xn, Config.PciConfig.rfm2gOrRegSize); printf ( rfm2gCsBase 0x%08xn, Config.PciConfig.r
16、fm2gCsBase); printf ( rfm2gCsWindowSize 0x%08xn, Config.PciConfig.rfm2gCsWindowSize); printf ( rfm2gCsRegSize 0x%08xn, Config.PciConfig.rfm2gCsRegSize); printf ( rfm2gBase 0x%08xn, Config.PciConfig.rfm2gBase); printf ( rfm2gWindowSize 0x%08xn, Config.PciConfig.rfm2gWindowSize); printf ( interruptNum
17、ber 0x%02xn, Config.PciConfig.interruptNumber); 3.2.2 测试反射内存网连接 RFM2G_STATUS status; /* If the ring is intact, the own-data bit will be set */ status = RFM2gCheckRingCont(cmd-Handle); if( status = RFM2G_SUCCESS ) printf( The Reflective Memory link is intact.n ); else printf( Error: %s.nn, RFM2gError
18、Msg(status); 3.2.3 DMA性能测试 RFM2G_INT32 index; /* Selects appropriate nomenclature */ char * name; /* Local pointer to command name */ char * desc; /* Local pointer to command description */ RFM2G_STATUS Status; time_t time1; /* ANSI C time */ double mBytePerSec = 0; int numBytes = 0; int numIteratio
19、ns = 10000; int count; int timeToRunTest = 2; /* Time to run tests in seconds */ RFM2G_UINT32 dmaThreshold; /* Get the DMA Threshold */ RFM2gGetDMAThreshold(Handle, &dmaThreshold); printf(nRFM2g Performance Test (DMA Threshold is %d)n, dmaThreshold); printf(-n); printf( Bytes Read IOps Read MBps Wri
20、te IOps Write MBpsn); for (numBytes = 0; numBytes MEMBUF_SIZE; ) if (numBytes 32) numBytes += 4; else if (numBytes 128) numBytes += 32; else if (numBytes 2048) numBytes += 128; else if (numBytes 4096) numBytes += 512; else if (numBytes 16384) numBytes += 4096; else if (numBytes 131072) numBytes += 1
21、6384; else if (numBytes 262144) numBytes += 65536; else numBytes += 262144; numIterations = 0; if (time(&time1) = -1) printf(ANSI C time function returned ERRORn); return(-1); /* Wait for the timer to get to the begining of a second */ while (difftime(time(0), time1) = 0) /* Lets wait */ count+; /*
22、Get the start time */ time(&time1); /* The accuracy of the results is dependent on the amount of time the test runs and the Number of IOs per second. This is not a precise test, the priority of this task along with the limited resolution (1 Sec) of the ANSI C time function affects the precision. */
23、while (difftime(time(0), time1) timeToRunTest) Status = RFM2gRead(Handle, 0, /* rfmOffset */ (void*) MemBuf, numBytes); if (Status != RFM2G_SUCCESS) printf(RFM2gRead : Failuren); printf( Error: %s.nn, RFM2gErrorMsg(Status); return(-1); numIterations+; /* Calculate MByte/Sec = Total number of bytes t
24、ransferred / (Time in seconds * 1024 * 1024) */ mBytePerSec = (double)(numBytes * numIterations) / ( timeToRunTest * 1024.0 * 1024.0); printf(%8d %10d %6.1f, numBytes, (numIterations / timeToRunTest), mBytePerSec); numIterations = 0; time(&time1); /* Wait for the timer to get to the begining of a se
25、cond */ while (difftime(time(0), time1) = 0) /* Lets wait */ count+; /* Get the start time */ time(&time1); /* Perform the IO until the elapsed time occurs */ while (difftime(time(0), time1) timeToRunTest) Status = RFM2gWrite(Handle, 0, /* rfmOffset */ (void*) MemBuf, numBytes); if (Status != RFM2G_
26、SUCCESS) printf( RFM2gWrite : Failuren); printf( Error: %s.nn, RFM2gErrorMsg(Status); return(-1); numIterations+; mBytePerSec = (double) (numBytes * numIterations) / (timeToRunTest * 1024.0 * 1024.0); printf( %10d %6.1fn, (numIterations / timeToRunTest), mBytePerSec); /* for */3.3 常用API3.3.1 RFM2gOp
27、en()Several programs and execution threads may have the same RFM2g interface open at any given time. The driver and the API library are thread-safe; (该函数支持多线程)SyntaxSTDRFM2GCALL RFM2gOpen( char *DevicePath, RFM2GHANDLE *rh );ParametersDevicePath Path to special device file (I). Refer to your driver-
28、specific manual for the format of DevicePath.rh Pointer to an RFM2GHANDLE structure (IO).3.3.2 RFM2gClose()Once the RFM2g handle is closed, all of the facilities using that handle are no longer accessible, including the local RFM2g memory, which may be mapped into the application programs virtual me
29、mory space.SyntaxSTDRFM2GCALL RFM2gClose( RFM2GHANDLE *rh );Parametersrh Initialized previously with a call to RFM2gOpen() (I).3.3.3 RFM2gRead()The RFM2g driver attempts to fulfill the RFM2gRead() request using the bus master DMA feature available on the RFM2g device. The driver will move the data using the DMA feature if the length of the I/O request is at least as long as the minimum DMA threshold.If the RFM2g device does not support the bus master DMA feature, or if the I/O requ
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1