📄 hamaro_cx24108.c
字号:
unsigned long nar_str; /* string of bits to be written to tuner */
/* default: set the frequency, rdiv, vcodiv */
nim->pll_frequency = freq;
if (_HAMARO_TUNER_CX24108_set_refdivider(nim,nim->tuner.cx24108.R) == False) return(False);
nar_str = _HAMARO_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 = (unsigned int)ulRegVal;
/* write the pll setting to the tuner */
ulRegVal = nar_str;
ulRegVal |= ((unsigned long)nim->tuner.cx24108.RefDivider<<17UL); /* ref divider programming bits */
ulRegVal |= ((unsigned long)nim->tuner.cx24108.CPCPolarity<<16UL); /* charge pump polarity */
ulRegVal |= (((unsigned long)nim->tuner.cx24108.CPCCurrent&0x03UL)<<HAMARO_CX24108_CPC_START);
if (_HAMARO_TUNER_CX24108_io(nim,HAMARO_CX24108_PLL_PROG,ulRegVal) == False) return(False);
return(True);
} /* __HAMARO_TUNER_CX24108_freq_manual() */
/*******************************************************************************************************/
/* HAMARO_TUNER_CX_24108_SetReferenceDivider() */
/*******************************************************************************************************/
BOOL HAMARO_TUNER_CX24108_SetReferenceDivider( /* sets the current reference divider value */
HAMARO_NIM *nim, /* pointer to nim */
HAMARO_RDIVVAL rvalue) /* reference divider value */
{
unsigned int N;
unsigned int A;
HAMARO_TUNER_CX24108_VALIDATE(nim);
switch(rvalue)
{
case HAMARO_RDIV_10:
case HAMARO_RDIV_20:
case HAMARO_RDIV_40:
{
/* re-calculate where N,A should be set, if the R value changed */
if (_HAMARO_TUNER_CX24108_CalculateNAR(nim,nim->pll_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 (_HAMARO_TUNER_CX24108_set_refdivider(nim,rvalue) == True) break;
}
default:
{
HAMARO_DRIVER_SET_ERROR(nim,HAMARO_TUNERREF);
return(False);
break;
}
} /* switch(... */
return(True);
} /* HAMARO_TUNER_CX24108_SetReferenceDivider() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_GetPLLFrequency() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_GetPLLFrequency( /* returns current freq. programmed into the tuner pll register */
HAMARO_NIM *nim, /* pointer to nim */
unsigned long *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 */
HAMARO_TUNER_CX24108_VALIDATE(nim);
*pllfreq = 0UL;
NA = (int)_HAMARO_TUNER_CX24108_calc_pll(nim);
na = (int)((((unsigned long)nim->tuner.cx24108.N&0x1ffUL)<<5)|((unsigned long)nim->tuner.cx24108.A&0x1fUL));
if (na == 0)
{
return (False);
}
*pllfreq = _HAMARO_TUNER_CX24108_calc_Fpll(nim,na);
return(True);
} /* _HAMARO_TUNER_CX24108_GetPLLFrequency() */
/*******************************************************************************************************/
/* HAMARO_TUNER_CX24108_GetParameters() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_GetParameters( /* returns current tuner parameter settings to the caller */
HAMARO_NIM *nim, /* pointer to nim */
HAMARO_TUNERPARMS *tunerparms) /* pointer to HAMARO_TUNERPARMS, where copy will be written */
{
HAMARO_TUNER_CX24108_VALIDATE(nim);
if (tunerparms == NULL) return(False);
/* copy tunerparms to caller storage */
memcpy(tunerparms,&nim->tuner.cx24108.tunerparms,sizeof(HAMARO_TUNERPARMS));
return(True);
} /* _HAMARO_TUNER_CX24108_GetParameters() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_SetParameters() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_SetParameters( /* sets current HAMARO_TUNERPARMS struct in nim to that passed by caller */
HAMARO_NIM *nim, /* pointer to nim */
HAMARO_TUNERPARMS *tunerparms) /* copy of HAMARO_TUNERPARMS to use as default */
{
HAMARO_TUNER_CX24108_VALIDATE(nim);
if (tunerparms == NULL) return(False);
/* copy from user-buffer to tuner buffer */
memcpy(&nim->tuner.cx24108.tunerparms,tunerparms,sizeof(HAMARO_TUNERPARMS));
return(True);
} /* _HAMARO_TUNER_CX24108_SetParameters() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_SetFrequency() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_SetFrequency( /* returns last frequency set via SetFrequency() to caller */
HAMARO_NIM *nim, /* pointer to nim */
unsigned long freq) /* pointer to unsigned long */
{
HAMARO_TUNER_CX24108_VALIDATE(nim);
/* note: nim->freq_ideal hold Fi, used to calculate lnboffset */
return(_HAMARO_TUNER_CX24108_set_freq(nim,freq));
} /* _HAMARO_TUNER_CX24108_SetFrequency() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_GetVCOEdges() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_GetVCOEdges( /* retrieve s VCO edge data, returns copy to caller */
HAMARO_NIM *nim, /* nim pointer */
HAMARO_VCO_EDGE *vcoedge) /* HAMARO_VCO_EDGE struct where VCO edge data will be written */
{
HAMARO_TUNER_CX24108_VALIDATE(nim);
if (vcoedge != NULL)
{
memcpy(vcoedge,nim->tuner.cx24108.vco_edge,HAMARO_CX24108_VCOEDGE_LEN);
return(True);
}
HAMARO_DRIVER_SET_ERROR(nim,HAMARO_BAD_PARM);
return(False);
} /* _HAMARO_TUNER_CX24108_GetVCOEdges() */
/*******************************************************************************************************/
/* HAMARO_TUNER_CX24108_SetVCOEdges() */
/*******************************************************************************************************/
BOOL HAMARO_TUNER_CX24108_SetVCOEdges( /* Performs hardware VCO edge detection */
HAMARO_NIM *nim, /* pointer to nim */
HAMARO_VCO_EDGE *vcoedge) /* copy of VCO_edges returned to caller, if vcoedge != NULL */
{
HAMARO_TUNER_CX24108_VALIDATE(nim);
/* if function is passed a NULL, recalc the vco edges */
if (vcoedge == NULL)
{
/* calculate hardware vco edges */
if (_HAMARO_TUNER_CX24108_hardware_vcoedges(nim) == False) return(False);
return(True);
}
/* copy from nim's tuner buffer into user struct */
if (vcoedge != NULL && vcoedge != nim->tuner.cx24108.vco_edge)
memcpy(vcoedge,nim->tuner.cx24108.vco_edge,HAMARO_CX24108_VCOEDGE_LEN);
return(True);
} /* HAMARO_TUNER_CX24108_SetVCOEdges() */
/*******************************************************************************************************/
/* HAMARO_TUNER_GetVCOBreakpoints() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_GetVCOBreakpoints( /* retrieve s vco breakpoint and vco edge data from HAMARO_NIM */
HAMARO_NIM *nim, /* pointer to nim */
int *bp_percentage, /* breakpoint percentage returned to caller */
HAMARO_VCO_EDGE *vcoedge, /* vco edge struct returned to caller */
HAMARO_VCO_BP *vcobp) /* vco breakpoint struct returned to caller */
{
HAMARO_TUNER_CX24108_VALIDATE(nim);
/* get current bp percentage from vco_bp struct, set last bp% in rosie struct, set user bp% */
if (bp_percentage != NULL)
{
*bp_percentage = (int)nim->tuner.cx24108.vco_bp[0].percentage;
nim->tuner.cx24108.BPPercentage = (int)nim->tuner.cx24108.vco_bp[0].percentage;
}
if (vcoedge != NULL)
memcpy(vcoedge,nim->tuner.cx24108.vco_edge,HAMARO_CX24108_VCOEDGE_LEN);
if (vcobp != NULL)
memcpy(vcobp,nim->tuner.cx24108.vco_bp,HAMARO_CX24108_VCOBP_LEN);
return(True);
} /* HAMARO_TUNER_CX24108_GetVCOBreakpoints() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_SetVCOBreakpointPercentage() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_SetVCOBreakpointPercentage( /* sets the breakpoint pcts for the tuner VCO edge calcs */
HAMARO_NIM *nim, /* pointer to nim */
int bp_percentage) /* breakpoint percentage */
{
int i;
HAMARO_TUNER_CX24108_VALIDATE(nim);
/* save the current BP% and set all bp to same */
nim->tuner.cx24108.BPPercentage = bp_percentage;
for (i = 0 ; i < HAMARO_CX24108_BPCNT ; i++)
{
nim->tuner.cx24108.vco_bp[i].percentage = (unsigned long)nim->tuner.cx24108.BPPercentage;
}
/* recalculate edges using new BP % */
_HAMARO_TUNER_CX24108_calc_bp(nim);
return(True);
} /* _HAMARO_TUNER_CX24108_SetVCOBreakpointPercentage() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_GetVCOBreakpointPercentage() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_GetVCOBreakpointPercentage( /* sets the vco breakpoint percentage */
HAMARO_NIM *nim, /* nim pointer */
int *bp_percentage) /* breakpoint percentage */
{
HAMARO_TUNER_CX24108_VALIDATE(nim);
/* pull bp% from current structure, save to current bp setting, return */
*bp_percentage = (int)nim->tuner.cx24108.vco_bp[0].percentage;
nim->tuner.cx24108.BPPercentage = *bp_percentage;
return(True);
} /* _HAMARO_TUNER_CX24108_GetVCOBreakpointPercentage() */
/*******************************************************************************************************/
/* tunerBWtoV[] */
/*******************************************************************************************************/
static const unsigned int tunerBWtoV[25] = {
308U, 402U, 493U, 585U,
679U, 780U, 884U, 986U,
1084U, 1181U, 1296U, 1400U,
1496U, 1596U, 1720U, 1843U,
1960U, 2078U, 2209U, 2321U,
2436U, 2572U, 2681U, 2867U,
3034U};
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_SetFilterBandwidth() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_SetFilterBandwidth(/* function to set the input voltage for tuner's anti-alias filter */
HAMARO_NIM *nim, /* pointer to nim */
unsigned long bandwidthkhz) /* bandwidth in khz */
{
unsigned int fractionalPart;
unsigned int index;
HAMARO_TUNER_CX24108_VALIDATE(nim);
/* (CR 6886) */
nim->antialias_bandwidthkhz = bandwidthkhz; /* (CR 7482) */
bandwidthkhz += HAMARO_ANTI_ALIAS_FILTER_UNCERTANTY;
if (bandwidthkhz <= 4000UL)
{
nim->antialias_mV_setting = tunerBWtoV[0];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -