📄 myintr.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Module Name:
myintr.c
Abstract:
This is the implementation to setup an interrupt
Functions:
Notes:
--*/
#include <windows.h>
#include <nkintr.h>
#include <memory.h>
#include <ceddk.h>
#include <giisr.h>
#include "myintr.h"
#define DEFAULT_IST_PRIORITY 97
extern LPCTSTR pg_szActiveKey;
#ifndef __FUNCTION__
#define __FUNCTION__ " "
#endif
static ULONG myIST(MYINTRINFO* pMyIntrInfo)
{
DWORD dwStatus;
BOOLEAN res;
RETAILMSG(1,(TEXT("MyIst-Priority : %d\n"), CeGetThreadPriority(GetCurrentThread())));
while (1) {
/// #if (USE_DEVIRQ == 1)
dwStatus = WaitForSingleObject(pMyIntrInfo->hIntrEvent, INFINITE);
//###xlin necessary to unload the driver
if(pMyIntrInfo->quitIST == TRUE)
break;
///crlo: Reset this object is necessary. Otherwise, the system will accumulate the
/// times to set the event. => we will be waken up, even no new interrupts
//###xlin we would need it???? ResetEvent(pMyIntrInfo->hIntrEvent);
///Callback the registered IST function outside intr module
res = pMyIntrInfo->pIstFunc(pMyIntrInfo->param);
///Finish the interrupt
/// #if (USE_DEVIRQ == 1)
InterruptDone(pMyIntrInfo->dwSysIntr);
/// #endif ///USE_DEVIRQ
}
SetEvent(pMyIntrInfo->waitobj);
//cfwang
RETAILMSG(1, (TEXT("!!!!!!!!!!!!!!!!!!!Exit myIST!!!!!!!\n")));
return TRUE;
}
int setupInterrupt(MYINTRINFO* pMyIntrInfo)
{
DWORD threadID;
///==============================================================
/// Request the IRQ
if(!(pMyIntrInfo->hIntrEvent = CreateEvent( NULL, FALSE, FALSE, NULL))) {
DEBUGMSG(1, (TEXT("CreateEvent() FAILED")));
goto errFuncRet;
}
// convert the hardware SSP controller interrupt IRQ into a logical SYSINTR value
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &pMyIntrInfo->irq, sizeof(DWORD),
&pMyIntrInfo->dwSysIntr, sizeof(pMyIntrInfo->dwSysIntr), NULL))
{
DEBUGMSG(1, (TEXT("Error obtaining SYSINTR value!\n")));
goto errFuncRet;
}
RETAILMSG(1, (TEXT("SysIntr: %d!\n"), pMyIntrInfo->dwSysIntr));
///Create a thread that waits for signals
pMyIntrInfo->hISTHandle = CreateThread((LPSECURITY_ATTRIBUTES)NULL,
0,
myIST,
pMyIntrInfo,
CREATE_SUSPENDED,
&threadID);
if (pMyIntrInfo->hISTHandle == NULL) {
DEBUGMSG(1, (TEXT("hSSPInterThread Create FAILED")));
goto errFuncRet;
}
//cfwang
RETAILMSG(1, (TEXT("MyIst Thread ID = %d\n"), pMyIntrInfo->hISTHandle));
CeSetThreadPriority(pMyIntrInfo->hISTHandle, DEFAULT_IST_PRIORITY);
InterruptDisable(pMyIntrInfo->dwSysIntr);
if (! InterruptInitialize(pMyIntrInfo->dwSysIntr, pMyIntrInfo->hIntrEvent, NULL, 0)) {
DEBUGMSG(1, (TEXT("%s - InterruptInitialize(%d,%08x) Failed\r\n"),
TEXT(__FUNCTION__), pMyIntrInfo->dwSysIntr, pMyIntrInfo->hISTHandle));
goto errFuncRet;
}
if(!(pMyIntrInfo->waitobj = CreateEvent( NULL, FALSE, FALSE,NULL))) {
DEBUGMSG(1, (TEXT("Init CreateEvent FAILED")));
goto errFuncRet;
}
pMyIntrInfo->quitIST = FALSE;
ResumeThread(pMyIntrInfo->hISTHandle);
return 0; ///success
errFuncRet:
pMyIntrInfo->dwSysIntr = SYSINTR_UNDEFINED;
return -1; ///fail
}
int installISR(MYINTRINFO* pMyIntrInfo)
{
GIISR_INFO Info;
// install the DMA ISR handler
pMyIntrInfo->hGIIsr = LoadIntChainHandler(
TEXT("giisr.dll"),
TEXT("ISRHandler"),
(BYTE)pMyIntrInfo->irq);
if (!(pMyIntrInfo->hGIIsr)) {
RETAILMSG(1, (TEXT("xxxxxxxx>Can not load giisr.dll\n")));
goto errFuncRet;
} else {
///RETAILMSG(1, (TEXT("*********> loading agiisr.dll ok\n")));
}
Info.SysIntr = pMyIntrInfo->dwSysIntr;
Info.CheckPort = TRUE;
Info.PortIsIO = FALSE;
Info.UseMaskReg = FALSE;
Info.PortAddr = (DWORD)pMyIntrInfo->IntrRgPhysAddr;
Info.PortSize = sizeof(DWORD);
Info.Mask = pMyIntrInfo->IntrMask;
Info.MaskAddr = 0;
if (!KernelLibIoControl(pMyIntrInfo->hGIIsr, IOCTL_GIISR_INFO,
&Info, sizeof(Info),
NULL, 0, NULL)) {
goto errFuncRet;
}
return 0;
errFuncRet:
return -1;
}
void clrInterrupt(MYINTRINFO* pMyIntrInfo)
{
///crlo:version-check ++
pMyIntrInfo->quitIST = TRUE;
///crlo:version-check --
///Clean up the handler
if (pMyIntrInfo->hIntrEvent != NULL) {
SetEvent(pMyIntrInfo->hIntrEvent);
}
if (pMyIntrInfo->hGIIsr != NULL) {
FreeIntChainHandler(pMyIntrInfo->hGIIsr);
}
if (!KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &pMyIntrInfo->dwSysIntr,
sizeof(pMyIntrInfo->dwSysIntr),NULL, 0, NULL))
{
DEBUGMSG(1, (TEXT("Error release SYSINTR value!\n")));
}
if (pMyIntrInfo->hISTHandle != NULL) {
WaitForSingleObject(pMyIntrInfo->waitobj, INFINITE);
CloseHandle(pMyIntrInfo->waitobj);
CloseHandle(pMyIntrInfo->hISTHandle);
}
memset(pMyIntrInfo, 0, sizeof(MYINTRINFO));
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -