📄 cx24108_tuner.c
字号:
{
VCASLOPE VCASlope;
VCAOFFSET VCAOffset;
VGA1VALS VGA1Offset;
VGA2VALS VGA2Offset;
ULONG ulRegVal;
int idx;
/* get tuner's VCA and VGA settings from NIM for the given symbol rate */
#ifdef CAMARIC_FEATURES
if (symbolrateksps < 5000UL)
{
idx = CX24108_MSPS_1_TO_5;
}
else
#endif /* #ifdef CAMARIC_FEATURES */
if (symbolrateksps < 15000UL)
{
idx = CX24108_MSPS_5_TO_15;
}
else
{
idx = 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 = VCASlope | (VCAOffset << 9);
if (_TUNER_CX24108_io(nim,CX24108_VCA_PROG,ulRegVal) == False)
{
return (False);
}
/* program tuner's VGA settings */
ulRegVal = VGA1Offset | (VGA2Offset << 9);
if (_TUNER_CX24108_io(nim,CX24108_VGA_PROG,ulRegVal) == False)
{
return (False);
}
return (True);
} /* _TUNER_CX24108_SetGainSettings() */
/*******************************************************************************************************/
/* _TUNER_CX24108_calc_Fpll() */
/*******************************************************************************************************/
ULONG _TUNER_CX24108_calc_Fpll( /* function to calculate the tuner pll freq using N,A reg settings */
NIM *nim, /* pointer to nim */
int na) /* N,A register (9MSB=N, 5LSB=a register) */
{
ULONG ulTemp;
RDIVVAL r = nim->tuner.cx24108.R;
if (r != RDIV_10 && r != RDIV_20 && r != RDIV_40) r = RDIV_10;
if (DRIVER_div_zero(nim,na) == False) return(False);
ulTemp = (nim->crystal_freq / (ULONG)r) * ((ULONG)na);
if (nim->tuner.cx24108.vcodiv != VCODIV2)
{
ulTemp++;
ulTemp /= 2UL;
}
return(ulTemp);
} /* _TUNER_CX24108_calc_Fpll() */
/*******************************************************************************************************/
/* __TUNER_CX24108_freq_manual() */
/*******************************************************************************************************/
BOOL _TUNER_CX24108_freq_manual( /* set tuner to a desired frequency */
NIM *nim, /* pointer to nim */
ULONG freq) /* frequency in khz to set tuner to */
{
DWORD n;
ULONG ulRegVal;
ULONG nar_str; /* string of bits to be written to tuner */
/* default: set the frequency, rdiv, vcodiv */
nim->frequency = freq;
if (_TUNER_CX24108_set_refdivider(nim,nim->tuner.cx24108.R) == False) return(False);
nar_str = _TUNER_CX24108_calc_pll(nim);
nim->tuner_nar = nar_str;
/* see if PLL can be loaded with a "better" value giving better performance */
ulRegVal = (nar_str&0x3fffUL)>>5UL;
n = (DWORD)ulRegVal;
/* write the pll setting to the tuner */
ulRegVal = nar_str;
ulRegVal |= ((ULONG)nim->tuner.cx24108.RefDivider<<17UL); /* ref divider programming bits */
ulRegVal |= ((ULONG)nim->tuner.cx24108.CPCPolarity<<16UL); /* charge pump polarity */
ulRegVal |= (((ULONG)nim->tuner.cx24108.CPCCurrent&0x03UL)<<CX24108_CPC_START);
if (_TUNER_CX24108_io(nim,CX24108_PLL_PROG,ulRegVal) == False) return(False);
return(True);
} /* __TUNER_CX24108_freq_manual() */
/*******************************************************************************************************/
/* _TUNER_CX24108_GetType() */
/*******************************************************************************************************/
BOOL _TUNER_CX24108_GetType( /* retrieve s tuner-type (enum TUNER) associated to nim */
NIM *nim, /* pointer to NIM struct */
TUNER *tunertype) /* contains returned tuner-type (enum TUNER) on function exit */
{
if (_TUNER_CX24108_validate(nim) == False) return(False);
*tunertype = nim->tuner_type;
return(True);
} /* _TUNER_CX24108_GetType() */
/*******************************************************************************************************/
/* _TUNER_CX24108_SetType() */
/*******************************************************************************************************/
BOOL _TUNER_CX24108_SetType( /* Sets the tuner-type (enum TUNER) associated to nim */
NIM *nim) /* pointer to NIM struct */
{
nim->tuner_type = CX24108;
return(True);
} /* _TUNER_CX24108_SetType() */
/*******************************************************************************************************/
/* _TUNER_CX24108_getvco() */
/*******************************************************************************************************/
BOOL _TUNER_CX24108_getvco( /* Funct to retrieve the last vco number used to tuning operation */
NIM *nim, /* pointer to nim */
UCHAR *vcono) /* vco number */
{
if (_TUNER_CX24108_validate(nim) == False) return(False);
*vcono = nim->tuner.cx24108.vcono;
return(True);
}/* _TUNER_CX24108_getvco() */
/*******************************************************************************************************/
/* _TUNER_CX_24108_SetReferenceDivider() */
/*******************************************************************************************************/
BOOL _TUNER_CX24108_SetReferenceDivider( /* sets the current reference divider value */
NIM *nim, /* pointer to nim */
RDIVVAL rvalue) /* reference divider value */
{
DWORD N;
DWORD A;
if (_TUNER_CX24108_validate(nim) == False) return(False);
switch(rvalue)
{
case RDIV_10:
case RDIV_20:
case RDIV_40:
{
/* re-calculate where N,A should be set, if the R value changed */
if (_TUNER_CX24108_CalculateNAR(nim,nim->frequency,rvalue,&N,&A) == False) return(False);
/* save last n,a,r settings */
nim->tuner.cx24108.N = N;
nim->tuner.cx24108.A = A;
nim->tuner.cx24108.R = rvalue;
/* set the ref divider bit mask that is sent to the tuner */
if (_TUNER_CX24108_set_refdivider(nim,rvalue) == True) break;
}
default:
{
DRIVER_SetError(nim,API_TUNERREF);
return(False);
break;
}
} /* switch(... */
return(True);
} /* TUNER_CX24108_SetReferenceDivider() */
/*******************************************************************************************************/
/* _TUNER_CX24108_GetVcoDivider() */
/*******************************************************************************************************/
BOOL _TUNER_CX24108_GetVcoDivider( /* gets the current vco divider, returns value to caller */
NIM *nim, /* pointer to nim */
VCODIV *vcodiv) /* vco divider value */
{
if (_TUNER_CX24108_validate(nim) == False) return(False);
*vcodiv = nim->tuner.cx24108.vcodiv;
return(True);
} /* _TUNER_CX24108_GetVcoDivider() */
/*******************************************************************************************************/
/* _TUNER_CX24108_GetReferenceDivider() */
/*******************************************************************************************************/
BOOL _TUNER_CX24108_GetReferenceDivider( /* retrieve s current reference divider value */
NIM *nim, /* pointer to nim */
RDIVVAL *rvalue) /* pointer to RDIVVAL where value is returned to caller */
{
if (_TUNER_CX24108_validate(nim) == False) return(False);
*rvalue = nim->tuner.cx24108.R;
return(True);
} /* _TUNER_CX24108_GetReferenceDivider() */
/*******************************************************************************************************/
/* _TUNER_CX24108_GetPLLFrequency() */
/*******************************************************************************************************/
BOOL _TUNER_CX24108_GetPLLFrequency( /* returns current freq. programmed into the tuner pll register */
NIM *nim, /* pointer to nim */
ULONG *pllfreq) /* pointer to unsigned long where pll freq. in Hz. will be returned */
{
int NA; /* value programmed to the tuner -- do not use to determine pll freq */
int na; /* computed value BEFORE adjustment to accomodate Rosie tuner */
if (_TUNER_CX24108_validate(nim) == False) return(False);
*pllfreq = 0UL;
NA = (int)_TUNER_CX24108_calc_pll(nim);
na = (int)((((ULONG)nim->tuner.cx24108.N&0x1ffUL)<<5)|((ULONG)nim->tuner.cx24108.A&0x1fUL));
*pllfreq = _TUNER_CX24108_calc_Fpll(nim,na);
return(True);
} /* _TUNER_CX24108_GetPLLFrequency() */
/*******************************************************************************************************/
/* TUNER_CX24108_GetRegisters() */
/*******************************************************************************************************/
BOOL _TUNER_CX24108_GetRegisters( /* function to retrieve N, A, R values last sent to the tuner */
NIM *nim, /* nim pointer */
int *nvalue, /* pointer to int, where n value will be returned to caller */
int *avalue, /* pointer to int, where a ... */
RDIVVAL *rvalue) /* pointer to RDIVVAL, where r value will be returned */
{
if (_TUNER_CX24108_validate(nim) == False) return(False);
*nvalue = nim->tuner.cx24108.N;
*avalue = nim->tuner.cx24108.A;
*rvalue = nim->tuner.cx24108.R;
/* r must be valid, if not, force to default value */
if (*rvalue != RDIV_10 && *rvalue != RDIV_20 && *rvalue != RDIV_40) *rvalue = RDIV_10;
return(True);
} /* _TUNER_CX24108_GetRegisters() */
/*******************************************************************************************************/
/* TUNER_CX24108_GetParameters() */
/*******************************************************************************************************/
BOOL _TUNER_CX24108_GetParameters( /* returns current tuner parameter settings to the caller */
NIM *nim, /* pointer to nim */
TUNERPARMS *tunerparms) /* pointer to TUNERPARMS, where copy will be written */
{
if (_TUNER_CX24108_validate(nim) == False) return(False);
if (tunerparms == NULL) return(False);
/* copy tunerparms to caller storage */
memcpy(tunerparms,&nim->tuner.cx24108.tunerparms,sizeof(TUNERPARMS));
return(True);
} /* TUNER_GetParameters() */
/*******************************************************************************************************/
/* _TUNER_CX24108_SetParameters() */
/*******************************************************************************************************/
BOOL _TUNER_CX24108_SetParameters( /* sets current TUNERPARMS struct in nim to that passed by caller */
NIM *nim, /* pointer to nim */
TUNERPARMS *tunerparms) /* copy of TUNERPARMS to use as default */
{
if (_TUNER_CX24108_validate(nim) == False) return(False);
if (tunerparms == NULL) return(False);
/* copy from user-buffer to tuner buffer */
memcpy(&nim->tuner.cx24108.tunerparms,tunerparms,sizeof(TUNERPARMS));
return(True);
} /* _TUNER_CX24108_SetParameters() */
/*******************************************************************************************************/
/* _TUNER_CX24108_GetFrequency() */
/*******************************************************************************************************/
BOOL _TUNER_CX24108_GetFrequency( /* returns last frequency set via SetFrequency() to caller */
NIM *nim, /* pointer to nim */
ULONG
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -