cx24143_fun.c

来自「QPSK Tuner details, for conexant chipset」· C语言 代码 · 共 1,929 行 · 第 1/5 页

C
1,929
字号
      /* additional set-up may be required */

      break;
    }
#endif  /* #ifdef CAMARIC_FEATURES */
    case  SPEC_UNDEF:
    default:
    {
      nim->tspec = SPEC_UNDEF;

      /* bad parameter passed */
      DRIVER_SetError(nim,API_BAD_PARM);
      return(False);
      break;
    }
  }  /* switch(... */

  /* (CR 7951) save a copy of the current transport spec to the nim */
  nim->tspec = transpec;

  return(True);

}  /* API_SetTransportSpec() */



/*******************************************************************************************************/
/* API_GetTransportSpec() */
/*******************************************************************************************************/
BOOL      API_GetTransportSpec(        /* function to return NIM's transport spec */
NIM       *nim,                        /* pointer to nim */
TRANSPEC  *transpec)                   /* returned transport spec setting */
{
   int  temp_modtype;

   ULONG  ulRegVal;

   /* test for valid NIM and parm not NULL */
   if (DRIVER_ValidateNim(nim) == False)  return(False);
   if (transpec == NULL)
   {
      DRIVER_SetError(nim,API_BAD_PARM);
      return (False);
   }

   *transpec = SPEC_UNDEF;
   if (nim->tspec == SPEC_UNDEF)
   {
      /* read the modulation type */
      if (RegisterRead(nim,CX24130_SYSTRANSTD,&ulRegVal) == False)  return(False);
      temp_modtype = (int)ulRegVal;

      /* translate Cobra raw values to application-usable */
      switch (temp_modtype)
      {
         /* DVB */
         case  0x00:
         {
            nim->tspec = SPEC_DVB;
            break;
         }
         /* DSS */  
         case  0x01:
         {
            nim->tspec = SPEC_DSS;
            break;
         }
         /* DCII */
         case  0x03:
         {
            /* DCII has several sub-modes */
            nim->tspec = SPEC_DCII;
            break;
         }
#ifdef CAMARIC_FEATURES
         case 0x02:
         {
            nim->tspec = SPEC_DVB_DSS;
            break;
         }
#endif  /* #ifdef CAMARIC_FEATURES */
         default:
         {
            /* hardware returned an invalid transspec value */
            DRIVER_SetError(nim,API_BAD_RTNVAL);
            return(False);
         }
      }  /* switch(... */
   }  /* if (nim->tspec == SPEC_UNDEF) */
   
   *transpec = nim->tspec;
   
#ifdef CAMARIC_FEATURES
   if (nim->tspec == SPEC_DVB_DSS)
   {
      /* read full sync flag */
      if (RegisterRead(nim,CX24130_ACQFULLSYNC,&ulRegVal) == False)  return(False);

      /* if locked, read actual locked-to transpec value */
      if (ulRegVal == 1UL)
      {
         *transpec = DRIVER_Tspec_Get_Auto(nim);
      }
   }
#endif  /* #ifdef CAMARIC_FEATURES */

   return(True);

}  /* API_GetTransportSpec() */


/*******************************************************************************************************/
/* API_SetSymbolRate() */
/*******************************************************************************************************/
BOOL      API_SetSymbolRate(           /* function to set the demod's symbol rate */
NIM       *nim,                        /* pointer to nim */
SYMBRATE  symbolrate)                  /* symbol rate (in Ksps) */
{
  LONG   temp_symbolrate;

  ULONG  ulRegVal;
  ULONG  samplerate;
  ULONG  requestedLNB;
  ULONG  bandwidth;
  ULONG  mV;

  SYMBRATE  low_test;
  SYMBRATE  high_test;

  BCDNO  bcd;

  /* test NIM for validity */
  if (DRIVER_ValidateNim(nim) == False)  return(False);

  low_test = SYM_RATE_LOW;
  high_test = SYM_RATE_HIGH;

#ifdef CAMARIC_FEATURES
  /* set-up default values only for Camaric */
  if (DRIVER_Camaric(nim) == True)
  {
    low_test = SYM_RATE_LOW_CAM;
    high_test = SYM_RATE_HIGH_CAM;
  }
#endif  /* #ifdef CAMARIC_FEATURES */

  /* range test symbolrate */
  if (symbolrate >= (ULONG)low_test && symbolrate <= (ULONG)high_test)
  {
	/* CR9879, always reset LNB search range to take cases where
	 * NIM_DEFAULT_LNB is greater than the front end LNB offset limit. */

    /* (CR 8514) Reset the LNB Search Range (bins) if required. */
#if 0
    if (nim->opt_fs_disable == True)
    {
      if (nim->symbol_rate_ideal != symbolrate)  reset_lnb = True;
    }
    else  reset_lnb = True;
#endif

    nim->symbol_rate_ideal = symbolrate;

    /* read the sample rate */
    if (API_GetSampleFrequency(nim,&samplerate) == False)  return(False);

#ifdef CAMARIC_FEATURES
    /* Cobra-drop-in-replacement meets only Cobra specs */
    if (DRIVER_Camaric(nim) == True)
    {
      /* (CR 8797 set the pdmfout and sample rate registers) */
      nim->pdmfout = DRIVER_Set_Pdmfout(nim,(nim->symbol_rate_ideal*(1UL*M)),samplerate);
    }
#endif  /* #ifdef CAMARIC_FEATURES */

    /* compute the symbol rate */
    temp_symbolrate = DRIVER_symbolrate_in(symbolrate,samplerate);
    nim->symbol_rate = (ULONG)temp_symbolrate;

    /* write computed value to demod */
    ulRegVal = (ULONG)temp_symbolrate;
    if (RegisterWrite(nim,CX24130_SYSSYMBOLRATE,ulRegVal) == False)  return(False);
    
    /* when the symbol rate changes, the number of bins searched will be modified to reflect */
    /* the default min lnb search range required per CR #5703 */
    /* nim->lnboffset = NIM_DEFAULT_LNB; */
    
    /* (REMOVED per CR 6748/6747) ... retrieve  the search-range-limit, convert actual to khz */
    /* if (API_GetSearchRangeLimit(nim,&actual) == False)  return(False); */
    /* actual /= 1000UL; */
        
    requestedLNB = DRIVER_GetRequestedSearchRangeLimit(nim);
#ifdef DEBUG_SCAN_LOSE_CHANNEL
	requestedLNB /= 2000UL;
#else
    requestedLNB /= 1000UL;
#endif
    if (requestedLNB == 0UL)  requestedLNB = 1UL;

    /* calculate the bandwidth */
    BCD_set(&bcd,symbolrate);
    BCD_mult(&bcd,675L);
    BCD_div(&bcd,1000L);    
    BCD_add(&bcd,(ULONG)requestedLNB);
    bandwidth = BCD_out(&bcd);
#ifndef DEBUG_SCAN_LOSE_CHANNEL
 // for low symbol rate of assia 3s-c 
	if(bandwidth < 8000L && bandwidth > 5000L )
		bandwidth = 4000L;
#endif
    /* calculate the voltage setting */
    if (TUNER_SetFilterBandwidth(nim,bandwidth,&mV) == False)  return(False);

    /* write voltage setting to the demod */
    if (DRIVER_SetTunerFilterBWVoltage(nim,mV) == False)  return(False);

    if (TUNER_SetGainSettings(nim,symbolrate) == False)  return(False);

#ifdef CAMARIC_FEATURES
    /* optimize CTL Tracking Bandwidth based on symbol rate */
    if(DRIVER_SetCTLTrackBW(nim,symbolrate) == False)  return(False);
#endif  /* #ifdef CAMARIC_FEATURES */

#ifdef OPTIMAL_FS_CODE                 /* Fs optimization */
    if (nim->opt_fs_disable != True)
    {
      if (DRIVER_Opt_Fs_calcPLLMult(nim) == False)  return(False);
    }
#endif  /* #ifdef OPTIMAL_FS_CODE */

    

/* Modify by yuxibo 2006.01.11 */
	/* CR9879, always reset LNB search range to take cases where
	 * NIM_DEFAULT_LNB is greater than the front end LNB offset limit. */

    /* (CR 8514) Reset the LNB Search Range (bins) if required. */
    //if (reset_lnb == True)
    //{
    if (API_SetSearchRangeLimit(nim,nim->lnboffset,&ulRegVal) == False)  return(False);
    //}

#if 0
		   if(symbolrate<=5000)
		   {
			//SP16NC1001SetOneRegister(0x3d, 0x1a);
			RegisterWrite(nim, CX24130_AGCTHRESH, 0x1a);
		   }
		   else
		   {
			//SP16NC1001SetOneRegister(0x3d, 0x16);
			RegisterWrite(nim, CX24130_AGCTHRESH, 0x16);
		   }		   


		  if(symbolrate<=10000)
                {
                        //print("\n================dwSymbolRate<=10000===============\n"); 
                        API_SetSearchRangeLimit(nim, 3000000UL, &ulRegVal);
                }
                else if(symbolrate<=20000)
                {
                       //print("\n================dwSymbolRate<=20000===============\n");            
                       API_SetSearchRangeLimit(nim, 5000000UL, &ulRegVal);
                }
                else 
                {
                    	   //print("\n================dwSymbolRate > 20000===============\n");            
                        API_SetSearchRangeLimit(nim, 10000000UL, &ulRegVal);
                 }
				
		//CSTRACE(QPSK_DEBUG_LEVEL,"[API_SetSymbolRate]SR:%d,actual:%d\n",symbolrate,ulRegVal);
#endif		

    return(True);
  }

  DRIVER_SetError(nim,API_PARM_RANGE);
  return(False);

}  /* API_SetSymbolRate() */


/*******************************************************************************************************/
/* API_GetSymbolRate() */
/*******************************************************************************************************/
BOOL      API_GetSymbolRate(           /* function to return demod's current symbol rate setting */
NIM       *nim,                        /* pointer to nim */
SYMBRATE  *symbolrate)                 /* returned current symbol rate setting */
{
  ULONG  temp_symbolrate;
  ULONG  samplerate;

  /* test NIM for validity */
  if (DRIVER_ValidateNim(nim) == False)  return(False);

  /* read the sample rate */
  if (API_GetSampleFrequency(nim,&samplerate) == False)  return(False);

  /* read the symbolrate teh demod is set to */
  if (RegisterRead(nim,CX24130_SYSSYMBOLRATE,symbolrate) == False)  return(False);

   /* compute the symbolrate to be returned to the caller */
  temp_symbolrate = (ULONG)DRIVER_symbolrate_out(*symbolrate,samplerate);
  nim->symbol_rate = temp_symbolrate;
  *symbolrate = temp_symbolrate;

  return(True);

}  /* API_GetSymbolRate() */


/*******************************************************************************************************/
/* API_SetViterbiRate() */
/*******************************************************************************************************/
BOOL      API_SetViterbiRate(          /* function to set the demod viterbi rate */
NIM       *nim,                        /* pointer to nim */
CODERATE  coderate)                    /* viterbi rate setting */
{
  /* test NIM for validity */
  if (DRIVER_ValidateNim(nim) == False)  return(False);

  return(DRIVER_SetViterbiRate(nim,coderate));

}  /* API_SetViterbiRate() */


/*******************************************************************************************************/
/* API_GetViterbiRate() */
/*******************************************************************************************************/
BOOL      API_GetViterbiRate(          /* function to read the demod's current viterbi rate setting */
NIM       *nim,                        /* pointer to nim */
CODERATE  *coderate)                   /* returned current viterbi code rate setting */
{
  /* test NIM for validity */
  if (DRIVER_ValidateNim(nim) == False)  return(False);

  return(DRIVER_GetViterbiRate(nim,coderate));

}  /* API_GetViterbiRate() */


/*******************************************************************************************************/
/* API_SetSpectralInversion() */
/*******************************************************************************************************/
BOOL     API_SetSpectralInversion(     /* function to set the demod's spectral inversion setting */
NIM      *nim,                         /* pointer to nim */
SPECINV  specinv)                      /* spectral inv. setting */
{
  ULONG  ulRegVal;

  /* test NIM for validity */
  if (DRIVER_ValidateNim(nim) == False)  return(False);

  switch(specinv)
  {
    case  SPEC_INV_OFF:
    {
      /* write zero to ACQVitSINom, one to ACQSISearchDis */
      ulRegVal = 0UL;
      if (RegisterWrite(nim,CX24130_ACQVITSINOM,ulRegVal) == False)  return(False);
      ulRegVal = 1UL;
      if (RegisterWrite(nim,CX24130_ACQSISEARCHDIS,ulRegVal) == False)  return(False);
      break;
    }
    case  SPEC_INV_ON:
    {
      /* write one to ACQVitSINom, one to ACQSISearchDis */
      ulRegVal = 1UL;
      if (RegisterWrite(nim,CX24130_ACQVITSINOM,ulRegVal) == False)  return(False);
      ulRegVal = 1UL;
      if (RegisterWrite(nim,CX24130_ACQSISEARCHDIS,ulRegVal) == False)  return(False);
      break;
    }
    case  SPEC_INV_ON_BOTH:
    {
      /* write one to AcqVitSINom, zero to ACQSISearchDis */
      ulRegVal = 1UL;
      if (RegisterWrite(nim,CX24130_ACQVITSINOM,ulRegVal) == False)  return(False);
      ulRegVal = 0UL;
      if (RegisterWrite(nim,CX24130_ACQSISEARCHDIS,ulRegVal) == False)  return(False);
      break;
    }
    case  SPEC_INV_OFF_BOTH:
   

⌨️ 快捷键说明

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