Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Devices /
Chapter 6 - Power Manager


Summary of the Power Manager

Pascal Summary

Constants

CONST
   {Power Manager Gestalt selector}
   gestaltPowerMgrAttr        = 'powr';   {Power Manager attributes selector}

   {bit values in Gestalt response parameter}
   gestaltPMgrExists          = 0;     {Power Manager is present}
   gestaltPMgrCPUIdle         = 1;     {CPU can idle}
   gestaltPMgrSCC             = 2;     {can stop SCC clock}
   gestaltPMgrSound           = 3;     {can shut off sound circuits}
   gestaltPMgrDispatchExists  = 4;     {Power Manager dispatch exists }
   slpQType                   = 16;    {sleep queue type}
   sleepQType                 = 16;    {sleep queue type}
   {bit positions for ModemStatus}
   modemOnBit                 = 0;     {1 if modem is on}
   ringWakeUpBit              = 2;     {1 if ring wakeup is enabled}
   modemInstalledBit          = 3;     {1 if internal modem is installed}
   ringDetectBit              = 4;     {1 if incoming call is detected}
   modemOnHookBit             = 5;     {1 if modem is off hook}
   {masks for ModemStatus}
   modemOnMask                = $1;    {modem on}
   ringWakeUpMask             = $4;    {ring wakeup enabled}
   modemInstalledMask         = $8;    {internal modem installed}
   ringDetectMask             = $10;   {incoming call detected}
   modemOnHookMask            = $20;   {modem off hook}
   {bit positions for BatteryStatus}
   chargerConnBit             = 0;     {1 if charger is connected}
   hiChargeBit                = 1;     {1 if charging at hicharge rate}
   chargeOverFlowBit          = 2;     {1 if hicharge counter has overflowed}
   batteryDeadBit             = 3;     {always 0}
   batteryLowBit              = 4;     {1 if battery is low}
   connChangedBit             = 5;     {1 if charger connection has changed}
{masks for BatteryStatus}
chargerConnMask      = $1;    {charger is connected}
hiChargeMask         = $2;    {charging at hicharge rate}
chargeOverFlowMask   = $4;    {hicharge counter has overflowed}
batteryDeadMask      = $8;    {battery is dead}
batteryLowMask       = $10;   {battery is low}
connChangedMask      = $20;   {connection has changed}
{sleep procedure selector codes}
sleepRequest         = 1;     {sleep request}
sleepDemand          = 2;     {sleep demand}
sleepWakeUp          = 3;     {wakeup demand}
sleepRevoke          = 4;     {sleep-request revocation}
{bits in bitfield returned by PMFeatures}
hasWakeupTimer       = 0;  {1 = wakeup timer is supported}
hasSharedModemPort   = 1;  {1 = modem port shared by SCC and internal modem}
hasProcessorCycling  = 2;  {1 = processor cycling is supported}
mustProcessorCycle   = 3;  {1 = processor cycling should not be turned off}
hasReducedSpeed      = 4;  {1 = processor can be started up at reduced speed}
dynamicSpeedChange   = 5;  {1 = processor speed can be switched dynamically}
hasSCSIDiskMode      = 6;  {1 = SCSI Disk Mode is supported}
canGetBatteryTime    = 7;  {1 = battery time can be calculated}
canWakeupOnRing      = 8;  {1 = can wakeup when the modem detects a ring}
hasDimmingSupport    = 9;  {1 = has dimming support built into the ROM}

{bits in BatteryInfo.flags}
batteryInstalled     = 7;  {1 = battery is currently connected}
batteryCharging      = 6;  {1 = battery is being charged}
chargerConnected     = 5;  {1 = charger is connected to the PowerBook }
                           { (this does not mean the charger is plugged in)}

{bits in bitfield returned by GetIntModemInfo}
hasInternalModem     = 0;  {1 = internal modem installed}
intModemRingDetect   = 1;  {1 = internal modem has detected a ring}
intModemOffHook      = 2;  {1 = internal modem is off hook}
intModemRingWakeEnb  = 3;  {1 = wakeup on ring is enabled}
extModemSelected     = 4;  {1 = external modem selected}

modemSetBit          = 15; {1 = set bit, 0=clear bit}

HDPwrQType           ='HD';{hard disk notification queue element type}

Data Types

TYPE SleepQRec = 
   RECORD
      sleepQLink:    SleepQRecPtr;  {next queue element}
      sleepQType:    Integer;       {queue type = 16}
      sleepQProc:    ProcPtr;       {pointer to sleep procedure}
      sleepQFlags:   Integer;       {reserved}
   END;
   SleepQRecPtr = ^SleepQRec;
