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

📄 tuner.c

📁 数字高频头的驱动程序,对做DVD,TV的开发人员是好的例子
💻 C
字号:
//============================================================================
//  File Name: newtuner.c
//
//  (c) Copyright [2003] Cirrus Logic Inc. All rights reserved
//  
//  This source code is Cirrus Logic, Inc. proprietary and confidential 
//  information
//  
//  Description:
//      Device driver for FQ1216L newtuner
//  
//  Modification History:
//      $Id: tuner.c,v 1.1 2005/05/10 10:34:18 michaell Exp $
//      $Log: tuner.c,v $
//      Revision 1.1  2005/05/10 10:34:18  michaell
//      merge 2.6 into head, stage 4
//
//      Revision 1.1  2005/04/09 00:42:02  xjwang
//      Add cr1-b target & BSP
//
//      Revision 1.1  2005/01/18 05:46:55  zhiguotao
//      add tcsn9082 tuner
//
//      Revision 1.1.1.1  2004/12/17 20:11:51  xjwang
//      Created for Simplified GUI project
//
//      Revision 1.5  2004/11/03 06:45:16  zhiguotao
//      bug_28158
//
//      Revision 1.4  2004/09/21 01:17:10  xjwang
//      Merge with Sonata2 HEAD 09192004
//
//      Revision 1.17  2004/09/17 20:19:33  haluk
//      21787
//
//      Revision 1.16  2004/07/21 21:08:13  haluk
//      Bug 22444
//
//      Revision 1.15  2004/05/21 06:48:32  akipnis
//      Merge into head 20040520
//
//      Revision 1.14.18.2  2004/05/17 22:40:08  haluk
//      fixed 18967
//
//      Revision 1.14.18.1  2004/05/12 22:13:21  haluk
//      fixed 18725
//
//      Revision 1.14  2004/03/11 20:02:21  haluk
//      fixed US channel tables
//
//      Revision 1.13  2004/02/28 21:33:14  haluk
//      vps emulation
//
//      Revision 1.12  2004/02/27 23:13:43  haluk
//      channel names for Europe
//
//      Revision 1.11  2004/02/24 21:36:21  haluk
//      iport vps pdc cc merge
// 
// 
//
//============================================================================

#define  DEBUG_CPU	2
#include "eromdbg.h"
#include "apitypes.h"
#include "osapi.h"
#include "tuner.h"

#include "apii2c.h"
#include "video_decoder.h"
#include "bsp_av.h"
#include "formatdetection.h"
#include "assert.h"

#include "tuner.h"
#include "apiconfig.h"

#define I2C_TUNER_ADDR	                   (     0xC0)
#define I2C_TUNER_IF_ADDR	               (     0x86)

#define TUNER_FREQ_STEP_VALUE              (    62500)

#define LOWBAND_MIDBAND_LIMIT              (130250000) //127250000~133250000
#define MIDBAND_HIGHBAND_LIMIT             (363250000) //361250000~367250000

#define TUNER_DBG(fmt, args...)		 //{ ERomPrintFunc(0, fmt, ## args); }

//----------------------------------------------------------------------------
//LOCAL VARIABLES
//----------------------------------------------------------------------------

#if (USE_SYS_M_TUNER != 0)
static Uint32          tuner_if  =  45750000;
static Uint32          tuner_min =  51050000; //55250000;
static Uint32          tuner_max = 805250000; //801250000
static TUNER_SYSTEM    tuner_std = TUNER_SYSTEM_NTSC_M_BTSC;
static Uint32          tuner_frq = 61250000;
#else
static Uint32          tuner_if  =  38900000;
static Uint32          tuner_min =  44900000;
static Uint32          tuner_max = 860900000;
static TUNER_SYSTEM    tuner_std = TUNER_SYSTEM_BG_PAL_A2;
static Uint32          tuner_frq = 55250000;
#endif

//----------------------------------------------------------------------------
// TUNER DRIVER INTERFACE
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
//  Function:
TUNER_ERROR TunerInitIF (
//  
//  Description:
//  setup IF for new standard and resets PLL      
//
//  
//  Parameters:
        TUNER_SYSTEM     std,  //video std
		Uint32           freq  //video carrier in HZ
)
//
//  Returns: TUNER_ERROR
//      TUNER_SUCCESS: If succesfull
//      
//----------------------------------------------------------------------------
{
	return TUNER_SUCCESS;
}

