// PciCardDriver.cpp: implementation of the PciCardDriver class.
//
//////////////////////////////////////////////////////////////////////
#include "PciCardDriver.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//板卡基类
PciCardDriver::PciCardDriver()
{
init();
}
PciCardDriver::PciCardDriver(
UINT uiCardID,
const DWORD SVID,
const DWORD DID,
const DWORD VID,
const DWORD PADDR,
const DWORD PRANGE,
const DWORD MRANGE,
char *iniPath
)
{
init(DID,VID,SVID,PADDR,PRANGE,MRANGE);
}
PciCardDriver::~PciCardDriver()
{
if(bHasRegistered)
{
UnRegister() ;
}
}
/*
* 函数介绍:驱动程序注册
* 输入参数:无
* 输出参数:无
* 返回值:TRUE-----注册成功
* FALSE----注册失败
*/
BOOL PciCardDriver::Register()
{
//
// Search for the device using vendor and device IDs
//
busNumber = DeviceSearch( m_VID, m_DID, &slotNumber, pciData );
//
// If the device is found
//
if( busNumber != DEVICE_NOT_FOUND )
if( !DeviceInit( busNumber, &slotNumber, pciData ) )
DeviceCleanup();
else
bHasRegistered=TRUE;
return bHasRegistered;
}
/*
* 函数介绍:驱动程序卸载
* 输入参数:无
* 输出参数:无
* 返回值:无
*/
void PciCardDriver::UnRegister()
{
bHasRegistered=FALSE;
DeviceCleanup();
}
/*
* 函数介绍:接收的数据类型转换 WORD->double
* 输入参数:wData WORD型数据
* 输出参数:无
* 返回值:double型数据
*/
double PciCardDriver::WordToDouble(WORD wData)
{
if (0x8000 > wData)
{
return (wData * 10.0 / 0x8000);
}
else if (0x8000 == wData)
{
return -10.0;
}
else
{
return((wData-0x8000) * 10.0 / 0x8000 -10.0);
}
}
/*
* 函数介绍:数据转换,double->WORD
* 输入参数:dbData---double 型数据
* 输出参数:无
* 返回值:WORD型数据
*/
WORD PciCardDriver::DoubleToWord(double dbData)
{
WORD wData = 0;
double dbTemp;
if (dbData > 0)
{
dbTemp = dbData * 0x8000/10.0;
wData = (WORD)dbTemp;
if (0x8000 == wData)
{
wData--;
}
}
else if (dbData < 0)
{
dbTemp = dbData / 10.0 * 0x8000 + 0x10000 ;
wData= (WORD)dbTemp;
}
return wData;
}
/*
* 函数介绍:返回打开卡的状态
* 输入参数:无
* 输出参数:无
* 返回值:BOOL型数据
*/
BOOL PciCardDriver::IsOpen()
{
return bHasRegistered;
}
//
// Search devices
//
int PciCardDriver::DeviceSearch (
int vendorID,
int deviceID,
PCI_SLOT_NUMBER *pSlotNumber,
PPCI_COMMON_CONFIG PciData
)
{
ULONG bus; // bus number
ULONG deviceNumber; // logical slot number for the PCI adapter
ULONG functionNumber; // function number on the specified adapter
ULONG bytesWritten; // return value from RtGetBusDataByOffset
BOOLEAN bFlag = TRUE;
int CardIndex = 0;
pSlotNumber->u.bits.Reserved = 0;
//
// All PCI cards have been searched when we are out of PCI busses. (bFlag = FALSE)
//
for ( bus=0; bFlag; bus++ )
{
for ( deviceNumber=0; deviceNumber < PCI_MAX_DEVICES && bFlag; deviceNumber++ )
{
pSlotNumber->u.bits.DeviceNumber = deviceNumber;
for ( functionNumber=0; functionNumber < PCI_MAX_FUNCTION; functionNumber++ )
{
pSlotNumber->u.bits.FunctionNumber = functionNumber;
bytesWritten = RtGetBusDataByOffset (
PCIConfiguration, // type of bus data to be retrieved
bus, // zero-based number of the bus
pSlotNumber->u.AsULONG, // logical slot number
PciData, // pointer to a buffer for configuration information
0, // byte offset into buffer
PCI_COMMON_HDR_LENGTH // length of buffer
);
if ( bytesWritten == 0 )
{
// out of PCI buses done
bFlag = FALSE;
break;
}
if ( bytesWritten == VENDOR_ID_SIZE && PciData->VendorID == PCI_INVALID_VENDORID )
{
// no device at this slot number, skip to next slot
break;
}
//
// If device is found return, otherwise continue
// until all buses have been searched.
// Base Class and sub Class can also be used to find your
// specific device.
//
if ( ( PciData->VendorID == vendorID ) && ( PciData->DeviceID == deviceID ) &&(PciData->u.type0.SubVendorID==m_SVID) )
return bus;
} // functionNumber loop
} // deviceNumber loop
} // bus loop
return DEVICE_NOT_FOUND;
}
//
// Initialize device
//
BOOLEAN PciCardDriver::DeviceInit (
int busNumber,
PCI_SLOT_NUMBER *pSlotNumber,
PPCI_COMMON_CONFIG PciData
)
{
LARGE_INTEGER memAddr; // a base port address
LARGE_INTEGER tranMemAddr; // translated base addresses returned by RtMapMemory
ULONG AddressSpace = 0; // indicates memory space
ULONG bytesWritten = 0;
int i=0;
int addressRange = m_maddressrange;
//
// Enable Port IO.
// It is not necessary to call RtEnablePortIo in an RTX application
//
if( !RtEnablePortIo ( ( unsigned char * ) IoAddress, sizeof ( DeviceIORegs ) ) )
return FALSE;
//
// Get the virtual bus addresses for each address register
// if call fails set to NULL and continue
//
for( i=0; i< NUM_REGISTERS; i++ )
{
memAddr.QuadPart = PciData->u.type0.BaseAddresses[i];
//
// Translate the base port addresses to system mapped addresses.
//
if (!RtTranslateBusAddress (
PCIBus, // bus interface type
busNumber, // bus number (zero based)
memAddr, // bus-relative address
&AddressSpace, // specifies port number or a memory address
&tranMemAddr // pointer to the translated address
) )
{
vMemAddr[i] = NULL;
continue;
}
//
// Map the addresses to virtual addresses the software can use
//
vMemAddr[i] = (char *)RtMapMemory (
tranMemAddr, // base of the physical address range to map
addressRange, // the length of address range in bytes
0 // whether or not to use cache
);
}
//
// Set the command parameter so we can access the PCI device's control registers.
//
PciData->Command = ( PCI_ENABLE_IO_SPACE | PCI_ENABLE_MEMORY_SPACE |
PCI_ENABLE_BUS_MASTER | PCI_ENABLE_WRITE_AND_INVALIDATE );
bytesWritten = RtSetBusDataByOffset (
PCIConfiguration, // type of bus data to be set
busNumber, // bus number (zero based)
pSlotNumber->u.AsULONG, // logical slot number
PciData, // pointer buffer containing configuration information
0, // byte offset in the buffer
PCI_COMMON_HDR_LENGTH // number of bytes in the buffer
);
if( bytesWritten == 0 )
return FALSE;
//
//TO DO:
// Setup _baseAddress if you plan to use defines setup in the header file
// Do any other initialization that is necessary for this device.
//
return TRUE;
}
//
// Cleanup
//
void PciCardDriver::DeviceCleanup ()
{
for(int i=0; i< NUM_REGISTERS; i++ )
{
if( vMemAddr[i] != NULL )
{
RtUnmapMemory ( vMemAddr[i] );
vMemAddr[i] = NULL;
}
}
RtDisablePortIo ( ( unsigned char * ) IoAddress, sizeof ( DeviceIORegs ) );
}
//
// Print message and exit
//
void PciCardDriver::MsgAndExit(
char *msg
)
{
RtPrintf ( "Error: %s (0x%X)\n", msg, RtGetLastError ( ) );
RtExitProcess ( 1 );
}
void PciCardDriver::MsgPrint(
char *msg
)
{
RtPrintf( "Error: %s (0x%X)\n",msg,RtGetLastEr
没有合适的资源?快使用搜索试试~ 我知道了~
RTX.rar_RTX_Windows RTX_rtx windows_rtx 反射内存_光纤
共94个文件
h:19个
obj:14个
sbr:12个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 2 下载量 7 浏览量
2022-09-19
21:20:53
上传
评论 1
收藏 8.56MB RAR 举报
温馨提示
用于在windows程序下,通过反射光纤卡,读取数据,写入共享内存。
资源推荐
资源详情
资源评论
收起资源包目录
RTX.rar (94个子文件)
安晓风第一学期末RTX接收发送
RTX接收发送程序
RTSimu.ncb 217KB
RTSimuFuncs.cpp 751B
RTSimu___Win32_RTSS_Debug
RTSimu.pch 4.41MB
RTSimu.bsc 1.92MB
RTSimu.sbr 0B
PciCardDriver.sbr 0B
RTSimu.pdb 313KB
vc60.idb 49KB
RTSimu.rtss 163KB
RTSimu.obj 40KB
PciCardDriver.obj 76KB
RTSimuFuncs.obj 38KB
VMIC5565RTX.obj 46KB
RTSimuFuncs.sbr 0B
VMIC5565RTX.sbr 0B
config
using.rtx 92B
MSP_VMIC.lib 28KB
RTSimu.dsw 537B
RTSimu.cpp 2KB
RTSimu.dsp 9KB
RTSimu.positions 348B
RTSimu.h 1KB
VMIC5565RTX.h 7KB
PciCardDriver.h 10KB
RTSimu.opt 55KB
RS422Set.ini 4KB
MSP_VMIC.H 12KB
RTSimu___Win32_RTSS_Release
RTSimu.pch 4.4MB
RTSimu.bsc 1.91MB
RTSimu.sbr 0B
PciCardDriver.sbr 0B
vc60.idb 41KB
RTSimu.obj 4KB
PciCardDriver.obj 16KB
RTSimuFuncs.obj 2KB
VMIC5565RTX.obj 4KB
RTSimuFuncs.sbr 0B
VMIC5565RTX.sbr 0B
PciCardDriver.cpp 33KB
Debug
RTSimu.pch 4.44MB
RTSimu.exe 149KB
RTSimu.bsc 1.92MB
RTSimu.sbr 952KB
PciCardDriver.sbr 0B
vc60.idb 41KB
RTSimu.obj 54KB
PciCardDriver.obj 76KB
RS422Set.ini 4KB
RTSimu___Win32_RTSS_Release
RTSimuFuncs.obj 50KB
VMIC5565RTX.obj 46KB
Debug
RTSimuFuncs.sbr 0B
VMIC5565RTX.sbr 0B
VMIC5565RTX.cpp 8KB
RTSimu.plg 3KB
win32程序
rfm2g_api.h 8KB
rfm2gdll_stdc.h 2KB
Release
BuildLog.htm 4KB
win32receive.idb 19KB
rfm2g_errno.h 4KB
rfm2g_windows.h 617B
RTSSDebug
BuildLog.htm 5KB
Win32Receive.obj 66KB
win32receive.idb 139KB
Win32Receive.rtss.intermediate.manifest 380B
RTSSRelease
BuildLog.htm 4KB
win32receive.idb 19KB
rfm2g_osspec.h 7KB
Win32Receive.suo 8KB
Win32Receive.h 688B
Win32Receive.sln 1KB
rfm2gdll_stdc.lib 17KB
Win32Receive.vcproj.LOCALHOST.Administrator.user 3KB
Win32Receive.ncb 9.17MB
Win32Receive.vcproj.BIT-FCCCC6544FA.Liu.user 3KB
rfm2g_regs.h 12KB
Win32Receive.cpp 2KB
rfm2g_read.h 1KB
Win32Receive.vcproj.1E3B4F2BEBEB4AA.Administrator.user 3KB
pmc5565_nt.h 31KB
RFM2gDrv.h 8KB
Win32Receive.vcproj 10KB
winlocal.h 576B
rfm2g_defs.h 11KB
regacc.h 30KB
Debug
BuildLog.htm 6KB
Win32Receive.obj 61KB
Win32Receive.pdb 1.5MB
mt.dep 67B
win32receive.idb 139KB
Win32Receive.exe 336KB
Win32Receive.exe.intermediate.manifest 145B
rfmsg_read.h 0B
rfm2g_types.h 2KB
Win32Receive.vcproj.1F5DB3CEBA3F4DB.Administrator.user 3KB
共 94 条
- 1
资源评论
- WYBO72022-11-02资源很受用,资源主总结的很全面,内容与描述一致,解决了我当下的问题。
- liushenwen20092023-10-14内容与描述一致,超赞的资源,值得借鉴的内容很多,支持!
JaniceLu
- 粉丝: 78
- 资源: 1万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功