USB allows hot-swapping. This is made possible by both the physical structure of the system and the logical processing on the system. In this section, we will omit the physical specifications and provide an overview of the system behavior. As illustrated below, USB drivers have a stacked structure.

 

System of USB

System of USB

 

When there is no connected device, there is no client, since there is no function to communicate with.

 

When there is no connected device

 

As soon as a device is connected, enumeration is performed to allow the USB system software to identify the connected device. During enumeration, device descriptors are loaded, USB addresses are allocated, and various configurations are performed.

Device drivers are loaded by matching the Vender ID or Product ID in the Device Descriptor, or the Class or Subclass in the Class, Subclass, or Interface Descriptor with the drivers list in "Inf" files.

 

As soon as a device is connected

 

Thus, the driver software is loaded and become available for use. When using a hub, the USB system software goes through the same procedure to detect the devices, as well as to power up and enable the hub ports. When a device is disconnected, the change of port status is notified to the USB system software, so that the USB system software can unload the applicable client software. In terms of power consumption, USB specifications define Bus-Powered/Self-Powered and Suspend/Resume. With USB, a certain amount of consumption current can be provided via the power line on an upstream port. Peripheral devices that use the power line on an upstream port to fulfill all power requirements are referred to as being "Bus-Powered," while those that have a separate power source such as an AC adapter are referred to as being "Self-Powered." The amount of consumption current that can be provided via an upstream port remains unchanged for USB 2.0, since utmost priority was placed on maintaining compatibility of the connectors and cables.
USB defines Suspend and Resume as means to reduce power consumption by peripheral devices while the system is suspended (paused). When a system becomes suspended, so does the issuing of SOF packets that indicate the beginning of frames. The USB bus hence becomes Idle for a prolonged time. USB peripheral devices should be designed to halt the system clock or the USB sampling clock when the USB bus has been Idle for 3 ms or longer, so as to minimize the power consumption. To Resume, or recover from the Suspend state, you can either have the host change the USB bus from the Idle state, or have the function change the USB bus from the Idle state to wake the host (remote wakeup) and hence the entire system. (Suspend/Resume and Reset under USB 2.0)

Suspend/Resume under USB