TYPE HDQueueElement = 
   RECORD
      hdQLink:       Ptr;           {pointer to next queue element}
      hdQType:       Integer;       {queue element type (must be HDQType)}
      hdFlags:       Integer;       {miscellaneous flags}
      hdProc:        ProcPtr;       {pointer to routine to call}
      hdUser:        LongInt;       {user-defined (variable storage, etc.)}
   END;
TYPE WakeupTime = 
   PACKED RECORD
      wakeTime:      LongInt;       {wakeup time (same format as time)}
      wakeEnabled:   Byte;          {1 = enable, 0=disable wakeup timer}
   END;
TYPE BatteryInfo = 
   PACKED RECORD
      flags:         Byte;          {misc flags (see above)}
      warningLevel:  Byte;          {scaled warning level (0-255)}
      reserved:      Byte;          {reserved for internal use}
      batteryLevel:  Byte;          {scaled battery level (0-255)}
   END;
TYPE BatteryTimeRec = 
   RECORD

      expectedBatteryTime: LongInt; {estimated battery time remaining}
      minimumBatteryTime:  LongInt; {minimum battery time remaining}
      maximumBatteryTime:  LongInt; {maximum battery time remaining}
      timeUntilCharged:    LongInt; {time until battery is fully charged}
   END;

Power Manager Routines

Controlling the Idle State

FUNCTION IdleUpdate   : LongInt;
PROCEDURE EnableIdle;
PROCEDURE DisableIdle;
FUNCTION GetCPUSpeed  : LongInt;

Controlling and Reading the Wakeup Timer

FUNCTION SetWUTime      (WUTime: LongInt): OSErr;
FUNCTION DisableWUTime  : OSErr;
FUNCTION GetWUTime      (VAR WUTime: LongInt; VAR WUFlag: Byte): OSErr;

Controlling the Sleep Queue

PROCEDURE SleepQInstall   (qRecPtr: SleepQRecPtr);
PROCEDURE SleepQRemove    (qRecPtr: SleepQRecPtr);

Controlling Serial Power

PROCEDURE AOn;
PROCEDURE AOnIgnoreModem;
PROCEDURE BOn;
PROCEDURE AOff;
PROCEDURE BOff;

Reading the Status of the Internal Modem

FUNCTION ModemStatus     (VAR Status: Byte): OSErr;

Reading the Status of the Battery and the Battery Charger

FUNCTION BatteryStatus   (VAR Status: Byte; VAR Power: Byte): OSErr;

Power Manager Dispatch Routines

Determining the Power Manager Features Available

FUNCTION PMSelectorCount  : Integer;
FUNCTION PMFeatures       : LongInt;

Controlling the Sleep and Wakeup Timers

FUNCTION GetSleepTimeout           : Byte;
PROCEDURE SetSleepTimeout          (timeout : Byte);
PROCEDURE AutoSleepControl         (enableSleep : Boolean);
FUNCTION IsAutoSlpControlDisabled  () : Boolean;
PROCEDURE GetWakeupTimer           (VAR theTime : WakeupTime);
PROCEDURE SetWakeupTimer           (theTime : WakeupTime);

Controlling the Dimming Timer

FUNCTION GetDimmingTimeout         () : Byte;
PROCEDURE SetDimmingTimeout        (timeout : Byte);
PROCEDURE DimmingControl           (enableDimming : Boolean);
FUNCTION IsDimmingControlDisabled  () : Boolean;

Controlling the Hard Disk

FUNCTION GetHardDiskTimeout        : Byte;
PROCEDURE SetHardDiskTimeout       (timeout : Byte);
FUNCTION HardDiskPowered           : Boolean;
PROCEDURE SpinDownHardDisk;
FUNCTION IsSpindownDisabled        : Boolean;
PROCEDURE SetSpindownDisable       (setDisable : BOOLEAN);
FUNCTION HardDiskQInstall          (VAR theElement : HDQueueElement) : OSErr;
FUNCTION HardDiskQRemove           (VAR theElement : HDQueueElement) : OSErr;

Getting Information About the Battery

PROCEDURE GetScaledBatteryInfo      (whichBattery : Integer; VAR theInfo : 
BatteryInfo);
FUNCTION BatteryCount : Integer;
FUNCTION GetBatteryVoltage          (whichBattery : Integer) : Fixed;
PROCEDURE GetBatteryTimes           (whichBattery : INTEGER; VAR theTimes : 
                                     BatteryTimeRec);

