有兩種方式可以讓設備和應用程序之間聯(lián)系:1. 通過為設備創(chuàng)建的一個符號鏈;2. 通過輸出到一個接口WDM驅(qū)動程序建議使用輸出到一個接口而不推薦使用創(chuàng)建符號鏈的方法。這個接口保證PDO的安全,也保證安全地創(chuàng)建一個惟一的、獨立于語言的訪問設備的方法。一個應用程序使用Win32APIs來調(diào)用設備。在某個Win32 APIs和設備對象的分發(fā)函數(shù)之間存在一個映射關系。獲得對設備對象訪問的第一步就是打開一個設備對象的句柄。 用符號鏈打開一個設備的句柄為了打開一個設備,應用程序需要使用CreateFile。如果該設備有一個符號鏈出口,應用程序可以用下面這個例子的形式打開句柄:hDevice = CreateFile("\\\\.\\OMNIPORT3", GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL ,NULL);文件路徑名的前綴“\\.\”告訴系統(tǒng)本調(diào)用希望打開一個設備。這個設備必須有一個符號鏈,以便應用程序能夠打開它。有關細節(jié)查看有關Kdevice和CreateLink的內(nèi)容。在上述調(diào)用中第一個參數(shù)中前綴后的部分就是這個符號鏈的名字。注意:CreatFile中的第一個參數(shù)不是Windows 98/2000中驅(qū)動程序(.sys文件)的路徑。是到設備對象的符號鏈。如果使用DriverWizard產(chǎn)生驅(qū)動程序,它通常使用類KunitizedName來構(gòu)成設備的符號鏈。這意味著符號鏈名有一個附加的數(shù)字,通常是0。例如:如果鏈接名稱的主干是L“TestDevice”那么在CreateFile中的串就該是“\\\\.\\TestDevice0”。如果應用程序需要被覆蓋的I/O,第六個參數(shù)(Flags)必須或上FILE_FLAG_OVERLAPPED。 使用一個輸出接口打開句柄用這種方式打開一個句柄會稍微麻煩一些。DriverWorks庫提供兩個助手類來使獲得對該接口的訪問容易一些,這兩個類是CDeviceInterface, 和 CdeviceInterfaceClass。CdeviceInterfaceClass類封裝了一個設備信息集,該信息集包含了特殊類中的所有設備接口信息。應用程序能有用CdeviceInterfaceClass類的一個實例來獲得一個或更多的CdeviceInterface類的實例。CdeviceInterface類是一個單一設備接口的抽象。它的成員函數(shù)DevicePath()返回一個路徑名的指針,該指針可以在CreateFile中使用來打開設備。下面用一個小例子來顯示這些類最基本的使用方法:extern GUID TestGuid;HANDLE OpenByInterface( GUID* pClassGuid, DWORD instance, PDWORD pError){ CDeviceInterfaceClass DevClass(pClassGuid, pError); if (*pError != ERROR_SUCCESS) return INVALID_HANDLE_VALUE; CDeviceInterface DevInterface(&DevClass, instance, pError); if (*pError != ERROR_SUCCESS) return INVALID_HANDLE_VALUE; cout << "The device path is " << DevInterface.DevicePath() << endl; HANDLE hDev; hDev = CreateFile( DevInterface.DevicePath(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if (hDev == INVALID_HANDLE_VALUE) *pError = GetLastError(); return hDev;} 在設備中執(zhí)行I/O操作一旦應用程序獲得一個有效的設備句柄,它就能使用Win32 APIs來產(chǎn)生到設備對象的IRPs。下面的表顯示了這種對應關系。Win32 API DRIVER_FUNCTION_xxxIRP_MJ_xxx KDevice subclass member function CreateFile CREATE Create ReadFile READ Read WriteFile WRITE Write DeviceIoControl DEVICE_CONTROL DeviceControl CloseHandle CLOSECLEANUP CloseCleanUp 需要解釋一下設備類成員的Close和CleanUp:CreateFile使內(nèi)核為設備創(chuàng)建一個新的文件對象。這使得多個句柄可以映射同一個文件對象。當這個文件對象的最后一個用戶級句柄被撤銷后,I/O管理器調(diào)用CleanUp。當沒有任何用戶級和核心級的對文件對象的訪問的時候,I/O管理器調(diào)用Close。如果被打開的設備不支持指定的功能,則調(diào)用相應的Win32將引起錯誤(無效功能)。以前為Windows95編寫的VxD的應用程序代碼中可能會在打開設備的時候使用FILE_FLAG_DELETE_ON_CLOSE屬性。在Windows NT/2000中,建議不要使用這個屬性,因為它將導致沒有特權(quán)的用戶企圖打開這個設備,這是不可能成功的。I/O管理器將ReadFile和WriteFile的buff參數(shù)轉(zhuǎn)換成IRP域的方法依賴于設備對象的屬性。當設備設置DO_DIRECT_IO標志,I/O管理器將buff鎖住在存儲器中,并且創(chuàng)建了一個存儲在IRP中的MDL域。一個設備可以通過調(diào)用Kirp::Mdl來存取MDL。當設備設置DO_BUFFERED_IO標志,設備對象分別通過KIrp::BufferedReadDest或 KIrp::BufferedWriteSource為讀或?qū)懖僮鳙@得buff地址。當設備不設置DO_BUFFERED_IO標志也不設置DO_DIRECT_IO,內(nèi)核設置IRP 的UserBuffer域來對應ReadFile或WriteFile中的buff參數(shù)。然而,存儲區(qū)并沒有被鎖住而且地址只對調(diào)用進程有效。驅(qū)動程序可以使用KIrp::UserBuffer來存取IRP域。對于DeviceIoControl調(diào)用,buffer參數(shù)的轉(zhuǎn)換依賴于特殊的I/O控制代碼,它不在設備對象的特性中。宏CTL_CODE(在winioctl.h中定義)用來構(gòu)造控制代碼。這個宏的其中一個參數(shù)指明緩沖方法是METHOD_BUFFERED, METHOD_IN_DIRECT, METHOD_OUT_DIRECT, 或METHOD_NEITHER。下面的表顯示了這些方法和與之對應的能獲得輸入緩沖與輸出緩沖的KIrp中的成員函數(shù):Method Input Buffer Parameter Output Buffer Parameter METHOD_BUFFERED KIrp::IoctlBuffer KIrp::IoctlBuffer METHOD_IN_DIRECT KIrp::IoctlBuffer KIrp::Mdl METHOD_OUT_DIRECT KIrp::IoctlBuffer KIrp::Mdl METHOD_NEITHER KIrp::IoctlType3InputBuffer KIrp::UserBuffer 如果控制代碼指明METHOD_BUFFERED,系統(tǒng)分配一個單一的緩沖來作為輸入與輸出。驅(qū)動程序必須在向輸出緩沖放數(shù)據(jù)之前拷貝輸入數(shù)據(jù)。驅(qū)動程序通過調(diào)用KIrp::IoctlBuffer獲得緩沖地址。在完成時,I/O管理器從系統(tǒng)緩沖拷貝數(shù)據(jù)到提供給Ring 3級調(diào)用者使用的緩沖中。驅(qū)動程序必須在結(jié)束前存儲拷貝到IRP的Information成員中的數(shù)據(jù)個數(shù)。如果控制代碼不指明METHOD_IN_DIRECT或METHOD_OUT_DIRECT,則DeviceIoControl的參數(shù)呈現(xiàn)不同的含義。參數(shù)InputBuffer被拷貝到一個系統(tǒng)緩沖,這個緩沖驅(qū)動程序可以通過調(diào)用KIrp::IoctlBuffer。參數(shù)OutputBuffer被映射到KMemory對象,驅(qū)動程序?qū)@個對象的訪問通過調(diào)用KIrp::Mdl來實現(xiàn)。對于METHOD_OUT_DIRECT,調(diào)用者必須有對緩沖的寫訪問權(quán)限。注意,對METHOD_NEITHER,內(nèi)核只提供虛擬地址;它不會做映射來配置緩沖。虛擬地址只對調(diào)用進程有效。這里是一個用METHOD_BUFFERED的例子:首先,使用宏CTL_CODE來定義一個IOCTL代碼:#define IOCTL_MYDEV_GET_FIRMWARE_REV \CTL_CODE (FILE_DEVICE_UNKNOWN,0,METHOD_BUFFERED,FILE_ANY_ACCESS)現(xiàn)在使用一個DeviceIoControl調(diào)用:BOOLEAN b;CHAR FirmwareRev[60];ULONG FirmwareRevSize;b = DeviceIoControl(hDevice, IOCTL_MYDEV_GET_VERSION_STRING, NULL, // no input 注意,這里放的是包含有執(zhí)行操作命令的字符串指針 0, FirmwareRev, //這里是output串指針,存放從驅(qū)動程序中返回的字符串。sizeof(FirmwareRev),& FirmwareRevSize, NULL // not overlapped I/O );如果輸出緩沖足夠大,設備拷貝串到里面并將拷貝的資結(jié)束設置到FirmwareRevSize中。在驅(qū)動程序中,代碼看起來如下所示:const char* FIRMWARE_REV = "FW 16.33 v5";NTSTATUS MyDevice::DeviceControl( KIrp I ){ ULONG fwLength=0; switch ( I.IoctlCode() ) { case IOCTL_MYDEV_GET_FIRMWARE_REV: fwLength = strlen(FIRMWARE_REV)+1; if (I.IoctlOutputBufferSize() >= fwLength) { strcpy((PCHAR)I.IoctlBuffer(),FIRMWARE_REV); I.Information() = fwLength; return I.Complete(STATUS_SUCCESS); } else { } case . . . } }
上傳時間: 2013-10-17
上傳用戶:gai928943
//芯片資料請到www.elecfans.com查找 //DS1820 C51 子程序//這里以11.0592M晶體為例,不同的晶體速度可能需要調(diào)整延時的時間//sbit DQ =P2^1;//根據(jù)實際情況定義端口 typedef unsigned char byte;typedef unsigned int word; //延時void delay(word useconds){ for(;useconds>0;useconds--);} //復位byte ow_reset(void){ byte presence; DQ = 0; //pull DQ line low delay(29); // leave it low for 480us DQ = 1; // allow line to return high delay(3); // wait for presence presence = DQ; // get presence signal delay(25); // wait for end of timeslot return(presence); // presence signal returned} // 0=presence, 1 = no part //從 1-wire 總線上讀取一個字節(jié)byte read_byte(void){ byte i; byte value = 0; for (i=8;i>0;i--) { value>>=1; DQ = 0; // pull DQ low to start timeslot DQ = 1; // then return high delay(1); //for (i=0; i<3; i++); if(DQ)value|=0x80; delay(6); // wait for rest of timeslot } return(value);} //向 1-WIRE 總線上寫一個字節(jié)void write_byte(char val){ byte i; for (i=8; i>0; i--) // writes byte, one bit at a time { DQ = 0; // pull DQ low to start timeslot DQ = val&0x01; delay(5); // hold value for remainder of timeslot DQ = 1; val=val/2; } delay(5);} //讀取溫度char Read_Temperature(void){ union{ byte c[2]; int x; }temp; ow_reset(); write_byte(0xCC); // Skip ROM write_byte(0xBE); // Read Scratch Pad temp.c[1]=read_byte(); temp.c[0]=read_byte(); ow_reset(); write_byte(0xCC); //Skip ROM write_byte(0x44); // Start Conversion return temp.x/2;}
上傳時間: 2013-11-03
上傳用戶:hongmo
24c16讀寫驅(qū)動程序,//=-------------------------------------------------------------------------------/*模塊調(diào)用:讀數(shù)據(jù):read(unsigned int address)寫數(shù)據(jù):write(unsigned int address,unsigned char dd) dd為要寫的 數(shù)據(jù)字節(jié)*///------------------------------------------------------------------------------ sbit sda=P3^0;sbit scl=P3^1; sbit a0=ACC^0; //定義ACC的位,利用ACC操作速度最快sbit a1=ACC^1;sbit a2=ACC^2;sbit a3=ACC^3;sbit a4=ACC^4;sbit a5=ACC^5;sbit a6=ACC^6;sbit a7=ACC^7; //------------------------------------------------------------------------------#pragma disablevoid s24(void) //起始函數(shù){_nop_(); scl=0; sda=1; scl=1; _nop_(); sda=0; _nop_(); _nop_(); scl=0; _nop_(); _nop_(); sda=1;} //------------------------------------------------------------------------------#pragma disablevoid p24(void) //停止函數(shù){sda=0; scl=1; _nop_(); _nop_(); sda=1;} //-----------------------------------------------------------------------------#pragma disableunsigned char rd24(void) /////////////////從24c16讀一字節(jié)數(shù)據(jù){ ACC=0x00;sda=1;scl=1;a7=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a6=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a5=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a4=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a3=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a2=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a1=sda;_nop_();_nop_();_nop_();_nop_();scl=0;scl=1;a0=sda;_nop_();_nop_();_nop_();_nop_();scl=0;sda=1;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0; /// ///////////////24c16的一位回答位。return(ACC);}//------------------------------------------------------------------------------#pragma disablevoid wd24(unsigned char dd) ////////////////向24c16寫一字節(jié)數(shù)據(jù){ sda=1;ACC=dd;sda=a7;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a6;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a5;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a4;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a3;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a2;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a1;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=a0;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;sda=0;scl=1;//scl=0;(在下面程序中)}//---------------------------------------------------------------------------#pragma disableunsigned char read(unsigned int address){unsigned char dd; s24(); ////////////////////////開始條件 wd24(0xa0); /////////////////////////寫器件地址(寫命令) _nop_();_nop_();_nop_();_nop_(); scl=0; ///////////////////////////////////接收器件地址確認信號 wd24(address); //////////////////////////// 寫數(shù)據(jù)地址 _nop_();_nop_();_nop_();_nop_(); scl=0;s24(); ///////////////////////////////////開始條件 wd24(0xa1); /////////////////////////////寫器件地址(讀命令) scl=0; dd=rd24(); //////////////////////////////////讀 一字節(jié) p24(); ////////////////////////////////////停止條件 return(dd);}//------------------------------------------------------------------------------#pragma disablevoid write(unsigned int address,unsigned char dd){s24(); /////////////////開始條件 wd24(0xa0); ////////////////////////寫器件地址; scl=0; wd24(address); /////////////////////寫數(shù)據(jù)地址 scl=0; wd24(dd); //////////////////////////寫dd數(shù)據(jù) scl=0; p24(); /////////////////////////停止條件; }
上傳時間: 2013-11-18
上傳用戶:墻角有棵樹
This application note covers the design considerations of a system using the performance features of the LogiCORE™ IP Advanced eXtensible Interface (AXI) Interconnect core. The design focuses on high system throughput through the AXI Interconnect core with F MAX and area optimizations in certain portions of the design. The design uses five AXI video direct memory access (VDMA) engines to simultaneously move 10 streams (five transmit video streams and five receive video streams), each in 1920 x 1080p format, 60 Hz refresh rate, and up to 32 data bits per pixel. Each VDMA is driven from a video test pattern generator (TPG) with a video timing controller (VTC) block to set up the necessary video timing signals. Data read by each AXI VDMA is sent to a common on-screen display (OSD) core capable of multiplexing or overlaying multiple video streams to a single output video stream. The output of the OSD core drives the DVI video display interface on the board. Performance monitor blocks are added to capture performance data. All 10 video streams moved by the AXI VDMA blocks are buffered through a shared DDR3 SDRAM memory and are controlled by a MicroBlaze™ processor. The reference system is targeted for the Virtex-6 XC6VLX240TFF1156-1 FPGA on the Xilinx® ML605 Rev D evaluation board
上傳時間: 2013-11-14
上傳用戶:fdmpy
UART 4 UART參考設計,Xilinx提供VHDL代碼 uart_vhdl This zip file contains the following folders: \vhdl_source -- Source VHDL files: uart.vhd - top level file txmit.vhd - transmit portion of uart rcvr.vhd - - receive portion of uart \vhdl_testfixture -- VHDL Testbench files. This files only include the testbench behavior, they do not instantiate the DUT. This can easily be done in a top-level VHDL file or a schematic. This folder contains the following files: txmit_tb.vhd -- Test bench for txmit.vhd. rcvr_tf.vhd -- Test bench for rcvr.vhd.
上傳時間: 2013-11-07
上傳用戶:jasson5678
This book is for students and Linux System Administrators. It provides the skills to read, write, and debug Linux shell scripts using bash shell. The book begins by describing Linux and simple scripts to automate frequently executed commands and continues by describing conditional logic, user interaction, loops, menus, traps, and functions.
上傳時間: 2014-12-30
上傳用戶:黃蛋的蛋黃
The NCV7356 is a physical layer device for a single wire data linkcapable of operating with various Carrier Sense Multiple Accesswith Collision Resolution (CSMA/CR) protocols such as the BoschController Area Network (CAN) version 2.0. This serial data linknetwork is intended for use in applications where high data rate is notrequired and a lower data rate can achieve cost reductions in both thephysical media components and in the microprocessor and/ordedicated logic devices which use the network.The network shall be able to operate in either the normal data ratemode or a high-speed data download mode for assembly line andservice data transfer operations. The high-speed mode is onlyintended to be operational when the bus is attached to an off-boardservice node. This node shall provide temporary bus electrical loadswhich facilitate higher speed operation. Such temporary loads shouldbe removed when not performing download operations.The bit rate for normal communications is typically 33 kbit/s, forhigh-speed transmissions like described above a typical bit rate of83 kbit/s is recommended. The NCV7356 features undervoltagelockout, timeout for faulty blocked input signals, output blankingtime in case of bus ringing and a very low sleep mode current.
上傳時間: 2013-10-24
上傳用戶:s藍莓汁
U 盤作為一種便利的存儲設備,可以應用于嵌入式系統(tǒng)中,其應用的基礎就是對Linux 的USB Mass Storage 驅(qū)動的裁剪,以獲得所需的簡化的驅(qū)動程序。分析了Linux 下的USB mass storage 協(xié)議,簡化系統(tǒng)中所不需要的代碼,使其僅支持基于Bulk-Only 傳輸模式下的ATAPI 協(xié)議的存儲設備,從而使嵌入式系統(tǒng)更加精簡,對USB mass storage 驅(qū)動程序進行了裁剪。經(jīng)過裁剪的USB Mass Storage 驅(qū)動程序移植到三星公司的QT2410E 開發(fā)板上并取得成功。
上傳時間: 2013-11-23
上傳用戶:wfl_yy
The LPC2292/2294 microcontrollers are based on a 16/32-bit ARM7TDMI-S CPU with real-time emulation and embedded trace support, together with 256 kB of embedded high-speed flash memory. A 128-bit wide memory interface and a unique accelerator architecture enable 32-bit code execution at the maximum clock rate. For critical code size applications, the alternative 16-bit Thumb mode reduces code by more than 30 pct with minimal performance penalty. With their 144-pin package, low power consumption, various 32-bit timers, 8-channel 10-bit ADC, 2/4 (LPC2294) advanced CAN channels, PWM channels and up to nine external interrupt pins these microcontrollers are particularly suitable for automotive and industrial control applications as well as medical systems and fault-tolerant maintenance buses. The number of available fast GPIOs ranges from 76 (with external memory) through 112 (single-chip). With a wide range of additional serial communications interfaces, they are also suited for communication gateways and protocol converters as well as many other general-purpose applications. Remark: Throughout the data sheet, the term LPC2292/2294 will apply to devices with and without the /00 or /01 suffix. The suffixes /00 and /01 will be used to differentiate from other devices only when necessary.
上傳時間: 2014-12-30
上傳用戶:aysyzxzm
6小時學會labview, labview Six Hour Course – Instructor Notes This zip file contains material designed to give students a working knowledge of labview in a 6 hour timeframe. The contents are: Instructor Notes.doc – this document. labviewIntroduction-SixHour.ppt – a PowerPoint presentation containing screenshots and notes on the topics covered by the course. Convert C to F (Ex1).vi – Exercise 1 solution VI. Convert C to F (Ex2).vi – Exercise 2 solution subVI. Thermometer-DAQ (Ex2).vi – Exercise 2 solution VI. Temperature Monitor (Ex3).vi – Exercise 3 solution VI. Thermometer (Ex4).vi – Exercise 4 solution subVI. Convert C to F (Ex4).vi – Exercise 4 solution subVI. Temperature Logger (Ex4).vi – Exercise 4 solution VI. Multiplot Graph (Ex5).vi – Exercise 5 solution VI. Square Root (Ex6).vi – Exercise 6 solution VI. State Machine 1 (Ex7).vi – Exercise 7 solution VI. The slides can be presented in two three hour labs, or six one hour lectures. Depending on the time and resources available in class, you can choose whether to assign the exercises as homework or to be done in class. If you decide to assign the exercises in class, it is best to assign them in order with the presentation. This way the students can create VI’s while the relevant information is still fresh. The notes associated with the exercise slide should be sufficient to guide the students to a solution. The solution files included are one possible solution, but by no means the only solution.
標簽: labview
上傳時間: 2013-10-13
上傳用戶:zjwangyichao