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

📄 dcf_drv.c

📁 机顶盒解调芯片DCF8722驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************/
/*                   CONEXANT PROPRIETARY AND CONFIDENTIAL                  */
/*                   Conexant Systems Inc. (c) 2007 - 2012                  */
/*                             Shanghai, CHINA                              */
/*                           All Rights Reserved                            */
/****************************************************************************/
/*
 * Filename:      DCF_DRV.C
 *
 * Description:   The file defines API to CABLE HAL
 *
 * Author:        Yong Huang
 *
 ****************************************************************************/
/* $Header: dcf_drv.c, 1, 2007-10-8 13:36:53, Yong Huang$
 * $Id: dcf_drv.c,v 1.0, 2007-10-08 05:36:53Z, Yong Huang$
 ****************************************************************************/

/***************************/
/*      Header Files       */
/***************************/
//#define DCFEXT                         /* forces globals to be static to this function */

#include "dcf_defs.h"
#include "dcf_str.h"
#include "dcf_enum.h"
#include "dcf_reg.h"
#include "dcf_dbg.h"

extern DCF_REGISTER gDemReg[DCF_REG_NUM];

/*****************************************************************************/
/*  FUNCTION:    DCF_DRIVER_Init_Regs                                        */
/*                                                                           */
/*  PARAMETERS:  pNim - pointer to DCF_NIM struct.                           */
/*                                                                           */
/*  DESCRIPTION: This function sets all of STV0297 internal registers        */
/*               with the application default values.                        */
/*                                                                           */
/*  RETURNS:     True if successful, False if unsuccessful.                  */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
bool DCF_DRIVER_Init_Regs(DCF_NIM *pNim)
{
   unsigned char   u8RegData;
   bool            bRetVal;
   unsigned char   u8Index;
	
   /* sanity check */
   if(pNim == NULL)
      return(False);
   
   for(u8Index=0; u8Index < DCF_REG_NUM; u8Index++)
   {
      /* check if the register is read-only */
      if(gDemReg[u8Index].wflag)
      {  /* if the register is writable, set it with default value */
         gDemReg[u8Index].value = gDemReg[u8Index].start;
         u8RegData = gDemReg[u8Index].value;
         bRetVal= DCF_RegWrite(pNim, gDemReg[u8Index].addr, 1, &u8RegData, DCF_DEMOD_I2C);
         if(bRetVal == False)
            return(False);
      }
   }
   return(True);
}

/*****************************************************************************/
/*  FUNCTION:    DCF_DRIVER_Set_Modulation                                   */
/*                                                                           */
/*  PARAMETERS:  pNim - pointer to DCF_NIM struct.                           */
/*               u8Mod - the QAM mode ( 16 / 32 / 64 / 128 / 256 )           */
/*                        or the auto-detect QAM mode                        */
/*                                                                           */
/*  DESCRIPTION: The function sets the QAM mode                              */
/*               by programming the MODE_SELECT bits of EQU_0 register or    */
/*               the bits of CTRL_9 register.                                */
/*                                                                           */
/*  RETURNS:     True if successful, False if unsuccessful.                  */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
bool DCF_DRIVER_Set_Modulation(DCF_NIM *pNim)
{
	unsigned char   u8RegData;
	bool                 bRetVal;
	/* sanity check */
	if(pNim == NULL)
	   return(False);
	
  if(pNim->isAutoQAMMode)
  {
     /* set the MODE_SELECT bits of EQU_0 register to 000b */
     gDemReg[ST0_RID_EQU_0].value &= 0x8F;
     u8RegData = gDemReg[ST0_RID_EQU_0].value;
     bRetVal= DCF_RegWrite(pNim, gDemReg[ST0_RID_EQU_0].addr, 1, &u8RegData, DCF_DEMOD_I2C);
	 
     /* set the CTRL_9 register for the auto-detect QAM mode
       *
       * the AUTO_QAMMODE_SEL bit  = 1b
       * the AUTOCONSTEL_TIMER bit = 0111b
       * the AUTOSTOP_CONSTEL bit  = 1b
       * the AUTOCONSTEL_ON bit    = 1b
        */
         gDemReg[ST0_RID_CTRL_9].value = 0xBE;
         u8RegData = gDemReg[ST0_RID_CTRL_9].value;
         bRetVal= DCF_RegWrite(pNim, gDemReg[ST0_RID_CTRL_9].addr, 1, &u8RegData, DCF_DEMOD_I2C);
  }
  else
  {
	/* 0x00[6:4] */
   gDemReg[ST0_RID_EQU_0].value &= 0x8F;
   gDemReg[ST0_RID_EQU_0].value |= ((pNim->mod_type << 4) & 0x70);
   u8RegData = gDemReg[ST0_RID_EQU_0].value;
   bRetVal= DCF_RegWrite(pNim, gDemReg[ST0_RID_EQU_0].addr, 1, &u8RegData, DCF_DEMOD_I2C);
  }

   return (bRetVal);
}

