T_TxIqImbalance.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:12k
- /*****************************************************************************
- * 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_PhaseError.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Phase error 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
- // misc
- #ifndef _BAND_UTILS_H_
- #include "band_utils.h"
- #endif
- #ifndef _MATH_UTILS_H_
- #include "math_utils.h"
- #endif
- #ifndef _AGE_MISC_H_
- #include "age_misc.h"
- #endif
- #ifndef _GSM_UTILS_H_
- #include "gsm_utils.h"
- #endif
- #ifndef _TIME_UTILS_H_
- #include "time_utils.h"
- #endif
- // equipment
- #ifndef _AGECOMMON_H_
- #include "agecommon.h"
- #endif
- // TX phase error calibration
- #ifndef _RF_OFFSET_IQ_SWEEP_INIT_AGE8960_H_
- #include "rf_offset_iq_sweep_init_age8960.h"
- #endif
- #ifndef _RF_TXIQ_H_
- #include "rf_txiq.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
- //----------------------------------------------------------------------------
- // phase error
- extern RfNbtx_Req *MF_rf_tx_level_req;
- extern CRFTXIQ* MF_rf_txiq_ptr;
- // Tthread
- extern T_META_factory_calibration* pt_calibration;
- extern bool is_suspend_cal; // in T_META_factory_calibration.cpp
- //------------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::TXIQGainImbalanceCal( void )
- {
- sIQ TrimIQ[] =
- {
- { 0, 0},
- { 7, -7},
- { -7, 7},
- };
- sIQ IQt;
- ViReal64 Xt;
- PostMessage(
- ctrl.hPostMsgDestHandle,
- WM_MF_RF_TX_IQ_GAIN_IMBALANCE_BEGIN,
- 0,
- 0
- );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ============== TX IQ gain imbalance calibration begin ================== "
- );
- if( ! TrimOffIQCalCommon() )
- {
- return false;
- }
- // get OOS
- // RFReq_BBTXCFG.TxOffsetI = 0;
- // RFReq_BBTXCFG.TxOffsetQ = 0;
- for(int i=0; i<3; i++)
- {
- rf_bb_tx_cfg2_req.TxTrimI = TrimIQ[i].I;
- rf_bb_tx_cfg2_req.TxTrimQ = TrimIQ[i].Q;
- if( META_Rf_SetBBTxCfg2_r(5000, &rf_bb_tx_cfg2_req, &rf_bb_tx_cfg2_cnf) != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_SET_BB_TX_CFG_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: RF set BB TX config fail."
- );
- return false;
- }
-
- CheckTerminateByUser
- Sleep(50);
- MF_rf_tx_level_req->arfcn = m_sTX_IQ_IMBALANCE_ARFCN;
- MF_rf_tx_level_req->bsic = m_cTSC;
- MF_rf_tx_level_req->power = i_TX_IQ_IMBALANCE_PCL;
- MF_rf_tx_level_req->frames = 1000;
- MF_rf_tx_level_req->dacValue = m_sDefault_value;
- if( Form_META_Factory->rbAgilent8960->Checked )
- {
- MF_rf_tx_level_req->burstTypeNB = NB_TX_ALL_ONES_WITHOUT_TSC;
- }
- else
- { MF_rf_tx_level_req->burstTypeNB = NB_TX_RANDOM_WITH_TSC;
- }
- if ( META_Rf_NB_TX_r(
- MF_rf_tx_level_req,
- ::ccb_MF_rf_tx_level_TrOff,
- &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_sTX_IQ_IMBALANCE_ARFCN ) +
- ", TSC = " + IntToStr( m_cTSC ) +
- ", power = " + IntToStr( i_TX_IQ_IMBALANCE_PCL ) +
- ", frames = " + IntToStr(i_N_TX) +
- ", dac value = " + IntToStr( m_sDefault_value )
- );
- return false;
- }
- SUSPEND_CAL_THREAD
- if( age1960_initMeasFcn(
- ctrl.vi,
- age1960_IQTUNING
- ) != VI_SUCCESS )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_MESA_FUNC_IQ_TUNNING_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Agilent 8960< Initialize TX IQ tunning mesaurement function fail."
- );
- return false;
- }
- if( age1960_fetchIQTuning_Q (
- ctrl.vi,
- age1960_IQ_ARRAY_MIN,
- &IQTIntegrity,
- &IQTSpurFreq,
- &IQTSpurLevel,
- IQTResultsArray,
- IQTFreqsArray,
- &IQTTuningCount
- ) != VI_SUCCESS )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_MESA_FUNC_IQ_TUNNING_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Agilent 8960> Read TX IQ tunning fail."
- );
- return false;
- }
- d_SBS[i] = get_TX_IQ_Imbalance(IQTFreqsArray, IQTResultsArray, IQTTuningCount);
- if( NAN == d_SBS[i] )
- {
- CalErrorHandler( WM_MF_RF_TX_DC_OFFSET_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Get TX IQ imbalance fail."
- );
- return false;
- }
- d_PSBS[i] = pow(10.0, d_SBS[i]/10.0);
- STOP_RF
- }
- Xt = 14*(d_PSBS[2]-d_PSBS[1]) / (2*(d_PSBS[2]+d_PSBS[1]-2*d_PSBS[0]));
- IQt.I = Xt /2;
- IQt.Q = Xt - IQt.I;
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ============== TX IQ gain imbalance calibration end ================== "
- );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ============== TX IQ gain imbalance check begin ================== "
- );
- // set BBTxCfg2
- rf_bb_tx_cfg2_req.TxTrimI = IQt.I;
- rf_bb_tx_cfg2_req.TxTrimQ = IQt.Q;
- if( META_Rf_SetBBTxCfg2_r(5000, &rf_bb_tx_cfg2_req, &rf_bb_tx_cfg2_cnf) != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_SET_BB_TX_CFG_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: RF set BB TX config fail."
- );
- return false;
- }
- Sleep(50);
- MF_rf_tx_level_req->arfcn = m_sTX_IQ_IMBALANCE_ARFCN;
- MF_rf_tx_level_req->bsic = m_cTSC;
- MF_rf_tx_level_req->power = i_TX_IQ_IMBALANCE_PCL;
- MF_rf_tx_level_req->frames = 1000;
- MF_rf_tx_level_req->dacValue = m_sDefault_value;
- MF_rf_tx_level_req->burstTypeNB = NB_TX_RANDOM_WITH_TSC;;
- if ( META_Rf_NB_TX_r(
- MF_rf_tx_level_req,
- ::ccb_MF_rf_tx_level_TrOff,
- &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_sTX_IQ_IMBALANCE_ARFCN ) +
- ", TSC = " + IntToStr( m_cTSC ) +
- ", power = " + IntToStr( i_TX_IQ_IMBALANCE_PCL ) +
- ", frames = " + IntToStr(i_N_TX) +
- ", dac value = " + IntToStr( m_sDefault_value )
- );
- return false;
- }
- SUSPEND_CAL_THREAD
- if( ! FetchRMSPhaseErr( &CheckPhaseErr ) )
- {
- return false;
- }
- // read TXIQ from NVRAM
- MF_rf_txiq_ptr->ConfirmCallback = ccb_read_txiq_from_nvram;
- MF_rf_txiq_ptr->REQ_Read_From_NVRAM_Start(m_pCal->rf_id);
- RestartTimerCal ( WM_MF_FDM_TXIQ_READ_FAIL );
- SUSPEND_CAL_THREAD
- if (MF_rf_txiq_ptr->Get_ConfirmState() != STATE_TXIQ_OK)
- {
- CalErrorHandler( WM_MF_FDM_TXIQ_READ_FAIL );
- pt_calibration->log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target< Read txiq value from NVRAM fail "
- );
- return false;
- }
- MF_rf_txiq_ptr->Set_BBTxParametersFromAutoK( &rf_bb_tx_cfg2_req );
- if( d_PHASE_ERROR_RMS_ERROR < CheckPhaseErr )
- {
- MF_rf_txiq_ptr->Set_BBTx_isCalibrated(0);
- }
- else
- {
- MF_rf_txiq_ptr->Set_BBTx_isCalibrated(BBTX_CALIBRATED_SCALE);
- }
-
- MF_rf_txiq_ptr->ConfirmCallback = ::ccb_write_txiq_to_nvram;
- MF_rf_txiq_ptr->REQ_Write_To_NVRAM_Start(m_pCal->rf_id);
- RestartTimerCal ( WM_MF_FDM_TXIQ_WRITE_FAIL );
- SUSPEND_CAL_THREAD
- if (MF_rf_txiq_ptr->Get_ConfirmState() != STATE_TXIQ_OK)
- {
- CalErrorHandler( WM_MF_FDM_TXIQ_WRITE_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target< Write txiq value to NVRAM fail "
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target< Write TXIQ value to NVRAM"
- );
- if( d_PHASE_ERROR_RMS_ERROR < CheckPhaseErr )
- {
- CalErrorHandler( WM_MF_RF_TX_IQ_GAIN_IMBALANCE_CHECK_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: TX IQ gain imbalance calibration."
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " PASS: TX IQ gain imbalance calibration."
- );
- PostMessage(
- ctrl.hPostMsgDestHandle,
- WM_MF_RF_TX_IQ_GAIN_IMBALANCE_CALIBRATION_DONE,
- 0,
- 0
- );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ============== TX IQ gain imbalance check end ================== "
- );
- }
- //------------------------------------------------------------------------------
- ViReal64 __fastcall T_META_factory_calibration::get_TX_IQ_Imbalance(ViReal64 *p_IQTFreqs, ViReal64 *p_IQTResults, ViInt32 IQTTuningCount)
- {
- for(int i=0; i<IQTTuningCount; i++)
- {
- if( *(p_IQTFreqs+i) == IQT_IQ_IMBALANCE_FREQ )
- {
- return *(p_IQTResults+i);
- }
- }
- return NAN;
- }