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

📄 drv_8722.c

📁 机顶盒解调芯片DCF8722驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
      pCNimCfg->SignalQAM = pTuning->tune.nim_cable_tune.modulation;
      pCNimCfg->SignalAutoSP = pTuning->tune.nim_cable_tune.auto_spectrum;
      pCNimCfg->SignalSI = pTuning->tune.nim_cable_tune.spectrum;
      
      pCNimCfg->TunerFlag = 0x01;
      pCNimCfg->DemodFlag = 0x07;
   }
   else
   {
      pCNimCfg->TunerFlag = 0x00;
      pCNimCfg->DemodFlag = 0x00;
      
      /* check the Annex mode, ITU-J83 Annex mode must be always ANNEX_A */
      if ( pTuning->tune.nim_cable_tune.annex != ANNEX_A )
      {
         return (DRV_BAD_SIGNAL);
      }
      
      pCNimCfg->SignalAutoSP = pTuning->tune.nim_cable_tune.auto_spectrum;
      
      /* check the signal frequency */
      if ( pTuning->tune.nim_cable_tune.frequency != pCNimCfg->SignalFREQ )
      {  /* if the frequency of the signal to be tuned is different. */
         /* store the new frequency */
         pCNimCfg->SignalFREQ = pTuning->tune.nim_cable_tune.frequency;
         /* set the changing flag */
         pCNimCfg->TunerFlag = 0x01;
      }
      /* check the QAM size */
      if ( pTuning->tune.nim_cable_tune.modulation != pCNimCfg->SignalQAM )
      {  /* if the QAM size of the signal to be tuned is different. */
         /* store the new QAM size */
         pCNimCfg->SignalQAM = pTuning->tune.nim_cable_tune.modulation;
         /* set the changing flag */
         pCNimCfg->DemodFlag |= 0x01;
      }
      /* check the symbol rate */
      if ( pTuning->tune.nim_cable_tune.symbol_rate != pCNimCfg->SignalSR )
      {  /* if the symbol rate of the signal to be tuned is different. */
         /* store the new symbol rate */
         pCNimCfg->SignalSR = pTuning->tune.nim_cable_tune.symbol_rate;
         /* set the changing flag */
         pCNimCfg->DemodFlag |= 0x02;
      }
      /* check the spectrum inversion option */
      if ( pTuning->tune.nim_cable_tune.spectrum != pCNimCfg->SignalSI )
      {  /* if the spectrum inversion option is different. */
         /* store the new spectrum inversion option */
         pCNimCfg->SignalSI = pTuning->tune.nim_cable_tune.spectrum;
         /* set the changing flag */
         pCNimCfg->DemodFlag |= 0x04;
      }
   }
   
   /*
   debug_out (TL_INFO, "CONNECT Param: freq    = %d\n", pCNimCfg->SignalFREQ);
   debug_out (TL_INFO, "CONNECT Param: QAM     = %d\n", pCNimCfg->SignalQAM);
   debug_out (TL_INFO, "CONNECT Param: sym rate= %d\n", pCNimCfg->SignalSR);
   debug_out (TL_INFO, "CONNECT Param: auto_sp = %d\n", pCNimCfg->SignalAutoSP);
   debug_out (TL_INFO, "CONNECT Param: spec inv= %d\n", pCNimCfg->SignalSI);
   debug_out (TL_INFO, "CONNECT Param: annex   = %d\n", pCNimCfg->SignalAnnex);
   */
   
   /**************************************************************************/
   /*   Check the changing flag and Apply the new parameters of the signal.
    */
   if (pCNimCfg->TunerFlag)
   {  /* if the tuner frequency needs change, set tuner to the new frequency.
       */
      dcf872x_tuner_set_freq (pCNimCfg, pCNimCfg->SignalFREQ);
   }
   
   /* always reinitialize the QAM demodulator */
   dcf872x_reinit (uUnit);
   
   /* if the QAM size has been changed, set to the new QAM size */
   if (pCNimCfg->DemodFlag & 0x01)
   {
      switch ( pCNimCfg->SignalQAM )
      {
         case MOD_QAMAUTO:
            pCNimCfg->DemodQAM = ST0_QAM_AUTO;
            break;
         
         case MOD_QAM16:
            pCNimCfg->DemodQAM = ST0_QAM16;
            break;
         
         case MOD_QAM32:
            pCNimCfg->DemodQAM = ST0_QAM32;
            break;
         
         case MOD_QAM64:
            pCNimCfg->DemodQAM = ST0_QAM64;
            break;
         
         case MOD_QAM128:
            pCNimCfg->DemodQAM = ST0_QAM128;
            break;
         
         case MOD_QAM256:
            pCNimCfg->DemodQAM = ST0_QAM256;
            break;
         
         default:
            pCNimCfg->DemodQAM = ST0_QAM_UNSUPPORTED;
            return (DRV_BAD_SIGNAL);
      }
      
      st0_set_qam_size (ui8Addr, (pCNimCfg->DemodQAM));
      st0_stl_unfreeze (ui8Addr);
   }
   
   /* if the symbol rate has been changed, set to the new symbol rate */
   if (pCNimCfg->DemodFlag & 0x02)
   {
      dcf872x_set_symbol_rate (uUnit);
   }
   
   /* setting for the frequency sweep, according to the new symbol rate. */
   dcf872x_set_freq_sweep (uUnit);
   
   /* if the spectrum inversion option has been changed, set it. */
   if (pCNimCfg->DemodFlag & 0x04)
   {
      if ( pCNimCfg->SignalSI == SPECTRUM_NORMAL )
      {
         pCNimCfg->DemodSI = ST0_SPECTRUM_NORMAL;
      }
      else
      {
         pCNimCfg->DemodSI = ST0_SPECTRUM_INVERSION;
      }
      st0_set_spec_inv (ui8Addr, (pCNimCfg->DemodSI));
   }
   
   /* start the acquisition phase 1 processing */
   st0_acquisition_1 (ui8Addr);
   /* waiting for about 30 ms after the acquisition phase 1 processing */
   task_time_sleep ((u_int32)(DCF872x_ACQP1_DELAY));
   /* check the WBAGC lock status, and get the agc2sd value. */
   st0_wbagc_get_acq (ui8Addr, &(pCNimCfg->DemodWBAGCLock));
   if (ST0_WBAGC_LOCKED == pCNimCfg->DemodWBAGCLock)
   {
      dcf872x_get_strength (uUnit);
   }
   /* start the acquisition phase 2 processing */
   st0_acquisition_2 (ui8Addr);
   /* waiting for about 30 ms after the acquisition phase 2 processing */
   task_time_sleep ((u_int32)(DCF872x_ACQP2_DELAY));
   /* start the acquisition phase 3 processing */
   st0_acquisition_3 (ui8Addr);
   
   return (DRV_OK);
}

/*****************************************************************************/
/*  FUNCTION:    dcf872x_get_tuning                                          */
/*                                                                           */
/*  PARAMETERS:  uUnit  - the unit id of the unit to access.                 */
/*               pTuning - pointer to the TUNING_SPEC structure containing   */
/*                         parameters to store.                              */
/*                                                                           */
/*  DESCRIPTION: The function get the parameters of the current tuning.      */
/*                                                                           */
/*  RETURNS:     DRV_OK if successful, DRV_ERROR if unsuccessful.            */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DRV_RETURN dcf872x_get_tuning (u_int32 uUnit, TUNING_SPEC *pTuning)
{
   CNIM_CFG   *pCNimCfg = (CNIM_CFG *)(&gCNimCfg);
   
   /* return the current signal type */
   pTuning->type = pCNimCfg->UnitType;
   /* return the current signal parameters, such frequency, symbol rate, ... */
   pTuning->tune.nim_cable_tune.frequency     = pCNimCfg->SignalFREQ;
   pTuning->tune.nim_cable_tune.symbol_rate   = pCNimCfg->SignalSR;
   pTuning->tune.nim_cable_tune.modulation    = pCNimCfg->SignalQAM;
   pTuning->tune.nim_cable_tune.auto_spectrum = pCNimCfg->SignalAutoSP;
   pTuning->tune.nim_cable_tune.spectrum      = pCNimCfg->SignalSI;
   pTuning->tune.nim_cable_tune.annex         = pCNimCfg->SignalAnnex;
   return (DRV_OK);
}

/*****************************************************************************/
/*  FUNCTION:    dcf872x_init                                                */
/*                                                                           */
/*  PARAMETERS:  uUnit  - the unit id of the unit to initialize.             */
/*                                                                           */
/*  DESCRIPTION: The function initializes THOMSON Cable Front-End DCF8722    */
/*                                                                           */
/*  RETURNS:     DRV_OK if successful, DRV_INVALID_CHIPID if unsuccessful.   */
/*                                                                           */
/*  CONTEXT:     Must be called from a non-interrupt context.                */
/*                                                                           */
/*****************************************************************************/
DRV_RETURN dcf872x_init (u_int32 uUnit)
{
   CNIM_CFG   *pCNimCfg = (CNIM_CFG *)(&gCNimCfg);
   u_int8      ui8Addr;
   u_int8      ui8Vers;
   
   gCNimCfg.UnitId   = uUnit;             /* the unit id */
   gCNimCfg.UnitType = DEMOD_NIM_CABLE;   /* the unit type */
   
   /**************************************************************************/
   /*          Configure the tuner module of the Cable Front-end
    */
   dcf872x_tuner_init (pCNimCfg);
   
   /**************************************************************************/
   /*       Configure the demodulator module of the Cable Front-end
    */
   
   /* set i2c slave address to access the demodulator internal registers. */
   ui8Addr              = (u_int8)ST0_I2CADDR;
   pCNimCfg->DemodAddr  = (u_int8)ST0_I2CADDR;
   
   /* get the version information from register through i2c bus and check it */
   st0_get_ver (ui8Addr, &ui8Vers);
   if ( ui8Vers != ST0_VERSION )
   {
      return (DRV_INVALID_CHIPID);
   }
   pCNimCfg->DemodChipId = ui8Vers;
   
   /* the demodulator external CLOCK in KHz - 28.8 MHz */
   pCNimCfg->DemodClkExt = 28800;
   /* the sampled IF in KHz after A/D convert, for initial demodulator. */
   pCNimCfg->DemodF1 = pCNimCfg->TunerIF - pCNimCfg->DemodClkExt;
   /* disable the initial quadrature demodulator */
   pCNimCfg->DemodINITDEM = (u_int8)ST0_INITDEM_DISABLE;
   /* configure the working mode of the demodulator internal BERT. */
   dcf872x_set_bert (uUnit);
   /* initialize for C/N estimation */
   st0_init_CN_estimation (ui8Addr);
   pCNimCfg->DemodCNEmean   = 3000;
   pCNimCfg->DemodCNEoffset = 0;
   /* initialize the lock status */
   pCNimCfg->LockStatus.PrevSYNC = DEM_NO_LOCKED;
   pCNimCfg->LockStatus.CurrSYNC = DEM_NO_LOCKED;
   pCNimCfg->LockStatus.uNumLOSS = 0;
   
   /* initialize the parameters of signal */
   pCNimCfg->SignalFREQ   = 0;
   pCNimCfg->SignalSR     = 0;
   pCNimCfg->SignalQAM    = MOD_QAM64;       /* EQU_0  - 0x49 */
   pCNimCfg->SignalAutoSP = 1;   /* auto-detect spectrum inversion */
   pCNimCfg->SignalSI     = SPECTRUM_NORMAL; /* CTRL_3 - 0x00 */
   pCNimCfg->SignalAnnex  = ANNEX_A;         /* CTRL_3 - 0x00 */
   
   /* initialize the frequency sweep rate and the frequency offset. */
   pCNimCfg->iSweepRate     = (int32)DCF872x_SWEEP_RATE;
   pCNimCfg->iCarrierOffset = (int32)DCF872x_FREQ_OFFSET;
   
   /* software reset all internal modules of the demodulator. */
   st0_swreset (ui8Addr);
   st0_equ_swreset (ui8Addr);
   st0_di_swreset (ui8Addr);
   st0_rs_swreset (ui8Addr);
   /* initialize all demodulator internal registers with default values */
   st0_init_regs (ui8Addr);
   
   /**************************************************************************/
   /*       Configure the hardware interrupt for the Cable Front-end
    */
   return (DRV_OK);
}


/****************************************************************************
 * Modifications:
 * $Log: 
 *  5    mpeg      1.4         5/31/04 1:10:46 AM     Steven Shen     CR(s) 
 *        9273 9274 : Adjust the tuner frequency for the signal frequecny 
 *        shift.
 *  4    mpeg      1.3         5/26/04 2:39:51 AM     Steven Shen     CR(s) 
 *        9022 9023 : The DEMOD_DCF8722 driver version 1.20. Fix some bugs.
 *  3    mpeg      1.2         5/20/04 4:27:29 AM     Steven Shen     CR(s) 
 *        9254 9255 : Add the support for the Auto-QAM detection mode.
 *  2    mpeg      1.1         4/4/04 1:01:37 AM      Steven Shen     CR(s) 
 *        8674 8675 : Changed the default auto-detect spectrum inversion option
 *         to 1 (ENABLED).
 *  1    mpeg      1.0         3/15/04 10:30:38 AM    Matt Korte      CR(s) 
 *        8566 : Initial version of Thomson Cable Tuner/Demod
 * $
 *
 ****************************************************************************/

⌨️ 快捷键说明

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