Crystal_Sweep_RX.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:18k
- /*****************************************************************************
- * 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:
- * ---------
- * Crystal_Sweep_RX.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Crystal sweep RX 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 <vcl.h>
- #include <assert.h>
- #pragma hdrstop
- #include "form_RFTool.h"
- #ifndef _CRYSTAL_SWEEP_RX_H_
- #include "Crystal_Sweep_RX.h"
- #endif
- #ifndef _META_UTILS_H_
- #include "meta_utils.h"
- #endif
- #ifndef _CRYSTAL_INIFILEHANDLE_H_
- #include "Crystal_INIFileHandle.h"
- #endif
- #ifndef _MAN_DLL_H_
- #include "man_dll.h"
- #endif
- #ifndef _META_CONST_H_
- #include "meta_const.h"
- #endif
- // equipment
- #ifndef _AGECOMMON_H_
- #include "agecommon.h"
- #endif
- #ifndef _AGE1968A_H_
- #include "age1968a.h"
- #endif
- #ifndef _CMU200_H_
- #include "cmu200.h"
- #endif
- #ifndef _RCT_COMMON_H_
- #include "rct_common.h"
- #endif
- // form
- //#ifndef _FORM_MAIN_H_
- //#include "form_main.h"
- //#endif
- // misc
- #ifndef _BAND_UTILS_H_
- #include "band_utils.h"
- #endif
- //---------------------------------------------------------------------------
- #define ONE_SECOND 1
- //extern TfrmMainSel *frmMainSel; // for GSM 850
- //------------------------------------------------------------------------------
- static RfAfc_Cnf MF_rf_afc_cnf;
- CMU_VAR cmu_crystal_r;
- //==============================================================================
- static void CNF_CASR(void)
- {
- if (frmRFTool->pt_Age8960_Crystal_Sweep_RX != NULL)
- {
- frmRFTool->pt_Age8960_Crystal_Sweep_RX->Resume();
- }
- }
- //------------------------------------------------------------------------------
- static void cb_write_CrystalAFC_to_nvram()
- {
- if(frmRFTool->pt_Age8960_Crystal_Sweep_RX != NULL )
- {
- frmRFTool->pt_Age8960_Crystal_Sweep_RX->Resume();
- }
- }
- //------------------------------------------------------------------------------
- void __stdcall cb_rf_afc(const RfAfc_Cnf *cnf, const short token, void *usrData)
- {
- MF_rf_afc_cnf.deviation = cnf->deviation;
- MF_rf_afc_cnf.fcb_ok_number = cnf->fcb_ok_number;
- MF_rf_afc_cnf.freqOffset = cnf->freqOffset;
- MF_rf_afc_cnf.ok = cnf->ok;
- if(frmRFTool->pt_Age8960_Crystal_Sweep_RX != NULL )
- {
- frmRFTool->pt_Age8960_Crystal_Sweep_RX->Resume();
- }
- }
- //------------------------------------------------------------------------------
- static void cb_rf_stop_rx()
- {
- if(frmRFTool->pt_Age8960_Crystal_Sweep_RX != NULL )
- {
- frmRFTool->pt_Age8960_Crystal_Sweep_RX->Resume();
- }
- }
- //==============================================================================
- void _fastcall Crystal_Sweep_RX::ShowMsg()
- {
- ShowMessage(as_Msg);
- }
- //------------------------------------------------------------------------------
- void _fastcall Crystal_Sweep_RX::SyncShowMsg(AnsiString as)
- {
- as_Msg = as;
- Synchronize(ShowMsg);
- }
- //=========================================================================================
- __fastcall Crystal_Sweep_RX::Crystal_Sweep_RX(bool CreateSuspended, S_CAS_T *cas)
- : TThread(CreateSuspended)
- {
- m_pCAS = cas;
- }
- //---------------------------------------------------------------------------
- void __fastcall Crystal_Sweep_RX::Execute()
- {
- ViInt16 vi_Band;
- m_rct.device_type = m_pCAS->e_device_type;
- if (AGILENT_8960 == m_pCAS->e_device_type)
- {
- if ((! m_pCAS->crystal_cfg->getGSM400_CableLoss( m_rct.age.d400 )) ||
- (! m_pCAS->crystal_cfg->getGSM850_CableLoss( m_rct.age.d850 )) ||
- (! m_pCAS->crystal_cfg->getGSM900_CableLoss( m_rct.age.d900 )) ||
- (! m_pCAS->crystal_cfg->getDCS1800_CableLoss( m_rct.age.d1800 )) ||
- (! m_pCAS->crystal_cfg->getPCS1900_CableLoss( m_rct.age.d1900 ))
- )
- {
- SyncShowMsg(" Agilent 8960 read config file (cable loss) fail ");
- return;
- }
- if (!m_pCAS->crystal_cfg->getTimeOut(m_rct.age.TMO))
- {
- SyncShowMsg("Get Time Out from file fail");
- return;
- }
- if (!m_pCAS->crystal_cfg->getGPIB_Addr(m_rct.age.ADD))
- {
- SyncShowMsg("Get GPIB address from file fail");
- return;
- }
- }
- else // CMU 200
- {
- if(
- (! m_pCAS->crystal_cfg->getCMU200_INPUT_GSM850_CableLoss( m_rct.cmu.loss_gsm850_i )) ||
- (! m_pCAS->crystal_cfg->getCMU200_INPUT_GSM900_CableLoss( m_rct.cmu.loss_gsm_i )) ||
- (! m_pCAS->crystal_cfg->getCMU200_INPUT_DCS1800_CableLoss( m_rct.cmu.loss_dcs_i )) ||
- (! m_pCAS->crystal_cfg->getCMU200_INPUT_PCS1900_CableLoss( m_rct.cmu.loss_pcs_i ))
- )
- {
- SyncShowMsg( " CMU200 read config file (input cable loss) fail " );
- return;
- }
- //************************************************************
- if(
- (! m_pCAS->crystal_cfg->getCMU200_OUTPUT_GSM850_CableLoss( m_rct.cmu.loss_gsm850_o )) ||
- (! m_pCAS->crystal_cfg->getCMU200_OUTPUT_GSM900_CableLoss( m_rct.cmu.loss_gsm_o )) ||
- (! m_pCAS->crystal_cfg->getCMU200_OUTPUT_DCS1800_CableLoss( m_rct.cmu.loss_dcs_o )) ||
- (! m_pCAS->crystal_cfg->getCMU200_OUTPUT_PCS1900_CableLoss( m_rct.cmu.loss_pcs_o ))
- )
- {
- SyncShowMsg( " CMU200 read config file (output cable loss) fail " );
- return;
- }
- if(! m_pCAS->crystal_cfg->getCMU200_TimeOut( m_rct.cmu.TMO ) )
- {
- SyncShowMsg( "Get Time Out from file fail" );
- return;
- }
- if(! m_pCAS->crystal_cfg->getCMU200_GPIB_Addr( m_rct.cmu.ADD ) )
- {
- SyncShowMsg( "Get GPIB address from file fail" );
- return;
- }
- m_rct.cmu.ADD = m_rct.cmu.ADD.SubString(0, m_rct.cmu.ADD.Pos("::INSTR")-1);
- }
- if (m_pCAS->b_temp_sweep)
- {
- if (!m_cts_ctrl.CTS_Init(m_pCAS->com_port))
- {
- SyncShowMsg("Initialize CTS fail");
- return;
- }
- m_pCAS->hCOM = m_cts_ctrl.CTS_GetComHandle();
- m_pCAS->original_dcb = m_cts_ctrl.Get_OriginalDCB();
- if( ! m_cts_ctrl.CTS_Start() )
- {
- SyncShowMsg( "Start CTS fail" );
- return;
- }
- }
- if (!m_rct_ctrl.RCT_Init(&m_rct, BandIdx_To_FreqBandString(m_pCAS->e_band)))
- {
- SyncShowMsg("Initialize equipment fail");
- return;
- }
- E_AGE_OPERATING_MODE mode = m_pCAS->b_cont_sine_wave ? OPERATING_MODE_GSM_CW : OPERATING_MODE_GSM_BCH_TCH;
- if (!m_rct_ctrl.RCT_operatingMode(&m_rct, mode))
- {
- SyncShowMsg("Set operation mode fail");
- return;
- }
- AnsiString as_RCT = m_rct_ctrl.RCT_DeviceTypeToString(m_pCAS->e_device_type);
- //********************************************************************
- /////////////////////////////////////////////////////////////////////////////
- switch (m_pCAS->e_band)
- {
- case BANDSEL_GSM900:
- {
- vi_Band = age1960_EGSM_BAND;
- cmu_crystal_r.BAND = "GSM";
- }
- break;
- case BANDSEL_DCS1800:
- {
- vi_Band = age1960_DCS1800_BAND;
- cmu_crystal_r.BAND = "DCS";
- }
- break;
- case BANDSEL_PCS1900:
- {
- vi_Band = age1960_PCS1900_BAND;
- cmu_crystal_r.BAND = "PCS";
- }
- break;
- case BANDSEL_GSM850:
- {
- vi_Band = age1960_GSM850_BAND;
- cmu_crystal_r.BAND = "GSM850";
- }
- break;
- default:
- {
- assert(false);
- }
- break;
- } // switch
- FrequencyBand FreqBand = BandIdx_To_FreqBand(m_pCAS->e_band);
- if (!m_rct_ctrl.RCT_cellBand(&m_rct, vi_Band))
- {
- AnsiString as_msg = as_RCT + " set cell band fail";
- SyncShowMsg(as_msg);
- return;
- }
- if (m_pCAS->b_cont_sine_wave)
- {
- if (!m_rct_ctrl.RCT_GenFreqOffset(&m_rct, 67.7))
- {
- AnsiString as_msg = as_RCT + " set frequency offset fail";
- SyncShowMsg(as_msg);
- return;
- }
- if (!m_rct_ctrl.RCT_PowTranCont(&m_rct))
- {
- AnsiString as_msg = as_RCT + " set cell band fail";
- SyncShowMsg(as_msg);
- return;
- }
- if (!m_rct_ctrl.RCT_GenBitMod(&m_rct, CMU200_GEN_BIT_MODU_OFF))
- {
- AnsiString as_msg = as_RCT + " set cell band fail";
- SyncShowMsg(as_msg);
- return;
- }
- }
- else
- {
- if (!m_rct_ctrl.RCT_PowTranBurst(&m_rct))
- {
- AnsiString as_msg = as_RCT + " set cell band fail";
- SyncShowMsg(as_msg);
- return;
- }
- if (!m_rct_ctrl.RCT_GenBitMod(&m_rct, CMU200_GEN_BIT_MODU_ALL_ZERO))
- {
- AnsiString as_msg = as_RCT + " set cell band fail";
- SyncShowMsg(as_msg);
- return;
- }
- if ((MT6205 == m_pCAS->e_bb_chip) ||
- (MT6205B == m_pCAS->e_bb_chip) ||
- (MT6223 == m_pCAS->e_bb_chip) ||
- (MT6223P == m_pCAS->e_bb_chip) ||
- (MT6225 == m_pCAS->e_bb_chip) ||
- (MT6229 == m_pCAS->e_bb_chip) ||
- (MT6230 == m_pCAS->e_bb_chip) ||
- (MT6235 == m_pCAS->e_bb_chip) ||
- (MT6238 == m_pCAS->e_bb_chip) ||
- (TK6516_MD == m_pCAS->e_bb_chip)
- )
- {
- if (!m_rct_ctrl.RCT_GenTsc(&m_rct, CMU200_GEN_TSC_ALL_ZERO))
- {
- AnsiString as_msg = as_RCT + " Generate TSC fail";
- SyncShowMsg(as_msg);
- return;
- }
- }
- else
- {
- if (!m_rct_ctrl.RCT_GenTsc(&m_rct, CMU200_GEN_TSC_GSM_5))
- {
- AnsiString as_msg = as_RCT + " Generate TSC fail";
- SyncShowMsg(as_msg);
- return;
- }
- }
- }
- if (!m_rct_ctrl.RCT_InitRfg(&m_rct))
- {
- AnsiString as_msg = as_RCT + " initialize generator fail";
- SyncShowMsg(as_msg);
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- if (m_pCAS->b_cont_sine_wave && (AGILENT_8960 == m_pCAS->e_device_type))
- {
- if (!m_rct_ctrl.RCT_GenFreq_CW(&m_rct, FreqBand, m_pCAS->s_arfcn))
- {
- AnsiString as_msg = as_RCT + " set ARFCN fail";
- SyncShowMsg(as_msg);
- return;
- }
- }
- else
- {
- if (!m_rct_ctrl.RCT_BCHARFCN(&m_rct, m_pCAS->s_arfcn))
- {
- AnsiString as_msg = as_RCT + " set BCCH ARFCN fail";
- SyncShowMsg(as_msg);
- return;
- }
- }
- CRFAFC RF_AFC_Obj;
- RF_AFC_Obj.ConfirmCallback = ::CNF_CASR;
- RF_AFC_Obj.REQ_SetAfcSinWaveDetection_Start(m_pCAS->b_cont_sine_wave);
- this->Suspend();
- if (RF_AFC_Obj.Get_ConfirmState() != METAAPP_SUCCESS)
- {
- SyncShowMsg("Execution Failure : set continuous sine wave");
- return;
- }
- double d_P_DL;
- /////////////////////////////////////////////////////////////////////////////
- if(!m_pCAS->crystal_cfg->getP_DL(d_P_DL))
- {
- SyncShowMsg("Get P_DL from file fail");
- return;
- }
- if (m_pCAS->b_cont_sine_wave && (AGILENT_8960 == m_pCAS->e_device_type))
- {
- if (!m_rct_ctrl.RCT_cellPower_CW(&m_rct, d_P_DL))
- {
- AnsiString as_msg = as_RCT + " set downlink power fail";
- SyncShowMsg(as_msg);
- return;
- }
- }
- else
- {
- if (!m_rct_ctrl.RCT_cellPower(&m_rct, d_P_DL))
- {
- AnsiString as_msg = as_RCT + " set downlink power fail";
- SyncShowMsg(as_msg);
- return;
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- Sleep(50);
- // save header to log
- buf[0]=' ';
- for (int j=m_pCAS->s_min_afc_dac; j<=m_pCAS->s_max_afc_dac; j=j+m_pCAS->s_afc_dac_step)
- {
- sprintf(buf1, "%15d", j );
- strcat(buf, buf1);
- }
- m_pCAS->st_Log->Add(buf);
- frmRFTool->write_CAS_log();
- if( ! m_pCAS->b_temp_sweep ) m_pCAS->max_temp = m_pCAS->min_temp;
- for(float temp=m_pCAS->min_temp; temp<=m_pCAS->max_temp; temp+=m_pCAS->temp_step)
- {
- if( m_pCAS->b_temp_sweep )
- {
- if( ! m_cts_ctrl.CTS_SetTemp( temp ) )
- {
- SyncShowMsg("CTS set temp fail");
- return;
- }
- double current_temp, setting_temp;
- do
- {
- if (this->Terminated)
- {
- this->OnTerminate = m_pCAS->ne_onTermByUser;
- return;
- }
- if (!m_cts_ctrl.CTS_GetTemp(current_temp, setting_temp))
- {
- continue;
- }
- }
- while(temp != current_temp);
- }
- for (int i = m_pCAS->min_cap_id; i <= m_pCAS->max_cap_id; i = i+m_pCAS->cap_id_step)
- {
- CRYSTAL_AFC_Object.ConfirmCallback = ::CNF_CASR;
- CRYSTAL_AFC_Object.REQ_SetCapID_Start(i);
- this->Suspend();
- buf[0]=' ';
- if( m_pCAS->b_temp_sweep )
- {
- sprintf(buf0, "%3.1f %3d", temp, i);
- }
- else
- {
- sprintf(buf0, " %3d", i);
- }
- strcat(buf, buf0);
- if(CRYSTAL_AFC_Object.Get_ConfirmState() != METAAPP_SUCCESS)
- {
- SyncShowMsg("Execution Failure : read crystal AFC from NVRAM ");
- return;
- }
- for (int j = m_pCAS->s_min_afc_dac; j <= m_pCAS->s_max_afc_dac; j = j + m_pCAS->s_afc_dac_step)
- {
- if (this->Terminated)
- {
- this->OnTerminate = m_pCAS->ne_onTermByUser;
- return;
- }
- Sleep(50);
- MF_rf_afc_req.arfcn = m_pCAS->s_arfcn;
- MF_rf_afc_req.dacValue = j;
- 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_pCAS->test_count;
- if ( META_Rf_AFC_r( m_META_HANDLE_Obj.Get_MainHandle(),
- &MF_rf_afc_req,
- ::cb_rf_afc,
- &MF_rf_afc_token,
- NULL
- ) != META_SUCCESS)
- {
- return;
- }
- this->Suspend();
- FreqError = MF_rf_afc_cnf.freqOffset;
- sprintf(buf1, "%12.4f", FreqError );
- strcat(buf, buf1);
- strcat(buf, " ");
- }
- m_pCAS->st_Log->Add(buf);
- frmRFTool->write_CAS_log();
- }
- }
- this->OnTerminate = m_pCAS->ne_onTermSuccess;
- }