⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pf_io.cpp

📁 freescale i.mx31 BSP CE5.0全部源码
💻 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, Freescale Semiconductor, Inc. All Rights Reserved
//  THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
//  BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
//  Freescale Semiconductor, Inc.
//
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//
//  File:  Pf_io.cpp
//
//  This module provides a stream interface for the Post-filter (PF)
//  driver.  Client drivers can use the stream interface to
//  configure the PF driver and run test programs.
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <Devload.h>
#include <ceddk.h>
#include <NKIntr.h>
#include "mxarm11.h"
#include "pf.h"
#include "PfClass.h"


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


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


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


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


//------------------------------------------------------------------------------
// Global Variables
#ifdef DEBUG
extern DBGPARAM dpCurSettings =
{
    _T("PF"),
    {
        _T("Init"), _T("DeInit"), _T("Ioctl"), _T("Device"),
        _T(""), _T(""), _T(""), _T(""),
        _T(""),_T(""),_T(""),_T(""),
        _T("Info"),_T("Function"),_T("Warnings"),_T("Errors")
    },
    0xffff//ZONEMASK_ERROR | ZONEMASK_WARN | ZONEMASK_FUNCTION | ZONEMASK_INFO | ZONE_INIT | ZONE_DEVICE
//    ZONEMASK_ERROR | ZONEMASK_WARN
};
#endif


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


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


//------------------------------------------------------------------------------
//
// Function: POF_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 POF_Init(LPCTSTR pContext)
{
    PF_FUNCTION_ENTRY();

    // Construct the Post-Processor Module Class
    PfClass* pPF = new PfClass();

    // Managed to create the class?
    if (pPF == NULL)
    {
        DEBUGMSG (ZONE_INIT|ZONE_ERROR, (TEXT("POF_Init: PF Class Failed!\r\n")));
        delete pPF;
        return NULL;
    }

    DEBUGMSG (ZONE_INIT|ZONE_FUNCTION, (TEXT("POF_Init - hDev=0x%x\r\n"), pPF));

    PF_FUNCTION_EXIT();

    // Otherwise return the created instance
    return (DWORD) pPF;
}


//------------------------------------------------------------------------------
//
// Function: POF_Deinit
//
// This function uninitializes a device.
//
// Parameters:
//      hDeviceContext
//          [in] Handle to the device context.
//
// Returns:
//      TRUE indicates success. FALSE indicates failure.
//
//------------------------------------------------------------------------------
BOOL POF_Deinit(DWORD hDeviceContext)
{
    PfClass * pPF = (PfClass*) hDeviceContext;

    PF_FUNCTION_ENTRY();

    if (pPF != NULL)
    {
        delete pPF;
    }

    PF_FUNCTION_EXIT();

    return TRUE;
}


//------------------------------------------------------------------------------
//
// Function: POF_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 POF_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
    PF_FUNCTION_ENTRY();

    PF_FUNCTION_EXIT();
    return hDeviceContext;
}


//------------------------------------------------------------------------------
//
// Function: POF_Close
//
// This function closes the PP 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 POF_Close(DWORD hOpenContext)
{
    PF_FUNCTION_ENTRY();

    PF_FUNCTION_EXIT();
    return TRUE;
}


//------------------------------------------------------------------------------
//
// Function: POF_PowerDown
//
// This function suspends power to the device. It is useful only with
// devices that can power down under software control.
//
// Parameters:
//      hDeviceContext
//          [in] Handle to the device context.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void POF_PowerDown(DWORD hDeviceContext)
{
    PF_FUNCTION_ENTRY();
    PF_FUNCTION_EXIT();
}


//------------------------------------------------------------------------------
//
// Function: POF_PowerUp
//
// This function restores power to a device.
//
// Parameters:
//      hDeviceContext
//          [in] Handle to the device context.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void POF_PowerUp(void)
{
    PF_FUNCTION_ENTRY();
    PF_FUNCTION_EXIT();
}


//------------------------------------------------------------------------------
//
// Function: POF_IOControl
//
// This function sends a command to a device.
//
// Parameters:
//      hOpenContext
//          [in] Handle to the open context of the device. The XXX_Open
//          function creates and returns this identifier.
//
//      dwCode
//          [in] I/O control operation to perform. These codes are
//          device-specific and are usually exposed to developers through
//          a header file.
//
//      pBufIn
//          [in] Pointer to the buffer containing data to transfer to the
//          device.
//
//      dwLenIn
//          [in] Number of bytes of data in the buffer specified for pBufIn.
//
//      pBufOut
//          [out] Pointer to the buffer used to transfer the output data
//          from the device.
//
//      dwLenOut
//          [in] Maximum number of bytes in the buffer specified by pBufOut.
//
//      pdwActualOut
//          [out] Pointer to the DWORD buffer that this function uses to
//          return the actual number of bytes received from the device.
//
// Returns:
//      The new data pointer for the device indicates success. A value of -1
//      indicates failure.
//
//------------------------------------------------------------------------------
BOOL POF_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn,
                   DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut,
                   PDWORD pdwActualOut)
{
    pfConfigData  *pConfigData;
    pfStartParams *pStartParms;
    DWORD *pdwResumeReturn;
    UINT32 *pauseRow;
    BOOL bRet = FALSE;

    // hOpenContext is a pointer to I2CClass instance!
    PfClass* pPF = (PfClass*) hOpenContext;

    switch(dwCode)
    {
        case PF_IOCTL_CONFIGURE:
            pConfigData = (pPfConfigData) MapCallerPtr(pBufIn, dwLenIn);
            bRet = pPF->PfConfigure(pConfigData);
            DEBUGMSG(ZONE_IOCTL, (TEXT("POF_IOControl: PF_IOCTL_CONFIGURE occurred\r\n")));
            break;

        case PF_IOCTL_START:
            pStartParms = (pPfStartParams) MapCallerPtr(pBufIn, dwLenIn);
            pStartParms->in = (pPfBuffer) MapCallerPtr(pStartParms->in, sizeof(pfBuffer));
            pStartParms->out = (pPfBuffer) MapCallerPtr(pStartParms->out, sizeof(pfBuffer));
            bRet = pPF->PfStartChannel(pStartParms);
            DEBUGMSG(ZONE_IOCTL, (TEXT("POF_IOControl: PF_IOCTL_START occurred\r\n")));
            break;

        case PF_IOCTL_RESUME:
            pdwResumeReturn = (DWORD *) MapCallerPtr(pBufOut, dwLenOut);
            pauseRow = (UINT32 *) MapCallerPtr(pBufIn, dwLenIn);
            *pdwResumeReturn = pPF->PfResume(*pauseRow);
            if (pdwResumeReturn != PF_SUCCESS)
            {
                bRet = TRUE;
            }
            DEBUGMSG(ZONE_IOCTL, (TEXT("POF_IOControl: PF_IOCTL_RESUME occurred\r\n")));
            break;

        default:
            DEBUGMSG(ZONE_WARN, (TEXT("POF_IOControl: No matching IOCTL.\r\n")));
            break;
    }

    return bRet;
}

BOOL WINAPI POF_DllEntry(HANDLE hInstDll, DWORD dwReason, LPVOID lpvReserved)
{
   switch (dwReason)
   {
      case DLL_PROCESS_ATTACH:
         //Register Debug Zones
         DEBUGREGISTER((HINSTANCE) hInstDll);
         DEBUGMSG(ZONE_INFO, (TEXT("POF_DllEntry: DLL_PROCESS_ATTACH lpvReserved(0x%x)\r\n"),lpvReserved));
         DisableThreadLibraryCalls((HMODULE) hInstDll);
         break;

      case DLL_PROCESS_DETACH:
         DEBUGMSG(ZONE_INFO, (TEXT("POF_DllEntry: DLL_PROCESS_DETACH lpvReserved(0x%x)\r\n"),lpvReserved));
         break;
   }
   // Return TRUE for success
   return TRUE;
}

⌨️ 快捷键说明

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