📄 prp_io.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) 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: prp_io.cpp
//
// This module provides a stream interface for the Pre-processor (PrP)
// driver. Client drivers can use the stream interface to
// configure the PP driver and run test programs.
//
//------------------------------------------------------------------------------
#include <windows.h>
#include "csp.h"
#include "prp.h"
#include "PrpClass.h"
//------------------------------------------------------------------------------
// External Functions
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
// Global Variables
#ifdef DEBUG
DBGPARAM dpCurSettings = {
TEXT("PRP"), {
TEXT("Init"), TEXT("Deinit"),
TEXT("Ioctl"), TEXT(""),
TEXT(""), TEXT(""),
TEXT(""), TEXT(""),
TEXT(""), TEXT(""),
TEXT(""), TEXT("Device"),
TEXT("Information"), TEXT("Function"),
TEXT("Warning"), TEXT("Error")
},
ZONEMASK_WARN | ZONEMASK_ERROR
};
#endif
//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
// Local Functions
//------------------------------------------------------------------------------
//
// Function: PRP_DllEntry
//
// This is the entry and exit point for the PrP module. This function
// is called when processed and threads attach and detach from this module.
//
// Parameters:
// hInstDll
// [in] The handle to this module.
//
// dwReason
// [in] Specifies a flag indicating why the DLL entry-point function
// is being called.
//
// lpvReserved
// [in] Specifies further aspects of DLL initialization and cleanup.
//
// Returns:
// TRUE if the everything is OK; FALSE if an error occurred.
//
//------------------------------------------------------------------------------
BOOL WINAPI PRP_DllEntry(HINSTANCE hInstDll, DWORD dwReason,
LPVOID lpvReserved)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
// Register debug zones
DEBUGREGISTER(hInstDll);
DEBUGMSG(ZONE_INIT,
(TEXT("%s: DLL_PROCESS_ATTACH\r\n"), __WFUNCTION__));
DisableThreadLibraryCalls((HMODULE)hInstDll);
break;
case DLL_PROCESS_DETACH:
DEBUGMSG(ZONE_DEINIT,
(TEXT("%s: DLL_PROCESS_DETACH\r\n"), __WFUNCTION__));
break;
}
// return TRUE for success
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: PRP_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.
//
// lpvBusContext
// [in] Pointer to bus context.
//
// Returns:
// Returns a handle to the device context created if successful; returns
// zero if not successful.
//
//------------------------------------------------------------------------------
DWORD PRP_Init(LPCTSTR pContext, LPCVOID lpvBusContext)
{
PRP_FUNCTION_ENTRY();
// Construct the Pre-Processor Module Class
PrpClass *pPrP = new PrpClass();
if (pPrP == NULL) {
DEBUGMSG(ZONE_INIT | ZONE_ERROR,
(TEXT("%s: PrP Class Failed!\r\n"), __WFUNCTION__));
delete pPrP;
return NULL;
}
PRP_FUNCTION_EXIT();
// Return the created instance
return (DWORD)pPrP;
}
//------------------------------------------------------------------------------
//
// Function: PRP_Deinit
//
// This function uninitializes a device.
//
// Parameters:
// hDeviceContext
// [in] Handle to the device context returned from PRP_Init.
//
// Returns:
// TRUE indicates success. FALSE indicates failure.
//
//------------------------------------------------------------------------------
BOOL PRP_Deinit(DWORD hDeviceContext)
{
PrpClass *pPrP = (PrpClass *)hDeviceContext;
PRP_FUNCTION_ENTRY();
if (pPrP != NULL)
delete pPrP;
PRP_FUNCTION_EXIT();
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: PRP_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 PRP_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
PrpClass *pPrP = (PrpClass *)hDeviceContext;
PRP_FUNCTION_ENTRY();
// If power up failure, it will release the resource automatically.
if (!pPrP->PrpPowerUp()) {
DEBUGMSG(ZONE_ERROR, (TEXT("%s: PrP Power Up Failed!\r\n"), __WFUNCTION__));
return NULL;
}
// If there is a module has opened PrP module or PrP enable failure, PrpEnable() return FALSE.
if (!pPrP->PrpEnable()) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: PrpEnable Failed!\r\n"), __WFUNCTION__));
pPrP->PrpPowerDown();
return NULL;
}
PRP_FUNCTION_EXIT();
return hDeviceContext;
}
//------------------------------------------------------------------------------
//
// Function: PRP_Close
//
// This function opens a device for reading, writing, or both.
//
// 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 PRP_Close(DWORD hOpenContext)
{
PrpClass *pPrP = (PrpClass *)hOpenContext;
PRP_FUNCTION_ENTRY();
pPrP->PrpDisable();
pPrP->PrpPowerDown();
PRP_FUNCTION_EXIT();
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: PRP_Read
//
// This function reads data from the device identified by the open context.
//
// Parameters:
// hOpenContext
// [in] Handle to the open context of the device. The XXX_Open
// function creates and returns this identifier.
//
// pBuffer
// [out] Pointer to the buffer that stores the data read from the
// device. This buffer should be at least Count bytes long.
//
// Count
// [in] Number of bytes to read from the device into pBuffer.
//
// Returns:
// Returns zero to indicate end-of-file. Returns -1 to indicate an
// error. Returns the number of bytes read to indicate success.
//
//------------------------------------------------------------------------------
DWORD PRP_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
PRP_FUNCTION_ENTRY();
PRP_FUNCTION_EXIT();
return 0;
}
//------------------------------------------------------------------------------
//
// Function: PRP_Write
//
// This function writes data to the device.
//
// Parameters:
// hOpenContext
// [in] Handle to the open context of the device. The XXX_Open
// function creates and returns this identifier.
//
// pBuffer
// [out] Pointer to the buffer that contains the data to write.
//
// Count
// [in] Number of bytes to read from the device into pBuffer.
//
// Returns:
// The number of bytes written indicates success. A value of -1
// indicates failure.
//
//------------------------------------------------------------------------------
DWORD PRP_Write(DWORD hOpenContext, LPCVOID pBuffer, DWORD Count)
{
PRP_FUNCTION_ENTRY();
PRP_FUNCTION_EXIT();
return 0;
}
//------------------------------------------------------------------------------
//
// Function: PRP_Seek
//
// This function moves the data pointer in the device.
//
// Parameters:
// hOpenContext
// [in] Handle to the open context of the device. The XXX_Open
// function creates and returns this identifier.
//
// Amount
// [in] Number of bytes to move the data pointer in the device.
// A positive value moves the data pointer toward the end of the
// file, and a negative value moves it toward the beginning.
//
// Type
// [in] Starting point for the data pointer.
//
// Returns:
// The new data pointer for the device indicates success. A value of -1
// indicates failure.
//
//------------------------------------------------------------------------------
DWORD PRP_Seek(DWORD hOpenContext, long Amount, WORD Type)
{
PRP_FUNCTION_ENTRY();
PRP_FUNCTION_EXIT();
return (DWORD)-1;
}
//------------------------------------------------------------------------------
//
// Function: PRP_PowerUp
//
// This function restores power to a device.
//
// Parameters:
// hDeviceContext
// [in] Handle to the device context.
//
// Returns:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -