T_TXPCL_RenesasPF08155B.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:21k
源码类别:
MTK
开发平台:
C++ Builder
- /*****************************************************************************
- * 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_TXPCL_RenesasPF08155B.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Renesas PF08151B TX PCL 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
- #ifndef _APCCAL_COMMON_H_
- #include "apccal_common.h"
- #endif
- #ifndef _RF_APC_H_
- #include "rf_apc.h"
- #endif
- // callback
- #ifndef _META_FACTORY_RF_CB_H_
- #include "meta_factory_rf_cb.h"
- #endif
- #ifndef _META_FACTORY_NVRAM_CB_H_
- #include "meta_factory_nvram_cb.h"
- #endif
- // form
- #ifndef _META_FACTORY_H_
- #include "META_Factory.h"
- #endif
- // equipment
- #ifndef _AGE_MISC_H_
- #include "age_misc.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
- static const double RENESAS_PF08151B_CONST = 3.1303;
- static const double RENESAS_PF08151B_GSM850_SWITCH_LOSS = 1.2;
- static const double RENESAS_PF08151B_GSM_SWITCH_LOSS = 1.2;
- static const double RENESAS_PF08151B_DCS1800_SWITCH_LOSS = 1.3;
- static const double RENESAS_PF08151B_PCS1900_SWITCH_LOSS = 1.3;
- //----------------------------------------------------------------------------
- extern CRFAPC* MF_rf_apc_ptr;
- extern RfNbtx_Req *MF_rf_tx_level_req;
- extern bool MF_rf_tx_level_cnf;
- extern bool is_suspend_cal; // in T_META_factory_calibration.cpp
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ///////////////////////////// Renesas PF08155B ///////////////////////
- //---------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::TXPCLCal_EvalDac_RenesasPF08155B( void )
- {
- AnsiString as_tx_pcl;
- AnsiString as_tx_cal_pcl;
- AnsiString as_wanted_p;
- AnsiString as_correction;
- AnsiString as_sub_tx_pcl;
- AnsiString as_sub_tx_cal_pcl;
- AnsiString as_sub_wanted_p;
- AnsiString as_sub_correction;
- // Evaluate a and b
- double switch_loss;
- unsigned short weight;
- double d_weight;
- unsigned short ramp_value;
- unsigned short battery_compensate;
- double d_battery_compensate;
- double al, ah, bl, bh;
- unsigned short i_PCL_Cal[MAX_SUPPORT_BAND_NUM][RF_TX_LEVEL_3_CAL_COUNT];
- unsigned short EffPCLDac_Cal[MAX_SUPPORT_BAND_NUM][RF_TX_LEVEL_3_CAL_COUNT];
- double PoutV_Cal[MAX_SUPPORT_BAND_NUM][RF_TX_LEVEL_3_CAL_COUNT];
- double Vramp_Cal[MAX_SUPPORT_BAND_NUM][RF_TX_LEVEL_3_CAL_COUNT];
- double PoutV_Eval[MAX_SUPPORT_BAND_NUM][RF_RAMP_TABLE_TX_LEVEL_COUNT];
- double Vramp_Eval[MAX_SUPPORT_BAND_NUM][RF_RAMP_TABLE_TX_LEVEL_COUNT];
- unsigned short EffPclDac_Eval[MAX_SUPPORT_BAND_NUM][RF_RAMP_TABLE_TX_LEVEL_COUNT];
- log->Add( "n" +DateToStr(Date()) + " " + CurrentTimeStr() +
- " =================== Evaluate PCL DAC value begin =================== "
- );
- int FIRST_PCL=0;
- short s_ARFCN;
- E_BANDSEL band_index;
- FrequencyBand eFreqBand = FrequencyBand850;
- while (eFreqBand < FrequencyBandCount)
- {
- switch (eFreqBand)
- {
- case FrequencyBand850:
- {
- if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- s_ARFCN = m_sARFCN_C0_GSM850;
- band_index = BANDSEL_GSM850;
- FIRST_PCL = GSM850_FIRST_PCL;
- as_tx_pcl = m_as_gsm850_tx_pcl;
- as_tx_cal_pcl = m_as_gsm850_tx_cal_pcl;
- as_wanted_p = m_as_gsm850_wanted_p;
- as_correction = m_as_gsm850_correction;
- switch_loss = RENESAS_PF08151B_GSM850_SWITCH_LOSS;
- }
- break;
- case FrequencyBand900:
- {
- if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- s_ARFCN = m_sARFCN_C0_GSM;
- band_index = BANDSEL_GSM900;
- FIRST_PCL = GSM900_FIRST_PCL;
- as_tx_pcl = m_as_gsm900_tx_pcl;
- as_tx_cal_pcl = m_as_gsm900_tx_cal_pcl;
- as_wanted_p = m_as_gsm900_wanted_p;
- as_correction = m_as_gsm900_correction;
- switch_loss = RENESAS_PF08151B_GSM_SWITCH_LOSS;
- }
- break;
- case FrequencyBand1800:
- {
- if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- s_ARFCN = m_sARFCN_C0_DCS;
- band_index = BANDSEL_DCS1800;
- FIRST_PCL = DCS1800_FIRST_PCL;
- as_tx_pcl = m_as_dcs1800_tx_pcl;
- as_tx_cal_pcl = m_as_dcs1800_tx_cal_pcl;
- as_wanted_p = m_as_dcs1800_wanted_p;
- as_correction = m_as_dcs1800_correction;
- switch_loss = RENESAS_PF08151B_DCS1800_SWITCH_LOSS;
- }
- break;
- case FrequencyBand1900:
- {
- if (! IsFreqBankSupported(m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- s_ARFCN = m_sARFCN_C0_PCS;
- band_index = BANDSEL_PCS1900;
- FIRST_PCL = PCS1900_FIRST_PCL;
- as_tx_pcl = m_as_pcs1900_tx_pcl;
- as_tx_cal_pcl = m_as_pcs1900_tx_cal_pcl;
- as_wanted_p = m_as_pcs1900_wanted_p;
- as_correction = m_as_pcs1900_correction;
- switch_loss = RENESAS_PF08151B_PCS1900_SWITCH_LOSS;
- }
- break;
- default:
- assert(false);
- break;
- } // switch
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " " +
- "---------------------------------------------"
- );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " " +
- BandIdx_To_String(band_index)
- );
- int i=0;
- for(i=0; i<RF_TX_LEVEL_3_CAL_COUNT; i++)
- {
- PoutV_Cal[band_index][i] = sqrt(50.0*pow(10, (m_dPCL_dBm[band_index][i]+switch_loss)/10.0)/1000.0);
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " PoutV_Cal[" + IntToStr(band_index) + "][" + IntToStr(i) + "] = " +
- Double_To_AnsiString(PoutV_Cal[band_index][i]) + "n"
- );
- if (! getAnsiStrSubItem( as_tx_cal_pcl, i+1, DEFAULT_SEP_CHAR, as_sub_tx_cal_pcl) )
- {
- CalErrorHandler( WM_MF_CFG_READ_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Read config file fail(sub_tx_cal_pcl)."
- );
- return false;
- }
- i_PCL_Cal[band_index][i] = as_sub_tx_cal_pcl.ToInt();
- l1cal_rampTable_T* p_ramp_table = MF_rf_apc_ptr->Get_ApcProfile(band_index);
- if(! MF_rf_apc_ptr->Get_SubBandWeighting(*p_ramp_table, s_ARFCN, as_sub_tx_cal_pcl.ToInt(), weight) )
- {
- CalErrorHandler( WM_MF_RF_TX_LEVEL_EVALDAC_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: get sub-band weighting."
- );
- return false;
- }
- d_weight = 1.0 * weight / WEIGHT_SCALE;
- if(! MF_rf_apc_ptr->Get_RightTopRampUpValue(*p_ramp_table, band_index, FIRST_PCL-as_sub_tx_cal_pcl.ToInt(), ramp_value) )
- {
- CalErrorHandler( WM_MF_RF_TX_LEVEL_EVALDAC_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: get ramp up value."
- );
- return false;
- }
- if(! MF_rf_apc_ptr->Get_BatteryCompensate(*p_ramp_table, MID_VOLTAGE_INDEX, MID_TEMPERATURE_INDEX, battery_compensate) )
- {
- CalErrorHandler( WM_MF_RF_TX_LEVEL_EVALDAC_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: get battery_compensate value."
- );
- return false;
- }
- d_battery_compensate = 1.0* battery_compensate / BATTERY_COMPENSATE_SCALE;
- EffPCLDac_Cal[band_index][i] = m_usPCLDacValue[band_index][i] * d_weight * d_battery_compensate * ramp_value / MAX_RAMP_VALUE;
- // Vramp_Cal[band_index][i] = (MF_rf_apc_ptr->Get_HighApcDcOffset(band_index)+EffPCLDac_Cal[band_index][i])/pow(2.0, 10.0) * 2.8;
- if( ! MF_rf_apc_ptr->Get_RealApcDcOffset(m_pCal->b_TADOSupport, band_index, i_PCL_Cal[band_index][i], m_iApcDcOffset ) )
- {
- CalErrorHandler( WM_MF_RF_TX_LEVEL_EVALDAC_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: PCL to dBm " +
- " TADO support = " + IntToStr( m_pCal->b_TADOSupport ) +
- " eFreqBand = " + IntToStr( eFreqBand ) +
- " pcl = " + IntToStr( i_PCL_Cal[band_index][i] )
- );
- return false;
- }
- Vramp_Cal[band_index][i] = (m_iApcDcOffset+EffPCLDac_Cal[band_index][i])/pow(2.0, 10.0) * 2.8;
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Vramp_Cal[" + IntToStr(band_index) + "][" + IntToStr(i) + "] = " +
- Double_To_AnsiString(Vramp_Cal[band_index][i]) + "n"
- );
- }
- al = ( PoutV_Cal[band_index][1] - PoutV_Cal[band_index][0] - RENESAS_PF08151B_CONST * (pow(Vramp_Cal[band_index][1], 2.0)-pow(Vramp_Cal[band_index][0], 2.0)) )/(2*RENESAS_PF08151B_CONST *(Vramp_Cal[band_index][1]-Vramp_Cal[band_index][0]));
- bl = PoutV_Cal[band_index][0]-RENESAS_PF08151B_CONST*pow(Vramp_Cal[band_index][0]+al,2.0);
- ah = ( PoutV_Cal[band_index][2] - PoutV_Cal[band_index][1] - RENESAS_PF08151B_CONST * (pow(Vramp_Cal[band_index][2], 2.0)-pow(Vramp_Cal[band_index][1], 2.0)) )/(2*RENESAS_PF08151B_CONST *(Vramp_Cal[band_index][2]-Vramp_Cal[band_index][1]));
- bh = PoutV_Cal[band_index][2]-RENESAS_PF08151B_CONST*pow(Vramp_Cal[band_index][2]+ah,2.0);
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Evaluate: al = " + Double_To_AnsiString(al) +
- ", bl = " + Double_To_AnsiString(bl) +
- ", ah = " + Double_To_AnsiString(ah) +
- ", bh = " + Double_To_AnsiString(bh)
- );
- // Evaluate DAC except highest and lowest PCL
- for(int i=0; i<RF_RAMP_TABLE_TX_LEVEL_COUNT; i++)
- {
- if( i==RF_RAMP_TABLE_TX_LEVEL_COUNT-1 &&
- (eFreqBand==FrequencyBand850 || eFreqBand==FrequencyBand900 )
- )
- {
- break;
- }
- if (! getAnsiStrSubItem( as_tx_pcl, i+1, DEFAULT_SEP_CHAR, as_sub_tx_pcl) )
- {
- CalErrorHandler( WM_MF_CFG_READ_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Read config file fail(sub_tx_pcl)."
- );
- return false;
- }
- if (! getAnsiStrSubItem( as_wanted_p, i+1, DEFAULT_SEP_CHAR, as_sub_wanted_p) )
- {
- CalErrorHandler( WM_MF_CFG_READ_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Read config file fail(sub_wanted_p)."
- );
- return false;
- }
- if (! getAnsiStrSubItem( as_correction, i+1, DEFAULT_SEP_CHAR, as_sub_correction) )
- {
- CalErrorHandler( WM_MF_CFG_READ_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Read config file fail(as_sub_correction)."
- );
- return false;
- }
- if( as_sub_tx_pcl.ToInt() != i_PCL_Cal[band_index][PCL_LOW_INDEX] &&
- as_sub_tx_pcl.ToInt() != i_PCL_Cal[band_index][PCL_MID_INDEX] &&
- as_sub_tx_pcl.ToInt() != i_PCL_Cal[band_index][PCL_HIGH_INDEX]
- )
- {
- PoutV_Eval[band_index][i] = sqrt( 50*pow(10.0, (switch_loss + atof(as_sub_wanted_p.c_str()) + atof(as_sub_correction.c_str()))/10.0 )/1000.0 );
- if( as_sub_tx_pcl.ToInt() > i_PCL_Cal[band_index][PCL_MID_INDEX] )
- {
- Vramp_Eval[band_index][i] = sqrt((PoutV_Eval[band_index][i]-bl)/RENESAS_PF08151B_CONST) - al;
- }
- else
- {
- Vramp_Eval[band_index][i] = sqrt((PoutV_Eval[band_index][i]-bh)/RENESAS_PF08151B_CONST) - ah;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " PoutV_Eval[" + IntToStr(band_index) + "][" + IntToStr(i) + "] = " +
- Double_To_AnsiString(PoutV_Eval[band_index][i]) + "n"
- );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Vramp_Eval[" + IntToStr(band_index) + "][" + IntToStr(i) + "] = " +
- Double_To_AnsiString(Vramp_Eval[band_index][i]) + "n"
- );
- // EffPclDac_Eval[band_index][i] = (Vramp_Eval[band_index][i]*pow(2.0,10.0))/2.8 - MF_rf_apc_ptr->Get_HighApcDcOffset(band_index);
- if( ! MF_rf_apc_ptr->Get_RealApcDcOffset( m_pCal->b_TADOSupport, band_index, as_sub_tx_pcl.ToInt(), m_iApcDcOffset ) )
- {
- CalErrorHandler( WM_MF_RF_TX_LEVEL_EVALDAC_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Get APC DC offset " +
- " TADO support = " + IntToStr( m_pCal->b_TADOSupport ) +
- " eFreqBand = " + IntToStr( eFreqBand ) +
- " pcl = " + IntToStr( i_PCL_Cal[band_index][i] )
- );
- return false;
- }
- EffPclDac_Eval[band_index][i] = (Vramp_Eval[band_index][i]*pow(2.0,10.0))/2.8 - m_iApcDcOffset;
- if( d_weight*d_battery_compensate*ramp_value == 0 )
- {
- CalErrorHandler( WM_MF_RF_TX_LEVEL_EVALDAC_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: weight*battery_compensate*ramp_value = 0."
- );
- return false;
- }
- m_usPCLDacValue_ideal[band_index][i] = EffPclDac_Eval[band_index][i]*MAX_RAMP_VALUE/(d_weight*d_battery_compensate*ramp_value);
- MF_rf_apc_ptr->Set_ApcProfilePower( band_index, i, m_usPCLDacValue_ideal[band_index][i] );
- // MF_rf_apc_ptr->ApcProfile[band_index].rampData.power[i] = m_usPCLDacValue_ideal[band_index][i];
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " " +
- " m_usPCLDacValue_ideal[" + IntToStr(band_index) + "][" + IntToStr(i) + "] = " +
- Double_To_AnsiString(m_usPCLDacValue_ideal[band_index][i]) + "n"
- );
- }
- }
- MF_rf_apc_ptr->ConfirmCallback = ::ccb_write_apc_to_nvram;
- MF_rf_apc_ptr->REQ_Write_APC_To_NVRAM_Single_Band_Start(m_pCal->ui_rf_id, band_index, m_pCal->b_TADOSupport );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Write to NVRAM band_index = " + IntToStr(band_index)
- );
- //log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- // " TimerCal->Enabled 15= " + IntToStr((int)frmFatcory->TimerCal->Enabled) + "n"
- // );
- RestartTimerCal(WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL);
- CHECK_TERMINATE_BY_USER
- SUSPEND_CAL_THREAD
- E_METAAPP_RESULT_T state = MF_rf_apc_ptr->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_L1_RAMPTABLE_xxx_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_L1_RAMPTABLE_xxx_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL);
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < write APC to NVRAM "
- );
- }
- return false;
- }
- WriteAPCCalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath, FreqBand_To_BandIdx(eFreqBand) );
- eFreqBand++;
- } // while
- frmFatcory->DisableAllCalTimer();
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ===================== Evaluate other PCL DAC value end =========== n "
- );
- return true;
- }