KeyLargoWatchDogTimer.cpp [plain text]
#include "KeyLargoWatchDogTimer.h"
#define super IOWatchDogTimer
OSDefineMetaClassAndStructors(KeyLargoWatchDogTimer, IOWatchDogTimer);
KeyLargoWatchDogTimer *KeyLargoWatchDogTimer::withKeyLargo(KeyLargo *keyLargo)
{
KeyLargoWatchDogTimer *watchDogTimer = new KeyLargoWatchDogTimer;
if (watchDogTimer == 0) return 0;
while (1) {
if (!watchDogTimer->init()) break;
watchDogTimer->attach(keyLargo);
if (watchDogTimer->start(keyLargo)) return watchDogTimer;
watchDogTimer->detach(keyLargo);
break;
}
return 0;
}
bool KeyLargoWatchDogTimer::start(IOService *provider)
{
keyLargo = OSDynamicCast(KeyLargo, provider);
if (keyLargo == 0) return false;
return super::start(provider);
}
void KeyLargoWatchDogTimer::setWatchDogTimer(UInt32 timeOut)
{
UInt32 timeLow, timeHigh, watchDogLow, watchDogHigh;
UInt64 offset, time;
if (timeOut != 0) {
offset = (UInt64)timeOut * kKeyLargoGTimerFreq;
timeLow = keyLargo->readRegUInt32(kKeyLargoCounterLoOffset);
timeHigh = keyLargo->readRegUInt32(kKeyLargoCounterHiOffset);
time = (((UInt64)timeHigh) << 32) + timeLow;
time += offset;
watchDogLow = time & 0x0FFFFFFFFULL;
watchDogHigh = time >> 32;
keyLargo->writeRegUInt32(kKeyLargoWatchDogLowOffset, watchDogLow);
keyLargo->writeRegUInt32(kKeyLargoWatchDogHighOffset, watchDogHigh);
}
keyLargo->writeRegUInt32(kKeyLargoWatchDogEnableOffset, (timeOut != 0) ? 1 : 0);
return;
}