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

📄 cal_dll.cpp

📁 这是一个手机校准程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//Generate GSM Gsys table
	if(parms.cal_rx)
    {
		fprintf(ReportFileP, "//***********************************************************************************\n");
		fprintf(ReportFileP,"// Setup serial AGC Gsys Table\n");
		fprintf(ReportFileP, "//***********************************************************************************\n");
		fprintf(ReportFileP,"//      Band Index Offset\n");
		fprintf(ReportFileP,"//      ==== ===== ======\n");
		if (parms.cal_gsm)
		{
			for( i= 0; i < GSYS_SIZE; i++)
			{
				gsys_entry=cal_data.GSMRxPwr[i]+cal_data.GSMRxPwrDelta[i];
				fprintf(ReportFileP,"SYSGAIN GSM  %d	%d\n",i,gsys_entry);
			}
		}
//Generate DCS Gsys table
		if(parms.cal_dcs)
		{
			fprintf(ReportFileP, "//***********************************************************************************\n");
			fprintf(ReportFileP,"//      Band Index Offset\n");
			fprintf(ReportFileP,"//      ==== ===== ======\n");
		
			if(cal_hs.HS_GetHSCurGsys(DCS,0,&FirstGsys)==FALSE)
			{
				return GSYS_ERROR;
			}
			for( i= 0; i < GSYS_SIZE; i++)
			{
				gsys_entry=cal_data.DCSRxPwr[i]+cal_data.DCSRxPwrDelta[i];
				fprintf(ReportFileP,"SYSGAIN DCS  %d	%d\n",i,gsys_entry);
			}
		}

		if(parms.cal_gsm850)
		{
			fprintf(ReportFileP, "//***********************************************************************************\n");
			fprintf(ReportFileP,"//      Band Index Offset\n");
			fprintf(ReportFileP,"//      ==== ===== ======\n");

			if(cal_hs.HS_GetHSCurGsys(GSM850,0,&FirstGsys)==FALSE)
			{
				return GSYS_ERROR;
			}
			for( i= 0; i < GSYS_SIZE; i++)
			{
				gsys_entry=cal_data.GSM850RxPwr[i]+cal_data.GSM850RxPwrDelta[i];
				fprintf(ReportFileP,"SYSGAIN GSM850  %d	%d\n",i,gsys_entry);
			}
		}
		
//Generate PCS Gsys table
		if(parms.cal_pcs)
		{
			fprintf(ReportFileP, "//***********************************************************************************\n");
			fprintf(ReportFileP,"//      Band Index Offset\n");
			fprintf(ReportFileP,"//      ==== ===== ======\n");

			if(cal_hs.HS_GetHSCurGsys(PCS,0,&FirstGsys)==FALSE)
			{
				return GSYS_ERROR;
			}
			for( i= 0; i < GSYS_SIZE; i++)
			{
				gsys_entry=cal_data.PCSRxPwr[i]+cal_data.PCSRxPwrDelta[i];
				fprintf(ReportFileP,"SYSGAIN PCS  %d	%d\n",i,gsys_entry);
			}
		}

    } // end if rx cal

	if(parms.cal_gsm)
	{
//Generate GSM Ramp Profile Table
		fprintf(ReportFileP, "//***********************************************************************************\n");
		fprintf(ReportFileP,"// Setup GSM Transmit Ramps table\n");
		fprintf(ReportFileP, "//***********************************************************************************\n");

		for(i=0;i<RAMP_TABLE_SIZE;i++)
		{
			fprintf(ReportFileP, "RAMP_UP	GSM   %d",i);
			for(j=0;j<16;j++)
			{
				fprintf(ReportFileP, " 0x%04x",cal_data.GSMRampTable[j][2*i]);	
			}
			fprintf(ReportFileP, "\n");	
			fprintf(ReportFileP, "RAMP_DN	GSM   %d",i);
			for(j=0;j<16;j++)
			{
				fprintf(ReportFileP, " 0x%04x",cal_data.GSMRampTable[j][2*i+1]);	
			}
			fprintf(ReportFileP, "\n");	
		} // end for all power levels
	}

	if(parms.cal_dcs)
    {	 
		fprintf(ReportFileP, "\n");	
		fprintf(ReportFileP, "//***********************************************************************************\n");
		fprintf(ReportFileP,"// Setup DCS transmit RAMP Table\n");
		fprintf(ReportFileP, "//***********************************************************************************\n");
	
//Generate DCS RAMP table 

		for(i=0;i<RAMP_TABLE_SIZE;i++)
		{
			fprintf(ReportFileP, "RAMP_UP	DCS   %d",i);
			for(j=0;j<16;j++)
			{
				fprintf(ReportFileP, " 0x%04x",cal_data.DCSRampTable[j][2*i]);	
			}
			fprintf(ReportFileP, "\n");	
			fprintf(ReportFileP, "RAMP_DN	DCS   %d",i);
		
			for(j=0;j<16;j++)
			{
				fprintf(ReportFileP, " 0x%04x",cal_data.DCSRampTable[j][2*i+1]);	
			}
			fprintf(ReportFileP, "\n");	
		} // end for all power levels
	}

