Technical Document #53

Technical Document #53        [Product Version: 5.0.4–5.2.2]
How do I reset my USB device using version 5.2.2 of WinDriver?

WinDriver provides you with an API for resetting your USB device: WD_UsbResetDevice() and WD_UsbResetDeviceEx() (added in version 5.0.4 of WinDriver). These functions cause the hub driver to reinitialize the device, while preserving the existing configuration.

WD_UsbResetDeviceEx() — added in version 5.0.4 — enables you to distinguish between performing a soft reset — which is similar to the reset performed with the WD_UsbResetDevice() function, used in previous versions; Or a hard reset.

The differences between a soft reset and a hard reset, performed with WD_UsbResetDeviceEx(), are as follows:

  • Soft reset: The reset request will be issued only if the device is in a disabled state (as done by Microsoft's driver).

  • Hard reset: The reset request will always be issued — regardless if the device is in the disabled or enabled state.

To use the hard reset option, set the WD_USB_HARD_RESET flag in the dwOptions field of the WD_USB_RESET_DEVICE structure, which is passed to WD_UsbResetDeviceEx(). By default, when the dwOptions field is set to 0, the function will perform a soft reset — i.e., the reset request will be issued only if the device is currently disabled.

Following is an an example of using WD_UsbResetEx() to perform a hard reset:

    reset.hDevice = hDevice; // The handle received from
         // WD_UsbDeviceRegister()
    reset.dwOptions = WD_USB_HARD_RESET;
    WD_UsbResetDeviceEx(hWD, &reset);

NOTE: To prevent a system crash when performing hard reset, it is recommended to do the following: immediately after calling WD_UsbResetDeviceEx(), un-register the device (by calling WD_UsbDeviceUnregister()), scan for it (by calling WD_UsbScanDevice()) and then register it again (by calling WD_UsbDeviceRegister()). This will ensure that Windows will allocate all the resources for the device and will eliminate possible conflicts later on.