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
0 | sleepQLink | long | pointer to next element in the queue |
4 | sleepQType | word | queue type (should be 16) |
6 | sleepQProc | long | pointer to a sleep procedure |
10 | sleepQFlags | word | reserved |
Hard Disk Queue Structure
0 | hdQLink | long | pointer to next element in the queue |
4 | hdQType | word | queue type (should be HDPwrQType ) |
6 | hdFlags | word | reserved |
8 | hdProc | long | pointer to a hard disk power-down procedure |
12 | hdUser | long | user defined |
Wakeup Time Structure
0 | wakeTime | long | wakeup time in seconds since 00:00:00, 1/1/1904 |
4 | wakeEnabled | byte | 1 = enable wakeup timer, 0 = disable timer |
Battery Information Structure
0 | flags | byte | flags |
1 | warningLevel | byte | scaled warning level (0--255) |
2 | reserved | byte | reserved |
3 | batteryLevel | byte | scaled battery level (0--255) |
Battery Time Structure
0 | expectedBatteryTime | long | estimated battery time remaining in seconds |
4 | minimumBatteryTime | long | minimum battery time remaining |
8 | maximumBatteryTime | long | maximum battery time remaining |
12 | timeUntilCharged | long | time remaining until battery is fully charged |
Trap Macros
Trap Macros Requiring Routine Selectors
_IdleState
Selector | Routine |
0 | EnableIdle |
Any positive number | DisableIdle |
Any negative number | GetCPUSpeed |
_SerialPower
Selector | Routine |
$04 | AOn |
$05 | AOnIgnoreModem |
$00 | BOn |
$84 | AOff |
$80 | BOff |
_PowerMgrDispatch
Selector | Routine |
$00 | PMSelectorCount |
$01 | PMFeatures |
$02 | GetSleepTimeout |
$03 | SetSleepTimeout |
$04 | GetHardDiskTimeout |
$05 | SetHardDiskTimeout |
$06 | HardDiskPowered |
$07 | SpinDownHardDisk |
$08 | IsSpindownDisabled |
$09 | SetSpindownDisable |
$0A | HardDiskQInstall |
$0B | HardDiskQRemove |
$0C | GetScaledBatteryInfo |
$0D | AutoSleepControl |
$0E | GetIntModemInfo |
$0F | SetIntModemState |
$10 | MaximumProcessorSpeed |
$11 | CurrentProcessorSpeed |
$12 | FullProcessorSpeed |
$13 | SetProcessorSpeed |
$14 | GetSCSIDiskModeAddress |
$15 | SetSCSIDiskModeAddress |
$16 | GetWakeupTimer |
$17 | SetWakeupTimer |
$18 | IsProcessorCyclingEnabled |
$19 | EnableProcessorCycling |
$1A | BatteryCount |
$1B | GetBatteryVoltage |
$1C | GetBatteryTimes |
$1D | GetDimmingTimeout |
$1E | SetDimmingTimeout |
$1F | DimmingControl |
$20 | IsDimmingControlDisabled |
$21 | IsAutoSlpControlDisabled
|
Result Codes
noErr | 0 | No error |
pmBusyErr | -13000 | Power Manager IC stuck busy |
pmReplyTOErr | -13001 | Timed out waiting to begin reply handshake |
pmSendStartErr | -13002 | Power Manager IC did not start handshake |
pmSendEndErr | -13003 | During send, Power Manager did not finish handshake |
pmRecvStartErr | -13004 | During receive, Power Manager did not start handshake |
pmRecvEndErr | -13005 | During receive, Power Manager did not finish handshake |