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

📄 stv0297.c

📁 机顶盒解调芯片DCF8722驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
/*  DESCRIPTION: This function gets one STV0297 internal register            */
/*               through the I2C bus.                                        */
/*                                                                           */
/*  RETURNS:     DEM_OK if successful, DEM_ERROR if unsuccessful.            */
/*                                                                           */
/*  NOTES:       The read datum is stored in the gobal register map.         */
/*                                                                           */
/*  CONTEXT:     Can be called from a non-interrupt or an interrupt context. */
/*                                                                           */
/*****************************************************************************/
static DEM_RETURN st0_get_a_reg (u_int8 ui8Addr, u_int8 ui8Index)
{
   IICTRANS    iicTransBuf;
   u_int8      ui8Data[ST0_I2CBF_LEN];
   u_int8      ui8Cmd[ST0_I2CBF_LEN];
   
   /* 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;
   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);
   }
   else
   {  /* if the i2c transaction is successful, copy data into register map */
      gDemReg[ui8Index].value = ui8Data[1];
      return (DEM_OK);
   }
}

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

/*****************************************************************************/
/*  FUNCTION:    st0_init_regs                                               */
/*                                                                           */
/*  PARAMETERS:  i2cAddr  - the i2c address for accessing STV0297 registers. */
/*                                                                           */
/*  DESCRIPTION: This function sets all of STV0297 internal registers        */
/*               with the application default values.                        */
/*                                                                           */
/*  RETURNS:     DEM_OK if successful, DEM_ERROR if unsuccessful.            */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DEM_RETURN st0_init_regs (u_int8 i2cAddr)
{
   u_int8      ui8Index;
   
   for (ui8Index=0; ui8Index<(DEM_REG_NUM); ui8Index++)
   {
      /* check if the register is read-only */
      if ( gDemReg[ui8Index].wflag )
      {  /* if the register is writable, set it with default value */
         gDemReg[ui8Index].value = gDemReg[ui8Index].start;
         st0_set_a_reg( i2cAddr, ui8Index);
      }
   }
   return (DEM_OK);
}

/*****************************************************************************/
/*  FUNCTION:    st0_catch_regs                                              */
/*                                                                           */
/*  PARAMETERS:  i2cAddr  - the i2c address for accessing STV0297 registers. */
/*                                                                           */
/*  DESCRIPTION: This function gets all values of STV0297 internal registers */
/*               and stores them into the register map. (ONLY FOR DEBUG)     */
/*                                                                           */
/*  RETURNS:     DEM_OK if successful, DEM_ERROR if unsuccessful.            */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DEM_RETURN st0_catch_regs (u_int8 i2cAddr)
{
   u_int8      ui8Index;
   
   for (ui8Index=0; ui8Index<(DEM_REG_NUM); ui8Index++)
   {
      st0_get_a_reg( i2cAddr, ui8Index);
      gDemReg[ui8Index].resv3 = gDemReg[ui8Index].value;
   }
   return (DEM_OK);
}

/*****************************************************************************/
/*  FUNCTION:    st0_store_regs                                              */
/*                                                                           */
/*  PARAMETERS:  i2cAddr  - the i2c address for accessing STV0297 registers. */
/*                                                                           */
/*  DESCRIPTION: This function stores all current values of STV0297 internal */
/*               registers into the register map.                            */
/*                                                                           */
/*  RETURNS:     DEM_OK if successful, DEM_ERROR if unsuccessful.            */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DEM_RETURN st0_store_regs (u_int8 i2cAddr)
{
   u_int8      ui8Index;
   
   for (ui8Index=0; ui8Index<(DEM_REG_NUM); ui8Index++)
   {
      gDemReg[ui8Index].store = gDemReg[ui8Index].value;
   }
   return (DEM_OK);
}

/*****************************************************************************/
/*  FUNCTION:    st0_reload_regs                                             */
/*                                                                           */
/*  PARAMETERS:  i2cAddr  - the i2c address for accessing STV0297 registers. */
/*                                                                           */
/*  DESCRIPTION: This function reloads all of STV0297 internal registers     */
/*               with the stored values.                                     */
/*                                                                           */
/*  RETURNS:     DEM_OK if successful, DEM_ERROR if unsuccessful.            */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DEM_RETURN st0_reload_regs (u_int8 i2cAddr)
{
   u_int8      ui8Index;
   
   for (ui8Index=0; ui8Index<(DEM_REG_NUM); ui8Index++)
   {
      if ( gDemReg[ui8Index].wflag )
      {
         gDemReg[ui8Index].value = gDemReg[ui8Index].store;
         st0_set_a_reg( i2cAddr, ui8Index);
      }
   }
   return (DEM_OK);
}

/*****************************************************************************/
/*  FUNCTION:    st0_swreset                                                 */
/*                                                                           */
/*  PARAMETERS:  i2cAddr  - the i2c address for accessing STV0297 registers. */
/*                                                                           */
/*  DESCRIPTION: This function resets most of STV0297 QAM demodulator        */
/*               by programming the SOFT_RESET bit of CTRL_0 register.       */
/*               However, blocks that can be individually reset under        */
/*               software control are not affected, such as EQ, RS, DI.      */
/*               The S/W reset is same as grounding pin NRESET of STV0297.   */
/*                                                                           */
/*  RETURNS:     DEM_OK if successful, DEM_ERROR if unsuccessful.            */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DEM_RETURN st0_swreset (u_int8 i2cAddr)
{
   /* forces most of the chip to reset by setting SOFT_RESET bit. */
   gDemReg[ST0_RID_CTRL_0].value = 0x01;
   st0_set_a_reg( i2cAddr, ST0_RID_CTRL_0);
   /* goes out of reset by clearing SOFT_RESET bit. */
   gDemReg[ST0_RID_CTRL_0].value = 0x00;
   st0_set_a_reg( i2cAddr, ST0_RID_CTRL_0);
   return (DEM_OK);
}

/*****************************************************************************/
/*  FUNCTION:    st0_rs_swreset                                              */
/*                                                                           */
/*  PARAMETERS:  i2cAddr  - the i2c address for accessing STV0297 registers. */
/*                                                                           */
/*  DESCRIPTION: This function resets R-S block of STV0297 QAM demodulator   */
/*               by programming the RESET_RS bit of CTRL_3 register.         */
/*                                                                           */
/*  RETURNS:     DEM_OK if successful, DEM_ERROR if unsuccessful.            */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DEM_RETURN st0_rs_swreset (u_int8 i2cAddr)
{
   gDemReg[ST0_RID_CTRL_3].value = gDemReg[ST0_RID_CTRL_3].value | 0x10;
   st0_set_a_reg( i2cAddr, ST0_RID_CTRL_3);
   gDemReg[ST0_RID_CTRL_3].value = gDemReg[ST0_RID_CTRL_3].value & 0xEF;
   st0_set_a_reg( i2cAddr, ST0_RID_CTRL_3);
   return (DEM_OK);
}

/*****************************************************************************/
/*  FUNCTION:    st0_di_swreset                                              */
/*                                                                           */
/*  PARAMETERS:  i2cAddr  - the i2c address for accessing STV0297 registers. */
/*                                                                           */
/*  DESCRIPTION: The function reset deinterleaver, descrambler sync detector */
/*               and deinterleaver sync detector of STV0297 QAM demodulator  */
/*               by programming the RESET_DI bit of CTRL_1 register.         */
/*                                                                           */
/*  RETURNS:     DEM_OK if successful, DEM_ERROR if unsuccessful.            */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DEM_RETURN st0_di_swreset (u_int8 i2cAddr)
{
   gDemReg[ST0_RID_CTRL_1].value = gDemReg[ST0_RID_CTRL_1].value | 0x01;
   st0_set_a_reg( i2cAddr, ST0_RID_CTRL_1);
   gDemReg[ST0_RID_CTRL_1].value = gDemReg[ST0_RID_CTRL_1].value & 0xFE;
   st0_set_a_reg( i2cAddr, ST0_RID_CTRL_1);
   return (DEM_OK);
}

/*****************************************************************************/
/*  FUNCTION:    st0_get_ver                                                 */
/*                                                                           */
/*  PARAMETERS:  i2cAddr  - the i2c address for accessing STV0297 registers. */
/*               pData    - the pointer to the data of version information.  */
/*                                                                           */
/*  DESCRIPTION: The function get the STV0297 chip version information       */
/*               by reading the VERSION bits of CTRL_0 register.             */
/*                                                                           */
/*  RETURNS:     DEM_OK if successful, DEM_ERROR if unsuccessful.            */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DEM_RETURN st0_get_ver (u_int8 i2cAddr, u_int8 *pData)
{
   /* read the internal register */
   st0_get_a_reg( i2cAddr, ST0_RID_CTRL_0);
   /* get the chip version information */

⌨️ 快捷键说明

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