RackMac3_1_InletTempCtrlLoop.cpp [plain text]
#include "IOPlatformPluginDefs.h"
#include "IOPlatformPluginSymbols.h"
#include "IOPlatformPlugin.h"
#include "IOPlatformSensor.h"
#include "RackMac3_1_InletTempCtrlLoop.h"
#define super IOPlatformPIDCtrlLoop
OSDefineMetaClassAndStructors(RackMac3_1_InletTempCtrlLoop, IOPlatformPIDCtrlLoop)
extern const OSSymbol * gRM31EnableSlewing;
IOReturn RackMac3_1_InletTempCtrlLoop::initPlatformCtrlLoop( const OSDictionary *dict)
{
IOReturn status;
const OSArray * array;
status = super::initPlatformCtrlLoop(dict);
if ((array = OSDynamicCast(OSArray, dict->getObject(kIOPPluginThermalSensorIDsKey))) == NULL)
{
CTRLLOOP_DLOG("RackMac3_1_InletTempCtrlLoop::initPlatformCtrlLoop no SensorIDArray\n");
return(kIOReturnError);
}
if ((inputSensor2 = OSDynamicCast(IOPlatformSensor, platformPlugin->lookupSensorByID( OSDynamicCast(OSNumber, array->getObject(1)) ))) == NULL)
{
CTRLLOOP_DLOG("RackMac3_1_InletTempCtrlLoop::initPlatformCtrlLoop no inlet temperature CPU B sensor ID!!\n");
return(kIOReturnError);
}
inputSensor2->retain();
addSensor( inputSensor2 );
return(status);
}
bool RackMac3_1_InletTempCtrlLoop::acquireSample( void )
{
inletATemperature = inputSensor->forceAndFetchCurrentValue();
inputSensor->setCurrentValue( inletATemperature );
inletBTemperature = inputSensor2->forceAndFetchCurrentValue();
inputSensor2->setCurrentValue( inletBTemperature );
return(true);
}
void RackMac3_1_InletTempCtrlLoop::deadlinePassed( void )
{
bool deadlineAbsolute;
SensorValue result;
deadlineAbsolute = (ctrlloopState == kIOPCtrlLoopFirstAdjustment);
timerCallbackActive = true;
if (!acquireSample())
{
CTRLLOOP_DLOG("RackMac3_1_CPUFanCtrlLoop::deadlinePassed FAILED TO ACQUIRE INPUT SAMPLE!!!\n");
}
result.sensValue = (inletATemperature.sensValue + inletBTemperature.sensValue)/2;
if( result.sensValue >= inputTarget.sensValue)
platformPlugin->setEnvArray(gRM31EnableSlewing, this, true);
else
platformPlugin->setEnvArray(gRM31EnableSlewing, this, false);
if (deadlineAbsolute)
{
AbsoluteTime adjustedInterval;
const OSNumber * id = getCtrlLoopID();
clock_interval_to_absolutetime_interval(100 * id->unsigned32BitValue(), NSEC_PER_USEC, &adjustedInterval);
ADD_ABSOLUTETIME( &adjustedInterval, &interval );
clock_absolutetime_interval_to_deadline(adjustedInterval, &deadline);
ctrlloopState = kIOPCtrlLoopAllRegistered;
}
else
{
ADD_ABSOLUTETIME(&deadline, &interval);
}
timerCallbackActive = false;
}