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

📄 hamaro_api.c

📁 机顶盒Hamaro解调器驱动。包含自动搜台
💻 C
📖 第 1 页 / 共 5 页
字号:
		}
	}

  /* (CR 7957) */
  nim->CLKSMDIV_flag = HAMARO_CLKSMOOTHDIV_UPDATE;
  nim->CLKSMDIV_CR = HAMARO_CODERATE_NONE;
  /* if locked to a signal, the acq-offset will be valid, otherwise use 0 */
  nim->actual_tuner_offset = 0L;  /* (CR 6243) */
  acqoffset = 0L;

  nim->symbol_rate_ideal = chanobj->symbrate; 
  if (HAMARO_SetSampleFrequency(nim) == False)  return(False); 

  /* (CR 7672) added line below */
  if (HAMARO_SetSymbolRate(nim,chanobj->symbrate) == False)  return(False);

  /* Set optimal preload values for the auto-tuning system.*/
  /*CR 29373: Change LO Breakpoint from 1165MHz to 1100MHz. Change the frequency where the preload value changes from 1165MHz to 1100MHz.*/
  /*    We just change the following constant from 1165 to 1100*/
#if HAMARO_INCLUDE_RATTLER  
  if (nim->tuner_type == HAMARO_CX24113)  
  {   
       div_cnt_val = 1024;       
       /* >= 950 && <= 1100 || >= 1800 && <= 2150 */       
       if ( (chanobj->frequency >= HAMARO_CX24113_PRELOAD_VALUE_FREQ_THRESH1_KHZ && chanobj->frequency <= HAMARO_CX24113_PRELOAD_VALUE_FREQ_THRESH2_KHZ) ||
       (chanobj->frequency >= HAMARO_CX24113_PRELOAD_VALUE_FREQ_THRESH3_KHZ && chanobj->frequency <= HAMARO_CX24113_PRELOAD_VALUE_FREQ_THRESH4_KHZ) )
       {       
           freq_val = 1000;                         
       } /* > 1100 && < 1800 */  
       else   
       {  
           freq_val = 1024;  
       }
       
       if (HAMARO_RegisterWrite(nim, (unsigned short)(HAMARO_CX24128_BS_FREQ), freq_val, nim->tuner.cx24128.io_method) != True)  
       {  
            return(False);  
       }
       
       if (HAMARO_RegisterWrite(nim, (unsigned short)(HAMARO_CX24128_BS_DIV_CNT), div_cnt_val, nim->tuner.cx24128.io_method) != True)  
       {
            return(False);
       }  
  }
#endif

  if (nim->shadowed_tuner_freq != chanobj->frequency)
  {
	if (HAMARO_SetTunerFrequency(nim,chanobj->frequency) == False)  return(False);
	nim->shadowed_tuner_freq = chanobj->frequency;
  }
	
  if (HAMARO_SetTunerBWAndGain(nim, chanobj->symbrate) == False) return(False);
 
  if (HAMARO_GetFrequencyOffset(nim,&tuneroffset) == False)  return(False);
  freqoffset = acqoffset + tuneroffset;

  /* call HAMARO_SetTunerFrequency before HAMARO_SetCentralFreq */
  if (HAMARO_SetCentralFreq(nim, freqoffset) == False)  return(False);

  if (HAMARO_SetSpectralInversion(nim,chanobj->specinv) == False)  return(False);
  //if (HAMARO_SetLNBDC(nim,chanobj->lnbpol) == False)  return(False);
/*  if (HAMARO_SetLNBTone(nim,chanobj->lnbtone) == False)  return(False);
*/  
  /* set the Viterbi code rate settings  */
  vrates = (chanobj->viterbicoderates | chanobj->coderate);
  if (HAMARO_AcqSetViterbiCodeRates(nim,vrates) == False)  return(False);  /* new style */

  if (HAMARO_SetModulation(nim,chanobj->modtype) == False)  return(False);
  if (HAMARO_DRIVER_SetViterbiRate(nim,chanobj->coderate) == False)  return(False);

  if (HAMARO_AcqBegin(nim) == False)  return(False); 

  /* successful channel change operation, save copy in the nim */
  memcpy(&nim->chanobj,chanobj,sizeof(HAMARO_CHANOBJ));

  /* (CR6838) clear the esno average buffer */
  if (HAMARO_GetChannelEsNo(nim,HAMARO_ESNOMODE_UNDEF,NULL,NULL) == False)  return(False); 

  /* set the clock smoother freq if required (otherwise, clksmooth freq will be set at HAMARO_SetOutputOptions() ) */
  if (nim->mpeg_out.ClkSmoothSel == HAMARO_DDS_LEGACY_SMOOTHING || nim->mpeg_out.ClkSmoothSel == HAMARO_PLL_ADVANCED_SMOOTHING)
  {
    if (HAMARO_DRIVER_SetSmoothClock(nim,nim->mpeg_out.ClkSmoothSel,True) == False)  return(False);
  }

#if HAMARO_INCLUDE_BANDWIDTHADJ
  nim->tuner_bw_adjust = True;
#endif

  return(True);

}  /* HAMARO_ChangeChannel() */