//Generate GSM850 RAMP table 

	if(parms.cal_gsm850)
    {
		fprintf(ReportFileP, "\n");	
		fprintf(ReportFileP, "//***********************************************************************************\n");
		fprintf(ReportFileP,"// Setup GSM850 transmit RAMP Table\n");
		fprintf(ReportFileP, "//***********************************************************************************\n");
 
      {
      for(i=0;i<RAMP_TABLE_SIZE;i++)
        {
		    fprintf(ReportFileP, "RAMP_UP	GSM850   %d",i);
        for(j=0;j<16;j++)
          {
			    fprintf(ReportFileP, " 0x%04x",cal_data.GSM850RampTable[j][2*i]);	
          }
		    fprintf(ReportFileP, "\n");	
		    fprintf(ReportFileP, "RAMP_DN	GSM850   %d",i);
        for(j=0;j<16;j++)
          {
			    fprintf(ReportFileP, " 0x%04x",cal_data.GSM850RampTable[j][2*i+1]);	
          }
		    fprintf(ReportFileP, "\n");	
        } // end for all power levels
      } // end if Infineon chipset 
    
	}


//Generate PCS RAMP table 

	if(parms.cal_pcs)
    {
		fprintf(ReportFileP, "\n");	
		fprintf(ReportFileP, "//***********************************************************************************\n");
		fprintf(ReportFileP,"// Setup PCS transmit RAMP Table\n");
		fprintf(ReportFileP, "//***********************************************************************************\n");
 
      {
      for(i=0;i<RAMP_TABLE_SIZE;i++)
        {
		    fprintf(ReportFileP, "RAMP_UP	PCS   %d",i);
        for(j=0;j<16;j++)
          {
			    fprintf(ReportFileP, " 0x%04x",cal_data.PCSRampTable[j][2*i]);	
          }
		    fprintf(ReportFileP, "\n");	
		    fprintf(ReportFileP, "RAMP_DN	PCS   %d",i);
        for(j=0;j<16;j++)
          {
			    fprintf(ReportFileP, " 0x%04x",cal_data.PCSRampTable[j][2*i+1]);	
          }
		    fprintf(ReportFileP, "\n");	
        } // end for all power levels
      } // end if Infineon chipset 
    
	}


	fprintf(ReportFileP, "//END of SysParm file.  Cal'd using version 1.07\n");	

	stat=fclose( ReportFileP );
	return SUCCESS;
  }


UInt16 cal::GetTxPwrIndex(UInt16 TotalSteps, UInt16	CurStep)
  {
	UInt16 TxIndex;
	switch(band)
	{
	case GSM:
		switch(TotalSteps)
		{
		case 2:
			switch(CurStep)
			{
			case 0:
				TxIndex = 17;
				break;
			case 1:
				TxIndex = 6;
				break;
			default: break;
			}
			break;
		case FULL_GSM_RAMP_STEPS:
			TxIndex = CurStep + 3;
			break;
		}

		break;
	case DCS:
		switch(TotalSteps)
		{
		case 2:
			switch(CurStep)
			{
			case 0:
				TxIndex = 13;
				break;
			case 1:
				TxIndex = 9;
				break;
			default: break;
			}
			break;
		case FULL_GSM_RAMP_STEPS:
			TxIndex = CurStep + 3;
			break;
		}

		break;
	case PCS:
		break;
	default: break;
	}
	return TxIndex;
}

float cal::CalTxRampSlope(UInt16 TotalSteps,float	*RxlevDb,UInt16	*ApcDac,UInt16  *TxRampIndex)
  {
	float Slope;

	switch(TotalSteps)
    {
	  case TWO_STEPS:
		  Slope = (*RxlevDb - *(RxlevDb + 1) )
			  / ( *(ApcDac + *TxRampIndex ) 
			     - *(ApcDac + *(TxRampIndex + 1)));
		  break;
	  default:
		  Slope = (*RxlevDb - *(RxlevDb + (TotalSteps - 1) ) )
			  / (*ApcDac - *(ApcDac + (TotalSteps - 1) ) );
		  break;
    }
	return Slope;
  }

//*******************************************************************************
float cal::GetNormTxPwr(UInt16 TxPwrIndex)
  {
  return(TargetTxPwrValue[(band==GSM ? 0 : 1)][TxPwrIndex]);
  }

