pp_io.cpp

来自「i.mx27 soc for wince 6.0」· C++ 代码 · 共 499 行 · 第 1/2 页

CPP
499
字号
//
// 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: pp_io.cpp
//
// This module provides a stream interface for the Post-processor (PP)
// driver.  Client drivers can use the stream interface to
// configure the PP driver and run test programs.
//
//------------------------------------------------------------------------------
#include <windows.h>
#include "csp.h"
#include "pp.h"
#include "PpClass.h"

//------------------------------------------------------------------------------
// External Functions

//------------------------------------------------------------------------------
// External Variables 

//------------------------------------------------------------------------------
// Defines 

//------------------------------------------------------------------------------
// Types

//------------------------------------------------------------------------------
// Global Variables 
#ifdef DEBUG
DBGPARAM dpCurSettings = {
    TEXT("PP"), {
        TEXT("Init"),           TEXT("Deinit"),
        TEXT("Ioctl"),          TEXT("Thread"),
        TEXT(""),               TEXT(""),
        TEXT(""),               TEXT(""),
        TEXT(""),               TEXT(""),
        TEXT(""),               TEXT("Registers"),
        TEXT("Information"),    TEXT("Function"),
        TEXT("Warning"),        TEXT("Error")
    },
    ZONEMASK_WARN | ZONEMASK_ERROR
};
#endif

//------------------------------------------------------------------------------
// Local Variables 

//------------------------------------------------------------------------------
// Local Functions

//------------------------------------------------------------------------------
//
// Function: POP_DllEntry
//
// This is the entry and exit point for the PP 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 POP_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: POP_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 POP_Init(LPCTSTR pContext, LPCVOID lpvBusContext)
{
    PP_FUNCTION_ENTRY();

    // Construct the Post-Processor Module Class
    PpClass *pPP = new PpClass();
    if (pPP == NULL) {
        DEBUGMSG(ZONE_INIT | ZONE_ERROR, 
            (TEXT("%s: PP Class Failed!\r\n"), __WFUNCTION__));
        delete pPP;
        return NULL;
    }
    
    PP_FUNCTION_EXIT();

    // Return the created instance
    return (DWORD)pPP;
}

//------------------------------------------------------------------------------
//
// Function: POP_Deinit
//
// This function uninitializes a device.
//
// Parameters:
//      hDeviceContext
//          [in] Handle to the device context returned from POP_Init.
//
// Returns:
//      TRUE indicates success. FALSE indicates failure.
//
//------------------------------------------------------------------------------
BOOL POP_Deinit(DWORD hDeviceContext)
{
    PpClass *pPP = (PpClass *)hDeviceContext;

    PP_FUNCTION_ENTRY();

    if (pPP != NULL)
        delete pPP;

    PP_FUNCTION_EXIT();

    return TRUE;
}

//------------------------------------------------------------------------------
//
// Function: POP_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 POP_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
    PpClass *pPP = (PpClass *)hDeviceContext;
    
    PP_FUNCTION_ENTRY();

    if (!pPP->PpEnable()) {
        DEBUGMSG(ZONE_ERROR, 
            (TEXT("%s: PpEnable Failed! \r\n"), __WFUNCTION__));
        return NULL;
    }

    PP_FUNCTION_EXIT();

    return hDeviceContext;
}

//------------------------------------------------------------------------------
//
// Function: POP_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 POP_Close(DWORD hOpenContext)
{
    PpClass *pPP = (PpClass *)hOpenContext;
    
    PP_FUNCTION_ENTRY();

    pPP->PpDisable();

    PP_FUNCTION_EXIT();

    return TRUE;
}

//------------------------------------------------------------------------------
//
// Function: POP_Read
//

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?