/*******************************************************************************************************/
/* HAMARO_Monitor() */
/*******************************************************************************************************/
BOOL      HAMARO_Monitor(                 /* Monitors the demod after a successful channel change operation */
HAMARO_NIM       *nim,                        /* pointer to HAMARO_NIM */
HAMARO_ACQSTATE  *state,                      /* storage for returned acqusition state of demod */
HAMARO_LOCKIND   *lockinds)                   /* storage for returned demod lock indicators */
{
  unsigned long  locked;

#if HAMARO_INCLUDE_BANDWIDTHADJ  
  long			 lnboffset;
  unsigned long  bandwidth;
  long		     sigmadelta;

  HAMARO_SYMBRATE symbol_rate;
  HAMARO_TRANSPEC transpec;

#endif
   
  /* test for valid nim */
	HAMARO_DRIVER_VALIDATE_NIM(nim);

  if (state == NULL || lockinds == NULL)  
  {
    HAMARO_DRIVER_SET_ERROR(nim,HAMARO_BAD_PARM);
    return(False);
  }
  /* if an i/o error occurred during last i/o attempt, do not allow a Monitor deadlock condition to occur */
  if (nim->iostatus != 0UL)  return(False);

  /* retrieve  lock indicators */
  if (HAMARO_GetLockIndicators(nim,lockinds) == False)  return(False);

  /* give some time to the acq engine */
  if (HAMARO_AcqContinue(nim,state) == False)  return(False);

  /* perform SW assist acq when NOT locked*/
  if (*state == HAMARO_ACQ_SEARCHING || *state == HAMARO_ACQ_FADE)
  {
    /* re-read the acq state after we re-gained lock */
    if (HAMARO_AcqContinue(nim,state) == False)  return(False);
  }

  /* retrieve  lock indicators */
  if (HAMARO_GetLockIndicators(nim,lockinds) == False)  return(False);

  /* perform performance changes once */
  if (lockinds->reedsolomon == TRUE)
  {
	/* We are locked. */
    if (nim->prevstatecounter == 0)
	{
      if (HAMARO_DRIVER_SetSoftDecisionThreshold(nim) == False)
	  {
        return (False);
	  }

      nim->prevstatecounter = 1;
	}
  }
  else
  {
	  /* we are NOT locked, set the state as such. */
      nim->prevstatecounter = 0;
  }
  
#if HAMARO_INCLUDE_BANDWIDTHADJ
    if (*state == HAMARO_ACQ_LOCKED_AND_TRACKING) /* narrow */
    {
		if (HAMARO_GetAcquisitionOffset(nim,&lnboffset) != True)  return(False);		
		if (HAMARO_GetSymbolRate(nim, &symbol_rate) != True) return(FALSE);

		HAMARO_GetTransportSpec(nim, &transpec);
		switch(transpec)
		{
			case  HAMARO_SPEC_DVB:
                bandwidth = (((symbol_rate/1000UL) * 675UL) / 1000UL) + (unsigned long)labs(lnboffset/1000L);
				HAMARO_SetTunerBW(nim, (bandwidth+500UL), &sigmadelta); /* Add 500kHz for rounding */
				break;
			default:
				break;
		}      

        nim->tuner_bw_adjust = True;
		nim->shadowed_tuner_lnboffset = 0; /* next acquisition should re-program */ 
		nim->shadowed_tuner_symbrate  = 0; /* next acquisition should re-program */
    }
    else if (*state == HAMARO_ACQ_FADE) /* open */
    {
        if (nim->tuner_bw_adjust == True) // just do it the moment fade is detected
        {            
            HAMARO_SetTunerBW(nim, nim->anti_alias_bandwidth, &sigmadelta); /* use shadowed value */
            nim->tuner_bw_adjust = False; 
        }
    }

#endif /* COBRA_INCLUDE_BANDWIDTHADJ */

  /* (CR 9436) set the clksmoothdiv only if required.  (after Chan.Change or after lock/unlock transition) */
  if (nim->CLKSMDIV_flag == HAMARO_CLKSMOOTHDIV_UPDATE)
  {
    /* test for first HAMARO_Monitor after change-channel.  If so, test lock */
    if (HAMARO_RegisterRead(nim,CX2430X_ACQFULLSYNC,&locked, HAMARO_DEMOD_I2C_IO) == False)  return(False);

    if (locked == 0x01UL)
    {
      /* Demod is locked.  This is first HAMARO_Monitor after Chan.Change, so set ClkSmootherDiv rate */
      /* when the clock smoother is turned on */
      if (nim->mpeg_out.ClkSmoothSel == HAMARO_DDS_LEGACY_SMOOTHING   /* CR9436 */
          || nim->mpeg_out.ClkSmoothSel == HAMARO_PLL_ADVANCED_SMOOTHING)
      {
        unsigned long  nominal;
        unsigned long  curr;
						 
        /* Read the Current Viterbi code rate */
        if (HAMARO_RegisterRead(nim,CX2430X_ACQVITCURRCR,&curr, HAMARO_DEMOD_I2C_IO) != True)  return(False);

        /* Read the nominal Viterbi code rate */
        if (HAMARO_RegisterRead(nim,CX2430X_ACQVITCRNOM,&nominal, HAMARO_DEMOD_I2C_IO) != True)  return(False);

        /* CR9436: - No need to set ClkSmoothFreqDiv if code rates are equal */
        if (curr != nominal)
        {
		  if (HAMARO_DRIVER_SetSmoothClock(nim,nim->mpeg_out.ClkSmoothSel,False) == False)  return(False);
        }  
		/* cause HAMARO_Monitor() to not adjust clk smooth div until next chan.change */
        nim->CLKSMDIV_flag = HAMARO_CLKSMOOTHDIV_PASS;
	  }
    }
  }

  return(True);

}  /* HAMARO_Monitor() */


/*******************************************************************************************************/
/* HAMARO_NIMGetChipInfo() */
/*******************************************************************************************************/
BOOL      HAMARO_NIMGetChipInfo(          /* function to return HAMARO_NIM (demod+tuner) info to caller */
HAMARO_NIM       *nim,                        /* pointer to HAMARO_NIM */
char      **demod_string,              /* returns name of demod to caller */
char      **tuner_string,              /* returns name of tuner associated to demod */
int       *demod_type,                 /* returns demod type (aka chip version) to caller */
int       *tuner_type,                 /* returns tuner type to caller */
int       *board_type)                 /* returns user board-type info (aka board version) to caller */
{
  unsigned long  ulRegVal = 0;

  //static int   board_ver = -1;
  static char  *demods[3] = {NULL,NULL,NULL};
  static char  *tuners[5] = {NULL,"CX24108","CX24128","CX24113",NULL};

  BOOL   rtn = 0;
  HAMARO_DEMOD  demod;
  
  /* set the default driver product id */
  demods[1] = HAMARO_PRODUCT_NAME_STRING;

  HAMARO_DRIVER_VALIDATE_NIM(nim);

  /* determine the type of demod, if possible */
  if (HAMARO_DRIVER_CxType(nim,&demod,&demods[1]) == False)  return(False);

  *board_type = 0x00;

    /* read demod type from chip, zero, then return if error */
    rtn = HAMARO_RegisterRead(nim,CX2430X_SYSVERSION,&ulRegVal, HAMARO_DEMOD_I2C_IO);
    *demod_type = (int)ulRegVal;
    if (rtn == False)  return(False);

    /* grab the tuner type from the nim */
    *tuner_type = (int)nim->tuner_type;

    /* save the strings: tuner-type and demod string */
    *demod_string = demods[1];  
    *tuner_string = tuners[nim->tuner_type];
    nim->tuner_str = tuners[nim->tuner_type];              /* save the tuner string */

  return(True);

}  /* HAMARO_NIMGetChipInfo() */


