📄 bspvpu.c
字号:
//------------------------------------------------------------------------------
// Copyright (C) 2006-2007, 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: bspvpu.c
//
// Provides BSP-specific configuration routines for the VPU module.
//
//-----------------------------------------------------------------------------
#pragma warning(push)
#pragma warning(disable: 4115)
#pragma warning(disable: 4201)
#pragma warning(disable: 4204)
#pragma warning(disable: 4214)
#include <windows.h>
#pragma warning(pop)
#include "vpu_api.h"
#include "bsp.h"
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
// VPU Name of Mutex accessing the global parameters
#define VPU_ARG_MUTEX_NAME L"Vpu Arg Mutex"
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
typedef struct {
BOOL Initialized;
BOOL MPEG4Codec;
UINT8 UsedInst[4];
} BSP_VPU_GLOBALS, *PBSP_VPU_GLOBALS;
//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
static BSP_VPU_GLOBALS g_VPUGlobal;
static HANDLE g_hVpuArgMutex;
//-----------------------------------------------------------------------------
//
// Function: BSPVpuGetWorkingBufAddress
//
// This method allocates the physical memmory used for working buffer,
// parameter buffer and code table.
//
// Parameters: The size of physical memory requested.
//
//
// Returns:
// The Physical address of working buffer, parameter buffer and code table
//
//-----------------------------------------------------------------------------
PhysicalAddress BSPVpuGetWorkingBufAddress(Uint32 size)
{
// Remove-W4: Warning C4100 workaround
UNREFERENCED_PARAMETER(size);
return IMAGE_SHARE_VPU_RAM_PA_START;
}
//-----------------------------------------------------------------------------
//
// Function: BSPVpuInit
//
// This method does the board specific initialization for accessing to VPU
//
//
// Parameters: The pointer to the Uint32 that stores the flag, which indicates
// if the hardware has already been used by other application
//
// Returns:
// TRUE for success, FALSE for failure
//
//-----------------------------------------------------------------------------
BOOL BSPVpuInit(Uint32 *pUsedInOtherProcess)
{
int i;
BOOL initState;
g_hVpuArgMutex = CreateMutex(NULL, FALSE, VPU_ARG_MUTEX_NAME);
if (g_hVpuArgMutex == NULL) {
ERRORMSG(TRUE, (TEXT("Create mutex for global args failed!\r\n")));
return FALSE;
}
g_VPUGlobal.Initialized = FALSE;
// Get VPU global parameters
WaitForSingleObject(g_hVpuArgMutex, INFINITE);
if(g_VPUGlobal.Initialized && pUsedInOtherProcess)
*pUsedInOtherProcess = 1;
else {
for (i = 0; i < MAX_NUM_INSTANCE; ++i)
g_VPUGlobal.UsedInst[i] = 0; // Initailizing the used instances flag.
g_VPUGlobal.Initialized = TRUE;
g_VPUGlobal.MPEG4Codec= FALSE;
*pUsedInOtherProcess = 0;
}
ReleaseMutex(g_hVpuArgMutex);
if(*pUsedInOtherProcess == 0) {
// Enable H.264 BAUD clock clocks
initState = DDKClockSetGatingMode(DDK_CLOCK_GATE_INDEX_H264_BAUD, DDK_CLOCK_GATE_MODE_ENABLE);
if(initState != TRUE) {
ERRORMSG(1, (TEXT("%s: H264 BAUD clock enable failed!\r\n"), __WFUNCTION__));
goto cleanUp;
}
// Enable H.264 HAB clocks
initState = DDKClockSetGatingMode(DDK_CLOCK_GATE_INDEX_HCLK_H264, DDK_CLOCK_GATE_MODE_ENABLE);
if(initState != TRUE) {
ERRORMSG(1, (TEXT("%s: H264 HAB clock enable failed!\r\n"), __WFUNCTION__));
goto cleanUp;;
}
}
return TRUE;
cleanUp:
if(g_hVpuArgMutex) {
CloseHandle(g_hVpuArgMutex);
g_hVpuArgMutex = NULL;
}
DDKClockSetGatingMode(DDK_CLOCK_GATE_INDEX_H264_BAUD, DDK_CLOCK_GATE_MODE_DISABLE);
return FALSE;
}
//-----------------------------------------------------------------------------
//
// Function: BSPVpuDeinit
//
// This method does the board specific deinitialization
//
//
// Parameters: The pointer to the Uint32 that stores the flag, which indicates
// if the hardware is used by other application
//
// Returns:
// TRUE for success, FALSE for failure
//
//-----------------------------------------------------------------------------
BOOL BSPVpuDeinit(Uint32 *pUsedInOtherProcess)
{
int i;
*pUsedInOtherProcess = 0;
// Update VPU global parameters
WaitForSingleObject(g_hVpuArgMutex, INFINITE);
for (i = 0; i < MAX_NUM_INSTANCE; ++i) {
if (g_VPUGlobal.UsedInst[i]) {
*pUsedInOtherProcess = 1;
break;
}
}
if(*pUsedInOtherProcess == 0)
g_VPUGlobal.Initialized = FALSE;
ReleaseMutex(g_hVpuArgMutex);
if(!g_hVpuArgMutex) {
CloseHandle(g_hVpuArgMutex);
g_hVpuArgMutex = NULL;
}
if(*pUsedInOtherProcess == 0) {
// Disable H.264 BAUD clock clocks
DDKClockSetGatingMode(DDK_CLOCK_GATE_INDEX_H264_BAUD, DDK_CLOCK_GATE_MODE_DISABLE);
// Disable H.264 HAB clocks
DDKClockSetGatingMode(DDK_CLOCK_GATE_INDEX_HCLK_H264, DDK_CLOCK_GATE_MODE_DISABLE);
}
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: BSPVpuGetCodecInstance
//
// This function obtains a processing instance
//
// Parameters:
// No input
//
// Returns:
// Index allocated for current decoder instance
//
//------------------------------------------------------------------------------
UINT32 BSPVpuGetCodecInstance(void)
{
int i;
int AvailableInstidx = MAX_NUM_INSTANCE;
// Update VPU global parameters
WaitForSingleObject(g_hVpuArgMutex, INFINITE);
for (i = 0; i < MAX_NUM_INSTANCE; ++i) {
if (!g_VPUGlobal.UsedInst[i]) {
g_VPUGlobal.UsedInst[i] = 1;
AvailableInstidx = i;
break;
}
}
ReleaseMutex(g_hVpuArgMutex);
return AvailableInstidx;
}
//------------------------------------------------------------------------------
//
// Function: BSPVpuFreeCodecInstance
//
// This function releases a processing instance
//
// Parameters:
// uInstIdx
// [in] Index of decoder instance that'll be freed
//
// Returns:
// No return value.
//
//------------------------------------------------------------------------------
void BSPVpuFreeCodecInstance(UINT32 uInstIdx)
{
// Update VPU global parameters
WaitForSingleObject(g_hVpuArgMutex, INFINITE);
g_VPUGlobal.UsedInst[uInstIdx] = 0;
ReleaseMutex(g_hVpuArgMutex);
}
//------------------------------------------------------------------------------
// The method to access the ESDRAMC registers for TO2 MPEG4 software workaround
//------------------------------------------------------------------------------
BOOL SetEsdramcLatencyHiding(CodStd codestd)
{
BOOL SetLH = FALSE;
BOOL rc = FALSE;
WaitForSingleObject(g_hVpuArgMutex, INFINITE);
if(!g_VPUGlobal.MPEG4Codec && codestd == STD_MPEG4) {
if(!KernelIoControl(IOCTL_HAL_SET_ESDMISC_LH, &SetLH, sizeof(BOOL), NULL, 0, NULL)){
ERRORMSG(TRUE, (TEXT("IOCTL_HAL_SET_ESDMISC_LH failed !\r\n")));
goto CleanUp;
}
g_VPUGlobal.MPEG4Codec = TRUE;
}
else if (g_VPUGlobal.MPEG4Codec && codestd != STD_MPEG4){
SetLH = TRUE;
if(!KernelIoControl(IOCTL_HAL_SET_ESDMISC_LH, &SetLH, sizeof(BOOL), NULL, 0, NULL)){
ERRORMSG(TRUE, (TEXT("IOCTL_HAL_SET_ESDMISC_LH failed !\r\n")));
goto CleanUp;
}
g_VPUGlobal.MPEG4Codec = FALSE;
}
ReleaseMutex(g_hVpuArgMutex);
rc = TRUE;
CleanUp:
return rc;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -