none
API for USB Port reset in WINCE RRS feed

  • Question

  • Hi

    I'm trying to find a USB API which will do a USB port reset (a equivalent implementation in windows would be http://www.osronline.com/ddkx/buses/usbirp_3ctu.htm". LPDISABLE_DEVICE will do a power cycle of the port, but I dont want to power cycle my device.

    I just want to reset the port. Is there a way in Windows CE. Kindly help me out on this.


    Karthikeyan
    • Moved by Jesse Jiang Monday, May 30, 2011 7:00 AM (From:Windows Mobile Development)
    Thursday, May 26, 2011 6:43 PM

All replies

  • Hi Karthikeyan,

     

    I think your issue should be raised in the Windows Embedded Compact Platform Development. I believe they will know more information of this issue than us, and I will move this one to that forum.

     

    Thanks for your understanding,

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 30, 2011 7:00 AM
  • In Windows CE there is not an USB API, i.e. a programming interface which allows user mode code to perform arbitrary tasks on the bus. The USB ports are reset by the USB host controller in several scenarios (for example during device configuration). It is possiblr to add a custom IOCTL to the USB host controller code to reset the port (check for 'ResetAndEnablePort' in the USB host controller code) but likely when you call it you will mess up all the USB internal stack status
    Luca Calligaris lucaDOTcalligarisATeurotechDOTcom www.eurotech.com Check my blog: http://lcalligaris.wordpress.com
    Monday, May 30, 2011 7:58 AM
  • Thanks a lot for your response. We are a device manufacturing company so we don't get to modify controller code. The reason why I'm looking out for such a option is to perform firmware download to our device. So when I issue a USB reset the firmware jumps from functional mode to boot loader mode and then we start the download process. Is it possible to do the rest thru USB device driver? that way I can add an IOCTL to my functional device driver and when the user app issues this IOCTL the device driver will perform the reset.


    Karthikeyan
    Friday, June 3, 2011 3:07 AM
  • I don't understand why this requires a USB reset.   I really don't understand what resetting the USB controller has to do with "the firmware jumps from functional mode to boot loader mode".

    But ignoring my lack of understanding, of course you can modify your driver to do anything that you want it to do. 


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com
    Friday, June 3, 2011 12:28 PM
    Moderator
  • I have the same problem also... Sometimes my usb device stops responding because of a bug in the power up and power down function of the usb drivers, and I don't have control over the code in PB nor in the USB drivers. When I unplug and plug my usb device manually, then the device starts working again. so as an application developer, all i want to do is disconnect the usb and reconnect it via WindowsCE software commands. Anyone have any example code?
    Sunday, October 16, 2011 7:49 PM
  • HI mk_cs.

    Have you solved the problem?. Cold you please explain me how to rest usb port?

    Thanks

    Enrico

    Tuesday, January 29, 2013 4:01 PM
  • As Luca mentioned, you can add a custom IOCONTROL code to reset the host port. i shown a sample code to power off/on etc.. on the host port PDD driver for PXA3xx based device. you can open the driver using "HCD1:" as a driver name.
    #define IOCTL_USB_SUSPEND	0x4000000
    #define IOCTL_USB_RESUME	0x4000001
    #define IOCTL_USB_SUSPEND_ALL	0x4000002
    #define IOCTL_USB_RESUME_ALL	0x4000003
    #define IOCTL_USB_POWER_ON	0x4000004
    #define IOCTL_USB_POWER_OFF	0x4000005
    #define IOCTL_USB_HOST_POWER_ON 0x4000006
    #define IOCTL_USB_HOST_POWER_OFF 0x4000007
    #define IOCTL_USB_POWER_STATUS		0x4000008
    
    extern "C" BOOL HcdPdd_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn,
            DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut)
    {
    	BOOL Retval;
    	PPOWER_CAPABILITIES PowerCaps;
    	CEDEVICE_POWER_STATE NewDx;
    	SOhcdPdd * pPddObject = (SOhcdPdd *)hOpenContext;
    
    	RETAILMSG (1, (TEXT("\r\nHCD_IOControl+ dwCode: 0x%x\r\n"),dwCode));
    	switch (dwCode)
    	{
    		case IOCTL_POWER_CAPABILITIES:
    			NKDbgPrintfW(L"HCD::Get capability for USB Host driver Lenout = 0x%x\r\n",dwLenOut);
           	     	   	if ( pBufOut != NULL && dwLenOut == sizeof(*PowerCaps) )
    	           	{
            	        	NKDbgPrintfW(L"HCD IOCTL_POWER_CAPABILITIES\r\n");
                    		PowerCaps = (PPOWER_CAPABILITIES) pBufOut;
    		                memcpy(PowerCaps, &DrvPowerCaps, sizeof(DrvPowerCaps));
    				*pdwActualOut=sizeof(*PowerCaps);
            		        Retval = TRUE;
                		}
                		else
               		{
               	     		SetLastError(MMSYSERR_INVALPARAM);
              	    		Retval = FALSE;
              		}
    	        break;
    		case IOCTL_POWER_QUERY:
               	NKDbgPrintfW(L"Power query for USB HCD driver\r\n");
               	if ( pBufOut != NULL && dwLenOut == sizeof(CEDEVICE_POWER_STATE) )
               	{
                  		// Return a good status on any valid query since
                 		// we are always ready to change power states.
    	            	NewDx = *(PCEDEVICE_POWER_STATE) pBufOut;
    		
    			NKDbgPrintfW(L"USB HCD IOCTL_POWER_QUERY-(D%d) success (D%d)\r\n",NewDx,*pBufIn);
    	           	if ( ! VALID_DX(NewDx) )
            	        {
                    		Retval = TRUE;
    	                }
                	}
                	break;
    	        case IOCTL_POWER_SET:
               	if ( pBufOut != NULL && dwLenOut == sizeof(CEDEVICE_POWER_STATE) )
                	{
                    	NewDx = *(PCEDEVICE_POWER_STATE)pBufOut;
    			NKDbgPrintfW(L"Size of input:%d\r\nSize of output:%d\r\n",dwLenIn,dwLenOut);
    			if(dwLenIn>0)
    				NKDbgPrintfW(L"USB HCD IOCTL_POWER_QUERY-(D%d) success (D%d)\r\n",NewDx,*pBufIn);
    			else
    				NKDbgPrintfW(L"USB HCD IOCTL_POWER_QUERY-(D%d) success \r\n",NewDx);
                    	if ( VALID_DX(NewDx) )
                    	{
    	        	        SetPmPowerState(NewDx,pPddObject);
            	        	Retval = TRUE;
                            }
               	}
    	        break;
    	        case IOCTL_POWER_GET:
            		NKDbgPrintfW(L"USB HCD::IOCTL_POWER_GET\r\n");
    		        if ( pBufOut != NULL && dwLenOut == sizeof(CEDEVICE_POWER_STATE) )
    		        {
                    		*(PCEDEVICE_POWER_STATE) pBufOut = GetPmPowerState();
    		                Retval = TRUE;
                		}
    	 	break;
    		case IOCTL_USB_SUSPEND:
    			NKDbgPrintfW(L"USB HCD:IOCTL_USB_SUSPEND\r\n");
    			pPddObject->SelectUSBHOSTPowerManagementMode( USBOHCI_PORT_SUSPEND, 0, 0 );
    		break;
    		case IOCTL_USB_RESUME:
    			NKDbgPrintfW(L"USB HCD:IOCTL_USB_RESUME\r\n");
    			pPddObject->SelectUSBHOSTPowerManagementMode( USBOHCI_PORT_RESUME, 0, 0 );
    		break;
    		case IOCTL_USB_SUSPEND_ALL:
    			NKDbgPrintfW(L"USB HCD:IOCTL_USB_SUSPEND_ALL\r\n");
    			pPddObject->PowerDown();
    		break;
    		case IOCTL_USB_RESUME_ALL:
    			NKDbgPrintfW(L"USB HCD:IOCTL_USB_RESUME_ALL\r\n");
    			pPddObject->PowerUp();
    		break;
    		case IOCTL_USB_HOST_POWER_ON:
    			pPddObject->SelectUSBHOSTPowerManagementMode( USBOHCI_HOST_POWER_ON, 0, 0 );
    			g_PortPowerStatus = STATUS_HOST_PORT1_ON | STATUS_HOST_PORT2_ON | STATUS_HOST_PORT3_ON;	
    		break;
    		case IOCTL_USB_HOST_POWER_OFF:
    			pPddObject->SelectUSBHOSTPowerManagementMode( USBOHCI_HOST_POWER_OFF, 0, 0 );
    			g_PortPowerStatus &= ~(STATUS_HOST_PORT1_ON | STATUS_HOST_PORT2_ON | STATUS_HOST_PORT3_ON);	
    		break;
    		case IOCTL_USB_POWER_ON:
    			{
    				int portnum=*pBufIn;
    				pPddObject->SelectUSBHOSTPowerManagementMode( USBOHCI_PORT_POWER_ON, portnum, 0 );
    				if(portnum == 1)
    					g_PortPowerStatus |= STATUS_HOST_PORT1_ON;
    				else if(portnum ==2)
    					g_PortPowerStatus |= STATUS_HOST_PORT2_ON;
    				else if(portnum == 3)
    					g_PortPowerStatus |= STATUS_HOST_PORT3_ON;
    			}
    		break;
    		case IOCTL_USB_POWER_OFF:
    			{
    			int portnum=*pBufIn;
    			pPddObject->SelectUSBHOSTPowerManagementMode( USBOHCI_PORT_POWER_OFF, portnum, 0 );	
    				if(portnum == 1)
    					g_PortPowerStatus &= ~STATUS_HOST_PORT1_ON;
    				else if(portnum ==2)
    					g_PortPowerStatus &= ~STATUS_HOST_PORT2_ON;
    				else if(portnum == 3)
    					g_PortPowerStatus &= ~STATUS_HOST_PORT3_ON;
    			}
    		break;
    		case IOCTL_USB_POWER_STATUS:
    		{
    		    int portnum=*pBufIn;
    		    pPddObject->SelectUSBHOSTPowerManagementMode( USBOHCI_PORT_POWER_STATUS, portnum, (int*)pBufOut );	
    		}
    		break;
    	}
        return Retval;
    }



    Vinoth.R

    www.e-consystems.com

    http://vinoth-vinothblog.blogspot.com

    Wednesday, January 30, 2013 6:38 AM