驱动程序(7) WDF下DMA传输的驱动程序代码详细说明之应用程序

本文详细阐述了如何在Windows驱动程序框架(WDF)下编写应用程序,与驱动程序进行通信,包括识别并打开驱动,以及通过DeviceIoControl函数实现数据的传输与接收。首先介绍了如何手动创建应用程序项目,并确保其与驱动程序项目相关联。接着,重点解析GetDevicePath函数的使用,该函数用于查找指定PCIe设备的路径,以便后续打开驱动设备。DeviceIoControl函数则用于实际的设备控制操作,传递数据并接收驱动程序的返回数据。
摘要由CSDN通过智能技术生成

这一篇主要说明应用程序怎么去和驱动程序通信的,包括识别打开驱动程序,传递数据到驱动程序,同时接收驱动程序返回的数据。

application.c

  1. 首先是应用程序的创建,WDF里利用模板生成驱动程序时时不带有应用程序的源文件的,需要我们自己手动生成,其实就是和创建一个C语言文件一样。找到驱动程序的解决方案,右键选择‘添加’->‘新建项目’->‘测试’->‘Applications’,选择第一个就行了,保存时注意存为.c文件,因为整个项目都是C来写的,没有用C++。需要注意的就是这个文件一定要在驱动程序的那个解决方案下才行,然后在该项目的项目依赖项里勾选上你的驱动程序,表示它是依赖于驱动程序才有用的。
    在这里插入图片描述

2.代码

/*++
Module Name: application.c
Abstract:This file contains application which communicates with driversoft, including main and GetDevicePath function.
Environment: User-mode Driver Framework
Time: 20181015
--*/

#include <windows.h>
#include <winioctl.h>
#include <setupapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

#include "tchar.h"
#include "../PCIe/Public.h"


HANDLE hDevice = INVALID_HANDLE_VALUE;
PCHAR GetDevicePath(IN LPGUID InterfaceGuid);

int _tmain(int argc, _TCHAR* argv[])
{
   
	PCHAR DevicePath;
	ULONG nOutput;
	//LPDWORD count = 0;
	UNREFERENCED_PARAMETER(argc);
	UNREFERENCED_PARAMETER(argv);

	printf("Application control test starting...\n");
	//利用GUID号找到设备路径
	DevicePath = GetDevicePath((LPGUID)&GUID_DEVINTERFACE_PCIe);
	if (DevicePath == 0)
	{
   
		printf("ERROR: Get DevicePath failed! ErrNo:%0x\n"
├─reference_design │ ├─vhdl │ │ │ stratix_enh_pll.vhd │ │ │ stratix_top.vhd │ │ │ vhdl_components.vhd │ │ │ │ │ ├─001 ddr_cntrl │ │ │ ddr_top.vhd │ │ │ │ │ ├─004 pci_local │ │ │ backend.vhd │ │ │ cnten.vhd │ │ │ datapath_fifo.vhd │ │ │ dma.vhd │ │ │ dma_reg.vhd │ │ │ dma_sm.vhd │ │ │ fifo_128x32.vhd │ │ │ fifo_128x4.vhd │ │ │ fifo_128x64.vhd │ │ │ last_gen.vhd │ │ │ mstr_cntrl.vhd │ │ │ mstr_fifo_cntrl.vhd │ │ │ mstr_perf.vhd │ │ │ targ_cntrl.vhd │ │ │ targ_fifo_cntrl.vhd │ │ │ targ_perf.vhd │ │ │ │ │ ├─002 ddr_intf │ │ │ adr_gen.vhd │ │ │ clk_sync.vhd │ │ │ cntrl_intf.vhd │ │ │ ddr_intf.vhd │ │ │ mr_sm.vhd │ │ │ mw_sm.vhd │ │ │ tr_sm.vhd │ │ │ tw_sm.vhd │ │ │ │ │ ├─003 flash_cntrl │ │ │ erase_sm.vhd │ │ │ flash_mem_cntrl.vhd │ │ │ read_sm.vhd │ │ │ write_sm.vhd │ │ │ │ │ └─005 pci_mt64 │ │ pci_top.vhd │ │ │ ├─001 sim │ │ │ modelsim.ini │ │ │ sim.do │ │ │ stratix_pci2ddr.mpf │ │ │ stratix_pci2ddr_tb.vhd │ │ │ trgt_tranx_mem_init.dat │ │ │ wave_stratix_pciddr.do │ │ │ │ │ ├─001 altera_lib │ │ │ altera_mf.vhd │ │ │ │ │ ├─002 ddr_dimm │ │ │ ddr_dimm_model.vhd │ │ │ mt46v32m8.vhd │ │ │ │ │ └─003 pci_bfm │ │ arbiter.vhd │ │ clk_gen.vhd │ │ log.vhd │ │ monitor.vhd │ │ mstr_pkg.vhd │ │ mstr_tranx.vhd │ │ pull_up.vhd │ │ trgt_tranx.vhd │ │ │ └─002 syn_1s25 │ stratix_top.csf │ stratix_top.esf │ stratix_top.psf │ stratix_top.quartus │ stratix_top.rbf │ stratix_top.sof │ ├─001 bin │ altera.inf │ megaicon.ico │ StratixPCI.exe │ STRATIX_KIT_APP_HELP.HLP │ wdreg.exe │ windrvr6.inf │ windrvr6.sys │ ├─002 constraints │ mt32_23_ep1s25f1020c5_66_03_04.tcl │ mt64_23_ep1s25f1020c5_66_03_04.tcl │ Stratix_PCI_Board_DDR_settings.tcl │ t32_23_ep1s25f1020c5_66_03_04.tcl │ ├─003 doc │ an223.pdf │ banner.jpg │ ds_StratixPciBd.pdf │ readmeStratixPciKit.htm │ StratixPciKitDocContents.pdf │ ug_StratixPciKit.pdf │ ├─004 max_config │ max_stratix_config.pof │ └─006 software ├─001 driver │ altera_lib.c │ altera_lib.h │ └─002 gui altera.aps altera.clw altera.cpp altera.dsp altera.dsw altera.h altera.ncb altera.odl altera.opt altera.plg altera.rc Altera.rgs alteraDlg.cpp alteraDlg.h alteralogo.bmp CBox.cpp CBox.h Ioctl.h megaicon.ico Meter.cpp Meter.h MonWnd.cpp MonWnd.h resource.h resource.hm StdAfx.cpp StdAfx.h
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值