scaler: Added new version v7_0.

Added scaler_v7_0.
Deprecated scaler_v6_0.

Signed-off-by: Durga challa <vnsldurg@xilinx.com>
This commit is contained in:
Durga challa 2014-08-22 18:22:50 +05:30 committed by Suneel Garapati
parent fd752a2f35
commit d1a911f62c
12 changed files with 3121 additions and 0 deletions

View file

@ -0,0 +1,42 @@
###############################################################################
#
# Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# Use of the Software is limited solely to applications:
# (a) running on a Xilinx device, or
# (b) that interact with a Xilinx device through a bus or interconnect.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Except as contained in this notice, the name of the Xilinx shall not be used
# in advertising or otherwise to promote the sale, use or other dealings in
# this Software without prior written authorization from Xilinx.
#
###############################################################################
OPTION psf_version = 2.1;
BEGIN driver scaler
OPTION supported_peripherals = (v_scaler_v7_[0-9][0-9]_[a-z] v_scaler_v[8-9]_[0-9]);
OPTION driver_state = ACTIVE;
OPTION copyfiles = all;
OPTION VERSION = 7.0;
OPTION NAME = scaler;
END driver

View file

@ -0,0 +1,109 @@
###############################################################################
#
# Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# Use of the Software is limited solely to applications:
# (a) running on a Xilinx device, or
# (b) that interact with a Xilinx device through a bus or interconnect.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Except as contained in this notice, the name of the Xilinx shall not be used
# in advertising or otherwise to promote the sale, use or other dealings in
# this Software without prior written authorization from Xilinx.
#
###############################################################################
# MODIFICATION HISTORY:
# Ver Who Date Changes
# -------- ------ -------- ------------------------------------
# 5.0 adk 12/10/13 Updated as per the New Tcl API's
proc generate {drv_handle} {
xdefine_include_file $drv_handle "xparameters.h" "XSCALER" "NUM_INSTANCES" "DEVICE_ID" "C_BASEADDR" "C_HIGHADDR" "C_NUM_V_TAPS" "C_NUM_H_TAPS" "C_MAX_PHASES" "C_MAX_COEF_SETS" "C_CHROMA_FORMAT" "C_SEPARATE_YC_COEFS" "C_SEPARATE_HV_COEFS"
xdefine_config_file $drv_handle "xscaler_g.c" "XScaler" "DEVICE_ID" "C_BASEADDR" "NUM_V_TAPS" "NUM_H_TAPS" "MAX_PHASES" "MAX_COEF_SETS" "C_CHROMA_FORMAT" "C_SEPARATE_YC_COEFS" "C_SEPARATE_HV_COEFS"
xdefine_canonical_xpars $drv_handle "xparameters.h" "XScaler" "DEVICE_ID" "C_BASEADDR" "C_HIGHADDR" "C_NUM_V_TAPS" "C_NUM_H_TAPS" "C_MAX_PHASES" "C_MAX_COEF_SETS" "C_CHROMA_FORMAT" "C_SEPARATE_YC_COEFS" "C_SEPARATE_HV_COEFS"
}
#
# Given a list of arguments, define each as a canonical constant name, using
# the driver name, in an include file.
#
proc xdefine_canonical_xpars {drv_handle file_name drv_string args} {
# Open include file
set file_handle [::hsm::utils::open_include_file $file_name]
# Get all the peripherals connected to this driver
set periphs [::hsm::utils::get_common_driver_ips $drv_handle]
# Get the names of all the peripherals connected to this driver
foreach periph $periphs {
set peripheral_name [string toupper [get_property NAME $periph]]
lappend peripherals $peripheral_name
}
# Get possible canonical names for all the peripherals connected to this driver
set device_id 0
foreach periph $periphs {
set canonical_name [string toupper [format "%s_%s" $drv_string $device_id]]
lappend canonicals $canonical_name
# Create a list of IDs of the peripherals whose hardware instance name
# doesn't match the canonical name. These IDs can be used later to
# generate canonical definitions
if { [lsearch $peripherals $canonical_name] < 0 } {
lappend indices $device_id
}
incr device_id
}
set i 0
foreach periph $periphs {
set periph_name [string toupper [get_property NAME $periph]]
# Generate canonical definitions only for the peripherals whose
# canonical name is not the same as hardware instance name
if { [lsearch $canonicals $periph_name] < 0 } {
puts $file_handle "/* Canonical definitions for peripheral $periph_name */"
set canonical_name [format "%s_%s" $drv_string [lindex $indices $i]]
foreach arg $args {
set lvalue [::hsm::utils::get_driver_param_name $canonical_name $arg]
# The commented out rvalue is the name of the instance-specific constant
# set rvalue [::hsm::utils::get_ip_param_name $periph $arg]
# The rvalue set below is the actual value of the parameter
set rvalue [get_property CONFIG.$arg $periph]
if {[llength $rvalue] == 0} {
set rvalue 0
}
set rvalue [::hsm::utils::format_addr_string $rvalue $arg]
puts $file_handle "#define $lvalue $rvalue"
}
puts $file_handle ""
incr i
}
}
puts $file_handle "\n/******************************************************************/\n"
close $file_handle
}

View file

@ -0,0 +1,344 @@
/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/
/*****************************************************************************/
/**
*
* @file example.c
*
* This file demonstrates how to use Xilinx XScaler driver on Xilinx MVI Video
* Scaler core. This code does not cover the Video DMA (VDMA) setup and any
* other configuration which might be required to get the Scaler working
* properly.
*
* This code makes the following assumptions:
* - Caching is disabled. Flushing and Invalidation operations for data buffer
* need to be added to this code if it is not the case.
*
* <pre>
* MODIFICATION HISTORY:
*
* Ver Who Date Changes
* ----- ---- -------- ------------------------------------------------------
* 1.00a xd 02/09/09 First release
* </pre>
*
*****************************************************************************/
#include "xscaler.h"
#include "xparameters.h"
/*
* Device related constants. Defined in xparameters.h.
*/
#define SCALER_DEVICE_ID XPAR_SCALER_0_DEVICE_ID
/*
* Index of Coefficient Set to load and use
*/
#define COEFF_SET_INDEX 0
/*
* Scaler Device related data structures
*/
XScaler ScalerInstance; /* Device driver instance */
XScalerAperture Aperture; /* Aperture setting */
XScalerStartFraction StartFraction; /* Luma/Chroma Start Fraction setting*/
XScalerCoeffBank CoeffBank; /* Coefficient bank */
static int ScalerExample(u16 ScalerDeviceID);
static void DownScale(XScaler *ScalerInstPtr);
static void UpScale(XScaler *ScalerInstPtr);
static void ScalerSetup(XScaler *ScalerInstPtr,
int ScalerInWidth, int ScalerInHeight,
int ScalerOutWidth, int ScalerOutHeight);
/*****************************************************************************/
/**
*
* This is the main function for the Scaler example. This function is not
* included if the example is generated from the TestAppGen test tool.
*
* @param None.
*
* @return 0 to indicate success, otherwise 1.
*
* @note None.
*
****************************************************************************/
int main(void)
{
int Status;
/*
* Call the Scaler example , specify the Device ID generated in
* xparameters.h
*/
Status = ScalerExample(SCALER_DEVICE_ID);
if (Status != 0) {
return 1;
}
return 0;
}
/*****************************************************************************/
/**
*
* This function is the entry of the feature demonstrations on MVI Video Scaler
* core. It initializes the Scaler device, then starts operations like
* format downscaling and format up scaling.
*
* @param ScalerDeviceID is the device ID of the scaler core.
*
* @return 0 if all tests pass, 1 otherwise.
*
* @note None.
*
******************************************************************************/
static int ScalerExample(u16 ScalerDeviceID)
{
int Status;
XScaler_Config *ScalerCfgPtr;
u32 Rdy;
/* Initialize the Scaler instance */
ScalerCfgPtr = XScaler_LookupConfig(ScalerDeviceID);
Status = XScaler_CfgInitialize(&ScalerInstance, ScalerCfgPtr,
ScalerCfgPtr->BaseAddress);
if (Status) {
return 1;
}
/* DownScaling example */
DownScale(&ScalerInstance);
/* UpScaling example */
UpScale(&ScalerInstance);
/* All tests passed. Return success */
return 0;
}
/*****************************************************************************/
/**
*
* This function shows the downscaling feature. This function downscales the
* video format from 1280x720 to 640x480.
*
* @param ScalerInstPtr is the pointer to the instance of the Scaler
* device.
*
* @return None
*
* @note None.
*
******************************************************************************/
static void DownScale(XScaler *ScalerInstPtr)
{
int InWidth, InHeight, OutWidth, OutHeight;
InWidth = 1280;
InHeight = 720;
OutWidth = 640;
OutHeight = 480;
ScalerSetup (ScalerInstPtr, InWidth, InHeight, OutWidth, OutHeight);
return;
}
/*****************************************************************************/
/**
*
* This function shows the up scaling feature. This function up scales the
* video format from 640x480 to 1280x720.
*
* @param ScalerInstPtr is the pointer to the instance of the Scaler
* device.
*
* @return None
*
* @note None.
*
******************************************************************************/
static void UpScale(XScaler *ScalerInstPtr)
{
int InWidth, InHeight, OutWidth, OutHeight;
InWidth = 640;
InHeight = 480;
OutWidth = 1280;
OutHeight = 720;
ScalerSetup (ScalerInstPtr, InWidth, InHeight, OutWidth, OutHeight);
return;
}
/*****************************************************************************/
/**
*
* This function sets up the scaler core for the feature demonstrations below.
* After the execution of this function, a set of coefficient value (containing
* 2 vertical and 2 horizontal coefficient banks) are loaded; aperture is set
* up and the scaling operation is started. This function is utilized by
* DownScale() and UpScale().
*
* @param ScalerInstPtr is the pointer to the instance of the Scaler
* device.
*
* @param ScalerInWidth is the width of the input aperture.
*
* @param ScalerInHeight is the height of the input aperture.
*
* @param ScalerOutWidth is the width of the output aperture.
*
* @param ScalerOutHeight is the height of the output aperture.
*
* @return None.
*
* @note None.
*
******************************************************************************/
static void ScalerSetup(XScaler *ScalerInstPtr,
int ScalerInWidth, int ScalerInHeight,
int ScalerOutWidth, int ScalerOutHeight)
{
int i;
u8 ChromaFormat;
u8 ChromaLumaShareCoeffBank;
u8 HoriVertShareCoeffBank;
/*
* Disable the scaler before setup and tell the device not to pick up
* the register updates until all are done
*/
XScaler_Disable(ScalerInstPtr);
XScaler_DisableRegUpdate(ScalerInstPtr);
/*
* Load a set of Coefficient values
*/
/* Fetch Chroma Format and Coefficient sharing info */
XScaler_GetCoeffBankSharingInfo(ScalerInstPtr,
&ChromaFormat,
&ChromaLumaShareCoeffBank,
&HoriVertShareCoeffBank);
CoeffBank.SetIndex = COEFF_SET_INDEX;
CoeffBank.PhaseNum = ScalerInstPtr->Config.MaxPhaseNum;
CoeffBank.TapNum = ScalerInstPtr->Config.VertTapNum;
/* Locate coefficients for Horizontal scaling */
CoeffBank.CoeffValueBuf = (u16 *)
XScaler_CoefValueLookup(ScalerInWidth,
ScalerOutWidth,
CoeffBank.TapNum,
CoeffBank.PhaseNum);
/* Load coefficient bank for Horizontal Luma */
XScaler_LoadCoeffBank(ScalerInstPtr, &CoeffBank);
/* Horizontal Chroma bank is loaded only if chroma/luma sharing flag
* is not set */
if (!ChromaLumaShareCoeffBank)
XScaler_LoadCoeffBank(ScalerInstPtr, &CoeffBank);
/* Vertical coeff banks are loaded only if horizontal/vertical sharing
* flag is not set
*/
if (!HoriVertShareCoeffBank) {
/* Locate coefficients for Vertical scaling */
CoeffBank.CoeffValueBuf = (u16 *)
XScaler_CoefValueLookup(ScalerInHeight,
ScalerOutHeight,
CoeffBank.TapNum,
CoeffBank.PhaseNum);
/* Load coefficient bank for Vertical Luma */
XScaler_LoadCoeffBank(ScalerInstPtr, &CoeffBank);
/* Vertical Chroma coeff bank is loaded only if chroma/luma
* sharing flag is not set
*/
if (!ChromaLumaShareCoeffBank)
XScaler_LoadCoeffBank(ScalerInstPtr, &CoeffBank);
}
/*
* Load phase-offsets into scaler
*/
StartFraction.LumaLeftHori = 0;
StartFraction.LumaTopVert = 0;
StartFraction.ChromaLeftHori = 0;
StartFraction.ChromaTopVert = 0;
XScaler_SetStartFraction(ScalerInstPtr, &StartFraction);
/*
* Set up Aperture.
*/
Aperture.InFirstLine = 0;
Aperture.InLastLine = ScalerInHeight - 1;
Aperture.InFirstPixel = 0;
Aperture.InLastPixel = ScalerInWidth - 1;
Aperture.OutVertSize = ScalerOutHeight;
Aperture.OutHoriSize = ScalerOutWidth;
Aperture.SrcVertSize = ScalerInHeight;
Aperture.SrcHoriSize = ScalerInWidth;
XScaler_SetAperture(ScalerInstPtr, &Aperture);
/*
* Set up phases
*/
XScaler_SetPhaseNum(ScalerInstPtr, ScalerInstPtr->Config.MaxPhaseNum,
ScalerInstPtr->Config.MaxPhaseNum);
/*
* Choose active set indexes for both vertical and horizontal directions
*/
XScaler_SetActiveCoeffSet(ScalerInstPtr, COEFF_SET_INDEX,
COEFF_SET_INDEX);
/*
* Enable the scaling operation
*/
XScaler_EnableRegUpdate(ScalerInstPtr);
XScaler_Enable(ScalerInstPtr);
return;
}

View file

@ -0,0 +1,17 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Driver example applications</title>
<link rel="stylesheet" type="text/css" href="../help.css">
</head>
<body bgcolor="#FFFFFF">
<h1> Example Applications for the driver scaler_v5_0 </h1>
<HR>
<ul>
<li>example.c <a href="example.c">(source)</a> </li>
</ul>
<p><font face="Times New Roman" color="#800000">Copyright © 1995-2014 Xilinx, Inc. All rights reserved.</font></p>
</body>
</html>

View file

@ -0,0 +1,28 @@
COMPILER=
ARCHIVER=
CP=cp
COMPILER_FLAGS=lm
EXTRA_COMPILER_FLAGS=
LIB=libxil.a
LEVEL=0
RELEASEDIR=../../../lib
INCLUDEDIR=../../../include
INCLUDES=-I./. -I${INCLUDEDIR}
INCLUDEFILES=*.h
LIBSOURCES=*.c
OUTS = *.o
libs:
echo "Compiling scaler"
$(COMPILER) $(COMPILER_FLAGS) $(EXTRA_COMPILER_FLAGS) $(INCLUDES) $(LIBSOURCES)
$(ARCHIVER) -r ${RELEASEDIR}/${LIB} ${OUTS}
make clean
include:
${CP} $(INCLUDEFILES) $(INCLUDEDIR)
clean:
rm -rf ${OUTS}

View file

@ -0,0 +1,934 @@
/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/
/**
*
* @file xscaler.c
*
* This is main code of Xilinx MVI Video Scaler device driver. The Scaler device
* converts a specified rectangular area of an input digital video image from
* one original sampling grid to a desired target sampling grid. Please see
* xscaler.h for more details of the driver.
*
* <pre>
* MODIFICATION HISTORY:
*
* Ver Who Date Changes
* ----- ---- -------- -------------------------------------------------------
* 1.00a xd 02/10/09 First release
* 2.00a xd 12/14/09 Updated doxygen document tags
* 4.01a cw 06/27/12 Updated tcl file with new parameter names (num_x_taps)
Updated mdd file with updated supported_peripherals field.
* 4.02a mpv 03/11/13 Updated the Driver to select the correct coeff bin.
* Changed RegValue variable to a volatile type
* Removed 10.x patch in the Tcl file
* 4.03a mpv 05/28/13 Fixed version limit in MDD file
* Updated the Driver input, output and aperture size mask
* 5.00a mpv 12/13/13 Updated to dynamic coeff generation to reduce driver size
* </pre>
*
******************************************************************************/
/***************************** Include Files *********************************/
#include "xscaler.h"
#include "xenv.h"
#include "xil_io.h"
#include "xil_assert.h"
/************************** Constant Definitions *****************************/
/**************************** Type Definitions *******************************/
/***************** Macros (Inline Functions) Definitions *********************/
/** @name Utility Macros
* @{
*/
/*****************************************************************************/
/**
*
* This macro calculates the integral value nearest to x rounding half-way cases
* away from zero, regardless of the current rounding direction.
*
* @param x has a float type value
*
* @return the integral value nearest to x rounding half-way cases away from
* zero, regardless of the current rounding direction.
*
* @note
* C-style signature:
* s32 round(float x);
*
******************************************************************************/
#define round(x) ((x) >= 0 ? (s32)((x) + 0.5) : (s32)((x) - 0.5))
/*@}*/
/************************** Function Prototypes ******************************/
static u32 XScaler_CoeffBinOffset(u32 InSize, u32 OutSize);
static void StubCallBack(void *CallBackRef, u32 Mask);
/************************* Data Structure Definitions ************************/
/**
* XScaler_CoefficientsBinScalingFactors contains scaling factors calculated
* using (Output_Size * 10000 / Input_Size). This table could help find
* the index of coefficient Bin given an input size and a output size.
*/
extern u16 XScaler_CoefficientBinScalingFactors[XSCL_NUM_COEF_BINS];
/**
* XScaler_GenCoefTable generates XScaler_coef_table containing the coefficient
* values for scaling operations
*/
extern s16 *XScaler_GenCoefTable(u32 Tap, u32 Phase);
/************************** Function Definition ******************************/
/*****************************************************************************/
/**
* This function initializes a Scaler device. This function must be called
* prior to using a Scaler device. Initialization of a Scaler includes setting
* up the instance data, and ensuring the hardware is in a quiescent state.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
* @param CfgPtr points to the configuration structure associated with the
* Scaler device.
* @param EffectiveAddr is the base address of the device. If address
* translation is being used, then this parameter must
* reflect the virtual base address. Otherwise, the physical address
* should be used.
* @return XST_SUCCESS
*
*****************************************************************************/
int XScaler_CfgInitialize(XScaler *InstancePtr, XScaler_Config *CfgPtr,
u32 EffectiveAddr)
{
/* Verify arguments */
Xil_AssertNonvoid(InstancePtr != NULL);
Xil_AssertNonvoid(CfgPtr != NULL);
Xil_AssertNonvoid(CfgPtr->MaxPhaseNum > 0);
Xil_AssertNonvoid(CfgPtr->MaxPhaseNum <= XSCL_MAX_PHASE_NUM);
Xil_AssertNonvoid(CfgPtr->HoriTapNum > 0);
Xil_AssertNonvoid(CfgPtr->HoriTapNum <= XSCL_MAX_TAP_NUM);
Xil_AssertNonvoid(CfgPtr->VertTapNum > 0);
Xil_AssertNonvoid(CfgPtr->VertTapNum <= XSCL_MAX_TAP_NUM);
Xil_AssertNonvoid(CfgPtr->CoeffSetNum > 0);
Xil_AssertNonvoid(CfgPtr->CoeffSetNum <= XSCL_MAX_COEFF_SET_NUM);
Xil_AssertNonvoid(EffectiveAddr != (u32)NULL);
/* Setup the instance */
memset((void *)InstancePtr, 0, sizeof(XScaler));
memcpy((void *)&(InstancePtr->Config), (const void *)CfgPtr,
sizeof(XScaler_Config));
InstancePtr->Config.BaseAddress = EffectiveAddr;
/* Set all handlers to stub values, let user configure this data later
*/
InstancePtr->EventCallBack = (XScaler_CallBack)StubCallBack;
InstancePtr->ErrorCallBack = (XScaler_CallBack)StubCallBack;
/* Reset the hardware and set the flag to indicate the driver is ready
*/
//XScaler_Reset(InstancePtr);
InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
return XST_SUCCESS;
}
/*****************************************************************************/
/**
* This function sets up aperture of a Scaler device. The aperture setting
* consists of input video aperture and output video size. This function
* calculates the scale factor accordingly based on the aperture setting and
* sets up the Scaler appropriately.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
* @param AperturePtr points to the aperture setting structure to set up
* the Scaler device.
* @return XST_SUCCESS
*
*****************************************************************************/
int XScaler_SetAperture(XScaler *InstancePtr, XScalerAperture *AperturePtr)
{
double VertScaleFactor;
double HoriScaleFactor;
u32 InLine;
u32 InPixel;
u32 OutSize;
u32 SrcSize;
u32 QuantizedHoriSize;
u32 QuantizedVertSize;
u32 QuantizedInLastPixel;
u32 QuantizedInLastLine;
/* Assert bad arguments and conditions */
Xil_AssertNonvoid(InstancePtr != NULL);
Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
Xil_AssertNonvoid(AperturePtr != NULL);
Xil_AssertNonvoid(AperturePtr->InFirstLine <= AperturePtr->InLastLine);
Xil_AssertNonvoid(AperturePtr->InFirstPixel <= AperturePtr->InLastPixel);
Xil_AssertNonvoid(AperturePtr->OutVertSize > 0);
Xil_AssertNonvoid(AperturePtr->OutHoriSize > 0);
/* Calculate vertical and horizontal scale factors */
VertScaleFactor =
(float)(AperturePtr->InLastLine - AperturePtr->InFirstLine
+ 1);
VertScaleFactor /=
(float)(AperturePtr->OutVertSize);
HoriScaleFactor =
(float)(AperturePtr->InLastPixel - AperturePtr->InFirstPixel
+ 1);
HoriScaleFactor /=
(float)AperturePtr->OutHoriSize;
/* Convert HoriScaleFactor and VertScaleFactor values into a format
* to write to HSF and VSF registers.
*/
VertScaleFactor *= XSCL_SHRINK_FACTOR;
HoriScaleFactor *= XSCL_SHRINK_FACTOR;
/* Quantize Aperture - feed scale-factor back in to provide the
* actual aperture required to generate the desired number of output
* samples.
*/
QuantizedHoriSize = AperturePtr->OutHoriSize - 1;
QuantizedHoriSize =
(u32)(((float)QuantizedHoriSize * HoriScaleFactor) /
XSCL_SHRINK_FACTOR);
QuantizedHoriSize += 1 + (InstancePtr->Config.HoriTapNum + 1) / 2;
QuantizedInLastPixel = AperturePtr->InFirstPixel + QuantizedHoriSize
- 1;
if (QuantizedInLastPixel > AperturePtr->InLastPixel)
QuantizedInLastPixel = AperturePtr->InLastPixel;
QuantizedVertSize = AperturePtr->OutVertSize - 1;
QuantizedVertSize =
(u32)(((float)QuantizedVertSize * VertScaleFactor) /
XSCL_SHRINK_FACTOR);
QuantizedVertSize += 1 + (InstancePtr->Config.VertTapNum + 1) / 2;
QuantizedInLastLine = AperturePtr->InFirstLine + QuantizedVertSize - 1;
if (QuantizedInLastLine > AperturePtr->InLastLine)
QuantizedInLastLine = AperturePtr->InLastLine;
/* Calculate input line, pixel and output size values */
InLine = AperturePtr->InFirstLine & XSCL_APTVERT_FIRSTLINE_MASK;
InLine |= (QuantizedInLastLine << XSCL_APTVERT_LASTLINE_SHIFT)
& XSCL_APTVERT_LASTLINE_MASK;
InPixel = AperturePtr->InFirstPixel & XSCL_APTHORI_FIRSTPXL_MASK;
InPixel |= (QuantizedInLastPixel << XSCL_APTHORI_LASTPXL_SHIFT)
& XSCL_APTHORI_LASTPXL_MASK;
OutSize = AperturePtr->OutHoriSize & XSCL_OUTSIZE_NUMPXL_MASK;
OutSize |= (AperturePtr->OutVertSize << XSCL_OUTSIZE_NUMLINE_SHIFT)
& XSCL_OUTSIZE_NUMLINE_MASK;
SrcSize = AperturePtr->SrcHoriSize & XSCL_SRCSIZE_NUMPXL_MASK;
SrcSize |= (AperturePtr->SrcVertSize << XSCL_SRCSIZE_NUMLINE_SHIFT)
& XSCL_SRCSIZE_NUMLINE_MASK;
/* Set up aperture related register in the Scaler */
XScaler_WriteReg((InstancePtr)->Config.BaseAddress,
XSCL_APTVERT, InLine);
XScaler_WriteReg((InstancePtr)->Config.BaseAddress,
XSCL_APTHORI, InPixel);
XScaler_WriteReg((InstancePtr)->Config.BaseAddress,
XSCL_OUTSIZE, OutSize);
XScaler_WriteReg((InstancePtr)->Config.BaseAddress,
XSCL_SRCSIZE, SrcSize);
XScaler_WriteReg((InstancePtr)->Config.BaseAddress,
XSCL_HSF, (u32)(round(HoriScaleFactor)));
XScaler_WriteReg((InstancePtr)->Config.BaseAddress,
XSCL_VSF, (u32)(round(VertScaleFactor)));
return XST_SUCCESS;
}
/*****************************************************************************/
/**
* This function gets aperture of a Scaler device. The aperture setting
* consists of input video aperture and output video size.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
* @param AperturePtr points to the aperture structure to store the current
* Scaler device setting after this function returns.
* @return None
*
*****************************************************************************/
void XScaler_GetAperture(XScaler *InstancePtr, XScalerAperture *AperturePtr)
{
u32 InLine;
u32 InPixel;
u32 OutSize;
/* Assert bad arguments and conditions */
Xil_AssertVoid(InstancePtr != NULL);
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
Xil_AssertVoid(AperturePtr != NULL);
/* Read the first/last line and pixel info for input side and
* vertical/horizontal size for output size
*/
InLine = XScaler_ReadReg((InstancePtr)->Config.BaseAddress,
XSCL_APTVERT);
InPixel = XScaler_ReadReg((InstancePtr)->Config.BaseAddress,
XSCL_APTHORI);
OutSize = XScaler_ReadReg((InstancePtr)->Config.BaseAddress,
XSCL_OUTSIZE);
/* Parse the info and populate the aperture structure */
AperturePtr->InFirstLine = InLine & XSCL_APTVERT_FIRSTLINE_MASK;
AperturePtr->InLastLine =
(InLine & XSCL_APTVERT_LASTLINE_MASK) >>
XSCL_APTVERT_LASTLINE_SHIFT;
AperturePtr->InFirstPixel = InPixel & XSCL_APTHORI_FIRSTPXL_MASK;
AperturePtr->InLastPixel =
(InPixel & XSCL_APTHORI_LASTPXL_MASK) >>
XSCL_APTHORI_LASTPXL_SHIFT;
AperturePtr->OutHoriSize = OutSize & XSCL_OUTSIZE_NUMPXL_MASK;
AperturePtr->OutVertSize =
(OutSize & XSCL_OUTSIZE_NUMLINE_MASK) >>
XSCL_OUTSIZE_NUMLINE_SHIFT;
return;
}
/*****************************************************************************/
/**
* This function sets the numbers of vertical and horizontal phases to be used
* by a Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
* @param VertPhaseNum is the number of vertical phase to set to
* @param HoriPhaseNum is the number of horizontal phase to set to
* @return None
*
*****************************************************************************/
void XScaler_SetPhaseNum(XScaler *InstancePtr, u16 VertPhaseNum,
u16 HoriPhaseNum)
{
u32 PhaseRegValue;
/* Assert bad arguments and conditions */
Xil_AssertVoid(InstancePtr != NULL);
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
Xil_AssertVoid(VertPhaseNum > 0);
Xil_AssertVoid(HoriPhaseNum > 0);
Xil_AssertVoid(VertPhaseNum <= InstancePtr->Config.MaxPhaseNum);
Xil_AssertVoid(HoriPhaseNum <= InstancePtr->Config.MaxPhaseNum);
/* Calculate the value to write to "Number of Phases Register" */
PhaseRegValue =
(VertPhaseNum << XSCL_NUMPHASE_VERT_SHIFT) &
XSCL_NUMPHASE_VERT_MASK;
PhaseRegValue |= HoriPhaseNum & XSCL_NUMPHASE_HORI_MASK;
/* Set up the Scaler core using the numbers of phases */
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_NUMPHASE,
PhaseRegValue);
return;
}
/*****************************************************************************/
/**
* This function gets the numbers of vertical and horizontal phases currently
* used by a Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
* @param VertPhaseNumPtr will point to the number of vertical phases used
* after this function returns.
* @param HoriPhaseNumPtr will point to the number of horizontal phases used
* after this function returns.
* @return None
*
*****************************************************************************/
void XScaler_GetPhaseNum(XScaler *InstancePtr, u16 *VertPhaseNumPtr,
u16 *HoriPhaseNumPtr)
{
u32 PhaseRegValue;
/* Assert bad arguments and conditions */
Xil_AssertVoid(InstancePtr != NULL);
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
Xil_AssertVoid(VertPhaseNumPtr != NULL);
Xil_AssertVoid(HoriPhaseNumPtr != NULL);
/* Get the value of "Number of Phases Register" */
PhaseRegValue = XScaler_ReadReg((InstancePtr)->Config.BaseAddress,
XSCL_NUMPHASE);
/* Parse the value and store the results */
*VertPhaseNumPtr =
(PhaseRegValue & XSCL_NUMPHASE_VERT_MASK) >>
XSCL_NUMPHASE_VERT_SHIFT;
*HoriPhaseNumPtr = PhaseRegValue & XSCL_NUMPHASE_HORI_MASK;
return;
}
/*****************************************************************************/
/**
* This function sets up Luma and Chroma start fractional values used by a
* Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
* @param StartFractionPtr is a pointer to a start fractional value set to be
* used.
* @return None
*
*****************************************************************************/
void XScaler_SetStartFraction(XScaler *InstancePtr,
XScalerStartFraction *StartFractionPtr)
{
/* Assert bad arguments and conditions */
Xil_AssertVoid(InstancePtr != NULL);
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
Xil_AssertVoid(StartFractionPtr != NULL);
/* Set up the fractional values */
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_FRCTLUMALEFT,
(u32)StartFractionPtr->LumaLeftHori &
XSCL_FRCTLUMALEFT_VALUE_MASK);
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_FRCTLUMATOP,
(u32)StartFractionPtr->LumaTopVert &
XSCL_FRCTLUMATOP_VALUE_MASK);
XScaler_WriteReg((InstancePtr)->Config.BaseAddress,
XSCL_FRCTCHROMALEFT,
(u32)StartFractionPtr->ChromaLeftHori &
XSCL_FRCTCHROMALEFT_VALUE_MASK);
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_FRCTCHROMATOP,
(u32)StartFractionPtr->ChromaTopVert &
XSCL_FRCTCHROMATOP_VALUE_MASK);
return;
}
/*****************************************************************************/
/**
* This function gets Luma and Chroma start fractional values currently used
* by a Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
* @param StartFractionPtr is a pointer to a start fractional value structure
* to be populated with the fractional values after this function
* returns.
* @return None
*
*****************************************************************************/
void XScaler_GetStartFraction(XScaler *InstancePtr,
XScalerStartFraction *StartFractionPtr)
{
/* Assert bad arguments and conditions */
Xil_AssertVoid(InstancePtr != NULL);
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
Xil_AssertVoid(StartFractionPtr != NULL);
/* Fetch the fractional values */
StartFractionPtr->LumaLeftHori = (s32)
XScaler_ReadReg((InstancePtr)->Config.BaseAddress,
XSCL_FRCTLUMALEFT)
& XSCL_FRCTLUMALEFT_VALUE_MASK;
StartFractionPtr->LumaTopVert = (s32)
XScaler_ReadReg((InstancePtr)->Config.BaseAddress,
XSCL_FRCTLUMATOP)
& XSCL_FRCTLUMATOP_VALUE_MASK;
StartFractionPtr->ChromaLeftHori = (s32)
XScaler_ReadReg((InstancePtr)->Config.BaseAddress,
XSCL_FRCTCHROMALEFT)
& XSCL_FRCTCHROMALEFT_VALUE_MASK;
StartFractionPtr->ChromaTopVert = (s32)
XScaler_ReadReg((InstancePtr)->Config.BaseAddress,
XSCL_FRCTCHROMATOP)
& XSCL_FRCTCHROMATOP_VALUE_MASK;
return;
}
/*****************************************************************************/
/**
* This function fetches the color space format and coefficient bank sharing
* decisions made on a Scaler device at build-time.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
* @param ChromaFormat points to an 8-bit variable that will be assigned with
* the Chroma format chosen for the Scaler device at the build time
* after this function returns. Please use XSCL_CHROMA_FORMAT_* defined
* in xscaler_hw.h to interpret the variable value.
* @param ChromaLumaShareCoeff points to an 8-bit variable that will be
* assigned by this function with the decision value on coefficient
* bank sharing between Chroma and Luma filter operations. The decision
* is made for the Scaler device at build time and can NOT be changed
* at run-time. Value 0 indicates that each of Chroma and Luma filter
* operations has its own coefficient bank. Value 1 indicates that
* Chroma and Luma filter operations share one common coefficient bank.
* @param HoriVertShareCoeff points to an 8-bit variable that will be
* assigned by this function with the decision value on coefficient
* bank sharing between Horizontal and Vertical filter operations. The
* decision is made for the Scaler device at build time and can NOT
* be changed at run-time. Value 0 indicates that each of Horizontal
* and Vertical filter operations has its own coefficient bank. Value 1
* indicates that Horizontal and Vertical filter operations share one
* common coefficient bank.
* @return None.
* @note
*
* !!!IMPORTANT!!!
*
* The application of this function is responsible for loading the correct
* number of coefficient banks in the proper sequence order. The number of
* coefficient banks to load and the proper loading sequence totally depends
* on the values of the output parameters of this function. Please use the
* table below as reference.
*
* <pre>
* ChromaFormat ChromaLumaShareCoeff HoriVertShareCoeff # of sequence
* coeff of
* banks loading
* to load coeff
* banks
* ------------ -------------------- ------------------ -------- -------------
* YUV420 1 1 1 1.Single bank
* ------------ -------------------- ------------------ -------- -------------
* YUV420 1 0 2 1.Hori bank
* 2.Vert bank
* ------------ -------------------- ------------------ -------- -------------
* YUV420 0 1 2 1.Luma bank
* 2.Chroma bank
* ------------ -------------------- ------------------ -------- -------------
* YUV420 0 0 4 1.Hori Luma
* 2.Hori Chroma
* 3.Vert Luma
* 4.Vert Chroma
* ------------ -------------------- ------------------ -------- -------------
* YUV422 1 1 1 1.Single bank
* ------------ -------------------- ------------------ -------- -------------
* YUV422 1 0 2 1.Hori bank
* 2.Vert bank
* ------------ -------------------- ------------------ -------- -------------
* YUV422 0 1 2 1.Luma bank
* 2.Chroma bank
* ------------ -------------------- ------------------ -------- -------------
* YUV422 0 0 4 1.Hori Luma
* 2.Hori Chroma
* 3.Vert Luma
* 4.Vert Chroma
* ------------ -------------------- ------------------ -------- -------------
* YUV444 Always 1 1 1 1.Single bank
* ------------ -------------------- ------------------ -------- -------------
* YUV444 Always 1 0 2 1.Hori bank
* 2.Vert bank
* ------------ -------------------- ------------------ -------- -------------
* </pre>
*
*****************************************************************************/
void XScaler_GetCoeffBankSharingInfo(XScaler *InstancePtr,
u8 *ChromaFormat,
u8 *ChromaLumaShareCoeff,
u8 *HoriVertShareCoeff)
{
/* Assert bad arguments and conditions */
Xil_AssertVoid(InstancePtr != NULL);
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
Xil_AssertVoid(ChromaFormat != NULL);
Xil_AssertVoid(ChromaLumaShareCoeff != NULL);
Xil_AssertVoid(HoriVertShareCoeff != NULL);
/* Output the Chroma format info */
*ChromaFormat = InstancePtr->Config.ChromaFormat;
/* Output the Coefficient bank sharing info between Horizontal and
* Vertical filter operations */
if (InstancePtr->Config.SeparateHvCoef)
*HoriVertShareCoeff = 0;
else
*HoriVertShareCoeff = 1;
/* Output the Coefficient bank sharing info between Chroma and
* Luma filter operations */
switch (*ChromaFormat) {
case XSCL_CHROMA_FORMAT_420:
case XSCL_CHROMA_FORMAT_422:
if (InstancePtr->Config.SeparateYcCoef)
*ChromaLumaShareCoeff = 0;
else
*ChromaLumaShareCoeff = 1;
break;
case XSCL_CHROMA_FORMAT_444:
*ChromaLumaShareCoeff = 1;
break;
}
return;
}
/*****************************************************************************/
/**
* This function returns the pointer to the coefficients for a scaling
* operation given input/output sizes and the Tap and Phase numbers.
*
* @param InSize indicates the size (width or height) of the input video.
* @param OutSize indicates the size (width or height) of the output video.
* @param Tap indicates the Tap number.
* @param Phase indicates the Phase number.
* @return The points to the coefficients ready for the scaling operation.
* @note None.
*
*****************************************************************************/
s16 *XScaler_CoefValueLookup(u32 InSize, u32 OutSize, u32 Tap, u32 Phase)
{
u32 CoeffBinIndex;
u32 CoeffValueOffset;
/* Validate the input parameters */
Xil_AssertNonvoid(InSize > 0);
Xil_AssertNonvoid(OutSize > 0);
Xil_AssertNonvoid(Tap >= XSCL_MIN_TAP_NUM);
Xil_AssertNonvoid(Tap <= XSCL_MAX_TAP_NUM);
Xil_AssertNonvoid(Phase >= XSCL_MIN_PHASE_NUM);
Xil_AssertNonvoid(Phase <= XSCL_MAX_PHASE_NUM);
/* Find the index of the Coefficient Bin */
CoeffBinIndex = XScaler_CoeffBinOffset(InSize, OutSize);
/* Find the offset of the Coefficients within the Bin */
CoeffValueOffset = XScaler_CoefTapOffset(Tap);
CoeffValueOffset += XScaler_CoefPhaseOffset(Tap, Phase);
return (XScaler_GenCoefTable(Tap,Phase));
}
/*****************************************************************************/
/**
* This function loads a coefficient bank to the Scaler core. A complete
* coefficient set contains 4 banks (if Luma, Chroma, Horizontal and Vertical
* filter operations do not share common banks. For more details see
* XScaler_GetCoeffBankSharingInfo()): Horizontal Luma, Horizontal Chroma,
* Vertical Luma and Vertical Chroma. all 4 banks must be loaded back to back
* in the order listed here. The caller is responsible for ensuring the
* sequence and this function does not check it.
*
* An example sequence to load an whole coefficient set is like:
* <pre>
* XScaler_LoadCoeffBank(&Scaler, &HoriLumaCoeffBank);
* XScaler_LoadCoeffBank(&Scaler, &HoriChromaCoeffBank);
* XScaler_LoadCoeffBank(&Scaler, &VertLumaCoeffBank);
* XScaler_LoadCoeffBank(&Scaler, &VertChromaCoeffBank);
* </pre>
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
* @param CoeffBankPtr is a pointer to a coefficient bank that is to be loaded
* @return None
*
*****************************************************************************/
void XScaler_LoadCoeffBank(XScaler *InstancePtr,
XScalerCoeffBank *CoeffBankPtr)
{
int PhaseIndex;
int TapIndex;
s16 *CoeffValueTapBase;
u32 CoeffValue;
/* Assert bad arguments and conditions */
Xil_AssertVoid(InstancePtr != NULL);
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
Xil_AssertVoid(CoeffBankPtr != NULL);
Xil_AssertVoid(CoeffBankPtr->SetIndex < InstancePtr->Config.CoeffSetNum);
Xil_AssertVoid(CoeffBankPtr->CoeffValueBuf != NULL);
Xil_AssertVoid(CoeffBankPtr->PhaseNum > 0);
Xil_AssertVoid(CoeffBankPtr->PhaseNum <=
InstancePtr->Config.MaxPhaseNum);
Xil_AssertVoid(CoeffBankPtr->TapNum > 0);
Xil_AssertVoid(CoeffBankPtr->TapNum <= XSCL_MAX_TAP_NUM);
/* Start the coefficient bank loading by writing the bank index first
*/
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_COEFFSETADDR,
CoeffBankPtr->SetIndex & XSCL_COEFFSETADDR_ADDR_MASK);
/* Now load the valid values */
CoeffValueTapBase = CoeffBankPtr->CoeffValueBuf;
for (PhaseIndex = 0;
PhaseIndex < CoeffBankPtr->PhaseNum; PhaseIndex++) {
for (TapIndex = 0; TapIndex < CoeffBankPtr->TapNum;) {
CoeffValue = ((u32)CoeffValueTapBase[TapIndex++]) &
0xFFFF;
if (TapIndex < CoeffBankPtr->TapNum) {
CoeffValue |=
(((u32)CoeffValueTapBase[TapIndex++]) &
0xFFFF) << 16;
}
XScaler_WriteReg((InstancePtr)->Config.BaseAddress,
XSCL_COEFFVALUE, CoeffValue);
}
CoeffValueTapBase += CoeffBankPtr->TapNum;
}
/*
* Load padding if the real phase number is less than the maximum phase
* number
*/
for (PhaseIndex = CoeffBankPtr->PhaseNum;
PhaseIndex < InstancePtr->Config.MaxPhaseNum; PhaseIndex++) {
for (TapIndex = 0; TapIndex < (CoeffBankPtr->TapNum + 1) / 2;
TapIndex++) {
XScaler_WriteReg((InstancePtr)->Config.BaseAddress,
XSCL_COEFFVALUE, 0);
}
}
return;
}
/*****************************************************************************/
/**
*
* This function chooses the active vertical and horizontal coefficient sets to
* be used by a Scaler device.
*
* Each coefficient set contains 4 banks: Horizontal Luma, Horizontal Chroma,
* Vertical Luma and Vertical Chroma. The horizontal part is independent from
* the vertical part and the Scaler device supports using the horizontal part
* of one coefficient set w/ the vertical part of a different coefficient set.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on
*
* @param VertSetIndex indicates the index of the coefficient set in which
* the vertical part will be used by the Scaler device. Valid value
* is from 0 to (the number of the coefficient sets implemented by the
* Scaler device - 1)
*
* @param HoriSetIndex indicates the index of the coefficient set in which
* the horizontal part will be used by the Scaler device. Valid value
* is from 0 to (the number of the coefficient sets implemented by the
* Scaler device - 1)
*
* @return None.
*
* @note None.
*
******************************************************************************/
void XScaler_SetActiveCoeffSet(XScaler *InstancePtr,
u8 VertSetIndex,
u8 HoriSetIndex)
{
volatile u32 RegValue;
/* Assert bad arguments and conditions */
Xil_AssertVoid(InstancePtr != NULL);
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
Xil_AssertVoid(VertSetIndex < InstancePtr->Config.CoeffSetNum);
Xil_AssertVoid(HoriSetIndex < InstancePtr->Config.CoeffSetNum);
RegValue = ((u32)HoriSetIndex) & XSCL_COEFFSETS_HORI_MASK;
RegValue |= (((u32)VertSetIndex) << XSCL_COEFFSETS_VERT_SHIFT) &
XSCL_COEFFSETS_VERT_MASK;
XScaler_WriteReg((InstancePtr)->Config.BaseAddress,
XSCL_COEFFSETS, RegValue);
return;
}
/*****************************************************************************/
/**
*
* This function fetches the indexes of active vertical and horizontal
* coefficient sets being used by a Scaler device.
*
* Each coefficient set contains 4 banks: Horizontal Luma, Horizontal Chroma,
* Vertical Luma and Vertical Chroma. The horizontal part is independent from
* the vertical part and the Scaler device supports using the horizontal part
* of one coefficient set w/ the vertical part of a different coefficient set.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @param VertSetIndexPtr points to the index of the active coefficient set
* in which the vertical part is being used by the Scaler device
* after this function returns.
*
* @param HoriSetIndexPtr points to the index of the active coefficient set
* in which the horizontal part is being used by the Scaler device
* after this function returns.
*
* @return None.
*
* @note None.
*
******************************************************************************/
void XScaler_GetActiveCoeffSet(XScaler *InstancePtr,
u8 *VertSetIndexPtr,
u8 *HoriSetIndexPtr)
{
u32 RegValue;
/* Assert bad arguments and conditions */
Xil_AssertVoid(InstancePtr != NULL);
Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
Xil_AssertVoid(VertSetIndexPtr != NULL);
Xil_AssertVoid(HoriSetIndexPtr != NULL);
RegValue = XScaler_ReadReg((InstancePtr)->Config.BaseAddress,
XSCL_COEFFSETS);
*VertSetIndexPtr = (u8)
((RegValue & XSCL_COEFFSETS_VERT_MASK) >>
XSCL_COEFFSETS_VERT_SHIFT);
*HoriSetIndexPtr = (u8)(RegValue & XSCL_COEFFSETS_HORI_MASK);
return;
}
/*****************************************************************************/
/**
* This function calculates the index of the coefficient Bin to use based on
* the input and output video size (Width or Height)
*
* @param InSize indicates the size (width or height) of the input video.
* @param OutSize indicates the size (width or height) of the output video.
* @return The index of the coefficient Bin.
*
*****************************************************************************/
static u32 XScaler_CoeffBinOffset(u32 InSize, u32 OutSize)
{
u32 CoeffBinIndex;
/* Validate the input parameters */
Xil_AssertNonvoid(InSize > 0);
Xil_AssertNonvoid(OutSize > 0);
if (OutSize > InSize)
CoeffBinIndex = 0;
else
CoeffBinIndex =1 + (OutSize * 16 / InSize);
return CoeffBinIndex;
}
/*****************************************************************************/
/**
*
* This function returns the version of a Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be
* worked on.
* @param Major points to an unsigned 16-bit variable that will be assigned
* with the major version number after this function returns. Value
* range is from 0x0 to 0xF.
* @param Minor points to an unsigned 16-bit variable that will be assigned
* with the minor version number after this function returns. Value
* range is from 0x00 to 0xFF.
* @param Revision points to an unsigned 16-bit variable that will be assigned
* with the revision version number after this function returns. Value
* range is from 0xA to 0xF.
* @return None.
* @note Example: Device version should read v2.01.c if major version number
* is 0x2, minor version number is 0x1, and revision version number is
* 0xC.
*
******************************************************************************/
//void XScaler_GetVersion(XScaler *InstancePtr, u16 *Major, u16 *Minor,
// u16 *Revision)
//{
// u32 Version;
//
// /* Verify arguments */
// Xil_AssertVoid(InstancePtr != NULL);
// Xil_AssertVoid(Major != NULL);
// Xil_AssertVoid(Minor != NULL);
// Xil_AssertVoid(Revision != NULL);
//
// /* Read device version */
// Version = XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_VER);
//
// /* Parse the version and pass the info to the caller via output
// * parameters
// */
// *Major = (u16)
// ((Version & XSCL_VER_MAJOR_MASK) >> XSCL_VER_MAJOR_SHIFT);
//
// *Minor = (u16)
// ((Version & XSCL_VER_MINOR_MASK) >> XSCL_VER_MINOR_SHIFT);
//
// *Revision = (u16)
// ((Version & XSCL_VER_REV_MASK) >> XSCL_VER_REV_SHIFT);
//
// return;
//}
/*****************************************************************************/
/*
* This routine is a stub for the frame done interrupt callback. The stub is
* here in case the upper layer forgot to set the callback. On initialization,
* the frame done interrupt callback is set to this stub. It is considered an
* error for this function to be invoked.
*
*****************************************************************************/
static void StubCallBack(void *CallBackRef, u32 EventMask)
{
Xil_AssertVoidAlways();
}

View file

@ -0,0 +1,743 @@
/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/
/**
*
* @file xscaler.h
*
* This is the main header file of the Xilinx MVI Video Scaler device driver.
* The Scaler device converts a specified rectangular area of an input digital
* video image from one original sampling grid to a desired target sampling
* grid.
*
* Video Scaler Device v3.00a features are as follows:
*
* - Target Clock Frequencies:
* - S3ADSP(-4), S6(-2) Families: 150MHz
* - V5(-1), V6(-1) Families: 225MHz
* - 8, 10 or 12-bit video data supported
* - YC (4:2:2), YC (4:2:0), RGB (4:4:4) chroma formats supported
* - 1080P/60 supported for 4:2:2 and 4:4:4 (RGB formats (not 4:2:0)
* - Serial or parallel options (single or multiple filter engines) available to
* suit high or low bandwidth requirements
* - Supports spatial resolutions up to 4096x4096
* - 2-12 taps per dimension
* - Up to 16 user-loadable sets of 16-bit coefficients
* - Up to 64 phases per coefficient set
* - 16-bit intermediate bitwidth
* - Programmable (dynamic) scaling factor in both H and V dimensions
* - Max 12x resolution change either up or down ~V allows for conversion
* between QCIF and 1080p
* - 24-bit input fixed point scaling factors: 4 bits integer, 20-bit
* fraction
* - Independent H and V scaling factors
* - Optional coefficient sharing between Y and C filter operations (where
* appropriate)
* - Optional coefficient sharing between H and V filter operations (where
* appropriate)
* - Programmable (dynamic) start phase (independent H, V start-phase values),
* range -0.99 to +0.99
* - Programmable (dynamic) subject area size
* - Programmable (dynamic) target area size
* - Coefficient set selectable during operation (eg on V-sync)
* - Coefficient range -2.0 to +1.99
* - 3 Control interface options
* - pCore, with drivers
* - General Purpose Processor GPP
* - Constant
* - Coefficient preload (via .coe file) functionality for all above modes.
* - Full EDK GUI for scaler customization under XPS
* - 2 Video interface options
* - Live video source
* - Memory source
* - Interrupts
*
*
* For a full description of Scaler features, please see the hardware spec.
*
* An example is shipped with the driver to demonstrate how to use the APIs
* this driver provides to access and control the Video Scaler device.
*
*
* <b>Limitation</b>
*
* - Function XScaler_CalcCoeffs() only calculates coefficient values if this
* driver is *NOT* used on Linux platform. In Linux case, the math library is
* not available in the kernel and this function only clears the coefficient
* buffer passed in.
*
* <pre>
* MODIFICATION HISTORY:
*
* Ver Who Date Changes
* ----- ---- -------- -------------------------------------------------------
* 1.00a xd 05/14/09 First release
* 2.00a xd 12/14/09 Updated doxygen document tags
* 3.00a xd 07/29/10 Added device version & sharable coefficient bank support
* 6.0 adk 19/12/13 Updated as per the New Tcl API's
* </pre>
*
******************************************************************************/
#ifndef XSCALER_H /* prevent circular inclusions */
#define XSCALER_H /* by using protection macros */
#ifdef __cplusplus
extern "C" {
#endif
/***************************** Include Files *********************************/
#include "stdio.h"
#include "math.h"
#include "stdlib.h"
#include "xscaler_hw.h"
#include "xil_types.h"
#include "xstatus.h"
/************************** Constant Definitions *****************************/
/** @name Interrupt Types for setting up Callbacks
* @{
*/
#define XSCL_HANDLER_EVENT 1 /**< Normal Event Interrupt Type */
#define XSCL_HANDLER_ERROR 2 /**< Error Interrupt Type */
/*@}*/
/** @name Minimum and Maximum Tap Numbers
* @{
*/
#define XSCL_MIN_TAP_NUM 2 /**< Minimum Tap Number */
#define XSCL_MAX_TAP_NUM 12 /**< Maximum Tap Number */
/*@}*/
/** @name Minimum and Maximum Phase Numbers
* @{
*/
#define XSCL_MIN_PHASE_NUM 2 /**< Minimum Phase Number */
#define XSCL_MAX_PHASE_NUM 64 /**< Maximum Phase Number */
/*@}*/
/** @name Coefficient Precision
* @{
*/
#define XSCL_COEFF_PRECISION 16 /**< Coefficient Precision */
/*@}*/
/** @name Maximum Coefficient Set Number
* @{
*/
#define XSCL_MAX_COEFF_SET_NUM 16 /**< Maximum Coefficient Set Number */
/*@}*/
/** @name The number of coefficient Bins
* @{
*/
#define XSCL_NUM_COEF_BINS 19 /**< The number of coefficient Bins */
/*@}*/
/** @name The size of a coefficient Bin in 16-bit integers.
* @{
*/
#define XSCL_COEF_BIN_SIZE XScaler_CoefTapOffset(XSCL_MAX_TAP_NUM + 1)
/*@}*/
/** @name Shrink factor constants
* @{
*/
#define XSCL_SHRINK_FACTOR 0x100000 /**< For calculating HSF/VSF values */
/*@}*/
/**************************** Type Definitions *******************************/
/**
* This typedef contains configuration information for a Scaler device.
* Each Scaler device should have a configuration structure associated
*/
typedef struct {
u16 DeviceId; /**< DeviceId is the unique ID of the device */
u32 BaseAddress; /**< BaseAddress is the physical base address of the
* device's registers */
u16 VertTapNum; /**< The number of Vertical Taps */
u16 HoriTapNum; /**< The number of Horizontal Taps */
u16 MaxPhaseNum; /**< The maximum number of Phases */
u8 CoeffSetNum; /**< The number of coefficient sets implemented */
u8 ChromaFormat; /**< Chroma Format */
u8 SeparateYcCoef; /**< Separate Chroma/Luma Coefficient banks */
u8 SeparateHvCoef; /**< Separate Horizontal/Vertical Coefficient
banks. Common only possible if num_h_taps =
num_v_taps */
} XScaler_Config;
/**
* Callback type for interrupts
*
* @param CallBackRef is a callback reference passed in by the upper layer
* when setting the callback functions, and passed back to the
* upper layer when the callback is invoked.
* @param EventMask indicates which events are happening. They could be
* either normal events or errors. The value is created by "OR'ing"
* XSCL_IXR_* constants defined in xscaler_hw.h
*/
typedef void (*XScaler_CallBack) (void *CallBackRef, u32 EventMask);
/**
* The XScaler driver instance data. An instance must be allocated for each
* Scaler device in use.
*/
typedef struct {
XScaler_Config Config; /**< Hardware configuration */
u32 IsReady; /**< Device and the driver instance are
initialized */
XScaler_CallBack EventCallBack; /**< Call back for Normal Event
interrupt */
void *EventRef; /**< To be passed to the Normal Event
interrupt callback */
XScaler_CallBack ErrorCallBack; /**< Call back for Error interrupt */
void *ErrorRef; /**< To be passed to the Error
interrupt callback */
} XScaler;
/**
* The XScalerAperture data structure for Aperture and scale factor control.
* The scale factor values are calculated using the field in this structure
*/
typedef struct {
u32 InFirstLine; /**< The first line index in the input video */
u32 InLastLine; /**< The last line index in the input video */
u32 InFirstPixel; /**< The first pixel index in the input video*/
u32 InLastPixel; /**< The last pixel index in the input video */
u32 OutVertSize; /**< Vertical size of the output video */
u32 OutHoriSize; /**< Horizontal size of the output video */
u32 SrcVertSize; /**< Vertical size of the source video */
u32 SrcHoriSize; /**< Horizontal size of the source video */
} XScalerAperture;
/**
* The XScalerCoeffBank data structure for loading a Bank in a Coefficient Set,
* which contains 4 banks.
*/
typedef struct {
u16 SetIndex; /**< Coefficient Set Index (0 based). */
s16 *CoeffValueBuf; /**< Pointer to a coefficient value data buffer
*/
u16 PhaseNum; /**< The number of the phases associated w/
* the bank */
u16 TapNum; /**< The number of the Tap associated w/ the
* bank */
} XScalerCoeffBank;
/**
* The XScalerStartFraction data structure for Luma and Chroma Start Fraction
* setting
*/
typedef struct {
s32 LumaLeftHori; /**< Horizontal accumulator at rectangle left edge
for Luma */
s32 LumaTopVert; /**< Vertical accumulator at rectangle top edge for
Luma */
s32 ChromaLeftHori;/**< Horizontal accumulator at rectangle left edge
for Chroma */
s32 ChromaTopVert; /**< Vertical accumulator at rectangle top edge for
Chroma */
} XScalerStartFraction;
/***************** Macros (Inline Functions) Definitions *********************/
/** @name Macros for operating a Scaler device
* @{
*/
/*****************************************************************************/
/**
*
* This macro enables a Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @return None.
*
* @note
* C-style signature:
* void XScaler_Enable(XScaler *InstancePtr);
*
******************************************************************************/
#define XScaler_Enable(InstancePtr) \
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_CTL, \
XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_CTL) \
| XSCL_CTL_ENABLE)
/*****************************************************************************/
/**
*
* This macro disables a Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @return None.
*
* @note
* C-style signature:
* void XScaler_Disable(XScaler *InstancePtr);
*
******************************************************************************/
#define XScaler_Disable(InstancePtr) \
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_CTL, \
XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_CTL) \
& (~XSCL_CTL_ENABLE))
/*****************************************************************************/
/**
*
* This macro checks if a Scaler device is enabled.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @return TRUE if the Scaler device is enabled; FALSE otherwise.
*
* @note
* C-style signature:
* boolean XScaler_IsEnabled(XScaler *InstancePtr);
*
******************************************************************************/
#define XScaler_IsEnabled(InstancePtr) \
((XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_CTL) & \
XSCL_CTL_ENABLE) ? TRUE : FALSE)
/*****************************************************************************/
/**
*
* This macro checks if a Scaler operation is finished
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @return TRUE if the Scaler operation is finished; FALSE otherwise.
*
* @note
* C-style signature:
* boolean XScaler_CheckDone(XScaler *InstancePtr);
*
******************************************************************************/
#define XScaler_CheckDone(InstancePtr) \
((XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_STSDONE) & \
XSCL_STSDONE_DONE) ? TRUE : FALSE)
/*****************************************************************************/
/**
*
* This macro tells a Scaler device to pick up the register value changes made
* so far.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @return None.
*
* @note
* C-style signature:
* void XScaler_EnableRegUpdate(XScaler *InstancePtr);
*
******************************************************************************/
#define XScaler_EnableRegUpdate(InstancePtr) \
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_CTL, \
XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_CTL) \
| XSCL_CTL_REGUPDATE)
/*****************************************************************************/
/**
*
* This macro tells a Scaler device not to pick up the register value changes
* until XScaler_EnableRegUpdate() is invoked again. This is very useful when
* multiple registers need to be updated. All register updates could be made
* with no tight time constraints with the help of this macro.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @return None.
*
* @note
* C-style signature:
* void XScaler_DisableRegUpdate(XScaler *InstancePtr);
*
******************************************************************************/
#define XScaler_DisableRegUpdate(InstancePtr) \
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_CTL, \
XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_CTL) \
& ~XSCL_CTL_REGUPDATE)
/*****************************************************************************/
/**
*
* This macro checks if a Scaler device is ready to accept the coefficients
* the software is going to load.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @return TRUE if the Scaler device is ready for the coefficient load; FALSE
otherwise
*
* @note
* C-style signature:
* boolean XScaler_CoeffLoadReady(XScaler *InstancePtr);
*
******************************************************************************/
#define XScaler_CoeffLoadReady(InstancePtr) \
((XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_STS) & \
XSCL_STS_COEF_W_RDY_MASK) ? TRUE : FALSE)
/*****************************************************************************/
/**
*
* This macro checks the error status of a Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @return The error type, if any. Use XSCL_STSERR_* defined in xscaler_hw.h
* to interpret the value.
*
* @note
* C-style signature:
* u32 XScaler_GetError(XScaler *InstancePtr);
*
******************************************************************************/
#define XScaler_GetError(InstancePtr) \
XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_STSERR)
/*****************************************************************************/
/**
*
* This macro resets a Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @return None.
*
* @note
* C-style signature:
* void XScaler_Reset(XScaler *InstancePtr);
*
******************************************************************************/
#define XScaler_Reset(InstancePtr) \
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_CTL, \
XSCL_RESET_RESET_MASK)
/*****************************************************************************/
/**
*
* This macro checks if the reset on a Scaler device is done.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @return TRUE if the reset is done; FALSE otherwise.
*
* @note
* C-style signature:
* boolean XScaler_IsResetDone(XScaler *InstancePtr);
*
******************************************************************************/
#define XScaler_IsResetDone(InstancePtr) \
((XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_RESET) & \
XSCL_RESET_RESET_MASK) ? FALSE : TRUE)
/*****************************************************************************/
/**
* This macro calculates the N-th Triangular number: 1 + 2 + ... + N
*
* @param N indicates the positive integer number to calculate the N-th
* Triangular number.
* @return The N-th triangular number.
*
* @note
* C-style signature:
* u32 XScaler_TriangularNumber(u32 N);
*
*****************************************************************************/
#define XScaler_TriangularNumber(N) ((N) * ((N) + 1) / 2)
/*****************************************************************************/
/**
* This macro calculates the offset of a coefficient Tap from the beginning of
* a coefficient Bin.
*
* @param Tap indicates the index of the coefficient tap in the coefficient
* Bin
* @return The offset of the coefficient TAP from the beginning of a
* coefficient Bin
* @note
* C-style signature:
* u32 XScaler_CoefTapOffset(u32 Tap);
*
*****************************************************************************/
#define XScaler_CoefTapOffset(Tap) \
((XScaler_TriangularNumber((Tap) - 1) - 1) * \
(XScaler_TriangularNumber(16) - 1 + 32 + 64))
/*****************************************************************************/
/**
* This macro calculates the offset of the first coefficient Phase from the
* beginning of a coefficient Tap given the currently used Phase and Tap
* numbers for scaling operation.
*
* @param Tap indicates the number of Taps used for the scaling operation
* @param Phase indicates the number of Phases used for the scaling operation
* @return The offset of the first coefficient Phase from the beginning of a
* coefficient Tap.
* @note
* C-style signature:
* u32 XScaler_CoefPhaseOffset(u32 Tap, u32 Phase);
*
*****************************************************************************/
#define XScaler_CoefPhaseOffset(Tap, Phase) \
(((Phase) < 32) ? \
(Tap) * (XScaler_TriangularNumber((Phase) - 1) - 1) : \
((Phase) == 32) ? \
(Tap) * (XScaler_TriangularNumber(16) - 1) : \
(Tap) * (XScaler_TriangularNumber(16) - 1 + 32))
/*****************************************************************************/
/**
*
* This macro enables the global interrupt on a Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @return None.
*
* @note
* C-style signature:
* void XScaler_IntrEnableGlobal(XScaler *InstancePtr);
*
******************************************************************************/
//#define XScaler_IntrEnableGlobal(InstancePtr) \
// XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_GIER, \
// XSCL_GIER_GIE_MASK)
/*****************************************************************************/
/**
*
* This macro disables the global interrupt on a Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @return None.
*
* @note
* C-style signature:
* void XScaler_IntrDisableGlobal(XScaler *InstancePtr);
*
******************************************************************************/
//#define XScaler_IntrDisableGlobal(InstancePtr) \
// XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_GIER, 0)
/*****************************************************************************/
/**
*
* This macro enables the given individual interrupt(s) on a Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @param IntrType is the type of the interrupts to enable. Use OR'ing of
* XSCL_IXR_* constants defined in xscaler_hw.h to create this parameter
* value.
*
* @return None
*
* @note
*
* The existing enabled interrupt(s) will remain enabled.
*
* C-style signature:
* void XScaler_IntrEnable(XScaler *InstancePtr, u32 IntrType);
*
******************************************************************************/
//#define XScaler_IntrEnable(InstancePtr, IntrType) \
// XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_IER, \
// ((IntrType) & XSCL_IXR_ALLINTR_MASK) | \
// XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_IER))
/*****************************************************************************/
/**
*
* This macro disables the given individual interrupt(s) on a Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @param IntrType is the type of the interrupts to disable. Use OR'ing of
* XSCL_IXR_* constants defined in xscaler_hw.h to create this parameter
* value.
*
* @return None
*
* @note
*
* Any other interrupt not covered by parameter IntrType, if enabled before
* this macro is called, will remain enabled.
*
* C-style signature:
* void XScaler_IntrDisable(XScaler *InstancePtr, u32 IntrType);
*
******************************************************************************/
//#define XScaler_IntrDisable(InstancePtr, IntrType) \
// XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_IER, \
// (~(IntrType)) & XSCL_IXR_ALLINTR_MASK & \
// XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_IER))
/*****************************************************************************/
/**
*
* This macro returns the pending interrupts of a Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @return The pending interrupts of the Scaler. Use XSCL_IXR_* constants
* defined in xscaler_hw.h to interpret this value.
*
* @note
*
* C-style signature:
* u32 XScaler_IntrGetPending(XScaler *InstancePtr)
*
******************************************************************************/
//#define XScaler_IntrGetPending(InstancePtr) \
// (XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_IER) & \
// XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_ISR) & \
// XSCL_IXR_ALLINTR_MASK)
/*****************************************************************************/
/**
*
* This macro clears/acknowledges pending interrupts of a Scaler device.
*
* @param InstancePtr is a pointer to the Scaler device instance to be worked
* on.
*
* @param IntrType is the pending interrupts to clear/acknowledge. Use OR'ing
* of XSCL_IXR_* constants defined in xscaler_hw.h to create this
* parameter value.
*
* @return None
*
* @note
*
* C-style signature:
* void XScaler_IntrClear(XScaler *InstancePtr, u32 IntrType)
*
******************************************************************************/
//#define XScaler_IntrClear(InstancePtr, IntrType) \
// XScaler_WriteReg((InstancePtr)->Config.BaseAddress, XSCL_ISR, \
// (IntrType) & XSCL_IXR_ALLINTR_MASK & \
// XScaler_ReadReg((InstancePtr)->Config.BaseAddress, XSCL_ISR))
/*@}*/
/************************** Function Prototypes ******************************/
/*
* Initialization and control functions in xscaler.c
*/
/* Initialization */
int XScaler_CfgInitialize(XScaler *InstancePtr, XScaler_Config *CfgPtr,
u32 EffectiveAddr);
/* Aperture & Scale */
int XScaler_SetAperture(XScaler *InstancePtr, XScalerAperture *AperturePtr);
void XScaler_GetAperture(XScaler *InstancePtr, XScalerAperture *AperturePtr);
/* Phase */
void XScaler_SetPhaseNum(XScaler *InstancePtr, u16 VertPhaseNum,
u16 HoriPhaseNum);
void XScaler_GetPhaseNum(XScaler *InstancePtr, u16 *VertPhaseNumPtr,
u16 *HoriPhaseNumPtr);
/* Start Fractional value setting */
void XScaler_SetStartFraction(XScaler *InstancePtr,
XScalerStartFraction *StartFractionPtr);
void XScaler_GetStartFraction(XScaler *InstancePtr,
XScalerStartFraction *StartFractionPtr);
/* Coefficient functions */
s16 *XScaler_CoefValueLookup(u32 InSize, u32 OutSize, u32 Tap, u32 Phase);
void XScaler_LoadCoeffBank(XScaler *InstancePtr,
XScalerCoeffBank *CoeffBankPtr);
void XScaler_SetActiveCoeffSet(XScaler *InstancePtr,
u8 VertSetIndex,
u8 HoriSetIndex);
void XScaler_GetActiveCoeffSet(XScaler *InstancePtr,
u8 *VertSetIndexPtr,
u8 *HoriSetIndexPtr);
void XScaler_GetCoeffBankSharingInfo(XScaler *InstancePtr,
u8 *ChromaFormat,
u8 *ChromaLumaShareCoeff,
u8 *HoriVertShareCoeff);
/* Version functions */
//void XScaler_GetVersion(XScaler *InstancePtr, u16 *Major, u16 *Minor,
// u16 *Revision);
/*
* Initialization functions in xscaler_sinit.c
*/
XScaler_Config *XScaler_LookupConfig(u16 DeviceId);
/*
* Interrupt related functions in xscaler_intr.c
*/
void XScaler_IntrHandler(void *InstancePtr);
int XScaler_SetCallBack(XScaler *InstancePtr, u32 IntrType,
void *CallBackFunc, void *CallBackRef);
#ifdef __cplusplus
}
#endif
#endif /* end of protection macro */

View file

@ -0,0 +1,181 @@
/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/
/**
*
* @file xscaler_coefs.c
*
* This file contains Lanczos coefficient generation for use in the Xilinx Video Scaler.
*
*
*
* <pre>
* MODIFICATION HISTORY:
*
* Ver Who Date Changes
* ----- ---- -------- -------------------------------------------------------
* 1.00a xd 06/15/09 First release. Coefficients are auto-generated in
* Matlab using
* /Video_Scaler/reference_model/src/CreateCoefficients.m
* 2.00a xd 12/14/09 Updated doxygen document tags
* 5.00a mpv 12/13/13 Updated to dynamic coeff generation to reduce driver size
* </pre>
*
******************************************************************************/
#include "xscaler.h"
/************************** Constant Definitions *****************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************* Data Structure Definitions ************************/
/**
* XScaler_CoefficientsBinScalingFactors contains scaling factors calculated
* using (Output_Size * 10000 / Input_Size). This table could help find
* the index of coefficient Bin given an input size and a output size.
*/
u16 XScaler_CoefficientBinScalingFactors[XSCL_NUM_COEF_BINS] = {
20000,
625,
1250,
1875,
2500,
3125,
3750,
4375,
5000,
5625,
6250,
6875,
7500,
8125,
8750,
9375,
10000,
10000,
6666
};
/**
* XScaler_GenCoefTable generates a table that contains the coefficient values
* for scaling operations
* @param Tap is the number of taps configured
* @param Phase is the number of phase configured
* the Scaler device.
* @return XScaler_coef_table
*
************ new coef generation************
*/
#define PI 3.14159265358979
typedef unsigned short uint16;
struct coefs_struct{
short int** coefficients;
}SingleFrameCoefs;
/*memory allocation*/
int XScaler_AllocCoefsBuff(struct coefs_struct* coefs, int max_taps, int max_phases)
{
int phase, tap;
if ((coefs->coefficients = (short int **) ((uint16**)calloc(max_phases, sizeof(uint16*)))) == 0) return(1);
for (phase = 0; phase <max_phases; phase++) {
if ((coefs->coefficients[phase] = (short int *) ((uint16*)calloc(max_taps, sizeof(uint16)))) == 0) return(1);
}
return(0);
}
/**
* Sine generation
* This Sine generation algorithm implements Taylor series decomposition of the
* Sine function according to http://en.wikipedia.org/wiki/Taylor_series#Approximation_and_convergence
*/
float XScaler_Sine(float x)
{
int n, fac=1;
float px, taylor=0;
float rng = ((x-PI)/PI);
x = x - rng*PI;
px = x;
for (n=0;n<6;n++)
{
taylor += (px / fac);
px *= -(x*x);
fac *= (2*n+2)*(2*n+3);
}
return taylor;
}
/*coef generation*/
float XScaler_Lanczos(float x, int a)
{
return((x<-a) ? 0 : ((x>a) ? 0 : ((x==0) ? 1.0 : ( a*XScaler_Sine(PI*x)*XScaler_Sine(PI*x/a)/(PI*PI*x*x)))));
}
/**
* This coefficient generation algorithm implements the Lanczos coefficients: http://en.wikipedia.org/wiki/Lanczos_resampling
* For a particular scaling ratio, the coefficients can be pre-canned to memory
*/
void XScaler_GetLanczosCoeffs(float p, short int icoeffs[], int NCOEFF)
{
float s=0;
float coeff[64];
int i;
for (i=0; i<NCOEFF; i++) s+=(coeff[i] = XScaler_Lanczos( i-(NCOEFF>>1)+p, (NCOEFF>>1))); /* To implement convolution using the 2D FIR kernel, coefficient order is reversed*/
for (i=0; i<NCOEFF; i++) icoeffs[i]=(int) (0.5+coeff[i]*16384/s); /* Normalize coefficients, so sum()=1 for all phases.*/
}
s16 *XScaler_GenCoefTable(u32 Tap, u32 Phase)
{
int phase, i , j;
short int *current_phase_ptr;
double dy;
XScaler_AllocCoefsBuff(&SingleFrameCoefs, Tap, Phase);
s16* XScaler_coef_table;
XScaler_coef_table = calloc(Tap*Phase, sizeof(uint16));
for (i=0; i<Phase; i++) {
dy=((double) i)/Phase;
current_phase_ptr = SingleFrameCoefs.coefficients[i];
XScaler_GetLanczosCoeffs(dy,current_phase_ptr, Tap);
for (j=0; j<Tap; j++){
XScaler_coef_table[((i*Tap) + j)] = SingleFrameCoefs.coefficients[i][j];
}
}
return (XScaler_coef_table);
}

