## The LOOPBACK Sample

The LOOPBACK Sample accompanies Chapter 12 and illustrates how to do input and output to a bulk transfer pipe. This sample accommodates application requests of any size by recycling a single IRP. The sample was modified for the 2d edition to incorporate service pack fixes and to add error recovery.

The sample includes three components:

- LOOPBACK.SYS (SYS subdirectory) is a WDM driver for a USB device based on the Anchor Chips development board.
- TEST.EXE (TEST subdirectory) is a Win32 console application for testing LOOPBACK.SYS.
- LOOPBACK.HEX (EZUSB subdirectory) is the firmware image for the LOOPBACK device.

### Building LOOPBACK

To build LOOPBACK.SYS, follow the general instructions for building a WDM sample. The Microsoft Visual C++ project file is named LOOPBACK.DSP in the SYS subdirectory.

To build TEST.EXE, follow the general instructions for building user-mode programs. The Microsoft Visual C++ project file is named TEST.DSP in the TEST subdirectory.

### Testing LOOPBACK

First follow the general instructions for testing USB samples to install the device firmware (LOOPBACK.HEX in the EZUSB subdirectory) and the driver. Then open a command prompt and run TEST.EXE from the TEST\DEBUG subdirectory. TEST will output some data to the LOOPBACK device, read it back, and compare the input data to the output data to verify successful operation.

Test accepts a command line argument in the range 1-1024 to specify how many 32-bit data words it will transfer. If you specify a value bigger than 256, you'll force the driver to exercise the multi-segment transfer logic.

### Special note about power management

This driver doesn't automatically repower the device when the computer comes out of standby. I recommend not putting the computer through a power cycle with this device connected. A more realistic driver would establish some sort of policy about when the device should be powered and would use techinques like shown in the WAKEUP sample to enforce that policy.

### What to look for

The important routines in this sample are StartIo and OnReadWriteComplete, both in ReadWrite.cpp.