You are persistent, that's good news
Getting the Device-Descriptor(DD) is a huge step ahead. It is still not clear to me whether you have managed to do that or not.
It was several months ago, when I implemented USB, so I forgot a lot. I had to check the code (I did it for a few minutes).
The C-code, that comes with the book, first initializes the controller. There are many things it does here, e.g. delays are very important, it waits 20ms after powering a port.
It gets the number of ports of the EHCI-controller and then:
Code: Select all
for (i=0; i<portsnum; i++)
if (reset_port(i))
get_desc()
In reset_port(port), the enable bit and status change bits are cleared (PortStatus+port*4) and then that Status-register is read, and see if there is a device attached from its value (the enable-bit will be set if device is a high-speed one).
EDIT: It seems to me, that the port-number is not used later. The port is enabled and later will be used without its number(or index).
I wouldn't be fair to publish more source-code from the book
Getting the other descriptors (e.g. Configuration) is the same but you need to send a different data-structure.
I think it's not a bad idea to discuss how to use the data-toggle in the QHs in this topic, because it is not in the book(using it in the TDs was already explained above). Later you(and others) may find it useful. Of course, this will only be helpful in case of bulk-transfers, where huge amount of data is transfered.
You need two QHs: one for in and one for out (the bit will be toggled for you). You insert QHin into the list of QHs in case of a read, and QHout in case of a write.
If you want to do a new transfer, you simply don't touch the value of the dt in the QH, you only need to update parts of the QH that are necessary.
We can transfer max. 0x5000 bytes per TD, if dt is used in the QH.
If used in TD, and MPS(Max Packet Size) of usb-drive is e.g. 512, we would need to use much more memory, and the software would be slower.
Let's assume that we would like to read 65535 sectors from USB-drive.
Using the dt-bit in the TD with mps=512 would need ~4Mb memory (size of TD-structure is 64 bytes).
Using the dt in QH, and transfering 0x5000 bytes per TD will be: 40* less.
It's also much faster not to create that many TDs.
We'll be able to help you only after you have managed to get the DD of an EHCI (i.e. high-speed) device. USB-2.0 external HUBs will also be found and their DDs can be retrieved, but a USB-keyboard or mouse can't because they are low-speed devices (UHCI or OHCI).