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

相关文章

关于C++中的虚拟继承的一些总结(虚拟继承,覆盖,派生,隐藏)

1.为什么要引入虚拟继承 虚拟继承是多重继承中特有的概念。虚拟基类是为解决多重继承而出现的。如:类D继承自类B1、B2,而类B1、B2都继承自类A,因此在类D中两次出现类A中的变量和函数。为了节省内存空间,可以将B1、B2对A的继承定义为虚拟继承,而A就成了虚拟基类。实现的代码如下: class A class B1:public virtual A; class B2:pu

十五.各设计模式总结与对比

1.各设计模式总结与对比 1.1.课程目标 1、 简要分析GoF 23种设计模式和设计原则,做整体认知。 2、 剖析Spirng的编程思想,启发思维,为之后深入学习Spring做铺垫。 3、 了解各设计模式之间的关联,解决设计模式混淆的问题。 1.2.内容定位 1、 掌握设计模式的"道" ,而不只是"术" 2、 道可道非常道,滴水石穿非一日之功,做好长期修炼的准备。 3、 不要为了

问题-windows-VPN不正确关闭导致网页打不开

为什么会发生这类事情呢? 主要原因是关机之前vpn没有关掉导致的。 至于为什么没关掉vpn会导致网页打不开,我猜测是因为vpn建立的链接没被更改。 正确关掉vpn的时候,会把ip链接断掉,如果你不正确关掉,ip链接没有断掉,此时你vpn又是没启动的,没有域名解析,所以就打不开网站。 你可以在打不开网页的时候,把vpn打开,你会发现网络又可以登录了。 方法一 注意:方法一虽然方便,但是可能会有

Windows/macOS/Linux 安装 Redis 和 Redis Desktop Manager 可视化工具

本文所有安装都在macOS High Sierra 10.13.4进行,Windows安装相对容易些,Linux安装与macOS类似,文中会做区分讲解 1. Redis安装 1.下载Redis https://redis.io/download 把下载的源码更名为redis-4.0.9-source,我喜欢跟maven、Tomcat放在一起,就放到/Users/zhan/Documents

Eclipse+ADT与Android Studio开发的区别

下文的EA指Eclipse+ADT,AS就是指Android Studio。 就编写界面布局来说AS可以边开发边预览(所见即所得,以及多个屏幕预览),这个优势比较大。AS运行时占的内存比EA的要小。AS创建项目时要创建gradle项目框架,so,创建项目时AS比较慢。android studio基于gradle构建项目,你无法同时集中管理和维护多个项目的源码,而eclipse ADT可以同时打开

人工智能机器学习算法总结神经网络算法(前向及反向传播)

1.定义,意义和优缺点 定义: 神经网络算法是一种模仿人类大脑神经元之间连接方式的机器学习算法。通过多层神经元的组合和激活函数的非线性转换,神经网络能够学习数据的特征和模式,实现对复杂数据的建模和预测。(我们可以借助人类的神经元模型来更好的帮助我们理解该算法的本质,不过这里需要说明的是,虽然名字是神经网络,并且结构等等也是借鉴了神经网络,但其原型以及算法本质上还和生物层面的神经网络运行原理存在

Java注解详细总结

什么是注解?         Java注解是代码中的特殊标记,比如@Override、@Test等,作用是:让其他程序根据注解信息决定怎么执行该程序。         注解不光可以用在方法上,还可以用在类上、变量上、构造器上等位置。 自定义注解  现在我们自定义一个MyTest注解 public @interface MyTest{String aaa();boolean bbb()

Python应用开发——30天学习Streamlit Python包进行APP的构建(9)

st.area_chart 显示区域图。 这是围绕 st.altair_chart 的语法糖。主要区别在于该命令使用数据自身的列和指数来计算图表的 Altair 规格。因此,在许多 "只需绘制此图 "的情况下,该命令更易于使用,但可定制性较差。 如果 st.area_chart 无法正确猜测数据规格,请尝试使用 st.altair_chart 指定所需的图表。 Function signa

Windows中,.net framework 3.5安装

安装.net framework,目前已知2种方法,如下: 一、在MSDN下载对应的安装包,安装,这种可能无法安装成功,概率很大,不成功使用第二种方法,基本上没问题。 二、win8/8.1/10 下安装 .net framework 3.5.1: 1. 打开 win8/8.1/10 安装盘(这里指系统安装镜像文件),提取 sources\sxs 文件夹到 X:\sources\sxs (X代

Windows 可变刷新率是什么?如何开启?

在现代计算设备中,显示屏的刷新率对用户体验起着至关重要的作用。随着显示技术的不断进步,固定刷新率显示器逐渐被支持可变刷新率(Variable Refresh Rate, VRR)技术的显示器所取代。 可变刷新率定义 可变刷新率是什么?可变刷新率(VRR)是一种显示技术,它允许显示器的刷新率动态调整,以匹配显卡输出的帧率。传统的显示器通常具有固定的刷新率(如60Hz、75Hz等),这意味着显示器