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

📄 comeml_drv_if.cpp

📁 The Lite Evaluation/Demonstration Kit is intended to illustrate use of the AN3042. The AN3042 is c
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//////////////////////////////////////////////////////////////////////
//
// File:  ComemL_drv_if.cpp
// $Archive: /ComemL/Host/ComemLif/comemL_drv_if.cpp $
//
// Purpose:
//    Contains lowest level functions used by C and C++ programs to
//    interface to the co-memory driver (.vxd or .sys).
//
// $Author: Tpm $
//
// $History: comemL_drv_if.cpp $
//  
//  *****************  Version 13  *****************
//  User: Tpm          Date: 2/02/99    Time: 6:25p
//  Updated in $/ComemL/Host/ComemLif
//  CoMem Lite Init Dev Kit more cleanup.
//  
//  *****************  Version 12  *****************
//  User: Tpm          Date: 2/01/99    Time: 5:34p
//  Updated in $/ComemL/Host/ComemLif
//  CoMem Lite initial Dev Kit release cleanup.
//  
//  *****************  Version 11  *****************
//  User: Tpm          Date: 11/25/98   Time: 11:53a
//  Updated in $/ComemL/Host/ComemLif
//  Add GetVersion.
//  
//  *****************  Version 10  *****************
//  User: Tpm          Date: 11/12/98   Time: 5:09p
//  Updated in $/ComemL/Host/ComemLif
//  I modified comemCopyBarPtrL() and comemCreateBarPtrL() to get
//  rid of linpage and physpage.
//  
//  *****************  Version 9  *****************
//  User: Tpm          Date: 11/11/98   Time: 5:17p
//  Updated in $/ComemL/Host/ComemLif
//  SHK Review cleanup.
//  
//  *****************  Version 8  *****************
//  User: Tpm          Date: 11/06/98   Time: 4:58p
//  Updated in $/ComemL/Host/ComemLif
//  Creat seperate directory for ComemLite IF Library.
//  
//  *****************  Version 6  *****************
//  User: Tpm          Date: 10/27/98   Time: 12:08p
//  Updated in $/ComemL/Host/ComemLif
//  Clean up Lib.
//  
//  *****************  Version 5  *****************
//  User: Tpm          Date: 10/27/98   Time: 9:53a
//  Updated in $/ComemL/Host/ComemLif
//  Replace comemDev with comemDevL.
//  
//  *****************  Version 4  *****************
//  User: Tpm          Date: 10/23/98   Time: 6:05p
//  Updated in $/ComemL/Host/ComemLif
//  Modified to add IOCTL_COMEM_ALLOCCONTIGMEM.
//  
//  *****************  Version 3  *****************
//  User: Tpm          Date: 10/21/98   Time: 6:56p
//  Updated in $/ComemL/Host/ComemLif
//  Seperate ComemL.lib from Comem.lib by using comemOpenDriverL()
//  instead of openComemDriver(), etc.
//  Get rid of intel, srec, binary in/out.
//  
//  *****************  Version 2  *****************
//  User: Tpm          Date: 8/27/98    Time: 9:12a
//  Updated in $/ComemL/Host/ComemLif
//  use ComelL.vxd.
//  
//  *****************  Version 1  *****************
//  User: Tpm          Date: 8/27/98    Time: 9:10a
//  Created in $/ComemL/Host/ComemLif
//  
//  *****************  Version 27  *****************
//  User: Tpm          Date: 1/13/98    Time: 4:49p
//  Updated in $/Comem/Mapper
//  Allocate the comemDevice whether there is a card or not (run with no
//  card)
//  
//  *****************  Version 26  *****************
//  User: Stevek       Date: 12/10/97   Time: 8:18a
//  Updated in $/Comem/Mapper
//  Added copyBarPtr call to the library.
//  
//  *****************  Version 24  *****************
//  User: Stevek       Date: 11/07/97   Time: 11:05a
//  Updated in $/Comem/Mapper
//  Open Driver now allocates the device object
//  
//  *****************  Version 23  *****************
//  User: Stevek       Date: 11/05/97   Time: 11:16p
//  Updated in $/Comem/comem_if
//  Added reference count to permit mapper to check for multiple mappers on
//  a single comem.
//  
//  *****************  Version 22  *****************
//  User: Stevek       Date: 10/28/97   Time: 9:57a
//  Updated in $/Comem/Mapper
//  More seperation for seperate library file.
//  Removed embeddedSystems stuff.
//  
//  *****************  Version 21  *****************
//  User: Stevek       Date: 10/27/97   Time: 1:16p
//  Updated in $/Comem/Mapper
//  Moved interface functions into the comem_if.lib file.
//  
//  *****************  Version 20  *****************
//  User: Stevek       Date: 10/24/97   Time: 3:55p
//  Updated in $/Comem/Mapper
//  Started to seperate library functions out of mapper files.
//  Current code is tested with one comem.
//  
//  *****************  Version 19  *****************
//  User: Stevek       Date: 10/23/97   Time: 11:59a
//  Updated in $/Comem/Mapper
//  Added comemID to closeDriver
//  
//  *****************  Version 18  *****************
//  User: Stevek       Date: 10/23/97   Time: 11:50a
//  Updated in $/Comem/Mapper
//  Naming convention changes, comemID changes for manual
//  
// Copyright (c) 1997 Anchor Chips, Inc.  May not be reproduced without
// permission.  See the license agreement for more details.
//
//////////////////////////////////////////////////////////////////////
#include "windows.h"
#include "winioctl.h"
#include "comemDevice.h"
#include "stdio.h" 
                