Controlling the Internal Modem

FUNCTION GetIntModemInfo    : LongInt;
PROCEDURE SetIntModemState  (theState : Integer);

Controlling the Processor

FUNCTION MaximumProcessorSpeed      : Integer;
FUNCTION CurrentProcessorSpeed      : Integer;
FUNCTION FullProcessorSpeed         : Boolean;
FUNCTION SetProcessorSpeed          (fullSpeed : Boolean) : Boolean;
FUNCTION IsProcessorCyclingEnabled  : Boolean;
PROCEDURE EnableProcessorCycling    (enable : Boolean);

Getting and Setting the SCSI ID

FUNCTION GetSCSIDiskModeAddress     : Integer;
PROCEDURE SetSCSIDiskModeAddress    (scsiAddress : Integer);

Application-Defined Routines

PROCEDURE MySleepProc;
PROCEDURE MyHDSpindownProc  (theElement : HDQueueElement);

C Summary

Constants and Data Types

/* Power Manager Gestalt selector */
#define gestaltPowerMgrAttr 'powr'  /* Power Manager attributes selector */

/* bit values in Gestalt response parameter */
enum {
   gestaltPMgrExists          = 0,     /* Power Manager is present */
   gestaltPMgrCPUIdle         = 1,     /* CPU can idle */
   gestaltPMgrSCC             = 2,     /* can stop SCC clock */
   gestaltPMgrSound           = 3,     /* can shut off sound circuits */
   gestaltPMgrDispatchExists  = 4      /* Power Manager dispatch exists */
};
enum {
   slpQType                   = 16,    /* sleep queue type */
   sleepQType                 = 16     /* sleep queue type */
};
enum {
   /* bit positions for ModemStatus */
   modemOnBit                 = 0,     /* 1 if modem is on */
   ringWakeUpBit              = 2,     /* 1 if ring wakeup is enabled */
   modemInstalledBit       = 3,     /* 1 if internal modem is installed */
   ringDetectBit           = 4,     /* 1 if incoming call is detected */
   modemOnHookBit          = 5,     /* 1 if modem is off hook */
   /* masks for ModemStatus */
   modemOnMask             = 0x1,   /* modem on */
   ringWakeUpMask          = 0x4,   /* ring wakeup enabled */
   modemInstalledMask      = 0x8,   /* internal modem installed */
   ringDetectMask          = 0x10,  /* incoming call detected */
   modemOnHookMask         = 0x20,  /* modem off hook */
   /* bit positions for BatteryStatus */
   chargerConnBit          = 0,     /* 1 if charger is connected */
   hiChargeBit             = 1,     /* 1 if charging at hicharge rate */
   chargeOverFlowBit       = 2,     /* 1 if hicharge counter has overflowed */
   batteryDeadBit          = 3,     /* always 0 */
   batteryLowBit           = 4,     /* 1 if battery is low */
   connChangedBit          = 5,     /* 1 if charger connection has changed */
   /* masks for BatteryStatus */
   chargerConnMask         = 0x1,   /* charger is connected */
   hiChargeMask            = 0x2,   /* charging at hicharge rate */
   chargeOverFlowMask      = 0x4,   /* hicharge counter has overflowed */
   batteryDeadMask         = 0x8,   /* battery is dead */
   batteryLowMask          = 0x10,  /* battery is low */
   connChangedMask         = 0x20,  /* connection has changed */
   /* sleep procedure selector codes */
   sleepRequest            = 1,     /* sleep request */
   sleepDemand             = 2,     /* sleep demand */
   sleepWakeUp             = 3,     /* wakeup demand */
   sleepRevoke             = 4      /* sleep-request revocation */
};
/* bits in bitfield returned by PMFeatures */
#define hasWakeupTimer 0            /* 1 = wakeup timer is supported */
#define hasSharedModemPort 1        /* 1 = modem port shared by SCC and */
                                    /*  internal modem */
#define hasProcessorCycling 2       /* 1 = processor cycling is supported */
#define mustProcessorCycle 3        /* 1 = processor cycling should not be */
                                    /*  turned off */
#define hasReducedSpeed 4           /* 1 = processor can be started up at */
                                    /*  reduced speed */
#define dynamicSpeedChange 5        /* 1 = processor speed can be */
                                    /* switched dynamically */
#define hasSCSIDiskMode 6     /* 1 = SCSI Disk Mode is supported */
#define canGetBatteryTime 7   /* 1 = battery time can be calculated */
#define canWakeupOnRing 8     /* 1 = can wakeup when the modem detects */
                              /*  a ring */