//*******************************************************************************
void cal::build_pedestal_ramp(UInt16 min_up_dac, UInt16 min_down_dac, UInt16 peak_dac, UInt16 ramp[RAMP_LENGTH], 
				                      float slope,UserDefParm_t parms)
{
static const double CosSquar[17] =
{1.000000,  0.990393,  0.961940,  0.915735,  0.853554,  0.777785,  0.691342,  0.597546,
0.500001,  0.402456,  0.308659,  0.222216,  0.146447,  0.084266,  0.038061,  0.009608, 0};
UInt16 Step;
float RampPoint;
float D26_D25;
float D27_D25;

if(band==DCS)
	{
	D26_D25 = parms.dcs_ramp_start/slope;
	D27_D25 = parms.dcs_ramp_end/slope;
	}
else if(band==PCS)
	{
	D26_D25 = parms.pcs_ramp_start/slope;
	D27_D25 = parms.pcs_ramp_end/slope;
	}
else
	{
	D26_D25 = parms.gsm_ramp_start/slope;
	D27_D25 = parms.gsm_ramp_end/slope;
	}

//Generate one RAMP UP line
if(band==GSM)
	{
	for(Step = 1; Step < 17; Step++)
		{
		RampPoint = (float)((double)min_up_dac > (peak_dac - D26_D25 * CosSquar[Step])?
					min_up_dac: (peak_dac - D26_D25 * CosSquar[Step] ));
		ramp[Step-1]=RampPoint;	
		}
//Generate one RAMP DOWN line
	for(Step = 1; Step < 17; Step++)
		{
		RampPoint = (float)((peak_dac - (int)(D27_D25 * ( 1 - CosSquar[Step]))) > 0)?
					(peak_dac - D27_D25 * ( 1 - CosSquar[Step]) ): 0;
		if(RampPoint<0)
			RampPoint=0;
		ramp[16+(Step-1)]=(unsigned)RampPoint;
		}
	}
else // DCS and PCS
	{
	for(Step = 1; Step < 17; Step++)
		{
		RampPoint = (double)min_up_dac > (peak_dac - D26_D25 * CosSquar[Step])?
					min_up_dac: (peak_dac - D26_D25 * CosSquar[Step] );
		ramp[Step-1]=(unsigned)RampPoint;;	
		}
//Generate one RAMP DOWN line
	for(Step = 1; Step < 17; Step++)
		{
		RampPoint = (float)((peak_dac - (int)(D27_D25 * ( 1 - CosSquar[Step]))) > 0)?
					(peak_dac - D27_D25 * ( 1 - CosSquar[Step]) ): 0;
		if(RampPoint<0)
			RampPoint=0;
		ramp[16+(Step-1)]=(unsigned)RampPoint;
		}
	}

}

// start with the peak dac value for the highest power - 50. This should 
// ensure that the phone starts out non-saturated. Increment the peak
// dac value in steps of 5 - this should increase the output power 0.5 dB
// at a time. When the output power increases less than 0.1 dB, 
// it's saturated.
// Version 6.13
// Don't search for saturation beyond the higest power level + 0.5 dB
Error_t cal::FindSatPower(float *sat_power,unsigned *sat_dac,
                          float *highest_unsat_power,unsigned *highest_unsat_dac,
                          unsigned start_dac,
                          float limit,
                          UserDefParm_t parms)
  {
  unsigned int i;
  float delta;
  float prev_measured,curr_measured,measured;
  unsigned stat;
  unsigned pk_dac;
	unsigned trial_ramp[RAMP_LENGTH];

  i=1;
  build_pedestal_ramp(0x1f0,0x1f0,start_dac,trial_ramp,(float)0.1,parms);
	cal_hs.HS_SetRamp(trial_ramp);
	Sleep(100);
  stat=cal_measure.GetTxPower(TargetTxPwrValue[DCS][3],&prev_measured);
	curr_measured=prev_measured;
  if(stat==FALSE)
    {
		return POWER_ERROR;
    }

  pk_dac=start_dac;
  delta=1.0;
  i=1;
  while(delta>0.12 && pk_dac<0x3f0 && prev_measured<limit)
    {
  	pk_dac=start_dac+i*10;
    build_pedestal_ramp(0x1f0,0x1f0,pk_dac,trial_ramp,(float)0.1,parms);
		cal_hs.HS_SetRamp(trial_ramp);
	  Sleep(100);
    stat=cal_measure.GetTxPower(prev_measured,&curr_measured);
	  if(stat==FALSE)
      {
		  return POWER_ERROR;
      }
    i++;
    delta=curr_measured-prev_measured;
    prev_measured=curr_measured;
    }

  if(prev_measured>=limit)  // saturated power is going to be higher than required 
    {
    *sat_power=curr_measured+1.0;
    *sat_dac=pk_dac+10;
    return SUCCESS;
    }

// power is saturated now. Back off 10 LSBs and measure the corresponding power
  build_pedestal_ramp(0x1f0,0x1f0,pk_dac-10,trial_ramp,(float)0.1,parms);
  cal_hs.HS_SetRamp(trial_ramp);
	Sleep(100);
  stat=cal_measure.GetTxPower(prev_measured,&measured);
	*highest_unsat_power=measured;
  *highest_unsat_dac=pk_dac-10;
  if(stat==FALSE)
    {
		return POWER_ERROR;
    }

// set Tx power to a lower level
  build_pedestal_ramp(0x1f0,0x1f0,start_dac,trial_ramp,(float)0.1,parms);
	cal_hs.HS_SetRamp(trial_ramp);

  *sat_power=curr_measured;
  *sat_dac=pk_dac;

  return SUCCESS;
  }

⌨️ 快捷键说明

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