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

📄 drv_8722.c

📁 机顶盒解调芯片DCF8722驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
   //debug_out (TL_INFO, "Strength = %d\n", pCNimCfg->SignalStrength);
   return (DRV_OK);
}


DRV_RETURN dcf872x_print_statics (u_int32 uUnit)
{
   CNIM_CFG    *pCNimCfg = (CNIM_CFG *)(&gCNimCfg);
   
   debug_out (TL_INFO, "======================================\n");
   debug_out (TL_INFO, "   Frequency (Hz) = %d\n", pCNimCfg->SignalFREQ);
   debug_out (TL_INFO, "         QAM Mode = %d\n", pCNimCfg->SignalQAM);
   debug_out (TL_INFO, "SymbolRate (Baud) = %d\n", pCNimCfg->SignalSR);
   if (DEM_LOCKED == pCNimCfg->LockStatus.CurrSYNC)
   {
      debug_out (TL_INFO, "             SYNC = YES\n");
      debug_out (TL_INFO, "   Received Block = %d\n", pCNimCfg->DemodBlkCnt);
      debug_out (TL_INFO, "  Corrected Block = %d\n", pCNimCfg->DemodCorrCnt);
      debug_out (TL_INFO, "Uncorrected Block = %d\n", pCNimCfg->DemodUncorrCnt);
      debug_out (TL_INFO, "              CNE = %d\n", pCNimCfg->DemodCNE);
      debug_out (TL_INFO, "              BER = %f\n", pCNimCfg->DemodBER);
   }
   else
   {
      debug_out (TL_INFO, "             SYNC = NO\n");
   }
   debug_out (TL_INFO, "======================================\n\n");
   return (DRV_OK);
}


/*****************************************************************************/
/*  FUNCTION:    dcf872x_get_lockstatus                                      */
/*                                                                           */
/*  PARAMETERS:  uUnit  - the unit id of the unit to access.                 */
/*               pLocked - pointer to a boolean to indicate the lock status  */
/*                                                                           */
/*  DESCRIPTION: The function get the current lock status.                   */
/*                                                                           */
/*  RETURNS:     DRV_OK if successful, DRV_ERROR if unsuccessful.            */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DRV_RETURN dcf872x_get_lockstatus (u_int32 uUnit, bool *pLocked)
{
   CNIM_CFG   *pCNimCfg = (CNIM_CFG *)(&gCNimCfg);
   
   /* get the lock status of the STV0297 QAM demodulator */
   st0_get_lock_status ((pCNimCfg->DemodAddr), pLocked);
   if (TRUE == *pLocked)
   {
      if (DEM_LOCKED != pCNimCfg->LockStatus.CurrSYNC)
      {
         pCNimCfg->LockStatus.PrevSYNC = pCNimCfg->LockStatus.CurrSYNC;
         pCNimCfg->LockStatus.CurrSYNC = DEM_LOCKED;
      }
   }
   else
   {
      if (DEM_LOCKED == pCNimCfg->LockStatus.CurrSYNC)
      {
         pCNimCfg->LockStatus.PrevSYNC = pCNimCfg->LockStatus.CurrSYNC;
         pCNimCfg->LockStatus.CurrSYNC = DEM_LOCK_LOSS;
         pCNimCfg->LockStatus.uNumLOSS ++;
      }
   }
   return (DRV_OK);
}