#define hasDimmingSupport 9   /* 1 = has dimming support built into the ROM */
/* bits in bitfield returned by GetIntModemInfo and set by SetIntModemState */
#define hasInternalModem 0    /* 1 = internal modem installed */
#define intModemRingDetect 1  /* 1 = internal modem has detected a ring */
#define intModemOffHook 2     /* 1 = internal modem is off hook */
#define intModemRingWakeEnb 3 /* 1 = wakeup on ring is enabled */
#define extModemSelected 4    /* 1 = external modem selected */

#define modemSetBit 15        /* 1 = set bit, 0=clear bit (SetIntModemState) */
/* bits in BatteryInfo.flags */
#define batteryInstalled 7    /* 1 = battery is currently connected */
#define batteryCharging 6     /* 1 = battery is being charged */
#define chargerConnected 5    /* 1 = charger is connected to the PowerBook */
                              /*  (this does not mean the charger is */
                              /*  plugged in) */
struct SleepQRec {
   struct SleepQRec  *sleepQLink;   /* next queue element */
   short             sleepQType;    /* queue type = 16 */
   ProcPtr           sleepQProc;    /* pointer to sleep procedure */
   short             sleepQFlags;   /* reserved */
};
typedef struct SleepQRec SleepQRec;
typedef SleepQRec *SleepQRecPtr;
/* hard disk spindown notification queue element */
typedef struct HDQueueElement HDQueueElement;

typedef pascal void (*HDSpindownProc)(HDQueueElement *theElement);

struct HDQueueElement {
   Ptr hdQLink;            /* pointer to next queue element */
   short hdQType;          /* queue element type (must be HDQType) */
   short hdFlags;          /* miscellaneous flags */
   HDSpindownProc hdProc;  /* pointer to routine to call */
   long hdUser;            /* user-defined private storage */
};
#define HDPwrQType 'HD'    /* queue element type */
/* wakeup time record */
typedef struct WakeupTime {
   unsigned long wakeTime;    /* wakeup time (same format as current time) */
   char wakeEnabled;          /* 1 = enable wakeup timer, 0=disable */
} WakeupTime;
/* battery time information (in seconds) */
typedef struct BatteryTimeRec {
   unsigned long expectedBatteryTime; /* estimated battery time remaining */
   unsigned long inimumBatteryTime;  /* minimum battery time remaining */
   unsigned long maximumBatteryTime; /* maximum battery time remaining */
   unsigned long timeUntilCharged;   /* time until battery is fully charged */
} BatteryTimeRec;

Power Manager Functions

Controlling the Idle State

pascal long IdleUpdate   (void);
pascal void EnableIdle   (void);
pascal void DisableIdle  (void);
pascal long GetCPUSpeed  (void);

Controlling and Reading the Wakeup Timer

pascal OSErr SetWUTime       (long WUTime);
pascal OSErr DisableWUTime   (void);
pascal OSErr GetWUTime       (long *WUTime, Byte *WUFlag);

Controlling the Sleep Queue

pascal void SleepQInstall  (SleepQRecPtr qRecPtr);
pascal void SleepQRemove   (SleepQRecPtr qRecPtr);

Controlling Serial Power

pascal void AOn             (void);
pascal void AOnIgnoreModem  (void);
pascal void BOn             (void);
pascal void AOff            (void);
pascal void BOff            (void);

Reading the Status of the Internal Modem

pascal OSErr ModemStatus    (Byte *Status);

Reading the Status of the Battery and the Battery Charger

pascal OSErr BatteryStatus  (Byte *Status, Byte *Power);

Power Manager Dispatch Functions

Determining the Power Manager Features Available

short PMSelectorCount       (void);
unsigned long PMFeatures    (void);

Controlling the Sleep and Wakeup Timers

unsigned char GetSleepTimeout     (void);
void SetSleepTimeout              (unsigned char timeout);
void AutoSleepControl             (Boolean enableSleep);
Boolean IsAutoSlpControlDisabled  (void);
void GetWakeupTimer               (WakeupTime *theTime);
void SetWakeupTimer               (WakeupTime *theTime);

Controlling the Dimming Timer

unsigned char GetDimmingTimeout   (void);
void SetDimmingTimeout            (unsigned char timeout);
void DimmingControl               (Boolean enableDimming);
Boolean IsDimmingControlDisabled  (void);

Controlling the Hard Disk