//----------------------------------------------------------------------------
//  Function:
TUNER_ERROR TunerSetPLL (
//  
//  Description:
//  setup PLL      
//
//  
//  Parameters:
		Uint32           freq  //video carrier in HZ
)
//
//  Returns: TUNER_ERROR
//      TUNER_SUCCESS: If succesfull
//      
//----------------------------------------------------------------------------
{//set pll parameters
	Uint32 osc;
	Uint16 pll;
	Uint8  data[4];

/*	FOSC = FRF  + FIF */
	osc  = freq + tuner_if;
/*  pll divider value*/
	pll  = osc / TUNER_FREQ_STEP_VALUE;

	data[0] = (Uint8) ((pll >> 8) & 0xff);
	data[1] = (Uint8) ((pll >> 0) & 0xff);
	data[2] = 0xc6;

	if(freq < tuner_min)
	{//too low
		TUNER_DBG("<TunerSetPLL> freq err\n");
		return TUNER_FREQ_ERROR;
	}
	else if (freq < LOWBAND_MIDBAND_LIMIT)
	{//lowband
		data[3]   = 0x1;
		tuner_frq = freq;
	}
	else if (freq < MIDBAND_HIGHBAND_LIMIT)
	{//midband
		data[3]   = 0x2;
		tuner_frq = freq;
	}
	else if (freq < tuner_max)
	{//highband
		data[3]   = 0x8;
		tuner_frq = freq;
	}
	else
	{//too high
		TUNER_DBG("<TunerSetPLL> freq err\n");
		return TUNER_FREQ_ERROR;
	}

	TUNER_DBG("<TunerSetPLL> search %d -> %2x %2x %2x %2x\n", freq, data[0], data[1], data[2], data[3]);

	if(API_SendSeqI2C((Byte)I2C_TUNER_ADDR, 4, &data[0]) != SUCCESS)
	{
		TUNER_DBG("<TunerSetPLL> comm err\n");
		return TUNER_COMM_ERROR;
	}

	return TUNER_SUCCESS;
}


//----------------------------------------------------------------------------
//  Function:
TUNER_ERROR TunerGetAFC (
//  
//  Description:
//  retreives AFC level      
//
//  
//  Parameters:
		TUNER_AFC   *afc  //afc level
)
//
//  Returns: TUNER_ERROR
//      TUNER_SUCCESS: If succesfull
//      
//----------------------------------------------------------------------------
{//get afc level
	/*Uint8	afclevel;
	int status;

	status = API_GetSeqI2C((Byte)I2C_TUNER_IF_ADDR, 1, &afclevel);

	if( (status != SUCCESS) || ((afclevel & 0x1) != 0) )
	{//err
		status = API_GetSeqI2C((Byte)I2C_TUNER_IF_ADDR, 1, &afclevel);

		if( (status != SUCCESS) || ((afclevel & 0x1) != 0) )
		{//retry
			TUNER_DBG("<TunerGetAFC> comm err\n");

			*afc = TUNER_AFC_OPTIMAL;
			return TUNER_COMM_ERROR;
		}
	}

	afclevel = (afclevel >> 1) & 0xf;

	if(afclevel == 0)
	{
		*afc = TUNER_AFC_OPTIMAL;
	}
	else if(afclevel <= 7)
	{//4bit signed pos
		*afc = TUNER_AFC_HIGH;
	}
	else
	{//4bit signed neg
		*afc = TUNER_AFC_LOW;
	}*/

	return TUNER_SUCCESS;
}

//----------------------------------------------------------------------------
//  Function:
TUNER_ERROR TunerGetHLock (
//  
//  Description:
//  retreives HLOCK status      
//
//  
//  Parameters:
		Boolean     *lock //horizontal lock
)
//
//  Returns: TUNER_ERROR
//      TUNER_SUCCESS: If succesfull
//      
//----------------------------------------------------------------------------
{//get horizontal lock
	video_decoder_result_type       status;
	video_decoder_signal_lock_type  locklevel;

	status = video_decoder_signal_lock_status_get(&locklevel);

	if(status != VIDEO_DECODER_RESULT_SUCCESS)
	{
		status = video_decoder_signal_lock_status_get(&locklevel);
		if(status != VIDEO_DECODER_RESULT_SUCCESS)
		{
			TUNER_DBG("<TunerGetHLock> comm err\n");
			*lock = FALSE;
			return TUNER_COMM_ERROR;
		}
	}

	if(locklevel != VIDEO_DECODER_SIGNAL_LOCK_NONE)
	{
		*lock = TRUE;
	}
	else
	{
		*lock = FALSE;
	}

	return TUNER_SUCCESS;
}

//----------------------------------------------------------------------------
//  Function:
TUNER_ERROR TunerDelay (
//  
//  Description:
//  delays between PLL settings and status checks
//
//  
//  Parameters:
		Boolean     jumped //jumped to different freq or iterating
)
//
//  Returns: TUNER_ERROR
//      TUNER_SUCCESS: If succesfull
//      
//----------------------------------------------------------------------------
{
	if(jumped == TRUE)
	{
		OS_TaskDelay(10);
	}
	else
	{
		OS_TaskDelay(5);
	}

	return TUNER_SUCCESS;
}

//----------------------------------------------------------------------------
//  Function:
TUNER_ERROR TunerInit(
//  
//  Description:
//      inits tuner
//  
//  Parameters:
        void
)
//
//  Returns: TUNER_ERROR
//      TUNER_SUCCESS: If succesfull
//      
//----------------------------------------------------------------------------
{
	return(TunerInitIF(tuner_std,  tuner_frq));
}


//----------------------------------------------------------------------------
//  Function:
TUNER_ERROR TunerGetProperties(
//  
//  Description:
//      retreives tuner limits
//  
//  Parameters:
        Uint32          *step_size,
		Uint32          *min_freq,
		Uint32          *max_freq,
		TUNER_SYSTEM    *tuner_sys
)
//
//  Returns: TUNER_ERROR
//      TUNER_SUCCESS: If succesfull
//      
//----------------------------------------------------------------------------
{
	*step_size = TUNER_FREQ_STEP_VALUE;
	*min_freq  = tuner_min;
	*max_freq  = tuner_max;
	*tuner_sys = tuner_std;

	return TUNER_SUCCESS;
}


⌨️ 快捷键说明

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