📄 sicommon_amcc_win.cpp
字号:
pAMCCDev->hDevice = INVALID_HANDLE_VALUE;
return e_Err_DeviceNotFound;
}
CloseHandle(pAMCCDev->hDevice);
pAMCCDev->hDevice = INVALID_HANDLE_VALUE;
// board to register is more than the total boards in system.
if ( board >= numberOfBoardsFound )
return e_Err_DeviceNotFound;
// 3. now open the driver and register it.
pAMCCDev->hDevice =
CreateFile
(
driverNameTemp,
// if data goes both ways use READ and WRITE
GENERIC_WRITE | GENERIC_READ,
// for multiple program access to the device
FILE_SHARE_WRITE | FILE_SHARE_READ,
// Security attributes go here, but don't really apply to devices
NULL,
// A must for devices
OPEN_EXISTING,
// O-LAPPED now on EVERY call
FILE_FLAG_DELETE_ON_CLOSE | FILE_FLAG_OVERLAPPED,
// template file, not used by the driver
NULL
);
// could not open driver handle
if (pAMCCDev->hDevice == INVALID_HANDLE_VALUE)
return e_Err_DeviceNotFound;
// register the device with the driver
if
(
!DeviceIoControl
(
pAMCCDev->hDevice,
IOCTL_SHELDON_REGISTER_NEW_BOARD,
&board,
sizeof(UINT32),
NULL,
0,
&returnedBytes,
NULL
)
)
{
CloseHandle(pAMCCDev->hDevice);
pAMCCDev->hDevice = INVALID_HANDLE_VALUE;
return e_Err_MiscError;
}
// Begin: Win95 specific callback handling.
// function to translate Ring 3 handle to Ring 0 handle
typedef DWORD(WINAPI *OPENVXDHANDLE)(HANDLE);
OPENVXDHANDLE OpenVxDHandle;
// translation for ring3 / 0 for system DLL.
OpenVxDHandle =
(OPENVXDHANDLE)GetProcAddress
(
GetModuleHandle("KERNEL32"),
"OpenVxDHandle"
);
//This is a call to a system dll which converts the application
// event to a system event
pAMCCDev->hCallbackEventDriver =
(HANDLE)OpenVxDHandle(pAMCCDev->hCallbackEvent);
// End: Win95 specific callback handling.
return e_Err_NoError;
}
///////////////////////////////////////////////////////////////////////////////
// INT32 SI_AMCC_OpenDriver
//
// Description:
// Attempts to link a valid driver to our program
//
// Parameters:
// UINT32 board ID Number of the board
// PAMCCDevice pAMCCDev Handle to the driver
//
INT32 SI_AMCC_OpenDriver( UINT32 board, PAMCCDevice pAMCCDev )
{
UINT32 error;
// 0. create events
error = SI_AMCC_OverlappedCreate(pAMCCDev);
if ( error != e_Err_NoError )
{
SI_AMCC_OverlappedDestroy(pAMCCDev);
return error;
}
// 1. Try to open WIN95 driver.
error =
SI_AMCC_OpenDriverWin95
(
"SIDRV95.VXD", board,
pAMCCDev
);
if (error != e_Err_NoError)
{
// 2. Try to open WINNT4 driver.
error =
SI_AMCC_OpenDriverNT4
(
"SIDRV", board,
pAMCCDev
);
if (error != e_Err_NoError)
{
// 3. Try to open WDM driver.
error =
SI_AMCC_OpenDriverWDM
(
"SIWDM", board,
pAMCCDev
);
if (error != e_Err_NoError)
{
SI_AMCC_OverlappedDestroy(pAMCCDev);
return e_Err_DeviceNotFound;
}
}
}
return e_Err_NoError;
}
///////////////////////////////////////////////////////////////////////////////
// INT32 SI_AMCC_CloseDriver
//
// Description:
//
// Parameters:
// PAMCCDevice pAMCCDev : Handle to the device driver.
INT32 SI_AMCC_CloseDriver( PAMCCDevice pAMCCDev )
{
if ( pAMCCDev->hDevice != INVALID_HANDLE_VALUE )
{
SI_AMCC_ReleaseDirectAccessAddr(pAMCCDev);
CloseHandle(pAMCCDev->hDevice);
SI_AMCC_OverlappedDestroy(pAMCCDev);
pAMCCDev->hDevice = INVALID_HANDLE_VALUE;
}
return e_Err_NoError;
}
///////////////////////////////////////////////////////////////////////////////
// INT32 SI_AMCC_ReadPCI_ConfSpace
//
// Description:
//
// Parameters:
// PAMCCDevice pAMCCDev : Handle to the device driver.
// UINT32 count : Number of UINT32 to access.
// UINT32 offset : Byte offset from 0 for PCI config space.
// UINT32 *data : Pointer to host memory where the data resides.
// todo: fix this
INT32 SI_AMCC_ReadPCI_ConfSpace
(
PAMCCDevice pAMCCDev,
UINT32 count, UINT32 offset, UINT32 *data
)
{
DWORD cbIn, cbOut, cbReturned;
UINT32 config_params[2];
gSI_AMCC_BenchmarkTime0 = GetTickCount();
if (count == 0)
return e_Err_NoError;
// load the input struct
cbIn = SI_CONFIG_READ_TOSIZE;
// this is the size of the configuration space used by the AMCC chip
cbOut = count * sizeof(UINT32);
config_params[SI_CONFIG_OFFSET_INDEX] = offset;
config_params[SI_CONFIG_COUNT_INDEX] = cbOut;
// call the Driver
if
(
!DeviceIoControl
(
pAMCCDev->hDevice,
IOCTL_SHELDON_CONFIG_READ,
config_params,
cbIn,
data,
cbOut,
&cbReturned,
pAMCCDev->pOverlappedMisc
)
)
return e_Err_ReadError;
gSI_AMCC_BenchmarkTime1 = GetTickCount();
return e_Err_NoError;
}
///////////////////////////////////////////////////////////////////////////////
// INT32 SI_AMCC_ReadPCI_NVWord
//
// Description:
//
// Parameters:
// PAMCCDevice pAMCCDev : Handle to the device driver.
// UINT32 count : Number of UINT32 to access.
// UINT32 addrNVRam: NVRAM address to access (byte offset).
// UINT32 *data : Pointer to host memory where the data resides.
INT32 SI_AMCC_ReadPCI_NVWord
(
PAMCCDevice pAMCCDev,
UINT32 count, UINT32 addrNVRam, UINT32 *data
)
{
DWORD cbReturned, cnt;
UINT32 addrNVRam1;
gSI_AMCC_BenchmarkTime0 = GetTickCount();
if (count == 0)
return e_Err_NoError;
for (cnt=0; cnt<count; cnt++)
{
// driver is expecting byte address, and returning byte data.
// however, data is returned in UINT32 array, so upper 24 bits are
// invalid.
addrNVRam1 = addrNVRam + cnt;
if
( !DeviceIoControl
(
pAMCCDev->hDevice,
IOCTL_SHELDON_NVRAM_READ,
&addrNVRam1,
SI_NV_READ_TOSIZE,
&data[cnt],
SI_NV_READ_FROMSIZE,
&cbReturned,
pAMCCDev->pOverlappedMisc
)
)
return e_Err_ReadError;
data[cnt] = data[cnt] & 0xFF; // maskout upper 24 bits
}
gSI_AMCC_BenchmarkTime1 = GetTickCount();
return e_Err_NoError;
}
///////////////////////////////////////////////////////////////////////////////
// INT32 SI_AMCC_WritePCI_NVWord
//
// Description:
//
// Parameters:
// PAMCCDevice pAMCCDev : Handle to the device driver.
// UINT32 count : Number of UINT32 to access.
// UINT32 addrNVRam: NVRAM address to access (byte offset).
// UINT32 *data : Pointer to host memory where the data resides.
INT32 SI_AMCC_WritePCI_NVWord
(
PAMCCDevice pAMCCDev,
UINT32 count, UINT32 addrNVRam, UINT32 *data
)
{
DWORD cbReturned;
UINT32 nv_write_params[2];
UINT32 cnt;
gSI_AMCC_BenchmarkTime0 = GetTickCount();
for(cnt =0; cnt < count; cnt++)
{
// driver is expecting byte address, and returning byte data.
// however, data is written in UINT32 array, so upper 24 bits are
// invalid.
nv_write_params[0] = addrNVRam + cnt;
nv_write_params[1] = *data++;
if
(
!DeviceIoControl
(
pAMCCDev->hDevice,
IOCTL_SHELDON_NVRAM_WRITE,
&nv_write_params,
SI_NV_WRITE_TOSIZE,
NULL,
SI_NV_WRITE_FROMSIZE,
&cbReturned,
pAMCCDev->pOverlappedMisc
)
)
return e_Err_WriteError;
}
gSI_AMCC_BenchmarkTime1 = GetTickCount();
return e_Err_NoError;
}
///////////////////////////////////////////////////////////////////////////////
// INT32 SI_AMCC_ReleaseDirectAccessAddr
//
// Description:
//
// Parameters:
// PAMCCDevice pAMCCDev : Handle to the device driver.
// todo: fix this
INT32 SI_AMCC_ReleaseDirectAccessAddr
(
PAMCCDevice pAMCCDev
)
{
DWORD cbReturned;
gSI_AMCC_BenchmarkTime0 = GetTickCount();
if
(
!DeviceIoControl
(
pAMCCDev->hDevice,
IOCTL_SHELDON_RELEASE_BADDR,
NULL,
0,
NULL,
0,
&cbReturned,
pAMCCDev->pOverlappedMisc
)
)
return e_Err_MiscError;
gSI_AMCC_BenchmarkTime1 = GetTickCount();
return e_Err_NoError;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -