1. 程式人生 > >windows wdf 驅動開發總結(1)--usb驅動

windows wdf 驅動開發總結(1)--usb驅動

()EZ-USB-Fx2 USB驅動相關

(1)WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE

功能:初始化驅動的WDF_IO_QUEUE_CONFIG結構

VOID WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(
__outPWDF_IO_QUEUE_CONFIG Config,
__inWDF_IO_QUEUE_DISPATCH_TYPE DispatchType
);

Parameters

Config [out]

A pointer to the driver's WDF_IO_QUEUE_CONFIG structure.

DispatchType [in]

A WDF_IO_QUEUE_DISPATCH_TYPE enumerator that identifies the request dispatching type for the queue.

typedef enum _WDF_IO_QUEUE_DISPATCH_TYPE {

WdfIoQueueDispatchInvalid= 0,

WdfIoQueueDispatchSequential= 1,

WdfIoQueueDispatchParallel= 2,

WdfIoQueueDispatchManual= 3,

WdfIoQueueDispatchMax= 4

} WDF_IO_QUEUE_DISPATCH_TYPE;

typedef struct _WDF_IO_QUEUE_CONFIG {

ULONGSize;

WDF_IO_QUEUE_DISPATCH_TYPEDispatchType;

WDF_TRI_STATE PowerManaged;

BOOLEANAllowZeroLengthRequests;

BOOLEANDefaultQueue;

PFN_WDF_IO_QUEUE_IO_DEFAULTEvtIoDefault;

PFN_WDF_IO_QUEUE_IO_READEvtIoRead;

PFN_WDF_IO_QUEUE_IO_WRITEEvtIoWrite;

PFN_WDF_IO_QUEUE_IO_DEVICE_CONTROLEvtIoDeviceControl;

PFN_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL EvtIoInternalDeviceControl;

PFN_WDF_IO_QUEUE_IO_STOPEvtIoStop;

PFN_WDF_IO_QUEUE_IO_RESUMEEvtIoResume;

PFN_WDF_IO_QUEUE_IO_CANCELED_ON_QUEUEEvtIoCanceledOnQueue;

union {

struct {

ULONG NumberOfPresentedRequests;

} Parallel;

} Settings;

} WDF_IO_QUEUE_CONFIG, *PWDF_IO_QUEUE_CONFIG;

(2) WdfDeviceCreate

函式功能:建立一個裝置物件框架(creates a framework device object)

NTSTATUS WdfDeviceCreate(

[in, out]PWDFDEVICE_INIT *DeviceInit,

[in, optional]PWDF_OBJECT_ATTRIBUTES DeviceAttributes,

[out] WDFDEVICE *Device

);

引數:

DeviceInit [in, out]

The address of a pointer to a WDFDEVICE_INIT structure. If WdfDeviceCreate encounters no errors, it sets the pointer to NULL.

DeviceAttributes [in, optional]

