4.2. DriverWizard Walkthrough

To use DriverWizard, follow these steps:

  1. Attach your hardware to the computer:
    Attach the card to the appropriate bus slot on your computer.
    Alternatively, you have the option to use DriverWizard to generate code for a virtual PCI device, without having the actual device installed, by selecting the PCI Virtual Device DriverWizard option (see information in Step 2). When selecting this option, DriverWizard will generate code for your virtual PCI device.
  2. Run DriverWizard and select your device:
    1. Start DriverWizard — <path to WinDriver>/wizard/wdwizard. On Windows you can also run DriverWizard from the Start menu: Start | Programs | WinDriver | DriverWizard.
      On Windows 7 and higher you must run DriverWizard as administrator.
    2. Click New host driver project to start a new project, or Open an existing project to open a saved session.

      Figure 4.1. Create or Open a Driver Project

      Create or Open a Driver Project

    3. Select your Plug-and-Play card from the list of devices detected by DriverWizard.

      Figure 4.2. Select Your Plug-and-Play Device

      Select Your Plug-and-Play Device

      For non-Plug-and-Play cards, select ISA.
      To generate code for a PCI device that is not currently attached to the computer, select PCI Virtual Device.

      When selecting the PCI Virtual Device option, DriverWizard allows you to define the device's resources. By specifying the I/O and/or memory ranges, you may further define run-time registers (the offsets are relative to BARs). In addition, the IRQ must be specified if you want to generate code that acknowledges interrupts via run-time registers. Note, that the IRQ number and the size of the I/O and memory ranges are irrelevant, since these will be automatically detected by DriverWizard when you install a physical device.
  3. Generate and install an INF file for your device [Windows]:
    On the supported Windows operating systems, the driver for Plug-and-Play devices (such as PCI) is installed by installing an INF file for the device. DriverWizard enables you to generate an INF file that registers your device to work with WinDriver (i.e., with the windrvr1230.sys driver). The INF file generated by DriverWizard should later be distributed to your Windows customers, and installed on their PCs.
    The INF file that you generate in this step is also designed to enable DriverWizard to diagnose your device on Windows (for example, when no driver is installed for your PCI device). Additional information concerning the need for an INF file is provided in Section 15.1.1.

    If you don't need to generate and install an INF file (e.g., if you are using DriverWizard on Linux), skip this step.

    To generate and install the INF file with DriverWizard, do the following:

    1. In the Select Your Device screen (see Step 2), click the Generate .INF file button or click Next.
    2. DriverWizard will display information detected for your device — Vendor ID, Device ID, Device Class, manufacturer name and device name — and allow you to modify this information, as demonstrated in Figure 4.3 below.

      Figure 4.3. DriverWizard INF File Information

      DriverWizard INF File Information

    3. When you are done, click Next and choose the directory in which you wish to store the generated INF file. DriverWizard will then automatically generate the INF file for you.

      You can choose to automatically install the INF file by checking the Automatically Install the INF file option in the DriverWizard's INF generation dialogue.
      If the automatic INF file installation fails, DriverWizard will notify you and provide manual installation instructions (refer also the manual INF file installation instructions in Section 15.1).

      Handling of PCI Message-Signaled Interrupts (MSI) and Extended Message-Signaled Interrupts (MSI-X) requires specific configuration in the device's INF file, as explained in Section of the manual.
      On Windows 7 and higher, if your hardware supports MSI or MSI-X, the Support Message Signaled Interrupts option in the DriverWizard's INF generation dialogue will be enabled and checked by default. When this option is checked, the generated DriverWizard INF file for your device will include support for MSI/MSI-X handling. However, when this option is not checked, PCI interrupts will be handled using the legacy level-sensitive interrupts method, regardless of whether the hardware and OS support MSI/MSI-X.
    4. When the INF file installation completes, select and open your device from the list in the Select Your Device screen.

  4. Uninstall the INF file of your device [Windows]:
    On Windows, you can use DriverWizard to uninstall a previously installed Plug-and-Play PCI) device INF file. This will unregister the device from its current driver and delete the copy of the INF file in the Windows INF directory.

    In order for WinDriver to correctly identify the resouces of a Plug-and-Play device and communicate with it — including for the purpose of the DriverWizard device diagnostics outlined in the next step — the deivce must be registered to work with WinDriver via an INF file (see Step 3).

    If you do not wish to uninstall an INF file, skip this step.

    To uninstall the INF file, do the following:

    1. In the Select Your Device screen (see Step 2), click the Uninstall .INF file button.
    2. Select the INF file to be removed.

  5. Diagnose your device:
    Before writing your device driver, it is important to make sure your hardware is working as expected. Use DriverWizard to diagnose your hardware. All of your activity will be logged in the DriverWizard log so that you may later analyze your tests:
    1. Define and test your device's I/O and memory ranges, registers and interrupts:
      • DriverWizard will automatically detect your Plug-and-Play hardware resources: I/O ranges, memory ranges, and interrupts.

        Figure 4.4. PCI Resources

        PCI Resources

        For non-Plug-and-Play hardware, define your hardware's resources manually.

        On Windows 7 and higher, you may need to register an IRQ with WinDriver before you can assign it to your non-Plug-and-Play hardware [9.2.3].

        You can also manually define hardware registers, as demonstrated in Figure 4.5 below.

        Figure 4.5. Define Registers

        Define Registers

        When defining registers, you may check the Auto Read box in the Register Information window. Registers marked as Auto Read will automatically be read for any register read/write operation performed from DriverWizard. The read results will be displayed in the wizard's Log window.
      • Read and write to the I/O ports, memory space and your defined registers, as demonstrated in Figure 4.6.

        Figure 4.6. Read/Write Memory and I/O

        Read/Write Memory and I/O

      • 'Listen' to your hardware's interrupts.

        Figure 4.7. Listen to Interrupts

        Listen to Interrupts

        For level-sensitive interrupts, such as legacy PCI interrupts, you must use DriverWizard to define the interrupt status register and assign the read/write command(s) for acknowledging (clearing) the interrupt, before attempting to listen to the interrupts with the wizard, otherwise the OS may hang! Figure 4.8 below demonstrates how to define an interrupt acknowledgment command for a defined INTCSR hardware register. Note, however, that interrupt acknowledgment information is hardware-specific.

        Figure 4.8. Define Transfer Commands for Level-Sensitive Interrupts

        Define Transfer Commands for Level-Sensitive Interrupts

  6. Generate the skeletal driver code:
    1. Select to generate code either via the Generate Code toolbar icon or from the Project | Generate Code menu.
    2. In the Select Code Generation Options dialogue box that will appear, you may optionally select to generate additional customized code for one of the supported devices [7]; then choose the code language and development environment(s) for the generated code and select Next to generate the code.

      Figure 4.9. Code Generation Options

      Code Generation Options

    3. Click Next and select whether to handle handle Plug-and-Play and power management events from within your driver code, whether to generate Kernel PlugIn code [11] (and what type of related application to create), and whether to build your project's library as a DLL (for MS Visual Studio Windows projects).

      Figure 4.10. Additional Driver Options

      Additional Driver Options

      [Note]Kernel PlugIn Windows Project Notes
      • To compile the generated Kernel PlugIn code, the Windows Driver Kit (WDK) must be installed.
      • To successfully build a Kernel PlugIn project using MS Visual Studio, the path to the project directory must not contain any spaces.
    4. Save your project (if required) and click OK to open your development environment with the generated driver.
  7. Compile and run the generated code:

    • Use this code as a starting point for your device driver. Modify where needed to perform your driver's specific functionality.
    • The source code DriverWizard creates can be compiled with any 32-bit compiler, and will run on all supported platforms without modification.

    For detailed compilation instructions, refer to Section 4.2.2.

