T_AFC.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:133k
- MF_crystal_afc_ptr->REQ_Write_CAPID_To_NVRAM_Start();
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- E_METAAPP_RESULT_T state = MF_crystal_afc_ptr->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_L1_CRYSTAL_CAPDATA_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_L1_CRYSTAL_CAPDATA_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_CRYSTAL_AFC_CAPID_WRITE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< Write crystal AFC CAP ID to NVRAM fail "
- );
- }
- return false;
- }
- }
- else
- {
- MetaResult = META_Rf_SetCrystalCapId_r( m_pCal->i_MainMETAHandle, 5000, &CrystalCfg_req );
- if( MetaResult != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_SET_CAPID_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< Set crystal AFC CAP ID fail "
- );
- return false;
- }
- }
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- Sleep(50);
- if (!MF_rf_stop.REQ_Start())
- {
- CalErrorHandler( WM_MF_RF_STOP_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < stop RF fail."
- );
- return false;
- }
- // Sleep(50);
- int i_CRYSTAL_AFC_PCL = Get_CRYSTAL_AFC_PCL( as_CRYSTAL_AFC_BAND );
- MF_rf_tx_level_req->arfcn = m_sCRYSTAL_AFC_ARFCN;
- MF_rf_tx_level_req->bsic = m_cTSC;
- MF_rf_tx_level_req->power = i_CRYSTAL_AFC_PCL;
- MF_rf_tx_level_req->frames = 2000;
- MF_rf_tx_level_req->dacValue = m_sCRYSTAL_AFC_CAL_DAC;
- MF_rf_tx_level_req->burstTypeNB = NB_TX_RANDOM_WITH_TSC; // NB burst
- if ( META_Rf_NB_TX_r( m_pCal->i_MainMETAHandle,
- MF_rf_tx_level_req,
- cb_MF_rf_tx_level_crystal,
- &MF_rf_tx_level_token,
- NULL
- ) != META_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< ARFCN = " + IntToStr(m_sCRYSTAL_AFC_ARFCN) +
- ", TSC = " + IntToStr( m_cTSC ) +
- ", power = " + i_CRYSTAL_AFC_PCL +
- ", frames = " + IntToStr(i_N_TX) +
- ", dac value = " + IntToStr( m_sDefault_value )
- );
- return false;
- }
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (! MF_rf_tx_level_cnf )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: TX level (! MF_rf_tx_level_cnf ) ."
- );
- return false;
- }
- //*******************************************************
- if( ! FetchAverageFreqErr( cal_CapIdFreqErr.FreqErr ) )
- {
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " CAP ID = " + IntToStr( cal_CapIdFreqErr.cap_id ) + "," +
- " AFC DAC = " + IntToStr( m_sCRYSTAL_AFC_CAL_DAC ) + "," +
- " Freq error = " + Double_To_AnsiString(cal_CapIdFreqErr.FreqErr)
- );
- //***************************************************************
- if( Abs_double(cal_CapIdFreqErr.FreqErr) < min_CapIdFreqErr.FreqErr )
- {
- min_CapIdFreqErr.cap_id = cal_CapIdFreqErr.cap_id;
- min_CapIdFreqErr.FreqErr = Abs_double(cal_CapIdFreqErr.FreqErr);
- }
- if( cal_CapIdFreqErr.FreqErr < 0 )
- {
- //isAnyNegativeFreqErr = true;
- last_cap_id = cal_CapIdFreqErr.cap_id;
- }
- else if( cal_CapIdFreqErr.FreqErr >0 )
- {
- //isAnyPositiveFreqErr = true;
- first_cap_id = cal_CapIdFreqErr.cap_id + 1;
- }
- if( first_cap_id >= last_cap_id || pre_cap_id == cal_CapIdFreqErr.cap_id) break;
- pre_cap_id = cal_CapIdFreqErr.cap_id;
- cal_CapIdFreqErr.cap_id = (first_cap_id+last_cap_id) /2;
- }
- if (min_CapIdFreqErr.cap_id < CAP_ID_MIN)
- {
- min_CapIdFreqErr.cap_id = CAP_ID_MIN;
- }
- else if (min_CapIdFreqErr.cap_id > cap_id_max)
- {
- min_CapIdFreqErr.cap_id = cap_id_max;
- }
- MF_crystal_afc_ptr->Set_cap_id(min_CapIdFreqErr.cap_id);
- CrystalCfg_req.cap_id = min_CapIdFreqErr.cap_id;
- if (WRITE_NVARM == m_pCal->s_crystal_afc_option.crystal_cap_id_update)
- {
- MF_crystal_afc_ptr->ConfirmCallback = ::ccb_write_CrystalAFC_to_nvram;
- MF_crystal_afc_ptr->REQ_Write_CAPID_To_NVRAM_Start();
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- E_METAAPP_RESULT_T state = MF_crystal_afc_ptr->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_L1_CRYSTAL_CAPDATA_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_L1_CRYSTAL_CAPDATA_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_CRYSTAL_AFC_CAPID_WRITE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< Write crystal AFC CAP ID to NVRAM fail "
- );
- }
- return false;
- }
- }
- else
- {
- MetaResult = META_Rf_SetCrystalCapId_r( m_pCal->i_MainMETAHandle, 5000, &CrystalCfg_req );
- if( MetaResult != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_SET_CAPID_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< Set crystal AFC CAP ID fail "
- );
- return false;
- }
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================= Crystal CAPID calibration end ================== "
- );
- Sleep(50);
- if (!MF_rf_stop.REQ_Start())
- {
- CalErrorHandler( WM_MF_RF_STOP_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < stop RF fail."
- );
- return false;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::CrystalAFCCapIDCalInc( void )
- {
- int init_cap_id = MF_crystal_afc_ptr->Get_cap_id();
- min_CapIdFreqErr.cap_id = init_cap_id;
- min_CapIdFreqErr.FreqErr = 1000000000.0;
- cal_CapIdFreqErr.cap_id = min_CapIdFreqErr.cap_id;
- int pre_cap_id = -1;
- int cap_id_max;
- int first_cap_id = CAP_ID_MIN;
- int last_cap_id = MF_crystal_afc_ptr->Get_max_cap_id(m_pCal->ui_rf_id);
- cap_id_max = last_cap_id;
- int count=0;
- while( min_CapIdFreqErr.FreqErr != 0.0 &&
- first_cap_id < last_cap_id &&
- CAP_ID_MIN <= cal_CapIdFreqErr.cap_id &&
- cal_CapIdFreqErr.cap_id <= cap_id_max &&
- count < m_sCRYSTAL_AFC_RECURSIVE_TIMES
- )
- {
- count++;
- MF_crystal_afc_ptr->Set_cap_id(cal_CapIdFreqErr.cap_id);
- CrystalCfg_req.cap_id = cal_CapIdFreqErr.cap_id;
- if (WRITE_NVARM == m_pCal->s_crystal_afc_option.crystal_cap_id_update)
- {
- MF_crystal_afc_ptr->ConfirmCallback = ::ccb_write_CrystalAFC_to_nvram;
- MF_crystal_afc_ptr->REQ_Write_CAPID_To_NVRAM_Start();
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- E_METAAPP_RESULT_T state = MF_crystal_afc_ptr->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_L1_CRYSTAL_CAPDATA_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_L1_CRYSTAL_CAPDATA_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_CRYSTAL_AFC_CAPID_WRITE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< Write crystal AFC CAP ID to NVRAM fail "
- );
- }
- return false;
- }
- }
- else
- {
- MetaResult = META_Rf_SetCrystalCapId_r( m_pCal->i_MainMETAHandle, 5000, &CrystalCfg_req );
- if( MetaResult != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_SET_CAPID_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< Set crystal AFC CAP ID fail "
- );
- return false;
- }
- }
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- Sleep(50);
- if (!MF_rf_stop.REQ_Start())
- {
- CalErrorHandler( WM_MF_RF_STOP_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < stop RF fail."
- );
- return false;
- }
- // Sleep(50);
- int i_CRYSTAL_AFC_PCL = Get_CRYSTAL_AFC_PCL( as_CRYSTAL_AFC_BAND );
- MF_rf_tx_level_req->arfcn = m_sCRYSTAL_AFC_ARFCN;
- MF_rf_tx_level_req->bsic = m_cTSC;
- MF_rf_tx_level_req->power = i_CRYSTAL_AFC_PCL;
- MF_rf_tx_level_req->frames = 2000;
- MF_rf_tx_level_req->dacValue = m_sCRYSTAL_AFC_CAL_DAC;
- MF_rf_tx_level_req->burstTypeNB = NB_TX_RANDOM_WITH_TSC; // NB burst
- if ( META_Rf_NB_TX_r( m_pCal->i_MainMETAHandle,
- MF_rf_tx_level_req,
- cb_MF_rf_tx_level_crystal,
- &MF_rf_tx_level_token,
- NULL
- ) != META_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< ARFCN = " + IntToStr(m_sCRYSTAL_AFC_ARFCN) +
- ", TSC = " + IntToStr( m_cTSC ) +
- ", power = " + i_CRYSTAL_AFC_PCL +
- ", frames = " + IntToStr(i_N_TX) +
- ", dac value = " + IntToStr( m_sDefault_value )
- );
- return false;
- }
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (! MF_rf_tx_level_cnf )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: TX level (! MF_rf_tx_level_cnf ) ."
- );
- return false;
- }
- //*******************************************************
- if( ! FetchAverageFreqErr( cal_CapIdFreqErr.FreqErr ) )
- {
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " CAP ID = " + IntToStr( cal_CapIdFreqErr.cap_id ) + "," +
- " AFC DAC = " + IntToStr(m_sCRYSTAL_AFC_CAL_DAC) + "," +
- " Freq error = " + Double_To_AnsiString(cal_CapIdFreqErr.FreqErr)
- );
- //***************************************************************
- if( Abs_double(cal_CapIdFreqErr.FreqErr) < min_CapIdFreqErr.FreqErr )
- {
- min_CapIdFreqErr.cap_id = cal_CapIdFreqErr.cap_id;
- min_CapIdFreqErr.FreqErr = Abs_double(cal_CapIdFreqErr.FreqErr);
- }
- if( cal_CapIdFreqErr.FreqErr > 0 )
- {
- //isAnyNegativeFreqErr = true;
- last_cap_id = cal_CapIdFreqErr.cap_id;
- }
- else if( cal_CapIdFreqErr.FreqErr < 0 )
- {
- //isAnyPositiveFreqErr = true;
- first_cap_id = cal_CapIdFreqErr.cap_id + 1;
- }
- if( first_cap_id >= last_cap_id || pre_cap_id == cal_CapIdFreqErr.cap_id) break;
- pre_cap_id = cal_CapIdFreqErr.cap_id;
- cal_CapIdFreqErr.cap_id = (first_cap_id+last_cap_id) /2;
- }
- if (min_CapIdFreqErr.cap_id < CAP_ID_MIN)
- {
- min_CapIdFreqErr.cap_id = CAP_ID_MIN;
- }
- else if (min_CapIdFreqErr.cap_id > cap_id_max)
- {
- min_CapIdFreqErr.cap_id = cap_id_max;
- }
- MF_crystal_afc_ptr->Set_cap_id(min_CapIdFreqErr.cap_id);
- CrystalCfg_req.cap_id = min_CapIdFreqErr.cap_id;
- if (WRITE_NVARM == m_pCal->s_crystal_afc_option.crystal_cap_id_update)
- {
- MF_crystal_afc_ptr->ConfirmCallback = ::ccb_write_CrystalAFC_to_nvram;
- MF_crystal_afc_ptr->REQ_Write_CAPID_To_NVRAM_Start();
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- E_METAAPP_RESULT_T state = MF_crystal_afc_ptr->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_L1_CRYSTAL_CAPDATA_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_L1_CRYSTAL_CAPDATA_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_CRYSTAL_AFC_CAPID_WRITE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< Write crystal AFC CAP ID to NVRAM fail "
- );
- }
- return false;
- }
- }
- else
- {
- MetaResult = META_Rf_SetCrystalCapId_r( m_pCal->i_MainMETAHandle, 5000, &CrystalCfg_req );
- if( MetaResult != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_SET_CAPID_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< Set crystal AFC CAP ID fail "
- );
- return false;
- }
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================= Crystal CAPID calibration end ================== "
- );
- Sleep(50);
- if (!MF_rf_stop.REQ_Start())
- {
- CalErrorHandler( WM_MF_RF_STOP_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < stop RF fail."
- );
- return false;
- }
- return true;
- }
- //----------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::CrystalAFCCapIDCheck_BypassCapIDCal( void )
- {
- char tempbuf[256];
- bool isCrystalAfcCheckFinish[2];
- ////////////////////////// check crystal AFC result ///////////////////////
- log->Add( "n" +DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================== Crystal CAPID check begin ===================== "
- );
- int i_CRYSTAL_AFC_PCL = Get_CRYSTAL_AFC_PCL( as_CRYSTAL_AFC_BAND );
- for(int i=0; i<2; i++ )
- {
- Sleep(50);
- if (!MF_rf_stop.REQ_Start())
- {
- CalErrorHandler( WM_MF_RF_STOP_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < stop RF fail."
- );
- return false;
- }
- MF_rf_tx_level_req->arfcn = m_sCRYSTAL_AFC_ARFCN;
- MF_rf_tx_level_req->bsic = m_cTSC;
- MF_rf_tx_level_req->power = i_CRYSTAL_AFC_PCL;
- MF_rf_tx_level_req->frames = 2000;
- MF_rf_tx_level_req->dacValue = m_sCHECK_DAC[i];
- MF_rf_tx_level_req->burstTypeNB = NB_TX_RANDOM_WITH_TSC;
- if ( META_Rf_NB_TX_r( m_pCal->i_MainMETAHandle,
- MF_rf_tx_level_req,
- cb_MF_rf_tx_level_crystal,
- &MF_rf_tx_level_token,
- NULL
- ) != META_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< ARFCN = " + IntToStr(m_sCRYSTAL_AFC_ARFCN) +
- ", TSC = " + IntToStr( m_cTSC ) +
- ", power = " + i_CRYSTAL_AFC_PCL +
- ", frames = " + IntToStr(i_N_TX) +
- ", dac value = " + IntToStr( m_sDefault_value )
- );
- return false;
- }
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (! MF_rf_tx_level_cnf )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: TX level (! MF_rf_tx_level_cnf ) ."
- );
- return false;
- }
- if(! FetchAverageFreqErr(chk_CapIdFreqErr[i].FreqErr) )
- {
- return false;
- }
- //********************************************************
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " CAP ID = " + IntToStr( MF_crystal_afc_ptr->Get_cap_id() ) + "," +
- " AFC DAC = " + IntToStr( m_sCHECK_DAC[i] ) + "," +
- " Freq error = " + Double_To_AnsiString(chk_CapIdFreqErr[i].FreqErr)
- );
- FreqErrorPPM = chk_CapIdFreqErr[i].FreqErr / d_CAL_Center_Freq;
- if( (FreqErrorPPM < d_CRYSTAL_AFC_MAX_FREQ_ERR_PPM && FreqErrorPPM>=0) ||
- (FreqErrorPPM > d_CRYSTAL_AFC_MIN_FREQ_ERR_PPM && FreqErrorPPM < 0) //||
- // (chk_CapIdFreqErr[0].FreqErr > 0 && i==0 ) ||
- // (chk_CapIdFreqErr[1].FreqErr < 0 && i==1 )
- )
- {
- //CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_CHECK_FAIL );
- isCrystalAfcCheckFinish[i] = false;
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Crystal AFC check:" +
- " CAP ID = " + IntToStr( MF_crystal_afc_ptr->Get_cap_id() ) + "," +
- " AFC DAC = " + IntToStr( m_sCHECK_DAC[i] ) + "," +
- " Freq error PPM = " + Double_To_AnsiString(FreqErrorPPM)+ "," +
- " min Freq error PPM = " + Double_To_AnsiString( d_CRYSTAL_AFC_MIN_FREQ_ERR_PPM )+ "," +
- " max Freq error PPM = " + Double_To_AnsiString( d_CRYSTAL_AFC_MAX_FREQ_ERR_PPM )+ "n"
- );
- //FreqErrorPPMFail = FreqErrorPPM;
- }
- else
- {
- isCrystalAfcCheckFinish[i] = true;
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " PASS: Crystal AFC check:" +
- " CAP ID = " + IntToStr( MF_crystal_afc_ptr->Get_cap_id() ) + ", " +
- " AFC DAC = " + IntToStr( m_sCHECK_DAC[i] ) + ", " +
- " Freq error PPM = " + Double_To_AnsiString(FreqErrorPPM)+ ", " +
- " min Freq error PPM = " + Double_To_AnsiString( d_CRYSTAL_AFC_MIN_FREQ_ERR_PPM ) + ", " +
- " max Freq error PPM = " + Double_To_AnsiString( d_CRYSTAL_AFC_MAX_FREQ_ERR_PPM ) + "n"
- );
- }
- } // for
- if( !isCrystalAfcCheckFinish[0] || !isCrystalAfcCheckFinish[1] )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_CHECK_FAIL );
- return false;
- }
- PostMessage(
- ctrl.hPostMsgDestHandle,
- WM_MF_RF_CRYSTAL_AFC_CAPID_DONE,
- 0,
- 0
- );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================== Crystal CAPID check end ======================= "
- );
- Sleep(50);
- if (!MF_rf_stop.REQ_Start())
- {
- CalErrorHandler(WM_MF_RF_STOP_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < stop RF fail."
- );
- return false;
- }
- return true;
- }
- //----------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::CrystalAFCCapIDCheck_Normal( void )
- {
- char tempbuf[256];
- ////////////////////////// check crystal AFC result ///////////////////////
- log->Add( "n" +DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================== Crystal CAPID check begin ===================== "
- );
- // if( ! isAnyPositiveFreqErr )
- // {
- // CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_ALL_FREQ_ERR_POSITIVE_FAIL );
- // log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " FAIL: crystal AFC calibration all frequency error are positive."
- // );
- // return false;
- // }
- // if( ! isAnyNegativeFreqErr )
- // {
- // CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_ALL_FREQ_ERR_NEGATIVE_FAIL );
- // log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " FAIL: crystal AFC calibration all frequency error are negative."
- // );
- // return false;
- // }
- bool isCrystalAfcCheckFinish[2];
- isCrystalAfcCheckFinish[0] = false;
- isCrystalAfcCheckFinish[1] = false;
- double FreqErrorPPMFail;
- int cap_id_max;
- cap_id_max = MF_crystal_afc_ptr->Get_max_cap_id(m_pCal->ui_rf_id);
- // fine tune cap_id
- int last_min_cap_id[2];
- last_min_cap_id[0] = -10000;
- last_min_cap_id[1] = -10000;
- do
- {
- int i_CRYSTAL_AFC_PCL = Get_CRYSTAL_AFC_PCL( as_CRYSTAL_AFC_BAND );
- int i=0;
- for (i=0; i<2; i++)
- {
- Sleep(50);
- if (!MF_rf_stop.REQ_Start())
- {
- CalErrorHandler( WM_MF_RF_STOP_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < stop RF fail."
- );
- return false;
- }
- MF_rf_tx_level_req->arfcn = m_sCRYSTAL_AFC_ARFCN;
- MF_rf_tx_level_req->bsic = m_cTSC;
- MF_rf_tx_level_req->power = i_CRYSTAL_AFC_PCL;
- MF_rf_tx_level_req->frames = 2000;
- MF_rf_tx_level_req->dacValue = m_sCHECK_DAC[i];
- MF_rf_tx_level_req->burstTypeNB = NB_TX_RANDOM_WITH_TSC;
- if ( META_Rf_NB_TX_r( m_pCal->i_MainMETAHandle,
- MF_rf_tx_level_req,
- cb_MF_rf_tx_level_crystal,
- &MF_rf_tx_level_token,
- NULL
- ) != META_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< ARFCN = " + IntToStr(m_sCRYSTAL_AFC_ARFCN) +
- ", TSC = " + IntToStr( m_cTSC ) +
- ", power = " + i_CRYSTAL_AFC_PCL +
- ", frames = " + IntToStr(i_N_TX) +
- ", dac value = " + IntToStr( m_sDefault_value )
- );
- return false;
- }
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (! MF_rf_tx_level_cnf )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: TX level (! MF_rf_tx_level_cnf ) ."
- );
- return false;
- }
- if(! FetchAverageFreqErr(chk_CapIdFreqErr[i].FreqErr) )
- {
- return false;
- }
- //********************************************************
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " CAP ID = " + IntToStr( MF_crystal_afc_ptr->Get_cap_id() ) + "," +
- " AFC DAC = " + IntToStr( m_sCHECK_DAC[i] ) + "," +
- " Freq error = " + Double_To_AnsiString(chk_CapIdFreqErr[i].FreqErr)
- );
- FreqErrorPPM = chk_CapIdFreqErr[i].FreqErr / d_CAL_Center_Freq;
- if( (FreqErrorPPM < d_CRYSTAL_AFC_MAX_FREQ_ERR_PPM && FreqErrorPPM>=0) ||
- (FreqErrorPPM > d_CRYSTAL_AFC_MIN_FREQ_ERR_PPM && FreqErrorPPM < 0) //||
- // (chk_CapIdFreqErr[0].FreqErr > 0 && i==0 ) ||
- // (chk_CapIdFreqErr[1].FreqErr < 0 && i==1 )
- )
- {
- //CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_CHECK_FAIL );
- isCrystalAfcCheckFinish[i] = false;
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Crystal AFC check:" +
- " CAP ID = " + IntToStr( MF_crystal_afc_ptr->Get_cap_id() ) + "," +
- " AFC DAC = " + IntToStr( m_sCHECK_DAC[i] ) + "," +
- " Freq error PPM = " + Double_To_AnsiString(FreqErrorPPM)+ "," +
- " min Freq error PPM = " + Double_To_AnsiString( d_CRYSTAL_AFC_MIN_FREQ_ERR_PPM )+ "," +
- " max Freq error PPM = " + Double_To_AnsiString( d_CRYSTAL_AFC_MAX_FREQ_ERR_PPM )+ "n"
- );
- FreqErrorPPMFail = FreqErrorPPM;
- }
- else
- {
- isCrystalAfcCheckFinish[i] = true;
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " PASS: Crystal AFC check:" +
- " CAP ID = " + IntToStr( MF_crystal_afc_ptr->Get_cap_id() ) + ", " +
- " AFC DAC = " + IntToStr( m_sCHECK_DAC[i] ) + ", " +
- " Freq error PPM = " + Double_To_AnsiString(FreqErrorPPM)+ ", " +
- " min Freq error PPM = " + Double_To_AnsiString( d_CRYSTAL_AFC_MIN_FREQ_ERR_PPM ) + ", " +
- " max Freq error PPM = " + Double_To_AnsiString( d_CRYSTAL_AFC_MAX_FREQ_ERR_PPM ) + "n"
- );
- }
- } // for
- if( isCrystalAfcCheckFinish[0] ^ isCrystalAfcCheckFinish[1] )
- {
- last_min_cap_id[1] = last_min_cap_id[0];
- last_min_cap_id[0] = min_CapIdFreqErr.cap_id;
- if( FreqErrorPPMFail < d_CRYSTAL_AFC_MAX_FREQ_ERR_PPM && FreqErrorPPMFail>=0 )
- {
- if( m_bFreqErrIncrease )
- {
- min_CapIdFreqErr.cap_id++;
- }
- else
- {
- min_CapIdFreqErr.cap_id--;
- }
- }
- else
- {
- if( m_bFreqErrIncrease )
- {
- min_CapIdFreqErr.cap_id--;
- }
- else
- {
- min_CapIdFreqErr.cap_id++;
- }
- }
- MF_crystal_afc_ptr->Set_cap_id( min_CapIdFreqErr.cap_id );
- CrystalCfg_req.cap_id = min_CapIdFreqErr.cap_id;
- if (WRITE_NVARM == m_pCal->s_crystal_afc_option.crystal_cap_id_update)
- {
- MF_crystal_afc_ptr->ConfirmCallback = ::ccb_write_CrystalAFC_to_nvram;
- MF_crystal_afc_ptr->REQ_Write_CAPID_To_NVRAM_Start();
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- E_METAAPP_RESULT_T state = MF_crystal_afc_ptr->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_L1_CRYSTAL_CAPDATA_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_L1_CRYSTAL_CAPDATA_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_CRYSTAL_AFC_CAPID_WRITE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< Write crystal AFC CAP ID to NVRAM fail "
- );
- }
- return false;
- }
- }
- else
- {
- MetaResult = META_Rf_SetCrystalCapId_r( m_pCal->i_MainMETAHandle, 5000, &CrystalCfg_req );
- if( MetaResult != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_SET_CAPID_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< Set crystal AFC CAP ID fail "
- );
- return false;
- }
- }
- }
- } // while
- while( (isCrystalAfcCheckFinish[0] ^ isCrystalAfcCheckFinish[1]) &&
- min_CapIdFreqErr.cap_id >=CAP_ID_MIN &&
- min_CapIdFreqErr.cap_id <=cap_id_max &&
- min_CapIdFreqErr.cap_id !=last_min_cap_id[0] &&
- min_CapIdFreqErr.cap_id !=last_min_cap_id[1]
- );
- if( !isCrystalAfcCheckFinish[0] || !isCrystalAfcCheckFinish[1] )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_CHECK_FAIL );
- return false;
- }
- // save to result
- for(int i=0; i<2; i++)
- {
- sprintf(tempbuf, "%8.3f", chk_CapIdFreqErr[i].FreqErr/d_CAL_Center_Freq);
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- }
- sprintf(tempbuf, "%8d", min_CapIdFreqErr.cap_id);
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- WriteCrystalAFCCalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath);
- // write CAP ID to NVRAM
- MF_crystal_afc_ptr->ConfirmCallback = ::ccb_write_CrystalAFC_to_nvram;
- MF_crystal_afc_ptr->REQ_Write_CAPID_To_NVRAM_Start();
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- E_METAAPP_RESULT_T state = MF_crystal_afc_ptr->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_L1_CRYSTAL_CAPDATA_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_L1_CRYSTAL_CAPDATA_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_CRYSTAL_AFC_CAPID_WRITE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< Write crystal AFC CAP ID to NVRAM fail "
- );
- }
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target< Write crystal AFC CAP ID to NVRAM"
- );
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- PostMessage(
- ctrl.hPostMsgDestHandle,
- WM_MF_RF_CRYSTAL_AFC_CAPID_DONE,
- 0,
- 0
- );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================== Crystal CAPID check end ======================= "
- );
- Sleep(50);
- if (!MF_rf_stop.REQ_Start())
- {
- CalErrorHandler( WM_MF_RF_STOP_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < stop RF fail."
- );
- return false;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::EquConfigPFER(void)
- {
- RestartTimerCal(WM_MF_AGE8960_SET_MESA_FUNC_PFER_FAIL);
- if (!m_rct_ctrl.RCT_confPFER( m_pRct, m_sCRYSTAL_AFC_FREQ_ERR_MEASUSE_COUNT))
- {
- CalErrorHandler(WM_MF_AGE8960_CONFIG_PFER_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: " + m_pRct->as_RCT + " < config phase and frequency error."
- );
- return false;
- }
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " " +
- m_pRct->as_RCT + " < config phase and frequency error."
- );
- frmFatcory->DisableAllCalTimer();
- return true;
- }
- //-----------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::FetchAverageFreqErr(ViReal64& AvgFreqErr)
- {
- RestartTimerCal(WM_MF_AGE8960_READ_PFER_FAIL);
- if (!m_rct_ctrl.RCT_FetchAvgFreqErr(m_pRct, AvgFreqErr))
- {
- CalErrorHandler(WM_MF_AGE8960_READ_PFER_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: " + m_pRct->as_RCT + " < fetch phase error."
- );
- return false;
- }
- frmFatcory->DisableAllCalTimer();
- return true;
- }
- //-----------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::FetchSigAverageFreqErr(ViReal64& AvgFreqErr)
- {
- RestartTimerCal(WM_MF_AGE8960_READ_PFER_FAIL);
- if (!m_rct_ctrl.RCT_sig_FetchAvgFreqErr(m_pRct, AvgFreqErr))
- {
- CalErrorHandler(WM_MF_AGE8960_READ_PFER_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: " + m_pRct->as_RCT + " < fetch phase error."
- );
- return false;
- }
- frmFatcory->DisableAllCalTimer();
- return true;
- }
- //----------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::CrystalAFCMeasureRxFreqErr( void )
- {
- char tempbuf[256];
-
- MF_rf_afc_req->arfcn = m_sAFC_ARFCN;
- MF_rf_afc_req->dacValue = (TCVCXO == m_pCal->e_AFC_type)?m_sDAC1:m_sCRYSTAL_DAC1;
- MF_rf_afc_req->gain = (MF_RF_GAIN_TO_BE_SUB - d_P_DL) * GAIN_REQUEST_PC_SIDE_MULTIPLY;
- MF_rf_afc_req->testNumber = m_sN_AFC;
- if ( META_Rf_AFC_r( m_pCal->i_MainMETAHandle, MF_rf_afc_req, MF_rf_afc_cb, &MF_rf_afc_token,NULL ) != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_AFC_CONTROL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target < AFC: ARFCN = "+ IntToStr( m_sAFC_ARFCN ) +
- ", dac value = "+ IntToStr(MF_rf_afc_req->dacValue) +
- ", gain = " + Double_To_AnsiString(MF_rf_afc_req->gain/RF_RX_GAIN_SCALE) + " dB" +
- ", testing number = " + IntToStr( m_sN_AFC )
- );
- return false;
- }
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < ARFCN = "+ IntToStr( m_sAFC_ARFCN ) +
- ", dac value = "+ IntToStr(MF_rf_afc_req->dacValue) +
- ", gain = " + Double_To_AnsiString(MF_rf_afc_req->gain/RF_RX_GAIN_SCALE) + " dB" +
- ", testing number = " + IntToStr( m_sN_AFC )
- );
- //log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " TimerCal->Enabled 2= " + IntToStr((int)frmFatcory->TimerCal->Enabled)
- // );
- RestartTimerCal(WM_MF_RF_AFC_CONTROL_FAIL);
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (this->Terminated)
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Terminate at line " + AnsiString(__FILE__) + " " + AnsiString(__LINE__)
- );
- this->OnTerminate = neByUser;
- return false;
- }
- if ( MF_rf_afc_cnf->fcb_ok_number <= 0 )
- {
- CalErrorHandler( WM_MF_RF_AFC_CONTROL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< AFC FB detection fail "
- );
- return false;
- }
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- frmFatcory->DisableAllCalTimer();
- sprintf(tempbuf, "%11d", MF_rf_afc_cnf->freqOffset);
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- if (!WriteAFCCalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath))
- {
- CalErrorHandler(WM_MF_RF_AFC_WRITE_CAL_RESULT_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : write RX frequency error to cal file "
- );
- return false;
- }
- frmFatcory->DisableAllCalTimer();
- return true;
- }
- //----------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::CrystalTXAfcOffsetCal( void )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================== AFC TRX offset calibration begin ======================= "
- );
- PostMessage(
- ctrl.hPostMsgDestHandle,
- WM_MF_RF_CRYSTAL_AFC_TRX_OFFSET_BEGIN,
- 0,
- 0
- );
- m_bFirstAfcTracking = true;
- if( ! m_rct_ctrl.RCT_operatingMode(m_pRct, OPERATING_MODE_GSM_BCH_TCH))
- {
- CalErrorHandler(WM_MF_AGE8960_SET_OPERATION_MODE_FAIL);
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- m_pRct->as_RCT + " < Operation mode = GSM BCH+TCH"
- );
- return false;
- }
- char tempbuf[256];
- double FreqErr;
- int i_CRYSTAL_AFC_PCL;
- short sARFCN;
- int vi_Band;
- FrequencyBand eFreqBand = FrequencyBand850;
- while (eFreqBand < FrequencyBandCount)
- {
- switch (eFreqBand)
- {
- case FrequencyBand850:
- {
- if (! IsFreqBankSupported( m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- vi_Band = age1960_GSM850_BAND;
- sARFCN = m_sARFCN_C0_GSM850;
- i_CRYSTAL_AFC_PCL = i_CRYSTAL_AFC_GSM850_PCL;
- }
- break;
- case FrequencyBand900:
- {
- if (! IsFreqBankSupported( m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- vi_Band = age1960_EGSM_BAND;
- sARFCN = m_sARFCN_C0_GSM;
- i_CRYSTAL_AFC_PCL = i_CRYSTAL_AFC_GSM900_PCL;
- }
- break;
- case FrequencyBand1800:
- {
- if (! IsFreqBankSupported( m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- vi_Band = age1960_DCS1800_BAND;
- sARFCN = m_sARFCN_C0_DCS;
- i_CRYSTAL_AFC_PCL = i_CRYSTAL_AFC_DCS1800_PCL;
- }
- break;
- case FrequencyBand1900:
- {
- if (! IsFreqBankSupported( m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- vi_Band = age1960_PCS1900_BAND;
- sARFCN = m_sARFCN_C0_PCS;
- i_CRYSTAL_AFC_PCL = i_CRYSTAL_AFC_PCS1900_PCL;
- }
- break;
- default:
- assert(false);
- break;
- } // switch
-
- log->Add( "n" + DateToStr(Date()) + " " + CurrentTimeStr() +
- " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
- );
- int band_idx = FreqBand_To_BandIdx(eFreqBand);
- // Sleep( 10000 ); // temp test
- if (IsFreqBankSupported(m_asFreqBank, eFreqBand))
- {
- if(eFreqBand == FrequencyBand1900)
- {
- if(META_Rf_SelectFrequencyBand1900_r( m_pCal->i_MainMETAHandle, 1, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) != META_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < set Band1900 flag = 1"
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < set Band1900 flag = 1"
- );
- }
- else
- {
- if(META_Rf_SelectFrequencyBand1900_r( m_pCal->i_MainMETAHandle, 0, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) != META_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < set Band1900 flag = 0"
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < set Band1900 flag = 0"
- );
- }
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- }
- if (AGILENT_8960 == m_pRct->device_type)
- {
- if (!m_rct_ctrl.RCT_cellBand(m_pRct, vi_Band))
- {
- CalErrorHandler(WM_MF_AGE8960_SET_BAND_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL:"+
- " Agilent 8960 < Band = " + ViBand_To_Str(vi_Band)
- );
- return false;
- }
- }
- else
- {
- if( ! m_rct_ctrl.RCT_sig_cellBand( m_pRct, vi_Band ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " CMU 200 < Band = " + ViBand_To_Str( vi_Band )
- );
- return false;
- }
- }
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- m_pRct->as_RCT + " < Band = " + ViBand_To_Str(vi_Band)
- );
- // Sleep( 100 ); // wait Agilent 8960 ready!
- // if Agilent 8960 not read, target will get error power!
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- if (AGILENT_8960 == m_pRct->device_type)
- {
- if( ! m_rct_ctrl.RCT_cellPower( m_pRct, d_P_DL ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_POWER_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: " + m_pRct->as_RCT + " < Power = " +
- Double_To_AnsiString( d_P_DL) + " dBm" );
- return false;
- }
- }
- else
- {
- if( ! m_rct_ctrl.RCT_sig_cellPower( m_pRct, d_P_DL ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_POWER_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: " + m_pRct->as_RCT + " < Power = " +
- Double_To_AnsiString( d_P_DL) + " dBm");
- return false;
- }
- if( ! m_rct_ctrl.RCT_sig_TCHLevel( m_pRct, d_CRYSTAL_AFC_TCH_P_DL ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_POWER_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: cmu200 < Power = " +
- Double_To_AnsiString( d_CRYSTAL_AFC_TCH_P_DL) + " dBm");
- return false;
- }
- }
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- m_pRct->as_RCT + " < cell power = "+
- Double_To_AnsiString(d_P_DL)
- );
- if (AGILENT_8960 == m_pRct->device_type)
- {
- if( ! m_rct_ctrl.RCT_BCHARFCN( m_pRct, sARFCN) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_BCH_ARFCN_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : "+
- m_pRct->as_RCT + " < BCH ARFCN = " + IntToStr( sARFCN )
- );
- return false;
- }
- }
- else
- {
- if( ! m_rct_ctrl.RCT_sig_BCHARFCN( m_pRct, sARFCN ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_BCH_ARFCN_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- m_pRct->as_RCT + " < BCH ARFCN = " + IntToStr( sARFCN )
- );
- return false;
- }
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- m_pRct->as_RCT + " < BCH ARFCN = " + IntToStr(sARFCN)
- );
- if( frmFatcory->rbAgilent8960->Checked )
- {
- if (!m_rct_ctrl.RCT_TCHARFCN(m_pRct, sARFCN))
- {
- CalErrorHandler( WM_MF_AGE8960_SET_TCH_ARFCN_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- m_pRct->as_RCT + " < TCH ARFCN = " + IntToStr(sARFCN)
- );
- return false;
- }
- }
- else
- {
- if (!m_rct_ctrl.RCT_sig_TCHARFCN(m_pRct, sARFCN))
- {
- CalErrorHandler( WM_MF_AGE8960_SET_TCH_ARFCN_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- m_pRct->as_RCT + " < TCH ARFCN = " + IntToStr(sARFCN)
- );
- return false;
- }
- }
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- m_pRct->as_RCT + " < TCH ARFCN = " + IntToStr(sARFCN)
- );
- if (frmFatcory->rbAgilent8960->Checked)
- {
- if( ! m_rct_ctrl.RCT_TCHTimeslot(m_pRct, TIMESLOT_3) )
- {
- CalErrorHandler(WM_MF_AGE8960_SET_TCH_TIMESLOT_FAIL);
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- m_pRct->as_RCT + " < timeslot = " + IntToStr( TIMESLOT_3 )
- );
- return false;
- }
- }
- else
- {
- if( ! m_rct_ctrl.RCT_sig_TCHTimeslot(m_pRct, TIMESLOT_3) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_TCH_TIMESLOT_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- m_pRct->as_RCT + " < timeslot = " + IntToStr(TIMESLOT_3)
- );
- return false;
- }
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- m_pRct->as_RCT + " < TCH timeslot = " + IntToStr(TIMESLOT_3)
- );
- if ( frmFatcory->rbAgilent8960->Checked )
- {
- if( ! m_rct_ctrl.RCT_ConfigTSC( m_pRct, m_cTSC ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_TSC_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- "FAIL : " + m_pRct->as_RCT + " < set TSC fail."
- );
- return false;
- }
- }
- else
- {
- if( ! m_rct_ctrl.RCT_sig_ConfigTSC( m_pRct, 0 ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_TSC_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : " + m_pRct->as_RCT + " < TSC = " + IntToStr( 0 )
- );
- return false;
- }
- }
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- m_pRct->as_RCT + " < TSC = " + IntToStr( m_cTSC)
- );
- if ( frmFatcory->rbAgilent8960->Checked )
- {
- if( ! m_rct_ctrl.RCT_MSTXLevel( m_pRct, i_CRYSTAL_AFC_PCL ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_MS_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : " + m_pRct->as_RCT + " < MS TX level = " + IntToStr(i_CRYSTAL_AFC_PCL)
- );
- return false;
- }
- }
- else
- {
- if( ! m_rct_ctrl.RCT_sig_MSTXLevel( m_pRct, i_CRYSTAL_AFC_PCL ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_MS_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : " + m_pRct->as_RCT + " < MS TX level = " + IntToStr( i_CRYSTAL_AFC_PCL )
- );
- return false;
- }
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- m_pRct->as_RCT + " < MS TX level = " + IntToStr(i_CRYSTAL_AFC_PCL)
- );
- // log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " TimerCal->Enabled 8= " + IntToStr((int)frmFatcory->TimerCal->Enabled)
- // );
- RestartTimerCal( WM_MF_AGE8960_CONFIG_PFER_FAIL );
- if ( frmFatcory->rbAgilent8960->Checked )
- {
- if( ! m_rct_ctrl.RCT_confPFER( m_pRct, m_sCRYSTAL_AFC_FREQ_ERR_MEASUSE_COUNT ) )
- {
- CalErrorHandler( WM_MF_AGE8960_CONFIG_PFER_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : " + m_pRct->as_RCT + " < config PRER."
- );
- return false;
- }
- }
- else
- {
- if( ! m_rct_ctrl.RCT_sig_confPFER( m_pRct, m_sCRYSTAL_AFC_FREQ_ERR_MEASUSE_COUNT ) )
- {
- CalErrorHandler( WM_MF_AGE8960_CONFIG_PFER_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : " + m_pRct->as_RCT + " < config PRER."
- );
- return false;
- }
- }
- // Sleep(10000);
- float slope;
- unsigned short us_init_value;
- if(! AFCSlopeCal( vi_Band, sARFCN, slope, us_init_value ) )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_CONTROL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " TX AFC offset calibration "
- );
- return false;
- }
- #if 0
- int count=0;
- while( count<m_sCRYSTAL_AFC_RECURSIVE_TIMES )
- {
- count++;
- int band_idx = FreqBand_To_BandIdx(eFreqBand);
- int band;
- short s_arfcn;
- int tsc;
- if( frmFatcory->rbAgilent8960->Checked )
- {
- tsc = c_TSC;
- }
- else
- {
- tsc = 0;
- }
- if (!MF_rf_stop.REQ_Start())
- {
- CalErrorHandler( WM_MF_RF_STOP_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < stop RF fail."
- );
- return false;
- }
- MF_rf_tx_level_req->arfcn = sARFCN;
- MF_rf_tx_level_req->bsic = tsc;
- MF_rf_tx_level_req->power = i_CRYSTAL_AFC_PCL;
- MF_rf_tx_level_req->frames = -99;
- MF_rf_tx_level_req->dacValue = MASK_AFC_TRACKING | us_init_value;
- MF_rf_tx_level_req->burstTypeNB = NB_TX_RANDOM_WITH_TSC; // NB burst
- if ( META_Rf_NB_TX_r( m_META_HANDLE_Obj.Get_MainHandle(),
- MF_rf_tx_level_req,
- cb_MF_rf_tx_level_crystal,
- &MF_rf_tx_level_token,
- NULL
- ) != META_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< ARFCN = " + IntToStr( sARFCN ) +
- ", TSC = " + IntToStr( tsc ) +
- ", power = " + IntToStr( i_CRYSTAL_AFC_PCL ) +
- ", frames = " + IntToStr(i_N_TX) +
- ", dac value = " + IntToStr( us_init_value )
- );
- return false;
- }
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (! MF_rf_tx_level_cnf )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: TX level (! MF_rf_tx_level_cnf ) ."
- );
- return false;
- }
- Sleep(100);
- if( frmFatcory->rbAgilent8960->Checked )
- {
- if( ! FetchAverageFreqErr( FreqErr ) )
- {
- return false;
- }
- }
- else
- {
- if( ! FetchSigAverageFreqErr( FreqErr ) )
- {
- return false;
- }
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " AFC DAC = " + IntToStr( us_init_value ) + "," +
- " Freq error = " + Double_To_AnsiString(FreqErr)
- );
- } // while()
- #endif
- // if( frmFatcory->cbWriteTXAFCOffset->Checked )
- {
- double FreqErr_min;
- double FreqErr_norm;
- double FreqErr_norm_last = 0;
- double FreqErr_norm_min = 10000000.0;
- int count = 0;
- //bool b_first_time = true;
- short tx_afc_offset;
- short tx_afc_offset_last;
- short tx_afc_offset_min;
- //int band;
- //short arfcn;
- int pcl[4];
- int tsc;
- int afc_dac;
- int cs[4];
- int ta;
- int pattern;
- char TimeSlotMask;
- //band = band_idx;
- //arfcn = sARFCN;
- if( frmFatcory->rbAgilent8960->Checked )
- {
- tsc = m_cTSC;
- }
- else
- {
- tsc = 0;
- }
- if (!MF_rf_stop.REQ_Start())
- {
- CalErrorHandler( WM_MF_RF_STOP_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < stop RF fail."
- );
- return false;
- }
- MF_rf_tx_level_req->arfcn = sARFCN;
- MF_rf_tx_level_req->bsic = tsc;
- MF_rf_tx_level_req->power = i_CRYSTAL_AFC_PCL;
- MF_rf_tx_level_req->frames = -99;
- MF_rf_tx_level_req->dacValue = MASK_AFC_TRACKING | us_init_value;
- MF_rf_tx_level_req->burstTypeNB = NB_TX_RANDOM_WITH_TSC; // NB burst
- if ( META_Rf_NB_TX_r( m_pCal->i_MainMETAHandle,
- MF_rf_tx_level_req,
- cb_MF_rf_tx_level_crystal,
- &MF_rf_tx_level_token,
- NULL
- ) != META_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target< ARFCN = " + IntToStr( sARFCN ) +
- ", TSC = " + IntToStr( tsc ) +
- ", power = " + IntToStr( i_CRYSTAL_AFC_PCL ) +
- ", frames = " + IntToStr(i_N_TX) +
- ", dac value = " + IntToStr( us_init_value )
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target< ARFCN = " + IntToStr( sARFCN ) +
- ", TSC = " + IntToStr( tsc ) +
- ", power = " + IntToStr( i_CRYSTAL_AFC_PCL ) +
- ", frames = " + IntToStr(i_N_TX) +
- ", dac value = " + IntToStr( us_init_value )
- );
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (! MF_rf_tx_level_cnf )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: TX level (! MF_rf_tx_level_cnf ) ."
- );
- return false;
- }
- while( FreqErr_norm_last * FreqErr_norm >=0 && count<m_sCRYSTAL_AFC_RECURSIVE_TIMES )
- {
- Sleep(100);
- if( frmFatcory->rbAgilent8960->Checked )
- {
- if( ! FetchAverageFreqErr( FreqErr ) )
- {
- return false;
- }
- }
- else
- {
- if( ! FetchSigAverageFreqErr( FreqErr ) )
- {
- return false;
- }
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Freq error = " + Double_To_AnsiString(FreqErr)
- );
- FreqErr_norm_last = FreqErr_norm;
- FreqErr_norm = FreqErr * MF_rf_afc_ptr->Get_Afc_Slope_factor( band_idx );
- if( count == 0 || count == 1 )
- {
- FreqErr_norm_last = 0;
- }
- if( count == 0 )
- {
- S_AFC_RESULT navram_afc;
- MF_rf_afc_ptr->Get_AfcResult(navram_afc);
- tx_afc_offset = (short) (0 - FreqErr_norm) / (1.0*RF_AFC_SLOPE_DENOMINATOR/navram_afc.i_AfcSlopeInv);
- tx_afc_offset_last = tx_afc_offset;
- }
- else
- {
- tx_afc_offset_last = tx_afc_offset;
- if( FreqErr_norm >= 0 )
- {
- tx_afc_offset--;
- }
- else
- {
- tx_afc_offset++;
- }
- }
- if( FreqErr_norm_min > Abs_double( FreqErr_norm ) )
- {
- FreqErr_min = FreqErr;
- tx_afc_offset_min = tx_afc_offset_last;
- FreqErr_norm_min = Abs_double( FreqErr_norm );
- }
- MF_rf_apc_ptr->Set_TxAfcOffset( band_idx, tx_afc_offset );
- //int band_index = FreqBand_To_BandIdx( eFreqBand );
- MF_rf_apc_ptr->ConfirmCallback = ::ccb_write_apc_to_nvram;
- MF_rf_apc_ptr->REQ_RfSetRampTable_Start(m_pCal->ui_rf_id, m_pCal->b_TADOSupport, band_idx);
- // MF_rf_apc_ptr->ConfirmCallback = ::ccb_write_apc_to_nvram;
- // MF_rf_apc_ptr->REQ_Write_APC_To_NVRAM_Single_Band_Start( band_idx, p_cal->b_TADOSupport );
- RestartTimerCal( WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL );
- SUSPEND_CAL_THREAD
- CHECK_TERMINATE_BY_USER
- if (MF_rf_apc_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target< set TX AFC offset " +
- " TX AFC offset = " + IntToStr( tx_afc_offset )
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target< set TX AFC offset " +
- " TX AFC offset = " + IntToStr( tx_afc_offset )
- );
- count++;
- } // while( norm )
- if( count > m_sCRYSTAL_AFC_RECURSIVE_TIMES )
- {
- CalErrorHandler( WM_MF_RF_CRYSTAL_AFC_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " count reach limit"
- );
- return false;
- }
- if( tx_afc_offset != tx_afc_offset_min )
- {
- MF_rf_apc_ptr->Set_TxAfcOffset( band_idx, tx_afc_offset_min );
- //int band_index = FreqBand_To_BandIdx( eFreqBand );
- MF_rf_apc_ptr->ConfirmCallback = ::ccb_write_apc_to_nvram;
- MF_rf_apc_ptr->REQ_RfSetRampTable_Start(m_pCal->ui_rf_id, m_pCal->b_TADOSupport, band_idx);
- //MF_rf_apc_ptr->ConfirmCallback = ::ccb_write_apc_to_nvram;
- //MF_rf_apc_ptr->REQ_Write_APC_To_NVRAM_Single_Band_Start( band_idx, m_pCal->b_TADOSupport );
- RestartTimerCal( WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL );
- SUSPEND_CAL_THREAD
- CHECK_TERMINATE_BY_USER
- if (MF_rf_apc_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target< set TX AFC offset " +
- " TX AFC offset = " + IntToStr( tx_afc_offset_min )
- );
- return false;
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target< set TX AFC offset " +
- " TX AFC offset = " + IntToStr( tx_afc_offset_min )
- );
- }
- }
- sprintf(tempbuf, "%8.3f", FreqErr_min);
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- sprintf(tempbuf, "%8d", tx_afc_offset_min);
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- }
- Sleep(50);
- if (!MF_rf_stop.REQ_Start())
- {
- CalErrorHandler( WM_MF_RF_STOP_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < stop RF fail."
- );
- return false;
- }
-
- WriteAPCCalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath, FreqBand_To_BandIdx(eFreqBand));
- MF_rf_apc_ptr->ConfirmCallback = ::ccb_write_apc_to_nvram;
- MF_rf_apc_ptr->REQ_Write_APC_To_NVRAM_Single_Band_Start(m_pCal->ui_rf_id, band_idx, m_pCal->b_TADOSupport);
- RestartTimerCal( WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL );
- SUSPEND_CAL_THREAD
- CHECK_TERMINATE_BY_USER
- if (MF_rf_apc_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target< write TX AFC offset to NVRAM "
- );
- return false;
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target< write TX AFC offset to NVRAM. "
- );
- }
- eFreqBand++;
- } // while
- Sleep(50);
- if (!(m_pCal->s_CalItem.b_bt_cap_id_cal && (BTMODULE_MT6611 == m_pCal->s_bt_bb_id.id)))
- {
- if (!MF_rf_stop.REQ_Start())
- {
- CalErrorHandler(WM_MF_RF_STOP_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < stop RF fail."
- );
- return false;
- }
- }
- PostMessage(
- ctrl.hPostMsgDestHandle,
- WM_MF_RF_CRYSTAL_AFC_TRX_OFFSET_CALIBRATION_DONE,
- 0,
- 0
- );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================== AFC TRX offset calibration end ======================= "
- );
- return true;
- }
- //===========================================================================
- //----------------------------------------------------------------------------
- int __fastcall T_META_factory_calibration::Get_CRYSTAL_AFC_PCL( AnsiString as_band )
- {
- int i_pcl;
- ViInt16 vi_band = Get_AgeBand( as_CRYSTAL_AFC_BAND );;
- switch( vi_band )
- {
- case age1960_PGSM_BAND:
- case age1960_EGSM_BAND:
- i_pcl = i_CRYSTAL_AFC_GSM900_PCL;
- break;
- case age1960_DCS1800_BAND:
- i_pcl = i_CRYSTAL_AFC_DCS1800_PCL;
- break;
- case age1960_PCS1900_BAND:
- i_pcl = i_CRYSTAL_AFC_PCS1900_PCL;
- break;
- case age1960_GSM850_BAND:
- i_pcl = i_CRYSTAL_AFC_GSM850_PCL;
- break;
- }
- return i_pcl;
- }