A pointer to a caller-allocated WDF_OBJECT_ATTRIBUTES structure that contains attributes for the new object. (The structure's ParentObject member must be NULL.) This parameter is optional and can be WDF_NO_OBJECT_ATTRIBUTES.

Device [out]

A pointer to a location that receives a handle to the new framework device object.

(3) WdfDriverCreate

函式功能:為了呼叫驅動,建立驅動物件

NTSTATUS WdfDriverCreate(

[in]PDRIVER_OBJECT DriverObject,

[in]PCUNICODE_STRING RegistryPath,

[in, optional]PWDF_OBJECT_ATTRIBUTES DriverAttributes,

[in]PWDF_DRIVER_CONFIG DriverConfig,

[out, optional]WDFDRIVER *Driver

);

DriverObject [in]

A pointer to a DRIVER_OBJECT structure that represents a Windows Driver Model (WDM) driver object. The driver receives this pointer as input to its DriverEntry routine.

RegistryPath [in]

A pointer to a UNICODE_STRING structure that contains the registry path string that the driver received as input to its DriverEntry routine.

DriverAttributes [in, optional]

A pointer to a caller-allocated WDF_OBJECT_ATTRIBUTES structure. (The structure's ParentObject member must be NULL.) This parameter is optional and can be WDF_NO_OBJECT_ATTRIBUTES.

DriverConfig [in]

A pointer to a caller-allocated WDF_DRIVER_CONFIG structure.

Driver [out, optional]

A pointer to a location that receives a handle to the new framework driver object. This parameter is optional and can be WDF_NO_HANDLE.

typedef struct _WDF_OBJECT_ATTRIBUTES {

ULONGSize;

PFN_WDF_OBJECT_CONTEXT_CLEANUP EvtCleanupCallback;

PFN_WDF_OBJECT_CONTEXT_DESTROY EvtDestroyCallback;

WDF_EXECUTION_LEVELExecutionLevel;

WDF_SYNCHRONIZATION_SCOPESynchronizationScope;

WDFOBJECTParentObject;

size_tContextSizeOverride;

PCWDF_OBJECT_CONTEXT_TYPE_INFO ContextTypeInfo;

} WDF_OBJECT_ATTRIBUTES, *PWDF_OBJECT_ATTRIBUTES;

(4) WdfIoQueueCreate

函式功能:creates and configures an I/O queue for a specified device

NTSTATUS WdfIoQueueCreate(

[in]WDFDEVICE Device,

[in]PWDF_IO_QUEUE_CONFIG Config,

[in, optional]PWDF_OBJECT_ATTRIBUTES QueueAttributes,

[out, optional]WDFQUEUE *Queue

);

Device [in]

A handle to the framework device object that the queue will be associated with.

Config [in]

A pointer to a caller-allocated WDF_IO_QUEUE_CONFIG structure.

QueueAttributes [in, optional]

A pointer to a caller-allocated WDF_OBJECT_ATTRIBUTES structure that specifies object attributes for the new object. This parameter is optional and can be WDF_NO_OBJECT_ATTRIBUTES.

Queue [out, optional]

A pointer to a location that receives a handle to a framework queue object.

評論:

Each call to WdfIoQueueCreatecreates an I/O queue for a device. Your driver can create multiple I/O queues for each device.

The Config and QueueAttributes parameters specify the queue's configuration and object attributes.

(5) WdfDeviceCreateDeviceInterface

函式功能:建立裝置介面creates a device interface for a specified device.

NTSTATUS WdfDeviceCreateDeviceInterface(

[in]WDFDEVICE Device,

[in]const GUID *InterfaceClassGUID,

[in, optional]PCUNICODE_STRING ReferenceString

);

引數:

Device [in]

A handle to a framework device object.

InterfaceClassGUID [in]

A pointer to a GUID that identifies the device interface class.

ReferenceString [in, optional]

A pointer to a UNICODE_STRING structure that describes a reference string for the device interface. This parameter is optional and can be NULL. For more information, see the following Remarks section.

NTSTATUSstatus;

status = WdfDeviceCreateDeviceInterface(

Device,

(LPGUID) &GUID_DEVINTERFACE_COMPORT,

NULL

);

(6) WdfRequestComplete

函式功能:completes a specified I/O request and supplies a completion status.

VOID WdfRequestComplete(

[in]WDFREQUEST Request,

[in]NTSTATUS Status

);

(7) WdfRequestRetrieveInputBuffer

函式功能:retrieves an I/O request's input buffer. 獲取輸入緩衝區的地址

NTSTATUS WdfRequestRetrieveInputBuffer(

[in]WDFREQUEST Request,

[in]size_t MinimumRequiredSize,

[out]PVOID *Buffer,

[out, optional]size_t *Length

);

Request [in]

A handle to a framework request object.

MinimumRequiredSize [in]

The minimum buffer size, in bytes, that the driver needs to process the I/O request.

Buffer [out]

A pointer to a location that receives the buffer's address.

Length [out, optional]

A pointer to a location that receives the buffer's size, in bytes. This parameter is optional and can be NULL.

(8) WdfRequestRetrieveOutputBuffer

函式功能:獲取輸出緩衝區的地址

NTSTATUS WdfRequestRetrieveInputBuffer(

[in]WDFREQUEST Request,

[in]size_t MinimumRequiredSize,

[out]PVOID *Buffer,

[out, optional]size_t *Length

);

(9) WdfRequestCompleteWithInformation

函式功能:stores completion information and then completes a specified I/O request with a supplied completion status.(完成Io請求)

VOID WdfRequestCompleteWithInformation(

[in]WDFREQUEST Request,

[in]NTSTATUS Status,

[in]ULONG_PTR Information

);

queuesample(佇列例子)

(10)GetDeviceContext

//獲取裝置物件環境變數結構地址指標

pDeviceContext = GetDeviceContext(device);

deviceContext = GetDeviceContext(WdfIoQueueGetDevice(Queue));

(11) WdfIoQueueRetrieveNextRequest

函式功能: 從非預設手工佇列中取出I/O請求,做相應處理

NTSTATUSWdfIoQueueRetrieveNextRequest(
    IN WDFQUEUE  Queue,
    OUT WDFREQUEST*  
OutRequest
    );

Queue

A handle to a framework queue object.

OutRequest

A pointer to a location that receives a handle to a framework request object. If the queue is empty or the last request has been retrieved, this parameter receives NULL.

(12) WdfTimerStop

函式功能:關閉定時器

BOOLEANWdfTimerStop(
    IN WDFTIMER  Timer,
    IN BOOLEAN  
Wait
    );

Timer

A handle to a framework timer object that was obtained by calling WdfTimerCreate.

Wait

A Boolean value that, if TRUE, specifies that the framework does not return until all queued calls to the driver's deferred procedure calls (DPCs), including the driver's EvtTimerFunc callback functions, have executed.

WdfTimerStop returns TRUE if the timer object was in the system's timer queue. Otherwise, this method returns FALSE.

(13) WdfRequestForwardToIoQueue

函式功能:requeues an I/O request to one of the calling driver's I/O queues.

NTSTATUS WdfRequestForwardToIoQueue(

[in]WDFREQUEST Request,

[in]WDFQUEUE DestinationQueue

);

Request [in]

A handle to a framework request object.

DestinationQueue [in]

A handle to a framework queue object.

The driver must own the I/O request and must have obtained the request from one of its I/O queues.

The source and destination queues cannot be the same. In other words, the driver cannot call WdfRequestForwardToIoQueue to return a request to the queue that it came from. To requeue a request to the same queue, use WdfRequestRequeue .