⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frontend.c

📁 PHILIPS1316 tuner 驱动软件用于PHILIPS TDM1316 DVB-T tuner。经过实际测试。
💻 C
字号:
/**************************************************************************

        (C)Copyright Cheertek Inc. 2002-2004,
           D700, all right reserved.

        Product : STB Firmware

****************************************************************************/

#include <stdio.h>

#include "dvb_type.h"
#include "dvb_sys.h"

#include "winav.h"
#include "w99av.h"
#include "hal.h"
#include "ct210.h"	    
#include "customer.h"

#include "frontend.h"
#include "mt352.h"

static u8 code u8Dummy;

static STnimChannel channel;
static STnimAuxChannelInfo aux;

/*******************************************************************************************/
static bool8 b8InitSuccess=FALSE;
/*******************************************************************************************
Function    : init_frontend()
Description : initial the frontend device
Input       : none
Return      : SUCCESS   : TRUE 
              FAIL      : FALSE
*******************************************************************************************/
bool8 init_frontend(void)
{
	u8	RS_ERRPER = 0xF ;

	{
		struct STnimTunerTable TnimTunerTable;
		extern struct STnimTunerInfo  TnimTunerInfo;
		u16 x;
		u8 *p=(u8*) &g_TheTnim;
		
		for (x=0;x<sizeof(STnimControl);x++)
		{
			*p=0;
			p++;
		}
		g_TheTnim.DeviceID = 30;
		g_TheTnim.NoAutoRSUBC = 1;
		g_TheTnim.NoMDOswap = 1;
		g_TheTnim.pfRegisterRead = (PFRegisterRead)RegisterRead2wb;
		g_TheTnim.pfRegisterWrite = (PFRegisterWrite)RegisterWrite2wb;
		//g_TheTnim.pfEnable= (PFEnable)TestE;
		g_TheTnim.pMilliSeconds= &g_dwClock;
		g_TheTnim.psTunerInfo = &TnimTunerInfo;
		g_TheTnim.psTunerTable = &TnimTunerTable;
	}
	
	if ( Tnim_Initialise(&g_TheTnim)==FALSE )
	{
   		printf(">> Frontend initiate fail\n");    
   		return FALSE;
	}

	b8InitSuccess=TRUE;
	RegisterWrite2wb(g_TheTnim.DeviceID,MT352_RS_ERRPER+1,&RS_ERRPER,1);
    printf(">> Frontend initiate success\n"); 
	return TRUE;
}
/*******************************************************************************************
Function    : set_frontend()
Description : setup the frontend tuner frequency and symbol rate
Input       : u32KHz_tuner_freq ; Tuner frequency (KHz)   
              u8MHzBW			: Bandwidth (MHz)
Return      : SUCCESS           : TRUE 
              FAIL              : FALSE
*******************************************************************************************/
bool8 set_frontend(u32 u32KHz_tuner_freq, u8 u8MHzBW)
{
	printf("set_frontend() %ld KHz %d MHz.\n", u32KHz_tuner_freq, (int)u8MHzBW);
	if ( TnimAcquireFrequency(&g_TheTnim, u32KHz_tuner_freq, u8MHzBW)==FALSE )
	{
		printf("TnimAcquireFrequency() fail.\n");
	}
	if ( Tnim_AcqInit(&g_TheTnim)==FALSE )
	{
		printf("Tnim_AcqInit() fail.\n");
	}
    return TRUE;
}
/*******************************************************************************************
Function    : set_frontend_lnb()
Description : setup the frontend LNB on/off
Input       : lnb               : LNB ON(TRUE)/OFF(FALSE)                 
Return      : SUCCESS           : TRUE 
              FAIL              : FALSE
*******************************************************************************************/
bool8 set_frontend_lnb(bool8 lnb)
{
    u8    GPIO;
    GPIO = ct210_inb(CT210_AddBase+(CT210_GPIO_offset&0xff));
    GPIO &= 0xFE;
	/* the DVB-T anntena power polar is difference */
    if(lnb==TRUE)
        GPIO |= 0x01;
    ct210_outb(CT210_AddBase+CT210_GPIO_offset,GPIO); 
    return TRUE;
}
/*******************************************************************************************
Function    : set_frontend_output()
Description : setup the frontend output type parallel or serial
Input       : output_type       : parallel(TRUE)/serial(FALSE)                 
Return      : SUCCESS           : TRUE 
              FAIL              : FALSE
*******************************************************************************************/
bool8 set_frontend_output(bool8 output_type)
{
    u8    CT210CTRL;
    u8    AUXCTRL;
    
    CT210CTRL = ct210_inb(CT210_AddBase+(CT210_CtrlReg_offset&0xff));
    CT210CTRL &= 0xBF;
    
    AUXCTRL = ct210_inb(CT210_AddBase+(CT210_AuxctrlReg_offset&0xff));
    AUXCTRL &= 0xFE;
    if(output_type)
        AUXCTRL |= 0x01;
    ct210_outb(CT210_AddBase+CT210_AuxctrlReg_offset,AUXCTRL);    


    ct210_outb(CT210_AddBase+CT210_CtrlReg_offset,CT210CTRL);    
	/* TODO */
/*
    if(mt312_output_type(output_type)== MT312_NO_ERROR)
        return TRUE;       
*/
    return FALSE;
    
}
/*******************************************************************************************
Function    : reset_frontend_enable()
Description : start to reset frontend , control HW , set the voltage to Low
Input       : none
Return      : none
*******************************************************************************************/
void reset_frontend_enable(void)
{
#if(HW_VER==DR218_EVB)||(HW_VER==DR212_EVB)
    #ifdef IO_EPP
        Set8032P3(4, 0);
    #else
	    P3 = P3&0xEF ; // set P3.4 low
    #endif	    
#endif

#if ( (HW_VER==DR218_COMBO)||	\
	(HW_VER==DR218_COMBO_V21)||	\
	(HW_VER==DR218_COMBO_V22)||	\
	(HW_VER==DR218_COMBO_V23)||	\
	(HW_VER==DR218_COMBO_V24)||	\
	(HW_VER==DR218_COMBO_V25) )
	{
		extern DWORD __dwHAL1Temp ;
		// set P5.0 Low
		W99AV_OutIndex(0x700000A7); //SFR P5
		__dwHAL1Temp = W99AV_InData() & 0xff;
		__dwHAL1Temp &= ~(0x01) ;
		W99AV_OutIndex(0x700000A7); //SFR P5
		W99AV_OutData(__dwHAL1Temp);//PL
    
		W99AV_OutIndex(0x700000AF); //SFR P5CON
		W99AV_OutData(0x01);  //output mode 	
	}
#endif

/*
#if (HW_VER == DR218_COMBO_V21)
	HAL_WriteGPIO(0x02) ;		// set GPA2 Low
	//HAL_WriteGPIO(0x80|0x02) ;		// set GPA2 High
#endif
*/

}
/*******************************************************************************************
Function    : reset_frontend_disable()
Description : end of reset frontend , control HW , set the voltage to High
Input       : none
Return      : none
*******************************************************************************************/
void reset_frontend_disable(void)
{
#if(HW_VER==DR218_EVB)||(HW_VER==DR212_EVB)
    #ifdef IO_EPP
	    Set8032P3(4, 1) ;
    #else
        P3 = P3|0x10 ;	// setP3.4 high
    #endif	    
#endif

#if ( (HW_VER==DR218_COMBO)||		\
	(HW_VER==DR218_COMBO_V21)||	\
	(HW_VER==DR218_COMBO_V22)||	\
	(HW_VER==DR218_COMBO_V23)||	\
	(HW_VER==DR218_COMBO_V24)||	\
	(HW_VER==DR218_COMBO_V25) )
	{
		extern DWORD __dwHAL1Temp ;
		// set P5.0 High
		W99AV_OutIndex(0x700000A7); //SFR P5
		__dwHAL1Temp = W99AV_InData() & 0xff;
		__dwHAL1Temp |= (0x01) ;
		W99AV_OutIndex(0x700000A7); //SFR P5
		W99AV_OutData(__dwHAL1Temp);//PL
    
		W99AV_OutIndex(0x700000AF); //SFR P5CON
		W99AV_OutData(0x01);  //output mode 	
	}
#endif

/*
#if (HW_VER == DR218_COMBO_V21)
	//HAL_WriteGPIO(        0x02) ;	// set GPA2 Low
	HAL_WriteGPIO(0x80|0x02) ;		// set GPA2 High
#endif
*/

}
/*******************************************************************************************
Function    : reset_frontend()
Description : reset frontend
Input       : none
Return      : none
*******************************************************************************************/    
void reset_frontend(void)
{
}
/*******************************************************************************************
Function    : check_frontend_state()
Description : check frontend lock or unlock
Input       : none
Return      : UNLOCK    : FRONTEND_UNLOCK (0)
              QPSK LOCK : FRONTEND_QPSK_LOCK (1)
              FEC LOCK  : FRONTEND_FEC_LOCK (2)
*******************************************************************************************/
// just return FEC lock or not
FRONTEND_STATUS check_frontend_state(void)
{    
    u8 status ;

	if ( b8InitSuccess==FALSE )
		return FRONTEND_UNLOCK;

	if ( Tnim_IsLocked(&g_TheTnim)==TRUE )
	{
//		printf("LOCK\n");
		return FRONTEND_FEC_LOCK;
	}
//	printf("Unlock\n");
	return FRONTEND_UNLOCK;
}

static u8 u8TrnSNRx8ToLevel(u8 u8SNRx8)
{
/*
dB   0    13   17   21   28   OO
Val  0   104  136  168  224  255
Lev  0    10   40   80   95  100    
*/

/*
dB   0     5   10   21   28   OO
Val  0    40   80  168  224  255
Lev  0    10   40   80   95  100    
*/

	u32 u32SNRx8, u32SNRLevel;

    u32SNRx8=u8SNRx8;
    if (	   u8SNRx8>= 0 && u8SNRx8<= 40 ) /* level 0-10 */
    {
        u32SNRLevel= 0+(u32SNRx8-  0)*( 10- 0)/( 40-  0);
    }else if ( u8SNRx8> 40 && u8SNRx8<= 80 )/* level 10-40 */
    {
        u32SNRLevel=10+(u32SNRx8- 40)*( 40-10)/( 80- 40);
    }else if ( u8SNRx8> 80 && u8SNRx8<=168 )/* level 40-80 */
    {
        u32SNRLevel=40+(u32SNRx8- 80)*( 80-40)/(168- 80);
    }else if ( u8SNRx8>168 && u8SNRx8<=224 )/* level 80-95 */
    {
        u32SNRLevel=80+(u32SNRx8-168)*( 95-80)/(224-168);
    }else if ( u8SNRx8>224 && u8SNRx8<=255 )/* level 95-100 */
    {
        u32SNRLevel=95+(u32SNRx8-224)*(100-95)/(255-224);
    }else
    {
        u32SNRLevel=0;
    }
    if ( u32SNRLevel>100 )
    {
        u32SNRLevel=100;
    }
    return (u8)(u32SNRLevel);
}


/*******************************************************************************************
Function    : get_frontend_quality()
Description : Get the frontend SNR 
Input       : none
Return      : quality value 0 - 100
*******************************************************************************************/
u8 get_frontend_quality(void)
{    
    u8    u8Quality;

	if ( b8InitSuccess==FALSE )
		return 0;
	if ( Tnim_IsLocked(&g_TheTnim)==TRUE )
	{
		u8Quality=TnimReadSNRx8(&g_TheTnim);
//		printf("SNRx8=%d.\n", (int)u8Quality ); 
		u8Quality=u8TrnSNRx8ToLevel(u8Quality);
//		printf("quality=%d.\n", (int)u8Quality ); 
	}else
	{
		u8Quality=0;
	}
    return u8Quality; 
}
/*******************************************************************************************
Function    : get_frontend_strength()
Description : Get the frontend SNR 
Input       : none
Return      : SS Value 0 - 100
*******************************************************************************************/
u8 get_frontend_strength(void)
{
	if ( b8InitSuccess==FALSE )
		return 0;

//    get_frequency_offset();
	return mt352_get_ss();
}