View file

@ -0,0 +1,72 @@
/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/
/**
*
* @file xscaler_g.c
*
* This file contains a template for configuration table of Xilinx MVI Video
* Scaler devices.
*
* <pre>
* MODIFICATION HISTORY:
*
* Ver Who Date Changes
* ----- ---- -------- -------------------------------------------------------
* 1.00a xd 05/14/09 First release
* 2.00a xd 12/14/09 Updated doxygen document tags
* </pre>
*
******************************************************************************/
/***************************** Include Files *********************************/
#include "xparameters.h"
#include "xscaler.h"
/**
* The configuration table for Scaler devices
*/
XScaler_Config XScaler_ConfigTable[] = {
{
XPAR_SCALER_0_DEVICE_ID,
XPAR_SCALER_0_BASEADDR,
XPAR_SCALER_0_VERT_TAP_NUM,
XPAR_SCALER_0_HORI_TAP_NUM,
XPAR_SCALER_0_MAX_PHASE_NUM,
XPAR_SCALER_0_MAX_COEF_SETS,
XPAR_SCALER_0_CHROMA_FORMAT,
XPAR_SCALER_0_SEPARATE_YC_COEFS,
XPAR_SCALER_0_SEPARATE_HV_COEFS
}
};

View file

@ -0,0 +1,380 @@
/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/
/**
*
* @file xscaler_hw.h
*
* This header file contains identifiers and register-level driver functions (or
* macros) that can be used to access the Xilinx MVI Video Scaler device.
*
* For more information about the operation of this device, see the hardware
* specification and documentation in the higher level driver xscaler.h source
* code file.
*
* <pre>
* MODIFICATION HISTORY:
*
* Ver Who Date Changes
* ----- ---- -------- -------------------------------------------------------
* 1.00a xd 05/14/09 First release
* 2.00a xd 12/14/09 Updated doxygen document tags
* 4.03a mpv 05/28/13 Updated the Driver input, output and aperture size mask
* </pre>
*
******************************************************************************/
#ifndef XSCALER_HW_H /* prevent circular inclusions */
#define XSCALER_HW_H /* by using protection macros */
#ifdef __cplusplus
extern "C" {
#endif
/***************************** Include Files *********************************/
#include "xil_io.h"
/************************** Constant Definitions *****************************/
/** @name Device Register Offsets
* @{
*/
#define XSCL_CTL 0x000 /**< Control */
#define XSCL_STATUS 0x004 /**< Status */
#define XSCL_ERROR 0x008 /**< Error status */
#define IRQ_ENABLE 0x00C /**< For detecting operation status */
#define XSCL_VER 0x010 /**< Version Register */
#define XSCL_HSF 0x100 /**< Horizontal Shrink Factor */
#define XSCL_VSF 0x104 /**< Vertical Shrink Factor */
#define XSCL_SRCSIZE 0x108 /**< Source-video resolution */
#define XSCL_APTHORI 0x10C /**< First and last subject pixels in input line */
#define XSCL_APTVERT 0x110 /**< First and last subject lines in input image */
#define XSCL_OUTSIZE 0x114 /**< Output image size:width and height */
#define XSCL_NUMPHASE 0x118 /**< The numbers of phases in current filter */
#define XSCL_COEFFSETS 0x11C /**< Active horizontal and vertical coefficient sets to use */
#define XSCL_FRCTLUMALEFT 0x120 /**< Fractional value used to initialize horizontal accumulator
at rectangle left edge for luma */
#define XSCL_FRCTCHROMALEFT 0x124 /**< Fractional value used to initialize horizontal accumulator
at rectangle left edge for chroma */
#define XSCL_FRCTLUMATOP 0x128 /**< Fractional value used to initialize horizontal accumulator
at rectangle top edge for luma */
#define XSCL_FRCTCHROMATOP 0x12C /**< Fractional value used to initialize horizontal accumulator
at rectangle top edge for chroma */
#define XSCL_COEFFSETADDR 0x130 /**< Address of Coefficient set to write */
#define XSCL_COEFFVALUE 0x134 /**< Coefficient values to write */
#define XSCL_COEFF_SET_BANK 0x138 /**< Coefficient set/bank read address */
#define XSCL_COEFF_MEM 0x13C /**< Coefficient mem read address */
/*@}*/
/** @name Control Register bit definition
* @{
*/
#define XSCL_CTL_REGUPDATE 0x00000002 /**< Register Update Enable for
register HSF thru
FRCTCHROMATOP */
#define XSCL_CTL_ENABLE 0x00000001 /**< Enable the scaler on the next
video frame */
/*@}*/
/** @name Status Register bit definition
* @{
*/
#define XSCL_STS_COEF_W_RDY_MASK 0x00000001 /**< If 1, Coefficient values can
be written into the core */
/*@}*/
/** @name Error Status Register bit definition (to be defined)
* @{
*/
#define XSCL_STSERR_CODE3_MASK 0xFF000000 /**< code 3 */
#define XSCL_STSERR_CODE2_MASK 0x00FF0000 /**< code 2 */
#define XSCL_STSERR_CODE1_MASK 0x0000FF00 /**< code 1 */
#define XSCL_STSERR_CODE0_MASK 0x000000FF /**< code 0 */
/*@}*/
/** @name Done Status Register bit definition
* @{
*/
#define XSCL_STSDONE_DONE 0x00000001 /**< indicator of end of scaler
operation */
/*@}*/
/** @name Horizontal Shrink Factor Register bit definition
* @{
*/
#define XSCL_HSF_INT_MASK 0x00F00000 /**< Horizontal Shrink Factor
integer */
#define XSCL_HSF_FRAC_MASK 0x000FFFFF /**< Horizontal Shrink Factor
fractional */
/*@}*/
/** @name Vertical Shrink Factor Register bit definition
* @{
*/
#define XSCL_VSF_INT_MASK 0x00F00000 /**< Vertical Shrink Factor integer
*/
#define XSCL_VSF_FRAC_MASK 0x000FFFFF /**< Vertical Shrink Factor
fractional */
/*@}*/
/** @name Aperture Horizontal Register bit definition
* @{
*/
#define XSCL_APTHORI_LASTPXL_MASK 0x1FFF0000 /**< Location of last pixel
in line */
#define XSCL_APTHORI_LASTPXL_SHIFT 16 /**< Shift for location of
last pixel */
#define XSCL_APTHORI_FIRSTPXL_MASK 0x00001FFF /**< Location of first pixel
in line */
/*@}*/
/** @name Aperture Vertical Register bit definition
* @{
*/
#define XSCL_APTVERT_LASTLINE_MASK 0x1FFF0000 /**< Location of last line
in active video */
#define XSCL_APTVERT_LASTLINE_SHIFT 16 /**< Shift for location of
last line */
#define XSCL_APTVERT_FIRSTLINE_MASK 0x00001FFF /**< Location of first line
in active video */
/*@}*/
/** @name Output Size Register bit definition
* @{
*/
#define XSCL_OUTSIZE_NUMLINE_MASK 0x1FFF0000 /**< The number of lines in
output rectangle */
#define XSCL_OUTSIZE_NUMLINE_SHIFT 16 /**< Shift for the number of
lines */
#define XSCL_OUTSIZE_NUMPXL_MASK 0x00001FFF /**< The number of pixels in
output rectangle */
/*@}*/
/** @name Source Size Register bit definition
* @{
*/
#define XSCL_SRCSIZE_NUMLINE_MASK 0x1FFF0000 /**< The number of lines in
source image */
#define XSCL_SRCSIZE_NUMLINE_SHIFT 16 /**< Shift for the number of
lines */
#define XSCL_SRCSIZE_NUMPXL_MASK 0x00001FFF /**< The number of pixels in
source image */
/*@}*/
/** @name Number of Phases Register bit definition
* @{
*/
#define XSCL_NUMPHASE_VERT_MASK 0x00007F00 /**< The number of vertical
phases */
#define XSCL_NUMPHASE_VERT_SHIFT 8 /**< Shift for the number of
vertical phases */
#define XSCL_NUMPHASE_HORI_MASK 0x0000007F /**< The number of
horizontal phases */
/*@}*/
/** @name Active Coefficient Set Register bit definition
* @{
*/
#define XSCL_COEFFSETS_VERT_MASK 0x000000F0 /**< Active vertical
coefficient set */
#define XSCL_COEFFSETS_VERT_SHIFT 4 /**< Active vertical
coefficient set
shift */
#define XSCL_COEFFSETS_HORI_MASK 0x0000000F /**< Active horizontal
coefficient set */
/*@}*/
/** @name Luma left edge horizontal accumulator fractional value register
* @{
*/
#define XSCL_FRCTLUMALEFT_VALUE_MASK 0x001FFFFF /**< Fractional value to
initialize horizontal
accumulator for luma */
/*@}*/
/** @name Chroma left edge horizontal accumulator fractional value register
* @{
*/
#define XSCL_FRCTCHROMALEFT_VALUE_MASK 0x001FFFFF /**< Fractional value to
initialize horizontal
accumulator for
chroma */
/*@}*/
/** @name Luma top edge vertical accumulator fractional value register
* @{
*/
#define XSCL_FRCTLUMATOP_VALUE_MASK 0x001FFFFF /**< Fractional value to
initialize vertical
accumulator for luma */
/*@}*/
/** @name Chroma top edge vertical accumulator fractional value register
* @{
*/
#define XSCL_FRCTCHROMATOP_VALUE_MASK 0x001FFFFF /**< Fractional value to
initialize vertical
accumulator for
chroma */
/*@}*/
/** @name Coefficient band address register bit definition
* @{
*/
#define XSCL_COEFFSETADDR_ADDR_MASK 0x0000000F /**< Address of the
Coefficient bank to
write next */
/*@}*/
/** @name Coefficient Value Register bit definition
* @{
*/
#define XSCL_COEFFVALUE_NPLUS1_MASK 0xFFFF0000 /**< Second value in the
pair */
#define XSCL_COEFFVALUE_N_MASK 0x0000FFFF /**< First value in the
pair */
/*@}*/
/** @name Reset Register bit definition
* @{
*/
#define XSCL_RESET_RESET_MASK 0x80000000 /**< Software reset bit */
/*@}*/
/** @name Global Interrupt Enable Register bit definition
* @{
*/
#define XSCL_GIER_GIE_MASK 0x80000000 /**< Global interrupt
enable */
/*@}*/
/** @name Interrupt Status/Enable Register bit definition
* @{
*/
#define XSCL_IXR_REG_UPDATE_DONE_MASK 0x00000020 /**< Shadow Register
Update Interrupt */
#define XSCL_IXR_COEF_WR_ERROR_MASK 0x00000010 /**< Coefficient FIFO
Write Error
Interrupt */
#define XSCL_IXR_OUTPUT_ERROR_MASK 0x00000008 /**< Output Error
Interrupt */
#define XSCL_IXR_INPUT_ERROR_MASK 0x00000004 /**< Input Error
Interrupt */
#define XSCL_IXR_COEF_FIFO_READY_MASK 0x00000002 /**< Coefficient FIFO
Ready Interrupt */
#define XSCL_IXR_OUTPUT_FRAME_DONE_MASK 0x00000001 /**< Video Frame Done
Interrupt */
#define XSCL_IXR_EVENT_MASK (XSCL_IXR_OUTPUT_FRAME_DONE_MASK | \
XSCL_IXR_COEF_FIFO_READY_MASK | \
XSCL_IXR_REG_UPDATE_DONE_MASK)
/**< Mask for all
normal event
interrupts */
#define XSCL_IXR_ERROR_MASK (XSCL_IXR_INPUT_ERROR_MASK | \
XSCL_IXR_OUTPUT_ERROR_MASK | \
XSCL_IXR_COEF_WR_ERROR_MASK)
/**< Mask for all
error interrupts */
#define XSCL_IXR_ALLINTR_MASK (XSCL_IXR_EVENT_MASK | \
XSCL_IXR_ERROR_MASK) /**< Mask for all
interrupts */
/*@}*/
/** @name Chroma Format Type Definition
* @{
*/
#define XSCL_CHROMA_FORMAT_420 1 /**< YUV4:2:0 */
#define XSCL_CHROMA_FORMAT_422 2 /**< YUV4:2:2 */
#define XSCL_CHROMA_FORMAT_444 3 /**< YUV4:4:4 */
/*@}*/
/**************************** Type Definitions *******************************/
/***************** Macros (Inline Functions) Definitions *********************/
/** @name Scaler Register Access Macro Definition
* @{
*/
#define XScaler_In32 Xil_In32
#define XScaler_Out32 Xil_Out32
/*****************************************************************************/
/**
*
* Read the given register.
*
* @param BaseAddress is the base address of the device
* @param RegOffset is the register offset to be read
*
* @return The 32-bit value of the register
*
* @note
* C-style signature:
* u32 XScaler_ReadReg(u32 BaseAddress, u32 RegOffset)
*
******************************************************************************/
#define XScaler_ReadReg(BaseAddress, RegOffset) \
XScaler_In32((BaseAddress) + (RegOffset))
/*****************************************************************************/
/**
*
* Write the given register.
*
* @param BaseAddress is the base address of the device
* @param RegOffset is the register offset to be written
* @param Data is the 32-bit value to write to the register
*
* @return None.
*
* @note
* C-style signature:
* void XScaler_WriteReg(u32 BaseAddress, u32 RegOffset, u32 Data)
*
******************************************************************************/
#define XScaler_WriteReg(BaseAddress, RegOffset, Data) \
XScaler_Out32((BaseAddress) + (RegOffset), (Data))
/*@}*/
/************************** Function Prototypes ******************************/
#ifdef __cplusplus
}
#endif
#endif /* end of protection macro */

View file

@ -0,0 +1,176 @@
/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/
/**
*
* @file xscaler_intr.c
*
* This code contains interrupt related functions of Xilinx MVI Video Scaler
* device driver. The Scaler device converts a specified rectangular area of an
* input digital video image from one original sampling grid to a desired target
* sampling grid. Please see xscaler.h for more details of the driver.
*
* <pre>
* MODIFICATION HISTORY:
*
* Ver Who Date Changes
* ----- ---- -------- -------------------------------------------------------
* 1.00a xd 02/10/09 First release
* 2.00a xd 12/14/09 Updated doxygen document tags
* </pre>
*
******************************************************************************/
#include "xscaler.h"
/*****************************************************************************/
/**
*
* This function is the interrupt handler for the Scaler driver.
*
* This handler reads the pending interrupt from the IER/ISR, determines the
* source of the interrupts, calls according callbacks, and finally clears the
* interrupts.
*
* The application is responsible for connecting this function to the interrupt
* system. Application beyond this driver is also responsible for providing
* callbacks to handle interrupts and installing the callbacks using
* XScaler_SetCallBack() during initialization phase. An example delivered with
* this driver demonstrates how this could be done.
*
* @param InstancePtr is a pointer to the XScaler instance that just
* interrupted.
* @return None.
* @note None.
*
******************************************************************************/
void XScaler_IntrHandler(void *InstancePtr)
{
XScaler *XScalerPtr;
u32 PendingIntr;
u32 ErrorMask;
u32 EventMask;
XScalerPtr = (XScaler *)InstancePtr;
/* Validate parameters */
Xil_AssertVoid(XScalerPtr != NULL);
Xil_AssertVoid(XScalerPtr->IsReady == XIL_COMPONENT_IS_READY);
/* Get pending interrupts */
PendingIntr = XScaler_IntrGetPending(XScalerPtr);
/* Clear pending interrupt(s) */
XScaler_IntrClear(XScalerPtr, PendingIntr);
/* Error interrupt is occurring or spurious interrupt */
if ((0 == (PendingIntr & XSCL_IXR_ALLINTR_MASK)) ||
(PendingIntr & XSCL_IXR_ERROR_MASK)) {
ErrorMask = PendingIntr & XSCL_IXR_ERROR_MASK;
XScalerPtr->ErrorCallBack(XScalerPtr->ErrorRef, ErrorMask);
/* The Error Interrupt Callback should reset the Scaler device
* and so there is no need to handle other pending interrupts
*/
return;
}
/* A normal event just happened */
if ((PendingIntr & XSCL_IXR_EVENT_MASK)) {
EventMask = PendingIntr & XSCL_IXR_EVENT_MASK;
XScalerPtr->EventCallBack(XScalerPtr->EventRef, EventMask);
}
return;
}
/*****************************************************************************/
/**
*
* This routine installs an asynchronous callback function for the given
* HandlerType:
*
* <pre>
* HandlerType Callback Function Type
* ----------------------- ---------------------------
* XSCL_HANDLER_EVENT XScaler_CallBack
* XSCL_HANDLER_ERROR XScaler_CallBack
*
* HandlerType Invoked by this driver when:
* ----------------------- --------------------------------------------------
* XSCL_HANDLER_EVENT A normal event just happened. Normal events include
* frame done, Coefficient FIFO Ready and Shadow
* Register updated.
*
* XSCL_HANDLER_ERROR An error just happened.
*
* </pre>
*
* @param InstancePtr is a pointer to the XScaler instance to be worked
* on.
* @param HandlerType specifies which callback is to be attached.
* @param CallBackFunc is the address of the callback function.
* @param CallBackRef is a user data item that will be passed to the
* callback function when it is invoked.
*
* @return
* - XST_SUCCESS when handler is installed.
* - XST_INVALID_PARAM when HandlerType is invalid.
*
* @note
* Invoking this function for a handler that already has been installed replaces
* it with the new handler.
*
******************************************************************************/
int XScaler_SetCallBack(XScaler *InstancePtr, u32 HandlerType,
void *CallBackFunc, void *CallBackRef)
{
Xil_AssertNonvoid(InstancePtr != NULL);
Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
Xil_AssertNonvoid(CallBackFunc != NULL);
Xil_AssertNonvoid(CallBackRef != NULL);
switch (HandlerType) {
case XSCL_HANDLER_EVENT:
InstancePtr->EventCallBack = (XScaler_CallBack)CallBackFunc;
InstancePtr->EventRef = CallBackRef;
break;
case XSCL_HANDLER_ERROR:
InstancePtr->ErrorCallBack = (XScaler_CallBack)CallBackFunc;
InstancePtr->ErrorRef = CallBackRef;
break;
default:
return XST_INVALID_PARAM;
}
return XST_SUCCESS;
}

View file

@ -0,0 +1,95 @@
/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/
/**
*
* @file xscaler_sinit.c
*
* This file contains static initialization methods for Xilinx MVI Video Scaler
* device driver.
*
* <pre>
* MODIFICATION HISTORY:
*
* Ver Who Date Changes
* ----- ---- -------- -------------------------------------------------------
* 1.00a xd 05/14/09 First release
* 2.00a xd 12/14/09 Updated doxygen document tags
* </pre>
*
*****************************************************************************/
/***************************** Include Files *********************************/
#include "xscaler.h"
#include "xparameters.h"
/************************** Constant Definitions *****************************/
/**************************** Type Definitions *******************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
/*****************************************************************************/
/**
* XScaler_LookupConfig returns a reference to an XScaler_Config structure
* based on the unique device id, <i>DeviceId</i>. The return value will refer
* to an entry in the device configuration table defined in the xscaler_g.c
* file.
*
* @param DeviceId is the unique device ID of the device for the lookup
* operation.
*
* @return XScaler_LookupConfig returns a reference to a config record in
* the configuration table (in xscaler_g.c) corresponding to
* <i>DeviceId</i>, or NULL if no match is found.
*
*****************************************************************************/
XScaler_Config *XScaler_LookupConfig(u16 DeviceId)
{
extern XScaler_Config XScaler_ConfigTable[];
XScaler_Config *CfgPtr = NULL;
int i;
for (i = 0; i < XPAR_XSCALER_NUM_INSTANCES; i++) {
if (XScaler_ConfigTable[i].DeviceId == DeviceId) {
CfgPtr = &XScaler_ConfigTable[i];
break;
}
}
return (CfgPtr);
}