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

📄 pci9054device.cpp

📁 利用DriverWorks实现PCI9054IO读写操作。包括如何使用DW开发向导生成程序框架
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//		None
//
//	Comments:
//		This routine implements the PCI9054_IOCTL_800_ReadBase0 function.
//		This function was queued through StartIo, so this
//		handler is serialized with other StartIo requests.
//		This routine runs at dispatch level.
//

VOID PCI9054Device::Serial_PCI9054_IOCTL_800_ReadBase0_Handler(KIrp I)
{
	NTSTATUS status = STATUS_SUCCESS;

	t << "Entering PCI9054Device::Serial_PCI9054_IOCTL_800_ReadBase0_Handler, " << I << EOL;
// TODO:	Verify that the input parameters are correct
//			If not, return STATUS_INVALID_PARAMETER

// TODO:	Handle the the PCI9054_IOCTL_800_ReadBase0 request, or setup for further processing.

// TODO:	Assuming that the request was handled in this routine, set
//			I.Information to indicate how much data to copy back to the user,
//			and set I.Status to indicate the outcome of the IRP.  Then
//			complete this IRP and start the next IRP on the queue.
	KMemory Mem(I.Mdl());     
	// Use the memory object to create a pointer to the caller's buffer
	PULONG	pOutBuffer		= (PULONG) Mem.MapToSystemSpace();  //输出缓冲区

	ULONG   Offset=0x10;
	ULONG   count=1;
    
	m_MemoryRange0_ForBase0.ind(Offset,pOutBuffer,count);

	I.Information() = count;
	I.Status() = status;
// TODO:	The Wizard creates a single queue for all Irps.
//			If you have created additional queues, select
//			the appropriate queue for this Irp here.
	m_DriverManagedQueue.PnpNextIrp(I);
}

////////////////////////////////////////////////////////////////////////
//  PCI9054Device::Serial_PCI9054_IOCTL_801_WriteBase0_Handler
//
//	Routine Description:
//		Handler for IO Control Code PCI9054_IOCTL_801_WriteBase0
//
//	Parameters:
//		I - IRP containing IOCTL request
//
//	Return Value:
//		None
//
//	Comments:
//		This routine implements the PCI9054_IOCTL_801_WriteBase0 function.
//		This function was queued through StartIo, so this
//		handler is serialized with other StartIo requests.
//		This routine runs at dispatch level.
//

VOID PCI9054Device::Serial_PCI9054_IOCTL_801_WriteBase0_Handler(KIrp I)
{
	NTSTATUS status = STATUS_SUCCESS;

	t << "Entering PCI9054Device::Serial_PCI9054_IOCTL_801_WriteBase0_Handler, " << I << EOL;
// TODO:	Verify that the input parameters are correct
//			If not, return STATUS_INVALID_PARAMETER

// TODO:	Handle the the PCI9054_IOCTL_801_WriteBase0 request, or setup for further processing.

// TODO:	Assuming that the request was handled in this routine, set
//			I.Information to indicate how much data to copy back to the user,
//			and set I.Status to indicate the outcome of the IRP.  Then
//			complete this IRP and start the next IRP on the queue.
	PULONG  pInBuffer       = (PULONG) I.IoctlBuffer();     //输入缓冲区
   
	m_MemoryRange0_ForBase0.outd(0x10,pInBuffer,1);
	I.Information() = 1;
	I.Status() = status;
// TODO:	The Wizard creates a single queue for all Irps.
//			If you have created additional queues, select
//			the appropriate queue for this Irp here.
	m_DriverManagedQueue.PnpNextIrp(I);
}

////////////////////////////////////////////////////////////////////////
//  PCI9054Device::Serial_PCI9054_IOCTL_802_ReadBase2_Handler
//
//	Routine Description:
//		Handler for IO Control Code PCI9054_IOCTL_802_ReadBase2
//
//	Parameters:
//		I - IRP containing IOCTL request
//
//	Return Value:
//		None
//
//	Comments:
//		This routine implements the PCI9054_IOCTL_802_ReadBase2 function.
//		This function was queued through StartIo, so this
//		handler is serialized with other StartIo requests.
//		This routine runs at dispatch level.
//

