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

📄 pp_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:  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 <Devload.h>
#include <ceddk.h>
#include <NKIntr.h>
#include "mxarm11.h"
#include "pp.h"
#include "PpClass.h"


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


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


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


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


//------------------------------------------------------------------------------
// Global Variables
#ifdef DEBUG
extern DBGPARAM dpCurSettings =
{
    _T("PP"),
    {
        _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: 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.
//
// Returns:
//      Returns a handle to the device context created if successful. Returns
//      zero if not successful.
//
//------------------------------------------------------------------------------
DWORD POP_Init(LPCTSTR pContext)
{
    PP_FUNCTION_ENTRY();

    // Construct the Post-Processor Module Class
    PpClass* pPP = new PpClass();

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

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

    PP_FUNCTION_EXIT();

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


//------------------------------------------------------------------------------
//
// Function: POP_Deinit
//
// This function uninitializes a device.
//
// Parameters:
//      hDeviceContext
//          [in] Handle to the device context.
//
// 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)
{
    PP_FUNCTION_ENTRY();

    PP_FUNCTION_EXIT();
    return hDeviceContext;
}


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

    PP_FUNCTION_EXIT();
    return TRUE;
}


//------------------------------------------------------------------------------
//
// Function: POP_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 POP_PowerDown(DWORD hDeviceContext)
{
    PP_FUNCTION_ENTRY();
    PP_FUNCTION_EXIT();
}


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


//------------------------------------------------------------------------------
//
// Function: POP_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 POP_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn,
                   DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut,
                   PDWORD pdwActualOut)
{
    ppConfigData *pConfigData;
    pPpBuffers pBufs;
    UINT32 *pMaxBuffers, *pFrameCount;
    BOOL bRet = FALSE;
    

    // hOpenContext is a pointer to I2CClass instance!
    PpClass* pPp = (PpClass*) hOpenContext;

    switch(dwCode)
    {
        case PP_IOCTL_CONFIGURE:
            pConfigData = (pPpConfigData) MapCallerPtr(pBufIn, dwLenIn);
            bRet = pPp->PpConfigure(pConfigData);
            DEBUGMSG(ZONE_IOCTL, (TEXT("POP_IOControl: PP_IOCTL_CONFIGURE occurred\r\n")));
            break;

        case PP_IOCTL_START:
            bRet = pPp->PpStartChannel();
            DEBUGMSG(ZONE_IOCTL, (TEXT("POP_IOControl: PP_IOCTL_START occurred\r\n")));
            break;

        case PP_IOCTL_STOP:
            bRet = pPp->PpStopChannel();
            DEBUGMSG(ZONE_IOCTL, (TEXT("POP_IOControl: PP_IOCTL_STOP occurred\r\n")));
            break;

        case PP_IOCTL_ENQUEUE_BUFFERS:
            pBufs = (pPpBuffers) MapCallerPtr(pBufIn, dwLenIn);
            pBufs->inputBuf = (UINT32 *) MapCallerPtr(((pPpBuffers)pBufIn)->inputBuf, pBufs->inBufLen);
            pBufs->outputBuf = (UINT32 *) MapCallerPtr(((pPpBuffers)pBufIn)->outputBuf, pBufs->outBufLen);
            bRet = pPp->PpEnqueueBuffers(pBufs);
            DEBUGMSG(ZONE_IOCTL, (TEXT("POP_IOControl: PP_IOCTL_ADD_BUFFERS occurred\r\n")));
            break;

        case PP_IOCTL_CLEAR_BUFFERS:
            pPp->PpClearBuffers();
            bRet = TRUE;
            DEBUGMSG(ZONE_IOCTL, (TEXT("POP_IOControl: PP_IOCTL_CLEAR_BUFFERS occurred\r\n")));
            break;

        case PP_IOCTL_GET_MAX_BUFFERS:
            pMaxBuffers = (UINT32 *) MapCallerPtr(pBufOut, dwLenOut);
            *pMaxBuffers = pPp->PpGetMaxBuffers();
            bRet = TRUE;
            DEBUGMSG(ZONE_IOCTL, (TEXT("POP_IOControl: PP_IOCTL_GET_MAX_BUFFERS occurred\r\n")));
            break;

        case PP_IOCTL_PAUSE_VIEWFINDING:
            bRet = pPp->PpPauseViewfinding();
            DEBUGMSG(ZONE_IOCTL, (TEXT("POP_IOControl: PP_IOCTL_PAUSE_VIEWFINDING occurred\r\n")));
            break;

        case PP_IOCTL_GET_FRAME_COUNT:
            pFrameCount = (UINT32 *) MapCallerPtr(pBufOut, dwLenOut);
            *pFrameCount = pPp->PpGetFrameCount();
            bRet = TRUE;
            DEBUGMSG(ZONE_IOCTL, (TEXT("POP_IOControl: PP_IOCTL_GET_FRAME_COUNT occurred\r\n")));
            break;

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

    return bRet;
}

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

      case DLL_PROCESS_DETACH:
         DEBUGMSG(ZONE_INFO, (TEXT("POP_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 + -