T_IP2_MT6139.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:133k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2001
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * T_IP2_MT6139.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * MT6139 IP2 calibration source
- *
- * Author:
- * -------
- * Andy Ueng (mtk00490)
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * $Revision$
- * $Modtime$
- * $Log$
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- #include <assert.h>
- #include <math.h>
- #pragma hdrstop
- #ifndef _T_META_FACTORY_CALIBRATION_H_
- #include "T_META_factory_calibration.H"
- #endif
- #ifndef _CAL_COMMON_H_
- #include "cal_common.h"
- #endif
- // form
- #ifndef _META_FACTORY_H_
- #include "META_Factory.h"
- #endif
- // call back
- #ifndef _META_FACTORY_NVRAM_CB_H_
- #include "meta_factory_nvram_cb.h"
- #endif
- #ifndef _META_FACTORY_RF_CB_H_
- #include "meta_factory_rf_cb.h"
- #endif
- // misc
- #ifndef _FT_UTILS_H_
- #include "ft_utils.h"
- #endif
- #ifndef _BAND_UTILS_H_
- #include "band_utils.h"
- #endif
- #ifndef _TIME_UTILS_H_
- #include "time_utils.h"
- #endif
- // equipment
- #ifndef _AGECOMMON_H_
- #include "agecommon.h"
- #endif
- //----------------------------------------------------------------------------
- // IP2
- extern CRFPM* MF_rf_pm_ptr;
- extern RfPm_Cnf *MF_rf_pm_cnf; // define in T_META_factory_calibration.cpp
- extern RfPm_Req *MF_rf_pm_req;
- // Tthread
- extern T_META_factory_calibration* pt_calibration;
- extern bool is_suspend_cal; // in T_META_factory_calibration.cpp
- //============================================================================
- //////////////////////// Call back ///////////////////////
- //============================================================================
- void ccb_SetMT6139CoefToReg( void )
- {
- frmFatcory->DisableAllCalTimer();
- if(is_suspend_cal == true && pt_calibration != NULL )
- {
- is_suspend_cal = false;
- pt_calibration->Resume();
- }
- }
- //----------------------------------------------------------------------------
- void ccb_GetAcodeFromReg( void )
- {
- frmFatcory->DisableAllCalTimer();
- if(is_suspend_cal == true && pt_calibration != NULL )
- {
- is_suspend_cal = false;
- pt_calibration->Resume();
- }
- }
- //----------------------------------------------------------------------------
- void ccb_GetBCcodeFromReg( void )
- {
- frmFatcory->DisableAllCalTimer();
- if(is_suspend_cal == true && pt_calibration != NULL )
- {
- is_suspend_cal = false;
- pt_calibration->Resume();
- }
- }
- //----------------------------------------------------------------------------
- void ccb_GetMT6139CW7FromReg( void )
- {
- frmFatcory->DisableAllCalTimer();
- if(is_suspend_cal == true && pt_calibration != NULL )
- {
- is_suspend_cal = false;
- pt_calibration->Resume();
- }
- }
- //----------------------------------------------------------------------------
- void ccb_SetMT6139CW2ToReg( void )
- {
- frmFatcory->DisableAllCalTimer();
- if(is_suspend_cal == true && pt_calibration != NULL )
- {
- is_suspend_cal = false;
- pt_calibration->Resume();
- }
- }
- //----------------------------------------------------------------------------
- void ccb_SetMT6139CW7ToReg( void )
- {
- frmFatcory->DisableAllCalTimer();
- if(is_suspend_cal == true && pt_calibration != NULL )
- {
- is_suspend_cal = false;
- pt_calibration->Resume();
- }
- }
- //----------------------------------------------------------------------------
- void ccb_SetBCcodeToReg( void )
- {
- frmFatcory->DisableAllCalTimer();
- if(is_suspend_cal == true && pt_calibration != NULL )
- {
- is_suspend_cal = false;
- pt_calibration->Resume();
- }
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- /////////////////////// MT6139B IP2 calibration ///////////////////////
- //---------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::IP2Cal_mt6139b_cal(void)
- {
- char tempbuf[256];
- PostMessage(
- ctrl.hPostMsgDestHandle,
- WM_MF_RF_IP2_BEGIN,
- 0,
- 0
- );
- log->Add( "n" + DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================== IP2 calibration begin ==================="
- );
- #if 0
- // read IP2 register from NVRAM
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_read_ip2_from_nvram;
- MF_rf_pm_ptr->REQ_Read_IP2Reg_From_NVRAM(final_rfid);
- CHECK_TERMINATE_BY_USER
- RestartTimerCal( WM_MF_NVRAM_IP2_READ_FAIL );
- SUSPEND_CAL_THREAD
- if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_NVRAM_IP2_READ_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target > read IP2 from NVRAM fail."
- );
- return false;
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target > read IP2 from NVRAM."
- );
- }
- MF_rf_pm_ptr->Get_ucMT6139Coef( uc_mt6139_coef );
- #endif
- if( ! m_rct_ctrl.RCT_operatingMode( m_pRct, OPERATING_MODE_GSM_BCH ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_OPERATION_MODE_FAIL );
- if ( frmFatcory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " Agilent 8960< Operation mode = GSM BCH"
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " cmu200 < Band = Operation mode = GSM BCH"
- );
- }
- return false;
- }
- short s_ARFCN;
- FrequencyBand eFreqBand = FrequencyBand850;
- int vi_Band;
- while (eFreqBand < FrequencyBandCount)
- {
- switch (eFreqBand)
- {
- case FrequencyBand850:
- {
- if (! IsFreqBankSupported( m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- vi_Band = age1960_GSM850_BAND;
- s_ARFCN = m_sIP2_arfcn_C0_GSM850;
- }
- break;
- case FrequencyBand900:
- {
- if (! IsFreqBankSupported( m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- vi_Band = age1960_EGSM_BAND;
- s_ARFCN = m_sIP2_arfcn_C0_GSM;
- }
- break;
- case FrequencyBand1800:
- {
- if (! IsFreqBankSupported( m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- vi_Band = age1960_DCS1800_BAND;
- s_ARFCN = m_sIP2_arfcn_C0_DCS;
- }
- break;
- case FrequencyBand1900:
- {
- if (! IsFreqBankSupported( m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- vi_Band = age1960_PCS1900_BAND;
- s_ARFCN = m_sIP2_arfcn_C0_PCS;
- }
- break;
- default:
- assert(false);
- break;
- } // switch
- if( ! m_rct_ctrl.RCT_cellBand( m_pRct, vi_Band ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
- if ( frmFatcory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " Agilent 8960< Band = " + ViBand_To_Str( vi_Band )
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " cmu200 > Band = " + ViBand_To_Str( vi_Band )
- );
- }
- return false;
- }
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- if ( frmFatcory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " Agilent 8960< band = " +
- FreqBand_To_Str( eFreqBand) );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " CMU 200< band = " +
- FreqBand_To_Str( eFreqBand) );
- }
- if( ! m_rct_ctrl.RCT_ContModTran( m_pRct ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
- if ( frmFatcory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " Agilent 8960< Set continuous tranmittion mode "
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " cmu200< Set continuous tranmittion mode "
- );
- }
- return false;
- }
- 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_PM_SELECT_BAND_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_PM_SELECT_BAND_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( ! m_rct_ctrl.RCT_BCHARFCN( m_pRct, s_ARFCN ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_BCH_ARFCN_FAIL );
- if ( frmFatcory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: Agilent 8960< BCH ARFCN = " +
- AnsiString(s_ARFCN)
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: cmu200 < BCH ARFCN = " +
- AnsiString(s_ARFCN)
- );
- }
- return false;
- }
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- if ( frmFatcory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " Agilent 8960< BCH ARFCN = " +
- AnsiString(s_ARFCN)
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " CMU 200< BCH ARFCN = " +
- AnsiString(s_ARFCN)
- );
- }
- i_IP2_AMCODEI[0]=i_IP2_AMCODEI1;
- i_IP2_AMCODEI[1]=i_IP2_AMCODEI2;
- i_IP2_AMCODEQ[0]=i_IP2_AMCODEQ1;
- i_IP2_AMCODEQ[1]=i_IP2_AMCODEQ2;
- for( int i=0; i<2; i++)
- {
- //===========================================================
- // 1.0 SS power off
- if( ! m_rct_ctrl.RCT_cellPower( m_pRct, d_IP2_CAL_P_DL_OFF_MT ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_POWER_FAIL );
- if( frmFatcory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: Agilent 8960< Power = " +
- Double_To_AnsiString( d_IP2_CAL_P_DL_OFF_MT) ) + " dBm";
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: cmu200< Power = " +
- Double_To_AnsiString( d_IP2_CAL_P_DL_OFF_MT) ) + " dBm";
- }
- return false;
- }
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- if( frmFatcory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " Agilent 8960< Power = " +
- Double_To_AnsiString( d_IP2_CAL_P_DL_OFF_MT) ) + " dBm";
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " CMU 200< Power = " +
- Double_To_AnsiString( d_IP2_CAL_P_DL_OFF_MT) ) + " dBm";
- }
- // if( frmFatcory->cbAFC->Checked || frmFatcory->cbRxPathLoss->Checked )
- // {
- // Sleep( 100 ); // wait Agilent 8960 ready!
- // }
- // else
- {
- Sleep( 200 ); // wait Agilent 8960 ready!
- }
- //-------------------------------------------------------------
- // 1.1 set AM, rxamcalmode=0
- uc_mt6139_coef.rx.coef[eFreqBand].amcodeI = i_IP2_AMCODEI[i];
- uc_mt6139_coef.rx.coef[eFreqBand].amcodeQ = i_IP2_AMCODEQ[i];
- uc_mt6139_coef.rx.rxamcalmode = RXAMCALMODE_MT6139B_READ_ACODE;
- MF_rf_pm_ptr->Set_ucMT6139Coef( uc_mt6139_coef );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < Set amcodeI = " + IntToStr( i_IP2_AMCODEI[i] ) +
- ", amcodeQ = " + IntToStr( i_IP2_AMCODEQ[i] ) +
- ", rxamcalmode=0"
- );
- // write AM to NVRAM
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_write_ip2_to_nvram;
- MF_rf_pm_ptr->REQ_Write_IP2Reg_To_NVRAM_Start(m_pCal->ui_rf_id);
- CHECK_TERMINATE_BY_USER
- RestartTimerCal(WM_MF_NVRAM_IP2_WRITE_FAIL);
- SUSPEND_CAL_THREAD
- E_METAAPP_RESULT_T state = MF_rf_pm_ptr->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_L1_RFSPECIALCOEF_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_L1_RFSPECIALCOEF_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_IP2_WRITE_FAIL);
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < write amcodeI, amcodeQ, rxamcalmode=0 to NVRAM fail."
- );
- }
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < write amcodeI, amcodeQ, rxamcalmode=0 to NVRAM."
- );
- //------------------------------------------------------------
- // 1.2 set gain
- // PM
- // if Agilent 8960 not read, target will get error power!
- MF_rf_pm_cnf->deviation = 0;
- MF_rf_pm_cnf->power = 0;
- MF_rf_pm_cnf->usedGain = 0;
- MF_rf_pm_cnf->extra_info.valid =0;
- MF_rf_pm_cnf->extra_info.iOffset=0;
- MF_rf_pm_cnf->extra_info.qOffset=0;
- MF_rf_pm_cnf->extra_info.validSamples =0;
- MF_rf_pm_req->arfcn = s_ARFCN-30;
- MF_rf_pm_req->sampleNoPerFrame = c_IP2_M_PM;
- MF_rf_pm_req->gain = d_IP2_GAIN *AVG_POWER_PC_SIDE_MULTIPLY ;
- MF_rf_pm_req->frames = i_IP2_N_PM;
- if( META_Rf_PM_r( m_pCal->i_MainMETAHandle, MF_rf_pm_req, MF_rf_pm_cnf_cb, &MF_rf_pm_token, NULL ) != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_IP2_PM_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: "+
- " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
- " sample per frame = " + IntToStr( c_IP2_M_PM) +
- " gain = " + IntToStr( MF_rf_pm_req->gain ) +
- " frames = " + IntToStr( i_IP2_N_PM)
- );
- return false;
- } // if
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
- ", sample per frame = " + IntToStr( c_IP2_M_PM) +
- ", gain = " + IntToStr( MF_rf_pm_req->gain ) +
- ", frames = " + IntToStr( i_IP2_N_PM)
- );
- // Sleep(100);// delay for power measurement
- RestartTimerCal( WM_MF_RF_IP2_PM_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_pm_cnf->ok )
- {
- CalErrorHandler( WM_MF_RF_IP2_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < ok = " + IntToStr(MF_rf_pm_cnf->ok) +
- ", power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
- ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
- ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
- ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
- ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
- ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
- ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target > power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
- ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
- ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
- ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
- ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
- ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
- ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
- );
- // EvalDC_I_sky[i] = MF_rf_pm_cnf->extra_info.iOffset;
- // EvalDC_Q_sky[i] = MF_rf_pm_cnf->extra_info.qOffset;
- //--------------------------------------------------------------
- // 1.3 read A code
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_GetAcodeFromReg;
- MF_rf_pm_ptr->Get_AcodeFromReg_Start( eFreqBand, uc_mt6139_coef, m_pCal->ui_rf_id );
- CHECK_TERMINATE_BY_USER
- RestartTimerCal( WM_MF_RF_IP2_GET_ACODE_FAIL );
- SUSPEND_CAL_THREAD
- if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_IP2_GET_ACODE_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target> get acode from register."
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target> get acode from register:" +
- " acodeI = " + IntToStr( uc_mt6139_coef.rx.coef[eFreqBand].acodeI ) +
- ", acodeQ = " + IntToStr( uc_mt6139_coef.rx.coef[eFreqBand].acodeQ )
- );
- //------------------------------------------------------------
- // 1.4 set stand-by mode(010)
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_SetMT6139CW2ToReg;
- MF_rf_pm_ptr->Set_MT6139CW2ToReg_Start( MODE_MT6139_CW2_STAND_BY, m_pCal->ui_rf_id );
- CHECK_TERMINATE_BY_USER
- RestartTimerCal( WM_MF_RF_IP2_SET_CW2_FAIL );
- SUSPEND_CAL_THREAD
- if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_IP2_SET_CW2_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < set CW2 to register."
- );
- return false;
- }
- //===============================================================
- // 2.1 set rxamcalmode=1, set A code, gain
- uc_mt6139_coef.rx.rxamcalmode = RXAMCALMODE_MT6139B_READ_BCCODE;
- MF_rf_pm_ptr->Set_ucMT6139Coef( uc_mt6139_coef );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < Set acodeI = " + IntToStr( uc_mt6139_coef.rx.coef[eFreqBand].acodeI ) +
- ", acodeQ = " + IntToStr( uc_mt6139_coef.rx.coef[eFreqBand].acodeQ ) +
- ", rxamcalmode=1"
- );
- // write rxamcalmode=1, A code
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_write_ip2_to_nvram;
- MF_rf_pm_ptr->REQ_Write_IP2Reg_To_NVRAM_Start(m_pCal->ui_rf_id);
- CHECK_TERMINATE_BY_USER
- RestartTimerCal(WM_MF_NVRAM_IP2_WRITE_FAIL);
- SUSPEND_CAL_THREAD
- state = MF_rf_pm_ptr->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_L1_RFSPECIALCOEF_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_L1_RFSPECIALCOEF_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_IP2_WRITE_FAIL);
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < write acodeI, acodeQ, rxamcalmode=1 to NVRAM fail."
- );
- }
- return false;
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < write acodeI, acodeQ, rxamcalmode=1 to NVRAM."
- );
- }
- // set gain, PM
- // if Agilent 8960 not read, target will get error power!
- MF_rf_pm_cnf->deviation = 0;
- MF_rf_pm_cnf->power = 0;
- MF_rf_pm_cnf->usedGain = 0;
- MF_rf_pm_cnf->extra_info.valid =0;
- MF_rf_pm_cnf->extra_info.iOffset=0;
- MF_rf_pm_cnf->extra_info.qOffset=0;
- MF_rf_pm_cnf->extra_info.validSamples =0;
- MF_rf_pm_req->arfcn = s_ARFCN-30;
- MF_rf_pm_req->sampleNoPerFrame = c_IP2_M_PM;
- MF_rf_pm_req->gain = d_IP2_GAIN *AVG_POWER_PC_SIDE_MULTIPLY ;
- MF_rf_pm_req->frames = i_IP2_N_PM;
- if( META_Rf_PM_r( m_pCal->i_MainMETAHandle, MF_rf_pm_req, MF_rf_pm_cnf_cb, &MF_rf_pm_token, NULL ) != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_IP2_PM_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: "+
- " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
- " sample per frame = " + IntToStr( c_IP2_M_PM) +
- " gain = " + IntToStr( MF_rf_pm_req->gain ) +
- " frames = " + IntToStr( i_IP2_N_PM)
- );
- return false;
- } // if
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
- ", sample per frame = " + IntToStr( c_IP2_M_PM) +
- ", gain = " + IntToStr( MF_rf_pm_req->gain ) +
- ", frames = " + IntToStr( i_IP2_N_PM)
- );
- // Sleep(100);// delay for power measurement
- RestartTimerCal( WM_MF_RF_IP2_PM_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_pm_cnf->ok )
- {
- CalErrorHandler( WM_MF_RF_IP2_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < ok = " + IntToStr(MF_rf_pm_cnf->ok) +
- ", power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
- ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
- ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
- ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
- ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
- ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
- ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target > power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
- ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
- ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
- ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
- ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
- ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
- ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
- );
- //------------------------------------------------------------
- // 2.2 read B & C code
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_GetBCcodeFromReg;
- MF_rf_pm_ptr->Get_BCcodeFromReg_Start( eFreqBand, uc_mt6139_coef, m_pCal->ui_rf_id );
- CHECK_TERMINATE_BY_USER
- RestartTimerCal( WM_MF_RF_IP2_GET_BCCODE_FAIL );
- SUSPEND_CAL_THREAD
- if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_IP2_GET_BCCODE_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target> read IP2 B,C code from register fail."
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target> get B, C code from register:" +
- " bcodeI = " + IntToStr( uc_mt6139_coef.rx.coef[eFreqBand].bcodeI ) +
- ", bcodeQ = " + IntToStr( uc_mt6139_coef.rx.coef[eFreqBand].bcodeQ ) +
- " ccodeI = " + IntToStr( uc_mt6139_coef.rx.coef[eFreqBand].ccodeI ) +
- ", ccodeQ = " + IntToStr( uc_mt6139_coef.rx.coef[eFreqBand].ccodeQ )
- );
- //--------------------------------------------------------------
- // 2.3 set stand-by mode(010)
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_SetMT6139CW2ToReg;
- MF_rf_pm_ptr->Set_MT6139CW2ToReg_Start( MODE_MT6139_CW2_STAND_BY, m_pCal->ui_rf_id );
- CHECK_TERMINATE_BY_USER
- RestartTimerCal( WM_MF_RF_IP2_SET_CW2_FAIL );
- SUSPEND_CAL_THREAD
- if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_IP2_SET_CW2_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < set CW2 to register."
- );
- return false;
- }
- //---------------------------------------------------------------
- // 2.4 set AUTO_CAL = 0 (CW7)
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_GetMT6139CW7FromReg;
- MF_rf_pm_ptr->Get_MT6139CW7FromReg_Start( m_mt6139_cw7, m_pCal->ui_rf_id );
- CHECK_TERMINATE_BY_USER
- RestartTimerCal( WM_MF_RF_IP2_SET_CW2_FAIL );
- SUSPEND_CAL_THREAD
- if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_IP2_GET_CW7_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target> get CW7 from register."
- );
- return false;
- }
- m_mt6139_cw7.uc_auto_cal = 0;
- m_mt6139_cw7.uc_man_cal = 1;
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_SetMT6139CW7ToReg;
- MF_rf_pm_ptr->Set_MT6139CW7ToReg_Start( m_mt6139_cw7, m_pCal->ui_rf_id );
- CHECK_TERMINATE_BY_USER
- RestartTimerCal( WM_MF_RF_IP2_SET_CW7_FAIL );
- SUSPEND_CAL_THREAD
- if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_IP2_SET_CW7_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < set CW7 auto_cal=0 to register."
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < set CW7 auto_cal=0 to register."
- );
-
- //---------------------------------------------------------------
- // 2.5 set I channel B & C code
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_SetBCcodeToReg;
- MF_rf_pm_ptr->Set_BCcodeToReg_Start( eFreqBand, uc_mt6139_coef, m_pCal->ui_rf_id );
- CHECK_TERMINATE_BY_USER
- RestartTimerCal( WM_MF_RF_IP2_SET_BCCODE_FAIL );
- SUSPEND_CAL_THREAD
- if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_IP2_SET_BCCODE_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < set B, C code to register."
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < set B, C code to register."
- );
- //===============================================================
- // 3.1 set rxamcalmode=2, set gain
- uc_mt6139_coef.rx.rxamcalmode = RXAMCALMODE_MT6139B_NORMAL;
- MF_rf_pm_ptr->Set_ucMT6139Coef( uc_mt6139_coef );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- "Target < rxamcalmode=2"
- );
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_write_ip2_to_nvram;
- MF_rf_pm_ptr->REQ_Write_IP2Reg_To_NVRAM_Start(m_pCal->ui_rf_id);
- CHECK_TERMINATE_BY_USER
- RestartTimerCal(WM_MF_NVRAM_IP2_WRITE_FAIL);
- SUSPEND_CAL_THREAD
- state = MF_rf_pm_ptr->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_L1_RFSPECIALCOEF_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_L1_RFSPECIALCOEF_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_IP2_WRITE_FAIL);
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < write rxamcalmode=2 to NVRAM fail."
- );
- }
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < write rxamcalmode=2 to NVRAM."
- );
- // 3.2 get MDC1 from DSP
- MF_rf_pm_cnf->deviation = 0;
- MF_rf_pm_cnf->power = 0;
- MF_rf_pm_cnf->usedGain = 0;
- MF_rf_pm_cnf->extra_info.valid =0;
- MF_rf_pm_cnf->extra_info.iOffset=0;
- MF_rf_pm_cnf->extra_info.qOffset=0;
- MF_rf_pm_cnf->extra_info.validSamples =0;
- MF_rf_pm_req->arfcn = s_ARFCN-30;
- MF_rf_pm_req->sampleNoPerFrame = c_IP2_M_PM;
- MF_rf_pm_req->gain = d_IP2_GAIN *AVG_POWER_PC_SIDE_MULTIPLY ;
- MF_rf_pm_req->frames = i_IP2_N_PM;
- if( META_Rf_PM_r( m_pCal->i_MainMETAHandle, MF_rf_pm_req, MF_rf_pm_cnf_cb, &MF_rf_pm_token, NULL ) != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_IP2_PM_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: "+
- " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
- " sample per frame = " + IntToStr( c_IP2_M_PM) +
- " gain = " + IntToStr( MF_rf_pm_req->gain ) +
- " frames = " + IntToStr( i_IP2_N_PM)
- );
- return false;
- } // if
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
- ", sample per frame = " + IntToStr( c_IP2_M_PM) +
- ", gain = " + IntToStr( MF_rf_pm_req->gain ) +
- ", frames = " + IntToStr( i_IP2_N_PM)
- );
- // Sleep(100);// delay for power measurement
- RestartTimerCal( WM_MF_RF_IP2_PM_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_pm_cnf->ok || !MF_rf_pm_cnf->extra_info.valid )
- {
- CalErrorHandler( WM_MF_RF_IP2_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Fail: Target < ok = " + IntToStr(MF_rf_pm_cnf->ok) +
- ", power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
- ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
- ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
- ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
- ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
- ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
- ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target > power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
- ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
- ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
- ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
- ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
- ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
- ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
- );
- EvalMDC1_I_mt6139[i] = MF_rf_pm_cnf->extra_info.iOffset;
- EvalMDC1_Q_mt6139[i] = MF_rf_pm_cnf->extra_info.qOffset;
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target > " +
- ", MDC1_I = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
- ", MDC1_Q = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset)
- );
- //================================================================
- // 4.0 SS power on
- if( ! m_rct_ctrl.RCT_cellPower( m_pRct, d_IP2_CAL_P_DL_ON_MT ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_POWER_FAIL );
- if( frmFatcory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: Agilent 8960< Power = " +
- Double_To_AnsiString( d_IP2_CAL_P_DL_ON_MT) ) + " dBm";
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: cmu200< Power = " +
- Double_To_AnsiString( d_IP2_CAL_P_DL_ON_MT) ) + " dBm";
- }
- return false;
- }
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- if( frmFatcory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " Agilent 8960< Power = " +
- Double_To_AnsiString( d_IP2_CAL_P_DL_ON_MT) ) + " dBm";
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " CMU 200< Power = " +
- Double_To_AnsiString( d_IP2_CAL_P_DL_ON_MT) ) + " dBm";
- }
- // if( frmFatcory->cbAFC->Checked || frmFatcory->cbRxPathLoss->Checked )
- // {
- // Sleep( 100 ); // wait Agilent 8960 ready!
- // }
- // else
- {
- Sleep( 200 ); // wait Agilent 8960 ready!
- }
- //--------------------------------------------------------
- // 4.1 get MDC2 from DSP
- MF_rf_pm_cnf->deviation = 0;
- MF_rf_pm_cnf->power = 0;
- MF_rf_pm_cnf->usedGain = 0;
- MF_rf_pm_cnf->extra_info.valid =0;
- MF_rf_pm_cnf->extra_info.iOffset=0;
- MF_rf_pm_cnf->extra_info.qOffset=0;
- MF_rf_pm_cnf->extra_info.validSamples =0;
- MF_rf_pm_req->arfcn = s_ARFCN-30;
- MF_rf_pm_req->sampleNoPerFrame = c_IP2_M_PM;
- MF_rf_pm_req->gain = d_IP2_GAIN *AVG_POWER_PC_SIDE_MULTIPLY ;
- MF_rf_pm_req->frames = i_IP2_N_PM;
- if( META_Rf_PM_r( m_pCal->i_MainMETAHandle, MF_rf_pm_req, MF_rf_pm_cnf_cb, &MF_rf_pm_token, NULL ) != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_IP2_PM_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: "+
- " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
- " sample per frame = " + IntToStr( c_IP2_M_PM) +
- " gain = " + IntToStr( MF_rf_pm_req->gain ) +
- " frames = " + IntToStr( i_IP2_N_PM)
- );
- return false;
- } // if
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
- ", sample per frame = " + IntToStr( c_IP2_M_PM) +
- ", gain = " + IntToStr( MF_rf_pm_req->gain ) +
- ", frames = " + IntToStr( i_IP2_N_PM)
- );
- // Sleep(100);// delay for power measurement
- RestartTimerCal( WM_MF_RF_IP2_PM_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_pm_cnf->ok || !MF_rf_pm_cnf->extra_info.valid )
- {
- CalErrorHandler( WM_MF_RF_IP2_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < ok = " + IntToStr(MF_rf_pm_cnf->ok) +
- ", power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
- ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
- ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
- ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
- ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
- ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
- ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target > power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
- ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
- ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
- ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
- ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
- ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
- ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
- );
- EvalMDC2_I_mt6139[i] = MF_rf_pm_cnf->extra_info.iOffset;
- EvalMDC2_Q_mt6139[i] = MF_rf_pm_cnf->extra_info.qOffset;
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target > " +
- ", MDC2_I = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
- ", MDC2_Q = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset)
- );
- //---------------------------------------------------------------
- // 4.2 set AUTO_CAL = 1 (CW7)
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_GetMT6139CW7FromReg;
- MF_rf_pm_ptr->Get_MT6139CW7FromReg_Start( m_mt6139_cw7, m_pCal->ui_rf_id );
- CHECK_TERMINATE_BY_USER
- RestartTimerCal( WM_MF_RF_IP2_SET_CW2_FAIL );
- SUSPEND_CAL_THREAD
- if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_IP2_GET_CW7_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target> get CW7 from register."
- );
- return false;
- }
- m_mt6139_cw7.uc_auto_cal = 1;
- m_mt6139_cw7.uc_man_cal = 0;
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_SetMT6139CW7ToReg;
- MF_rf_pm_ptr->Set_MT6139CW7ToReg_Start( m_mt6139_cw7, m_pCal->ui_rf_id );
- CHECK_TERMINATE_BY_USER
- RestartTimerCal( WM_MF_RF_IP2_SET_CW7_FAIL );
- SUSPEND_CAL_THREAD
- if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_IP2_SET_CW7_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < set CW7 auto_cal=1 to register."
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < set CW7 auto_cal=1 to register."
- );
-
- } // for
- //============================== Evaluate =======================
- // 5.0 SS power off
- if( ! m_rct_ctrl.RCT_cellPower( m_pRct, d_IP2_CAL_P_DL_OFF_MT ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_POWER_FAIL );
- if( frmFatcory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: Agilent 8960< Power = " +
- Double_To_AnsiString( d_IP2_CAL_P_DL_OFF_MT) ) + " dBm";
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: cmu200< Power = " +
- Double_To_AnsiString( d_IP2_CAL_P_DL_OFF_MT) ) + " dBm";
- }
- return false;
- }
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- if( frmFatcory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " Agilent 8960< Power = " +
- Double_To_AnsiString( d_IP2_CAL_P_DL_OFF_MT) ) + " dBm";
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " CMU 200< Power = " +
- Double_To_AnsiString( d_IP2_CAL_P_DL_OFF_MT) ) + " dBm";
- }
- int c0_I = i_IP2_AMCODEI[0];
- int c0_Q = i_IP2_AMCODEQ[0];
- int c1_I = i_IP2_AMCODEI[1];
- int c1_Q = i_IP2_AMCODEQ[1];
- int f0_I = EvalMDC2_I_mt6139[0]-EvalMDC1_I_mt6139[0];
- int f1_I = EvalMDC2_I_mt6139[1]-EvalMDC1_I_mt6139[1];
- int f0_Q = EvalMDC2_Q_mt6139[0]-EvalMDC1_Q_mt6139[0];
- int f1_Q = EvalMDC2_Q_mt6139[1]-EvalMDC1_Q_mt6139[1];
- unsigned char amcode_I;
- unsigned char amcode_Q;
- if( (c1_I - c0_I) == 0 && (c1_Q - c0_Q)==0 ) return false;
- // display evaluate error
- if( (c1_I - c0_I) != 0 )
- {
- float slope_I = 1.0*(f1_I - f0_I) / (c1_I - c0_I);
- int offset_I = f0_I - slope_I*c0_I;
- if( slope_I != 0 )
- {
- amcode_I = - offset_I/slope_I;
- }
- }
- if( (c1_Q - c0_Q) != 0 )
- {
- float slope_Q = 1.0*(f1_Q - f0_Q) / (c1_Q - c0_Q);
- int offset_Q = f0_Q - slope_Q*c0_Q;
- if( slope_Q != 0 )
- {
- amcode_Q = - offset_Q/slope_Q;
- }
- }
- uc_mt6139_coef.rx.coef[eFreqBand].amcodeI = amcode_I;
- uc_mt6139_coef.rx.coef[eFreqBand].amcodeQ = amcode_Q;
- uc_mt6139_coef.rx.rxamcalmode = RXAMCALMODE_MT6139C_READ_ACODE;
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Evaluate: amcodeI = " + IntToStr(amcode_I) +
- ", amcodeQ = " + IntToStr(amcode_Q)
- );
- sprintf(tempbuf, "%8d", amcode_I);
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- sprintf(tempbuf, "%8d", amcode_Q);
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- MF_rf_pm_ptr->Set_ucMT6139Coef( uc_mt6139_coef );
- // write IP2 register to NVRAM
- MF_rf_pm_ptr->ConfirmCallback = ccb_write_ip2_to_nvram;
- MF_rf_pm_ptr->REQ_Write_IP2Reg_To_NVRAM_Start(m_pCal->ui_rf_id);
- CHECK_TERMINATE_BY_USER
- RestartTimerCal(WM_MF_NVRAM_IP2_WRITE_FAIL);
- SUSPEND_CAL_THREAD
- E_METAAPP_RESULT_T state = MF_rf_pm_ptr->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_L1_RFSPECIALCOEF_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_L1_RFSPECIALCOEF_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_IP2_WRITE_FAIL);
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < write amcodeI, amcode_Q, rxamcalmode=0 to NVRAM fail."
- );
- }
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < write amcodeI, amcode_Q, rxamcalmode=0 to NVRAM"
- );
-
- //------------------------------------------------------------
- #if 0
- // set rxamcalmode=0, gain
- if( !MF_rf_pm_ptr->Set_ucMT6139Coef( uc_mt6139_coef ) )
- {
- CalErrorHandler( WM_MF_RF_IP2_SET_MT6139_COEF_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: IP2 Set MT6139 coefficient fail."
- );
- return false;
- }
- // write AM to NVRAM
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_write_ip2_to_nvram;
- MF_rf_pm_ptr->REQ_Write_IP2Reg_To_NVRAM(m_pCal->ui_rf_id);
- CHECK_TERMINATE_BY_USER
- RestartTimerCal( WM_MF_NVRAM_IP2_READ_FAIL );
- SUSPEND_CAL_THREAD
- // if (MF_rf_pm_ptr->ConfirmState != METAAPP_SUCCESS)
- if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_NVRAM_IP2_READ_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < write IP2 to NVRAM fail."
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < write IP2 to NVRAM."
- );
- #endif
- // set gain, PM
- // if Agilent 8960 not read, target will get error power!
- MF_rf_pm_cnf->deviation = 0;
- MF_rf_pm_cnf->power = 0;
- MF_rf_pm_cnf->usedGain = 0;
- MF_rf_pm_cnf->extra_info.valid =0;
- MF_rf_pm_cnf->extra_info.iOffset=0;
- MF_rf_pm_cnf->extra_info.qOffset=0;
- MF_rf_pm_cnf->extra_info.validSamples =0;
- MF_rf_pm_req->arfcn = s_ARFCN-30;
- MF_rf_pm_req->sampleNoPerFrame = c_IP2_M_PM;
- MF_rf_pm_req->gain = d_IP2_GAIN *AVG_POWER_PC_SIDE_MULTIPLY ;
- MF_rf_pm_req->frames = i_IP2_N_PM;
- if( META_Rf_PM_r( m_pCal->i_MainMETAHandle, MF_rf_pm_req, MF_rf_pm_cnf_cb, &MF_rf_pm_token, NULL ) != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_IP2_PM_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: "+
- " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
- " sample per frame = " + IntToStr(c_IP2_M_PM) +
- " gain = " + IntToStr( MF_rf_pm_req->gain ) +
- " frames = " + IntToStr( i_IP2_N_PM)
- );
- return false;
- } // if
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
- ", sample per frame = " + IntToStr( c_IP2_M_PM) +
- ", gain = " + IntToStr( MF_rf_pm_req->gain ) +
- ", frames = " + IntToStr( i_IP2_N_PM)
- );
- // Sleep(100);// delay for power measurement
- RestartTimerCal( WM_MF_RF_IP2_PM_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_pm_cnf->ok )
- {
- CalErrorHandler( WM_MF_RF_IP2_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < ok = " + IntToStr(MF_rf_pm_cnf->ok) +
- ", power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
- ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
- ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
- ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
- ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
- ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
- ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target > power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
- ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
- ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
- ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
- ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
- ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
- ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
- );
- //--------------------------------------------------------------
- // read A code
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_GetAcodeFromReg;
- MF_rf_pm_ptr->Get_AcodeFromReg_Start( eFreqBand, uc_mt6139_coef, m_pCal->ui_rf_id );
- CHECK_TERMINATE_BY_USER
- RestartTimerCal( WM_MF_RF_IP2_GET_ACODE_FAIL );
- SUSPEND_CAL_THREAD
- if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_IP2_GET_ACODE_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target> get acode from register."
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target> get acode from register:" +
- " acodeI = " + IntToStr( uc_mt6139_coef.rx.coef[eFreqBand].acodeI ) +
- ", acodeQ = " + IntToStr( uc_mt6139_coef.rx.coef[eFreqBand].acodeQ )
- );
- sprintf( tempbuf, "%8d", uc_mt6139_coef.rx.coef[eFreqBand].acodeI );
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- sprintf( tempbuf, "%8d", uc_mt6139_coef.rx.coef[eFreqBand].acodeQ );
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- // write IP2 register to NVRAM
- uc_mt6139_coef.rx.rxamcalmode = RXAMCALMODE_MT6139B_NORMAL;
- MF_rf_pm_ptr->Set_ucMT6139Coef( uc_mt6139_coef );
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_write_ip2_to_nvram;
- MF_rf_pm_ptr->REQ_Write_IP2Reg_To_NVRAM_Start(m_pCal->ui_rf_id);
- CHECK_TERMINATE_BY_USER
- RestartTimerCal(WM_MF_NVRAM_IP2_WRITE_FAIL);
- SUSPEND_CAL_THREAD
- state = MF_rf_pm_ptr->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_L1_RFSPECIALCOEF_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_L1_RFSPECIALCOEF_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_IP2_WRITE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < write acodeI, acodeQ, rxamcalmode=2 to NVRAM fail."
- );
- }
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < write acodeI, acodeQ, rxamcalmode=2 to NVRAM."
- );
- if (!WriteIP2CalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath, m_pCal->ui_rf_id, eFreqBand ) )
- {
- CalErrorHandler( WM_MF_RF_AFC_WRITE_CAL_RESULT_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : write IP2 parameter to cal file "
- );
- return false;
- }
- #if 0
- //------------------------------------------------------------
- // set rxamcalmode=0, gain
- // uc_mt6139_coef.rx.rxamcalmode = RXAMCALMODE_READ_ACODE;
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_SetMT6139CoefToReg;
- MF_rf_pm_ptr->Set_MT6139CoefToReg_Start(uc_mt6139_coef);
- CHECK_TERMINATE_BY_USER
- RestartTimerCal( WM_MF_RF_IP2_SET_AMCALMODE_FAIL );
- SUSPEND_CAL_THREAD
- if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_RF_IP2_SET_AMCALMODE_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < set rxamcalmode=2 to register."
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < set rxamcalmode=2 to register."
- );
- #endif
- eFreqBand++;
- } // while
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " =================== IP2 calibration end ==================== n "
- );
- frmFatcory->DisableAllCalTimer();
- return true;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- /////////////////////// MT6139C IP2 calibration ///////////////////////
- //---------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::IP2Cal_mt6139c_cal( void )
- {
- char tempbuf[256];
- PostMessage(
- ctrl.hPostMsgDestHandle,
- WM_MF_RF_IP2_BEGIN,
- 0,
- 0
- );
- log->Add( "n" + DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================== IP2 calibration begin ==================="
- );
- #if 0
- // read IP2 register from NVRAM
- MF_rf_pm_ptr->ConfirmCallback = ::ccb_read_ip2_from_nvram;
- MF_rf_pm_ptr->REQ_Read_IP2Reg_From_NVRAM(m_pCal->ui_rf_id);
- CHECK_TERMINATE_BY_USER
- RestartTimerCal( WM_MF_NVRAM_IP2_READ_FAIL );
- SUSPEND_CAL_THREAD
- // if (MF_rf_pm_ptr->ConfirmState != METAAPP_SUCCESS)
- if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
- {
- CalErrorHandler( WM_MF_NVRAM_IP2_READ_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target > read IP2 from NVRAM fail."
- );
- return false;
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target > read IP2 from NVRAM."
- );
- }
- MF_rf_pm_ptr->Get_ucMT6139Coef( uc_mt6139_coef );
- #endif
- if( ! m_rct_ctrl.RCT_operatingMode( m_pRct, OPERATING_MODE_GSM_BCH ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_OPERATION_MODE_FAIL );
- if ( frmFatcory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " Agilent 8960< Operation mode = GSM BCH"
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " cmu200 < Band = Operation mode = GSM BCH"
- );
- }
- return false;
- }
- short s_ARFCN;
- short s_TCH_ARFCN;
- FrequencyBand eFreqBand = FrequencyBand850;
- int vi_Band;
- while ( eFreqBand < FrequencyBandCount )
- {
- switch (eFreqBand)
- {
- case FrequencyBand850:
- {
- if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }