📄 d0370vsb_util.c
字号:
#include "370_VSB_map.h"
#ifdef HOST_PC
#include "gen_macros.h"
#endif
#define MAX_MEAN 512
static int RegExtClk;
/** solution to div() function*/
typedef struct div_s
{
int quot;
int rem;
}div_t;
/*****************************************************
**FUNCTION :: MaxBuffer
**ACTION :: Compute 2^n (where n is an integer)
**PARAMS IN :: number -> n
**PARAMS OUT:: NONE
**RETURN :: 2^n
*****************************************************/
void InsertNewValue(int size,double Buffer[],double value,int *Position)
{
int i;
if ((*Position)<=MAX_MEAN-1)
{
Buffer[(*Position)]=value;
(*Position)++;
}
else
{
for (i=1;i<=MAX_MEAN-1;i++)
Buffer[i-1]=Buffer[i]; /* FAUT revoir*/
Buffer[MAX_MEAN-1]=value;
}
}
/*Assuming DIV Value*/
/*************/
div_t div(int divisor, int divider)
{
div_t ldiv;
ldiv.quot = divisor/divider;
ldiv.rem = divisor%divider;
return ldiv;
}
/***************/
void ResetBuffer(int size,double Buffer[])
{
int i;
for (i=0;i<=size-1;i++)
Buffer[i]=0;
}
/*****************************************************
**FUNCTION :: PowOf2
**ACTION :: Compute 2^n (where n is an integer)
**PARAMS IN :: number -> n
**PARAMS OUT:: NONE
**RETURN :: 2^n
*****************************************************/
unsigned long PowOf2(int number)
{
int i;
unsigned long result=1;
for(i=0;i<number;i++)
result*=2;
return result;
}
/*****************************************************
**FUNCTION :: LongSqrt
**ACTION :: Compute the square root of n (where n is a long integer)
**PARAMS IN :: number -> n
**PARAMS OUT:: NONE
**RETURN :: sqrt(n)
*****************************************************/
long LongSqrt(long Value)
{
/* this routine performs a classical root extraction
** on long integers */
long Factor=1;
long Root=1;
long R;
long Ltmp;
if(Value<=1)
return (Value);
Ltmp=Value;
while (Ltmp>3)
{
Factor<<=2;
Ltmp>>=2;
}
R=Value-Factor; /* Ratio */
Factor>>=2;
while(Factor>0)
{
Root<<=1;
Ltmp=Root<<1;
Ltmp*=Factor;
Ltmp+=Factor;
Factor>>=2;
if(R-Ltmp>=0)
{
R=R-Ltmp;
Root+=1;
}
}
return (Root) ;
}
long BinaryFloatDiv(long n1, long n2, int precision)
{
int i=0;
long result=0;
/* division de N1 par N2 avec N1<N2 */
while(i<=precision) /* n1>0 */
{
if(n1<n2)
{
result*=2;
n1*=2;
}
else
{
result=result*2+1;
n1=(n1-n2)*2;
}
i++;
}
return result;
}
/*****************************************************
**FUNCTION :: RegSetExtClk
**ACTION :: Set the value of the external clock variable
**PARAMS IN :: NONE
**PARAMS OUT:: NONE
**RETURN :: NONE
*****************************************************/
void RegSetExtClk(long _Value)
{
RegExtClk =(int) _Value;
}
/*****************************************************
**FUNCTION :: RegGetExtClk
**ACTION :: Get the external clock value
**PARAMS IN :: NONE
**PARAMS OUT:: NONE
**RETURN :: External clock value
*****************************************************/
long RegGetExtClk(void)
{
return (RegExtClk);
}
unsigned long int GetBERPeriod(STTUNER_IOREG_DeviceMap_t *DeviceMap,IOARCH_Handle_t IOHandle)
{
U32 berperiod;
berperiod=(U32)(STTUNER_IOREG_GetField(DeviceMap, IOHandle,F0370_BER_PERIOD_LLSB)+
(STTUNER_IOREG_GetField(DeviceMap, IOHandle,F0370_BER_PERIOD_LSB)<<8)+
(STTUNER_IOREG_GetField(DeviceMap, IOHandle,F0370_BER_PERIOD_MSB)<<16)+
(STTUNER_IOREG_GetField(DeviceMap, IOHandle,F0370_BER_PERIOD_MMSB)<<24));
return berperiod;
}
long Calc_vcxoOffset(double SymbolRate,int clk)
{
U32 result;
result= (U32)(((SymbolRate*1000000 * PowOf2(31))/clk)+0.5);
return result;
}
long Calc_NCOcnst(double IFfrequency,int clk)
{
U32 result;
result= (U32)(((IFfrequency * PowOf2(23))/clk)+0.5);
return result;
}
void Set_vcxoOffset_Regs(STTUNER_IOREG_DeviceMap_t *DeviceMap,IOARCH_Handle_t IOHandle,int value)
{
div_t divi;
divi=div(value,16777216);
STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0370_VCXOOFFSET4,divi.quot);
divi=div(divi.rem,65536);
STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0370_VCXOOFFSET3,divi.quot);
divi=div(divi.rem,256);
STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0370_VCXOOFFSET2,divi.quot);
STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0370_VCXOOFFSET1,divi.rem);
}
void Set_NCOcnst_Regs(STTUNER_IOREG_DeviceMap_t *DeviceMap,IOARCH_Handle_t IOHandle,int value)
{
div_t divi;
divi=div(value,65536);
STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0370_NCOCNST_MMSB,divi.quot);
divi=div(divi.rem,256);
STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0370_NCOCNST_MSB,divi.quot);
STTUNER_IOREG_SetField(DeviceMap,IOHandle,F0370_NCOCNST_LSB,divi.rem);
}
/* commented, may be used in future*/
/*
int Get_NCOcnst_Value(STCHIP_Handle_t hChip)
{
int result;
result= ChipGetField(hChip,F0370_NCOCNST_LSB)+
(ChipGetField(hChip,F0370_NCOCNST_MSB)<<8)+
(ChipGetField(hChip,F0370_NCOCNST_MMSB)<<16);
return result;
}
*/
int Get_NCOerr_Value(STTUNER_IOREG_DeviceMap_t *DeviceMap,IOARCH_Handle_t IOHandle)
{
int result;
result= STTUNER_IOREG_GetField(DeviceMap, IOHandle,F0370_NCOERR_LSB)+
(STTUNER_IOREG_GetField(DeviceMap, IOHandle,F0370_NCOERR_MSB)<<8)+
(STTUNER_IOREG_GetField(DeviceMap, IOHandle,F0370_NCOERR_MMSB)<<16);
return result;
}
int Get_FrequencyOffset(STTUNER_IOREG_DeviceMap_t *DeviceMap,IOARCH_Handle_t IOHandle,int clk) /* return freq offset in khz */
{
double NCOerr;
double frequencyoffset;
NCOerr= Get_NCOerr_Value(DeviceMap,IOHandle);
if (NCOerr>=65536)
{
NCOerr= 131072-NCOerr;
frequencyoffset=-(NCOerr*clk)/(PowOf2(23));
}
else
{
frequencyoffset=(NCOerr*clk)/(PowOf2(23));
}
return (int)frequencyoffset;
}
/*temporary commented*/
/*int Get_vcxoOffset_Value(STCHIP_Handle_t hChip)
{
int result;
result=ChipGetField(hChip,VCXOOFFSET1)+(ChipGetField(hChip,VCXOOFFSET2)<<8)+
(ChipGetField(hChip,VCXOOFFSET3)<<16)+(ChipGetField(hChip,VCXOOFFSET4)<<24);
return result;
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -