T_TXPCL_RFMD3159.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:16k
源码类别:

MTK

开发平台:

C++ Builder

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *   T_TXPCL_RFMD3159.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  RFMD 3159 TX PCL source
  48.  *
  49.  * Author:
  50.  * -------
  51.  *  Andy Ueng (mtk00490)
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * $Revision$
  58.  * $Modtime$
  59.  * $Log$
  60.  *
  61.  *------------------------------------------------------------------------------
  62.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  63.  *============================================================================
  64. ****************************************************************************/
  65. #include <assert.h>
  66. #include <math.h>
  67. #pragma hdrstop
  68. #ifndef _T_META_FACTORY_CALIBRATION_H_
  69. #include "T_META_factory_calibration.H"
  70. #endif
  71. #ifndef _CAL_COMMON_H_
  72. #include "cal_common.h"
  73. #endif
  74. #ifndef _APCCAL_COMMON_H_
  75. #include "apccal_common.h"
  76. #endif
  77. #ifndef  _RF_APC_H_
  78. #include "rf_apc.h"
  79. #endif
  80. // callback
  81. #ifndef _META_FACTORY_RF_CB_H_
  82. #include "meta_factory_rf_cb.h"
  83. #endif
  84. #ifndef _META_FACTORY_NVRAM_CB_H_
  85. #include "meta_factory_nvram_cb.h"
  86. #endif
  87. // form
  88. #ifndef _META_FACTORY_H_
  89. #include "META_Factory.h"
  90. #endif
  91. // equipment
  92. #ifndef _AGECOMMON_H_
  93. #include "AgeCommon.h"
  94. #endif
  95. #ifndef  _AGE_MISC_H_
  96. #include "age_misc.h"
  97. #endif
  98. // misc
  99. #ifndef  _FT_UTILS_H_
  100. #include "ft_utils.h"
  101. #endif
  102. #ifndef  _BAND_UTILS_H_
  103. #include "band_utils.h"
  104. #endif
  105. #ifndef  _TIME_UTILS_H_
  106. #include "time_utils.h"
  107. #endif
  108. //----------------------------------------------------------------------------
  109. extern CRFAPC*  MF_rf_apc_ptr;
  110. extern CRFAPC8PSK*  MF_rf_apc_8psk_ptr;
  111. extern RfNbtx_Req *MF_rf_tx_level_req;
  112. extern bool MF_rf_tx_level_cnf;
  113. extern bool  is_suspend_cal; // in T_META_factory_calibration.cpp
  114. //==============================================================================
  115. bool __fastcall T_META_factory_calibration::TXPCLCal_EvalDac_RFMD3159_FixedPaBias(void)
  116. {
  117.     AnsiString   as_epsk_tx_pcl;
  118.     AnsiString   as_epsk_tx_4cal_pcl;
  119.     AnsiString   as_epsk_wanted_p;
  120.     AnsiString   as_epsk_correction;
  121.     AnsiString   as_epsk_sub_tx_pcl;
  122.     AnsiString   as_epsk_sub_tx_4cal_pcl;
  123.     AnsiString   as_epsk_sub_wanted_p;
  124.     AnsiString   as_epsk_sub_correction;
  125.     unsigned short i_EPSK_PCL_Cal[MAX_SUPPORT_BAND_NUM][RF_TX_LEVEL_4_CAL_COUNT];
  126.     double  slope_epsk1[MAX_SUPPORT_BAND_NUM]; // DAC/dBm
  127.     double  slope_epsk2[MAX_SUPPORT_BAND_NUM]; // DAC/dBm
  128.     unsigned short offset_epsk[MAX_SUPPORT_BAND_NUM]; // DAC/dB
  129.     log->Add( "n" +DateToStr(Date()) +  " " + CurrentTimeStr() +
  130.                   " =================== Evaluate PCL DAC value begin =================== "
  131.                 );
  132.     RF_GetITC_PCL  s_itc_pcl;
  133.     META_RESULT MetaResult = META_QueryITC_PCL_r(m_pCal->i_MainMETAHandle, 1000, &s_itc_pcl);
  134.     if (META_SUCCESS != MetaResult)
  135.     {
  136.         CalErrorHandler(WM_MF_RF_QUERY_ITC_PCL_FAIL);
  137.         log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  138.                               " FAIL: Target > query modulator switch PCL"
  139.                         );
  140.         return false;
  141.     }
  142.     unsigned short us_high_band_itc_pcl = (s_itc_pcl.pcl & 0xFFFF0000) >> 16;
  143.     unsigned short us_low_band_itc_pcl  = (s_itc_pcl.pcl & 0x0000FFFF);
  144.     unsigned short us_itc_pcl;
  145.     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  146.                               " Target > High band ITC PCL = " + IntToStr(us_high_band_itc_pcl) +
  147.                               ", Low band ITC PCL = " + IntToStr(us_low_band_itc_pcl)
  148.                         );
  149.     short s_ARFCN;
  150.     E_BANDSEL band_index;
  151.     FrequencyBand eFreqBand = FrequencyBand850;
  152.     while (eFreqBand < FrequencyBandCount)
  153.     {
  154.         switch (eFreqBand)
  155.         {
  156.             case FrequencyBand850:
  157.             {
  158.                 if (! IsFreqBankSupported(m_asFreqBank, eFreqBand))
  159.                 {
  160.                     eFreqBand++;
  161.                     continue;
  162.                 }
  163.                 band_index          = BANDSEL_GSM850;
  164.                 as_epsk_tx_4cal_pcl = m_as_gsm850_epsk_tx_4cal_pcl;
  165.                 as_epsk_tx_pcl      = m_as_gsm850_epsk_tx_pcl;
  166.                 as_epsk_wanted_p    = m_as_gsm850_epsk_wanted_p;
  167.                 as_epsk_correction  = m_as_gsm850_epsk_correction;
  168.                 us_itc_pcl          = us_low_band_itc_pcl;
  169.             }
  170.             break;
  171.             case FrequencyBand900:
  172.             {
  173.                 if (! IsFreqBankSupported(m_asFreqBank, eFreqBand))
  174.                 {
  175.                     eFreqBand++;
  176.                     continue;
  177.                 }
  178.                 band_index          = BANDSEL_GSM900;
  179.                 as_epsk_tx_4cal_pcl = m_as_gsm900_epsk_tx_4cal_pcl;
  180.                 as_epsk_tx_pcl      = m_as_gsm900_epsk_tx_pcl;
  181.                 as_epsk_wanted_p    = m_as_gsm900_epsk_wanted_p;
  182.                 as_epsk_correction  = m_as_gsm900_epsk_correction;
  183.                 us_itc_pcl          = us_low_band_itc_pcl;
  184.             }
  185.             break;
  186.             case FrequencyBand1800:
  187.             {
  188.                 if (! IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  189.                 {
  190.                     eFreqBand++;
  191.                     continue;
  192.                 }
  193.                 band_index          = BANDSEL_DCS1800;
  194.                 as_epsk_tx_4cal_pcl = m_as_dcs1800_epsk_tx_4cal_pcl;
  195.                 as_epsk_tx_pcl      = m_as_dcs1800_epsk_tx_pcl;
  196.                 as_epsk_wanted_p    = m_as_dcs1800_epsk_wanted_p;
  197.                 as_epsk_correction  = m_as_dcs1800_epsk_correction;
  198.                 us_itc_pcl          = us_high_band_itc_pcl;
  199.             }
  200.             break;
  201.             case FrequencyBand1900:
  202.             {
  203.                 if (! IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  204.                 {
  205.                     eFreqBand++;
  206.                     continue;
  207.                 }
  208.                 band_index          = BANDSEL_PCS1900;
  209.                 as_epsk_tx_4cal_pcl = m_as_pcs1900_epsk_tx_4cal_pcl;
  210.                 as_epsk_tx_pcl      = m_as_pcs1900_epsk_tx_pcl;
  211.                 as_epsk_wanted_p    = m_as_pcs1900_epsk_wanted_p;
  212.                 as_epsk_correction  = m_as_pcs1900_epsk_correction;
  213.                 us_itc_pcl          = us_high_band_itc_pcl;
  214.             }
  215.             break;
  216.             default:
  217.                 assert(false);
  218.             break;
  219.         } // switch
  220.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " " +
  221.                               BandIdx_To_String(band_index)
  222.                         );
  223.         for (int i=0; i<RF_TX_LEVEL_4_CAL_COUNT; i++)
  224.         {
  225.             // EPSK
  226.                 if (! getAnsiStrSubItem( as_epsk_tx_4cal_pcl, i+1, DEFAULT_SEP_CHAR, as_epsk_sub_tx_4cal_pcl) )
  227.                 {
  228.                     CalErrorHandler(WM_MF_CFG_READ_FAIL);
  229.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  230.                               " FAIL: Read config file fail(epsk_sub_tx_3cal_pcl)."
  231.                         );
  232.                     return false;
  233.                 }
  234.                 i_EPSK_PCL_Cal[band_index][i] = as_epsk_sub_tx_4cal_pcl.ToInt();
  235.         }
  236.         slope_epsk1[band_index] = (m_usPCLDacValue_EPSK[band_index][3]-m_usPCLDacValue_EPSK[band_index][2])/(m_dPCL_dBm_EPSK[band_index][3]-m_dPCL_dBm_EPSK[band_index][2]);
  237.         slope_epsk2[band_index] = (m_usPCLDacValue_EPSK[band_index][1]-m_usPCLDacValue_EPSK[band_index][0])/(m_dPCL_dBm_EPSK[band_index][1]-m_dPCL_dBm_EPSK[band_index][0]);
  238.         offset_epsk[band_index] = m_usPCLDacValue_EPSK[band_index][1]-(m_usPCLDacValue_EPSK[band_index][2]-(m_dPCL_dBm_EPSK[band_index][2]-m_dPCL_dBm_EPSK[band_index][1])*slope_epsk1[band_index]);
  239.         log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  240.                  " slope_epsk1 = " + Double_To_AnsiString(slope_epsk1[band_index]) + " (DAC/dBm)" +
  241.                  ", slope_epsk2 = " + Double_To_AnsiString(slope_epsk2[band_index]) + " (DAC/dBm)" +
  242.                  ", offset_epsk = " + IntToStr(offset_epsk[band_index])
  243.                             );
  244.         // Evaluate DAC except highest and lowest PCL
  245.             for(int i=0; i<RF_RAMP_TABLE_TX_LEVEL_COUNT; i++)
  246.             {
  247.                 if (i==RF_RAMP_TABLE_TX_LEVEL_COUNT-1 &&
  248.                     (eFreqBand==FrequencyBand850 || eFreqBand==FrequencyBand900 )
  249.                    )
  250.                 {
  251.                     break;
  252.                 }
  253.                 unsigned short us_pcl;
  254.                 double d_wanted_p;
  255.                 double d_correction_p;
  256.                 // EPSK
  257.                 if (! getAnsiStrSubItem(as_epsk_tx_pcl, i+1, DEFAULT_SEP_CHAR, as_epsk_sub_tx_pcl))
  258.                 {
  259.                     CalErrorHandler(WM_MF_CFG_READ_FAIL);
  260.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  261.                               " FAIL: Read config file fail(epsk_sub_tx_pcl)."
  262.                         );
  263.                     return false;
  264.                 }
  265.                 us_pcl = as_epsk_sub_tx_pcl.ToInt();
  266.                 // EPSK
  267.                 if (! getAnsiStrSubItem( as_epsk_wanted_p, i+1, DEFAULT_SEP_CHAR, as_epsk_sub_wanted_p) )
  268.                 {
  269.                     CalErrorHandler(WM_MF_CFG_READ_FAIL);
  270.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  271.                               " FAIL: Read config file fail(epsk_sub_wanted_p)."
  272.                             );
  273.                     return false;
  274.                 }
  275.                 d_wanted_p = atof(as_epsk_sub_wanted_p.c_str());
  276.                 // EPSK
  277.                 if (! getAnsiStrSubItem( as_epsk_correction, i+1, DEFAULT_SEP_CHAR, as_epsk_sub_correction) )
  278.                 {
  279.                     CalErrorHandler(WM_MF_CFG_READ_FAIL);
  280.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  281.                               " FAIL: Read config file fail(as_epsk_sub_correction)."
  282.                             );
  283.                     return false;
  284.                 }
  285.                 d_correction_p = atof(as_epsk_sub_correction.c_str());
  286.                 // EPSK
  287.                 if (as_epsk_sub_tx_pcl.ToInt() != i_EPSK_PCL_Cal[band_index][PCL_LOW_INDEX] &&
  288.                     as_epsk_sub_tx_pcl.ToInt() != i_EPSK_PCL_Cal[band_index][PCL_MID_INDEX] &&
  289.                     as_epsk_sub_tx_pcl.ToInt() != i_EPSK_PCL_Cal[band_index][PCL_HIGH_INDEX] &&
  290.                     as_epsk_sub_tx_pcl.ToInt() != i_EPSK_PCL_Cal[band_index][PCL_HIGH_INDEX+1]
  291.                    )
  292.                 {
  293.                     if (us_pcl <= us_itc_pcl)
  294.                     {
  295.                         m_usPCLDacValue_ideal_EPSK[band_index][i] = m_usPCLDacValue_EPSK[band_index][3] - (m_dPCL_dBm_EPSK[band_index][3] - (d_wanted_p + d_correction_p)) * slope_epsk1[band_index];
  296.                     }
  297.                     else if (us_pcl == us_itc_pcl+1)
  298.                     {
  299.                         m_usPCLDacValue_ideal_EPSK[band_index][i] = m_usPCLDacValue_EPSK[band_index][3] - (m_dPCL_dBm_EPSK[band_index][3] - (d_wanted_p + d_correction_p)) * slope_epsk1[band_index] + offset_epsk[band_index];
  300.                     }
  301.                     else
  302.                     {
  303.                         m_usPCLDacValue_ideal_EPSK[band_index][i] = m_usPCLDacValue_EPSK[band_index][1] - (m_dPCL_dBm_EPSK[band_index][1] - (d_wanted_p + d_correction_p)) * slope_epsk2[band_index];
  304.                     }
  305.                     MF_rf_apc_8psk_ptr->Set_ApcProfilePower( band_index, i, m_usPCLDacValue_ideal_EPSK[band_index][i] );
  306.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  307.                           // "                         " +
  308.                            " m_usPCLDacValue_ideal_EPSK[" + IntToStr(band_index) + "][" + IntToStr(i) + "] = " +
  309.                              Double_To_AnsiString(m_usPCLDacValue_ideal_EPSK[band_index][i]) + "n"
  310.                         );
  311.                 }
  312.             }
  313.         // EPSK
  314.             MF_rf_apc_8psk_ptr->ConfirmCallback = ::ccb_write_apc_to_nvram;
  315.             MF_rf_apc_8psk_ptr->REQ_Write_APC_To_NVRAM_Single_Band_Start(m_pCal->ui_rf_id, band_index);
  316.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  317.                       " Write to NVRAM band_index = " + IntToStr(band_index)
  318.                     );
  319.             RestartTimerCal(WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL);
  320.             CHECK_TERMINATE_BY_USER
  321.             SUSPEND_CAL_THREAD
  322.             E_METAAPP_RESULT_T state = MF_rf_apc_8psk_ptr->Get_ConfirmState();
  323.             if (state != METAAPP_SUCCESS)
  324.             {
  325.                 if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
  326.                 {
  327.                     CalErrorHandler(WM_MF_NVRAM_EF_L1_EPSK_RAMPTABLE_xxx_LID_VERNO_FAIL);
  328.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  329.                                               " FAIL : NVRAM_EF_L1_EPSK_RAMPTABLE_xxx_LID version is not support, please update META to latest version. "
  330.                                               );
  331.                 }
  332.                 else
  333.                 {
  334.                     CalErrorHandler(WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL);
  335.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  336.                                       " FAIL: Target< write EPSK APC to NVRAM "
  337.                                     );
  338.                 }
  339.                 return false;
  340.             }
  341.             WriteEpskAPCCalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath, FreqBand_To_BandIdx(eFreqBand) );
  342.         
  343.         eFreqBand++;
  344.     } // while
  345.     frmFatcory->DisableAllCalTimer();
  346.     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  347.                  " ===================== Evaluate other PCL DAC value end =========== n "
  348.                 );
  349.     return true;
  350. }