/*******************************************************************************************
Function    : read_frontend_reg()
Description : read the frontend device register
Input       : Address       : Register Address
Return      : none
*******************************************************************************************/
void read_frontend_reg(u8 Address)
{
}
/*******************************************************************************************
Function    : write_frontend_reg()
Description : write the frontend device register
Input       : Address       : Register Address
              Value         : write data
Return      : none
*******************************************************************************************/
void write_frontend_reg(u8 Address,u8 Value)
{
}
/*******************************************************************************************
Function    : show_frontend_regs()
Description : show all register of the frontend device 
Input       : none
Return      : none
*******************************************************************************************/
void show_frontend_regs(void)
{
	Show_Status();
}

/*******************************************************************************************
Function    : get_frequency_offset()
Description : get the frequency offset 
Input       : none
Return      : none
*******************************************************************************************/
s32 get_frequency_offset(void)
{
	s32 s32Offset;
	if ( Tnim_ReadOffsetkHz(&g_TheTnim, &s32Offset)==FALSE )
		return 0;
	printf("Offset %d KHz\n", s32Offset);
	return s32Offset;
}

bool8 get_COFDM_parameter(DVB_COFDMParameters *pstParameter)
{

	TnimReadChannel(&g_TheTnim, &channel, &aux);

	switch( TPS_CONSTELLATION(aux.wTPS) )
	{
	case 0:
		pstParameter->enConstellation=EN_QPSK; break;
	case 1:
		pstParameter->enConstellation=EN_QAM16; break;
	case 2:
		pstParameter->enConstellation=EN_QAM64; break;
	default:
		pstParameter->enConstellation=EN_QPSK_ERR; break;
	}
	switch( TPS_HIERARCHY(aux.wTPS) )
	{
	case 0:
		pstParameter->enHierarchy=EN_HIERARCHY_NON; break;
	case 1:
		pstParameter->enHierarchy=EN_HIERARCHY_1; break;
	case 2:
		pstParameter->enHierarchy=EN_HIERARCHY_2; break;
	case 3:
		pstParameter->enHierarchy=EN_HIERARCHY_4; break;
	default:
		pstParameter->enHierarchy=EN_HIERARCHY_ERR; break;
	}
	switch( TPS_HPCODERATE(aux.wTPS) )
	{
	case 0:
		pstParameter->enHPCodeRate=EN_FEC_1_2; break;
	case 1:
		pstParameter->enHPCodeRate=EN_FEC_2_3; break;
	case 2:
		pstParameter->enHPCodeRate=EN_FEC_3_4; break;
	case 3:
		pstParameter->enHPCodeRate=EN_FEC_5_6; break;
	case 4:
		pstParameter->enHPCodeRate=EN_FEC_7_8; break;
	default:
		pstParameter->enHPCodeRate=EN_FEC_ERR; break;
	}
	switch( TPS_LPCODERATE(aux.wTPS) )
	{
	case 0:
		pstParameter->enLPCodeRate=EN_FEC_1_2; break;
	case 1:
		pstParameter->enLPCodeRate=EN_FEC_2_3; break;
	case 2:
		pstParameter->enLPCodeRate=EN_FEC_3_4; break;
	case 3:
		pstParameter->enLPCodeRate=EN_FEC_5_6; break;
	case 4:
		pstParameter->enLPCodeRate=EN_FEC_7_8; break;
	default:
		pstParameter->enLPCodeRate=EN_FEC_ERR; break;
	}
	switch( TPS_GUARDINTERVAL(aux.wTPS) )
	{
	case 0:
		pstParameter->enGI=EN_GI_1_32;	break;
	case 1:
		pstParameter->enGI=EN_GI_1_16;	break;
	case 2:
		pstParameter->enGI=EN_GI_1_8;	break;
	case 3:
		pstParameter->enGI=EN_GI_1_4;	break;
	default:
		pstParameter->enGI=EN_GI_ERR;	break;
	}

	if ( TPS_FFTMODE8K(aux.wTPS) )
	{
		pstParameter->enFFT=EN_FFT_8K;
	}else
	{
		pstParameter->enFFT=EN_FFT_2K;
	}
	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -