Like most software, drivers benefit from an organized approach to development. This section gives some guidelines that may help shorten development time. Use Formal Design MethodsTraditionally, writing a device driver implied a license to code without a design strategy. In the haste to test brand new hardware, the unit test code became the basis for the ultimate driver. Perhaps, too, many device drivers were written by programmers unfamiliar with the operating system. The first driver written is really a journey of discovery as the driver author learns the overall I/O architecture of the system. Fortunately (or perhaps sadly, depending on one's perspective), the days of software cowboys are over. Between complicated hardware and operating systems, there is no longer room for design-as-you-go coding. Writing Windows 2000 drivers certainly entails a steep learning curve. Good software engineering and practices are required for success. A short list of design techniques, some of which are borrowed from real-time design methodology, are listed below.
Using these techniques helps decompose a driver into well-defined functional units. In some cases, this might mean breaking a single, monolithic driver into a pair of port and class drivers that handle hardware-dependent and hardware-independent functions. In any event, the time spent analyzing the design of a driver at the start of the project more than pays for itself in reduced debugging and maintenance. Use Incremental DevelopmentOnce an initial analysis and design is completed, it's time to start the actual development. Following the steps below can reduce debugging time by helping to detect problems while they're still easy to find.
Another useful tip: When the exact behavior of hardware is unknown, add a DeviceIoControl function that gives direct access to the device registers. This allows a simple Win32 program to manipulate the device registers directly. Remember to disable this function before shipping the final version of the driver. Examine and Use the Sample DriversThe Windows 2000 Device Driver Kit (DDK) contains a considerable amount of sample code. There are many ways to use this code to make driver development easier. Microsoft encourages cutting and pasting from their sample source code. Of course, as usual, no warranty is implied or should be assumed when using this code.
|