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

📄 stv0297.c

📁 机顶盒解调芯片DCF8722驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************/
/*                   CONEXANT PROPRIETARY AND CONFIDENTIAL                  */
/*                   Conexant Systems Inc. (c) 2003 - 2004                  */
/*                            Shanghai, CHINA                               */
/*                          All Rights Reserved                             */
/****************************************************************************/
/*
 * Filename:      STV0297.C
 *
 * Description:   The STV0297 QAM Demodulator IC Driver  is one part of cable
 *                front-end driver. Some cable front-ends use the demodulator
 *                IC to demodulate IF signals and do the FEC processing.
 *
 *                The file contains the functions to read/write registers and
 *                some operation functions,  such as set/get the symbol rate,
 *                set/get two AGC values, etc.
 *
 * Author:        Steven Shen
 *
 ****************************************************************************/
/* $Header: STV0297.C, 2, 2006-4-29 10:22:38, Eric (Feng) Liu$
 * $Id: STV0297.C,v 1.1, 2006-04-29 02:22:38Z, Eric (Feng) Liu$
 ****************************************************************************/

/***************************/
/*       Header Files      */
/***************************/
#include "stbcfg.h"
#include "STV0297.h"
#include "retcodes.h"
#include "iic.h"


#ifndef I2C_BUS_CABLE_FE
#define I2C_BUS_CABLE_FE      (I2C_BUS_0)
#endif


/***************************/
/*    Global Variables     */
/***************************/
extern DEM_REGISTER  gDemReg[DEM_REG_NUM];

/* Variables for C/N estimation */
int32    gST0CN[5][40];

/***************************/
/* Static Global Variables */
/***************************/


/***************************/
/* Static Local Functions  */
/***************************/
static DEM_RETURN st0_set_a_reg (u_int8 ui8Addr, u_int8 ui8Index);
static DEM_RETURN st0_get_a_reg (u_int8 ui8Addr, u_int8 ui8Index);

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#if (0)

static DEM_RETURN st0_set_regs (u_int8 ui8Addr, u_int8 ui8Index, u_int8 ui8Num);
static DEM_RETURN st0_get_regs (u_int8 ui8Addr, u_int8 ui8Index, u_int8 ui8Num);

/*****************************************************************************/
/*  FUNCTION:    st0_set_regs                                                */
/*                                                                           */
/*  PARAMETERS:  ui8Addr  - the i2c slave address for writing.               */
/*               ui8Index - the index of the first register to write in map. */
/*               ui8Num   - the number of data to write.                     */
/*                                                                           */
/*  DESCRIPTION: This function sets the STV0297 internal registers in burst  */
/*               through the I2C bus.                                        */
/*                                                                           */
/*  RETURNS:     DEM_OK if successful, DEM_ERROR if unsuccessful.            */
/*                                                                           */
/*  NOTES:       For burst writing, the index of registers must be continue. */
/*               The data to write are stored in the gobal register map.     */
/*               Please use this function carefully.                         */
/*                                                                           */
/*  CONTEXT:     Can be called from a non-interrupt or an interrupt context. */
/*                                                                           */
/*****************************************************************************/
static DEM_RETURN st0_set_regs (u_int8 ui8Addr, u_int8 ui8Index, u_int8 ui8Num)
{
   IICTRANS    iicTransBuf;
   u_int8      ui8Data[ST0_I2CBF_LEN];
   u_int8      ui8Cmd[ST0_I2CBF_LEN];
   u_int8      i;
   
   /* check the number of data to burst access. */
   if ( ui8Num > ST0_I2CBT_LEN )
   {
      return (DEM_ERROR);
   }
   
   /* setup data and commands for i2c transaction */
   ui8Data[0] = ui8Addr;                  /* i2c slave address - WR */
   ui8Data[1] = gDemReg[ui8Index].addr;   /* base register address */
   ui8Cmd[0]  = IIC_START;
   ui8Cmd[1]  = IIC_DATA;
   for (i=0; i<ui8Num; i++)
   {
      ui8Data[i+2] = gDemReg[ui8Index+i].value;
      ui8Cmd[i+2]  = IIC_DATA;
   }
   ui8Cmd[i+2] = IIC_STOP;
   
   iicTransBuf.dwCount = ui8Num + 3;
   iicTransBuf.pData   = ui8Data;
   iicTransBuf.pCmd    = ui8Cmd;
   if ( iicTransaction(&iicTransBuf, I2C_BUS_CABLE_FE) != TRUE )
   {  /* if the i2c transaction is failed, tell me the reason. */
      /* error code = iicTransBuf.dwError */
      return (DEM_ERROR);
   }
   else
   {
      return (DEM_OK);
   }
}

/*****************************************************************************/
/*  FUNCTION:    st0_get_regs                                                */
/*                                                                           */
/*  PARAMETERS:  ui8Addr  - the i2c slave address for reading.               */
/*               ui8Index - the index of the first register to read in map.  */
/*               ui8Num   - the number of data to read.                      */
/*                                                                           */
/*  DESCRIPTION: This function gets the STV0297 internal registers in burst  */
/*               through the I2C bus.                                        */
/*                                                                           */
/*  RETURNS:     DEM_OK if successful, DEM_ERROR if unsuccessful.            */
/*                                                                           */
/*  NOTES:       For burst reading, the index of registers must be continue. */
/*               The read data are stored in the gobal register map.         */
/*               Please use this function carefully.                         */
/*                                                                           */
/*  CONTEXT:     Can be called from a non-interrupt or an interrupt context. */
/*                                                                           */
/*****************************************************************************/
static DEM_RETURN st0_get_regs (u_int8 ui8Addr, u_int8 ui8Index, u_int8 ui8Num)
{
   IICTRANS    iicTransBuf;
   u_int8      ui8Data[ST0_I2CBF_LEN];
   u_int8      ui8Cmd[ST0_I2CBF_LEN];
   u_int8      i;
   
   /* check the number of data to burst access. */
   if ( ui8Num > ST0_I2CBT_LEN )
   {
      return (DEM_ERROR);
   }
   
   /* phase 1 */
   ui8Data[0] = ui8Addr;                  /* i2c slave address - WR */
   ui8Data[1] = gDemReg[ui8Index].addr;   /* base register address */
   ui8Cmd[0]  = IIC_START;
   ui8Cmd[1]  = IIC_DATA;
   ui8Cmd[2]  = IIC_STOP;
   iicTransBuf.dwCount = 3;
   iicTransBuf.pData   = ui8Data;
   iicTransBuf.pCmd    = ui8Cmd;
   if ( iicTransaction(&iicTransBuf, I2C_BUS_CABLE_FE) != TRUE )
   {  /* if the i2c transaction is failed, tell me the reason. */
      /* error code = iicTransBuf.dwError */
      return (DEM_ERROR);
   }
   
   /* phase 2 */
   ui8Data[0] = ui8Addr + 1;  /* i2c slave address - RD */
   ui8Cmd[0]  = IIC_START;
   for (i=0; i<ui8Num; i++)
   {
      ui8Cmd[i+1]  = IIC_DATA | IIC_ACK;
   }
   ui8Cmd[i]   = IIC_DATA;    /* clear IIC_ACK flag for the last byte */
   ui8Cmd[i+1] = IIC_STOP;
   
   iicTransBuf.dwCount = ui8Num + 2;
   iicTransBuf.pData   = ui8Data;
   iicTransBuf.pCmd    = ui8Cmd;
   if ( iicTransaction(&iicTransBuf, I2C_BUS_CABLE_FE) != TRUE )
   {  /* if the i2c transaction is failed, tell me the reason. */
      /* error code = iicTransBuf.dwError */
      return (DEM_ERROR);
   }
   else
   {  /* if the i2c transaction is successful, copy data into register map */
      for (i=0; i<ui8Num; i++)
      {
         gDemReg[ui8Index+i].value = ui8Data[1+i];
      }
      return (DEM_OK);
   }
}

#endif
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*****************************************************************************/
/*  FUNCTION:    st0_set_a_reg                                               */
/*                                                                           */
/*  PARAMETERS:  ui8Addr  - the i2c slave address for writing.               */
/*               ui8Index - the index of the register to write in map.       */
/*                                                                           */
/*  DESCRIPTION: This function sets one STV0297 internal register            */
/*               through the I2C bus.                                        */
/*                                                                           */
/*  RETURNS:     DEM_OK if successful, DEM_ERROR if unsuccessful.            */
/*                                                                           */
/*  NOTES:       The datum to write is stored in the gobal register map.     */
/*                                                                           */
/*  CONTEXT:     Can be called from a non-interrupt or an interrupt context. */
/*                                                                           */
/*****************************************************************************/
static DEM_RETURN st0_set_a_reg (u_int8 ui8Addr, u_int8 ui8Index)
{
   IICTRANS    iicTransBuf;
   u_int8      ui8Data[ST0_I2CBF_LEN];
   u_int8      ui8Cmd[ST0_I2CBF_LEN];
   
   /* setup data and commands for i2c transaction */
   ui8Data[0] = ui8Addr;                  /* i2c slave address - WR */
   ui8Data[1] = gDemReg[ui8Index].addr;   /* the register address */
   ui8Data[2] = gDemReg[ui8Index].value;  /* the data to write */
   ui8Cmd[0]  = IIC_START;
   ui8Cmd[1]  = IIC_DATA;
   ui8Cmd[2]  = IIC_DATA;
   ui8Cmd[3]  = IIC_STOP;
   
   iicTransBuf.dwCount = 4;
   iicTransBuf.pData   = ui8Data;
   iicTransBuf.pCmd    = ui8Cmd;
   if ( iicTransaction(&iicTransBuf, I2C_BUS_CABLE_FE) != TRUE )
   {  /* if the i2c transaction is failed, tell me the reason. */
      /* error code = iicTransBuf.dwError */
      return (DEM_ERROR);
   }
   else
   {
      return (DEM_OK);
   }
}

/*****************************************************************************/
/*  FUNCTION:    st0_get_a_reg                                               */
/*                                                                           */
/*  PARAMETERS:  ui8Addr  - the i2c slave address for reading.               */
/*               ui8Index - the index of the register to read in map.        */
/*                                                                           */

⌨️ 快捷键说明

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