National Instruments TPC-2012 Personal Computer User Manual


 
Appendix D Watchdog Timer Programming on WinCE
© National Instruments Corporation D-5 TPC-2012 User Manual
IOCTL_WDT_REBOOT
If you want your application to trigger the watchdog, use
IOCTL_WDT_REBOOT to notify the watchdog driver timer (WDT).
Otherwise, the WDT triggers itself automatically.
lpInBuffer: unused
nInBufferSize: unused
lpOutBuffer: unused
nOutBufferSize: unused
Programming Example
#define WDT_CODE(ID) CTL_CODE(FILE_DEVICE_UNKNOWN,ID, METHOD_BUFFERED,
FILE_ANY_ACCESS)
#define IOCTL_WDT_ENABLE WDT_CODE (0x900)
#define IOCTL_WDT_DISABLE WDT_CODE(0x901)
#define IOCTL_WDT_STROBE WDT_CODE(0x902)
#define IOCTL_WDT_GET_TIMEOUT WDT_CODE(0x903)
#define IOCTL_WDT_SET_TIMEOUT WDT_CODE(0x904)
#define IOCTL_WDT_REBOOT WDT_CODE(0x905)
// for compatibility reasons, you can define IOCTL as below:
// #define IOCTL_WDT_ENABLE 0x1001
// #define IOCTL_WDT_DISABLE 0x1002
// #define IOCTL_WDT_STROBE 0x1003
// #define IOCTL_WDT_GETTIMEOUT 0x1004
// #define IOCTL_WDT_SETTIMEOUT 0x1005
// #define IOCTL_WDT_REBOOT 0x1006
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 nIndex=2;
// Set the Watchdog Timer as 10 seconds. Number 2 means 10 seconds.
DeviceIoControl(m_hWDT, IOCTL_WDT_SET_TIMEOUT, &nIndex, sizeof(nIndex),
NULL, 0, &dwTemp, NULL);
// Enable the Watchdog timer
DeviceIoControl(m_hWDT, IOCTL_WDT_ENABLE, NULL, 0, NULL, 0, &dwTemp, NULL);