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

📄 xrpci.c

📁 wince 5.0下 实现PCI8串口卡驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
	// BTW, is there any need for those? I don't think so
	//
	BOOL   bRc = FALSE;	
    return bRc;
}

VOID
XRP_PowerDown(
	DWORD dwContext
    )
{
	UNREFERENCED_PARAMETER(dwContext);
}


VOID
XRP_PowerUp(
   DWORD dwContext
   )
{
	UNREFERENCED_PARAMETER(dwContext);
}


DWORD
XRP_Open(
    DWORD Context, 
    DWORD Access,
    DWORD ShareMode)
{

    DEBUGMSG(ZONE_FUNCTION,(_T("XRP_Open(%x, 0x%x, 0x%x)\r\n"),Context, Access, ShareMode));

    UNREFERENCED_PARAMETER(Access);
    UNREFERENCED_PARAMETER(ShareMode);

	// pass back the device handle
	return Context;		// 0 indicates failure
}


BOOL  
XRP_Close(
    DWORD Context
    ) 
{
    DEBUGMSG(ZONE_FUNCTION,(_T("XRP_Close(%x)\r\n"), Context));

    return TRUE;
}


DWORD
XRP_Read(
    DWORD  dwContext,
    LPVOID pBuf,
    DWORD  Len
    ) 
{
    UNREFERENCED_PARAMETER(dwContext);
    UNREFERENCED_PARAMETER(pBuf);
    UNREFERENCED_PARAMETER(Len);
    
    DEBUGMSG(ZONE_ERROR | ZONE_FUNCTION,(_T("XRP_Read\r\n")));
    SetLastError(ERROR_INVALID_FUNCTION);
    return  0;
}

DWORD
XRP_Write(
    DWORD  dwContext,
    LPVOID pBuf,
    DWORD  Len
    ) 
{
    UNREFERENCED_PARAMETER(dwContext);
    UNREFERENCED_PARAMETER(pBuf);
    UNREFERENCED_PARAMETER(Len);
    
    DEBUGMSG(ZONE_ERROR | ZONE_FUNCTION,(_T("XRP_Read\r\n")));
    SetLastError(ERROR_INVALID_FUNCTION);
    return  0;
}

ULONG
XRP_Seek(
   PVOID Context,
   LONG Position,
   DWORD Type
   )
{
    UNREFERENCED_PARAMETER(Context);
    UNREFERENCED_PARAMETER(Position);
    UNREFERENCED_PARAMETER(Type);
    
    return (DWORD)-1;
}

BOOL 
DllEntry(
   HANDLE hDllHandle, 
   DWORD  dwReason, 
   LPVOID lpreserved
   ) 
{
    BOOL bRc = TRUE;
    
    UNREFERENCED_PARAMETER(hDllHandle);
    UNREFERENCED_PARAMETER(lpreserved);
    
    switch (dwReason) {
        case DLL_PROCESS_ATTACH: 
			{
            DEBUGREGISTER((HINSTANCE)hDllHandle);
            DEBUGMSG(ZONE_INIT,(_T("*** DLL_PROCESS_ATTACH - XRPCI- Current Process: 0x%x, ID: 0x%x ***\r\n"),
                GetCurrentProcess(), GetCurrentProcessId()));
			} 
			break;
			
        case DLL_PROCESS_DETACH: 
			{
            DEBUGMSG(ZONE_INIT,(_T("*** DLL_PROCESS_DETACH - XRPCI - Current Process: 0x%x, ID: 0x%x ***\r\n"),
                GetCurrentProcess(), GetCurrentProcessId()));
			} 
			break;
			
        default:
            break;
    }
	
    return bRc;
}


