USB device driver guide (4)

Source: Internet
Author: User
After learning about all usbd interface functions last time, we have gained a lot of basic knowledge. Review the folder structure of the USB sample, we can still remember that the USB/class/common folder contains the source code of the public part, it is the structure and function encapsulation specially abstracted by Microsoft to serve drivers of most USB devices. Let's take a rough look at the source program here.

Three programs are included:
Remlock USB client utils
Next, let's take a look at the functions and interfaces of these three programs. Obviously, the USB driver will certainly use some of these functions, therefore, we do not need to understand every line of the line, but at least we need to have an impression on these functions, so that we do not know the source of the function when reading the driver.

The remlock program is a lock used to remove the device.
Typedef struct _ remove_lock
{
Bool removed;
Long iocount;
Handle removeevent;
} Remove_lock, * premove_lock
To implement synchronization control when the device is removed. Among them, the removed member is the identifier for whether the device has been removed, and the iocount member is the number of accesses to the device, which is also a common behavior in the driver, just like the lock program we saw earlier, removeevent is a kernel event, which should be clear to anyone familiar with Win32 programming. It is a way for the kernel to notify the application, it is also a means of thread concurrency control. If you are not familiar with it, you must find a book such as Windows Advanced Programming as I mentioned in previous articles to understand it, otherwise, it is difficult to control the driver.

The functions implemented by using it are not mentioned, and they are used in the same way as those in the critical section. In addition, there is a function like interlockedincrement in this program. This function is a Win32 API function designed to provide synchronous access to the same variable by multiple threads. You can use msdn to find detailed usage.

The USB client program is a function interface used to package usbd for USB device drivers. h. We can find that the definition of a group of functions about data transmission, attribute setting, status description, and resetting is in the original form. Let's look at the USB client again. in the c file, most of these functions have a parameter of the lpcusb_funcs type. Looking back at our previous understanding of usbd, we can see that this parameter can be used to access the service functions provided by usbd, through the implementation of the function, we can find that every function uses this parameter to call the usbd function and then process the called result. Therefore, there is only one more encapsulation, this makes the compilation of the driver clearer and easier to maintain.

In addition, we should pay attention to the issuebulktransfer (), issueinterrupttransfer (), and issuevendortransfer () functions, which implement general bulk transmission, interrupted transmission, and custom transmission modes, to be used in the driver.

Utils is a simple program that encapsulates registry operations. Using the _ reg_value_descr struct and the getsetkeyvalues () function, you can easily access the registry and use more in driver installation.

After talking about so many things, although we haven't looked at many programs, we are a little closer to the driver. At least we know that many functions are used in the driver, if you are interested, you can read the implementation methods of each function, but I don't think this will affect the development of the driver. If I write the driver, I will copy these public source programs without special circumstances. This can greatly shorten the development cycle!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.