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

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) 2001
  8. *
  9. *****************************************************************************/
  10. /*****************************************************************************
  11.  *
  12.  * Filename:
  13.  * ---------
  14.  *   T_TXPCL_A60111A.cpp
  15.  *
  16.  * Project:
  17.  * --------
  18.  *   Maui META APP
  19.  *
  20.  * Description:
  21.  * ------------
  22.  *  TX PCL calibration for A60111A transceiver source
  23.  *
  24.  * Author:
  25.  * -------
  26.  *  Andy Ueng (mtk00490)
  27.  *
  28.  *============================================================================
  29.  *             HISTORY
  30.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  31.  *------------------------------------------------------------------------------
  32.  * $Revision$
  33.  * $Modtime$
  34.  * $Log$
  35.  *
  36.  *------------------------------------------------------------------------------
  37.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  38.  *============================================================================
  39. ****************************************************************************/
  40. #include <assert.h>
  41. #include <math.h>
  42. #pragma hdrstop
  43. #ifndef _T_META_FACTORY_CALIBRATION_H_
  44. #include "T_META_factory_calibration.H"
  45. #endif
  46. #ifndef _APCCAL_COMMON_H_
  47. #include "apccal_common.h"
  48. #endif
  49. #ifndef  _RF_APC_H_
  50. #include "rf_apc.h"
  51. #endif
  52. // callback
  53. #ifndef _META_FACTORY_RF_CB_H_
  54. #include "meta_factory_rf_cb.h"
  55. #endif
  56. #ifndef _META_FACTORY_NVRAM_CB_H_
  57. #include "meta_factory_nvram_cb.h"
  58. #endif
  59. // form
  60. #ifndef _META_FACTORY_H_
  61. #include "META_Factory.h"
  62. #endif
  63. // equipment
  64. #ifndef _AGECOMMON_H_
  65. #include "agecommon.h"
  66. #endif
  67. #ifndef _AGE1968A_H_
  68. #include "age1968a.h"
  69. #endif
  70. // misc
  71. #ifndef  _FT_UTILS_H_
  72. #include "ft_utils.h"
  73. #endif
  74. #ifndef  _BAND_UTILS_H_
  75. #include "band_utils.h"
  76. #endif
  77. #ifndef  _GSM_UTILS_H_
  78. #include "gsm_utils.h"
  79. #endif
  80. #ifndef  _TIME_UTILS_H_
  81. #include "time_utils.h"
  82. #endif
  83. #ifndef  _MATH_UTILS_H_
  84. #include "math_utils.h"
  85. #endif
  86. #define MAX_APC_DAC_A60111A      127
  87. #define APC_DAC_A60111A_1DB_END   29
  88. //----------------------------------------------------------------------------
  89. extern CRFAPC*  MF_rf_apc_ptr;
  90. extern CRFAPC8PSK*  MF_rf_apc_8psk_ptr;
  91. //============================================================================
  92. bool __fastcall T_META_factory_calibration::TXPCLCal_EPSK_FullCal_A60111A(void)
  93. {
  94.     AnsiString  as_epsk_tx_pcl;
  95.     short  s_pcl_num;
  96.     AnsiString  as_epsk_max_p;
  97.     AnsiString  as_epsk_wanted_p;
  98.     AnsiString  as_epsk_min_p;
  99.     AnsiString  as_epsk_c;
  100.     log->Add("n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  101.              " ========== EPSK TX power control level calibration begin ========== n "
  102.            );
  103.     if (m_sMAX_APC_DAC > MAX_APC_DAC_A60111A)
  104.     {
  105.         CalErrorHandler(WM_MF_RF_TX_LEVEL_INI_FAIL);
  106.         log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  107.                  " FAIL : MAX_APC_DAC is out of range (range: 0~127)"
  108.                 );
  109.         return false;
  110.     }
  111.     if (!m_rct_ctrl.RCT_operatingMode(m_pRct, OPERATING_MODE_EGPRS_BCH_PDTCH))
  112.     {
  113.         CalErrorHandler(WM_MF_AGE8960_SET_OPERATION_MODE_FAIL);
  114.         log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  115.                  " FAIL : " + m_pRct->as_RCT + " < Operation mode = EGPRS BCH+PDTCH"
  116.                  );
  117.         return false;
  118.     }
  119.     if (!m_rct_ctrl.RCT_Config_EPSK_CodingScheme(m_pRct, MCS5))
  120.     {
  121.         CalErrorHandler(WM_MF_AGE8960_SET_CODING_SCHEME_FAIL);
  122.         log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  123.                  " FAIL: " + m_pRct->as_RCT + " < Coding scheme = MCS5"
  124.                  );
  125.         return false;
  126.     }
  127.     int FIRST_PCL;
  128.     int LAST_PCL;
  129.     short s_arfcn;
  130.     E_BANDSEL band_index;
  131.     int vi_Band;
  132.     FrequencyBand eFreqBand = FrequencyBand850;
  133.     i_N_TX = -99; // TX frames
  134.     //---------------------------------------------------------------------------
  135.     while (eFreqBand < FrequencyBandCount)
  136.     {
  137.         switch (eFreqBand)
  138.         {
  139.             case FrequencyBand850:
  140.             {
  141.                 if (! IsFreqBankSupported(m_asFreqBank, eFreqBand))
  142.                 {
  143.                     eFreqBand++;
  144.                     continue;
  145.                 }
  146.                 FIRST_PCL = GSM850_FIRST_PCL;
  147.                 LAST_PCL = GSM850_LAST_PCL;
  148.                 vi_Band = age1960_GSM850_BAND;
  149.                 band_index = BANDSEL_GSM850;
  150.                 s_arfcn = m_sARFCN_C0_GSM850;
  151.                 as_epsk_wanted_p = m_as_gsm850_epsk_wanted_p;
  152.                 as_epsk_min_p = m_as_gsm850_epsk_min_p;
  153.                 s_pcl_num = TOTAL_GSM850_PCL_NUM;
  154.             }
  155.             break;
  156.             case FrequencyBand900:
  157.             {
  158.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  159.                 {
  160.                     eFreqBand++;
  161.                     continue;
  162.                 }
  163.                 FIRST_PCL = GSM900_FIRST_PCL;
  164.                 LAST_PCL = GSM900_LAST_PCL;
  165.                 vi_Band = age1960_EGSM_BAND;
  166.                 band_index = BANDSEL_GSM900;
  167.                 s_arfcn = m_sARFCN_C0_GSM;
  168.                 as_epsk_wanted_p = m_as_gsm900_epsk_wanted_p;
  169.                 as_epsk_min_p = m_as_gsm900_epsk_min_p;
  170.                 s_pcl_num = TOTAL_GSM_PCL_NUM;
  171.             }
  172.             break;
  173.             case FrequencyBand1800:
  174.             {
  175.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  176.                 {
  177.                     eFreqBand++;
  178.                     continue;
  179.                 }
  180.                 FIRST_PCL = DCS1800_FIRST_PCL;
  181.                 LAST_PCL = DCS1800_LAST_PCL;
  182.                 vi_Band = age1960_DCS1800_BAND;
  183.                 band_index = BANDSEL_DCS1800;
  184.                 s_arfcn = m_sARFCN_C0_DCS;
  185.                 as_epsk_wanted_p = m_as_dcs1800_epsk_wanted_p;
  186.                 as_epsk_min_p = m_as_dcs1800_epsk_min_p;
  187.                 s_pcl_num = TOTAL_DCS_PCL_NUM;
  188.             }
  189.             break;
  190.             case FrequencyBand1900:
  191.             {
  192.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  193.                 {
  194.                     eFreqBand++;
  195.                     continue;
  196.                 }
  197.                 FIRST_PCL = PCS1900_FIRST_PCL;
  198.                 LAST_PCL = PCS1900_LAST_PCL;
  199.                 vi_Band = age1960_PCS1900_BAND;
  200.                 band_index = BANDSEL_PCS1900;
  201.                 s_arfcn = m_sARFCN_C0_PCS;
  202.                 as_epsk_wanted_p = m_as_pcs1900_epsk_wanted_p;
  203.                 as_epsk_min_p = m_as_pcs1900_epsk_min_p;
  204.                 s_pcl_num = TOTAL_PCS_PCL_NUM;
  205.             }
  206.             break;
  207.             default:
  208.                 assert(false);
  209.             break;
  210.         } // switch
  211.         if ( this->Terminated )
  212.         {
  213.             this->OnTerminate = neByUser;
  214.             return false;
  215.         }
  216.         log->Add("n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  217.                  " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  218.                 );
  219.         if (!MF_rf_apc_8psk_ptr->ApcSectionExist(m_pCal->as_IniFile.c_str(), band_index))
  220.         {
  221.             CalErrorHandler(WM_MF_RF_TX_LEVEL_INI_FAIL);
  222.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  223.                      " FAIL : APC section is not in initial file: " + FreqBand_To_Str(eFreqBand)
  224.                      );
  225.             return false;
  226.         }
  227.         unsigned char uc_selectPCS1900 = (FrequencyBand1900 == eFreqBand) ? 1:0;
  228.         if (META_Rf_SelectFrequencyBand1900_r(m_pCal->i_MainMETAHandle, uc_selectPCS1900, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) !=  META_SUCCESS)
  229.         {
  230.             CalErrorHandler(WM_MF_RF_TX_LEVEL_FAIL);
  231.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  232.                      " FAIL: target < set Band1900 flag = " + IntToStr(uc_selectPCS1900)
  233.                     );
  234.             return false;
  235.         }
  236.         is_suspend_cal = true;
  237.         this->Suspend();
  238.         is_suspend_cal = false;
  239.         if (!m_rct_ctrl.RCT_cellBand(m_pRct, vi_Band))
  240.         {
  241.             CalErrorHandler(WM_MF_AGE8960_SET_BAND_FAIL);
  242.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  243.                      " FAIL: " + m_pRct->as_RCT + " < Band = " + ViBand_To_Str(vi_Band)
  244.                      );
  245.             return false;
  246.         }
  247.         Sleep(100);
  248.         if (this->Terminated)
  249.         {
  250.             this->OnTerminate = neByUser;
  251.             return false;
  252.         }
  253.         log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  254.                  m_pRct->as_RCT + " < Band = " + ViBand_To_Str(vi_Band)
  255.                  );
  256.         short s_bch_arfcn = ::Get_SeperateChannel(vi_Band, s_arfcn);
  257.         if (!m_rct_ctrl.RCT_BCHARFCN(m_pRct, s_bch_arfcn))
  258.         {
  259.             CalErrorHandler(WM_MF_AGE8960_SET_BCH_ARFCN_FAIL);
  260.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  261.                      " FAIL: " + m_pRct->as_RCT + " < BCH ARFCN = " + IntToStr(s_bch_arfcn)
  262.                     );
  263.             return false;
  264.         }
  265.         if (!m_rct_ctrl.RCT_PDTCHARFCN(m_pRct, s_arfcn))
  266.         {
  267.             CalErrorHandler(WM_MF_AGE8960_SET_PDTCH_ARFCN_FAIL);
  268.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  269.                      " FAIL: " + m_pRct->as_RCT + " < PDTCH ARFCN = " + IntToStr(s_arfcn)
  270.                      );
  271.             return false;
  272.         }
  273.         if (this->Terminated)
  274.         {
  275.             this->OnTerminate = neByUser;
  276.             return false;
  277.         }
  278.         log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  279.                  m_pRct->as_RCT + " < PDTCH ARFCN = " + IntToStr(s_arfcn)
  280.                  );
  281.         if (!m_rct_ctrl.RCT_ConfigTSC(m_pRct, m_cTSC))
  282.         {
  283.             CalErrorHandler(WM_MF_AGE8960_SET_TSC_FAIL);
  284.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  285.                      "FAIL : " + m_pRct->as_RCT + " < set TSC fail."
  286.                      );
  287.             return false;
  288.         }
  289.         if (this->Terminated)
  290.         {
  291.             this->OnTerminate = neByUser;
  292.             return false;
  293.         }
  294.         log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  295.                  m_pRct->as_RCT + " < TSC = " + IntToStr(m_cTSC)
  296.                 );
  297.         if (!m_rct_ctrl.RCT_EPSK_TXPowerContOff(m_pRct))
  298.         {
  299.             CalErrorHandler(WM_MF_AGE8960_SET_TX_POWER_CONT_OFF_FAIL);
  300.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  301.                      " FAIL : " + m_pRct->as_RCT + " < set TX power continuous OFF "
  302.                      );
  303.             return false;
  304.         }
  305.         if (this->Terminated)
  306.         {
  307.             this->OnTerminate = neByUser;
  308.             return false;
  309.         }
  310.         RestartTimerCal(WM_MF_AGE8960_CONFIG_TX_POWER_FAIL);
  311.         if (!m_rct_ctrl.RCT_confTXPower_EPSK(m_pRct))
  312.         {
  313.             CalErrorHandler(WM_MF_AGE8960_CONFIG_TX_POWER_FAIL);
  314.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  315.                      " FAIL: " + m_pRct->as_RCT + " < config TX power "
  316.                     );
  317.             return false;
  318.         }
  319.         double d_wanted_p[TOTAL_PCS_PCL_NUM];
  320.         double d_min_p[TOTAL_PCS_PCL_NUM];
  321.         String_To_Array_double(as_epsk_wanted_p.c_str(), d_wanted_p, s_pcl_num);
  322.         String_To_Array_double(as_epsk_min_p.c_str(), d_min_p, s_pcl_num);
  323.         short s_equ_pcl = LAST_PCL;
  324.         double d_TxPwr[MAX_APC_DAC_A60111A+1];
  325.         double d_target_pwr = 0.0;
  326.         for (int i = m_sMAX_APC_DAC; i>= APC_DAC_A60111A_1DB_END ; i--)
  327.         {
  328.             if (AGILENT_8960 == m_pRct->device_type)
  329.             {
  330.                 if (!m_rct_ctrl.RCT_PDTCHMSTargetPower(m_pRct, d_target_pwr))
  331.                 {
  332.                     CalErrorHandler(WM_MF_AGE8960_SET_MS_TX_LEVEL_FAIL);
  333.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  334.                          " FAIL: " + m_pRct->as_RCT + " < MS TX level = " + IntToStr(s_equ_pcl)
  335.                          );
  336.                     return false;
  337.                 }
  338.             }
  339.             else
  340.             {
  341.                 if (i <= 40)
  342.                 {
  343.                     s_equ_pcl = FIRST_PCL;
  344.                 }
  345.                 else 
  346.                 {
  347.                     for (int pcl_idx = 0; pcl_idx <= s_pcl_num-1 ; pcl_idx++)
  348.                     {
  349.                         if (i == m_sMAX_APC_DAC)
  350.                         {
  351.                             s_equ_pcl = LAST_PCL;
  352.                             break;
  353.                         }
  354.                         //else if (d_TxPwr[i+1] < d_min_p[pcl_idx])
  355.                         else if (d_TxPwr[i+1] < d_wanted_p[pcl_idx])
  356.                         {
  357.                             s_equ_pcl = FIRST_PCL - pcl_idx;
  358.                             break;
  359.                         }
  360.                     }
  361.                 }
  362.                 if (s_equ_pcl > FIRST_PCL)
  363.                 {
  364.                     s_equ_pcl = FIRST_PCL;
  365.                 }
  366.                 if (!m_rct_ctrl.RCT_PDTCHMSTxLevel(m_pRct, s_equ_pcl))
  367.                 {
  368.                     CalErrorHandler(WM_MF_AGE8960_SET_MS_TX_LEVEL_FAIL);
  369.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  370.                          " FAIL: " + m_pRct->as_RCT + " < MS TX level = " + IntToStr(s_equ_pcl)
  371.                          );
  372.                     return false;
  373.                 }
  374.             }
  375.             if (!MF_rf_stop.REQ_Start())
  376.             {
  377.                 CalErrorHandler(WM_MF_RF_STOP_FAIL);
  378.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  379.                          " FAIL: Target < stop RF fail."
  380.                         );
  381.                 return false;
  382.             }
  383.             RfSetRampApcLevel_Req  RfSetApcDac;
  384.             RfSetApcDac.rf_band = eFreqBand;
  385.             RfSetApcDac.power_level = FIRST_PCL;
  386.             RfSetApcDac.apc_dac = i;
  387.             MF_rf_apc_8psk_ptr->ConfirmCallback = ::ccb_set_apc_level;
  388.             MF_rf_apc_8psk_ptr->REQ_EPSK_SetRampApcLevel_Start(&RfSetApcDac);
  389.             if (this->Terminated)
  390.             {
  391.                 this->OnTerminate = neByUser;
  392.                 return false;
  393.             }
  394.             RestartTimerCal(WM_MF_SET_APC_DAC_FAIL);
  395.             is_suspend_cal = true;
  396.             this->Suspend();
  397.             is_suspend_cal = false;
  398.             E_METAAPP_RESULT_T state = MF_rf_apc_8psk_ptr->Get_ConfirmState();
  399.             if (state != METAAPP_SUCCESS)
  400.             {
  401.                 CalErrorHandler(WM_MF_SET_APC_DAC_FAIL );
  402.                                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  403.                                 " FAIL: Target< set APC level ok. PCL = " + IntToStr(FIRST_PCL) + "," +
  404.                                 " APC DAC = " +  IntToStr(i)  
  405.                                 );
  406.                 return false;
  407.             }
  408.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  409.                      " Target< set APC level, PCL = " + IntToStr(FIRST_PCL) + "," +
  410.                      " APC DAC = " +  IntToStr(i)
  411.                      );
  412.             Sleep(50);
  413.             int pcl[4];
  414.             CodingScheme cs[4];
  415.             cs[0]  = CodingSchemeMCS5;
  416.             cs[1]  = CodingSchemeMCS5;
  417.             cs[2]  = CodingSchemeMCS5;
  418.             cs[3]  = CodingSchemeMCS5;
  419.             pcl[0] = FIRST_PCL;
  420.             pcl[1] = pcl[0];
  421.             pcl[2] = pcl[0];
  422.             pcl[3] = pcl[0];
  423.             S_MULTI_SLOT_TX_T multi_slot_tx;
  424.             multi_slot_tx.b_MultiSlotTXExSupport = m_pCal->b_MultiSlotTxExSupport;
  425.             multi_slot_tx.e_bandsel = band_index;
  426.             multi_slot_tx.req.arfcn = s_arfcn;
  427.             multi_slot_tx.req.bsic  = m_cTSC;
  428.             multi_slot_tx.req.timeSlotmask = 0x01;
  429.             for (int i=0; i<4; i++)
  430.             {
  431.                 multi_slot_tx.req.powerLev[i] = pcl[i];
  432.                 multi_slot_tx.req.cs[i]       = cs[i];
  433.             }
  434.             multi_slot_tx.req.ta = 0;
  435.             multi_slot_tx.req.frames = -99;
  436.             multi_slot_tx.req.dacValue = m_sDefault_value;
  437.             multi_slot_tx.req.pattern = NB_TX_RANDOM_WITH_TSC;
  438.             multi_slot_tx.req.pattern_data = 0;
  439.             RF_MULTI_SLOT_TX_Obj.ConfirmCallback = ::ConfirmCallback_MultiSlotTX;
  440.             RF_MULTI_SLOT_TX_Obj.REQ_Start(multi_slot_tx);
  441.             if (this->Terminated)
  442.             {
  443.                 this->OnTerminate = neByUser;
  444.                 return false;
  445.             }
  446.             log->Add (DateToStr(Date()) +  " " + CurrentTimeStr() +
  447.                       " Target< TX: ARFCN = " + IntToStr(s_arfcn) +
  448.                       ", TSC = " + IntToStr(m_cTSC) +
  449.                       ", PCL = " + IntToStr(pcl[0]) +
  450.                       ", frames = " + IntToStr(i_N_TX) +
  451.                       ", dac value = " + IntToStr(m_sDefault_value)
  452.                     );
  453.             RestartTimerCal(WM_MF_RF_TX_LEVEL_FAIL);
  454.             SUSPEND_CAL_THREAD
  455.             if (RF_MULTI_SLOT_TX_Obj.Get_ConfirmState() != METAAPP_SUCCESS )
  456.             {
  457.                 CalErrorHandler(WM_MF_RF_TX_LEVEL_FAIL);
  458.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  459.                          " FAIL: Target < multislot TX fail."
  460.                          );
  461.                 return false;
  462.             }
  463.             if (this->Terminated)
  464.             {
  465.                 this->OnTerminate = neByUser;
  466.                 return false;
  467.             }
  468.             RestartTimerCal(WM_MF_AGE8960_READ_TX_POWER_FAIL);
  469.             if (!m_rct_ctrl.RCT_ReadTxPower_EPSK(m_pRct, d_TxPwr[i]))
  470.             {
  471.                 CalErrorHandler(WM_MF_AGE8960_READ_TX_POWER_FAIL);
  472.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  473.                          "FAIL: " + m_pRct->as_RCT + " > read TX power"
  474.                          );
  475.                 return false;
  476.             }
  477.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  478.                          m_pRct->as_RCT + " > read TX power = " + Double_To_AnsiString(d_TxPwr[i]) + "n"
  479.                          );
  480.             d_target_pwr = d_TxPwr[i];
  481.         }
  482.         for (short pcl_idx = 0; pcl_idx < s_pcl_num; pcl_idx++)
  483.         {
  484.             for (int i = APC_DAC_A60111A_1DB_END; i <= m_sMAX_APC_DAC; i++)
  485.             {
  486.                 if (m_sMAX_APC_DAC == i)
  487.                 {
  488.                     if (d_TxPwr[i] <= d_wanted_p[pcl_idx])
  489.                     {
  490.                         MF_rf_apc_8psk_ptr->Set_ApcProfilePower(band_index, pcl_idx, i);
  491.                         break;
  492.                     }
  493.                 }
  494.                 else if ((d_TxPwr[i] <= d_wanted_p[pcl_idx]) && (d_wanted_p[pcl_idx] <= d_TxPwr[i+1]))
  495.                 {
  496.                     double d_diff1 = Abs_double(d_TxPwr[i] - d_wanted_p[pcl_idx]);
  497.                     double d_diff2 = Abs_double(d_TxPwr[i+1] - d_wanted_p[pcl_idx]);
  498.                     if (d_diff1 < d_diff2)
  499.                     {
  500.                         MF_rf_apc_8psk_ptr->Set_ApcProfilePower(band_index, pcl_idx, i);
  501.                     }
  502.                     else
  503.                     {
  504.                         MF_rf_apc_8psk_ptr->Set_ApcProfilePower(band_index, pcl_idx, i+1);
  505.                     }
  506.                     break;
  507.                 }
  508.             }
  509.         }
  510.         MF_rf_apc_8psk_ptr->ConfirmCallback = ::ccb_write_apc_to_nvram;
  511.         MF_rf_apc_8psk_ptr->REQ_Write_APC_To_NVRAM_Single_Band_Start(m_pCal->ui_rf_id, band_index);
  512.         log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  513.                       " Write to NVRAM band_index = " + IntToStr(band_index)
  514.                     );
  515.         RestartTimerCal(WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL);
  516.         CHECK_TERMINATE_BY_USER
  517.         SUSPEND_CAL_THREAD
  518.         E_METAAPP_RESULT_T state = MF_rf_apc_8psk_ptr->Get_ConfirmState();
  519.         if (state != METAAPP_SUCCESS)
  520.         {
  521.             if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
  522.             {
  523.                 CalErrorHandler(WM_MF_NVRAM_EF_L1_EPSK_RAMPTABLE_xxx_LID_VERNO_FAIL);
  524.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  525.                                               " FAIL : NVRAM_EF_L1_EPSK_RAMPTABLE_xxx_LID version is not support, please update META to latest version. "
  526.                                               );
  527.             }
  528.             else
  529.             {
  530.                 CalErrorHandler(WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL);
  531.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  532.                                       " FAIL: Target< write EPSK APC to NVRAM "
  533.                                     );
  534.             }
  535.             return false;
  536.         }
  537.         WriteEpskAPCCalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath, FreqBand_To_BandIdx(eFreqBand));
  538.         eFreqBand++;
  539.     } // while
  540.     log->Add("n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  541.              " =========== EPSK TX power control level calibration end =========== n "
  542.            );
  543.     RestartTimerCal(WM_MF_RF_STOP_FAIL);
  544.     if (!MF_rf_stop.REQ_Start())
  545.     {
  546.         CalErrorHandler(WM_MF_RF_STOP_FAIL);
  547.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  548.                           " FAIL: Target < stop RF fail."
  549.                         );
  550.         return false;
  551.     }
  552.     frmFatcory->DisableAllCalTimer();
  553.     return true;
  554. }
  555. //-----------------------------------------------------------------------------
  556. bool __fastcall T_META_factory_calibration::TXPCLCal_EvalDac_A60111A_EPSK(void)
  557. {
  558.     AnsiString as_epsk_wanted_p;
  559.     AnsiString as_epsk_correction;
  560.     short s_pcl_num;
  561.     E_BANDSEL band_index;
  562.     FrequencyBand eFreqBand = FrequencyBand850;
  563.     i_N_TX = -99; // TX frames
  564.     //---------------------------------------------------------------------------
  565.     while (eFreqBand < FrequencyBandCount)
  566.     {
  567.         switch (eFreqBand)
  568.         {
  569.             case FrequencyBand850:
  570.             {
  571.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  572.                 {
  573.                     eFreqBand++;
  574.                     continue;
  575.                 }
  576.                 band_index = BANDSEL_GSM850;
  577.                 as_epsk_wanted_p = m_as_gsm850_epsk_wanted_p;
  578.                 as_epsk_correction = m_as_gsm850_epsk_correction;
  579.                 s_pcl_num = TOTAL_GSM850_PCL_NUM;
  580.             }
  581.             break;
  582.             case FrequencyBand900:
  583.             {
  584.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  585.                 {
  586.                     eFreqBand++;
  587.                     continue;
  588.                 }
  589.                 band_index = BANDSEL_GSM900;
  590.                 as_epsk_wanted_p = m_as_gsm900_epsk_wanted_p;
  591.                 as_epsk_correction = m_as_gsm900_epsk_correction;
  592.                 s_pcl_num = TOTAL_GSM_PCL_NUM;
  593.             }
  594.             break;
  595.             case FrequencyBand1800:
  596.             {
  597.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  598.                 {
  599.                     eFreqBand++;
  600.                     continue;
  601.                 }
  602.                 band_index = BANDSEL_DCS1800;
  603.                 as_epsk_wanted_p = m_as_dcs1800_epsk_wanted_p;
  604.                 as_epsk_correction = m_as_dcs1800_epsk_correction;
  605.                 s_pcl_num = TOTAL_DCS_PCL_NUM;
  606.             }
  607.             break;
  608.             case FrequencyBand1900:
  609.             {
  610.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  611.                 {
  612.                     eFreqBand++;
  613.                     continue;
  614.                 }
  615.                 band_index = BANDSEL_PCS1900;
  616.                 as_epsk_wanted_p = m_as_pcs1900_epsk_wanted_p;
  617.                 as_epsk_correction = m_as_dcs1800_epsk_correction;
  618.                 s_pcl_num = TOTAL_PCS_PCL_NUM;
  619.             }
  620.             break;
  621.             default:
  622.             {
  623.                 assert(false);
  624.             }
  625.             break;
  626.         } // switch
  627.         if (this->Terminated)
  628.         {
  629.             this->OnTerminate = neByUser;
  630.             return false;
  631.         }
  632.         log->Add("n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  633.                          " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  634.                        );
  635.         double d_wanted_p[TOTAL_PCS_PCL_NUM];
  636.         double d_correction[TOTAL_PCS_PCL_NUM];
  637.         String_To_Array_double(as_epsk_wanted_p.c_str(), d_wanted_p, s_pcl_num);
  638.         String_To_Array_double(as_epsk_correction.c_str(), d_correction, s_pcl_num);
  639.         double d_gain_db[MAX_APC_DAC_A60111A+1] =
  640.         {
  641.             1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  // 0~9
  642.             1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  // 10~19
  643.             1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  1.0,  // 20~29
  644.             2.0,  2.0,  3.0,  3.0,  4.0,  4.0,  5.0,  5.0,  6.0,  6.0,  // 30~39
  645.             7.0,  7.0,  8.0,  8.0,  9.0,  9.0, 10.0, 10.0, 11.0, 11.0,  // 40~49
  646.            12.0, 12.0, 13.0, 13.5, 14.0, 14.5, 15.0, 15.5, 16.0, 16.5,  // 50~59
  647.            17.0, 17.5, 18.0, 18.5, 19.0, 19.0, 20.0, 20.5, 21.0, 21.5,  // 60~69
  648.            22.0, 22.5, 23.0, 23.5, 24.0, 24.5, 25.0, 25.5, 26.0, 26.5,  // 70~79
  649.            27.0, 27.5, 28.0, 28.5, 29.0, 29.5, 30.0, 30.5, 31.0, 31.5,  // 80~89
  650.            32.0, 32.5, 33.0, 33.5, 34.0, 34.5, 35.0, 35.5, 36.0, 36.5,  // 90~99
  651.            37.0, 37.0, 37.0, 37.0, 37.0, 37.0, 37.0, 37.0, 37.0, 37.0,  // 100~109
  652.            37.0, 37.0, 37.0, 37.0, 37.0, 37.0, 37.0, 37.0, 37.0, 37.0,  // 110~119
  653.            37.0, 37.0, 37.0, 37.0, 37.0, 37.0, 37.0, 37.0               // 120~127
  654.         };
  655.         for (short pcl_idx = 0; pcl_idx < s_pcl_num-1; pcl_idx++)
  656.         {
  657.             double d_p_diff = m_dPCL_dBm_EPSK[band_index][0] - (d_wanted_p[pcl_idx] + d_correction[pcl_idx]);
  658.             //d_p_diff += (d_p_diff>=0) ? 0.5 : -0.5 ;
  659.            // short s_p_diff = (short) d_p_diff;
  660.             for (short i = m_usPCLDacValue_EPSK[band_index][0]; i >= 29; i--)
  661.             {
  662.                 if (Abs_double(d_gain_db[m_usPCLDacValue_EPSK[band_index][0]] - d_gain_db[i] - d_p_diff) <= 0.5)
  663.                 {
  664.                     MF_rf_apc_8psk_ptr->Set_ApcProfilePower(band_index, pcl_idx, i);
  665.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  666.                              " PCLDacValue_EPSK[" + IntToStr(band_index) + "][" + IntToStr(pcl_idx) + "] = " + IntToStr(i)
  667.                      );
  668.                      break;
  669.                 }
  670.             }
  671.             //short s_eval_dac = m_usPCLDacValue_EPSK[band_index][0] + s_p_diff;
  672.         }
  673.         MF_rf_apc_8psk_ptr->ConfirmCallback = ::ccb_write_apc_to_nvram;
  674.         MF_rf_apc_8psk_ptr->REQ_Write_APC_To_NVRAM_Single_Band_Start(m_pCal->ui_rf_id, band_index);
  675.         log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  676.                  " Write to NVRAM band_index = " + IntToStr(band_index)
  677.                  );
  678.         RestartTimerCal(WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL);
  679.         CHECK_TERMINATE_BY_USER
  680.         SUSPEND_CAL_THREAD
  681.         E_METAAPP_RESULT_T state = MF_rf_apc_8psk_ptr->Get_ConfirmState();
  682.         if (state != METAAPP_SUCCESS)
  683.         {
  684.             if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
  685.             {
  686.                 CalErrorHandler(WM_MF_NVRAM_EF_L1_EPSK_RAMPTABLE_xxx_LID_VERNO_FAIL);
  687.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  688.                          " FAIL : NVRAM_EF_L1_EPSK_RAMPTABLE_xxx_LID version is not support, please update META to latest version. "
  689.                          );
  690.             }
  691.             else
  692.             {
  693.                 CalErrorHandler(WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL);
  694.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  695.                          " FAIL: Target< write EPSK APC to NVRAM "
  696.                          );
  697.             }
  698.             return false;
  699.         }
  700.         WriteEpskAPCCalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath, FreqBand_To_BandIdx(eFreqBand));
  701.         eFreqBand++;
  702.     } // while(eFreqBand)
  703.     return true;
  704. }