/*****************************************************************************/
/*  FUNCTION:    dcf872x_set_symbol_rate                                     */
/*                                                                           */
/*  PARAMETERS:  uUnit  - the unit id of the unit to access.                 */
/*                                                                           */
/*  DESCRIPTION: The function sets THOMSON Cable Front-End DCF8722 to        */
/*               the specified symbol rate (0.87 < SR < 11.7).               */
/*                                                                           */
/*  RETURNS:     DRV_OK if successful, DRV_ERROR if unsuccessful.            */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DRV_RETURN dcf872x_set_symbol_rate (u_int32 uUnit)
{
   CNIM_CFG   *pCNimCfg = (CNIM_CFG *)(&gCNimCfg);
   u_int32     uSymbolRate;
   u_int32     uTemp;
   float       fTemp;
   
   if ( pCNimCfg->SignalSR % 1000 )
   {
      uTemp = pCNimCfg->SignalSR / 1000;
      if (uTemp > 8192L) /* 2^13 */
      {
         uTemp = (uTemp << 18);  /* plus 2^18 */
         uTemp = uTemp / (pCNimCfg->DemodClkExt);
         uTemp = (uTemp << 14);  /* plus 2^14 */
      }
      else if (uTemp > 4096) /* 2^12 */
      {
         uTemp = (uTemp << 19);  /* plus 2^19 */
         uTemp = uTemp / (pCNimCfg->DemodClkExt);
         uTemp = (uTemp << 13);  /* plus 2^13 */
      }
      else if (uTemp > 2048) /* 2^11 */
      {
         uTemp = (uTemp << 20);  /* plus 2^20 */
         uTemp = uTemp / (pCNimCfg->DemodClkExt);
         uTemp = (uTemp << 12);  /* plus 2^12 */
      }
      else if (uTemp > 1024) /* 2^10 */
      {
         uTemp = (uTemp << 21);  /* plus 2^21 */
         uTemp = uTemp / (pCNimCfg->DemodClkExt);
         uTemp = (uTemp << 11);  /* plus 2^11 */
      }
      else if (uTemp > 512) /* 2^9 */
      {
         uTemp = (uTemp << 22);  /* plus 2^22 */
         uTemp = uTemp / (pCNimCfg->DemodClkExt);
         uTemp = (uTemp << 10);  /* plus 2^10 */
      }
      else
      {
         /* Never be here. Symbol rate is error. */
         return (DRV_ERROR);
      }
      uSymbolRate = uTemp;
   }
   else
   {
      fTemp = (float)(pCNimCfg->SignalSR) / (float)(pCNimCfg->DemodClkExt);
      fTemp = (fTemp * 4194304.0) / 1000.0;
      fTemp = fTemp * 1024.0;
      uSymbolRate = (u_int32)(fTemp);
   }
   
   pCNimCfg->DemodSR = uSymbolRate;
   st0_set_symbol_rate ((pCNimCfg->DemodAddr), uSymbolRate);
   return (DRV_OK);
}

/*****************************************************************************/
/*  FUNCTION:    dcf872x_set_freq_sweep                                      */
/*                                                                           */
/*  PARAMETERS:  uUnit  - the unit id of the unit to access.                 */
/*                                                                           */
/*  DESCRIPTION: The function configures the sweep rate & the carrier offset */
/*               for the frequency sweep.                                    */
/*                                                                           */
/*               sweep_value  = R(sweep) * (2^28) / Fs^2  [Fs = symbol rate] */
/*               iphase_value = F(offset) * (2^28) / Fs   [Fs = symbol rate] */
/*                                                                           */
/*  RETURNS:     DRV_OK if successful, DRV_ERROR if unsuccessful.            */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DRV_RETURN dcf872x_set_freq_sweep (u_int32 uUnit)
{
   CNIM_CFG   *pCNimCfg = (CNIM_CFG *)(&gCNimCfg);
   u_int32     uTemp;
   u_int32     uSweepRateValue;
   int32       iIPhaseValue;
   
   uTemp = (pCNimCfg->SignalSR >> 8);  // Fs / 2^8
   
   /* uSweepRateValue should be not less than 0. */
   if (pCNimCfg->iSweepRate < 0)
   {
      uSweepRateValue = ((u_int32)(- pCNimCfg->iSweepRate) << 12);   // 2^12
   }
   else
   {
      uSweepRateValue = ((u_int32)(  pCNimCfg->iSweepRate) << 12);   // 2^12
   }
   
   if(!uTemp)
      return(DRV_ERROR);
   uSweepRateValue = uSweepRateValue / uTemp;   // (KHz/s * 2 ^12) / (Fs / 2^8)
   uSweepRateValue = uSweepRateValue * 1000;    // KHz/s ==> Hz/s
   if(!uTemp)
      return(DRV_ERROR);
   uSweepRateValue = uSweepRateValue / uTemp;   // (Hz/s * 2 ^12) / (Fs / 2^8)^2
   
   /* iIPhaseValue should be not greater than 0. */
   if (pCNimCfg->iCarrierOffset < 0)
   {
      iIPhaseValue = (  pCNimCfg->iCarrierOffset) * 1048576L;  // 2^20
   }
   else
   {
      iIPhaseValue = (- pCNimCfg->iCarrierOffset) * 1048576L;  // 2^20
   }
   
   if(!uTemp)
      return(DRV_ERROR);
   iIPhaseValue = iIPhaseValue / (int32)(uTemp);   // (KHz * 2^20) / (Fs / 2^8)
   iIPhaseValue = iIPhaseValue * 1000;             // KHz ==> Hz
   iIPhaseValue = iIPhaseValue + 0x10000000;       // if (iIPhaseValue < 0)
   iIPhaseValue = (iIPhaseValue & 0x0FFFFFFF);
   
   st0_set_sweep_rate ((pCNimCfg->DemodAddr), uSweepRateValue);
   st0_stl_freeze (pCNimCfg->DemodAddr);
   st0_set_iphase ((pCNimCfg->DemodAddr), iIPhaseValue);
   
   return (DRV_OK);
}

/*****************************************************************************/
/*  FUNCTION:    dcf872x_reinit                                              */
/*                                                                           */
/*  PARAMETERS:  uUnit  - the unit id of the unit to re-initialize.          */
/*                                                                           */
/*  DESCRIPTION: The function re-initializes THOMSON Cable Front-End DCF8722 */
/*                                                                           */
/*  RETURNS:     DRV_OK if successful, DRV_ERROR if unsuccessful.            */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DRV_RETURN dcf872x_reinit (u_int32 uUnit)
{
   CNIM_CFG    *pCNimCfg = (CNIM_CFG *)(&gCNimCfg);
   u_int8      ui8Addr = pCNimCfg->DemodAddr;
   
   /* software reset all internal modules of the demodulator. */
   st0_swreset (ui8Addr);
   /* initialize all demodulator internal registers with default values */
   st0_init_regs (ui8Addr);
   
   /* check the option of the initial quadrature demodulator */
   if ( pCNimCfg->DemodINITDEM == ST0_INITDEM_ENABLE )
   {  /* if the initial quadrature demodulator is enabled, configure it */
      /* NOT IMPLEMENTED */
   }
   else
   {
      st0_disable_initdem (ui8Addr);
   }
   
   /* initialize the WB AGC */
   st0_wbagc_init (ui8Addr);
   /* initialize the PMF AGC */
   st0_pmfagc_init (ui8Addr);
   /* initialize Symbol Timing Loop */
   st0_stl_init (ui8Addr);
   /* initialize Carrier Recovery Loop */
   st0_crl_init (ui8Addr);
   /* initialize Equalizer */
   st0_equ_init (ui8Addr);
   /* initialize FEC */
   st0_fec_init (ui8Addr);
   
   /* initialize the lock status */
   pCNimCfg->LockStatus.PrevSYNC = DEM_NO_LOCKED;
   pCNimCfg->LockStatus.CurrSYNC = DEM_NO_LOCKED;
   pCNimCfg->LockStatus.uNumLOSS = 0;
   
   return (DRV_OK);
}

/*****************************************************************************/
/*  FUNCTION:    dcf872x_connect                                             */
/*                                                                           */
/*  PARAMETERS:  uUnit  - the unit id of the unit to connect.                */
/*               pTuning - pointer to the TUNING_SPEC structure containing   */
/*                         parameters for the requested connection.          */
/*               bForced - if TRUE, to set the parameters is forced.         */
/*                                                                           */
/*  DESCRIPTION: The function connects THOMSON Cable Front-End DCF8722 to    */
/*               the specified signal.                                       */
/*                                                                           */
/*  RETURNS:     DRV_OK if successful, DRV_BAD_SIGNAL if unsuccessful.       */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DRV_RETURN dcf872x_connect (u_int32 uUnit, TUNING_SPEC *pTuning, bool bForced)
{
   CNIM_CFG   *pCNimCfg = (CNIM_CFG *)(&gCNimCfg);
   u_int8      ui8Addr = pCNimCfg->DemodAddr;
   
   /**************************************************************************/
   /*   Check and Store the parameters of the specified signal to be tuned.
    */
   if (TRUE == bForced)
   {
      pCNimCfg->SignalFREQ = pTuning->tune.nim_cable_tune.frequency;
      pCNimCfg->SignalSR = pTuning->tune.nim_cable_tune.symbol_rate;

⌨️ 快捷键说明

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