VOID PCI9054Device::Serial_PCI9054_IOCTL_802_ReadBase2_Handler(KIrp I)
{
	NTSTATUS status = STATUS_SUCCESS;

	t << "Entering PCI9054Device::Serial_PCI9054_IOCTL_802_ReadBase2_Handler, " << I << EOL;

	KMemory Mem(I.Mdl());     
	// Use the memory object to create a pointer to the caller's buffer
	PUSHORT	pOutBuffer	= (PUSHORT) Mem.MapToSystemSpace();  //输出缓冲区指针,传出读取的数据
 
	PUSHORT  pInBuffer  = (PUSHORT) I.IoctlBuffer();    //输入缓冲区,传来应用程序的一些参数
	                                                    //以便通过应用程序指定读取的位置和数据个数

	USHORT   Offset;    //从应用程序中获取传来的读取的偏移地址
	Offset   = *pInBuffer;

	USHORT   count;     //从应用程序中获取传来的读取的数据个数
	count    = *(pInBuffer+1);

	m_MemoryRange1_ForBase2.inw(Offset,pOutBuffer,count);

	I.Information() = count*sizeof(USHORT);  //字节数
	I.Status() = status;
// TODO:	The Wizard creates a single queue for all Irps.
//			If you have created additional queues, select
//			the appropriate queue for this Irp here.
	m_DriverManagedQueue.PnpNextIrp(I);
}

////////////////////////////////////////////////////////////////////////
//  PCI9054Device::Serial_PCI9054_IOCTL_803_WriteBase2_Handler
//
//	Routine Description:
//		Handler for IO Control Code PCI9054_IOCTL_803_WriteBase2
//
//	Parameters:
//		I - IRP containing IOCTL request
//
//	Return Value:
//		None
//
//	Comments:
//		This routine implements the PCI9054_IOCTL_803_WriteBase2 function.
//		This function was queued through StartIo, so this
//		handler is serialized with other StartIo requests.
//		This routine runs at dispatch level.
//

VOID PCI9054Device::Serial_PCI9054_IOCTL_803_WriteBase2_Handler(KIrp I)
{
	NTSTATUS status = STATUS_SUCCESS;

	t << "Entering PCI9054Device::Serial_PCI9054_IOCTL_803_WriteBase2_Handler, " << I << EOL;

	PUSHORT  pInBuffer  = (PUSHORT) I.IoctlBuffer(); //输入缓冲区,应用程序通过它来指定写入的参数
	                                                 //参数包括要写入的数据个数和偏移地址
	                                                 //I.IoctlBuffer()对应着应用程序传过来的一个数组
	                                                 //该数组结构是:第一个元素是写入的数据的起始偏移地址
	                                                 //第二个元素是共写入的数据个数
	                                                 //第三个元素及其其它元素,为写入的数据
		
	//从输入缓冲区获得的要写入的数据的偏移地址
	USHORT   offset;     
	offset=*pInBuffer;	
	
	//从输入缓冲区获得的要写入的数据个数
	USHORT   count;       
	count=*(pInBuffer+1);

	//指向要写入的数据,该数据为传入的数组的第三个元素及其之后的元素
	PUSHORT  pBuffer  = pInBuffer+2;       

	m_MemoryRange1_ForBase2.outw(offset,pBuffer,count);

	I.Information() = count*sizeof(USHORT);  //字节数
	I.Status() = status;
// TODO:	The Wizard creates a single queue for all Irps.
//			If you have created additional queues, select
//			the appropriate queue for this Irp here.
	m_DriverManagedQueue.PnpNextIrp(I);
}

////////////////////////////////////////////////////////////////////////
//  PCI9054Device::Serial_PCI9054_IOCTL_804_ReadBase3_Handler
//
//	Routine Description:
//		Handler for IO Control Code PCI9054_IOCTL_804_ReadBase3
//
//	Parameters:
//		I - IRP containing IOCTL request
//
//	Return Value:
//		None
//
//	Comments:
//		This routine implements the PCI9054_IOCTL_804_ReadBase3 function.
//		This function was queued through StartIo, so this
//		handler is serialized with other StartIo requests.
//		This routine runs at dispatch level.
//

VOID PCI9054Device::Serial_PCI9054_IOCTL_804_ReadBase3_Handler(KIrp I)
{
	NTSTATUS status = STATUS_SUCCESS;

	t << "Entering PCI9054Device::Serial_PCI9054_IOCTL_804_ReadBase3_Handler, " << I << EOL;

	KMemory Mem(I.Mdl());     
	// Use the memory object to create a pointer to the caller's buffer
	PULONG	pOutBuffer	= (PULONG) Mem.MapToSystemSpace();  //输出缓冲区指针,传出读取的数据
 
	PULONG  pInBuffer       = (PULONG) I.IoctlBuffer();     //输入缓冲区指针

	ULONG   Offset;                     //读取的偏移地址
	Offset   = *pInBuffer;

	ULONG   count;                      //读取的数据个数
	count    = *(pInBuffer+1);

	m_IoPortRange1_ForBase3.ind(Offset,pOutBuffer,count);

	I.Information() = count;
	I.Status() = status;
// TODO:	The Wizard creates a single queue for all Irps.
//			If you have created additional queues, select
//			the appropriate queue for this Irp here.
	m_DriverManagedQueue.PnpNextIrp(I);
}

