Page 1 of 1

UHCI Simple question help?

Posted: Tue Dec 31, 2013 2:32 am
by PearOs
Hey guys, so I have been writing an UHCI Driver, and it works. I just have one question that the manuals and documentation I have doesn't exactly explain, and I was wondering if someone here knew. So in a USB Packet or TD as some call it, there's a Device address field. According to documentation any device unconfigured will respond to Address 0. Cool right? Well I have a UHCI Controller on my computer, and I plugged in two USB drives into it and ran my Os. I requested the Device Descriptor once for every device plugged into the two root ports "2 devices" and I got the first drivers descriptor the first time, and the second one the other time. My question is, how do I assign a device that was just plugged in an Device Address and know it when to the one connected to that port? Or does that really matter and I should just assign it the address before getting the descriptor and then mark that address as used and then get the descriptor?

Thanks guys.


Matt

Re: UHCI Simple question help?

Posted: Tue Dec 31, 2013 2:52 am
by thepowersgang
The USB enumeration process is documented in the USB Standard (iirc as a state machine).

Basic process is:
1. A hub detects a device is connected to a port and tells the USB stac (this could be the root hub or a previously enumerated child hub)
2. The USB stack tells the hub to do a port enable and reset, bringing the device into a usable state (just without an address, so it responds to 0)
3. The stack then allocates an address and sends a SET_ADDRESS command to device 0 on that bus.
4. The device now has its address configured, and can be queried uniquely via that.
5. Repeat from step 1 (make sure that you don't have two devices on the same bus listening for address 0 at the same, otherwise things get confusing).

Re: UHCI Simple question help?

Posted: Tue Dec 31, 2013 3:38 am
by rdos
thepowersgang wrote: (make sure that you don't have two devices on the same bus listening for address 0 at the same, otherwise things get confusing).
Yes, this is important. It is especially important to note that this also applies to USB hubs, which means that the RESET process of USB ports needs a per-function mutex if these tasks are handled by different threads.

Re: UHCI Simple question help?

Posted: Wed Jan 01, 2014 5:15 am
by PearOs
Thanks guys! I got it to work. :)

- Matt