ct202.c
来自「QPSK Tuner details, for conexant chipset」· C语言 代码 · 共 2,621 行 · 第 1/5 页
C
2,621 行
}
EN_DRV_RESULT CT_NIM_WriteDiSEqC(CT_DiSEqC_PARAMETER *stDiSEqCMsg,CSHDITunerIndex bTunerIndex)
{
#ifdef CT_OS_CHECK_STACKSIZE
CT_OS_RecordTaskStack();
#endif
u8 i;
lnb_cmd_S lnb_cmd;
lnb_cmd.lnb_cont = 0;
lnb_cmd.lnb_Vsel = 0;
lnb_cmd.lnb_mmsg = 0;
lnb_cmd.lnb_msg_len = stDiSEqCMsg->u16MsgLen;
for(i=0; i<lnb_cmd.lnb_msg_len; i++)
lnb_cmd.lnb_msg[i] = stDiSEqCMsg->au8Msg[i];
if(stDiSEqCMsg->u8Satellite == 1)
lnb_cmd.lnb_tburst = 1;
else
lnb_cmd.lnb_tburst = 0;
if (SetLNBmsg(lnb_cmd,bTunerIndex)!=TRUE)
{
return DRVERR_NOTOK;
}
return DRV_OK;
}
EN_DRV_RESULT CT_NIM_WriteDiSEqC_ToneBurst(CT_DiSEqC_PARAMETER *stDiSEqCMsg,CSHDITunerIndex bTunerIndex)
{
#ifdef CT_OS_CHECK_STACKSIZE
CT_OS_RecordTaskStack();
#endif
u8 i;
lnb_cmd_S lnb_cmd;
lnb_cmd.lnb_cont = 0;
lnb_cmd.lnb_Vsel = 0;
lnb_cmd.lnb_mmsg = 0;
lnb_cmd.lnb_msg_len = stDiSEqCMsg->u16MsgLen;
for(i=0; i<lnb_cmd.lnb_msg_len; i++)
lnb_cmd.lnb_msg[i] = stDiSEqCMsg->au8Msg[i];
if(stDiSEqCMsg->u8Satellite == 1)
lnb_cmd.lnb_tburst = 1;
else
lnb_cmd.lnb_tburst = 0;
if (SetLNBmsg_ToneBurst(lnb_cmd,bTunerIndex)!=TRUE)
{
return DRVERR_NOTOK;
}
return DRV_OK;
}
/*
* Get NIM signal quality current
*/
EN_DRV_RESULT CT_NIM_GetQuality(int *pu16Quality,CSHDITunerIndex bTunerIndex)
{
#ifdef CT_OS_CHECK_STACKSIZE
CT_OS_RecordTaskStack();
#endif
//printf("enter CT_NIM_GetQuality!!!");
u8 u8Quality = 0;
u16 u16CnR = 0;
u16 u16CN_Limit = 0;
u8 u8Locksta;
coderate_t coderate;
u32 temp, temp2;
u8 u8DoNotGetAverage;
u16 u16Strength;
u8 nReturn1;
u16 pu16LockStatus;
/*
if(_b8SetAcquireflag == TRUE)
{
u8DoNotGetAverage |= 0x80;
_b8SetAcquireflag = FALSE;
}*/
//nReturn1 = DRV_OK;//CT_NIM_CheckLock(&pu16LockStatus,bTunerIndex);
//nReturn1 = CT_NIM_CheckLock(&pu16LockStatus,bTunerIndex);
if ( 1/*(nReturn1 == DRV_OK)&& (TRUE == pu16LockStatus )*/)
{
SetCNRmon(0x400, bTunerIndex);
GetCNR(&u16CnR,bTunerIndex);
if (u16CnR > 350)
{
u16CnR = 350;
}
//printf("u16CnR == %d",u16CnR);
*pu16Quality = ((350 -u16CnR) *100) /350;
//printf("pu16Quality == %d",*pu16Quality);
return DRV_OK;
}
*pu16Quality = 0;
return DRVERR_NOTOK;
}
EN_DRV_RESULT CT_NIM_GetStrength(int *pu16Strength,CSHDITunerIndex bTunerIndex)
{
#ifdef CT_OS_CHECK_STACKSIZE
CT_OS_RecordTaskStack();
#endif
//printf("enter CT_NIM_GetStrength!!!");
u16 u16strength = 0;
u16 pu16LockStatus;
u8 u8Strength = 0;
u32 u32temp;
u8 nReturn1;
nReturn1 = DRV_OK;//CT_NIM_CheckLock(&pu16LockStatus,bTunerIndex);
if ( (nReturn1 == DRV_OK))
{
if(1/*pu16LockStatus == TRUE*/)
{
if(GetStrength(&u16strength,bTunerIndex) != TRUE)
return DRVERR_NOTOK;
if(u16strength > 80)
{
u8Strength = 0;
}
else if ( u16strength > 65 && u16strength <= 80 )
{//step 0 ~ 20
u32temp = 20;
u32temp *= (80 - u16strength);
u32temp /= (80 - 65);
u8Strength = (u8)u32temp;
}
else if ( u16strength > 51 && u16strength <= 65 )
{//step 20 ~ 70
u32temp = 50;
u32temp *= (65 - u16strength);
u32temp /= (65 - 51);
u8Strength = (u8)u32temp + 10;
}
else if ( u16strength > 25 && u16strength <= 51 )
{//step 70 ~ 90
u32temp = 20;
u32temp *= (51 - u16strength);
u32temp /= (51 - 25);
u8Strength = (u8)u32temp + 70;
}
else if ( u16strength > 10 && u16strength <= 25 )
{//step 90 ~ 100
u32temp = 10;
u32temp *= (25 - u16strength);
u32temp /= (25 - 10);
u8Strength = (u8)u32temp + 90;
}
else if ( u16strength <= 10)
{
u8Strength = 100;
}
#ifdef XYH_SIGNAL_INFO
u16strength = ((u16)u8Strength * 9) /10;
u8Strength = (u8)u16strength;
#endif
*pu16Strength = u8Strength;
return DRV_OK;
}
else
{
*pu16Strength = 0;/*if it is not lock,strength should be 0*/
return DRV_OK;
}
}
else
{
return DRVERR_NOTOK;
printf("CT_NIM_CheckLock failed!!!!!!");
}
}
/*
* Set scan channel by singal manual or auto blind scan
*/
EN_DRV_RESULT CT_NIM_SetChannel(CT_NIM_Channel stChannel,CSHDITunerIndex bTunerIndex)
{
// this func is ported from set_frontend of frontend.c.
#ifdef CT_OS_CHECK_STACKSIZE
CT_OS_RecordTaskStack();
#endif
coderate_t coderate;
cfo_range_t cfo_range;
if(1/*(stChannel.u32Freq != _Tuner_freq) || (stChannel.u16SymbRate != _Data_rate)*/)
{
/*
#ifdef NIM_TS_SERIAL // for Enable TS
SetTStype(0, stChannel.u16SymbRate,bTunerIndex);// 0: serial, 1: parallel; set to serial to disable TS input
#else
//SetTStype(1,stChannel.u16SymbRate);
#endif*/
SetTStype(g_ucTSMode, stChannel.u16SymbRate, bTunerIndex);
#ifdef CT202ADEBUG
printf(("Acquire New Channel"));
#endif
SetTune((stChannel.u32Freq/1000), stChannel.u16SymbRate, bTunerIndex); //in KHz //in Baud
cfo_range = CFO_6_3; // +/- 6MHz search range
//printf(("\nSetting CFO Search Range...%hx\n", (u8)cfo_range));
SetCFOSearchRange(cfo_range,bTunerIndex);
coderate=(coderate_t)(FEC_1_2|FEC_2_3|FEC_3_4|FEC_5_6|FEC_6_7|FEC_7_8);//search all coderates
if(SetAcquire(stChannel.u16SymbRate, coderate,bTunerIndex) == FALSE)
{
printf("Acquire Channel Fail!!!!!!!!!!!!!");
return DRVERR_NOTOK;
}
}
else
{
#ifdef CT202ADEBUG
printf("Acquire Re-sync!!!!!!!!!!!!!");
#endif
ReSync(bTunerIndex);/*start acquisition process*/
}
//_b8DoReSync = TRUE; //Do re-sync in check_frontend_state()
//_Tuner_freq = stChannel.u32Freq;
//_Data_rate = stChannel.u16SymbRate;
//_b8SetAcquireflag = TRUE;
return DRV_OK;
}
CSQPSK_Error_t CT202AInit(CSHDITunerIndex bTunerIndex)
{
CSI2C_Error_t ErrorCode;
g_CTK202A[bTunerIndex] = 0;
ErrorCode = CSI2COpen(bTunerIndex,TUNER_I2C_ADDRESS,&g_CTK202A[bTunerIndex]);
CSASSERT(ErrorCode == CSI2C_SUCCESS);
if ( ErrorCode != CSI2C_SUCCESS)
{
////////printf("[ct202ainit failed!!!!!!!!!!]");
return CSQPSK_I2C_ERROR;
}
return CSQPSK_SUCCESS;
}
CSQPSK_Error_t CT202ACheckchipID (CSHDITunerIndex bTunerIndex)
{
u8 partnum;
if (GetPartnum (&partnum, bTunerIndex) != TRUE)
{
////////printf("CT202CheckchipID failed!!!!!!!!!!");
return CSQPSK_FAILURE;
}
////////printf("partnum == %d",partnum);
if ((partnum == 0x03) || (partnum == 0x01))
{
#ifdef CT202ADEBUG
////////printf("CT202A has been found!!!!!!!!!");
#endif
return CSQPSK_SUCCESS;
}
return CSQPSK_FAILURE;
}
CSQPSK_Error_t CT202ARegInit (int nTSOutMode,CSHDITunerIndex bTunerIndex)
{
u16 i;
u8 reg1, reg2;
bool8 status = 1;
if (CSQPSK_SUCCESS!= CT202AInit(bTunerIndex))
{
////////printf("CT202AInit failed!!!!!!!!!!!");
}
for(i = 0; i < sizeof(INIT_REGISTERS) / 2; ++i)
{
if(INIT_REGISTERS[i][0]==0xff && INIT_REGISTERS[i][1]==0xff)
break;
reg1 = INIT_REGISTERS[i][0];
reg2 = INIT_REGISTERS[i][1];
status &= SetReg(g_CTK202A[bTunerIndex],reg1,®2,0x01);
}
reg1 = 0x08; /*QPSK & DVB MODE*/
status &= SetReg(g_CTK202A[bTunerIndex],SYSTEM_MODE_REG,®1,0x01);
/*to config TS output mode*/
if (TS_PARALLEL == nTSOutMode)
{
g_ucTSMode = 1;/*config the TS interface*/
if (DRV_OK != CT_Demux_SerialTS(NIM_0, FALSE))/*config the Demux*/
{
return CSQPSK_FAILURE;
}
}
else if (TS_SERIAL == nTSOutMode)
{
g_ucTSMode = 0;/*config the TS interface*/
if (DRV_OK != CT_Demux_SerialTS(NIM_0, TRUE))/*config the Demux*/
{
return CSQPSK_FAILURE;
}
}
if(status != PASS)
{
////////printf("SetReg failed!!!!!!!!!!!!!");
return CSQPSK_FAILURE;
}
CT202ADiSEqCReset(bTunerIndex);
return CSQPSK_SUCCESS;
}
#if 0
CSQPSK_Error_t CT202ACheckLockStatus ( CSHDITunerIndex bTunerIndex, int *pnLockStatus )
{
//*pnLockStatus = TRUE;
//return CSQPSK_SUCCESS;
//return;
int nReturn1,nReturn = CSQPSK_SUCCESS;
int nStatus;
BYTE szBuffer[3]={0,0,0};
*pnLockStatus = FALSE;
u16 pu16LockStatus;
u8 Locksta = 0, i = 0;
u8 regs_read, regs_read1, regs_read2, regs_read3;
/*
*pnLockStatus = 1;
return CSQPSK_SUCCESS;*/
//printf("CT202ACheckLockStatus!!!!");
#if 1
for (i = 0; i < 3; i++)
{
GetReg(g_CTK202A[bTunerIndex], LOCK_STATUS_REG_1, &Locksta, 0x01);
if((Locksta & 0x6f) == 0x6f)
{
*pnLockStatus = TRUE;
g_nLockStatus = 1;
return CSQPSK_SUCCESS;
}
else if ((Locksta & 0x40) != 0x40)////AGC not OK,so no signal!!!
{
*pnLockStatus = FALSE;
g_nLockStatus = 0;
return CSQPSK_SUCCESS;
}
else
{
if (GetAQCFail(bTunerIndex) == TRUE)
{
ReSync(bTunerIndex);////start a new sync process
}
CSSleep(3);///50
}
}
*pnLockStatus = FALSE;
return CSQPSK_SUCCESS;
#endif
#if 0
nReturn1 = CT_NIM_CheckLock(&pu16LockStatus, bTunerIndex);
//////////printf("nReturn1 === %d\r\n",nReturn1);
//////////printf("pu16LockStatus === %d\r\n",pu16LockStatus);
if ( nReturn1 == DRV_OK )
{
//printf("111111111111");
if(pu16LockStatus == TRUE)
{
//printf("22222222222");
#ifdef CT202ADEBUG
////////printf("t1t1ttttttt11111");
#endif
//nReturn = CSQPSK_SUCCESS;
*pnLockStatus = TRUE;
//printf("*pnLockStatus == LOCK!!!!");
return CSQPSK_SUCCESS;
}
else
{
//////////printf("333333333");
#ifdef CT202ADEBUG
////////printf("t12222222222");
#endif
//printf("*pnLockStatus == NOT LOCK!!!!");
*pnLockStatus = FALSE;
return CSQPSK_SUCCESS;
}
}
else
{
//////////printf("44444444");
#ifdef CT202ADEBUG
////////printf("t3333333333333");
#endif
//printf("*pnLockStatus == CT_NIM_CheckLock NOT OK!!!!");
*pnLockStatus = FALSE;
return CSQPSK_FAILURE;
}
//return nReturn;
#endif
}
#endif
#define SHOW_BER
#ifdef SHOW_BER
u32 u32ShowvitBERCounter = 0;
#endif
static CSQPSK_Error_t CT202AManualReSync (CSHDITunerIndex bTunerIndex)
{
#ifdef SHOW_BER
bool8 result = PASS;
u32 window_length[]={0x1000000, 0x100000, 0x10000, 0x1000};
u32 vitBERcount=0, RSBERcount=0;//KOHN
u8 RSBERcount_l=0, RSBERcount_h=0;//KOHN
u16 ii, j;
double vitBER;
u32 u32VitBer, u32VitBerP;
if(u32ShowvitBERCounter == 20)
{
u32ShowvitBERCounter = 0;
for(ii=0;ii<4;++ii)
{
//printf("1111111111111\r\n");
result = SetVitBERmon(bTunerIndex, window_length[ii]);
j=0;
do
{
//printf("222222222222222\r\n");
result = GetVitBERcount(&vitBERcount, bTunerIndex);
//printf("33333333333333\r\n");
j++;
}while(result== MONITOR_NOT_READY);// || j == 200); //wait for calculation to finish
//if the C/N monitor is saturated, increase the window size
//and start the measurement again
if(result != MONITOR_SATURATED)
break;
}
vitBER= (double) (vitBERcount) / (double) (window_length[ii]);
u32VitBer = vitBER;
vitBER -= u32VitBer;
u32VitBerP = vitBER * 10000000;
//printf("44444444444\r\n");
result = SetRSErrMon(bTunerIndex, window_length[2], 2, 3, 1);//KOHN
//printf("5555555555\r\n");
//result = GetRSErrCount(&RSBERcount, bTunerIndex);//KOHN
result = GetRSErrCount(&RSBERcount_l, &RSBERcount_h, bTunerIndex);//KOHN
//printf("66666666666\r\n");
if ((u32VitBerP > 20000) || (RSBERcount_l > 0) || (RSBERcount_h > 0))
{
//printf("7777777777\r\n");
ReSync(bTunerIndex);
//printf("88888888888\r\n");
//printf("\n RESYNC \n");
//printf("RS BER:%d\n", RSBERcount);//KOHN
//printf("Viterbi BER:%d.%05d\n", u32VitBer, u32VitBerP);
//printf("vitBERcount:%d window_length[ii]:%d\n", vitBERcount, window_length[ii]);
}
}
u32ShowvitBERCounter++;
#endif
//printf("9999999999999\r\n");
return CSQPSK_SUCCESS;
}
#if 1
CSQPSK_Error_t CT202ACheckLockStatus ( CSHDITunerIndex bTunerIndex, int *pnLockStatus )
{
//*pnLockStatus = TRUE;
//return CSQPSK_SUCCESS;
//return;
int nReturn1,nReturn = CSQPSK_SUCCESS;
int nStatus;
u8 szBuffer[3]={0,0,0};
u16 pu16LockStatus;
u8 Locksta = 0;
u8 i = 0;
u8 regs_read, regs_read1, regs_read2, regs_read3;
/*
*pnLockStatus = 1;
return CSQPSK_SUCCESS;*/
//printf("CT202ACheckLockStatus!!!!");
*pnLockStatus = FALSE;
#if 1
for (i = 0; i < 3; i++)
{
GetReg(g_CTK202A[bTunerIndex], LOCK_STATUS_REG_1, &Locksta, 0x01);
if((Locksta & 0x6f) == 0x6f)
{
*pnLockStatus = TRUE;
g_nLockStatus = 1;
g_nReSyncCnt = 0 ;
CT202AManualReSync(bTunerIndex);
return CSQPSK_SUCCESS;
}
else if ((Locksta & 0x40) != 0x40)////AGC not OK,so no signal!!!
{
*pnLockStatus = FALSE;
g_nLockStatus = 0;
CT202AManualReSync(bTunerIndex);
return CSQPSK_SUCCESS;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?