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

📄 dcf_tua6020.c

📁 机顶盒解调芯片DCF8722驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************/
/*                   CONEXANT PROPRIETARY AND CONFIDENTIAL                  */
/*                   Conexant Systems Inc. (c) 2007 - 2012                  */
/*                             Shanghai, CHINA                              */
/*                           All Rights Reserved                            */
/****************************************************************************/
/*
 * Filename:      DCF_TUNER.C
 *
 * Description:   The file defines communication approach to DEMOD
 *
 * Author:        Yong Huang
 *
 ****************************************************************************/
/* $Header: dcf_tua6020.c, 1, 2007-10-8 13:36:53, Yong Huang$
 * $Id: dcf_tua6020.c,v 1.0, 2007-10-08 05:36:53Z, Yong Huang$
 ****************************************************************************/
#include "dcf.h"

extern DCF_REGISTER gDemReg[DCF_REG_NUM];

/* local function declaration */
static bool TUA_TUNER_DRIVER_Get_Freq(DCF_NIM *pNim, unsigned long *pu32Data);
static bool TUA_TUNER_DRIVER_Set_CP(DCF_NIM *pNim, unsigned char u8CP);
static bool TUA_TUNER_DRIVER_Get_CP(DCF_NIM *pNim, unsigned char *pu8Data);
static bool TUA_TUNER_DRIVER_Set_Step(DCF_NIM *pNim, unsigned long u32Step);

/*****************************************************************************/
/*  FUNCTION:    TUA_DCF_TUNER_Start_I2C_Repeater                            */
/*                                                                           */
/*  PARAMETERS:  pNim - pointer to the DCF_NIM structure                     */
/*                                                                           */
/*  DESCRIPTION: The function enables the i2c repeater for one i2c access    */
/*               by setting the I2CT_EN bit of CTRL_6 register.              */
/*                                                                           */
/*  RETURNS:     True if successful, False if unsuccessful.                  */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
bool TUA_TUNER_DRIVER_Start_I2C_Repeater(DCF_NIM *pNim)
{
   unsigned char   u8RegData;
   bool            bRetVal;
	
   /* set the PRGCLKDIV bits. (the division ratio for the PRGCLK clock) */
   gDemReg[ST0_RID_CTRL_7].value = 0x2B;
   u8RegData = gDemReg[ST0_RID_CTRL_7].value;
   bRetVal = (pNim->BusWrite)(pNim->demod_handle, gDemReg[ST0_RID_CTRL_7].addr, 1, &u8RegData);
   if(bRetVal == False)
      return (bRetVal);
   
   gDemReg[ST0_RID_CTRL_6].value = gDemReg[ST0_RID_CTRL_6].value | 0x80;
   u8RegData = gDemReg[ST0_RID_CTRL_6].value;
   bRetVal = (pNim->BusWrite)(pNim->demod_handle, gDemReg[ST0_RID_CTRL_6].addr, 1, &u8RegData);
   return (bRetVal);
}

/*****************************************************************************/
/*  FUNCTION:    TUA_DCF_TUNER_Stop_I2C_Repeater                             */
/*                                                                           */
/*  PARAMETERS:  pNim - pointer to the DCF_NIM structure                     */
/*                                                                           */
/*  DESCRIPTION: The function disables the i2c repeater for one i2c access   */
/*               by clearing the I2CT_EN bit of CTRL_6 register.             */
/*                                                                           */
/*  RETURNS:     True if successful, False if unsuccessful.                  */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
bool TUA_TUNER_DRIVER_Stop_I2C_Repeater(DCF_NIM *pNim)
{
   unsigned char   uData;
   bool            bRetVal;
	
   /* disable the I2C repeater for one I2C access. */
   gDemReg[ST0_RID_CTRL_6].value = gDemReg[ST0_RID_CTRL_6].value & 0x7F;
   uData = gDemReg[ST0_RID_CTRL_6].value;
   bRetVal = (pNim->BusWrite)(pNim->demod_handle, gDemReg[ST0_RID_CTRL_6].addr, 1, &uData);
   return (bRetVal);
}