/*++
*******************************************************************************
Routine:

    XRPCI_GetRegistryData

Description:

    Take the registry path provided to XRP_Init and use it to find this 
    requested comm port's DeviceArrayIndex, the Memory Base Address, and the
    Interrupt number.
   
Arguments:

    LPCTSTR regKeyPath  the registry path passed in to XRP_Init.

Return Value:

    -1 if there is an error.

*******************************************************************************
--*/
BOOL
XRPCI_GetRegistryData(PXRPCI_INFO pHWHead, LPCTSTR regKeyPath)
{
#define GCI_BUFFER_SIZE 256   

    LONG    regError;
    HKEY    hKey;
    DWORD   dwDataSize = GCI_BUFFER_SIZE;
    DDKISRINFO dii;
    DDKWINDOWINFO dwi;
	DDKPCIINFO ppi;

	// UART register stride (default = 1 byte).
	DWORD dwRegStride = 1;

    DEBUGMSG(ZONE_INIT, (TEXT("Try to open %s\r\n"), regKeyPath));

    // We've been handed the name of a key in the registry that was generated
    // on the fly by device.exe.  We're going to open that key and pull from it
    // a value that is the name of this serial port's real key.  That key
    // will have the DeviceArrayIndex that we're trying to find.  
    hKey = OpenDeviceKey(regKeyPath);
    if ( hKey == NULL ) {
        DEBUGMSG(ZONE_INIT | ZONE_ERROR,
                 (TEXT("Failed to open device key\r\n")));
        return ( FALSE );        
    }

    // read interrupt configuration parameters
    dii.cbSize = sizeof(dii);
    regError = DDKReg_GetIsrInfo(hKey, &dii);
    if(regError == ERROR_SUCCESS) 
	{
        if(dii.dwSysintr != SYSINTR_NOP) 
		{
            pHWHead->dwSysIntr = dii.dwSysintr;
        } 
		else 
		{
            regError = ERROR_FILE_NOT_FOUND;
        }
		
		pHWHead->dwIrq = dii.dwIrq;
    }

	//get our PCI device number
	if ( regError == ERROR_SUCCESS ) 
	{
        ppi.cbSize = sizeof(ppi);
        regError = DDKReg_GetPciInfo(hKey, &ppi);
        if(regError == ERROR_SUCCESS) 
		{
			DEBUGMSG(ZONE_INIT | ZONE_ERROR,
                 (TEXT("PCI Device number -  FOR debugging/understanding  0x%X, 0x%X\r\n"),
                  ppi.dwDeviceNumber, ppi.idVals[PCIID_DEVICEID]));
            // to find out 158/154/152
			pHWHead->dwDeviceId = ppi.idVals[PCIID_DEVICEID];
        }	
    }

    // get our device instance's index
    if(regError == ERROR_SUCCESS) 
	{
        dwDataSize = PC_REG_DEVINDEX_VAL_LEN;
        regError = RegQueryValueEx(
                                  hKey, 
                                  PC_REG_DEVINDEX_VAL_NAME, 
                                  NULL, 
                                  NULL,
                                  (LPBYTE)(&pHWHead->dwDevIndex), 
                                  &dwDataSize);
    }

    if ( regError == ERROR_SUCCESS ) 
	{
        dwi.cbSize = sizeof(dwi);
        regError = DDKReg_GetWindowInfo(hKey, &dwi);
        if(regError == ERROR_SUCCESS) 
		{
            if(dwi.dwNumMemWindows  == 1) 
			{
				pHWHead->dwInterfaceType = dwi.dwInterfaceType;
				pHWHead->dwBusNumber = dwi.dwBusNumber;
                pHWHead->dwMemBase = dwi.memWindows[0].dwBase;
                pHWHead->dwMemLen = dwi.memWindows[0].dwLen;
            }
			else 
			{
                regError = ERROR_FILE_NOT_FOUND;
            }
        }
    }

	
    // get device register stride.
	if ( regError == ERROR_SUCCESS ) 
	{
        dwDataSize = PC_REG_REGSTRIDE_VAL_LEN;
        RegQueryValueEx(hKey, 
                PC_REG_REGSTRIDE_VAL_NAME, 
                NULL, 
                NULL,
                (LPBYTE)(&dwRegStride), 
                &dwDataSize);
		
		DEBUGMSG(ZONE_INIT,
                 (TEXT("dwRegStride -  FOR debugging/understanding  0x%X\r\n"),
                  dwRegStride));        
    }
	
    RegCloseKey (hKey);

    if ( regError != ERROR_SUCCESS ) 
	{
        DEBUGMSG(ZONE_INIT | ZONE_ERROR,
                 (TEXT("Failed to get XR PCI registry values, Error 0x%X\r\n"),
                  regError));
        return ( FALSE );
    }

    DEBUGMSG (ZONE_INIT,
              (TEXT("XRPCI_GetRegistryData - Devindex %d, SysIntr %d, MemB %X, MemLen %X \r\n"),
               pHWHead->dwDevIndex, pHWHead->dwSysIntr, pHWHead->dwMemBase, pHWHead->dwMemLen));

	return ( TRUE ); 
}

⌨️ 快捷键说明

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