none
USB : UHCI hard coded loop instead of Sleep() (usb expert needed) RRS feed

  • Question

  • Hello, while debugging a usb-attach problem i saw something i don't understand.

    Our problem was that whenever you plugged in a  uhci device (USB1.0 ?) it would interrupt *almost* everything for arround 300 ms. This lead to problems in higher level software where certain timeouts where reached, resulting in a failure/shutdown/restart of the machine.

    I traced the problem to the UHCI driver : (this code comes from the public source WINCE8)

    VOID CHW::ResumeHostController()
    {
        if ( m_portBase != 0 ) {
            WORD wUSBCmd = Read_USBCMD();
            wUSBCmd |= UHCD_USBCMD_FORCE_GLOBAL_RESUME;
            Write_USBCMD(wUSBCmd);
            // I need 20 ms delay here 30(30ns)*1000*20
            for (DWORD dwIndex =0; dwIndex<30*1000*20; dwIndex++)
                Read_USBCMD();
            wUSBCmd &= ~(UHCD_USBCMD_FORCE_GLOBAL_RESUME | UHCD_USBCMD_ENTER_GLOBAL_SUSPEND_MODE);
            wUSBCmd |= UHCD_USBCMD_RUN_STOP;
            Write_USBCMD(wUSBCmd);
        }
        ResumeNotification();
    }


    Instead of 20 ms, that for loop runs for about 300ms, quite allot of time doing "nothing". 

    When trying to alter this code by using :

    Sleep(20); or while(i < 20){Sleep(1);}

    Other code (CAN messages) fails, when using 

            for (DWORD dwIndex =0; dwIndex<2*1000*20; dwIndex++) 
                Read_USBCMD();
    the other code, runs fine.

    Before trying to figuring the reason why sleep isn't good.  Is there an explicit reason why we would use a hard coded loop instead of a sleep here ?  

    Regards, Deckx Kevin


     
    • Edited by Kevin Deckx Tuesday, December 17, 2013 3:52 PM
    Tuesday, December 17, 2013 3:49 PM

All replies

  • Hello Kevin,

    I had the same Problem a few years ago ;) I ended up by just changing the registry settings for the USB Host (ehci&uhci):

    "HcdCapability"=dword:4   ;HCD_SUSPEND_ON_REQUEST

    Instead of

    "HcdCapability"=dword:5   ;HCD_SUSPEND_ON_REQUEST|HCD_SUSPEND_RESUME

    Best Regards

    Chris

     

    P.S. It’s so long ago, so I’m not 100% sure that this was the solution... 

    Wednesday, December 18, 2013 12:33 PM