4.2.1. Automatic Code Generation

After you have finished diagnosing your device and have ensured that it runs according to your specifications, you are ready to write your driver. Generating the Code

Generate code by selecting this option either via DriverWizard's Generate Code toolbar icon or from the wizard's Project | Generate Code menu (see Section 4.2, Step 6). DriverWizard will generate the source code for your driver, and save it together with the wizard driver-project file (xxx.wdp, where "xxx" is the project name). The files are saved in a directory DriverWizard creates for every development environment and operating system selected in the code generation dialogue. The Generated PCI/ISA C Code

In the source code directory you now have a new xxx_lib.h file, which contains type definitions and functions declarations for the API created for you by the DriverWizard, and an xxx_lib.c source file, which contains the implementation of the generated device-specific API.
In addition, you will find an xxx_diag.c source file, which includes a main() function and implements a sample diagnostics application that utilizes the generated DriverWizard API to communicate with your device.

The code generated by DriverWizard is composed of the following elements and files, where xxx represents your DriverWizard project name:

  • Library functions for accessing each element of your card's resources (memory ranges and I/O, registers and interrupts):
    • xxx_lib.c — the implementation of the hardware-specific API (declared in xxx_lib.h), using the WinDriver Card (WDC) API [B.2].
    • xxx_lib.h — a header file that contains type definitions and function declarations for the API implemented in the xxx_lib.c source file.
      You should include this file in your source code to use the API generated by DriverWizard for your device.
  • A diagnostics program that utilizes the generated DriverWizard API (declared in xxx_lib.h) to communicate with your device(s):
    • xxx_diag.c The source code of the generated diagnostics console application.
      Use this diagnostics program as your skeletal device driver.
  • A list of all files created can be found at xxx_files.txt.

After creating your code, compile it with your favorite compiler, and see it work!

Change the function main() of the program so that the functionality suits your needs.

4.2.2. Compiling the Generated Code Windows and Windows CE Compilation

As explained above, on Windows you can select to generate project, solution, and make files for the supported compilers and development environments — MS Visual Studio, Windows GCC (MinGW/Cygwin), MS eMbedded Visual C++, or MS Platform Builder.
For integrated development environments (IDEs), such as MS Visual Studio, you can also select to automatically invoke your selected IDE from the wizard. You can then proceed to immediately build and run the code from your selected IDE.

You can also build the generated code using any other compiler or development environment that supports the selected code language and target OS. Simply create a new project or make file for your selected compiler/environment, include the generated source files, and run the code.

  • For Windows, the generated compiler/environment files are located under an x86 directory — for 32-bit projects — or an amd64 directory — for 64-bit projects.
  • For Windows CE, note that the generated Windows Mobile code is targeted at the Windows Mobile 5.0/6.0 ARMV4I SDK.
To build a Kernel PlugIn project (on Windows), follow the instructions in Section 12.7.1. Linux Compilation

Use the makefile that was created for you by DriverWizard in order to build the generated code using your favorite compiler, preferably GCC.

To build a Kernel PlugIn project, follow the instructions in Section 12.7.2.