📄 hamaro_cx24108.c
字号:
} /* __HAMARO_TUNER_CX24108_first_edgeone() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_pll_status( */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_pll_status( /* reads current tuner pll lock status */
HAMARO_NIM *nim, /* nim pointer */
BOOL *locked) /* BOOL pointer, where tuner pll lock status is returned */
{
unsigned long ulRegVal;
/* CR9507, add 1ms delay in order to get the correct lock detector status. */
HAMARO_OS_Wait(nim,HAMARO_TUNER_LDWAIT);
/* read the demod's tuner lock indicator pin */
if (HAMARO_RegisterRead(nim,CX2430X_TUNPLLLOCK,&ulRegVal, HAMARO_DEMOD_I2C_IO) == False) return(False);
if (ulRegVal == 0UL) *locked = False;
else *locked = True;
return(True);
} /* _HAMARO_TUNER_CX24108_pll_status() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_set_refdivider() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_set_refdivider(/* function to set the ref divider value prog'd to the tuner */
HAMARO_NIM *nim, /* pointer to nim (nim->RefDivider is set within nim) */
HAMARO_RDIVVAL rvalue) /* ref divider value (10,20...) */
{
int i;
static unsigned char _rvalue[] = {0x03,0x02, 0x01, 0x00}; /* value programmed to tuner */
static HAMARO_RDIVVAL rvalue_match[] = {HAMARO_RDIV_10,HAMARO_RDIV_20,HAMARO_RDIV_40,HAMARO_RDIV_UNDEF};
/* find the correct rvalue setting for the tuner */
for (i = 0 ; rvalue_match[i] != HAMARO_RDIV_UNDEF ; i++)
{
if (rvalue_match[i] == rvalue)
{
nim->tuner.cx24108.RefDivider = _rvalue[i];
return(True);
}
}
/* unable to equate rvalue to tuner setting */
HAMARO_DRIVER_SET_ERROR(nim,HAMARO_BAD_CXDATA);
return(False);
} /* _HAMARO_TUNER_CX24108_set_refdivider() */
/*******************************************************************************************************/
/* __HAMARO_TUNER_CX24108_set_freq() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_set_freq(/* set tuner to a desired frequency */
HAMARO_NIM *nim, /* pointer to nim */
unsigned long freq) /* frequency in khz to set tuner to */
{
unsigned int bandbin;
unsigned int vcodivbin;
unsigned long ulRegVal;
unsigned long nar_str; /* string of bits to be written to tuner */
unsigned long tunpll;
unsigned char loop;
BOOL rtn1;
BOOL rtn2;
BOOL rtn3;
BOOL lock;
HAMARO_VCOSET vcoset; /* vco number via VCOSET enum: HAMARO_VCO1D2 (aka VCO #1) .. HAMARO_VCO8D4 (aka VCO #11) */
/* default: set the frequency, rdiv, vcodiv */
nim->pll_frequency = freq;
nim->tuner.cx24108.vcodiv = HAMARO_VCODIV2;
/* special op to set freq 1mhz high */
_HAMARO_TUNER_CX24108_io_special(nim);
/* set the tuner band-select bit settings, plus set add'l tuner settings */
rtn1 = _HAMARO_TUNER_CX24108_band_info(nim,nim->pll_frequency,&bandbin,&vcodivbin,&vcoset,
&nim->tuner.cx24108.vcodiv,&nim->tuner.cx24108.vcono,&tunpll);
/* set VCO divider and band-select data */
ulRegVal = vcodivbin;
ulRegVal <<= 9;
ulRegVal |= bandbin;
rtn2 = _HAMARO_TUNER_CX24108_io(nim,HAMARO_CX24108_BAND_PROG,ulRegVal);
/* write the pll setting to the tuner */
nar_str = _HAMARO_TUNER_CX24108_calc_pll(nim);
ulRegVal = nar_str;
ulRegVal |= ((unsigned long)nim->tuner.cx24108.RefDivider<<17); /* ref divider programming bits */
ulRegVal |= ((unsigned long)nim->tuner.cx24108.CPCPolarity<<16); /* charge pump polarity */
ulRegVal |= (((unsigned long)nim->tuner.cx24108.CPCCurrent&0x03UL)<<HAMARO_CX24108_CPC_START);
rtn3 = _HAMARO_TUNER_CX24108_io(nim,HAMARO_CX24108_PLL_PROG,ulRegVal);
if (rtn1 != True || rtn2 != True || rtn3 != True) return(False);
loop = 0;
do
{
if (_HAMARO_TUNER_CX24108_pll_status(nim, &lock) == False)
{
return (False);
}
if (lock == True)
{
break;
}
loop++;
} while (loop < 3);
if (lock == False)
{
return (False);
}
return(True);
} /* __HAMARO_TUNER_CX24108_set_freq() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_calc_pll() */
/*******************************************************************************************************/
unsigned long _HAMARO_TUNER_CX24108_calc_pll(/* function to calc pll settings (n,a) using bcd functions */
HAMARO_NIM *nim) /* nim pointer */
{
unsigned long NA;
NA = _HAMARO_TUNER_CX24108_calc_pllNA(nim);
/* save the last NAR settings */
nim->tuner.cx24108.N = (int)((NA&0x3fffUL)>>5UL);
nim->tuner.cx24108.A = (int)(NA&0x1fUL);
/* this calculated N, A value is what is physically sent to the tuner */
/* the tuner has a feature where when A is zero, it tunes significantly above */
/* the calculated PLL freq. DO NOT USE THIS NA return value to perform calculations */
/* if the a portion of NA is zero, subtract 1 to n portion */
if ((NA&0x1fUL) == 0UL)
{
NA -= 32UL;
}
return(NA);
} /* _HAMARO_TUNER_CX24108_calc_pll() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_calc_pllNA() */
/*******************************************************************************************************/
unsigned long _HAMARO_TUNER_CX24108_calc_pllNA( /* function to calc pll settings (n,a) using bcd functions */
HAMARO_NIM *nim) /* nim pointer */
{
unsigned long NA;
/* set freq to a default setting, if not presently set, test xtal for zero before divide (CR 7452) */
if (nim->pll_frequency == 0UL) nim->pll_frequency = HAMARO_NIM_DEFAULT_FREQ;
if (nim->tuner_crystal_freq == 0UL) nim->tuner_crystal_freq = HAMARO_NIM_DEFAULT_XTAL;
NA = (nim->pll_frequency / 100UL) * ((unsigned long)nim->tuner.cx24108.R * (unsigned long)nim->tuner.cx24108.vcodiv);
NA /= ((nim->tuner_crystal_freq / HAMARO_M) * 2UL);
NA += 5UL;
NA /= 10UL;
return(NA);
} /* _HAMARO_TUNER_CX24108_calc_pllNA() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_calculateNAR() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_CalculateNAR( /* function to calc pll settings (n,a) using bcd functions */
HAMARO_NIM *nim, /* nim pointer */
unsigned long Fdesired, /* desired frequency */
HAMARO_RDIVVAL R, /* proposed reference divider */
unsigned int *N, /* returned N value */
unsigned int *A) /* returned A value */
{
unsigned long NA;
HAMARO_BCDNO bcd;
/* calculate tuner PLL settings: */
HAMARO_BCD_set(&bcd,Fdesired);
HAMARO_BCD_mult(&bcd,((unsigned long)R * (unsigned long)nim->tuner.cx24108.vcodiv * HAMARO_M));
HAMARO_BCD_div(&bcd,(nim->tuner_crystal_freq * 2UL));
NA = HAMARO_BCD_out(&bcd);
NA += 500UL;
NA /= 1000UL;
*N = (int)((NA&0x3fffUL)>>5UL);
*A = (int)(NA&0x1fUL);
return(True);
} /* _HAMARO_TUNER_CX24108_CalculateNAR() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_SetGainSettings() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_SetGainSettings( /* function to set the VCA, VGA settings for CX24108 tuner */
HAMARO_NIM *nim, /* pointer to nim */
unsigned long symbolrateksps) /* symbol rate determines the VCA, VGA settings */
{
HAMARO_VCASLOPE VCASlope;
HAMARO_VCAOFFSET VCAOffset;
HAMARO_VGA1VALS VGA1Offset;
HAMARO_VGA2VALS VGA2Offset;
unsigned long ulRegVal;
int idx;
/* get tuner's VCA and VGA settings from HAMARO_NIM for the given symbol rate */
if (symbolrateksps < 5000UL)
{
idx = HAMARO_CX24108_MSPS_1_TO_5;
}
else if (symbolrateksps < 15000UL)
{
idx = HAMARO_CX24108_MSPS_5_TO_15;
}
else
{
idx = HAMARO_CX24108_MSPS_15_TO_45;
}
VCASlope = nim->tuner.cx24108.tunerparms.SLP[idx].VCASlope;
VCAOffset = nim->tuner.cx24108.tunerparms.SLP[idx].VCAOffset;
VGA1Offset = nim->tuner.cx24108.tunerparms.SLP[idx].VGA1Offset;
VGA2Offset = nim->tuner.cx24108.tunerparms.SLP[idx].VGA2Offset;
/* program tuner's VCA settings */
ulRegVal = (unsigned long)VCASlope | ((unsigned long)VCAOffset << 9);
if (_HAMARO_TUNER_CX24108_io(nim,HAMARO_CX24108_VCA_PROG,ulRegVal) == False)
{
return (False);
}
/* program tuner's VGA settings */
ulRegVal = (unsigned long)VGA1Offset | ((unsigned long)VGA2Offset << 9);
if (_HAMARO_TUNER_CX24108_io(nim,HAMARO_CX24108_VGA_PROG,ulRegVal) == False)
{
return (False);
}
return (True);
} /* _HAMARO_TUNER_CX24108_SetGainSettings() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_calc_Fpll() */
/*******************************************************************************************************/
unsigned long _HAMARO_TUNER_CX24108_calc_Fpll( /* function to calculate the tuner pll freq using N,A reg settings */
HAMARO_NIM *nim, /* pointer to nim */
int na) /* N,A register (9MSB=N, 5LSB=a register) */
{
unsigned long ulTemp;
HAMARO_RDIVVAL r = nim->tuner.cx24108.R;
if (r != HAMARO_RDIV_10 && r != HAMARO_RDIV_20 && r != HAMARO_RDIV_40) r = HAMARO_RDIV_10;
ulTemp = (nim->tuner_crystal_freq / (unsigned long)r) * ((unsigned long)na);
if (nim->tuner.cx24108.vcodiv != HAMARO_VCODIV2)
{
ulTemp++;
ulTemp /= 2UL;
}
return(ulTemp);
} /* _HAMARO_TUNER_CX24108_calc_Fpll() */
/*******************************************************************************************************/
/* __HAMARO_TUNER_CX24108_freq_manual() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_freq_manual( /* set tuner to a desired frequency */
HAMARO_NIM *nim, /* pointer to nim */
unsigned long freq) /* frequency in khz to set tuner to */
{
unsigned int n;
unsigned long ulRegVal;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -