📄 hamaro_cx24128.c
字号:
/* Disable ps_test: set 0x10[6] to 0x00 */
/* Read 0x10, and clear 0x10[6] */
if (HAMARO_TunerRegisterRead(p_nim, (unsigned short)(0x10), (unsigned long*)®_value, HAMARO_IO_UNKNOWN) != True)
{
return(False);
}
reg_value &= 0xBF;
if (HAMARO_TunerRegisterWrite(p_nim, (unsigned short)(0x10), (unsigned long)reg_value, HAMARO_IO_UNKNOWN) != True)
{
return(False);
}
/* Calculate N,F,R by specified frequency value. */
if (HAMARO_TUNER_CX24128_calc_pllNF(p_nim,&nvalue,&fvalue) != True) return(False);
/* Set N,F,R to tuner registers. */
if (HAMARO_TUNER_CX24128_SetNFRRegisters(p_nim,nvalue,fvalue,p_nim->tuner.cx24128.R) != True) return(False);
/* set the vco divider to the tuner */
/* Read 0x18, and clear 0x18[6] */
if (HAMARO_TunerRegisterRead(p_nim, (unsigned short)(0x18), (unsigned long*)®_value, HAMARO_IO_UNKNOWN) != True)
{
return(False);
}
reg_value &= 0xBF;
if (p_nim->tuner.cx24128.vcodiv == HAMARO_VCODIV2)
{
reg_value |= 0x00;
}
else
{
reg_value |= 0x40;
}
if (HAMARO_TunerRegisterWrite(p_nim, (unsigned short)(0x18), (unsigned long)reg_value, HAMARO_IO_UNKNOWN) != True)
{
return(False);
}
/* Start tuning. */
/* Read 0x1C, and set 0x1C[4] to 1 */
if (HAMARO_TunerRegisterRead(p_nim, (unsigned short)(0x1C), (unsigned long*)®_value, HAMARO_IO_UNKNOWN) != True)
{
return(False);
}
reg_value |= 0x10;
if (HAMARO_TunerRegisterWrite(p_nim, (unsigned short)(0x1C), (unsigned long)reg_value, HAMARO_IO_UNKNOWN) != True)
{
return(False);
}
/* Check back again after some delay */
if (HAMARO_TUNER_CX24128_LockTest(p_nim) == False) /* pll did not lock */
{
return (False);
}
return(True);
} /* HAMARO_TUNER_CX24128_SetFrequency() */
/*******************************************************************************************************
* HAMARO_TUNER_CX24128_GetFilterBandwidth()
* function to get the filter bandwidth for tuner's anti-alias filter
*******************************************************************************************************/
BOOL
HAMARO_TUNER_CX24128_GetFilterBandwidth(HAMARO_NIM *p_nim, /* pointer to nim */
HAMARO_FILTERBW *p_filterbandwidth, /* filter bandwidth */
unsigned short *p_gmcbandwidth) /* gmc bandwidth */
{
unsigned short gmcbw;
HAMARO_TUNER_CX24128_VALIDATE(p_nim);
if (p_gmcbandwidth == 0 || p_filterbandwidth == 0) return(False);
*p_filterbandwidth = (HAMARO_FILTERBW)((p_nim->antialias_bandwidthkhz & 0xFC0) >> 6);
gmcbw = (unsigned short)(p_nim->antialias_bandwidthkhz & 0x3F);
/* convert gmc bandwidth to be in KHz. */
gmcbw = (unsigned short)(gmcbw * HAMARO_CX24128_GMCBW_STEP_SIZE + HAMARO_CX24128_MIN_GMCBW);
*p_gmcbandwidth = gmcbw;
return(True);
} /* HAMARO_TUNER_CX24128_GetFilterBandwidth */
/*******************************************************************************************************
* HAMARO_TUNER_CX24128_SetFilterBandwidth()
* function to set the filter bandwidth for tuner's anti-alias filter
*******************************************************************************************************/
BOOL
HAMARO_TUNER_CX24128_SetFilterBandwidth(HAMARO_NIM *p_nim, /* pointer to nim */
unsigned long bandwidthkhz) /* bandwidth in khz */
{
unsigned long reg_value = 0;
HAMARO_FILTERBW filterbandwidth = HAMARO_FILTERBW_35MHZ;
HAMARO_TUNER_CX24128_VALIDATE(p_nim);
/* gmcbandwidth is in KHz. */
if ((bandwidthkhz > HAMARO_CX24128_MAX_GMCBW) || (bandwidthkhz < HAMARO_CX24128_MIN_GMCBW))
{
return(False);
}
if (bandwidthkhz <= 19000UL) /* 19 MHz */
{
filterbandwidth = HAMARO_FILTERBW_35MHZ;
}
else if (bandwidthkhz > 19000UL && bandwidthkhz <= 25000UL) /* 19 MHz to 25 MHz */
{
filterbandwidth = HAMARO_FILTERBW_40MHZ;
}
else /* > 25 MHz */
{
filterbandwidth = HAMARO_FILTERBW_65MHZ;
}
/* 0x1E[5:0] */
reg_value = (unsigned long)((bandwidthkhz * 10UL - HAMARO_CX24128_MIN_GMCBW * 10UL) / HAMARO_CX24128_GMCBW_STEP_SIZE);
reg_value += 5UL;
reg_value /= 10UL;
/*reg_value = (unsigned long)((bandwidthkhz - HAMARO_CX24128_MIN_GMCBW) / HAMARO_CX24128_GMCBW_STEP_SIZE);*/
/* 0x1E[7:6] */
reg_value |= ((unsigned char)filterbandwidth << 6);
if (HAMARO_TunerRegisterWrite(p_nim, (unsigned short)(0x1E), (unsigned long)reg_value, HAMARO_IO_UNKNOWN) != True)
{
return(False);
}
p_nim->antialias_bandwidthkhz = ((unsigned long)filterbandwidth << 6UL) | reg_value;
return(True);
} /* HAMARO_TUNER_CX24128_SetFilterBandwidth */
/*******************************************************************************************************
* HAMARO_TUNER_CX24128_GetGainSettings()
* function to get the tuner gain settings
*******************************************************************************************************/
BOOL
HAMARO_TUNER_CX24128_GetGainSettings(HAMARO_NIM *p_nim, /* pointer to nim */
HAMARO_AMPOUT *p_ampout, /* Discrete gain control*/
HAMARO_VGA1OFFSET *p_vga1offset, /* VGA1 offset control*/
HAMARO_VGA2OFFSET *p_vga2offset, /* VGA2 offset control*/
HAMARO_RFVGAOFFSET *p_rfvgaoffset) /* RF VGA offset control*/
{
HAMARO_TUNER_CX24128_VALIDATE(p_nim);
if (p_ampout == 0 || p_vga1offset == 0 || p_vga2offset == 0 || p_rfvgaoffset == 0)
{
return(False);
}
*p_ampout = p_nim->tuner.cx24128.ampout;
*p_vga1offset = p_nim->tuner.cx24128.vga1offset;
*p_vga2offset = p_nim->tuner.cx24128.vga2offset;
*p_rfvgaoffset = p_nim->tuner.cx24128.rfvgaoffset;
return(True);
} /* HAMARO_TUNER_CX24128_GetGainSettings */
/*******************************************************************************************************
* HAMARO_TUNER_CX24128_SetGainSettigns()
* function to set the gain settings to tuner and nim
*******************************************************************************************************/
BOOL
HAMARO_TUNER_CX24128_SetGainSettings(HAMARO_NIM *p_nim, /* pointer to nim */
unsigned long symbolrateksps)/* symbol rate determines the VCA, VGA settings */
{
unsigned long reg_value;
signed char power_estimated = 0;
HAMARO_AMPOUT ampout;
HAMARO_VGA1OFFSET vga1offset;
HAMARO_VGA2OFFSET vga2offset;
HAMARO_RFVGAOFFSET rfvgaoffset;
HAMARO_TUNER_CX24128_VALIDATE(p_nim);
symbolrateksps = 0; /* Unused. However, the prototype should match HAMARO_TUNER_SetGainSettings function pointer */
if (HAMARO_GetPowerEstimation(p_nim, &power_estimated) == False)
{
return (False);
}
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
/* Read 0x1D, and clear 0x1D[3:0] */
if (HAMARO_TunerRegisterRead(p_nim, (unsigned short)(0x1D), (unsigned long*)®_value, HAMARO_IO_UNKNOWN) != True)
{
return(False);
}
reg_value &= 0xF0;
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
if (power_estimated >= p_nim->tuner.cx24128.tuner_gain_thresh) /* in dBm */
{ /* SET2 (Optimized for IIP3) - High seignal level */
p_nim->tuner.cx24128.gain_setting_selection = HAMARO_SIGNAL_LEVEL_HIGH;
rfvgaoffset = HAMARO_RFVGAOFFSET_0;
vga1offset = HAMARO_VGA1OFFSET_7;
vga2offset = HAMARO_VGA2OFFSET_7;
ampout = HAMARO_AMPOUT_25DB;
}
else /* SET1 (Optimized for NF) - low signal level */
{
p_nim->tuner.cx24128.gain_setting_selection = HAMARO_SIGNAL_LEVEL_LOW;
rfvgaoffset = HAMARO_RFVGAOFFSET_2;
vga1offset = HAMARO_VGA1OFFSET_2;
vga2offset = HAMARO_VGA2OFFSET_6;
ampout = HAMARO_AMPOUT_25DB;
}
reg_value |= ((unsigned char)ampout & 0x0F);
if(HAMARO_TunerRegisterWrite(p_nim, (unsigned short)(0x1D), (unsigned long)reg_value, HAMARO_IO_UNKNOWN) != True)
{
return(False);
}
p_nim->tuner.cx24128.ampout = ampout;
/* Read 0x1F, and clear 0x1F[5:0] */
if (HAMARO_TunerRegisterRead(p_nim, (unsigned short)(0x1F), (unsigned long*)®_value, HAMARO_IO_UNKNOWN) != True)
{
return(False);
}
reg_value &= 0xC0;
reg_value |= ((unsigned char)vga1offset & 0x07); /* 0x1F[2:0] */
p_nim->tuner.cx24128.vga1offset = vga1offset;
reg_value |= (((unsigned char)vga2offset << 3) & 0x38); /* 0x1F[5:3] */
if(HAMARO_TunerRegisterWrite(p_nim, (unsigned short)(0x1F), (unsigned long)reg_value, HAMARO_IO_UNKNOWN) != True)
{
return(False);
}
p_nim->tuner.cx24128.vga2offset = vga2offset;
/* Read 0x20, and clear 0x20[3:2] */
if (HAMARO_TunerRegisterRead(p_nim, (unsigned short)(0x20), (unsigned long*)®_value, HAMARO_IO_UNKNOWN) != True)
{
return(False);
}
reg_value &= 0xF3;
reg_value |= (((unsigned char)rfvgaoffset << 2) & 0x0C);
if(HAMARO_TunerRegisterWrite(p_nim, (unsigned short)(0x20), (unsigned long)reg_value, HAMARO_IO_UNKNOWN) != True)
{
return(False);
}
p_nim->tuner.cx24128.rfvgaoffset = rfvgaoffset;
return(True);
} /* HAMARO_TUNER_CX24128_SetGainSettings */
/*******************************************************************************************************
* HAMARO_TUNER_CX24128_GetClkInversion()
* gets the current clock inversion status, returns value to caller
*******************************************************************************************************/
BOOL
HAMARO_TUNER_CX24128_GetClkInversion(HAMARO_NIM *p_nim, /* pointer to nim */
BOOL *p_clkinversion) /* clock inversion value */
{
HAMARO_TUNER_CX24128_VALIDATE(p_nim);
*p_clkinversion = p_nim->tuner.cx24128.clkinversion;
return(True);
} /* HAMARO_TUNER_CX24128_GetClkInversion() */
/*******************************************************************************************************
* HAMARO_TUNER_CX24128_GetEnableRegister()
* read the enable bits from tuner
*******************************************************************************************************/
BOOL
HAMARO_TUNER_CX24128_GetEnableRegister(HAMARO_NIM *p_nim, /* pointer to nim */
unsigned char *p_enable) /* enable bits */
{
unsigned long reg_value;
HAMARO_TUNER_CX24128_VALIDATE(p_nim);
/* read the enable bits from the tuner */
if(HAMARO_RegisterRead(p_nim, HAMARO_CX24128_EN, ®_value, p_nim->tuner.cx24128.io_method) != True) return(False);
*p_enable = (unsigned char)reg_value;
return(True);
} /* HAMARO_TUNER_CX24128_GetEnableRegister() */
/*******************************************************************************************************
* HAMARO_TUNER_CX24128_GetVcoStatus()
* reads tuner register to get the Vco edge detection status
*******************************************************************************************************/
BOOL
HAMARO_TUNER_CX24128_GetVcoStatus(HAMARO_NIM *p_nim, /* pointer to nim */
HAMARO_VCOSTATUS *p_vcostatus) /* pointer to the returned vco status. */
{
unsigned long reg_value;
HAMARO_VCOMODE VcoMode;
HAMARO_TUNER_CX24128_VALIDATE(p_nim);
VcoMode = p_nim->tuner.cx24128.viperparms.VcoMode;
switch(VcoMode)
{
case HAMARO_VCOMODE_AUTO:
case HAMARO_VCOMODE_TEST:
{
if(HAMARO_RegisterRead(p_nim, HAMARO_CX24128_BS_ERR, ®_value, p_nim->tuner.cx24128.io_method) != True) return(False);
if (reg_value == 0x01UL)
{
*p_vcostatus = HAMARO_VCO_AUTO_FAIL;
}
else
{
*p_vcostatus = HAMARO_VCO_AUTO_DONE;
}
break;
}
default:
{
//HAMARO_DRIVER_SET_ERROR(p_nim,HAMARO_TUNERREF); /* need define a new err number. */
return(False);
break;
}
}
p_nim->tuner.cx24128.viperparms.VCOstatus = *p_vcostatus;
return(True);
}/* HAMARO_TUNER_CX24128_GetVcoStatus() */
/*******************************************************************************************************
* HAMARO_TUNER_CX24128_GetVcoStatus()
* reads tuner register to get the selected ICP level
*******************************************************************************************************/
BOOL
HAMARO_TUNER_CX24128_GetAnalogICPLevel(HAMARO_NIM *p_nim, HAMARO_ICPSELECT *p_icplevel)
{
unsigned long reg_value;
HAMARO_TUNER_CX24128_VALIDATE(p_nim);
/* get the selected level from the tuner */
if(HAMARO_RegisterRead(p_nim, HAMARO_CX24128_ICP_SEL, ®_value, p_nim->tuner.cx24128.io_method) != True) return(False);
if (reg_value == 0)
{
*p_icplevel = HAMARO_ICPSELECT_LEVEL1;
}
else
{
*p_icplevel = (HAMARO_ICPSELECT)reg_value;
}
p_nim->tuner.cx24128.viperparms.ICPselect = *p_icplevel;
return(True);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -