Recently, some people sent an email asking me which drivers can be dynamically loaded by the driver debugging assistant and whyUSBDevice drivers always fail. To explain this problem, you must first understandWinCE. This article mainly introducesWinCEDriverProgram.
The driver isCodeLayer, which provides an interface for the operating system to operate on different hardware, including physical and virtual devices. Although there are many types of drivers, from the programming point of view, it is nothing more than adding the corresponding code to a fixed framework. The framework here refers to an interface for the operating system. The purpose of code implementation is to write the correct value to the correct register at the right time.
Driver classification, which varies from different perspectives. Take the serial driver for example, you can say that it is a hierarchical driver, you can also say that it is a stream driver, you can also say that it is a driver automatically loaded when the boot ...... This seems a bit messy. If you think so too, we recommend that you look down. If you know all this, it will not be a waste of time. Of course, you are willing to find something, I will thank you very much!
Local driver first (Native drivers) And stream-driven (Stream drivers) . WinCE The drivers under can be classified into the two, and the two must be one of them. This is distinguished by the interfaces provided by the driver to the operating system. The stream Driver provides stream interface functions for the operating system, such Xxx_init () , Xxx_open () , Xxx_read () , Xxx_write () , Xxx_close () And so on. This type of driver Device Manager It calls ActivateDeviceEx () Function to load the stream driver. ActivateDeviceEx () The parameter is the corresponding key in the registry, used to set the attributes of the stream driver to be loaded, as shown in Index , Order , Prefix And so on. The stream-driven registry configuration information is generally stored in [HKEY_LOCAL_MACHINE \ drivers \ builtin] . After the stream driver is loaded successfully, the application calls Createfile () , Readfile () , Wirtefile () And so on. The stream driver can be dynamically managed, and the driver debugging assistant is used to help debug such drivers.
In contrast to the stream driver, what the local driver provides to the operating system is not a standard stream interface, but a specific interface agreed in advance. Different devices have different interfaces.WinCECommon local drivers includeLCDDisplay driver, touch screen driver, mouse and keyboard driver, printer driver, etc. We can see that the local driver is mainly related to the man-machine interface. They are composedGWESManagement, load when the system starts. They also have their own configuration information in the registry. For example, the Registry configuration of mouse and keyboard is as follows:
[HKEY_LOCAL_MACHINE "system" CurrentControlSet "control" layouts "00000409]
"Layout file" = "kbdmouse. dll"
"Layout text" = "us"
"Ps2_at" = "kbdmouse. dll"
"Matrix" = "kbdmouse. dll"
The local driver is called by the operating system and cannot be accessed by applications. For such drivers, the driver debugging assistant is powerless and can only be honestly compiled, downloaded, and verified.
wince drivers often hear MDD (Model Device Driver) and PDD (platform dependent driver) this concept is distinguished by the structure of the driver code implementation. the wince driver can be single-layer, or PDD + MDD . There is no rigid rule that a driver can adopt a layered structure or a single layer structure. In general, the driver execution efficiency of a single-layer structure is higher, while the driver of a hierarchical structure facilitates code maintenance and transplantation. Taking the serial driver as an example, a single-layer structure can be used. It is divided into PDD and MDD As a general developer, we only need to implement the PDD layer, MDD layers are implemented by Microsoft. In this way, the workload for development is much less, and the code reliability is better guaranteed. What kind of structure is used as the driver depends on your needs.
wince 6.0 introduces the concepts of kernel-mode drivers and user-mode drivers. In wince5.0 and earlier versions, the driver works in user mode. From the code perspective, there is no big difference between kernel-mode drivers and user-mode drivers. If no special technology is used in the driver, the kernel-mode driver is Binary compatible with the user-mode driver. I have tried to load a DLL to the kernel state and user State respectively, and they both work well. The kernel-state driver is loaded into the kernel space, and the user-state driver is loaded into a specific user process space. In terms of execution efficiency, the kernel-mode driver is more efficient than the user-mode driver. In terms of stability, user-mode drivers do not have a fatal impact on the system, while kernel-mode drivers are relatively dangerous. Which type of driver is also your requirement.
there are two types of driver loading time: load when the system starts and when needed. Generally, local drivers are loaded at startup, so here we mainly talk about stream drivers. If you want to load the driver when the system starts, you only need to put its registry configuration information in [HKEY_LOCAL_MACHINE \ drivers \ builtin \] , for example, [HKEY_LOCAL_MACHINE \ drivers \ builtin \ battery] when the system is started, Device Manager automatically loads the Device Manager. if you need to load a file, you just need to load the file. If you want to uninstall the file, you can uninstall the file, which is flexible. USB Device Driver loading, for example, USB camera driver, which is also a driver to be loaded when needed. From the perspective of the driver interface, it is a stream driver, but it is relatively common. It adds several functions: usbdeviceattach () , usbinstalldriver () , usbuninstalldriver () . USB the camera driver is loaded in usbdeviceattach () finished. Therefore, it does not need or cannot be loaded by the driver debugging assistant. The driver that needs to be loaded has another function. When the system cannot be modified, the driver is dynamically loaded in the application to complete hardware operations.
To sum up,WinCEDriver classification mainly includes the following methods:
Driver interfaces can be divided into local drivers and stream drivers;
Based on the driving structure, it can be divided into single-layer drivers and stratified drivers;
The space loaded by driver can be divided into kernel-mode drivers and user-mode drivers;
By driver loading time, it can be divided into loading at startup and loading at need.
The driver debugging assistant is used to dynamically manage the stream driver. Local driver andUSBThe driver is no longer under its control. You should pay attention to this when using it.
If there are any mistakes in this article, please leave a message to correct them. If you have any questions, please leave a message for discussion.