PATH 
ADC Home > Documentation > Hardware > Device Managers and Drivers > PCI Card Services > Designing PCI Cards and Drivers for Power Macintosh Computers


  

Sample Code

Listing 12-2 shows sample code that retrieves power consumption information from a PCI device.

Listing 12-2 Determining power consumption

/*
* IEEE 1275 defines the "power-consumption" property.
*/
#define kDevicePowerProperty    "power-consumption"
/*
* Power values are encoded in a vector of "maximum in microwatts." Unspecified
* values shall be zero if other values are provided. Power consumption is 0 for
* missing values. If the property is missing, the default value will be used.
*/
enum{
    kUnspecifiedStandby,
    kUnspecifiedFullPower,
    kFiveVoltStandby,
    kFiveVoltFullPower,
    kThreeVoltStandby,
    kThreeVoltFullPower,
    kIOPowerStandby,
    kIOPowerFullPower,
    kReservedStandby,
    kReservedFullPower
};

/*
* The function uses this structure to equate registry entry values with
* DriverGestalt selectors.
*/
typedef structPowerInfo{
    OSType              driverGestaltSelector;
    short               correctIndex;
    short               fallbackIndex;
}PowerInfo;
static constPowerInfogPowerInfo[] ={
    { kDriverGestalt5MaxHighPower,  kFiveVoltFullPower,     kUnspecifiedFullPower   },
    { kDriverGestalt5MaxLowPower,   kFiveVoltStandby,       kUnspecifiedStandby     },
    { kDriverGestalt3MaxHighPower,  kThreeVoltFullPower,    kUnspecifiedFullPower   },
    { kDriverGestalt3MaxLowPower,   kThreeVoltStandby,      kUnspecifiedStandby     },
    { 0,                            0,                      0                       }
};

/******************************************
* Retrieve the driver power consumption vector and search it for the desired power
* consumption value. Return the desired value, or a default value if the desired
* value is unavailable. This function does not allocate memory or return any errors.
*/
UInt32
GetDevicePowerConsumption(
        RegEntryIDPtr   regEntryIDPtr,              /* driver's NameRegistryID */
        OSType          driverGestaltSelector,      /* PBStatus parameter */
        UInt32          defaultPowerConsumption     /* default return value */
    )
{
        OSErr                       status;
        UInt32                      result;
        short                       i;
        short                       index;
        ItemCount                   nValues;
        RegPropertyValueSize        size;
        UInt32                      microWatts[kReservedFullPower];
        result = defaultPowerConsumption;
        status = RegistryPropertyGetSize(
                    regEntryIDPtr,
                    kDevicePowerProperty,
                    &size
                );
        if (status == noErr && size <= sizeofmicroWatts){
        status = RegistryPropertyGet(
        regEntryIDPtr,
                    kDevicePowerProperty,
                    (RegPropertyValue *) microWatts,
                    &size
                );
        }
        if (status == noErr){
            nValues = size/sizeofmicroWatts[0];
            for (i = 0; gPowerInfo[i].driverGestaltSelector != 0; i++){
                if (gPowerInfo[i].driverGestaltSelector == driverGestaltSelector){
                    index = gPowerInfo[i].correctIndex;
                    if (index >= nValues)
                        index = gPowerInfo[i].fallbackIndex;
                        if (index < nValues)
                            result = microWatts[index];
                    break;
                }
            }
        }
        return (result);
}

© 1999 Apple Computer, Inc. – (Last Updated 26 March 99)