////////////////////////////////////////////////////////////////////////
//  PCI9054Device::Serial_PCI9054_IOCTL_805_WriteBase3_Handler
//
//	Routine Description:
//		Handler for IO Control Code PCI9054_IOCTL_805_WriteBase3
//
//	Parameters:
//		I - IRP containing IOCTL request
//
//	Return Value:
//		None
//
//	Comments:
//		This routine implements the PCI9054_IOCTL_805_WriteBase3 function.
//		This function was queued through StartIo, so this
//		handler is serialized with other StartIo requests.
//		This routine runs at dispatch level.
//

VOID PCI9054Device::Serial_PCI9054_IOCTL_805_WriteBase3_Handler(KIrp I)
{
	NTSTATUS status = STATUS_SUCCESS;

	t << "Entering PCI9054Device::Serial_PCI9054_IOCTL_805_WriteBase3_Handler, " << I << EOL;

	PULONG  pInBuffer  = (PULONG) I.IoctlBuffer(); //输入缓冲区指针
	
	ULONG   count;                        //从输入缓冲区要写入的数据个数
	count=*(pInBuffer+1);

	ULONG   offset;                       //偏移地址
	offset=*pInBuffer;

	PULONG  pBuffer  = pInBuffer+2;       //指向要写入的数据
/*
	for(ULONG i=0;i<count;i++)
	{
		m_MemoryRange1_ForBase2.outd(0x00+i*4,pInBuffer+i,1);
		for(ULONG j=0;j<100;j++);

	}
*/
	m_IoPortRange1_ForBase3.outd(offset,pBuffer,count);

	I.Information() = count;
	I.Status() = status;
// TODO:	The Wizard creates a single queue for all Irps.
//			If you have created additional queues, select
//			the appropriate queue for this Irp here.
	m_DriverManagedQueue.PnpNextIrp(I);
}

////////////////////////////////////////////////////////////////////////////////
//  PCI9054Device_DriverManagedQueue::StartIo
//	
//	Routine Description:
//		This routine is called when an IRP is taken off
//		the Driver Managed Queue (used for serializing I/O) and
//		presented for processing.
//
//	Parameters:
//		I - IRP removed from queue
//
//	Return Value:
//		None
//
//	Comments:
//

VOID PCI9054Device_DriverManagedQueue::StartIo(KIrp I)
{
	t  << "Entering PCI9054Device_DriverManagedQueue StartIo, " << I;

	// The KDriverManagedQueueEx class gives us the Irp in a non-cancelable state
	// (cancel routine set to NULL) so we can process it without having to worry
	// about clearing the cancel routine first, as is the case with system queuing,
	// or the legacy class KDriverManagedQueue. You may want to set a different cancel
	// routine here, or at other points during the processing of this Irp.

	// Find the device class so we can call the serialized
	// routines in the device class.  The handlers can be
	// moved to the DriverManagedQueue class if it is more
	// convenient.
	PCI9054Device *pDev = (PCI9054Device *) KDevicePTR(I.DeviceObject());

	// Start processing request.

	// Switch on the IRP's function:
	switch (I.MajorFunction())
	{
		case IRP_MJ_DEVICE_CONTROL:
			switch (I.IoctlCode())
			{
				case PCI9054_IOCTL_800_ReadBase0:
					pDev->Serial_PCI9054_IOCTL_800_ReadBase0_Handler(I);
					break;

				case PCI9054_IOCTL_801_WriteBase0:
					pDev->Serial_PCI9054_IOCTL_801_WriteBase0_Handler(I);
					break;

				case PCI9054_IOCTL_802_ReadBase2:
					pDev->Serial_PCI9054_IOCTL_802_ReadBase2_Handler(I);
					break;

				case PCI9054_IOCTL_803_WriteBase2:
					pDev->Serial_PCI9054_IOCTL_803_WriteBase2_Handler(I);
					break;

				case PCI9054_IOCTL_804_ReadBase3:
					pDev->Serial_PCI9054_IOCTL_804_ReadBase3_Handler(I);
					break;

				case PCI9054_IOCTL_805_WriteBase3:
					pDev->Serial_PCI9054_IOCTL_805_WriteBase3_Handler(I);
					break;

				default:
					// We queued a request that shouldn't have been queued
					// (should never get here)
					ASSERT(FALSE);
					break;
			}
			break;

		default:
			// Error - unexpected IRP received
			// NextIrp completes this IRP and starts processing
			// for the next IRP in the queue.
			ASSERT(FALSE);
			I.Status() = STATUS_INVALID_PARAMETER;
			PnpNextIrp(I);
			break;
	}
}


⌨️ 快捷键说明

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