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

📄 ppclass.cpp

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

#include "Ipu.h"
#include "pp.h"
#include "PpClass.h"


//------------------------------------------------------------------------------
// External Functions
extern void BSPSetPPISRPriority();
extern void BSPSetPPBufferThreadPriority();
extern void BSPSetPPRotBufferThreadPriority();


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


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

#define THREAD_PRIORITY                            250

#define PP_MAX_NUM_BUFFERS                         100
#define PP_NUM_ROT_BUFFERS                         2

#define PP_IC_TO_MEM_DMA_CHANNEL                   IPU_DMA_CHA_DMAIC_2_LSH
#define PP_MEM_TO_IC_DMA_CHANNEL                   IPU_DMA_CHA_DMAIC_5_LSH
#define PP_IC_TO_MEM_ROT_DMA_CHANNEL               IPU_DMA_CHA_DMAIC_12_LSH
#define PP_MEM_TO_IC_ROT_DMA_CHANNEL               IPU_DMA_CHA_DMAIC_13_LSH


//------------------------------------------------------------------------------
// 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


// TODO:  Remove, for debug purposes only
static UINT16 g_iOutputWidth, g_iOutputHeight;
static UINT32 g_iOutputPhysAddr;

//------------------------------------------------------------------------------
// Local Functions
static void dumpChannelParams(pPpIDMACChannelParams);
static void dumpCoeffs(pPpCSCCoeffs);
static void dumpInterruptRegisters(PCSP_IPU_REGS);
static void dumpIpuRegisters(PCSP_IPU_REGS);
static void ReadVfDMA(PCSP_IPU_REGS);
static void generateBMP(UINT32 phyImageBuf, LONG width, LONG height);

//-----------------------------------------------------------------------------
//
// Function: PpClass
//
// Postprocessor class constructor.  Calls PpInit to initialize module.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//-----------------------------------------------------------------------------
PpClass::PpClass(void)
{
    PpInit();
}

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

//-----------------------------------------------------------------------------
//
// Function: PpInit
//
// This function initializes the Image Converter (postprocessor).
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//-----------------------------------------------------------------------------
BOOL PpClass::PpInit(void)
{
    MSGQUEUEOPTIONS queueOptions;

    PP_FUNCTION_ENTRY();

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

    DEBUGMSG(ZONE_INIT, (TEXT("%s: CreateEvent for PP EOF event\r\n"), __WFUNCTION__));
    // Events to signal pin that frame is ready
    m_hEOFEvent = CreateEvent(NULL, FALSE, FALSE, PP_EOF_EVENT_NAME);
    if (m_hEOFEvent == NULL)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: CreateEvent failed for PP EOF\r\n"), __WFUNCTION__));
        goto Error;
    }

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

    m_hRequestRotBuffer = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (m_hRequestRotBuffer == NULL)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: CreateEvent failed for Request PP for Rotataion Buffer\r\n"), __WFUNCTION__));
        goto Error;
    }


    DEBUGMSG(ZONE_INIT, (TEXT("%s: Create msgqueues\r\n"), __WFUNCTION__));
    // Create queues for reading and writing messages
    queueOptions.dwSize = sizeof(MSGQUEUEOPTIONS);
    queueOptions.dwFlags = MSGQUEUE_ALLOW_BROKEN;
    queueOptions.dwMaxMessages = PP_MAX_NUM_BUFFERS;
    queueOptions.cbMaxMessage = sizeof(DISPLAY_BUFFER);
    queueOptions.bReadAccess = TRUE; // we need read-access to msgqueue

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

    queueOptions.cbMaxMessage = sizeof(ppBuffers);

    m_hReadInputBufferQueue = CreateMsgQueue(NULL, &queueOptions);
    if (!m_hReadInputBufferQueue)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Error creating Input Buffer queue.  Initialization failed! \r\n"), __WFUNCTION__));
    }

    m_hReadOutputBufferQueue = CreateMsgQueue(NULL, &queueOptions);
    if (!m_hReadOutputBufferQueue)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Error creating Output Buffer queue.  Initialization failed! \r\n"), __WFUNCTION__));
    }

    queueOptions.cbMaxMessage = sizeof(DISPLAY_BUFFER);
    queueOptions.bReadAccess = FALSE; // we need write-access to msgqueue

    // Create write handles for queues
    m_hWriteDisplayBufferQueue = OpenMsgQueue(GetCurrentProcess(), m_hReadDisplayBufferQueue, &queueOptions);
    if (!m_hWriteDisplayBufferQueue)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Error opening display buffer queue for writing.  Initialization failed! \r\n"), __WFUNCTION__));
    }

    queueOptions.cbMaxMessage = sizeof(ppBuffers);

    m_hWriteInputBufferQueue = OpenMsgQueue(GetCurrentProcess(), m_hReadInputBufferQueue, &queueOptions);
    if (!m_hWriteInputBufferQueue)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Error opening input buffer queue for writing.  Initialization failed! \r\n"), __WFUNCTION__));
    }

    m_hWriteOutputBufferQueue = OpenMsgQueue(GetCurrentProcess(), m_hReadOutputBufferQueue, &queueOptions);
    if (!m_hWriteOutputBufferQueue)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Error opening output buffer queue for writing.  Initialization failed! \r\n"), __WFUNCTION__));
    }


    DEBUGMSG(ZONE_INIT, (TEXT("%s: Initializing class variables\r\n"), __WFUNCTION__));
    InitializeCriticalSection(&m_csStopping);

    pRotBufferManager = new IpuBufferManager();

    m_bConfigured = FALSE;
    m_bDisplayInitialized = FALSE;

    m_bRotBuffersAllocated = FALSE;

    m_iLastAllocatedBufferSize = 0;

    m_bInputPlanar = FALSE;
    m_bOutputPlanar = FALSE;
    
    m_bRequestSecondBuffer = FALSE;
    m_bRotRequestSecondBuffer = FALSE;

    m_hDisplay = NULL;

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

    m_bRestartBufferLoop = FALSE;
    m_bRotRestartBufferLoop = FALSE;
    m_bRestartISRLoop = FALSE;

    m_bRunning = FALSE;

    m_bFlipRot = FALSE;

    m_iFrameCount = 0;

    m_iBuf0Ready = FALSE;
    m_iBuf1Ready = FALSE;

    // One-time initialization of rotation buffers
    PpAllocateRotBuffers(PP_NUM_ROT_BUFFERS, 640*480*2);

    DEBUGMSG(ZONE_INIT, (TEXT("%s: Spawning threads\r\n"), __WFUNCTION__));

    // Initialize thread for Postprocessor 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_hPpISRThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PpIntrThread, this, 0, NULL);

    if (m_hPpISRThread == NULL)
    {
        DEBUGMSG(ZONE_ERROR,(TEXT("%s: CreateThread failed!\r\n"), __WFUNCTION__));
        goto Error;
    }
    else
    {
        DEBUGMSG(ZONE_INIT, (TEXT("%s: create camera ISR thread success\r\n"), __WFUNCTION__));
    }

    // Initialize PP buffer worker thread
    m_hPpBufThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PpBufferWorkerThread, this, 0, NULL);

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

    // Initialize PP rotation buffer worker thread
    m_hPpRotBufThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)PpRotBufferWorkerThread, this, 0, NULL);

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

    DEBUGMSG(ZONE_INIT, (TEXT("%s: Enabling postprocessor\r\n"), __WFUNCTION__));

    // Enable Postprocessor
    PpEnable();

    PP_FUNCTION_EXIT();

    return TRUE;

Error:
    PpDeinit();

⌨️ 快捷键说明

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