unsigned char GetHardDiskTimeout  (void);
void SetHardDiskTimeout           (unsigned char timeout);
Boolean HardDiskPowered           (void);
void SpinDownHardDisk             (void);
Boolean IsSpindownDisabled        (void);
void SetSpindownDisable           (Boolean setDisable);
OSErr HardDiskQInstall            (HDQueueElement *theElement);
OSErr HardDiskQRemove             (HDQueueElement *theElement);

Getting Information About the Battery

void GetScaledBatteryInfo      (short whichBattery, BatteryInfo *theInfo);
short BatteryCount             (void);
Fixed GetBatteryVoltage        (short whichBattery);
void GetBatteryTimes           (short whichBattery, BatteryTimeRec *theTimes);

Controlling the Internal Modem

unsigned long GetIntModemInfo  (void);
void SetIntModemState          (short theState);

Controlling the Processor

short MaximumProcessorSpeed        (void);
short CurrentProcessorSpeed        (void);
Boolean FullProcessorSpeed         (void);
Boolean SetProcessorSpeed          (Boolean fullSpeed);
Boolean IsProcessorCyclingEnabled  (void);
void EnableProcessorCycling        (Boolean enable);

Getting and Setting the SCSI ID

short GetSCSIDiskModeAddress  (void);
void SetSCSIDiskModeAddress   (short scsiAddress);

Application-Defined Functions

void MySleepProc        (void);
void (*HDSpindownProc)  (HDQueueElement *theElement);

Assembly-Language Summary

Data Structures

Sleep Queue Data Structure
0sleepQLinklongpointer to next element in the queue
4sleepQTypewordqueue type (should be 16)
6sleepQProclongpointer to a sleep procedure
10sleepQFlagswordreserved

Hard Disk Queue Structure
0hdQLinklongpointer to next element in the queue
4hdQTypewordqueue type (should be HDPwrQType)
6hdFlagswordreserved
8hdProclongpointer to a hard disk power-down procedure
12hdUserlonguser defined

Wakeup Time Structure
0wakeTimelongwakeup time in seconds since 00:00:00, 1/1/1904
4wakeEnabledbyte1 = enable wakeup timer, 0 = disable timer

Battery Information Structure
0flagsbyteflags
1warningLevelbytescaled warning level (0--255)
2reservedbytereserved
3batteryLevelbytescaled battery level (0--255)

Battery Time Structure
0expectedBatteryTimelongestimated battery time remaining in seconds
4minimumBatteryTimelongminimum battery time remaining
8maximumBatteryTimelongmaximum battery time remaining
12timeUntilChargedlongtime remaining until battery is fully charged

Trap Macros

Trap Macros Requiring Routine Selectors

_IdleState
SelectorRoutine
0EnableIdle
Any positive numberDisableIdle
Any negative numberGetCPUSpeed
_SerialPower
SelectorRoutine
$04AOn
$05AOnIgnoreModem
$00BOn
$84AOff
$80BOff
_PowerMgrDispatch
SelectorRoutine
$00PMSelectorCount
$01PMFeatures
$02GetSleepTimeout
$03SetSleepTimeout
$04GetHardDiskTimeout
$05SetHardDiskTimeout
$06HardDiskPowered
$07SpinDownHardDisk
$08IsSpindownDisabled
$09SetSpindownDisable
$0AHardDiskQInstall
$0BHardDiskQRemove
$0CGetScaledBatteryInfo
$0DAutoSleepControl
$0EGetIntModemInfo
$0FSetIntModemState
$10MaximumProcessorSpeed
$11CurrentProcessorSpeed
$12FullProcessorSpeed
$13SetProcessorSpeed
$14GetSCSIDiskModeAddress
$15SetSCSIDiskModeAddress
$16GetWakeupTimer
$17SetWakeupTimer
$18IsProcessorCyclingEnabled
$19EnableProcessorCycling
$1ABatteryCount
$1BGetBatteryVoltage
$1CGetBatteryTimes
$1DGetDimmingTimeout
$1ESetDimmingTimeout
$1FDimmingControl
$20IsDimmingControlDisabled
$21IsAutoSlpControlDisabled

Result Codes

noErr0No error
pmBusyErr-13000Power Manager IC stuck busy
pmReplyTOErr-13001Timed out waiting to begin reply handshake
pmSendStartErr-13002Power Manager IC did not start handshake
pmSendEndErr-13003During send, Power Manager did not finish handshake
pmRecvStartErr-13004During receive, Power Manager did not start handshake
pmRecvEndErr-13005During receive, Power Manager did not finish handshake


Previous Book Contents Book Index Next

© Apple Computer, Inc.
3 JUL 1996