T_TXPCL_Axiom502.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:19k
- /*****************************************************************************
- * 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_Axiom502.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * TX PCL calibration for Axiom AX502 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 _APCCAL_COMMON_H_
- #include "apccal_common.h"
- #endif
- #ifndef _RF_APC_H_
- #include "rf_apc.h"
- #endif
- #ifndef _META_FACTORY_RF_CB_H_
- #include "meta_factory_rf_cb.h"
- #endif
- // form
- #ifndef _META_FACTORY_H_
- #include "META_Factory.h"
- #endif
- // equipment
- #ifndef _AGE1968A_H_
- #include "age1968a.h"
- #endif
- // callback
- #ifndef _META_FACTORY_NVRAM_CB_H_
- #include "meta_factory_nvram_cb.h"
- #endif
- // misc
- #ifndef _BAND_UTILS_H_
- #include "band_utils.h"
- #endif
- #ifndef _TIME_UTILS_H_
- #include "time_utils.h"
- #endif
- #ifndef _FT_UTILS_H_
- #include "ft_utils.h"
- #endif
- //----------------------------------------------------------------------------
- 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
- // equipment
- //extern CMU_VAR cmu;
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ///////////////////////////// Axiom AX502 /////////////////////
- //---------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::TXPCLCal_Axiom502_3PCLEvalDac(void)
- {
- short s_ARFCN;
- short s_first_pcl;
- AnsiString as_wanted_p;
- AnsiString as_correction;
- AnsiString as_tx_pcl;
- AnsiString as_tx_6cal_pcl;
- AnsiString as_switch_pcl;
- char c_total_pcl_num;
- unsigned short us_weight;
- double d_weight;
- unsigned short us_ramp_value;
- unsigned short us_battery_compensate;
- double d_battery_compensate;
- short s_tx_6cal_pcl[RF_TX_LEVEL_6_CAL_COUNT];
- short s_tx_pcl[TOTAL_DCS_PCL_NUM];
- short s_switch_pcl[RF_TX_LEVEL_2_CAL_COUNT];
- double d_wanted_p[TOTAL_DCS_PCL_NUM];
- double d_correction[TOTAL_DCS_PCL_NUM];
- double d_Vout_cal[RF_TX_LEVEL_6_CAL_COUNT];
- double d_Vramp_cal[RF_TX_LEVEL_6_CAL_COUNT];
- double d_slope[RF_TX_LEVEL_3_CAL_COUNT];
- double d_Vout_eval[TOTAL_DCS_PCL_NUM];
- double d_Vramp_eval[TOTAL_DCS_PCL_NUM];
- unsigned short us_ApcDac_cal[RF_TX_LEVEL_6_CAL_COUNT];
- unsigned short us_ApcDac_eval[TOTAL_DCS_PCL_NUM];
- int i_ApcDcOffset;
- log->Add("n" +DateToStr(Date()) + " " + CurrentTimeStr() +
- " =================== Evaluate PCL DAC value begin =================== "
- );
- // calculate Vset DAC value
- FrequencyBand eFreqBand = FrequencyBand850;
- while (eFreqBand < FrequencyBandCount)
- {
- switch (eFreqBand)
- {
- case FrequencyBand850:
- {
- if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- s_ARFCN = m_sARFCN_C0_GSM850;
- s_first_pcl = GSM850_FIRST_PCL;
- c_total_pcl_num = TOTAL_GSM850_PCL_NUM;
- as_tx_pcl = m_as_gsm850_tx_pcl;
- as_tx_6cal_pcl = m_as_gsm850_tx_6cal_pcl;
- as_switch_pcl = m_asAXIOM502_GSM850_SWITCH_PCL;
- as_wanted_p = m_as_gsm850_wanted_p;
- as_correction = m_as_gsm850_correction;
- }
- break;
- case FrequencyBand900:
- {
- if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- s_ARFCN = m_sARFCN_C0_GSM;
- s_first_pcl = GSM900_FIRST_PCL;
- c_total_pcl_num = TOTAL_GSM_PCL_NUM;
- as_tx_pcl = m_as_gsm900_tx_pcl;
- as_tx_6cal_pcl = m_as_gsm900_tx_6cal_pcl;
- as_switch_pcl = m_asAXIOM502_GSM900_SWITCH_PCL;
- as_wanted_p = m_as_gsm900_wanted_p;
- as_correction = m_as_gsm900_correction;
- }
- break;
- case FrequencyBand1800:
- {
- if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- s_ARFCN = m_sARFCN_C0_DCS;
- s_first_pcl = DCS1800_FIRST_PCL;
- c_total_pcl_num = TOTAL_DCS_PCL_NUM;
- as_tx_pcl = m_as_dcs1800_tx_pcl;
- as_tx_6cal_pcl = m_as_dcs1800_tx_6cal_pcl;
- as_switch_pcl = m_asAXIOM502_DCS1800_SWITCH_PCL;
- as_wanted_p = m_as_dcs1800_wanted_p;
- as_correction = m_as_dcs1800_correction;
- }
- break;
- case FrequencyBand1900:
- {
- if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
- {
- eFreqBand++;
- continue;
- }
- s_ARFCN = m_sARFCN_C0_PCS;
- s_first_pcl = PCS1900_FIRST_PCL;
- c_total_pcl_num = TOTAL_PCS_PCL_NUM;
- as_tx_pcl = m_as_pcs1900_tx_pcl;
- as_tx_6cal_pcl = m_as_pcs1900_tx_6cal_pcl;
- as_switch_pcl = m_asAXIOM502_PCS1900_SWITCH_PCL;
- as_wanted_p = m_as_pcs1900_wanted_p;
- as_correction = m_as_pcs1900_correction;
- }
- break;
- default:
- {
- assert(false);
- }
- break;
- } // switch
- E_BANDSEL band_index = FreqBand_To_BandIdx(eFreqBand);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " " +
- "---------------------------------------------"
- );
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " " +
- BandIdx_To_String(band_index)
- );
- String_To_Array_short(as_tx_6cal_pcl.c_str(), s_tx_6cal_pcl, RF_TX_LEVEL_6_CAL_COUNT);
- String_To_Array_short(as_tx_pcl.c_str(), s_tx_pcl, c_total_pcl_num);
- String_To_Array_short(as_switch_pcl.c_str(), s_switch_pcl, RF_TX_LEVEL_2_CAL_COUNT);
- String_To_Array_double(as_wanted_p.c_str(), d_wanted_p, c_total_pcl_num);
- String_To_Array_double(as_correction.c_str(), d_correction, c_total_pcl_num);
- l1cal_rampTable_T* p_ramp_table = MF_rf_apc_ptr->Get_ApcProfile(band_index);
- for (int i=0; i<RF_TX_LEVEL_6_CAL_COUNT; i++)
- {
- d_Vout_cal[i] = sqrt(0.05 * pow(10.0, m_dPCL_dBm[band_index][i]/10.0));
- }
- for (int i=0; i<RF_TX_LEVEL_6_CAL_COUNT; i++)
- {
- // get subband weighting
- if (!MF_rf_apc_ptr->Get_SubBandWeighting(*p_ramp_table, s_ARFCN, s_tx_6cal_pcl[i], us_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 * us_weight / WEIGHT_SCALE;
- // get ramp up value
- if (! MF_rf_apc_ptr->Get_RightTopRampUpValue(*p_ramp_table, band_index, s_first_pcl-s_tx_6cal_pcl[i], us_ramp_value))
- {
- CalErrorHandler(WM_MF_RF_TX_LEVEL_EVALDAC_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: get ramp up value, index = " + IntToStr(s_first_pcl-s_tx_6cal_pcl[i])
- );
- return false;
- }
- // get battery compensation
- if (!MF_rf_apc_ptr->Get_BatteryCompensate(*p_ramp_table, MID_VOLTAGE_INDEX, MID_TEMPERATURE_INDEX, us_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* us_battery_compensate / BATTERY_COMPENSATE_SCALE;
- us_ApcDac_cal[i] = m_usPCLDacValue[band_index][i] * d_weight * d_battery_compensate * us_ramp_value / MAX_RAMP_VALUE;
- if (!MF_rf_apc_ptr->Get_RealApcDcOffset(m_pCal->b_TADOSupport, band_index, s_tx_6cal_pcl[i], i_ApcDcOffset))
- {
- 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(s_tx_6cal_pcl[i] )
- );
- return false;
- }
- d_Vramp_cal[i] = (i_ApcDcOffset + us_ApcDac_cal[i])/pow(2.0, 10.0) * 2.8;
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Vout_Cal[" + IntToStr(i) + "] = " +
- Double_To_AnsiString(d_Vout_cal[i]) +
- " Vramp_Cal[" + IntToStr(i) + "] = " +
- Double_To_AnsiString(d_Vramp_cal[i])
- );
- }
- for (int i=0; i<RF_TX_LEVEL_3_CAL_COUNT; i++)
- {
- d_slope[i] = (d_Vout_cal[2*i+1] - d_Vout_cal[2*i])/(d_Vramp_cal[2*i+1]-d_Vramp_cal[2*i]);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " slope[" + IntToStr(i) + "] = " +
- Double_To_AnsiString(d_slope[i]) + "n"
- );
- }
- // evalue DAC of each PCL
- for (int i=0; i<c_total_pcl_num; i++)
- {
- // get subband weighting
- if (!MF_rf_apc_ptr->Get_SubBandWeighting(*p_ramp_table, s_ARFCN, s_tx_pcl[i], us_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 * us_weight / WEIGHT_SCALE;
- // get ramp up value
- if (!MF_rf_apc_ptr->Get_RightTopRampUpValue(*p_ramp_table, band_index, s_first_pcl-s_tx_pcl[i], us_ramp_value))
- {
- CalErrorHandler(WM_MF_RF_TX_LEVEL_EVALDAC_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: get ramp up value, index = " + IntToStr(s_first_pcl-s_tx_pcl[i])
- );
- return false;
- }
- // get battery compensation
- if (!MF_rf_apc_ptr->Get_BatteryCompensate(*p_ramp_table, MID_VOLTAGE_INDEX, MID_TEMPERATURE_INDEX, us_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* us_battery_compensate / BATTERY_COMPENSATE_SCALE;
- // APC DC offset
- if (!MF_rf_apc_ptr->Get_RealApcDcOffset(m_pCal->b_TADOSupport, band_index, s_tx_pcl[i], i_ApcDcOffset))
- {
- 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(s_tx_pcl[i])
- );
- return false;
- }
- d_Vout_eval[i] = sqrt(0.05 * pow(10.0, (d_wanted_p[i] + d_correction[i])/10.0));
- if (s_tx_pcl[i] >= s_switch_pcl[0])
- {
- d_Vramp_eval[i] = d_Vramp_cal[0] + (d_Vout_eval[i] - d_Vout_cal[0])/d_slope[0];
- }
- else if ((s_tx_pcl[i] < s_switch_pcl[0]) && (s_tx_pcl[i] >= s_switch_pcl[1]))
- {
- d_Vramp_eval[i] = d_Vramp_cal[2] + (d_Vout_eval[i] - d_Vout_cal[2])/d_slope[1];
- }
- else
- {
- d_Vramp_eval[i] = d_Vramp_cal[4] + (d_Vout_eval[i] - d_Vout_cal[4])/d_slope[2];
- }
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Vramp_eval[" + IntToStr(i) + "] = " +
- Double_To_AnsiString(d_Vramp_eval[i]) + "n"
- );
- // evaluate APC DAC
- us_ApcDac_eval[i] = (d_Vramp_eval[i]*pow(2.0,10.0))/2.8 - i_ApcDcOffset;
- if (d_weight*d_battery_compensate*us_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;
- }
- us_ApcDac_eval[i] = us_ApcDac_eval[i] * MAX_RAMP_VALUE / (d_weight * d_battery_compensate * us_ramp_value);
- MF_rf_apc_ptr->Set_ApcProfilePower(band_index, i, us_ApcDac_eval[i]);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " us_ApcDac_eval[" + IntToStr(i) + "] = " +
- IntToStr(us_ApcDac_eval[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)
- );
- 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
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " ===================== Evaluate other PCL DAC value end =========== n "
- );
- return true;
- }