static DWORD WINAPI DSInterruptThread(LPVOID p)
{
DWORD RetVal = 0;
HANDLE hEvent;
DWORD SysintrValue;
DWORD IRQ = MYDRIVER_IRQ;
// Create an Event
hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
// Register with the Kernel
KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &IRQ, sizeof(DWORD), &SysintrValue, sizeof(DWORD), NULL) ;
RetVal = InterruptInitialize( SysintrValue, hEvent, NULL, 0 );
// Set the Thread Priority
CeSetThreadPriority(GetCurrentThread(), 150);
while (1)
{
// Wait for the Event to be Signaled
RetVal = WaitForSingleObject(hEvent, 2000 );
if( RetVal == WAIT_OBJECT_0 )
{
// Service the Interrupt
// In this case suspend the device
SetSystemPowerState(NULL, POWER_STATE_SUSPEND, POWER_FORCE);
// Tell the Kernel that the Interrupt has been Serviced
InterruptDone( SysintrValue );
}
else if( RetVal == WAIT_TIMEOUT )
{
// Optional, provide a way to stop the thread when the driver unloads
// This is optional because the driver may never unload
if( StopThreads )
break;
}
}
// When and if the driver unloads and the thread exits release resources
InterruptDisable( SysintrValue );
CloseHandle( hEvent );
KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &SysintrValue, sizeof(DWORD), NULL, 0, NULL);
return 0;
}
As Valter noted in his comment, there are many ways to write an IST. So this is only one way to do it.