📄 ppclass.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: PpClass.cpp
//
// This file contains the methods of post-processing class.
//
//------------------------------------------------------------------------------
#include <windows.h>
#include <ceddk.h>
#include <NKIntr.h>
#include "csp.h"
#include "emma.h"
#include "pp.h"
#include "PpClass.h"
//------------------------------------------------------------------------------
// External Functions
extern BOOL BSPPpAlloc();
extern void BSPPpDealloc();
extern BOOL BSPPpSetClockGatingMode(BOOL bEnable);
extern void BSPSetPpBufferThreadPriority();
extern void BSPSetPpIntrThreadPriority();
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
// Local Functions
//-----------------------------------------------------------------------------
//
// Function: PpClass
//
// Post-processor 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 post-processor.
//
// Parameters:
// None.
//
// Returns:
// TRUE if successful; FALSE if failed.
//
//-----------------------------------------------------------------------------
BOOL PpClass::PpInit(void)
{
PP_FUNCTION_ENTRY();
m_iInBufSize = 0;
m_iOutBufSize = 0;
if (!PpAlloc())
goto _error;
if (!PpEventsInit())
goto _error;
// Initial settings
m_bConfigured = FALSE;
PP_FUNCTION_EXIT();
return TRUE;
_error:
PpDeinit();
return FALSE;
}
//-----------------------------------------------------------------------------
//
// Function: PpDeinit
//
// This function deinitializes the post-processor.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void PpClass::PpDeinit(void)
{
PP_FUNCTION_ENTRY();
PpEventsDeinit();
PpDealloc();
m_iInBufSize = 0;
m_iOutBufSize = 0;
PP_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
//
// Function: PpAlloc
//
// This function allocates data structure for post-processor.
//
// Parameters:
// None.
//
// Returns:
// TRUE if successful; FALSE if failed.
//
//-----------------------------------------------------------------------------
BOOL PpClass::PpAlloc(void)
{
MSGQUEUEOPTIONS queueOptions;
PP_FUNCTION_ENTRY();
// Map post-processor registers
PHYSICAL_ADDRESS phyAddr;
phyAddr.QuadPart = CSP_BASE_REG_PA_EMMA_PP;
m_pPpReg = (PCSP_PP_REGS)MmMapIoSpace(phyAddr, sizeof(CSP_PP_REGS), FALSE);
if (m_pPpReg == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Map PP registers failed\r\n"), __WFUNCTION__));
return FALSE;
}
//
// 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(ppBuffers);
queueOptions.bReadAccess = TRUE; // we need read-access to msgqueue
// Create read handles for queues
m_hReadPpBufferQueue = CreateMsgQueue(NULL, &queueOptions);
if (m_hReadPpBufferQueue == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Creating input buffer queue failed.\r\n"),
__WFUNCTION__));
return FALSE;
}
queueOptions.bReadAccess = FALSE; // we need write-access to msgqueue
// Create write handles for queues
m_hWritePpBufferQueue = OpenMsgQueue(GetCurrentProcess(),
m_hReadPpBufferQueue, &queueOptions);
if (m_hWritePpBufferQueue == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Opening input buffer queue for writing failed.\r\n"),
__WFUNCTION__));
return FALSE;
}
// Call BSP-Specific allocation
if (!BSPPpAlloc()) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Calling BSPPpAlloc() failed.\r\n"),
__WFUNCTION__));
return FALSE;
}
PP_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: PpDealloc
//
// This function deallocates data structure for post-processor.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void PpClass::PpDealloc(void)
{
PP_FUNCTION_ENTRY();
// Unmap post-processor registers
if (m_pPpReg != NULL) {
MmUnmapIoSpace(m_pPpReg, sizeof(CSP_PP_REGS));
m_pPpReg = NULL;
}
//
// Close messages queues handlers
//
if (m_hReadPpBufferQueue != NULL) {
CloseHandle(m_hReadPpBufferQueue);
m_hReadPpBufferQueue = NULL;
}
if (m_hWritePpBufferQueue != NULL) {
CloseHandle(m_hWritePpBufferQueue);
m_hWritePpBufferQueue = NULL;
}
// Call BSP-Specific deallocation
BSPPpDealloc();
PP_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
//
// Function: PpEventsInit
//
// This function initializes events related for post-processor.
//
// Parameters:
// None.
//
// Returns:
// TRUE if successful; FALSE if failed.
//
//-----------------------------------------------------------------------------
BOOL PpClass::PpEventsInit(void)
{
PP_FUNCTION_ENTRY();
//
// Initialization for post-processor interrupt
//
// Create event for post-processor interrupt
m_hPpIntrEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (m_hPpIntrEvent == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: CreateEvent for PP interrupt failed\r\n"),
__WFUNCTION__));
return FALSE;
}
// Request sysintr for post-processor interrupt
DWORD irq = IRQ_EMMAPP;
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &irq, sizeof(DWORD),
&m_iPpSysintr, sizeof(DWORD), NULL)) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Request SYSINTR for PP interrupt failed\r\n"),
__WFUNCTION__));
return FALSE;
}
// Initialize post-processor interrupt
if (!InterruptInitialize(m_iPpSysintr, m_hPpIntrEvent, NULL, NULL)) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Initialize PP interrupt failed\r\n"), __WFUNCTION__));
return FALSE;
}
// Create the thread for post-processor interrupt
m_hPpIntrThread = ::CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE)PpIntrThread, this, 0, NULL);
if (m_hPpIntrThread == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Create thread for PP interrupt failed\r\n"),
__WFUNCTION__));
return FALSE;
}
//
// Initialize post-processing buffer worker thread
//
m_hPpBufThread = ::CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE)PpBufferWorkerThread, this, 0, NULL);
if (m_hPpBufThread == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Create thread for post-processing buffer worker failed\r\n"),
__WFUNCTION__));
return FALSE;
}
//
// Create other required events
//
// Event for signaling pin that frame is ready
m_hPpEOFEvent = CreateEvent(NULL, FALSE, FALSE, PP_EOF_EVENT_NAME);
if (m_hPpEOFEvent == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: CreateEvent failed for indicating PP EOF\r\n"),
__WFUNCTION__));
return FALSE;
}
// Event for signaling buffer worker thread that
// post-processor is ready for the new processing.
m_hPpReadyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (m_hPpReadyEvent == NULL) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: CreateEvent failed for indicating PP ready\r\n"),
__WFUNCTION__));
return FALSE;
}
PP_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: PpEventsDeinit
//
// This function deinitializes events related for post-processor.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void PpClass::PpEventsDeinit(void)
{
PP_FUNCTION_ENTRY();
// Release sysintr for post-processor interrupt
if (m_iPpSysintr != SYSINTR_UNDEFINED) {
// Disable post-processor interrupt first
InterruptDisable(m_iPpSysintr);
if (!KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &m_iPpSysintr,
sizeof(DWORD), NULL, 0, NULL)) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Release sysintr for PP interrupt failed\r\n"),
__WFUNCTION__));
}
}
// Close events
if (m_hPpEOFEvent != NULL) {
CloseHandle(m_hPpEOFEvent);
m_hPpEOFEvent = NULL;
}
if (m_hPpReadyEvent != NULL) {
CloseHandle(m_hPpReadyEvent);
m_hPpReadyEvent = NULL;
}
if (m_hPpIntrEvent != NULL) {
CloseHandle(m_hPpIntrEvent);
m_hPpIntrEvent = NULL;
}
// Terminate interrupt threads
if (m_hPpIntrThread != NULL) {
TerminateThread(m_hPpIntrThread, 0);
CloseHandle(m_hPpIntrThread);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -