#include "stdio.h"
#include "math.h"
#include "stdlib.h"
#include "xil_assert.h"
#include "xscaler_hw.h"
#include "xil_types.h"
#include "xstatus.h"
Classes | |
struct | XScaler_Config |
struct | XScaler |
struct | XScalerAperture |
struct | XScalerCoeffBank |
struct | XScalerStartFraction |
Minimum and Maximum Tap Numbers | |
#define | XSCL_MIN_TAP_NUM 2 |
#define | XSCL_MAX_TAP_NUM 12 |
Minimum and Maximum Phase Numbers | |
#define | XSCL_MIN_PHASE_NUM 2 |
#define | XSCL_MAX_PHASE_NUM 64 |
Coefficient Precision | |
#define | XSCL_COEFF_PRECISION 16 |
Maximum Coefficient Set Number | |
#define | XSCL_MAX_COEFF_SET_NUM 16 |
The number of coefficient Bins | |
#define | XSCL_NUM_COEF_BINS 19 |
The size of a coefficient Bin in 16-bit integers. | |
#define | XSCL_COEF_BIN_SIZE XScaler_CoefTapOffset(XSCL_MAX_TAP_NUM + 1) |
Shrink factor constants | |
#define | XSCL_SHRINK_FACTOR 0x100000 |
Macros for operating a Scaler device | |
#define | XScaler_Enable(InstancePtr) |
#define | XScaler_Disable(InstancePtr) |
#define | XScaler_IsEnabled(InstancePtr) |
#define | XScaler_CheckDone(InstancePtr) |
#define | XScaler_EnableRegUpdate(InstancePtr) |
#define | XScaler_DisableRegUpdate(InstancePtr) |
#define | XScaler_CoeffLoadReady(InstancePtr) |
#define | XScaler_GetError(InstancePtr) XScaler_ReadReg((InstancePtr)->Config.BaseAddress, (XSCL_ERROR_OFFSET)) |
#define | XScaler_Reset(InstancePtr) |
#define | XScaler_IsResetDone(InstancePtr) |
#define | XScaler_TriangularNumber(N) ((N) * ((N) + 1) / 2) |
#define | XScaler_CoefTapOffset(Tap) |
#define | XScaler_CoefPhaseOffset(Tap, Phase) |
#define | XScaler_IntrEnable(InstancePtr) |
#define | XScaler_IntrDisable(InstancePtr) |
#define | XScaler_IntrClear(InstancePtr) |
Defines | |
#define | XSCALER_H |
Typedefs | |
typedef void(*) | XScaler_CallBack (void *CallBackRef) |
Functions | |
int | XScaler_CfgInitialize (XScaler *InstancePtr, XScaler_Config *CfgPtr, u32 EffectiveAddr) |
int | XScaler_SetAperture (XScaler *InstancePtr, XScalerAperture *AperturePtr) |
void | XScaler_GetAperture (XScaler *InstancePtr, XScalerAperture *AperturePtr) |
void | XScaler_SetPhaseNum (XScaler *InstancePtr, u16 VertPhaseNum, u16 HoriPhaseNum) |
void | XScaler_GetPhaseNum (XScaler *InstancePtr, u16 *VertPhaseNumPtr, u16 *HoriPhaseNumPtr) |
void | XScaler_SetStartFraction (XScaler *InstancePtr, XScalerStartFraction *StartFractionPtr) |
void | XScaler_GetStartFraction (XScaler *InstancePtr, XScalerStartFraction *StartFractionPtr) |
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) |
u32 | XScaler_GetVersion (XScaler *InstancePtr) |
XScaler_Config * | XScaler_LookupConfig (u16 DeviceId) |
void | XScaler_IntrHandler (void *InstancePtr) |
void | XScaler_SetCallBack (XScaler *InstancePtr, void *CallBackFunc, void *CallBackRef) |
#define XScaler_CheckDone | ( | InstancePtr | ) |
Value:
XScaler_ReadReg((InstancePtr)->Config.BaseAddress, \ (XSCL_STATUS_OFFSET)) & \ (XSCL_STS_COEF_W_RDY_MASK) ? TRUE : FALSE
InstancePtr | is a pointer to the Scaler device instance to be worked on. |
#define XScaler_CoeffLoadReady | ( | InstancePtr | ) |
Value:
XScaler_ReadReg((InstancePtr)->Config.BaseAddress, \ (XSCL_STATUS_OFFSET)) & \ (XSCL_STS_COEF_W_RDY_MASK) ? TRUE : FALSE
InstancePtr | is a pointer to the Scaler device instance to be worked on. |
#define XScaler_CoefPhaseOffset | ( | Tap, | |||
Phase | ) |
Value:
(((Phase) < 32) ? \ (Tap) * (XScaler_TriangularNumber((Phase) - 1) - 1) : \ ((Phase) == 32) ? \ (Tap) * (XScaler_TriangularNumber(16) - 1) : \ (Tap) * (XScaler_TriangularNumber(16) - 1 + 32))
Tap | indicates the number of Taps used for the scaling operation. | |
Phase | indicates the number of Phases used for the scaling operation. |
#define XScaler_CoefTapOffset | ( | Tap | ) |
Value:
((XScaler_TriangularNumber((Tap) - 1) - 1) * \ (XScaler_TriangularNumber(16) - 1 + 32 + 64))
Tap | indicates the index of the coefficient tap in the coefficient Bin. |
#define XScaler_Disable | ( | InstancePtr | ) |
Value:
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, \ (XSCL_CTL_OFFSET), \ ((XScaler_ReadReg((InstancePtr)->Config.BaseAddress, \ (XSCL_CTL_OFFSET)) & (~(XSCL_CTL_SW_EN_MASK)))))
InstancePtr | is a pointer to the Scaler device instance to be worked on. |
#define XScaler_DisableRegUpdate | ( | InstancePtr | ) |
Value:
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, \ (XSCL_CTL_OFFSET), \ ((XScaler_ReadReg((InstancePtr)->Config.BaseAddress, \ (XSCL_CTL_OFFSET))) & (~(XSCL_CTL_RUE_MASK))))
InstancePtr | is a pointer to the Scaler device instance to be worked on. |
#define XScaler_Enable | ( | InstancePtr | ) |
Value:
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, \ (XSCL_CTL_OFFSET), \ ((XScaler_ReadReg((InstancePtr)->Config.BaseAddress, \ (XSCL_CTL_OFFSET))) | (XSCL_CTL_SW_EN_MASK)))
InstancePtr | is a pointer to the Scaler device instance to be worked on. |
#define XScaler_EnableRegUpdate | ( | InstancePtr | ) |
Value:
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, \ (XSCL_CTL_OFFSET), \ ((XScaler_ReadReg((InstancePtr)->Config.BaseAddress, \ (XSCL_CTL_OFFSET))) | (XSCL_CTL_RUE_MASK)))
InstancePtr | is a pointer to the Scaler device instance to be worked on. |
#define XScaler_GetError | ( | InstancePtr | ) | XScaler_ReadReg((InstancePtr)->Config.BaseAddress, (XSCL_ERROR_OFFSET)) |
This macro checks the error status of a Scaler device.
InstancePtr | is a pointer to the Scaler device instance to be worked on. |
#define XSCALER_H |
#define XScaler_IntrClear | ( | InstancePtr | ) |
Value:
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, \ (XSCL_STATUS_OFFSET), (XSCL_IXR_COEF_W_RDY_MASK))
InstancePtr | is a pointer to the Scaler device instance to be worked on. |
#define XScaler_IntrDisable | ( | InstancePtr | ) |
Value:
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, \ (XSCL_IRQ_EN_OFFSET), 0)
InstancePtr | is a pointer to the Scaler device instance to be worked on. |
#define XScaler_IntrEnable | ( | InstancePtr | ) |
Value:
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, \ (XSCL_IRQ_EN_OFFSET),(XSCL_IXR_COEF_W_RDY_MASK)) \
InstancePtr | is a pointer to the Scaler device instance to be worked on. |
#define XScaler_IsEnabled | ( | InstancePtr | ) |
Value:
XScaler_ReadReg((InstancePtr)->Config.BaseAddress, \ (XSCL_CTL_OFFSET)) & (XSCL_CTL_SW_EN_MASK) ? TRUE : FALSE
InstancePtr | is a pointer to the Scaler device instance to be worked on. |
#define XScaler_IsResetDone | ( | InstancePtr | ) |
Value:
XScaler_ReadReg((InstancePtr)->Config.BaseAddress, \ (XSCL_CTL_OFFSET)) & \ (XSCL_CTL_RESET_MASK) ? FALSE : TRUE
InstancePtr | is a pointer to the Scaler device instance to be worked on. |
#define XScaler_Reset | ( | InstancePtr | ) |
Value:
XScaler_WriteReg((InstancePtr)->Config.BaseAddress, \ (XSCL_CTL_OFFSET), (XSCL_CTL_RESET_MASK))
InstancePtr | is a pointer to the Scaler device instance to be worked on. |
#define XScaler_TriangularNumber | ( | N | ) | ((N) * ((N) + 1) / 2) |
This macro calculates the N-th Triangular number: 1 + 2 + ... + N
N | indicates the positive integer number to calculate the N-th Triangular number. |
#define XSCL_COEF_BIN_SIZE XScaler_CoefTapOffset(XSCL_MAX_TAP_NUM + 1) |
#define XSCL_COEFF_PRECISION 16 |
Coefficient Precision
#define XSCL_MAX_COEFF_SET_NUM 16 |
Maximum Coefficient Set Number
#define XSCL_MAX_PHASE_NUM 64 |
Maximum Phase Number
#define XSCL_MAX_TAP_NUM 12 |
Maximum Tap Number
#define XSCL_MIN_PHASE_NUM 2 |
Minimum Phase Number
#define XSCL_MIN_TAP_NUM 2 |
Minimum Tap Number
#define XSCL_NUM_COEF_BINS 19 |
The number of coefficient Bins
#define XSCL_SHRINK_FACTOR 0x100000 |
For calculating HSF/VSF values
typedef void(*) XScaler_CallBack(void *CallBackRef) |
Callback type for interrupts
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. | |
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 |
int XScaler_CfgInitialize | ( | XScaler * | InstancePtr, | |
XScaler_Config * | CfgPtr, | |||
u32 | EffectiveAddr | |||
) |
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.
InstancePtr | is a pointer to the Scaler device instance to be worked on. | |
CfgPtr | points to the configuration structure associated with the Scaler device. | |
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. |
s16* XScaler_CoefValueLookup | ( | u32 | InSize, | |
u32 | OutSize, | |||
u32 | Tap, | |||
u32 | Phase | |||
) |
This function returns the pointer to the coefficients for a scaling operation given input/output sizes and the Tap and Phase numbers.
InSize | indicates the size (width or height) of the input video. | |
OutSize | indicates the size (width or height) of the output video. | |
Tap | indicates the Tap number. | |
Phase | indicates the Phase number. |
void XScaler_GetActiveCoeffSet | ( | XScaler * | InstancePtr, | |
u8 * | VertSetIndexPtr, | |||
u8 * | HoriSetIndexPtr | |||
) |
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.
InstancePtr | is a pointer to the Scaler device instance to be worked on. | |
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. | |
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. |
void XScaler_GetAperture | ( | XScaler * | InstancePtr, | |
XScalerAperture * | AperturePtr | |||
) |
This function gets aperture of a Scaler device. The aperture setting consists of input video aperture and output video size.
InstancePtr | is a pointer to the Scaler device instance to be worked on. | |
AperturePtr | points to the aperture structure to store the current Scaler device setting after this function returns. |
void XScaler_GetCoeffBankSharingInfo | ( | XScaler * | InstancePtr, | |
u8 * | ChromaFormat, | |||
u8 * | ChromaLumaShareCoeff, | |||
u8 * | HoriVertShareCoeff | |||
) |
This function fetches the color space format and coefficient bank sharing decisions made on a Scaler device at build-time.
InstancePtr | is a pointer to the Scaler device instance to be worked on. | |
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. | |
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. | |
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. |
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.
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 ------------ -------------------- ------------------ -------- -------------
void XScaler_GetPhaseNum | ( | XScaler * | InstancePtr, | |
u16 * | VertPhaseNumPtr, | |||
u16 * | HoriPhaseNumPtr | |||
) |
This function gets the numbers of vertical and horizontal phases currently used by a Scaler device.
InstancePtr | is a pointer to the Scaler device instance to be worked on. | |
VertPhaseNumPtr | will point to the number of vertical phases used after this function returns. | |
HoriPhaseNumPtr | will point to the number of horizontal phases used after this function returns. |
void XScaler_GetStartFraction | ( | XScaler * | InstancePtr, | |
XScalerStartFraction * | StartFractionPtr | |||
) |
This function gets Luma and Chroma start fractional values currently used by a Scaler device.
InstancePtr | is a pointer to the Scaler device instance to be worked on. | |
StartFractionPtr | is a pointer to a start fractional value structure to be populated with the fractional values after this function returns. |
u32 XScaler_GetVersion | ( | XScaler * | InstancePtr | ) |
This function returns the contents of version register of the Scaler core.
InstancePtr | is a pointer to the Scaler core instance to be worked on. |
void XScaler_IntrHandler | ( | void * | InstancePtr | ) |
This function is the interrupt handler for the Scaler driver.
This handler calls callback, 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.
InstancePtr | is a pointer to the XScaler instance that just interrupted. |
void XScaler_LoadCoeffBank | ( | XScaler * | InstancePtr, | |
XScalerCoeffBank * | CoeffBankPtr | |||
) |
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:
XScaler_LoadCoeffBank(&Scaler, &HoriLumaCoeffBank); XScaler_LoadCoeffBank(&Scaler, &HoriChromaCoeffBank); XScaler_LoadCoeffBank(&Scaler, &VertLumaCoeffBank); XScaler_LoadCoeffBank(&Scaler, &VertChromaCoeffBank);
InstancePtr | is a pointer to the Scaler device instance to be worked on. | |
CoeffBankPtr | is a pointer to a coefficient bank that is to be loaded. |
XScaler_Config* XScaler_LookupConfig | ( | u16 | DeviceId | ) |
XScaler_LookupConfig returns a reference to an XScaler_Config structure based on the unique device id, DeviceId. The return value will refer to an entry in the device configuration table defined in the xscaler_g.c file.
DeviceId | is the unique device ID of the device for the lookup operation. |
void XScaler_SetActiveCoeffSet | ( | XScaler * | InstancePtr, | |
u8 | VertSetIndex, | |||
u8 | HoriSetIndex | |||
) |
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.
InstancePtr | is a pointer to the Scaler device instance to be worked on. | |
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). | |
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). |
int XScaler_SetAperture | ( | XScaler * | InstancePtr, | |
XScalerAperture * | AperturePtr | |||
) |
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.
InstancePtr | is a pointer to the Scaler device instance to be worked on. | |
AperturePtr | points to the aperture setting structure to set up the Scaler device. |
void XScaler_SetCallBack | ( | XScaler * | InstancePtr, | |
void * | CallBackFunc, | |||
void * | CallBackRef | |||
) |
This routine installs an asynchronous callback function.
InstancePtr | is a pointer to the XScaler instance to be worked on. | |
CallBackFunc | is the address of the callback function. | |
CallBackRef | is a user data item that will be passed to the callback function when it is invoked. |
void XScaler_SetPhaseNum | ( | XScaler * | InstancePtr, | |
u16 | VertPhaseNum, | |||
u16 | HoriPhaseNum | |||
) |
This function sets the numbers of vertical and horizontal phases to be used by a Scaler device.
InstancePtr | is a pointer to the Scaler device instance to be worked on. | |
VertPhaseNum | is the number of vertical phase to set to | |
HoriPhaseNum | is the number of horizontal phase to set to |
void XScaler_SetStartFraction | ( | XScaler * | InstancePtr, | |
XScalerStartFraction * | StartFractionPtr | |||
) |
This function sets up Luma and Chroma start fractional values used by a Scaler device.
InstancePtr | is a pointer to the Scaler device instance to be worked on. | |
StartFractionPtr | is a pointer to a start fractional value set to be used. |
Copyright @ 1995-2014 Xilinx, Inc. All rights reserved.