📄 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 <types.h>
#include <memory.h>
///#include <tchar.h>
#include <ceddk.h>
#include <giisr.h>
#include "myintr.h"
#define DEFAULT_IST_PRIORITY 101
extern LPCTSTR pg_szActiveKey;
static ULONG myIST(MYINTRINFO* pMyIntrInfo)
{
DWORD dwStatus;
BOOLEAN res;
RETAILMSG(1,(TEXT("MyIst-Priority : %d\n"), CeGetThreadPriority(GetCurrentThread())));
while (pMyIntrInfo->quitIST == FALSE) {
dwStatus = WaitForSingleObject(pMyIntrInfo->hIntrEvent, INFINITE);
///Callback the registered IST function outside intr module
res = pMyIntrInfo->pIstFunc(pMyIntrInfo->param, pMyIntrInfo->dwSysIntr);
}
SetEvent(pMyIntrInfo->waitobj);
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),
if (!KernelIoControl(IOCTL_HAL_TRANSLATE_IRQ, &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;
}
CeSetThreadPriority(pMyIntrInfo->hISTHandle, DEFAULT_IST_PRIORITY);
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 (pMyIntrInfo->hISTHandle != NULL) {
///crlo:version-check ++
///pMyIntrInfo->quitIST = TRUE;
///crlo:version-check --
///SetEvent(pHC->waitqueue);
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 + -