79
HANDLE m_hWDT=NULL;
TCHAR szClassName[60];
...
// assign the WDT driver name
wsprintf(szClassName, TEXT("WDT1:"));
// Open the WDT driver
m_hWDT = CreateFile(szClassName, GENERIC_READ | GENERIC_WRITE, 0,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if ( m_hWDT == INVALID_HANDLE_VALUE )
{
DebugMsg(CString("WDT driver fail"));
return;
}
...
DWORD dwTemp;
DWORD nPeriod=10000;
// Set the Watchdog Timer as 10 seconds (10000 mini-seconds)
DeviceIoControl(m_hWDT, IOCTL_SET_WDTPERIOD, &nPeriod, 4, NULL, 0, &dwTemp, NULL);
// Enable the Watchdog timer
DeviceIoControl(m_hWDT, IOCTL_ENABLE_WDT, NULL, NULL, NULL, 0, &dwTemp, NULL);
While (1)
{
// do your job here...
Sleep(8000);
DeviceIoControl(m_hWDT, IOCTL_ACCESS_WDT, NULL, NULL, NULL, 0, &dwTemp, NULL);
}
DeviceIoControl(m_hWDT, IOCTL_DISABLE_WDT, NULL, NULL, NULL, 0, NULL, NULL);
CloseHandle(m_hWDT);