📄 hamaro_cx24108.c
字号:
if (nim->tuner.cx24108.vcodiv == HAMARO_VCODIV4) start_pt = HAMARO_CX24108_START_DIV4;
/* step through each VCO, examine for a valid VCO edge, if edge is not valid, generate a warning */
for (j = 0 ; j < HAMARO_CX24108_VCOEDGES ; j++)
{
unsigned long Fl = nim->tuner.cx24108.vco_edge[j].lower;
unsigned long Fh = nim->tuner.cx24108.vco_edge[j].upperthresh;
if (Fl <= HAMARO_MAX_TUNER_VCOERROR || Fh <= HAMARO_MAX_TUNER_VCOERROR)
{
/* an invalid VCO edge was detected, flag as warning, then continue */
HAMARO_DRIVER_SET_ERROR(nim,HAMARO_TUNERVCO);
}
}
/* match Fr to vco edges, using high and low breakpoints, not actual edges */
for (j = start_pt ; j < HAMARO_CX24108_VCOEDGES ; j++)
{
/* find a VCO by looking into 1/2 .. 8/2, then 8/4, 8/4, 6/4 vcos */
i = _vcosearchorder[j]; /* remove this line if vco search s/b 1/2..8/2,6/4..8/4 */
if (_HAMARO_TUNER_CX24108_vco_range(nim,Fr,i) == True)
{
int idx;
/* grab vcoset, vcodiv, return to caller */
*vcono = (HAMARO_VCONO)(_vcono[i]+1); /* returns VCO number before divider is set */
*vcoset = _vcoset[i]; /* returns actual VCOSET enum value */
*vcodiv = _vcodiv[i]; /* vco divider */
*bandbin = _bandbin[i]; /* band sel prog'd directly to cx24108 */
*vcodivbin = (unsigned int)_vcodivbin[*vcodiv]; /* vcodiv prog'd directly to cx24108 */
*tunpll = 0UL;
/* compute current vco length */
vco_len = nim->tuner.cx24108.vco_edge[i].upperthresh - nim->tuner.cx24108.vco_edge[i].lower;
/* set cpc default current to mid level */
nim->tuner.cx24108.CPCCurrent = (int)nim->tuner.cx24108.tunerparms.CPC[_vcono[*vcoset]].mid;
/* is fr in lower percentage area (defined by tunerparms.low percentage)? */
if (Fr < (nim->tuner.cx24108.vco_edge[i].lower+
((vco_len/100UL)*nim->tuner.cx24108.tunerparms.CPC[_vcono[*vcoset]].LowPercentage)))
{
nim->tuner.cx24108.CPCCurrent = (int)nim->tuner.cx24108.tunerparms.CPC[_vcono[*vcoset]].low;
}
else
{
if (Fr >= (nim->tuner.cx24108.vco_edge[i].lower+
((vco_len/100UL)*nim->tuner.cx24108.tunerparms.CPC[_vcono[*vcoset]].HighPercentage)))
{
nim->tuner.cx24108.CPCCurrent = (int)nim->tuner.cx24108.tunerparms.CPC[_vcono[*vcoset]].high;
}
}
/* save tuner slope data into rosie (current settings) */
idx = 0;
srm = HAMARO_MM;
if (nim->symbol_rate < HAMARO_MM) srm = HAMARO_M;
if (nim->symbol_rate >= (1UL*srm) && nim->symbol_rate <= (5UL*srm)) idx = HAMARO_CX24108_MSPS_1_TO_5;
else if (nim->symbol_rate >= (5UL*srm) && nim->symbol_rate <= (15UL*srm)) idx = HAMARO_CX24108_MSPS_5_TO_15;
else if (nim->symbol_rate >= (15UL*srm) && nim->symbol_rate <= (45UL*srm)) idx = HAMARO_CX24108_MSPS_15_TO_45;
nim->tuner.cx24108.VCASlope = nim->tuner.cx24108.tunerparms.SLP[idx].VCASlope;
nim->tuner.cx24108.VCAOffset = nim->tuner.cx24108.tunerparms.SLP[idx].VCAOffset;
nim->tuner.cx24108.VGA1Offset = nim->tuner.cx24108.tunerparms.SLP[idx].VGA1Offset;
nim->tuner.cx24108.VGA2Offset = nim->tuner.cx24108.tunerparms.SLP[idx].VGA2Offset;
return(True);
}
}
/* this error number is set if a valid freq can not be found within the present VCO edges. */
/* (default VCO edges might have been used) */
HAMARO_DRIVER_SET_ERROR(nim,HAMARO_TUNERVCO);
return(False);
} /* _HAMARO_TUNER_CX24108_band_info() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_vco_range() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_vco_range( /* function to test if Freq. requested is within vcoidx bounds */
HAMARO_NIM *nim, /* pointer to nim */
unsigned long Fr, /* frequency requested */
int vcoidx) /* vco index */
{
unsigned long Ft; /* Freq-test */
unsigned long Fl = nim->tuner.cx24108.vco_edge[vcoidx].lower;
unsigned long Fh = nim->tuner.cx24108.vco_edge[vcoidx].upperthresh;
if (Fr >= Fl && Fr <= Fh)
{
/* test Fr against valid low range */
Ft = _HAMARO_TUNER_CX24108_vco_low(nim,vcoidx);
if (Fr < Ft) return(False);
Ft = _HAMARO_TUNER_CX24108_vco_high(nim,vcoidx);
if (Fr > Ft) return(False);
return(True);
}
return(False);
} /* _HAMARO_TUNER_CX24108_vco_range() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_vco_low() */
/*******************************************************************************************************/
unsigned long _HAMARO_TUNER_CX24108_vco_low( /* function to return Fr low range based on vcoidx */
HAMARO_NIM *nim, /* pointer to nim */
int vcoidx) /* vco index */
{
if (vcoidx >= 0)
{
switch(vcoidx)
{
case 0:
{
return(nim->tuner.cx24108.vco_bp[HAMARO_CX24108_BPCNT-1].breakpt);
break;
}
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
{
return(nim->tuner.cx24108.vco_bp[vcoidx-1].breakpt);
break;
}
case 8:
{
return(nim->tuner.cx24108.vco_edge[vcoidx].lower);
break;
}
case 9:
{
/* no other BP's to test, so return lowest freq tested */
return(nim->tuner.cx24108.vco_bp[7].breakpt);
break;
}
case 10:
{
return(nim->tuner.cx24108.vco_bp[8].breakpt);
break;
}
default:
{
break;
}
} /* switch(... */
}
return(0UL);
} /* _HAMARO_TUNER_vco_low() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_vco_high() */
/*******************************************************************************************************/
unsigned long _HAMARO_TUNER_CX24108_vco_high(/* function to return Fr high range based on vcoidx */
HAMARO_NIM *nim, /* pointer to nim */
int vcoidx) /* vco index */
{
if (vcoidx >= 0)
{
switch(vcoidx)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
{
return(nim->tuner.cx24108.vco_bp[vcoidx].breakpt);
break;
}
case 7:
{
return(nim->tuner.cx24108.vco_edge[vcoidx].upperthresh);
break;
}
case 8:
{
/* (CR 7452) should return the current break pt. */
return(nim->tuner.cx24108.vco_bp[7].breakpt);
break;
}
case 9:
{
/* no other BP's to test, so return lowest freq tested */
return(nim->tuner.cx24108.vco_bp[8].breakpt);
break;
}
case 10:
{
return(nim->tuner.cx24108.vco_edge[vcoidx].upperthresh);
break;
}
default:
{
break;
}
} /* switch(... */
}
return(0UL);
} /* _HAMARO_TUNER_vco_high() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_calc_bp() */
/*******************************************************************************************************/
void _HAMARO_TUNER_CX24108_calc_bp( /* calculates breakpoint values for nim's vco's */
HAMARO_NIM *nim) /* pointer to nim */
{
int i;
unsigned long ulTemp;
unsigned long ulTemp2;
long diff;
long bp;
/* build breakpoints for vcos: (1/2;2/3;3/4;4/5;5/6;6/7;7/8 )div2 -- count 7 */
for (i = 0 ; i < 7 ; i++)
{
ulTemp = (nim->tuner.cx24108.vco_edge[i].upperthresh/1000UL);
ulTemp2 = (nim->tuner.cx24108.vco_edge[i+1].lower/1000UL);
diff = ulTemp - ulTemp2;
bp = (diff * (long)nim->tuner.cx24108.vco_bp[i].percentage) / 100L;
nim->tuner.cx24108.vco_bp[i].breakpt = ((unsigned long)bp * 1000UL);
nim->tuner.cx24108.vco_bp[i].breakpt += nim->tuner.cx24108.vco_edge[i+1].lower;
}
/* use 6/D2 breakpoint div by two, for D/4 breakpoint */
i = 7;
nim->tuner.cx24108.vco_bp[i].breakpt = (nim->tuner.cx24108.vco_bp[5].breakpt/2UL);
/* use 7/D2 breakpoint div by two, for D/4 breakpoint */
i = 8;
nim->tuner.cx24108.vco_bp[i].breakpt = (nim->tuner.cx24108.vco_bp[6].breakpt/2UL);
/* manually build breakpoint for vco 8/0 div4 -- count 1 */
i = HAMARO_CX24108_BPCNT-1;
ulTemp = (nim->tuner.cx24108.vco_edge[i+1].upperthresh/1000UL);
ulTemp2 = (nim->tuner.cx24108.vco_edge[0].lower/1000UL);
if (ulTemp2 < (unsigned long)(1075UL*HAMARO_M)) ulTemp2 = (unsigned long)(1075UL*HAMARO_M);
diff = ulTemp - ulTemp2;
bp = (diff * (long)nim->tuner.cx24108.vco_bp[i].percentage) / 100L;
nim->tuner.cx24108.vco_bp[i].breakpt = ((unsigned long)bp * 1000UL);
nim->tuner.cx24108.vco_bp[i].breakpt += (nim->tuner.cx24108.vco_edge[0].lower);
return;
} /* _HAMARO_TUNER_CX24108_calc_bp() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_adjust() */
/*******************************************************************************************************/
void _HAMARO_TUNER_CX24108_adjust( /* adjusts VCO table, disallows vco below 2150 MHz */
HAMARO_NIM *nim) /* nim pointer */
{
if (nim == (HAMARO_NIM*)NULL) return;
/* adjust lower edge of vco 0 -- disallow use of this vco if freq is below 1075 */
/* REMOVED per CR 7878 */
/* if (nim->tuner.cx24108.vco_edge[0].lower < (unsigned long)(1075UL*HAMARO_MM)) */
/* nim->tuner.cx24108.vco_edge[0].lower = (unsigned long)(1075UL*HAMARO_MM); */
return;
} /* _HAMARO_TUNER_CX24108_adjust() */
/*******************************************************************************************************/
/* _HAMARO_TUNER_CX24108_hardware_vcoedges() */
/*******************************************************************************************************/
BOOL _HAMARO_TUNER_CX24108_hardware_vcoedges(/* calculates vco edges via binary search algorithm */
HAMARO_NIM *nim) /* pointer to nim */
{
int vcoidx;
int CPCCurrent;
unsigned long low_edge;
unsigned long high_edge;
unsigned long first_edge; /* returned from low edge detection */
/* set the default settings */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -