none
Controlling power of a usb device RRS feed

  • Question

  • Hi all,

    our WinCE600 iMX51 board has some devices connected (such as wifi, bt, ..) on a USB bus.

    Is there a software command to powerup/down them?

     


    SteMMo
    Wednesday, February 1, 2012 5:16 PM

Answers

  • In %_WINCEROOT%\PUBLIC\COMMON\OAK\DRIVERS\PM\TEST you can find several examples:

    DEVSAMPLE - Sample power-managed device simulation (software only, no hardware)
    GET     - Gets the system power state using GetSystemPowerState
    GETD    - Gets device power level using GetDevicePower
    MON     - Monitor to receive & display power manager broadcasts
    REQ     -   Sets specific device power requirements using SetPowerRequirement
                and ReleasePowerRequirement.
    SET     - Sets the system power state using SetSystemPowerState
    SETD    - Sets device power level using SetDevicePower

    Obviously your OS must include the Power Manager component, the default one rather than the one provided in the iMX51 BSP if any


    Luca Calligaris lucaDOTcalligarisATeurotechDOTcom www.eurotech.com Check my blog: http://lcalligaris.wordpress.com
    • Edited by Luca Calligaris Thursday, February 2, 2012 10:47 AM typo
    • Marked as answer by SteMMo Thursday, February 2, 2012 11:08 AM
    Thursday, February 2, 2012 10:47 AM

All replies

  • If you mean an API to enable/disable the USB ports, no there's no one. 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 enabled/disabled by the USB host controller in several scenarios. It is possibly to add a custom IOCTL to the USB host controller code to enable/disable the various ports but likely when you call it you will mess up all the USB internal stack status. A cleaner solution would be using the power manager API to control the power status of the single USB devices (if they support it)


    Luca Calligaris lucaDOTcalligarisATeurotechDOTcom www.eurotech.com Check my blog: http://lcalligaris.wordpress.com
    Thursday, February 2, 2012 10:35 AM
  • Thanks,

    can you provide a sample or an example of a power manager API call, please?

     


    SteMMo
    Thursday, February 2, 2012 10:43 AM
  • In %_WINCEROOT%\PUBLIC\COMMON\OAK\DRIVERS\PM\TEST you can find several examples:

    DEVSAMPLE - Sample power-managed device simulation (software only, no hardware)
    GET     - Gets the system power state using GetSystemPowerState
    GETD    - Gets device power level using GetDevicePower
    MON     - Monitor to receive & display power manager broadcasts
    REQ     -   Sets specific device power requirements using SetPowerRequirement
                and ReleasePowerRequirement.
    SET     - Sets the system power state using SetSystemPowerState
    SETD    - Sets device power level using SetDevicePower

    Obviously your OS must include the Power Manager component, the default one rather than the one provided in the iMX51 BSP if any


    Luca Calligaris lucaDOTcalligarisATeurotechDOTcom www.eurotech.com Check my blog: http://lcalligaris.wordpress.com
    • Edited by Luca Calligaris Thursday, February 2, 2012 10:47 AM typo
    • Marked as answer by SteMMo Thursday, February 2, 2012 11:08 AM
    Thursday, February 2, 2012 10:47 AM
  • Thanks, i'm testing the sample called SETD.

    The problem is that whatever name i enter, the response is ERROR:2 that i suppose means ERROR_FILE_NOT_FOUND

    Example: i have a wifi device connected to a USB port. When i connect it i see the message

    NDISPWR:: BIND notification for adapter [VNUWLC61]

    so i assune that VNUVLC61 is the name i have to provide in the command line for SETD, but i always receive ERROR:2

     


    SteMMo
    Thursday, February 2, 2012 1:20 PM
  • My try was:

    setd {98C5250D-C29A-4985-AE5F-AFE5367E5006}\VNUWLC61 0 1

    The SetDevicePower() does not return error but the wifi card is still there.

    Another try:

    setd {98C5250D-C29A-4985-AE5F-AFE5367E5006}\DSK2: 0 1

    where DSK2: is a USB storage key. Again no error but the key is not unmounted.

     


    SteMMo
    Thursday, February 2, 2012 3:01 PM
  • The setd program usage is 'SETD <Device> <DeviceState> <HexDeviceFlags>'

    You're setting the DeviceState to 0 (D0) which is the highest device power states while 4 (D4) is the lowest one.

    See %_WINCEROOT%\PUBLIC\COMMON\SDK\INC\pm.h  (or http://msdn.microsoft.com/en-us/library/ee497766.aspx):

    //
    // Device Power States
    //
    typedef enum _CEDEVICE_POWER_STATE {
        PwrDeviceUnspecified = -1,
        D0 = 0, // Full On: full power,  full functionality
        D1,     // Low Power On: fully functional at low power/performance
        D2,     // Standby: partially powered with automatic wake
        D3,     // Sleep: partially powered with device initiated wake
        D4,     // Off: unpowered
        PwrDeviceMaximum
    } CEDEVICE_POWER_STATE, *PCEDEVICE_POWER_STATE;
    

    Do not expect the USB storage to be unmounted since the USB mass storage class does not handle any IOCTL_POWER_XXX code.

    About the possible error returned by SETD sample application (SetDevicePower actually), it will display as RETAILMSG so you'll see it if you're connected with PB with KITL enabled or on the debug serial port if you're not running a SHIP BUILD. If you run SETD sample application from the Windows CE command processor shell you won't see anything

     

     


    Luca Calligaris lucaDOTcalligarisATeurotechDOTcom www.eurotech.com Check my blog: http://lcalligaris.wordpress.com
    Thursday, February 2, 2012 3:17 PM
  • ok for the storage.

    I substituted every RETAILMSG with printf() then i have every output into the console.

    My tests with every value for Dx (0-4) did nothing and no errors.

    I found other questions on forums: someone recall DevicePowerNotify() and SetDevicePower().

    I also added DevicePowerNotify() but nothing happen and none of the functions return error.


    SteMMo
    Thursday, February 2, 2012 3:57 PM
  • I wrote it in a previous post: are you sure that the OS include the Power Manager component? The 'full' one? If you included the  'minimum' all the PM function are stubbed so no error but even no effect


    Luca Calligaris lucaDOTcalligarisATeurotechDOTcom www.eurotech.com Check my blog: http://lcalligaris.wordpress.com
    Thursday, February 2, 2012 4:00 PM
  • Yes, the image includes 'Power Management (Full)' cause the 'Standard shell' 

     

    In my test i read the settings by GetDevicePower() before and after the SetDevicePower() and it seem that the command is done.

    I.e. if i turn to D4 from D0 the device, i see that before the state is 0, then is 4.

    IS it possible that the driver doesn't support the call??

    I have only the binary image of the driver .. is it possible to understand if the power management is supported by the driver ?? 


    SteMMo

    • Edited by SteMMo Thursday, February 2, 2012 4:47 PM
    Thursday, February 2, 2012 4:26 PM
  • I'm trying to get the power capabilities by a DeviceIoCtrl() call:

    hnd = CreateFile( device, GENERIC_READ+GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
    if(hnd==INVALID_HANDLE_VALUE)
    {
    	printf("Error opening err=%d\n", GetLastError());
    }
    else
    {
    	BOOL ret = DeviceIoControl( hnd, IOCTL_POWER_CAPABILITIES, &pr, sizeof(pr), &pc, sizeof(pc), &bytesRet, 0);
    	printf( "hnd=%x ret=%d Dx=0x%X Flags=0x%X Power=%x\n", hnd, ret, pc.DeviceDx, pc.Flags, pc.Power);
    	CloseHandle(hnd);
    }
    
    

    I'm not sure which device name to use for the CreateFile().

    If i use

    setd {98C5250D-C29A-4985-AE5F-AFE5367E5006}\VNUWLC61 4 1


    i receive error 3 but if i use only setd 'VNUWLC61' i receive error 2.


    SteMMo
    Monday, February 6, 2012 2:12 PM
  • The registry items of the device don't have any IClass=(PowerGUID) and the driver doesn't expose xx_IoCtrl() so my guess is that the driver does not support Power Management.

     

    What about if the driver is a USB driver, it is not present in the enum of the Drivers/BuiltIn list?

     


    SteMMo
    Monday, February 6, 2012 2:52 PM