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

相关文章

基于 Cursor 开发 Spring Boot 项目详细攻略

《基于Cursor开发SpringBoot项目详细攻略》Cursor是集成GPT4、Claude3.5等LLM的VSCode类AI编程工具,支持SpringBoot项目开发全流程,涵盖环境配... 目录cursor是什么?基于 Cursor 开发 Spring Boot 项目完整指南1. 环境准备2. 创建

Python中logging模块用法示例总结

《Python中logging模块用法示例总结》在Python中logging模块是一个强大的日志记录工具,它允许用户将程序运行期间产生的日志信息输出到控制台或者写入到文件中,:本文主要介绍Pyt... 目录前言一. 基本使用1. 五种日志等级2.  设置报告等级3. 自定义格式4. C语言风格的格式化方法

SpringBoot 多环境开发实战(从配置、管理与控制)

《SpringBoot多环境开发实战(从配置、管理与控制)》本文详解SpringBoot多环境配置,涵盖单文件YAML、多文件模式、MavenProfile分组及激活策略,通过优先级控制灵活切换环境... 目录一、多环境开发基础(单文件 YAML 版)(一)配置原理与优势(二)实操示例二、多环境开发多文件版

使用docker搭建嵌入式Linux开发环境

《使用docker搭建嵌入式Linux开发环境》本文主要介绍了使用docker搭建嵌入式Linux开发环境,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录1、前言2、安装docker3、编写容器管理脚本4、创建容器1、前言在日常开发全志、rk等不同

Spring 依赖注入与循环依赖总结

《Spring依赖注入与循环依赖总结》这篇文章给大家介绍Spring依赖注入与循环依赖总结篇,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. Spring 三级缓存解决循环依赖1. 创建UserService原始对象2. 将原始对象包装成工

Python实战之SEO优化自动化工具开发指南

《Python实战之SEO优化自动化工具开发指南》在数字化营销时代,搜索引擎优化(SEO)已成为网站获取流量的重要手段,本文将带您使用Python开发一套完整的SEO自动化工具,需要的可以了解下... 目录前言项目概述技术栈选择核心模块实现1. 关键词研究模块2. 网站技术seo检测模块3. 内容优化分析模

Java+AI驱动实现PDF文件数据提取与解析

《Java+AI驱动实现PDF文件数据提取与解析》本文将和大家分享一套基于AI的体检报告智能评估方案,详细介绍从PDF上传、内容提取到AI分析、数据存储的全流程自动化实现方法,感兴趣的可以了解下... 目录一、核心流程:从上传到评估的完整链路二、第一步:解析 PDF,提取体检报告内容1. 引入依赖2. 封装

基于Java开发一个极简版敏感词检测工具

《基于Java开发一个极简版敏感词检测工具》这篇文章主要为大家详细介绍了如何基于Java开发一个极简版敏感词检测工具,文中的示例代码简洁易懂,感兴趣的小伙伴可以跟随小编一起学习一下... 目录你是否还在为敏感词检测头疼一、极简版Java敏感词检测工具的3大核心优势1.1 优势1:DFA算法驱动,效率提升10

MySQL中查询和展示LONGBLOB类型数据的技巧总结

《MySQL中查询和展示LONGBLOB类型数据的技巧总结》在MySQL中LONGBLOB是一种二进制大对象(BLOB)数据类型,用于存储大量的二进制数据,:本文主要介绍MySQL中查询和展示LO... 目录前言1. 查询 LONGBLOB 数据的大小2. 查询并展示 LONGBLOB 数据2.1 转换为十

Python开发简易网络服务器的示例详解(新手入门)

《Python开发简易网络服务器的示例详解(新手入门)》网络服务器是互联网基础设施的核心组件,它本质上是一个持续运行的程序,负责监听特定端口,本文将使用Python开发一个简单的网络服务器,感兴趣的小... 目录网络服务器基础概念python内置服务器模块1. HTTP服务器模块2. Socket服务器模块