/*****************************************************************************/
/*  FUNCTION:    TUA_TUNER_DRIVER_Initialize                                 */
/*                                                                           */
/*  PARAMETERS:  pNim - pointer to the DCF_NIM structure                     */
/*                                                                           */
/*  DESCRIPTION: The function initialize the tuner.                          */
/*                                                                           */
/*  RETURNS:     True if successful, False if unsuccessful.                  */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
bool TUA_TUNER_DRIVER_Initialize(DCF_NIM *pNim)
{
   /* sanity check */
   if(pNim == NULL)
      return(False);

   /* stuff tuner crystal and tuner handle to NIM */
   pNim->tuner.tua6020.tuner_handle = DCF_TUNER_I2C_ADDR;
   
   /* set the tuner output IF in KHz - always 36 MHz */
   pNim->tuner.tua6020.tuner_interm_freq  = 36000;
   /* set the tuner bandwidth in Hz - always 8 MHz */
   pNim->tuner.tua6020.tuner_bw  = 8000000;
   /* set the tuner i2c address to 0xC0 */

   /* initialize the i2c control bytes for tuner */
   pNim->tuner.tua6020.tuner_shadow[0] = 0x00;    /* prog. divider byte 1 */
   pNim->tuner.tua6020.tuner_shadow[1] = 0x00;    /* prog. divider byte 2 */
   pNim->tuner.tua6020.tuner_shadow[2] = 0x86;    /* control byte 1 */
   pNim->tuner.tua6020.tuner_shadow[3] = 0x00;    /* control byte 2 */
   
   /* set the tuner reference frequency (step) - 62500 Hz */
   TUA_TUNER_DRIVER_Set_Step(pNim, DCF_STEP_62500);

   /* set the tuner charge pump current - 50 uA */
   TUA_TUNER_DRIVER_Set_CP(pNim, DCF_TUA_CP_50);
   return(True);
}

/*****************************************************************************/
/*  FUNCTION:    TUA_TUNER_DRIVER_SetFrequency                               */
/*                                                                           */
/*  PARAMETERS:  pCFG - pointer to the CNIM_CFG structure                    */
/*               uFreq - the signal frequency to tune                        */
/*                                                                           */
/*  DESCRIPTION: The function set the tuner to the signal frequency F(IN).   */
/*               N = F(OSC)/F(REF) = F(IN)/F(REF) + F(IF)/F(REF)             */
/*                 = F(IN)/F(REF) + tuner_IF_step                            */
/*                                                                           */
/*  NOTES:       Bandwidth 8 MHz = 128 * 62500, 6 MHz =  96 * 62500, 1M->16  */
/*               Bandwidth 8 MHz = 256 * 31250, 6 MHz = 192 * 31250, 1M->32  */
/*               Bandwidth 8 MHz = 160 * 50000, 6 MHz = 120 * 62500, 1M->20  */
/*                                                                           */
/*  RETURNS:     DRV_OK if successful, DRV_ERROR if unsuccessful.            */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
bool TUA_TUNER_DRIVER_SetFrequency(DCF_NIM *pNim,unsigned long u32freq)
{
   unsigned long   u32Divider;
   unsigned char   u8WaitCount;
   bool            bLocked = False;
   unsigned long   u32Offset;

   /* santity check */
   if(pNim == NULL)
      return(False);
   
   /* calculate the divider and set the tuner's programmable divider. */
   if(pNim->tuner.tua6020.tuner_ref_freq == 0)
      return(False);

   u32Divider = u32freq / (pNim->tuner.tua6020.tuner_ref_freq);
   
   u32Offset  = u32freq % (pNim->tuner.tua6020.tuner_ref_freq);
#if !defined(TOWER_CABLE_TUNER) || (TOWER_CABLE_TUNER==NO)
   if (u32Offset > 30000)
   {  
      /* If the frequency offset is greater than 30KHz, use next frequency. */
      u32Divider ++;
   }
#endif

   u32Divider = u32Divider + (pNim->tuner.tua6020.tuner_IF_step);
   pNim->tuner.tua6020.tuner_shadow[0] = (unsigned char)((u32Divider & 0x00007F00) >> 8);
   pNim->tuner.tua6020.tuner_shadow[1] = (unsigned char)(u32Divider & 0x000000FF);
   
   /* get the tuner actual frequency. (only for debugging) */
   TUA_TUNER_DRIVER_Get_Freq(pNim, &(pNim->tuner.tua6020.tuner_freq));

   /* before setting the new tuner charge pump current, save the old value. */
   TUA_TUNER_DRIVER_Get_CP(pNim, &(pNim->tuner.tua6020.tuner_charge_pump));
   
   /* set the tuner charge pump current */
#if defined(TOWER_CABLE_TUNER) && (TOWER_CABLE_TUNER==YES)
   TUA_TUNER_DRIVER_Set_CP(pNim, DCF_TUA_CP_50);
#else
   TUA_TUNER_DRIVER_Set_CP(pNim, DCF_TUA_CP_220);
#endif

   /* write the configuration bytes to the tuner through the i2c repeater */
   DCF_RegWrite(pNim,0x00,4,pNim->tuner.tua6020.tuner_shadow,DCF_TUNER_I2C);
   
   u8WaitCount = 0;
   /* wait 40ms at most, if tuner does not lock the signal, return flase */
   while(bLocked == False)
   {
      TUA_TUNER_DRIVER_Get_Lock_Status(pNim, &bLocked);
      (pNim->wait)(8);

⌨️ 快捷键说明

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