windows wdf 驱动开发总结(1)--usb驱动

2024-01-13 02:08

本文主要是介绍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(
  __out  PWDF_IO_QUEUE_CONFIG Config,
  __in   WDF_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 {

  ULONG                                          Size;

  WDF_IO_QUEUE_DISPATCH_TYPE                   DispatchType;

  WDF_TRI_STATE                                 PowerManaged;

  BOOLEAN                                        AllowZeroLengthRequests;

  BOOLEAN                                        DefaultQueue;

  PFN_WDF_IO_QUEUE_IO_DEFAULT                 EvtIoDefault;

  PFN_WDF_IO_QUEUE_IO_READ                    EvtIoRead;

  PFN_WDF_IO_QUEUE_IO_WRITE                   EvtIoWrite;

  PFN_WDF_IO_QUEUE_IO_DEVICE_CONTROL         EvtIoDeviceControl;

  PFN_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL EvtIoInternalDeviceControl;

  PFN_WDF_IO_QUEUE_IO_STOP                    EvtIoStop;

  PFN_WDF_IO_QUEUE_IO_RESUME                  EvtIoResume;

  PFN_WDF_IO_QUEUE_IO_CANCELED_ON_QUEUE     EvtIoCanceledOnQueue;

  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 {

  ULONG                          Size;

  PFN_WDF_OBJECT_CONTEXT_CLEANUP EvtCleanupCallback;

  PFN_WDF_OBJECT_CONTEXT_DESTROY EvtDestroyCallback;

  WDF_EXECUTION_LEVEL            ExecutionLevel;

  WDF_SYNCHRONIZATION_SCOPE      SynchronizationScope;

  WDFOBJECT                      ParentObject;

  size_t                         ContextSizeOverride;

  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 WdfIoQueueCreate creates 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.

Copy Code  调用例子

NTSTATUS  status;

 

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请求,做相应处理

NTSTATUS
  
WdfIoQueueRetrieveNextRequest(
    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

函数功能:关闭定时器

BOOLEAN
  
WdfTimerStop(
    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 .

这篇关于windows wdf 驱动开发总结(1)--usb驱动的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/599899

相关文章

如何在Ubuntu上安装NVIDIA显卡驱动? Ubuntu安装英伟达显卡驱动教程

《如何在Ubuntu上安装NVIDIA显卡驱动?Ubuntu安装英伟达显卡驱动教程》Windows系统不同,Linux系统通常不会自动安装专有显卡驱动,今天我们就来看看Ubuntu系统安装英伟达显卡... 对于使用NVIDIA显卡的Ubuntu用户来说,正确安装显卡驱动是获得最佳图形性能的关键。与Windo

一文教你如何解决Python开发总是import出错的问题

《一文教你如何解决Python开发总是import出错的问题》经常朋友碰到Python开发的过程中import包报错的问题,所以本文将和大家介绍一下可编辑安装(EditableInstall)模式,可... 目录摘要1. 可编辑安装(Editable Install)模式到底在解决什么问题?2. 原理3.

Linux区分SSD和机械硬盘的方法总结

《Linux区分SSD和机械硬盘的方法总结》在Linux系统管理中,了解存储设备的类型和特性是至关重要的,不同的存储介质(如固态硬盘SSD和机械硬盘HDD)在性能、可靠性和适用场景上有着显著差异,本文... 目录一、lsblk 命令简介基本用法二、识别磁盘类型的关键参数:ROTA查询 ROTA 参数ROTA

Python+Tkinter实现Windows Hosts文件编辑管理工具

《Python+Tkinter实现WindowsHosts文件编辑管理工具》在日常开发和网络调试或科学上网场景中,Hosts文件修改是每个开发者都绕不开的必修课,本文将完整解析一个基于Python... 目录一、前言:为什么我们需要专业的Hosts管理工具二、工具核心功能全景图2.1 基础功能模块2.2 进

Python+PyQt5开发一个Windows电脑启动项管理神器

《Python+PyQt5开发一个Windows电脑启动项管理神器》:本文主要介绍如何使用PyQt5开发一款颜值与功能并存的Windows启动项管理工具,不仅能查看/删除现有启动项,还能智能添加新... 目录开篇:为什么我们需要启动项管理工具功能全景图核心技术解析1. Windows注册表操作2. 启动文件

嵌入式Linux之使用设备树驱动GPIO的实现方式

《嵌入式Linux之使用设备树驱动GPIO的实现方式》:本文主要介绍嵌入式Linux之使用设备树驱动GPIO的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、设备树配置1.1 添加 pinctrl 节点1.2 添加 LED 设备节点二、编写驱动程序2.1

嵌入式Linux驱动中的异步通知机制详解

《嵌入式Linux驱动中的异步通知机制详解》:本文主要介绍嵌入式Linux驱动中的异步通知机制,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录前言一、异步通知的核心概念1. 什么是异步通知2. 异步通知的关键组件二、异步通知的实现原理三、代码示例分析1. 设备结构

使用Python开发Markdown兼容公式格式转换工具

《使用Python开发Markdown兼容公式格式转换工具》在技术写作中我们经常遇到公式格式问题,例如MathML无法显示,LaTeX格式错乱等,所以本文我们将使用Python开发Markdown兼容... 目录一、工具背景二、环境配置(Windows 10/11)1. 创建conda环境2. 获取XSLT

使用Python创建一个功能完整的Windows风格计算器程序

《使用Python创建一个功能完整的Windows风格计算器程序》:本文主要介绍如何使用Python和Tkinter创建一个功能完整的Windows风格计算器程序,包括基本运算、高级科学计算(如三... 目录python实现Windows系统计算器程序(含高级功能)1. 使用Tkinter实现基础计算器2.

Android开发环境配置避坑指南

《Android开发环境配置避坑指南》本文主要介绍了Android开发环境配置过程中遇到的问题及解决方案,包括VPN注意事项、工具版本统一、Gerrit邮箱配置、Git拉取和提交代码、MergevsR... 目录网络环境:VPN 注意事项工具版本统一:android Studio & JDKGerrit的邮