USB stack architecture
Theo Markettos (89) 919 posts |
Could someone give a two-minute rundown on how the USB stack is organised? Am I right in thinking the hierarchy goes something like: {OHCIDriver, EHCIDriver} → {USBDriver} → {DeviceFS} → {SCSISoftUSB, hub/mouse/keyboard/printer drivers) Where do all the hub/HID/printer drivers live? In USBDriver, based on the NetBSD code? How is USBDriver organised? Is all the code in mixed/RiscOS/Sources/HWSupport/USB/ (apart from SCSISoftUSB) or does some live elsewhere? Is the directory mixed/RiscOS/Sources/HWSupport/USB/Prototypes/ for testing the OHCIDriver? Or is it for testing devices without having run the full stack (OHCIDriver/USBDriver) and just skips the bits where they would be? And a question for Jeffrey… how did you go about getting the Beagle USB up? Presumably you started by writing MUSBDriver, but how did you test it? Did you use some simple test cases (perhaps some of the examples mentioned above)? Or did you just load the rest of the stack and tweaked the driver until something worked? Thanks! |
Theo Markettos (89) 919 posts |
And a followup question… how does the Castle USB podule software relate to the Iyonix USB implementation? The podule has modules USBop (low level stuff?), USBReport, USBMice and USBKeybd, which don’t seem to fit in with the stack above. There’s a PHCIDriver in ROOL CVS which seems to be targeted at the podule but, looking at Castle’s USB podule firmware, neither it nor USBDriver are anywhere to be seen. And the podule firmware seems to post-date PHCIDriver. Was the podule an implementation of the DeviceFS USB API but written outside Pace, while PHCIDriver was Pace’s implementation on the same hardware? Or is PHCIDriver a red herring, for different podule hardware from the Castle card? It seems to be hardcoded to use slot 0, which looks a bit fishy to me. <some time later> Ah, I think they use different chips. The Castle card apparently uses a TDUHC124B, while PHCIDriver is for an ISP1161. Can’t find a register description of the TDUHC124/UHC124 but they don’t look software compatible. Was PHCIDriver for some kind of prototype podule that later got rolled into a STB?Are Castle’s USB modules (USBop, USBKeybd etc) covered by the ROOL licence? |
Jeffrey Lee (213) 6048 posts |
Correct (ish – see below)
The hub & HID code lives in USBDriver, and is a port of the NetBSD code. And since it’s kept internal to USBDriver, it’s able to bypass the DeviceFS interface and talk to the lower-level drivers directly. I believe all the USB printer code is here in the source tree.
There are basically three parts:
With regards to how it’s laid out in the source tree, the NetBSD/build folder contains all the RISC OS-specific bits, and the NetBSD/dev folder contains all the NetBSD bits (with some RISC OS modifications made, usually inside #ifdef riscos). This means that to build EHCIDriver, the core EHCI driver code from NetBSD/dev is needed, as well as the RISC OS frontend from NetBSD/build. Makefile hackery is used to allow the one makefile to build either one of the three different modules (USBDriver, EHCIDriver, OHCIDriver) – although it isn’t a perfect process at the moment since the modules always get partially rebuilt, so even for a minor code change I have to sit and twiddle my thumbs for an extra minute or two waiting for the ROM image to build :(
Actually since I have a rev C board I started by patching the EHCIDriver so it can use the HAL USB API to detect USB controllers, like the “rhenium” version of OHCIDriver. Then once I’d had enough fun taunting rev B owners I started on the MUSBDriver ;) The process was basically:
Because of the dependencies between the driver modules, this is really the only way to test a new USB controller driver. With debugging enabled you can get lots of debug output, which helps a lot when trying to work out what USBDriver is trying to do and what results it’s expecting to receive. And of course reading the appropriate bits of the USB spec was a big help! |
Theo Markettos (89) 919 posts |
Thanks. Never having seen them, do the XAT HID drivers disable the HID stuff in USBDriver, or do they work together? Interesting that you didn’t use the test harnesses to at least get something up… past experience suggests you don’t want to try something with the whole stack until you know at least the basics are up (eg look for successful ethernet packets being received before you plumb into the IP stack and try TCP). I suppose once you’ve reached that point you do need the full stack to debug the corner cases. |