📄 gptmdd.cpp
字号:
//-----------------------------------------------------------------------------
//
// 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.
//
//-----------------------------------------------------------------------------
//
// Copyright (C) 2004, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2004-2006, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//-----------------------------------------------------------------------------
//
// File: gptmdd.c
//
// This module provides a stream interface for the GPT
// driver. Client drivers can use the stream interface to
// configure the GPT driver and run test programs.
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <Devload.h>
#include "csp.h"
#include "gpt.h"
#include "gpt_priv.h"
//------------------------------------------------------------------------------
// External Functions
extern BOOL BSPGptSetClockGatingMode(DWORD, BOOL);
//------------------------------------------------------------------------------
// Global Variables
#ifdef DEBUG
extern DBGPARAM dpCurSettings =
{
_T("GPT"),
{
_T("Init"), _T("DeInit"), _T("Ioctl"), _T(""),
_T(""), _T(""), _T(""), _T(""),
_T(""),_T(""),_T(""),_T(""),
_T("Info"),_T("Function"),_T("Warnings"),_T("Errors")
},
ZONEMASK_ERROR | ZONEMASK_WARN
};
#endif
//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
// Local Functions
//------------------------------------------------------------------------------
//
// Function: GPT_Init
//
// The Device Manager calls this function as a result of a call to the
// ActivateDevice() function.
//
// Parameters:
// pContext
// [in] Pointer to a string containing the registry path to the
// active key for the stream interface driver.
//
// Returns:
// Returns a handle to the device context created if successful. Returns
// zero if not successful.
//
//------------------------------------------------------------------------------
DWORD GPT_Init(LPCTSTR pContext)
{
LONG regError;
HKEY hKey;
DWORD dwDataSize;
DWORD dwIOBase;
DWORD dwIOLen;
DWORD dwIRQ;
gptClass *pGpt = NULL;
GPT_FUNCTION_ENTRY();
hKey = OpenDeviceKey((LPCTSTR)pContext);
if (hKey == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Failed to open GPT registry key.\r\n"), __WFUNCTION__));
return 0;
}
// Okay, we're finally ready to try and load our registry data
dwDataSize = GPT_REG_IOBASE_VAL_LEN;
regError = RegQueryValueEx(
hKey,
GPT_REG_IOBASE_VAL_NAME,
NULL,
NULL,
(LPBYTE)(&dwIOBase),
&dwDataSize);
if (regError == ERROR_SUCCESS) {
dwDataSize = GPT_REG_IOLEN_VAL_LEN;
regError = RegQueryValueEx(
hKey,
GPT_REG_IOLEN_VAL_NAME,
NULL,
NULL,
(LPBYTE)(&dwIOLen),
&dwDataSize);
}
if (regError == ERROR_SUCCESS) {
dwDataSize = GPT_REG_IRQ_VAL_LEN;
regError = RegQueryValueEx(
hKey,
GPT_REG_IRQ_VAL_NAME,
NULL,
NULL,
(LPBYTE)(&dwIRQ),
&dwDataSize);
}
RegCloseKey (hKey);
pGpt = new gptClass();
if (pGpt && !pGpt->GptInitialize(dwIOBase, dwIOLen, dwIRQ)) {
delete pGpt;
DEBUGMSG(ZONE_ERROR, (TEXT("GPT_Init: GptInitialize failed!!!\r\n")));
return 0;
}
GPT_FUNCTION_EXIT();
return (DWORD)pGpt;
}
//------------------------------------------------------------------------------
//
// Function: GPT_Deinit
//
// This function uninitializes a device.
//
// Parameters:
// hDeviceContext
// [in] Handle to the device context.
//
// Returns:
// TRUE indicates success. FALSE indicates failure.
//
//------------------------------------------------------------------------------
BOOL GPT_Deinit(DWORD hDeviceContext)
{
gptClass * pGpt=(gptClass *)hDeviceContext;
GPT_FUNCTION_ENTRY();
pGpt->GptRelease();
GPT_FUNCTION_EXIT();
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: GPT_Open
//
// This function opens a device for reading, writing, or both.
//
// Parameters:
// hDeviceContext
// [in] Handle to the device context. The XXX_Init function creates
// and returns this handle.
//
// AccessCode
// [in] Access code for the device. The access is a combination of
// read and write access from CreateFile.
//
// ShareMode
// [in] File share mode of the device. The share mode is a
// combination of read and write access sharing from CreateFile.
//
// Returns:
// This function returns a handle that identifies the open context of
// the device to the calling application.
//
//------------------------------------------------------------------------------
DWORD GPT_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
gptClass * pGpt=(gptClass *)hDeviceContext;
GPT_FUNCTION_ENTRY();
if (!BSPGptSetClockGatingMode(pGpt->m_dwIOBase, TRUE))
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Error setting GPT clock mode.\r\n"), __WFUNCTION__));
return 0;
}
GPT_FUNCTION_EXIT();
return hDeviceContext;
}
//------------------------------------------------------------------------------
//
// Function: GPT_Close
//
// This function closes the GPT for reading and writing.
//
// Parameters:
// hOpenContext
// [in] Handle returned by the XXX_Open function, used to identify
// the open context of the device.
//
// Returns:
// TRUE indicates success. FALSE indicates failure.
//
//------------------------------------------------------------------------------
BOOL GPT_Close(DWORD hOpenContext)
{
gptClass * pGpt=(gptClass *)hOpenContext;
GPT_FUNCTION_ENTRY();
if (!BSPGptSetClockGatingMode(pGpt->m_dwIOBase, FALSE))
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Error setting GPT clock mode.\r\n"), __WFUNCTION__));
return 0;
}
GPT_FUNCTION_EXIT();
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: GPT_PowerDown
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -