PowerMac7_2_PIDCtrlLoop.cpp [plain text]
#include "IOPlatformPluginDefs.h"
#include "IOPlatformPluginSymbols.h"
#include "IOPlatformPlugin.h"
#include "IOPlatformSensor.h"
#include "PowerMac7_2_PIDCtrlLoop.h"
#define super IOPlatformPIDCtrlLoop
OSDefineMetaClassAndStructors(PowerMac7_2_PIDCtrlLoop, IOPlatformPIDCtrlLoop)
extern const OSSymbol * gPM72EnvSystemUncalibrated;
bool PowerMac7_2_PIDCtrlLoop::updateMetaState( void )
{
const OSArray * metaStateArray;
const OSDictionary * metaStateDict;
const OSNumber * newMetaState;
if ((metaStateArray = OSDynamicCast(OSArray, infoDict->getObject(gIOPPluginThermalMetaStatesKey))) == NULL)
{
CTRLLOOP_DLOG("PowerMac7_2_PIDCtrlLoop::updateMetaState no meta state array\n");
return(false);
}
if ((platformPlugin->envArrayCondIsTrue(gIOPPluginEnvExternalOvertemp)) ||
(platformPlugin->getEnv(gPM72EnvSystemUncalibrated)) != NULL)
{
CTRLLOOP_DLOG("PowerMac7_2_PIDCtrlLoop::updateMetaState Entering Overtemp Mode\n");
if ((metaStateDict = OSDynamicCast(OSDictionary, metaStateArray->getObject(1))) != NULL &&
(cacheMetaState( metaStateDict ) == true))
{
setMetaState( gIOPPluginOne );
return(true);
}
else
{
CTRLLOOP_DLOG("PowerMac7_2_PIDCtrlLoop::updateMetaState Overtemp Mode Failed!\n");
}
}
if ((metaStateDict = OSDynamicCast(OSDictionary, infoDict->getObject(gIOPPluginForceCtrlLoopMetaStateKey))) != NULL)
{
if (cacheMetaState( metaStateDict ) == true)
{
CTRLLOOP_DLOG("PowerMac7_2_PIDCtrlLoop::updateMetaState using forced meta state\n");
newMetaState = OSNumber::withNumber( 0xFFFFFFFF, 32 );
setMetaState( newMetaState );
newMetaState->release();
return(true);
}
else
{
CTRLLOOP_DLOG("PowerMac7_2_PIDCtrlLoop::updateMetaState forced meta state is invalid, removing...\n");
infoDict->removeObject(gIOPPluginForceCtrlLoopMetaStateKey);
}
}
if ((metaStateDict = OSDynamicCast(OSDictionary, metaStateArray->getObject(0))) != NULL &&
(cacheMetaState( metaStateDict ) == true))
{
setMetaState( gIOPPluginZero );
return(true);
}
else
{
CTRLLOOP_DLOG("PowerMac7_2_PIDCtrlLoop::updateMetaState no valid meta states!\n");
return(false);
}
}
ControlValue PowerMac7_2_PIDCtrlLoop::calculateNewTarget( void ) const
{
SInt32 dRaw, rRaw;
SInt64 accum, dProd, rProd, pProd;
SInt32 result;
ControlValue newTarget;
samplePoint * latest;
if (overrideActive)
{
CTRLLOOP_DLOG("*** PID *** Override Active\n");
newTarget = outputOverride->unsigned32BitValue();
}
else
{
if (ctrlloopState == kIOPCtrlLoopFirstAdjustment)
{
result = 0;
}
else
{
result = (SInt32)outputControl->getTargetValue();
dRaw = calculateDerivativeTerm().sensValue;
accum = dProd = (SInt64)G_d * (SInt64)dRaw;
rRaw = calculateIntegralTerm().sensValue;
rProd = (SInt64)G_r * (SInt64)rRaw;
accum += rProd;
latest = sampleAtIndex(0);
pProd = (SInt64)G_p * (SInt64)latest->error.sensValue;
accum += pProd;
accum >>= 36;
result += (SInt32)accum;
}
newTarget = (UInt32)(result > 0) ? result : 0;
if (newTarget < outputMin)
newTarget = outputMin;
else if (newTarget > outputMax)
newTarget = outputMax;
}
return(newTarget);
}