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

📄 prpclass.cpp

📁 freescale i.mx31 BSP CE5.0全部源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//-----------------------------------------------------------------------------
//
// 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, 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:  prp.cpp
//
//  Implementation of preprocessor driver methods
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <Devload.h>
#include <ceddk.h>
#include <NKIntr.h>
#include "mxarm11.h"

#include "Ipu.h"
#include "cameradbg.h"
#include "PrpClass.h"


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


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


//------------------------------------------------------------------------------
// Defines
#define PRP_FUNCTION_ENTRY() \
    DEBUGMSG(ZONE_FUNCTION, (TEXT("++%s\r\n"), __WFUNCTION__))
#define PRP_FUNCTION_EXIT() \
    DEBUGMSG(ZONE_FUNCTION, (TEXT("--%s\r\n"), __WFUNCTION__))

#define THREAD_PRIORITY                            250

#define PRP_MAX_NUM_BUFFERS                        100

#define ENC_BUF_IDLE_QUEUE_NAME            L"Enc idle queue"
#define ENC_BUF_READY_QUEUE_NAME           L"Enc ready queue"
#define ENC_BUF_FILLED_QUEUE_NAME          L"Enc filled queue"
#define ENC_ROT_BUF_IDLE_QUEUE_NAME        L"Enc rot idle queue"
#define ENC_ROT_BUF_READY_QUEUE_NAME       L"Enc rot ready queue"
#define ENC_ROT_BUF_FILLED_QUEUE_NAME      L"Enc rot filled queue"
#define VF_BUF_IDLE_QUEUE_NAME             L"Vf idle queue"
#define VF_BUF_READY_QUEUE_NAME            L"Vf ready queue"
#define VF_BUF_FILLED_QUEUE_NAME           L"Vf filled queue"
#define VF_ROT_BUF_IDLE_QUEUE_NAME         L"Vf rot idle queue"
#define VF_ROT_BUF_READY_QUEUE_NAME        L"Vf rot ready queue"
#define VF_ROT_BUF_FILLED_QUEUE_NAME       L"Vf rot filled queue"

#define PRP_MAX_NUM_BUFFERS                        100

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


//------------------------------------------------------------------------------
// Global Variables

// Static variables from parent class
// must be defined before they can be used.
PCSP_IPU_REGS IpuModuleInterfaceClass::m_pIPU = NULL;
HANDLE IpuModuleInterfaceClass::m_hIpuMutex = NULL;


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


//------------------------------------------------------------------------------
// Local Functions
//static void CsiTestPatternOn(PCSP_IPU_REGS);
static void dumpChannelParams(pPrpIDMACChannelParams);
static void dumpCoeffs(pPrpCSCCoeffs);
static void dumpInterruptRegisters(PCSP_IPU_REGS);
static void dumpIpuRegisters(PCSP_IPU_REGS);
static void ReadVfDMA(PCSP_IPU_REGS);

//-----------------------------------------------------------------------------
//
// Function: PrpClass
//
// Preprocessor class constructor.  Calls PrpInit to initialize module.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//-----------------------------------------------------------------------------
PrpClass::PrpClass(void)
{
    PrpInit();
}

//-----------------------------------------------------------------------------
//
// Function: ~PrpClass
//
// The destructor for PrpClass.  Calls PrpDeinit to deinitialize.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//-----------------------------------------------------------------------------
PrpClass::~PrpClass(void)
{
    PrpDeinit();
}

