之前提到根据KMDF模板生成的程序里主要有5个头文件和3个源文件,接下来的几篇文章则会对这些文件详细说明,一个驱动程序是怎样写成的。这一篇主要说明几个头文件。
1. device.h
/*++
Module Name:
device.h
Abstract:
This file contains the device definitions.
Environment:
Kernel-mode Driver Framework
--*/
#include "Public.h"
#define LED_MEMORY_OFFSET 0xC0000000
#define DataTransferedStored_Address 0x100;
#define DataTransfered_Bytes 0x10; //定义一些后续程序需求的参数
typedef struct _INTERRUPT_CONTEXT INTERRUPT_CONTEXT, *PINTERRUPT_CONTEXT;//中断上下文的机构提
typedef struct _DEVICE_CONTEXT DEVICE_CONTEXT, *PDEVICE_CONTEXT;//设备上下文的结构体
struct _INTERRUPT_CONTEXT
{
BOOLEAN State;
PDEVICE_CONTEXT DeviceContext;
};
struct _DEVICE_CONTEXT
{
//设备资源相关参数
ULONG Counter_i;
PVOID MemBaseAddress0; //when i=0, it gets BAR0 start virtual address 内存映射地址
PVOID MemBaseAddress1; //when i=2, it gets BAR1 start virtual address
PVOID MemBaseAddress2; //when i=4, it gets BAR2 start virtual address
PVOID IoBaseAddress; //I/O映射地址
ULONG PhysicalAddressRegister0; //store the BAR0 start physical address
ULONG PhysicalAddressRegister1; //store the BAR1 start physical address
ULONG PhysicalAddressRegister2; //store the BAR2 start physical address
ULONG MemLength0; //映射后BAR的长度
ULONG Me