📄 prpclass.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, MOTOROLA, INC. All Rights Reserved
// THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
// BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
// MOTOROLA, INC.
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2004-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: PrpClass.cpp
//
// This file contains the methods of pre-processing class.
//
//------------------------------------------------------------------------------
#include <windows.h>
#include <ceddk.h>
#include <NKIntr.h>
#include "csp.h"
#include "emma.h"
#include "prp.h"
#include "PrpClass.h"
#ifndef PRP_MEM_MODE_DLL
#include "cameradbg.h"
#endif
//------------------------------------------------------------------------------
// External Functions
extern BOOL BSPPrpAlloc();
extern void BSPPrpDealloc();
extern BOOL BSPPrpSetClockGatingMode(BOOL bEnable);
extern void BSPSetPrpIntrThreadPriority();
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
// Local Functions
//-----------------------------------------------------------------------------
//
// Function: PrpClass
//
// Pre-processor 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 pre-processor.
//
// Parameters:
// None.
//
// Returns:
// TRUE if successful; FALSE if failed.
//
//-----------------------------------------------------------------------------
BOOL PrpClass::PrpInit(void)
{
PRP_FUNCTION_ENTRY();
m_bConfigured = FALSE;
m_bEnableVfOutput = FALSE;
m_bEnableEncOutput = FALSE;
m_iVfFrameCount = 0;
m_iEncFrameCount = 0;
#ifndef PRP_MEM_MODE_DLL
m_bVfStopReq = FALSE;
m_bEncStopReq = FALSE;
m_iVfState = prpChannelStopped;
m_iEncState = prpChannelStopped;
#endif
m_pPrpConfig = NULL;
if (!PrpAlloc())
goto _error;
PRP_FUNCTION_EXIT();
return TRUE;
_error:
PrpDeinit();
return FALSE;
}
//-----------------------------------------------------------------------------
//
// Function: PrpDeinit
//
// This function deinitializes the pre-processor.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void PrpClass::PrpDeinit(void)
{
PRP_FUNCTION_ENTRY();
PrpDealloc();
PRP_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
//
// Function: PrpAlloc
//
// This function allocates data structure for pre-processor.
//
// Parameters:
// None.
//
// Returns:
// TRUE if successful; FALSE if failed.
//
//-----------------------------------------------------------------------------
BOOL PrpClass::PrpAlloc(void)
{
PRP_FUNCTION_ENTRY();
// Map pre-processor registers
PHYSICAL_ADDRESS phyAddr;
phyAddr.QuadPart = CSP_BASE_REG_PA_EMMA_PRP;
m_pPrpReg = (PCSP_PRP_REGS )MmMapIoSpace(phyAddr,
sizeof(CSP_PRP_REGS), FALSE);
if (m_pPrpReg == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Map PrP registers failed\r\n"), __WFUNCTION__));
return FALSE;
}
// Call BSP-Specific allocation
if (!BSPPrpAlloc()) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Calling BSPPrpAlloc() failed.\r\n"),
__WFUNCTION__));
return FALSE;
}
#ifndef PRP_MEM_MODE_DLL
// Buffer manager
pEncBufferManager = new PrpBufferManager();
pVfBufferManager = new PrpBufferManager();
#endif
PRP_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: PrpDealloc
//
// This function deallocates data structure for pre-processor.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void PrpClass::PrpDealloc(void)
{
PRP_FUNCTION_ENTRY();
// Unmap PrP registers
if (m_pPrpReg != NULL) {
MmUnmapIoSpace(m_pPrpReg, sizeof(CSP_PRP_REGS));
m_pPrpReg = NULL;
}
// Call BSP-Specific deallocation
BSPPrpDealloc();
#ifndef PRP_MEM_MODE_DLL
// Buffer manager
if (pEncBufferManager != NULL)
delete pEncBufferManager;
if (pVfBufferManager != NULL)
delete pVfBufferManager;
#endif
if (NULL != m_pPrpConfig)
{
free(m_pPrpConfig);
m_pPrpConfig = NULL;
}
PRP_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
//
// Function: PrpEventsInit
//
// This function initializes events related for pre-processor.
//
// Parameters:
// None.
//
// Returns:
// TRUE if successful; FALSE if failed.
//
//-----------------------------------------------------------------------------
BOOL PrpClass::PrpEventsInit(void)
{
PRP_FUNCTION_ENTRY();
//
// Initialization for pre-processor interrupt
//
// Create event for pre-processor interrupt
m_hPrpIntrEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (m_hPrpIntrEvent == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: CreateEvent for PrP interrupt failed\r\n"),
__WFUNCTION__));
return FALSE;
}
// Request sysintr for pre-processor interrupt
DWORD irq = IRQ_EMMAPRP;
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &irq, sizeof(DWORD),
&m_iPrpSysintr, sizeof(DWORD), NULL)) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Request SYSINTR for PrP interrupt failed\r\n"),
__WFUNCTION__));
return FALSE;
}
// Initialize pre-processor interrupt
if (!InterruptInitialize(m_iPrpSysintr, m_hPrpIntrEvent, NULL, NULL)) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Initialize PrP interrupt failed\r\n"), __WFUNCTION__));
return FALSE;
}
// Create the thread for pre-processor interrupt
m_hPrpIntrThread = ::CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE)PrpIntrThread, this, 0, NULL);
if (m_hPrpIntrThread == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Create thread for PrP interrupt failed\r\n"),
__WFUNCTION__));
return FALSE;
}
//
// Create other required events
//
// Event for signaling pin that viewfinding frame is ready
m_hVfEOFEvent = CreateEvent(NULL, FALSE, FALSE, PRP_VF_EOF_EVENT_NAME);
if (m_hVfEOFEvent == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: CreateEvent for PRP viewfinding channel EOF failed! \r\n"),
__WFUNCTION__));
return FALSE;
}
// Event for signaling pin that encoding frame is ready
m_hEncEOFEvent = CreateEvent(NULL, FALSE, FALSE, PRP_ENC_EOF_EVENT_NAME);
if (m_hEncEOFEvent == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: CreateEvent for PRP encoding channel EOF failed! \r\n"),
__WFUNCTION__));
return FALSE;
}
#ifndef PRP_MEM_MODE_DLL
// Event for channel stop request
m_hVfStopEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (m_hVfStopEvent == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: CreateEvent for viewfinding channel stop request failed! \r\n"),
__WFUNCTION__));
return FALSE;
}
m_hEncStopEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (m_hEncStopEvent == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: CreateEvent for encoding channel stop request failed! \r\n"),
__WFUNCTION__));
return FALSE;
}
#endif
PRP_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: PrpEventsDeinit
//
// This function deinitializes events related for pre-processor.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void PrpClass::PrpEventsDeinit(void)
{
PRP_FUNCTION_ENTRY();
// Release sysintr for pre-processor interrupt
if (m_iPrpSysintr != SYSINTR_UNDEFINED) {
// Disable pre-processor interrupt first
InterruptDisable(m_iPrpSysintr);
if (!KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &m_iPrpSysintr,
sizeof(DWORD), NULL, 0, NULL)) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Release sysintr for PrP interrupt failed\r\n"),
__WFUNCTION__));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -