three. Writing of client programs
1 device interface
The ADDDEVICE code of the driver calls IOCREATEDEVICE to create a device object. There are two ways to provide names available to Win32 programs, the old method is to provide a clear symbolic link name, the new method is to use the device interface identifies the device that supports the defined API.
IOCREATEDEVICE call has a DeviceName parameter that can be used to specify a name for the device. This name is marked to the kernel instead of the Win32 identification device. So you need to create a symbolic link to make the kernel device name to Win32.
Old way to call IOCREATESYMBOLICLINK, pass the appropriate symbolic link name and device link name using the parameters. The main idea of the new method is to define an available application programming interface for the device object, and the global unique identifier (GUID) is used to identify this interface. GUID must be generated using the Guidgen tool, formulating its defined device interface in GUID.H. Call the iReGisterDeviceInterface function in the AddDevice routine to register its interface and call iOSetDeviceInterfaceState to enable this device interface. 2. User state program call driver
EZUSB.sys of the EZ-USB series is a driver that can be directly used without modification. When there is no very special requirement, it is possible to use this driver as a USB interface driver of the device, of course, It is a USB control chip that the device must use EZ-USB.
Use IOCREATESYMBOLICLINK to create a symbolic link in ezusb.sys to provide the name of the device available to the user state program. Therefore, the user program first obtains the handle of the device driver by calling a Win32 function createfile (); and then use the deviceiocontrol () function to submit the I / O control code and related input / output buffer with the handle returned by the createFile () function. To the driver, complete the task of USB data transfer in a Windows environment.
3. Relationship between firmware code, driver, and client program
The firmware code is very important, and he mainly implements the initialization and configuration of the equipment. The driver is primarily responsible for processing of various IRPs, and clients issuing IRP implementation specific features.
Take a simple read and write to EZ-USB's 2131 chip, data is output from EP2OUT to the chip, and read back from EP2IN to the host. The 2-end point output buffer of the 2131 chip is 7dc0, the address of the input buffer is 7E00, which requires the firmware program to copy all the data of the 2-end point input buffer to the output buffer. After the client program issues a read and write command, obtain the device handle via the createFile () function, then call the DeviceIoControl () function to submit the I / O control code and the related input output buffer to the driver. The driver is responsible for processing communication about IRP and implementing data.