Detecting ports on UHCI

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
SanderR
Member
Member
Posts: 70
Joined: Tue Aug 30, 2016 1:31 pm
Libera.chat IRC: SDR

Detecting ports on UHCI

Post by SanderR »

I am working on a UHCI driver.
When I boot my OS on Qemu or Bochs, it says there is a UHCI system with a device connected to the roothub.
When I boot my OS on real hardware, it says there is a UHCI system but it is not able to detect any device on the roothub.

The code I wrote:
https://github.com/AdeRegt/SanderOSUSB/tree/uhci_2

As you can see I did not put the "RUN" bit on because I have no idea how to run it and that the system is not doing anything (in case we have no devices attached) .
Does anyone have an idea of how to detect if a device is attached?

Thank you very much in advantage!!
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: Detecting ports on UHCI

Post by BenLunt »

I'm afraid to tell you that the USB is pretty much undefined until the Run bit is set. Sorry.

You can easily point it to a "dead" schedule and set the run bit. i.e.: The frame pointer can have a single dword pointing to itself or have 1024 entries all having the 'T' bit set.

Either way, real hardware may not function as specified until the Run bit is set.

Also, emulators don't have a timing issue whereas real hardware is very strict when it comes to timing. Make sure the timing between your reset and "un"reset and after the reset sequence is correct.

My book, linked below, goes into quite a bit of detail about all of this. However, feel free to continue to post your questions here. I try to visit about once a week and help as much as I can.

Ben
- http://www.fysnet.net/the_universal_serial_bus.htm
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: Detecting ports on UHCI

Post by BenLunt »

Just checking if adding a "dead" schedule and setting the Run bit allowed you to detect devices. If not, what is the status of your project?

Ben
- http://www.fysnet.net/osdesign_book_series.htm
SanderR
Member
Member
Posts: 70
Joined: Tue Aug 30, 2016 1:31 pm
Libera.chat IRC: SDR

Re: Detecting ports on UHCI

Post by SanderR »

Now the computer boots from the USB stick. the default state during boot is that it is running, but even then the bits of any device attached are switched off. I add some timer code to meet the 50ms sleep. Im afraid this does not help.

I updated the code on GitHub.

I tried the strategy to keep using the old queue to keep the system running and then wait a few seconds and then see if something is detected, but this does not seem to help. I first do a hardware reset (wait 50ms during reset), and then a port-reset(wait 50ms) and then wait two seconds before checking the registers for detections. should I send something specific to the port? should I maybe enable interrupts for UHCI?
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: Detecting ports on UHCI

Post by BenLunt »

You power the port, then you remove power from the port.

Code: Select all

  outportw(uhcibase+R_PORTS1,inportw(uhcibase+R_PORTS1) | 0b0000001000000000);
  outportw(uhcibase+R_PORTS2,inportw(uhcibase+R_PORTS2) | 0b0000001000000000);
  
  mssleep(5);
  
  outportw(uhcibase+R_PORTS1,(inportw(uhcibase+R_PORTS1) & 0b1111110111111111) | 0b0000000000000100);
  outportw(uhcibase+R_PORTS2,(inportw(uhcibase+R_PORTS2) & 0b1111110111111111) | 0b0000000000000100);
A port will not show a connection if there is no power....

Maybe you meant?

Code: Select all

  outportw(uhcibase+R_PORTS1,(inportw(uhcibase+R_PORTS1) & ~0b1111110111111111) | 0b0000000000000100);
  outportw(uhcibase+R_PORTS2,(inportw(uhcibase+R_PORTS2) & ~0b1111110111111111) | 0b0000000000000100);
However, note that technically, depending on where you are in the setup, you should know exactly what bits are set, so:

Code: Select all

  outportw(uhcibase+R_PORTS1,0b0000001000000100);
  outportw(uhcibase+R_PORTS2,0b0000001000000100);
works also. However, before you enable a port, you need to see if there is something connected, right?

Ben
- http://www.fysnet.net/the_universal_serial_bus.htm
Post Reply