static HANDLE	hdevice[COMEM_MAX_DEVICES];    // handle to the vxd.  
	    				    
//////////////////////////////////////////////////////////////////////
//
// DWORD comemOpenDriverL(DWORD comemID)
//
// Input:  
//    Zero based comem ID
//
// Function:  Opens a handle to the co-mem driver.  Assumes that the driver
//     is already loaded.  If the driver is going to be dynamically loaded
//     under win95, use the DynVxdName.
//
// Returns:  
//    NO_ERROR  if no errors were detected.
//    ERROR_NO_DRIVER if the driver could not be found
//
//////////////////////////////////////////////////////////////////////
DWORD comemOpenDriverL(DWORD comemID)
{
   if (comemID > COMEM_MAX_DEVICES)
		return ERROR_INVALID_COMEM_ID;

	OSVERSIONINFO OsVersionInfo;
	LPOSVERSIONINFO lpVersionInformation;
	lpVersionInformation = &OsVersionInfo;
	lpVersionInformation->dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx(lpVersionInformation);
	if(lpVersionInformation->dwPlatformId == VER_PLATFORM_WIN32_NT)
		{
		// These strings are special names that tell the file system that
		// we are loading a device, not a file

		CHAR StaticVxDName[0x100];
		sprintf(StaticVxDName, "\\\\.\\comem-%d", comemID);

		// Attempt to get a handle to the static VxD
		hdevice[comemID] = CreateFile(StaticVxDName, 
							GENERIC_READ | GENERIC_WRITE,
							FILE_SHARE_READ,
							0,
							OPEN_EXISTING,                                          
							NULL,
							0);
		}
	else
		{
		// These strings are special names that tell the file system that
		// we are loading a device, not a file

		const PCHAR StaticVxDName = "\\\\.\\comeml";

		// Attempt to get a handle to the static VxD
		hdevice[comemID] = CreateFile(StaticVxDName, 
							GENERIC_READ | GENERIC_WRITE,
							FILE_SHARE_READ,
							0,
							OPEN_EXISTING,                                          
							NULL,
							0);

		}

	if (hdevice[comemID] != INVALID_HANDLE_VALUE)
		{
		DWORD status = comemGetStatusL(NULL, comemID);
		if (status != NO_ERROR)
			{
			comemCloseDriverL(comemID);
			return(ERROR_INVALID_COMEM_ID);
			}
		}

   // Allocate the comemDevice whether there is a card or not (run with no card)
   comemDevL[comemID] = new CComemDevice(comemID);

   // If we couldn't get a handle for the device, return an error
   if (hdevice[comemID] == INVALID_HANDLE_VALUE)
       return(ERROR_NO_DRIVER);
       
   if (!comemDevL[comemID])
	   return (ERROR_MEMORY_ALLOC);
       
	return NO_ERROR;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// DWORD comemCopyBarPtrL(DWORD linBAR[COMEM_MAX_BARS], DWORD *linPage)                                                                            
//
// Function:  
//          Similar to comemCreateBarPtrL, but copies the BAR pointers that have already been created
//          in the comemDevice class.
//          Can be called any time the driver is open.  Since the BARs are fixed at Windows
//			   initialization time, there is no reason to call this function more than once.
//
// Inputs: 
//      linBAR -- Pointer to array of pointers to fill with the linear BAR pointers.
//
// Returns:	
//       ERROR_NO_DRIVER -- Driver not detected                                                       
// 		ERROR_UNKNOWN -- Other error reported by driver                                                 
// 		NO_ERROR -- No errors                                                                    
/////////////////////////////////////////////////////////////////////////////////////////////////////////
DWORD comemCopyBarPtrL(DWORD linBAR[COMEM_MAX_BARS], DWORD comemID)                                                                            
{
   if (comemID > COMEM_MAX_DEVICES)
		return ERROR_INVALID_COMEM_ID;

   for (int i = 0; i < COMEM_MAX_BARS; i++)
      linBAR[i] = comemDevL[comemID]->linBAR[i];

   return NO_ERROR;
}

//////////////////////////////////////////////////////////////////////
//
// DWORD comemCloseDriverL()
//
// Function:
//    Close our device handle.
//
// Input:
//    DWORD comemID
//
// Ouput:
//    INVALID_HANDLE_VALUE -- Device is not open
//
//////////////////////////////////////////////////////////////////////
DWORD comemCloseDriverL(DWORD comemID)
{
   if (comemID > COMEM_MAX_DEVICES)
		return ERROR_INVALID_COMEM_ID;

	if (hdevice[comemID] != INVALID_HANDLE_VALUE)
		CloseHandle(hdevice[comemID]);
    hdevice[comemID] = INVALID_HANDLE_VALUE;
    
   if (comemDevL[comemID])
      delete comemDevL[comemID];
      
	return NO_ERROR;
}

//////////////////////////////////////////////////////////////////////
// 
// DWORD comemGetStatusL(DWORD comemID)
//
// Function:  
//    Detects the driver
//
// Input:  	
//    refCount -- Pointer to reference count to update
//    comemID
//
// Output:
//    updated refCount value
//    
// Returns: 
// 	ERROR_NO_DRIVER -- No driver detected
// 	ERROR_UNKNOWN -- Driver detected, but there was a driver error
// 
//////////////////////////////////////////////////////////////////////
DWORD comemGetStatusL(DWORD *refCount, DWORD comemID)
{
   if (comemID > COMEM_MAX_DEVICES)
		return ERROR_INVALID_COMEM_ID;

	GetStatusIn in;
	GetStatusOut out;
	DWORD nRet = 0;
	DWORD status;

   in.comemID = comemID;

   if (hdevice[comemID] == INVALID_HANDLE_VALUE)
      return ERROR_NO_DRIVER;

	status =  DeviceIoControl(
				hdevice[comemID], 
				IOCTL_COMEM_GETSTATUS, 
				&in, 
				sizeof(in), 
				&out, 
				sizeof(out), 

⌨️ 快捷键说明

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