//-----------------------------------------------------------------------------
//
// Function: PrpInit
//
// This function initializes the Image Converter (preprocessor).
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//-----------------------------------------------------------------------------
BOOL PrpClass::PrpInit(void)
{
    MSGQUEUEOPTIONS queueOptions;

    PRP_FUNCTION_ENTRY();

    DEBUGMSG(ZONE_INIT, (TEXT("%s: CreateEvent for IPU Interrupt\r\n"), __WFUNCTION__));
    m_hPrpIntrEvent = CreateEvent(NULL, FALSE, FALSE, IPU_PRP_INTR_EVENT);
    if (m_hPrpIntrEvent == NULL)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: CreateEvent for IPU Interrupt failed\r\n"), __WFUNCTION__));
        goto Error;
    }

    // Events to signal pin that frame is ready
    m_hEncEOFEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (m_hEncEOFEvent == NULL)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: CreateEvent failed for Encoding EOF\r\n"), __WFUNCTION__));
        return FALSE;
    }

    m_hVfEOFEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (m_hVfEOFEvent == NULL)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: CreateEvent failed for Viewfinding EOF\r\n"), __WFUNCTION__));
        return FALSE;
    }

    // Initialize buffer management handles
    m_hRequestEncBuffer = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (m_hRequestEncBuffer == NULL)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: CreateEvent failed for Request Encoding Buffer\r\n"), __WFUNCTION__));
        return FALSE;
    }

    m_hRequestEncRotBuffer = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (m_hRequestEncRotBuffer == NULL)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: CreateEvent failed for Request Encoding for Rotataion Buffer\r\n"), __WFUNCTION__));
        return FALSE;
    }

    m_hRequestVfBuffer = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (m_hRequestVfBuffer == NULL)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: CreateEvent failed for Request Viewfinding Buffer\r\n"), __WFUNCTION__));
        return FALSE;
    }

    m_hRequestVfRotBuffer = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (m_hRequestVfRotBuffer == NULL)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: CreateEvent failed for Request Viewfinding for Rotataion Buffer\r\n"), __WFUNCTION__));
        return FALSE;
    }

    // Create queues for read messages and write messages
    queueOptions.dwSize = sizeof(MSGQUEUEOPTIONS);
    queueOptions.dwFlags = MSGQUEUE_ALLOW_BROKEN;
    queueOptions.dwMaxMessages = PRP_MAX_NUM_BUFFERS;
    queueOptions.cbMaxMessage = sizeof(DISPLAY_BUFFER);
    queueOptions.bReadAccess = TRUE; // we need read-access to msgqueue

    // Create read handles to idle and busy queues
    m_hReadVfBufferQueue = CreateMsgQueue(NULL, &queueOptions);
    if (!m_hReadVfBufferQueue)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Error creating Viewfinding Buffer queue.  Initialization failed! \r\n"), __WFUNCTION__));
    }

    queueOptions.bReadAccess = FALSE; // we need write-access to msgqueue

    // Create read handles to idle and busy queues
    m_hWriteVfBufferQueue = OpenMsgQueue(GetCurrentProcess(), m_hReadVfBufferQueue, &queueOptions);
    if (!m_hWriteVfBufferQueue)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Error opening viewfinding buffer queue for writing.  Initialization failed! \r\n"), __WFUNCTION__));
    }

    InitializeCriticalSection(&m_csEncStopping);
    InitializeCriticalSection(&m_csVfStopping);

    pEncBufferManager = new IpuBufferManager();
    pVfBufferManager = new IpuBufferManager();
    pEncRotBufferManager = new IpuBufferManager();
    pVfRotBufferManager = new IpuBufferManager();

    m_bEncRotBuffersAllocated = FALSE;
    m_bVfRotBuffersAllocated = FALSE;

    m_iEncNumBuffers = 0;
    m_iVfNumBuffers = 0;
    m_iEncBufSize = 0;
    m_iVfBufSize = 0;

    m_bEncRequestSecondBuffer = FALSE;
    m_bEncRotRequestSecondBuffer = FALSE;
    m_bVfRequestSecondBuffer = FALSE;
    m_bVfRotRequestSecondBuffer = FALSE;

    m_bVfConfigured = FALSE;
    m_bEncConfigured = FALSE;

    m_hDisplay = NULL;

    m_bVfDirectDisplay = FALSE;
    m_bVfDisplayActive = FALSE;
    m_bADCDirect = FALSE;

    m_bEncRestartBufferLoop = FALSE;
    m_bVfRestartBufferLoop = FALSE;
    m_bEncRotRestartBufferLoop = FALSE;
    m_bVfRotRestartBufferLoop = FALSE;
    m_bEncRestartISRLoop = FALSE;
    m_bVfRestartISRLoop = FALSE;

    m_bEncRunning = FALSE;
    m_bVfRunning = FALSE;

    m_bEncFlipRot = FALSE;
    m_bVfFlipRot = FALSE;

    m_iEncFrameCount = 0;
    m_iVfFrameCount = 0;

    m_iVfBuf0Ready = FALSE;
    m_iVfBuf1Ready = FALSE;
    m_iEncBuf0Ready = FALSE;
    m_iEncBuf1Ready = FALSE;

    // Initialize thread for Preprocessor ISR
    //      pThreadAttributes = NULL (must be NULL)
    //      dwStackSize = 0 => default stack size determined by linker
    //      lpStartAddress = CspiProcessQueue => thread entry point
    //      lpParameter = NULL => point to thread parameter
    //      dwCreationFlags = 0 => no flags
    //      lpThreadId = NULL => thread ID is not returned
    m_hPrpISRThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PrpIntrThread, this, 0, NULL);

    if (m_hPrpISRThread == NULL)
    {
        DEBUGMSG(ZONE_ERROR,(TEXT("%s: CreateThread failed!\r\n"), __WFUNCTION__));
        return FALSE;
    }
    else
    {
        DEBUGMSG(ZONE_INIT, (TEXT("%s: create camera ISR thread success\r\n"), __WFUNCTION__));
        CeSetThreadPriority(m_hPrpISRThread, 100);//THREAD_PRIORITY_TIME_CRITICAL);
    }

    // Initialize encoding buffer worker thread
    m_hPrpEncBufThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PrpEncBufferWorkerThread, this, 0, NULL);

    if (m_hPrpEncBufThread == NULL)
    {
        DEBUGMSG(ZONE_ERROR,(TEXT("%s: CreateThread failed!\r\n"), __WFUNCTION__));
        return FALSE;
    }
    else
    {
        DEBUGMSG(ZONE_INIT, (TEXT("%s: create encoding buffer worker thread success\r\n"), __WFUNCTION__));
    }

    // Initialize encoding buffer worker thread
    m_hPrpEncRotBufThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PrpEncRotBufferWorkerThread, this, 0, NULL);

    if (m_hPrpEncRotBufThread == NULL)
    {
        DEBUGMSG(ZONE_ERROR,(TEXT("%s: CreateThread failed!\r\n"), __WFUNCTION__));
        return FALSE;
    }
    else
    {
        DEBUGMSG(ZONE_INIT, (TEXT("%s: create rotation for encoding buffer worker thread success\r\n"), __WFUNCTION__));
    }

    // Initialize viewfinding buffer worker thread
    m_hPrpVfBufThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PrpVfBufferWorkerThread, this, 0, NULL);

    if (m_hPrpVfBufThread == NULL)
    {
        DEBUGMSG(ZONE_ERROR,(TEXT("%s: CreateThread failed!\r\n"), __WFUNCTION__));
        return FALSE;

⌨️ 快捷键说明

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