/*****************************************************************************/
/*  FUNCTION:    DCF_DRIVER_Symb_In                                          */
/*                                                                           */
/*  PARAMETERS:  p_nim - pointer to DCF_NIM struct.                          */
/*                                                                           */
/*  DESCRIPTION: The function unfreeze all blocks that work at symbol rate   */
/*               by programming the PHASE_CLR of the STLOOP_10 register.     */
/*                                                                           */
/*  RETURNS:     True if successful, False if unsuccessful.                  */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
bool DCF_DRIVER_Symb_In(DCF_NIM *pNim, unsigned long * pu32SymbRate)
{
   /* symb_rate[31:0] = 2^32 * (Nominal Symbol Rate) / (Demod Clock Frequency) 
      Demod clock frequency is 28.8MHz. The symbol rate demod can handle is 
      0~28.799963MHz = 2^32 / 149.131Hz */
   
   unsigned long   u32Temp;
   
   /* sanity check */
   if(pNim == NULL)
      return(False);
   
   u32Temp = pNim->symbol_rate_ideal;
   u32Temp /= 1000;
   u32Temp *= 149131UL; /* 149.131 = 2^32 / (demod clock frequency ) */
   
   *pu32SymbRate = u32Temp;
   
   return(True);
}

/*****************************************************************************/
/*  FUNCTION:    DCF_DRIVER_Set_Symbol_Rate                                  */
/*                                                                           */
/*  PARAMETERS:  p_nim - pointer to DCF_NIM struct.                          */
/*               uSymbolRate - a 32-bit symbol timing frequency.             */
/*                                                                           */
/*  DESCRIPTION: The function sets 32-bit symbol timing frequency            */
/*               by programming STLOOP_5 / STLOOP_6 / STLOOP_7 / STLOOP_8    */
/*               register.                                                   */
/*                                                                           */
/*  RETURNS:     True if successful, False if unsuccessful.                  */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
bool DCF_DRIVER_Set_Symbol_Rate(DCF_NIM *pNim, unsigned long u32SymbolRate)
{
   unsigned char   u8RegData;
   bool            bRetVal;
   
   /* sanity check */
   if(pNim == NULL)
      return(False);

   u8RegData = u32SymbolRate & 0xFF;
   gDemReg[ST0_RID_STLOOP_5].value = u8RegData; /* save to CMD to global variable */ 
   bRetVal = DCF_RegWrite(pNim, gDemReg[ST0_RID_STLOOP_5].addr, 1, &u8RegData, DCF_DEMOD_I2C);
   if(bRetVal == False)
   	return(bRetVal);
   
   u8RegData = (u32SymbolRate >> 8) & 0xFF;
   gDemReg[ST0_RID_STLOOP_6].value = u8RegData; /* save to CMD to global variable */ 
   bRetVal = DCF_RegWrite(pNim, gDemReg[ST0_RID_STLOOP_6].addr, 1, &u8RegData, DCF_DEMOD_I2C);
   if(bRetVal == False)
   	return(bRetVal);
   
   u8RegData = (u32SymbolRate >> 16) & 0xFF;
   gDemReg[ST0_RID_STLOOP_7].value = u8RegData; /* save to CMD to global variable */ 
   bRetVal = DCF_RegWrite(pNim, gDemReg[ST0_RID_STLOOP_7].addr, 1, &u8RegData, DCF_DEMOD_I2C);
   if(bRetVal == False)
   	return(bRetVal);
   
   u8RegData = (u32SymbolRate >> 24) & 0xFF;
   gDemReg[ST0_RID_STLOOP_8].value = u8RegData; /* save to CMD to global variable */ 
   bRetVal = DCF_RegWrite(pNim, gDemReg[ST0_RID_STLOOP_8].addr, 1, &u8RegData, DCF_DEMOD_I2C);
   
   return (bRetVal);
}

/*****************************************************************************/
/*  FUNCTION:    DCF_DRIVER_Set_SPEC_INV                                     */
/*                                                                           */
/*  PARAMETERS:  pNim - pointer to DCF_NIM struct.                           */
/*               specinv - option of spectrum inversion.                     */
/*                                                                           */
/*  DESCRIPTION: The function sets the spectrum inversion option             */
/*               by programming the SPEC_INV bit of CTRL_3 register.         */
/*                                                                           */
/*  RETURNS:     True if successful, False if unsuccessful.                  */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
bool DCF_DRIVER_Set_SPEC_INV(DCF_NIM *pNim, DCF_SPECINV specinv)
{
	bool            bRetVal;
	unsigned char   u8RegData;
	
   /* sanity check */
	if(pNim == NULL)
	   return(False);
	   
	/* save spectrum inversion to NIM structure */
	pNim->spec_inv = specinv;
	
	/* write spectrum inversion to DCF */
   if(specinv == DCF_SPEC_INV_ON)
   {
      gDemReg[ST0_RID_CTRL_3].value = gDemReg[ST0_RID_CTRL_3].value | 0x08;
   }
   else
   {
      gDemReg[ST0_RID_CTRL_3].value = gDemReg[ST0_RID_CTRL_3].value & 0xF7;
   }
   
   u8RegData = gDemReg[ST0_RID_CTRL_3].value;
   /* call iic */
   bRetVal = DCF_RegWrite(pNim, gDemReg[ST0_RID_CTRL_3].addr, 1, &u8RegData, DCF_DEMOD_I2C);
   
   return(bRetVal);
}

/*****************************************************************************/
/*  FUNCTION:    DCF_DRIVER_Set_Sweep_Rate                                   */
/*                                                                           */
/*  PARAMETERS:  pNim - pointer to DCF_NIM struct.                           */
/*               uSweep - sweep value                                        */
/*                                                                           */
/*  DESCRIPTION: The function sets sweep value to CRL_0 and CRL_9            */
/*                                                                           */
/*  RETURNS:     True if successful, False if unsuccessful.                  */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
bool DCF_DRIVER_Set_Sweep_Rate(DCF_NIM *pNim, long n32SweepRate)
{
   unsigned char   u8RegData;
   bool            bRetVal;
   long            n32Tmp;

   /* sanity check */
   if(pNim == NULL)
      return(False);

   /* set sweep rate: sweep_value = R(sweep) * (2^28) / Fs^2  [Fs = symbol rate] */
   n32Tmp = (pNim->symbol_rate_ideal >> 8);  /* Fs / 2^8 */
   /* calculate sweep value */
   if(!n32Tmp)
      return(False);

   /* uSweepRateValue should be not less than 0. */
   n32SweepRate = pNim->sweep_rate;
   n32SweepRate = n32SweepRate << 12;
   

⌨️ 快捷键说明

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