Thursday, March 12, 2009

USB 101 - Specifications

One of the major project I did in AMI is implementing USB 2.0 for AMIBIOS8. It was a wonderful adventure to learn USB and to be able to implement the host controller support from scratch. Programming for USB controller seems like a daunting task but if we get the basic operations of USB controller then it is very simple.

USB specification is not a good point to start. I find it is better to start with OHCI (Open Host Controller Interface) specification, then move to EHCI (Enhanced..) and finally to USB specification. Let us see what these specifications talk about and how it will help us to understand the USB itself.

USB Specification:
The USB specification defines the things starting from the USB connector on the board to the device. It details mechanical, electrical and communication protocol of the USB bus. Meaning it explains the various USB connectors (A, B, mini-A etc), bus characteristics, data transmission details etc. The latest specification version is 3.0. This 3.0 specification covers 4 different USB speeds such as:
  • Low speed (1.5 Mb/s) - keyboard, mouse etc
  • Full speed (12 Mb/s) - USB 1.1 flash drive
  • High speed (480 Mb/s) - USB 2.0 flash drive
  • Super Speed (5 Gb/s) - Newer devices
Host controller specifications:
The host controller specification talks about how actually software talks to the USB bus. It defines the hardware interface through which the system software (OS, BIOS etc) can communicate through the USB bus. There are 4 types of host controllers as below:
  • Universal Host Controller Interface (UHCI) - During USB 1.1 specification time frame there was split between hardware vendors on Host Controller Interface agreements, thus two different specifications were created and supported by different companies. UHCI is one of those two specifications and it is supported in Intel Chipsets. As this is the very first Host Controller interface this is one of the badly designed host controller interface (in my opinion). It supports only low & full speed otherwise called USB 1.1 speeds.
  • Open Host Controller Interface (OHCI) - Competitor to the UHCI specification, this is supported by AMD, Compaq and others. This is elegantly designed and easy to program when compared to UHCI. It supports USB 1.1 speeds only
  • Enhanced Host Controller Interface (EHCI) - This supports USB 2.0 speed aka high speed. Luckily for the software developers there is only on 2.0 Host Controller. This utilizes most of the OHCI approach and thus easy to program.
  • eXtensible Host Controller Interface (XHCI) - This host controller supports new USB 3.0 speed aka super speed. I didn't look at the specification yet as it is not publicly available. This specification was almost split up just like USB 1.1 controllers but saved at the last moment - that is what I heard!
Mostly System Software Engineers need to worry about how to communicate through the host controller interface. It is more like when you start programming serial port first thing we want to learn is the programming interface, how to set the transmission speed, how to receive a byte or transmit a byte etc. It is same in USB too.

As the main goal of USB is to support wide range of devices connected to a same connector, the complexity of identifying and configuring devices falls under software stack. The USB specification tells you how to generate a meaningful generic (in the sense of device types) communication in the USB bus. There are various other specifications which details communication details for various type of devices like Human Interface Devices (HID) such as keyboard, mouse etc, Mass Storage Devices such as CDROM, flash drives etc.

In the next post I will discuss more into communication details.

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Sivagar,
    Very good narration. I am waiting for your second part on this.

    Thanks
    Siva

    ReplyDelete