/*******************************************************************************************************/
/* BOOL  HAMARO_GetDriverVersion() */
/*******************************************************************************************************/
BOOL   HAMARO_GetDriverVersion(           /* function to return driver version data to caller */
HAMARO_NIM    *nim,                           /* pointer to nim */
HAMARO_VERDRV *verdrv)                        /* pointer to address where version string struct will be stored */
{
  int   i;

  if (nim == NULL || verdrv == NULL)  return(False);

  /* place a copy of the driver version into user-storage */
  memset(verdrv,CNULL,sizeof(HAMARO_VERDRV));
  strncpy(verdrv->version_str,HAMARO_PRODUCT_VERSION_STRING,(sizeof(HAMARO_VERDRV)-1));

  /* extract the minor-version from the version string, save to nim */
  nim->version_minor = 0;
  for (i = HAMARO_MAX_VERLEN -1 ; i > 0 ; i--)
  {
    if (verdrv->version_str[i] != CNULL)
    {
      for ( ; i > 0 ; i--)
      {
        if (isdigit((int)(verdrv->version_str[i])) == 0)
        {
          nim->version_minor = atoi(&verdrv->version_str[i+1]);
          break;
        }
      }
      break;
    }
  }

  return(True);

}  /* BOOL  HAMARO_GetDriverVersion() */



/*******************************************************************************************************/
/* HAMARO_ReleaseEnvironment() */
/*******************************************************************************************************/
BOOL  HAMARO_ReleaseEnvironment(          /* Function to "close" an opened HAMARO_NIM */
HAMARO_NIM   *nim)                            /* pointer to opened HAMARO_NIM */
{
  int  i;

  /* release a previously-saved nim (gives example of how to pre-test nims) */
  if (HAMARO_DRIVER_ValidNim(nim) == True)
  {
    for (i = 0 ; i < HAMARO_MAX_NIMS ; i++)
    {
      if (hamaro_nim_list.nim[i] == nim)
      {
		STS_Release();

        /* release the nim from the stored list */
        hamaro_nim_list.nim[i] = NULL;
        hamaro_nim_list.nim_cnt -= 1;

        /* clear the entire nim struct */
        memset(nim,CNULL,sizeof(HAMARO_NIM));
        
        return(True);
      }
    }
  }

  return(False);

}  /* HAMARO_ReleaseEnvironment() */



/*******************************************************************************************************/
/* HAMARO_SetOutputOptions() */
/*******************************************************************************************************/
BOOL      HAMARO_SetOutputOptions(        /* Function to set the demod MPEG output pins */
HAMARO_NIM       *nim,                        /* pointer to nim */
HAMARO_MPEG_OUT  *mpeg_out)                   /* mpeg settings struct */
{
  unsigned long  ulRegVal;

  /* validate nim and mpeg storage */
  HAMARO_DRIVER_VALIDATE_NIM(nim);

  if (mpeg_out == NULL)  HAMARO_DRIVER_SET_ERROR(nim,HAMARO_BADPTR);
  else

⌨️ 快捷键说明

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