T_PhaseError.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:43k
- /*****************************************************************************
- * 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) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * 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::TxPhaseErrorCal( void )
- {
- char tempbuf[256];
- PostMessage(
- ctrl.hPostMsgDestHandle,
- WM_MF_RF_TX_PHASE_ERR_BEGIN,
- 0,
- 0
- );
- if( ! TrimOffIQCalCommon() )
- {
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ============== TX phase error calibration precheck begin ================== "
- );
- MF_rf_tx_level_req->arfcn = m_sPHASE_ERROR_ARFCN;
- MF_rf_tx_level_req->bsic = m_cTSC;
- MF_rf_tx_level_req->power = i_PHASE_ERROR_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( s_ARFCN ) +
- ", TSC = " + IntToStr( m_cTSC ) +
- ", power = " + IntToStr( i_PHASE_ERROR_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( ! FetchRMSPhaseErr( &PFERRMSError ) )
- {
- return false;
- }
- #if 0
- if (! cfg->get_PHASE_ERROR_RMS_ERROR( d_PHASE_ERROR_RMS_ERROR ))
- {
- CalErrorHandler( WM_MF_CFG_READ_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Read config file fail(PHASE_ERROR_RMS_ERROR)."
- );
- return false;
- }
- #endif
-
-
- if( d_PHASE_ERROR_RMS_ERROR < PFERRMSError )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: TX phase error calibration. Precheck RMS phase error = " + Double_To_AnsiString(PFERRMSError) +
- ", Max RMS phase error = " + Double_To_AnsiString( d_PHASE_ERROR_RMS_ERROR )
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " PASS: TX phase error calibration. Precheck RMS phase error = " + Double_To_AnsiString(PFERRMSError) +
- ", Max RMS phase error = " + Double_To_AnsiString( d_PHASE_ERROR_RMS_ERROR )
- );
- PostMessage(
- ctrl.hPostMsgDestHandle,
- WM_MF_RF_TX_PHASE_ERR_CALIBRATION_DONE,
- 0,
- 0
- );
- return true;
- }
- // Sleep(50);
- STOP_RF
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ============== TX phase error calibration precheck end ================== "
- );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ============== TX phase error calibration begin ================== "
- );
- // calibrate Offset I
- bool iscalibrated[64];
- int i;
- for(i=0; i<sizeof(iscalibrated); i++)
- {
- iscalibrated[i] = false;
- }
- min_OffIPhErr.Off_IQ = 0;
- min_OffIPhErr.PhaseErr = 100000.0;
- begin_Offset_IQ = MIN_OFFSET_IQ;
- end_Offset_IQ = MAX_OFFSET_IQ;
- //last_Off_IQ[0] = 0;
- //last_Off_IQ[1] = 0;
- cal_OffIQPhErr[0].Off_IQ = MIN_OFFSET_IQ;
- cal_OffIQPhErr[1].Off_IQ = MAX_OFFSET_IQ;
- while( min_OffIPhErr.PhaseErr !=0.0 && cal_OffIQPhErr[0].Off_IQ < cal_OffIQPhErr[1].Off_IQ &&
- begin_Offset_IQ < end_Offset_IQ &&
- MIN_OFFSET_IQ<=cal_OffIQPhErr[0].Off_IQ && cal_OffIQPhErr[0].Off_IQ<=MAX_OFFSET_IQ &&
- MIN_OFFSET_IQ<=cal_OffIQPhErr[1].Off_IQ && cal_OffIQPhErr[1].Off_IQ<=MAX_OFFSET_IQ &&
- !( cal_OffIQPhErr[0].Off_IQ == last_Off_IQ[0] && cal_OffIQPhErr[1].Off_IQ == last_Off_IQ[1])
- )
- {
- last_Off_IQ[0] = cal_OffIQPhErr[0].Off_IQ;
- last_Off_IQ[1] = cal_OffIQPhErr[1].Off_IQ;
- cal_OffIQPhErr[0].Off_IQ = (begin_Offset_IQ + (begin_Offset_IQ+end_Offset_IQ)/2)/2;
- cal_OffIQPhErr[1].Off_IQ = (end_Offset_IQ + (begin_Offset_IQ+end_Offset_IQ)/2)/2;
- // log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " begin = " + IntToStr( begin_Offset_IQ ) +
- // ", end = " + IntToStr( end_Offset_IQ ) +
- // ", Off0 = " + IntToStr( cal_OffIQPhErr[0].Off_IQ ) +
- // ", Off1 = " + IntToStr( cal_OffIQPhErr[1].Off_IQ )
- // );
- for(i=0; i<2; i++)
- {
- if( iscalibrated[cal_OffIQPhErr[i].Off_IQ-MIN_OFFSET_IQ] ) continue;
- // log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " begin = " + IntToStr( begin_Offset_IQ ) +
- /// ", end = " + IntToStr( end_Offset_IQ ) +
- // ", OffI = " + IntToStr( cal_OffIQPhErr[i].Off_IQ )
- // );
-
- // set BBTxCfg2
- rf_bb_tx_cfg2_req.TxOffsetI = cal_OffIQPhErr[i].Off_IQ;
- if( META_Rf_SetBBTxCfg2_r(500, &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;
- }
- MF_rf_tx_level_req->arfcn = m_sPHASE_ERROR_ARFCN;
- MF_rf_tx_level_req->bsic = m_cTSC;
- MF_rf_tx_level_req->power = i_PHASE_ERROR_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_ALL_ONES_WITHOUT_TSC;
- 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( s_ARFCN ) +
- ", TSC = " + IntToStr( m_cTSC ) +
- ", power = " + i_PHASE_ERROR_PCL +
- ", frames = " + IntToStr(i_N_TX) +
- ", dac value = " + IntToStr( m_sDefault_value )
- );
- return false;
- }
- SUSPEND_CAL_THREAD
- if( ! FetchRMSPhaseErr( &PFERRMSError ) )
- {
- return false;
- }
- cal_OffIQPhErr[i].PhaseErr = PFERRMSError;
- // Sleep(50);
- STOP_RF
- } // for
- iscalibrated[cal_OffIQPhErr[0].Off_IQ-MIN_OFFSET_IQ] = 1;
- iscalibrated[cal_OffIQPhErr[1].Off_IQ-MIN_OFFSET_IQ] = 1;
- if( Abs_double(cal_OffIQPhErr[0].PhaseErr) < Abs_double(cal_OffIQPhErr[1].PhaseErr) )
- {
- if( Abs_double(cal_OffIQPhErr[0].PhaseErr) < min_OffIPhErr.PhaseErr )
- {
- min_OffIPhErr.Off_IQ = cal_OffIQPhErr[0].Off_IQ;
- min_OffIPhErr.PhaseErr = Abs_double(cal_OffIQPhErr[0].PhaseErr);
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " OffsetI = " + IntToStr( min_OffIPhErr.Off_IQ ) +
- ", cal phase error = " + Double_To_AnsiString( min_OffIPhErr.PhaseErr )
- );
- //log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " cal phase error = " + Double_To_AnsiString( min_OffIPhErr.PhaseErr )
- // );
- }
- // if( (begin_Offset_IQ+end_Offset_IQ)%2 == 0 )
- // {
- // end_Offset_IQ = (begin_Offset_IQ+end_Offset_IQ)/2;
- // }
- // else
- // {
- // end_Offset_IQ = (begin_Offset_IQ+end_Offset_IQ)/2 + 1;
- //}
- end_Offset_IQ = (begin_Offset_IQ+end_Offset_IQ)/2;
- }
- else
- {
- if( Abs_double(cal_OffIQPhErr[1].PhaseErr) < min_OffIPhErr.PhaseErr )
- {
- min_OffIPhErr.Off_IQ = cal_OffIQPhErr[1].Off_IQ;
- min_OffIPhErr.PhaseErr = Abs_double(cal_OffIQPhErr[1].PhaseErr);
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " OffsetI = " + IntToStr( min_OffIPhErr.Off_IQ ) +
- ", cal phase error = " + Double_To_AnsiString( min_OffIPhErr.PhaseErr )
- );
- // log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " cal phase error = " + Double_To_AnsiString( min_OffIPhErr.PhaseErr )
- // );
- }
- // if( (begin_Offset_IQ+end_Offset_IQ)%2 == 0 )
- // {
- // begin_Offset_IQ = (begin_Offset_IQ+end_Offset_IQ)/2;
- // }
- // else
- // {
- // begin_Offset_IQ = (begin_Offset_IQ+end_Offset_IQ)/2 - 1;
- // }
- begin_Offset_IQ = (begin_Offset_IQ+end_Offset_IQ)/2;
- }
- }//while
- // set BBTxCfg2
- rf_bb_tx_cfg2_req.TxOffsetI = min_OffIPhErr.Off_IQ;
- if( META_Rf_SetBBTxCfg2_r(500, &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;
- }
- MF_rf_txiq_ptr->Set_BBTx_OffsetI( rf_bb_tx_cfg2_req.TxOffsetI );
- // calibrate Offset Q
- for(i=0; i<sizeof(iscalibrated); i++)
- {
- iscalibrated[i] = false;
- }
- min_OffQPhErr.Off_IQ = 0;
- min_OffQPhErr.PhaseErr = 100000.0;
- begin_Offset_IQ = MIN_OFFSET_IQ;
- end_Offset_IQ = MAX_OFFSET_IQ;
- last_Off_IQ[0] = 0;
- last_Off_IQ[1] = 0;
- cal_OffIQPhErr[0].Off_IQ = MIN_OFFSET_IQ;
- cal_OffIQPhErr[1].Off_IQ = MAX_OFFSET_IQ;
- while( min_OffQPhErr.PhaseErr !=0.0 && cal_OffIQPhErr[0].Off_IQ < cal_OffIQPhErr[1].Off_IQ &&
- begin_Offset_IQ < end_Offset_IQ &&
- MIN_OFFSET_IQ<=cal_OffIQPhErr[0].Off_IQ && cal_OffIQPhErr[0].Off_IQ<=MAX_OFFSET_IQ &&
- MIN_OFFSET_IQ<=cal_OffIQPhErr[1].Off_IQ && cal_OffIQPhErr[1].Off_IQ<=MAX_OFFSET_IQ &&
- !( cal_OffIQPhErr[0].Off_IQ == last_Off_IQ[0] && cal_OffIQPhErr[1].Off_IQ == last_Off_IQ[1])
- )
- {
- last_Off_IQ[0] = cal_OffIQPhErr[0].Off_IQ;
- last_Off_IQ[1] = cal_OffIQPhErr[1].Off_IQ;
- cal_OffIQPhErr[0].Off_IQ = (begin_Offset_IQ + (begin_Offset_IQ+end_Offset_IQ)/2)/2;
- cal_OffIQPhErr[1].Off_IQ = (end_Offset_IQ + (begin_Offset_IQ+end_Offset_IQ)/2)/2;
- //log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " begin = " + IntToStr( begin_Offset_IQ ) +
- // ", end = " + IntToStr( end_Offset_IQ ) +
- // ", Off0 = " + IntToStr( cal_OffIQPhErr[0].Off_IQ ) +
- // ", Off1 = " + IntToStr( cal_OffIQPhErr[1].Off_IQ )
- // );
- for(int i=0; i<2; i++)
- {
- if( iscalibrated[cal_OffIQPhErr[i].Off_IQ-MIN_OFFSET_IQ] ) continue;
- //log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " begin = " + IntToStr( begin_Offset_IQ ) +
- /// ", end = " + IntToStr( end_Offset_IQ ) +
- // ", OffQ = " + IntToStr( cal_OffIQPhErr[i].Off_IQ )
- // );
- // set BBTxCfg2
- rf_bb_tx_cfg2_req.TxOffsetQ = cal_OffIQPhErr[i].Off_IQ;
- if( META_Rf_SetBBTxCfg2_r(500, &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;
- }
- MF_rf_tx_level_req->arfcn = m_sPHASE_ERROR_ARFCN;
- MF_rf_tx_level_req->bsic = m_cTSC;
- MF_rf_tx_level_req->power = i_PHASE_ERROR_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_ALL_ONES_WITHOUT_TSC;
- 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( s_ARFCN ) +
- ", TSC = " + IntToStr( m_cTSC ) +
- ", power = " + IntToStr( i_PHASE_ERROR_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( ! FetchRMSPhaseErr( &PFERRMSError ) )
- {
- return false;
- }
- cal_OffIQPhErr[i].PhaseErr = PFERRMSError;
- //Sleep(50);
- STOP_RF
- } // for
- iscalibrated[cal_OffIQPhErr[0].Off_IQ-MIN_OFFSET_IQ] = 1;
- iscalibrated[cal_OffIQPhErr[1].Off_IQ-MIN_OFFSET_IQ] = 1;
- if( Abs_double(cal_OffIQPhErr[0].PhaseErr) < Abs_double(cal_OffIQPhErr[1].PhaseErr) )
- {
- if( Abs_double(cal_OffIQPhErr[0].PhaseErr) < min_OffQPhErr.PhaseErr )
- {
- min_OffQPhErr.Off_IQ = cal_OffIQPhErr[0].Off_IQ;
- min_OffQPhErr.PhaseErr = Abs_double(cal_OffIQPhErr[0].PhaseErr);
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " OffsetQ = " + IntToStr( min_OffQPhErr.Off_IQ ) +
- ", cal phase error = " + Double_To_AnsiString( min_OffQPhErr.PhaseErr )
- );
- }
- //if( (begin_Offset_IQ+end_Offset_IQ)%2 == 0 )
- //{
- // end_Offset_IQ = (begin_Offset_IQ+end_Offset_IQ)/2;
- //}
- //else
- //{
- // end_Offset_IQ = (begin_Offset_IQ+end_Offset_IQ)/2 + 1;
- //}
- end_Offset_IQ = (begin_Offset_IQ+end_Offset_IQ)/2;
- }
- else
- {
- if( Abs_double(cal_OffIQPhErr[1].PhaseErr) < min_OffQPhErr.PhaseErr )
- {
- min_OffQPhErr.Off_IQ = cal_OffIQPhErr[1].Off_IQ;
- min_OffQPhErr.PhaseErr = Abs_double(cal_OffIQPhErr[1].PhaseErr);
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Offset Q = " + IntToStr( min_OffQPhErr.Off_IQ ) +
- ", cal phase error = " + Double_To_AnsiString( min_OffQPhErr.PhaseErr )
- );
- }
- // if( (begin_Offset_IQ+end_Offset_IQ)%2 == 0 )
- // {
- // begin_Offset_IQ = (begin_Offset_IQ+end_Offset_IQ)/2;
- // }
- // else
- // {
- // begin_Offset_IQ = (begin_Offset_IQ+end_Offset_IQ)/2 - 1;
- // }
- begin_Offset_IQ = (begin_Offset_IQ+end_Offset_IQ)/2+1;
- }
- }//while
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Offset I = " + IntToStr( min_OffIPhErr.Off_IQ ) +
- ", Offset Q = " + IntToStr( min_OffQPhErr.Off_IQ ) +
- ", calibrated phase error = " + Double_To_AnsiString( min_OffQPhErr.PhaseErr )
- );
- // set BBTxCfg2
- rf_bb_tx_cfg2_req.TxOffsetQ = min_OffQPhErr.Off_IQ;
- if( META_Rf_SetBBTxCfg2_r(500, &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;
- }
- MF_rf_txiq_ptr->Set_BBTx_OffsetQ( rf_bb_tx_cfg2_req.TxOffsetQ );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ============== TX phase error calibration end ================== "
- );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ============== TX phase error calibration check begin ================== "
- );
- 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( s_ARFCN ) +
- ", TSC = " + IntToStr( m_cTSC ) +
- ", power = " + IntToStr( i_PHASE_ERROR_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(! FetchRMSPhaseErr( &PFERRMSError ) )
- {
- return false;
- }
- // Sleep(50);
- STOP_RF
- if( d_PHASE_ERROR_RMS_ERROR < PFERRMSError )
- {
- MF_rf_txiq_ptr->Set_BBTx_isCalibrated(0);
- }
- else
- {
- MF_rf_txiq_ptr->Set_BBTx_isCalibrated(191);
- }
- 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"
- );
- sprintf(tempbuf, "%11d", MF_rf_txiq_ptr->Get_BBTx_OffsetI() );
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- sprintf(tempbuf, "%11d", MF_rf_txiq_ptr->Get_BBTx_OffsetQ());
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- if( ! Form_META_Factory->WriteTxPhaseErrCalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath ) )
- {
- CalErrorHandler( WM_MF_RF_TX_PHASE_ERR_WRITE_CAL_RESULT_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : write TX phase error parameter to cal file "
- );
- return false;
- }
- if( d_PHASE_ERROR_RMS_ERROR < PFERRMSError )
- {
- CalErrorHandler( WM_MF_RF_TX_PHASE_ERR_CHECK_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: TX phase error calibration. Check RMS phase error = " + Double_To_AnsiString(PFERRMSError) +
- ", Max RMS phase error = " + Double_To_AnsiString( d_PHASE_ERROR_RMS_ERROR )
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " PASS: TX phase error calibration. Check RMS phase error = " + Double_To_AnsiString(PFERRMSError) +
- ", Max RMS phase error = " + Double_To_AnsiString( d_PHASE_ERROR_RMS_ERROR )
- );
- PostMessage(
- ctrl.hPostMsgDestHandle,
- WM_MF_RF_TX_PHASE_ERR_CALIBRATION_DONE,
- 0,
- 0
- );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ============== TX phase error calibration check end ================== "
- );
- Form_META_Factory->DisableAllCalTimer();
- return true;
-
- }
- //------------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::TrimOffIQCalCommon( void )
- {
- if( ! rct_ctrl.RCT_operatingMode( m_pRct, OPERATING_MODE_GSM_BCH_TCH ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_OPERATION_MODE_FAIL );
- if ( Form_META_Factory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " Agilent 8960< Operation mode = GSM BCH+TCH"
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " cmu200 < Band = Operation mode = GSM BCH+TCH"
- );
- }
- return false;
- }
- vi_PHASE_ERROR_BAND = Get_AgeBand( as_PHASE_ERROR_BAND );
- if( ! rct_ctrl.RCT_cellBand( m_pRct, vi_PHASE_ERROR_BAND) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
- if ( Form_META_Factory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " Agilent 8960< Band = " + ViBand_To_Str( vi_PHASE_ERROR_BAND )
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " cmu200 < Band = " + ViBand_To_Str( vi_PHASE_ERROR_BAND )
- );
- }
- return false;
- }
- #if 0
- if ( Form_META_Factory->rbAgilent8960->Checked )
- {
- if ( age1960_cellBand(
- ctrl.vi,
- age1960_CELL_1,
- i_PHASE_ERROR_BAND
- ) != VI_SUCCESS )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Agilent 8960< Band = "+
- ViBand_To_Str( vi_PHASE_ERROR_BAND )
- );
- return false;
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Agilent 8960< Band = "+
- ViBand_To_Str( vi_PHASE_ERROR_BAND )
- );
- }
- }
- else
- {
- if( !cmu_cellband(vi_PHASE_ERROR_BAND, &cmu) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: cmu200 > Band = "+
- ViBand_To_Str( vi_PHASE_ERROR_BAND )
- );
- return false;
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " cmu200 > Band = "+
- ViBand_To_Str( vi_PHASE_ERROR_BAND )
- );
- }
- }
- #endif
- if ( Form_META_Factory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Agilent 8960< Band = "+
- ViBand_To_Str( vi_PHASE_ERROR_BAND )
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " cmu200 > Band = "+
- ViBand_To_Str( vi_PHASE_ERROR_BAND )
- );
- }
- short bch_arfcn = ::Get_SeperateChannel( vi_PHASE_ERROR_BAND, m_sPHASE_ERROR_ARFCN );
- if( ! rct_ctrl.RCT_BCHARFCN( m_pRct, bch_arfcn) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_TCH_ARFCN_FAIL );
- if ( Form_META_Factory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " Agilent 8960< BCH ARFCN = " + IntToStr( bch_arfcn )
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " CMU 200< BCH ARFCN = " + IntToStr( bch_arfcn )
- );
- }
- return false;
- }
- if( ! rct_ctrl.RCT_TCHARFCN( m_pRct, m_sPHASE_ERROR_ARFCN ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_TCH_ARFCN_FAIL );
- if ( Form_META_Factory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " Agilent 8960< TCH ARFCN = " + IntToStr( m_sPHASE_ERROR_ARFCN )
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " CMU 200< TCH ARFCN = " + IntToStr( m_sPHASE_ERROR_ARFCN )
- );
- }
- return false;
- }
- #if 0
- if ( Form_META_Factory->rbAgilent8960->Checked )
- {
- if ( age1960_TCHARFCN(
- ctrl.vi,
- m_sPHASE_ERROR_ARFCN,
- (short) 0, // current band
- VI_TRUE
- )!= VI_SUCCESS)
- {
- CalErrorHandler( WM_MF_AGE8960_SET_TCH_ARFCN_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " Agilent 8960< TCH ARFCN = " + IntToStr( m_sPHASE_ERROR_ARFCN )
- );
- return false;
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Agilent 8960< TCH ARFCN = " + IntToStr( m_sPHASE_ERROR_ARFCN )
- );
- }
- }
- else
- {
- if( !cmu_tcharfcn(m_sPHASE_ERROR_ARFCN, &cmu) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_TCH_ARFCN_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL :"+
- " cmu200 > TCH ARFCN = " + IntToStr( m_sPHASE_ERROR_ARFCN )
- );
- return false;
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " cmu200 > TCH ARFCN = " + IntToStr( m_sPHASE_ERROR_ARFCN )
- );
- }
- }
- #endif
- if ( Form_META_Factory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Agilent 8960< TCH ARFCN = " + IntToStr( m_sPHASE_ERROR_ARFCN )
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " cmu200 > TCH ARFCN = " + IntToStr( m_sPHASE_ERROR_ARFCN )
- );
- }
- #if 0
- if (! cfg->get_PHASE_ERROR_PCL( i_PHASE_ERROR_PCL ))
- {
- CalErrorHandler( WM_MF_CFG_READ_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Read config file fail(PHASE_ERROR_PCL)."
- );
- return false;
- }
- #endif
- if( ! rct_ctrl.RCT_MSTXLevel( m_pRct, i_PHASE_ERROR_PCL ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_MS_TX_LEVEL_FAIL );
- if ( Form_META_Factory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Agilent 8960< MS TX level = " + IntToStr( i_PHASE_ERROR_PCL)
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : cmu200 > MS TX level = " + IntToStr( i_PHASE_ERROR_PCL )
- );
- }
- return false;
- }
- #if 0
- if ( Form_META_Factory->rbAgilent8960->Checked )
- {
- if ( age1960_MSTXLevel(
- ctrl.vi,
- i_PHASE_ERROR_PCL,
- (short) 0, // current band
- VI_TRUE
- )!= VI_SUCCESS)
- {
- CalErrorHandler( WM_MF_AGE8960_SET_MS_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Agilent 8960< MS TX level = " + IntToStr( i_PHASE_ERROR_PCL )
- );
- return false;
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Agilent 8960< MS TX level = " + IntToStr( i_PHASE_ERROR_PCL )
- );
- }
- }
- else
- {
- if( !cmu_mxtxlevel(i_PHASE_ERROR_PCL, &cmu) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_MS_TX_LEVEL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : cmu200 > MS TX level = " + IntToStr( i_PHASE_ERROR_PCL)
- );
- return false;
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " cmu200 > MS TX level = " + IntToStr( i_PHASE_ERROR_PCL)
- );
- }
- }
- #endif
- if ( Form_META_Factory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Agilent 8960< MS TX level = " + IntToStr( i_PHASE_ERROR_PCL )
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " cmu200 > MS TX level = " + IntToStr( i_PHASE_ERROR_PCL)
- );
- }
- #if 0
- if (! cfg->getTSC( m_cTSC ))
- {
- CalErrorHandler( WM_MF_CFG_READ_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Read config file fail(TSC)."
- );
- return false;
- }
- #endif
- if( ! rct_ctrl.RCT_ConfigTSC( m_pRct, m_cTSC ) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_TSC_FAIL );
- if( Form_META_Factory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- "FAIL : Agilent 8960 set TSC fail."
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : cmu200 > TSC = " + IntToStr( m_cTSC)
- );
- }
- return false;
- }
- #if 0
- if ( Form_META_Factory->rbAgilent8960->Checked )
- {
- if( age1968A_ConfigTSC(ctrl.vi, m_cTSC, log) != VI_SUCCESS )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_TSC_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- "FAIL : Agilent 8960 > TSC = " + IntToStr( m_cTSC)
- );
- return false;
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Agilent 8960 > TSC = " + IntToStr( m_cTSC)
- );
- }
- }
- else
- {
- if( !cmu_tsc(m_cTSC, &cmu) )
- {
- CalErrorHandler( WM_MF_AGE8960_SET_TSC_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : cmu200 > TSC = " + IntToStr( m_cTSC)
- );
- return false;
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " cmu200 > TSC = " + IntToStr( m_cTSC)
- );
- }
- }
- #endif
- if( Form_META_Factory->rbAgilent8960->Checked )
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Agilent 8960 > TSC = " + IntToStr( m_cTSC)
- );
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " cmu200 > TSC = " + IntToStr( m_cTSC)
- );
- }
- EquConfigPFER();
- // // read BB TX parameter from NVRAM
- // MF_rf_txiq_ptr->ConfirmCallback = ::ccb_read_txiq_from_nvram;
- // MF_rf_txiq_ptr->REQ_Read_From_NVRAM_Start();
- //
- // 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 );
- // log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " FAIL: Target < Read txiq value from NVRAM fail "
- // );
- // return false;
- // }
- //
- // log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " Target < Read txiq value from NVRAM"
- // );
- //
- // BB TX auto calibration
- if( META_Rf_BBTXAutoCal_r( 500 ) != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_TX_GAIN_AUTO_CAL_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: RF TX gain auto calibration."
- );
- return false;
- }
- // get BBTxCfg2
- if( META_Rf_GetBBTxCfg2_r(500, &rf_bb_tx_cfg2_req) != META_SUCCESS )
- {
- CalErrorHandler( WM_MF_RF_GET_BB_TX_CFG_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: RF get BB TX CFG fail."
- );
- return false;
- }
- MF_rf_txiq_ptr->Set_BBTxParametersFromAutoK( &rf_bb_tx_cfg2_req );
- Form_META_Factory->DisableAllCalTimer();
- return true;
- }
- //-----------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::FetchRMSPhaseErr( ViReal64* RMSPhaseErr )
- {
- // if(! rct_ctrl.RCT_initMeasFcn_PFER( m_pRct ) )
- // {
- // return false;
- // }
- if(! rct_ctrl.RCT_FetchAvgPhErr( m_pRct, *RMSPhaseErr ) )
- {
- return false;
- }
- #if 0
- if ( Form_META_Factory->rbAgilent8960->Checked )
- {
- if( age1960_initMeasFcn(
- ctrl.vi,
- age1960_PFER
- ) != VI_SUCCESS)
- {
- CalErrorHandler( WM_MF_AGE8960_SET_MESA_FUNC_PFER_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Agilent 8960< set phase, frquency error mesaurement function fail."
- );
- return false;
- }
- Sleep(50);
- if ( age1960_fetchPFER_Q(
- ctrl.vi,
- &PFERIntegrity,
- &PFERRMSError,
- &PFERPeakError,
- &PFERFreqError
- )!= VI_SUCCESS)
- {
- CalErrorHandler( WM_MF_AGE8960_READ_PFER_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Agilent 8960< fetch phase error."
- );
- return false;
- }
- }
- else
- {
- if( ! cmu_mod_init( &cmu ) )
- {
- CalErrorHandler( WM_MF_AGE8960_READ_PFER_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Agilent 8960< fetch phase error."
- );
- return false;
- }
- if( ! cmu_mod_sample(&cmu, PH_ERR_RMS_AVERAGE, &PFERRMSError) )
- // if( !cmu_readmod(PH_ERR_RMS_AVERAGE, &cmu, &PFERFreqError) )
- {
- CalErrorHandler( WM_MF_AGE8960_READ_PFER_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Agilent 8960< fetch phase error."
- );
- return false;
- }
- if( ! cmu_mod_abort( &cmu ) )
- {
- CalErrorHandler( WM_MF_AGE8960_READ_PFER_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Agilent 8960< fetch phase error."
- );
- return false;
- }
- }
- *RMSPhaseErr = PFERRMSError;
- // log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " RMS phase error = " + Double_To_AnsiString(PFERRMSError)
- // );
- return true;
- #endif
- }