Saturday, November 7, 2009

USB-3rd Part

Descriptors and their types:-

All descriptors have three common fields like bLength bDescriptorType and bcdUSB. The first one decides the length of the descriptor, the second type indicates its type. The different types of descriptors are:-


1:- Device Descriptors: - The device descriptor represents the entire USB device and hence each device can have a single device descriptor. The idProduct and idVendor fields of device descriptor help the OS to find the appropriate driver for the device


2:- Configuration Descriptor:- The configuration descriptor specifies values such as the amount of power this particular configuration uses, if the device is self or bus powered and the number of interfaces it has. When a device is enumerated, the host reads the device descriptors and can make a decision of which configuration to enable. It can only enable one configuration at a time. Thus multiple configuration descriptors are possible.

3:- Interface descriptor: - This can be seen as a header or leader of a group of endpoints which is dedicated to perform a particular function. For example you could have a multi-function fax/scanner/printer device. Interface descriptor one could describe the endpoints of the fax function, Interface descriptor two the scanner function and Interface descriptor three the printer function. Unlike the configuration descriptor, there is no limitation as to having only one interface enabled at a time. A device could have 1 or many interface descriptors enabled at once. Though there is a system of identifying the primary and/or the secondary interface descriptor by judging the fields like bInterfaceNumber (specifying the Interface number) and a bAlternateSetting

4: - Endpoint Descriptor: - Endpoint descriptors are used to describe endpoints other than endpoint0. Endpoint zero is always assumed to be a control endpoint and is configured before any descriptors are even requested. The host will use the information returned from these descriptors to determine the bandwidth requirements of the bus

5: - String Descriptor: - These provides information to the end user and hence contains human readable data like the name “ Jetflash Mass Storage Device” which we are used to see in the property of a USB device.

Enumeration Steps:-

Enumeration is the initialization process by which an OS detects a device and specifies its power requirement, which class of device, type of data transfer it supports. The steps of enumeration in a windows machine are as follows:-

1:- First when the device is inserted in the USB connection of the machine, host gives it a time of 100ms for the power stabilization

2:- The device is assigned an address 0 by default by the host controller. No matter how many devices are attached to the host controller all those will be assigned as address 0 in the beginning and hence the multiple devices attached to the host are enumerated one by one and not simultaneously

3:- The host asks for the device descriptor

4: After receiving initial 8 bytes of the device descriptor the host assigns a reset command

5: The host now assigns an address to the device by issuing a set address command. The address issued by the host ranges from 1 to 127. Thus we are able to connect 127 devices to each host

6:- The remaining bytes of the device descriptor are asked for

7:- The host then asks for the configuration descriptor and then for the interface descriptor to determine the overall size and the types or no. of function to be performed by the device.

8:- The host then asks for string descriptor if there is any

After all these steps depending upon the idProduct and idVendor as provided by the device descriptor the OS will search for the device driver. If it founds one then it loads the driver and then pops up a message near the taskbar that “an USB device has been recognized “. If the OS can not load any driver then it will show the message “the device is not recognized”.


USB-2nd part

USB Data Transfer Protocol

The USB device consist of a logical entity called Endpoints in it through which the data transfer takes place. An USB device can have multiple Endpoints. The connection between the Endpoint and the host is called logical pipes. The device driver of the host sends data to the endpoint for any type of data transfer require point. It will send data to the Endpoint1-out buffer (for example) while will receive the incoming data packets in the Endpoint1-in buffer. Each device must support Endpoint0 which is used for the control transfer while the other are used for data transfer

Types Of Data Transfer

The types of data transfer are

1:- Control Transfer: - This type of transfer takes place for command and status operation like resetting or enumeration commands. Enumeration is the initialization of the of the USB device for the data transfer by communicating with the endpoint0. The steps taken for the process are as follows.

The host generates a setup token, which helps the incoming packet to recognize as the setup packet, to the endpoint0. The endpoint is selected by default as all the control transfers are done via the endpoint0. The host then sends the 8 bytes DATA0 packet requesting the device descriptor of the USB device, which will help the OS of the host to load the appropriate driver to recognize and control the USB device, to the endpoint0-out buffer. The USB device will acknowledge the packet if there is no error otherwise if the packet is corrupted then it just ignores the packet. The host will resend it in the next few seconds. The device descriptor request as send by the host to the endpoint0-out buffer is then checked and the device sends the device descriptors. But it sends these descriptors only when the host is ready to receive it which is indicated by the issuing of IN token by the host to the device. Then the device will send the device descriptor values to the endpoint0-in buffer.A small comparison between the OUT and IN concept is given below---
a: OUT :- Whenever the host wants to send any data it issues an out token followed by a data packet which is received by the device endpointx-out buffer and if there is no error an acknowledgement is send to the host.
b:- IN :- Whenever a host wants to receive something it issues an IN token which is received by the device and then it sends the data as requested by the host in the previous OUT data-packet, to the endpointx-in buffer.

Remember that the direction of data transfer is based with reference to the host not the device.

2:- Isochronous Transfer: - Isochronous transfers occur continuously and periodically. They typically contain time sensitive information, such as an audio or video stream

3:- Interrupt Transfer


Bulk Transfer: - Bulk transfers can be used for large bursty data. Such examples could include a print-job sent to a printer or an image generated from a scanner. These is supported only by the high speed or the full speed devices

Fields of Set-up Packet:-


The Setup Packet contains the following fields:-

bmRequestType , bRequest, wValue, wIndex, wLength


Depending upon various type of requests like

Standard device request, Standard Interface request, Standard endpoint request the above mentioned fields has different values


USB

Here I will tell about the USB protocol..which we all use but has a very little knowledge.As the very preliminary idea is also big I have make three parts of it.The first part deals with the introduction of USB..the second part describes the data transfer protocol and the third part is the zist of the transfer steps also called enumeration-------

Initialization:-

The USB protocol has been designed in 1990 by the leading companies like, INTEL, Compaq, IBM, Microsoft and Northan Telecom.

There are mainly 4 version of USB that are available now.

1:- USB1.0 protocol. Low Speed 1.5Mbits/s

2:- USB1.1 protocol. Low Speed 1.5Mbits/s and also full speed mode of 12Mbits/s

3:- USB2.0 protocol. High Speed 480Mbits/s

4:- USB3.0 protocol. Super Speed 4.8Gbits/s..

USB3.0 is not fully functional till now, though the first demonstration has takes place in the latest version of Linux.

Data Transfer Mechanical Explanation:-

The USB connector consists of 4 pins. Gnd, D+, D-, Vcc. Each data line corresponding to D+ and D- of the device in the host consist of a pull down resistor of typical value 15kOhm while in case of the device it is 1.5kOhm. While the device is not active the host pulls both the data line in logic 0 state thus producing the Single Ended Zero (SEZ0) state in USB Terminology.

In case of active state the host pulls one of the data lines of the device high through 1.5kOhm depending on the mode it is functioning. For 1.x mode of USB transfer the D+ line is pull high for full speed data transfer while the D- line is pulled low for low speed data transfer.

We get two state called Differential0 and Differential1 state by this.

Differential0:- D+ logic low D- logic high

Differential1:- D+ logic high D- logic low.

The corresponding two states Differential0 and Differential1 are known as J and K respectively in low speed mode while they are known as K and J in full speed mode respectively. The data gets transferred by alternating J and K state between the host and the device.

In case of USB2.0 the device first gets attached to the host as the full speed device i.e., D+ line is pulled high. After receiving the USB RESET command i.e., both the D+ and D- lines are pull low, it pulls the D- line high indicating that the device is capable of high speed data transfer.