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

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.  *   rf_txiq.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   RF TX IQ 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 <IniFiles.hpp>
  66. #pragma hdrstop
  67. #ifndef  _RF_COMMON_H_
  68. #include "rf_common.h"
  69. #endif
  70. #ifndef  _RF_TXIQ_H_
  71. #include "rf_txiq.h"
  72. #endif
  73. #ifndef  _MAN_ACTIVE_H_
  74. #include "man_active.h"
  75. #endif
  76. #ifndef  _MAN_FDM_H_
  77. #include "man_fdm.h"
  78. #endif
  79. // NVRAM
  80. #ifndef  _NVRAM_VER_H_
  81. #include "nvram_ver.h"
  82. #endif
  83. // misc
  84. #ifndef  _FT_UTILS_H_
  85. #include "ft_utils.h"
  86. #endif
  87. //===========================================================================
  88. static CRFTXIQ*  g_rf_txiq_ptr;
  89. static bool g_bIsRunning = false;
  90. //===========================================================================
  91. static void CNF_ReadFromNVRAM(void)
  92. {
  93.     g_rf_txiq_ptr->CNF_ReadFromNVRAM();
  94. }
  95. //------------------------------------------------------------------------------
  96. static void CNF_WriteToNVRAM(void)
  97. {
  98.     g_rf_txiq_ptr->CNF_WriteToNVRAM();
  99. }
  100. //===========================================================================
  101. CRFTXIQ::CRFTXIQ(void)
  102. {
  103.     g_bIsRunning = false;
  104.     ConfirmCallback = NULL;
  105.     m_uiTXIQBufSize = 0;
  106.     m_cTXIQBuf = NULL;
  107. }
  108. //---------------------------------------------------------------------------
  109. CRFTXIQ::~CRFTXIQ()
  110. {
  111.     g_bIsRunning = false;
  112.     ConfirmCallback = NULL;
  113.     ReleaseResource();
  114. }
  115. //---------------------------------------------------------------------------
  116. void CRFTXIQ::ReleaseResource(void)
  117. {
  118.     if (m_cTXIQBuf)
  119.     {
  120.         delete [] m_cTXIQBuf;
  121.         m_cTXIQBuf = NULL;
  122.     }
  123. }
  124. //---------------------------------------------------------------------------
  125. void CRFTXIQ::Init(void)
  126. {
  127.     ReleaseResource();
  128. }
  129. //---------------------------------------------------------------------------
  130. void CRFTXIQ::Confirm(E_METAAPP_RESULT_T confirm_state)
  131. {
  132.     if (!g_bIsRunning)
  133.     {
  134.         return;
  135.     }
  136.     g_bIsRunning = false;
  137.     if (NULL == ConfirmCallback)
  138.     {
  139.         return;
  140.     }
  141.     m_eConfirmState = confirm_state;
  142.     ActiveMan->SetActiveFunction( ConfirmCallback );
  143. }
  144. //===========================================================================
  145. void CRFTXIQ::ResetBbTxParaChangeFlag(void)
  146. {
  147.     m_BbTxParaChangeFlag.b_bbtx_common_mode_voltage = false;
  148.     m_BbTxParaChangeFlag.b_bbtx_gain = false;
  149.     m_BbTxParaChangeFlag.b_bbtx_calrcsel = false;
  150.     m_BbTxParaChangeFlag.b_bbtx_trimI = false;
  151.     m_BbTxParaChangeFlag.b_bbtx_trimQ = false;
  152.     m_BbTxParaChangeFlag.b_bbtx_offsetI = false;
  153.     m_BbTxParaChangeFlag.b_bbtx_offsetQ = false;
  154.     m_BbTxParaChangeFlag.b_bbtx_isCalibrated = false;
  155.     m_BbTxParaChangeFlag.b_apc_bat_low_voltage = false;
  156.     m_BbTxParaChangeFlag.b_apc_bat_high_voltage = false;
  157.     m_BbTxParaChangeFlag.b_apc_bat_low_temperature = false;
  158.     m_BbTxParaChangeFlag.b_apc_bat_high_temperature = false;
  159.     m_BbTxParaChangeFlag.b_bbtx_common_mode_voltage_h = false;
  160.     m_BbTxParaChangeFlag.b_bbtx_gain_h = false;
  161.     m_BbTxParaChangeFlag.b_bbtx_calrcsel_h = false;
  162.     m_BbTxParaChangeFlag.b_bbtx_trimI_h = false;
  163.     m_BbTxParaChangeFlag.b_bbtx_trimQ_h = false;
  164.     m_BbTxParaChangeFlag.b_bbtx_offsetI_h = false;
  165.     m_BbTxParaChangeFlag.b_bbtx_offsetQ_h = false;
  166.     m_BbTxParaChangeFlag.b_bbtx_phsel = false;
  167.     m_BbTxParaChangeFlag.b_bbtx_phsel_h = false;
  168. }
  169. //---------------------------------------------------------------------------
  170. void CRFTXIQ::SetBbTxParaChangeFlag(void)
  171. {
  172.     ResetBbTxParaChangeFlag();
  173.     m_BbTxParaChangeFlag.b_bbtx_trimI = true;
  174.     m_BbTxParaChangeFlag.b_bbtx_trimQ = true;
  175.     m_BbTxParaChangeFlag.b_bbtx_offsetI = true;
  176.     m_BbTxParaChangeFlag.b_bbtx_offsetQ = true;
  177.     if (m_eBbTxCfgVer >= BBTXCFG_VER2)
  178.     {
  179.         m_BbTxParaChangeFlag.b_bbtx_common_mode_voltage = true;
  180.         m_BbTxParaChangeFlag.b_bbtx_gain = true;
  181.         m_BbTxParaChangeFlag.b_bbtx_calrcsel = true;
  182.         m_BbTxParaChangeFlag.b_bbtx_isCalibrated = true;
  183.         m_BbTxParaChangeFlag.b_apc_bat_low_voltage = true;
  184.         m_BbTxParaChangeFlag.b_apc_bat_high_voltage = true;
  185.         m_BbTxParaChangeFlag.b_apc_bat_low_temperature = true;
  186.         m_BbTxParaChangeFlag.b_apc_bat_high_temperature = true;
  187.     }
  188.     if (m_eBbTxCfgVer >= BBTXCFG_VER3)
  189.     {
  190.         m_BbTxParaChangeFlag.b_bbtx_phsel = true;
  191.         if ((RF_ID_A60111A == m_uiFinalRfId) ||
  192.             (RF_ID_AERO2E  == m_uiFinalRfId) ||
  193.             (RF_ID_MT6140A == m_uiFinalRfId) ||
  194.             (RF_ID_MT6140B == m_uiFinalRfId) ||
  195.             (RF_ID_MT6140C == m_uiFinalRfId) ||
  196.             (RF_ID_MT6140D == m_uiFinalRfId)
  197.            )
  198.         {
  199.             m_BbTxParaChangeFlag.b_bbtx_common_mode_voltage_h = true;
  200.             m_BbTxParaChangeFlag.b_bbtx_gain_h = true;
  201.             m_BbTxParaChangeFlag.b_bbtx_calrcsel_h = true;
  202.             m_BbTxParaChangeFlag.b_bbtx_trimI_h = true;
  203.             m_BbTxParaChangeFlag.b_bbtx_trimQ_h = true;
  204.             m_BbTxParaChangeFlag.b_bbtx_offsetI_h = true;
  205.             m_BbTxParaChangeFlag.b_bbtx_offsetQ_h = true;
  206.             m_BbTxParaChangeFlag.b_bbtx_phsel_h = true;
  207.         }
  208.     }
  209. }
  210. //---------------------------------------------------------------------------
  211. void CRFTXIQ::Set_BBTxParametersFromAutoK(RfBBTXCfg2*  p_rf_bbtx_cfg)
  212. {
  213.     // low band
  214.     m_sL1CalTxIq.bbtx_trimI               = p_rf_bbtx_cfg->TxTrimI;
  215.     m_sL1CalTxIq.bbtx_trimQ               = p_rf_bbtx_cfg->TxTrimQ;
  216.     m_sL1CalTxIq.bbtx_offsetI             = p_rf_bbtx_cfg->TxOffsetI;
  217.     m_sL1CalTxIq.bbtx_offsetQ             = p_rf_bbtx_cfg->TxOffsetQ;
  218.     m_sL1CalTxIq.bbtx_gain                = p_rf_bbtx_cfg->TxGain;
  219.     m_sL1CalTxIq.bbtx_calrcsel            = p_rf_bbtx_cfg->TxCalrcsel;
  220.     m_sL1CalTxIq.bbtx_common_mode_voltage = p_rf_bbtx_cfg->TxCMV;
  221.     // high band
  222.     m_sL1CalTxIq.bbtx_trimI_h               = p_rf_bbtx_cfg->TxTrimI;
  223.     m_sL1CalTxIq.bbtx_trimQ_h               = p_rf_bbtx_cfg->TxTrimQ;
  224.     m_sL1CalTxIq.bbtx_offsetI_h             = p_rf_bbtx_cfg->TxOffsetI;
  225.     m_sL1CalTxIq.bbtx_offsetQ_h             = p_rf_bbtx_cfg->TxOffsetQ;
  226.     m_sL1CalTxIq.bbtx_gain_h                = p_rf_bbtx_cfg->TxGain;
  227.     m_sL1CalTxIq.bbtx_calrcsel_h            = p_rf_bbtx_cfg->TxCalrcsel; // new
  228.     m_sL1CalTxIq.bbtx_common_mode_voltage_h = p_rf_bbtx_cfg->TxCMV; // new
  229. }
  230. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  231. signed char CRFTXIQ::Get_BBTx_OffsetI(void)
  232. {
  233.     return m_sL1CalTxIq.bbtx_offsetI;
  234. }
  235. //---------------------------------------------------------------------------
  236. void CRFTXIQ::Set_BBTx_OffsetI(char offset_i)
  237. {
  238.     m_sL1CalTxIq.bbtx_offsetI = offset_i;
  239. }
  240. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  241. signed char CRFTXIQ::Get_BBTx_OffsetQ(void)
  242. {
  243.     return m_sL1CalTxIq.bbtx_offsetQ;
  244. }
  245. //---------------------------------------------------------------------------
  246. void CRFTXIQ::Set_BBTx_OffsetQ(char offset_q)
  247. {
  248.     m_sL1CalTxIq.bbtx_offsetQ = offset_q;
  249. }
  250. //---------------------------------------------------------------------------
  251. void CRFTXIQ::Set_BBTx_isCalibrated(unsigned char isCalibrated)
  252. {
  253.     m_sL1CalTxIq.bbtx_isCalibrated = isCalibrated;
  254. }
  255. //===========================================================================
  256. void CRFTXIQ::Compose_BBTXParameters(void)
  257. {
  258.     if (m_BbTxParaChangeFlag.b_bbtx_common_mode_voltage)
  259.     {
  260.         m_sL1CalTxIq.bbtx_common_mode_voltage = m_sUiL1CalTxIq.BBTXParameters.bbtx_common_mode_voltage & 0x07;
  261.     }
  262.     if (m_BbTxParaChangeFlag.b_bbtx_gain)
  263.     {
  264.         m_sL1CalTxIq.bbtx_gain = m_sUiL1CalTxIq.BBTXParameters.bbtx_gain & 0x07;
  265.     }
  266.     if (m_BbTxParaChangeFlag.b_bbtx_calrcsel)
  267.     {
  268.         m_sL1CalTxIq.bbtx_calrcsel = m_sUiL1CalTxIq.BBTXParameters.bbtx_calrcsel & 0x07;
  269.     }
  270.     if (m_BbTxParaChangeFlag.b_apc_bat_low_voltage)
  271.     {
  272.         m_sL1CalTxIq.apc_bat_low_voltage = m_sUiL1CalTxIq.BBTXParameters.apc_bat_low_voltage*BBTX_BATTERY_VOLTAGE_SCALE;
  273.     }
  274.     if (m_BbTxParaChangeFlag.b_apc_bat_high_voltage)
  275.     {
  276.         m_sL1CalTxIq.apc_bat_high_voltage = m_sUiL1CalTxIq.BBTXParameters.apc_bat_high_voltage*BBTX_BATTERY_VOLTAGE_SCALE;
  277.     }
  278.     if (m_BbTxParaChangeFlag.b_apc_bat_low_temperature)
  279.     {
  280.         m_sL1CalTxIq.apc_bat_low_temperature = m_sUiL1CalTxIq.BBTXParameters.apc_bat_low_temperature*BBTX_BATTERY_TEMP_SCALE;
  281.     }
  282.     if (m_BbTxParaChangeFlag.b_apc_bat_high_temperature)
  283.     {
  284.         m_sL1CalTxIq.apc_bat_high_temperature = m_sUiL1CalTxIq.BBTXParameters.apc_bat_high_temperature*BBTX_BATTERY_TEMP_SCALE;
  285.     }
  286.     if (m_BbTxParaChangeFlag.b_bbtx_trimI)
  287.     {
  288.         m_sL1CalTxIq.bbtx_trimI = m_sUiL1CalTxIq.BBTXParameters.bbtx_trimI;
  289.     }
  290.     if (m_BbTxParaChangeFlag.b_bbtx_trimQ)
  291.     {
  292.         m_sL1CalTxIq.bbtx_trimQ = m_sUiL1CalTxIq.BBTXParameters.bbtx_trimQ;
  293.     }
  294.     if (m_BbTxParaChangeFlag.b_bbtx_offsetI)
  295.     {
  296.         m_sL1CalTxIq.bbtx_offsetI = m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI;
  297.     }
  298.     if (m_BbTxParaChangeFlag.b_bbtx_offsetQ)
  299.     {
  300.         m_sL1CalTxIq.bbtx_offsetQ = m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ;
  301.     }
  302.     if (m_BbTxParaChangeFlag.b_bbtx_isCalibrated)
  303.     {
  304.         m_sL1CalTxIq.bbtx_isCalibrated = m_sUiL1CalTxIq.BBTXParameters.bbtx_isCalibrated*BBTX_CALIBRATED_SCALE;
  305.     }
  306.     if (m_BbTxParaChangeFlag.b_bbtx_phsel)
  307.     {
  308.         m_sL1CalTxIq.bbtx_phsel = m_sUiL1CalTxIq.BBTXParameters.bbtx_phsel;
  309.     }
  310.     if (m_eBbTxCfgVer >= BBTXCFG_VER4)
  311.     {
  312.         if (m_BbTxParaChangeFlag.b_bbtx_offsetI)
  313.         {
  314.             if (m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI > MAX_OFFSET_IQ_OLD)
  315.             {
  316.                 m_sL1CalTxIq.bbtx_offsetI   = m_sL1CalTxIq.bbtx_offsetI - (MAX_OFFSET_IQ_OLD + 1);
  317.                 m_sL1CalTxIq.bbtx_dccoarseI = 1;
  318.             }
  319.             else if (m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI < MIN_OFFSET_IQ_OLD)
  320.             {
  321.                 m_sL1CalTxIq.bbtx_offsetI = m_sL1CalTxIq.bbtx_offsetI + (MAX_OFFSET_IQ_OLD + 1);
  322.                 m_sL1CalTxIq.bbtx_dccoarseI = -1;
  323.             }
  324.             else
  325.             {
  326.                 m_sL1CalTxIq.bbtx_dccoarseI = 0;
  327.             }
  328.         }
  329.         if (m_BbTxParaChangeFlag.b_bbtx_offsetQ)
  330.         {
  331.             if (m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ > MAX_OFFSET_IQ_OLD)
  332.             {
  333.                 m_sL1CalTxIq.bbtx_offsetQ   = m_sL1CalTxIq.bbtx_offsetQ - (MAX_OFFSET_IQ_OLD + 1);
  334.                 m_sL1CalTxIq.bbtx_dccoarseQ = 1;
  335.             }
  336.             else if (m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ < MIN_OFFSET_IQ_OLD)
  337.             {
  338.                 m_sL1CalTxIq.bbtx_offsetQ = m_sL1CalTxIq.bbtx_offsetQ + (MAX_OFFSET_IQ_OLD + 1);
  339.                 m_sL1CalTxIq.bbtx_dccoarseQ = -1;
  340.             }
  341.             else
  342.             {
  343.                 m_sL1CalTxIq.bbtx_dccoarseQ = 0;
  344.             }
  345.         }
  346.     }
  347.     else
  348.     {
  349.         m_sL1CalTxIq.bbtx_dccoarseI = 0;
  350.         m_sL1CalTxIq.bbtx_dccoarseQ = 0;
  351.     }
  352.     // high band parameter
  353.     if ((RF_ID_A60111A == m_uiFinalRfId) ||
  354.         (RF_ID_AERO2E  == m_uiFinalRfId) ||
  355.         (RF_ID_MT6140A == m_uiFinalRfId) ||
  356.         (RF_ID_MT6140B == m_uiFinalRfId) ||
  357.         (RF_ID_MT6140C == m_uiFinalRfId) ||
  358.         (RF_ID_MT6140D == m_uiFinalRfId)
  359.        )
  360.     {
  361.         if (m_BbTxParaChangeFlag.b_bbtx_common_mode_voltage_h)
  362.         {
  363.             m_sL1CalTxIq.bbtx_common_mode_voltage_h = m_sUiL1CalTxIq.BBTXParameters.bbtx_common_mode_voltage_h & 0x07;
  364.         }
  365.         if (m_BbTxParaChangeFlag.b_bbtx_gain_h)
  366.         {
  367.             m_sL1CalTxIq.bbtx_gain_h = m_sUiL1CalTxIq.BBTXParameters.bbtx_gain_h & 0x07;
  368.         }
  369.         if (m_BbTxParaChangeFlag.b_bbtx_calrcsel_h)
  370.         {
  371.             m_sL1CalTxIq.bbtx_calrcsel_h = m_sUiL1CalTxIq.BBTXParameters.bbtx_calrcsel_h & 0x07;
  372.         }
  373.         if (m_BbTxParaChangeFlag.b_bbtx_trimI_h)
  374.         {
  375.             m_sL1CalTxIq.bbtx_trimI_h = m_sUiL1CalTxIq.BBTXParameters.bbtx_trimI_h;
  376.         }
  377.         if (m_BbTxParaChangeFlag.b_bbtx_trimQ_h)
  378.         {
  379.             m_sL1CalTxIq.bbtx_trimQ_h = m_sUiL1CalTxIq.BBTXParameters.bbtx_trimQ_h;
  380.         }
  381.         if (m_BbTxParaChangeFlag.b_bbtx_offsetI_h)
  382.         {
  383.             m_sL1CalTxIq.bbtx_offsetI_h = m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI_h;
  384.         }
  385.         if (m_BbTxParaChangeFlag.b_bbtx_offsetQ_h)
  386.         {
  387.             m_sL1CalTxIq.bbtx_offsetQ_h = m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ_h;
  388.         }
  389.         if (m_BbTxParaChangeFlag.b_bbtx_phsel_h)
  390.         {
  391.             m_sL1CalTxIq.bbtx_phsel_h = m_sUiL1CalTxIq.BBTXParameters.bbtx_phsel_h;
  392.         }
  393.         if (m_eBbTxCfgVer >= BBTXCFG_VER4)
  394.         {
  395.             if (m_BbTxParaChangeFlag.b_bbtx_offsetI_h)
  396.             {
  397.                 if (m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI_h > MAX_OFFSET_IQ_OLD)
  398.                 {
  399.                     m_sL1CalTxIq.bbtx_offsetI_h   = m_sL1CalTxIq.bbtx_offsetI_h - (MAX_OFFSET_IQ_OLD + 1);
  400.                     m_sL1CalTxIq.bbtx_dccoarseI_h = 1;
  401.                 }
  402.                 else if (m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI_h < MIN_OFFSET_IQ_OLD)
  403.                 {
  404.                     m_sL1CalTxIq.bbtx_offsetI_h   = m_sL1CalTxIq.bbtx_offsetI_h + (MAX_OFFSET_IQ_OLD + 1);
  405.                     m_sL1CalTxIq.bbtx_dccoarseI_h = -1;
  406.                 }
  407.                 else
  408.                 {
  409.                     m_sL1CalTxIq.bbtx_dccoarseI_h = 0;
  410.                 }
  411.             }
  412.             if (m_BbTxParaChangeFlag.b_bbtx_offsetQ_h)
  413.             {
  414.                 if (m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ_h > MAX_OFFSET_IQ_OLD)
  415.                 {
  416.                     m_sL1CalTxIq.bbtx_offsetQ_h   = m_sL1CalTxIq.bbtx_offsetQ_h - (MAX_OFFSET_IQ_OLD + 1);
  417.                     m_sL1CalTxIq.bbtx_dccoarseQ_h = 1;
  418.                 }
  419.                 else if (m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ_h < MIN_OFFSET_IQ_OLD)
  420.                 {
  421.                     m_sL1CalTxIq.bbtx_offsetQ_h   = m_sL1CalTxIq.bbtx_offsetQ_h + (MAX_OFFSET_IQ_OLD + 1);
  422.                     m_sL1CalTxIq.bbtx_dccoarseQ_h = -1;
  423.                 }
  424.                 else
  425.                 {
  426.                     m_sL1CalTxIq.bbtx_dccoarseQ_h = 0;
  427.                 }
  428.             }
  429.         }
  430.         else
  431.         {
  432.             m_sL1CalTxIq.bbtx_dccoarseI_h = 0;
  433.             m_sL1CalTxIq.bbtx_dccoarseQ_h = 0;
  434.         }
  435.     }
  436. }
  437. //---------------------------------------------------------------------------
  438. void CRFTXIQ::DeCompose_BBTXParameters(void)
  439. {
  440.     signed char NVRAM2BBTX[] =
  441.     {
  442.         0, 1, 2, 3, -4, -3, -2, -1
  443.     };
  444.     m_sUiL1CalTxIq.BBTXParameters.bbtx_common_mode_voltage = NVRAM2BBTX[m_sL1CalTxIq.bbtx_common_mode_voltage& 0x07];
  445.     m_sUiL1CalTxIq.BBTXParameters.bbtx_gain = NVRAM2BBTX[m_sL1CalTxIq.bbtx_gain & 0x07];
  446.     m_sUiL1CalTxIq.BBTXParameters.bbtx_calrcsel = NVRAM2BBTX[m_sL1CalTxIq.bbtx_calrcsel & 0x07];
  447.     m_sUiL1CalTxIq.BBTXParameters.apc_bat_low_voltage = m_sL1CalTxIq.apc_bat_low_voltage / BBTX_BATTERY_VOLTAGE_SCALE;
  448.     m_sUiL1CalTxIq.BBTXParameters.apc_bat_high_voltage = m_sL1CalTxIq.apc_bat_high_voltage / BBTX_BATTERY_VOLTAGE_SCALE;
  449.     m_sUiL1CalTxIq.BBTXParameters.apc_bat_low_temperature = m_sL1CalTxIq.apc_bat_low_temperature / BBTX_BATTERY_TEMP_SCALE;
  450.     m_sUiL1CalTxIq.BBTXParameters.apc_bat_high_temperature = m_sL1CalTxIq.apc_bat_high_temperature / BBTX_BATTERY_TEMP_SCALE;
  451.     m_sUiL1CalTxIq.BBTXParameters.bbtx_trimI = m_sL1CalTxIq.bbtx_trimI;
  452.     m_sUiL1CalTxIq.BBTXParameters.bbtx_trimQ = m_sL1CalTxIq.bbtx_trimQ;
  453.     m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI = m_sL1CalTxIq.bbtx_offsetI;
  454.     m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ = m_sL1CalTxIq.bbtx_offsetQ;
  455.     m_sUiL1CalTxIq.BBTXParameters.bbtx_isCalibrated = m_sL1CalTxIq.bbtx_isCalibrated / BBTX_CALIBRATED_SCALE;
  456.     if (m_eBbTxCfgVer >= BBTXCFG_VER4)
  457.     {
  458.         if (1 == m_sL1CalTxIq.bbtx_dccoarseI)
  459.         {
  460.             m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI += (MAX_OFFSET_IQ_OLD + 1);
  461.         }
  462.         else if (0xFF == m_sL1CalTxIq.bbtx_dccoarseI)
  463.         {
  464.             m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI -= (MAX_OFFSET_IQ_OLD + 1);
  465.         }
  466.         if (1 == m_sL1CalTxIq.bbtx_dccoarseQ)
  467.         {
  468.             m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ += (MAX_OFFSET_IQ_OLD + 1);
  469.         }
  470.         else if (0xFF == m_sL1CalTxIq.bbtx_dccoarseQ)
  471.         {
  472.             m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ -= (MAX_OFFSET_IQ_OLD + 1);
  473.         }
  474.     }
  475.     // high band parameter
  476.     //if ((RF_ID_MT6140A == rfmod_id) ||
  477.     //    (RF_ID_MT6140B == rfmod_id) ||
  478.     //    (RF_ID_MT6140C == rfmod_id) ||
  479.     //    (RF_ID_MT6140D == rfmod_id)
  480.     //   )
  481.     {
  482.         m_sUiL1CalTxIq.BBTXParameters.bbtx_phsel                 = m_sL1CalTxIq.bbtx_phsel;
  483.         m_sUiL1CalTxIq.BBTXParameters.bbtx_common_mode_voltage_h = NVRAM2BBTX[m_sL1CalTxIq.bbtx_common_mode_voltage_h & 0x07];
  484.         m_sUiL1CalTxIq.BBTXParameters.bbtx_gain_h                = NVRAM2BBTX[m_sL1CalTxIq.bbtx_gain_h & 0x07];
  485.         m_sUiL1CalTxIq.BBTXParameters.bbtx_calrcsel_h            = NVRAM2BBTX[m_sL1CalTxIq.bbtx_calrcsel_h & 0x07];
  486.         m_sUiL1CalTxIq.BBTXParameters.bbtx_trimI_h               = m_sL1CalTxIq.bbtx_trimI_h;
  487.         m_sUiL1CalTxIq.BBTXParameters.bbtx_trimQ_h               = m_sL1CalTxIq.bbtx_trimQ_h;
  488.         m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI_h             = m_sL1CalTxIq.bbtx_offsetI_h;
  489.         m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ_h             = m_sL1CalTxIq.bbtx_offsetQ_h;
  490.         m_sUiL1CalTxIq.BBTXParameters.bbtx_phsel_h               = m_sL1CalTxIq.bbtx_phsel_h;
  491.         if (m_eBbTxCfgVer >= BBTXCFG_VER4)
  492.         {
  493.             if (1 == m_sL1CalTxIq.bbtx_dccoarseI_h)
  494.             {
  495.                 m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI_h += (MAX_OFFSET_IQ_OLD + 1);
  496.             }
  497.             else if (0xFF == m_sL1CalTxIq.bbtx_dccoarseI_h)
  498.             {
  499.                 m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI_h -= (MAX_OFFSET_IQ_OLD + 1);
  500.             }
  501.             if (1 == m_sL1CalTxIq.bbtx_dccoarseQ_h)
  502.             {
  503.                 m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ_h += (MAX_OFFSET_IQ_OLD + 1);
  504.             }
  505.             else if (0xFF == m_sL1CalTxIq.bbtx_dccoarseQ_h)
  506.             {
  507.                 m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ_h -= (MAX_OFFSET_IQ_OLD + 1);
  508.             }
  509.         }    
  510.     }
  511. }
  512. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  513. void CRFTXIQ::REQ_Read_From_NVRAM_Start(unsigned int rfmod_id, E_BBTXCFG_VER_T bbtxcfg_ver)
  514. {
  515.     g_rf_txiq_ptr = this;
  516.     g_bIsRunning = true;
  517.     m_uiFinalRfId = rfmod_id;
  518.     m_eBbTxCfgVer = bbtxcfg_ver;
  519.     m_bDownloadTrigger = false;
  520.     REQ_Read_From_NVRAM();
  521. }
  522. //---------------------------------------------------------------------------
  523. void CRFTXIQ::REQ_Read_From_NVRAM(void)
  524. {
  525.     if (!g_bIsRunning)
  526.     {
  527.         return;
  528.     }
  529.     if (NULL == m_cTXIQBuf)
  530.     {
  531.         META_RESULT MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_TXIQ_LID", (int *) &m_uiTXIQBufSize );
  532.         if (MetaResult != META_SUCCESS)
  533.         {
  534.             Confirm(METAAPP_FAIL);
  535.             return;
  536.         }
  537.         m_cTXIQBuf = new char[m_uiTXIQBufSize];
  538.     }
  539.     NVRAMMan->ConfirmCallback = ::CNF_ReadFromNVRAM;
  540.     NVRAMMan->REQ_ReadNVRAM_Start("NVRAM_EF_L1_TXIQ_LID",
  541.                           1,
  542.                                   m_uiTXIQBufSize,
  543.                                   m_cTXIQBuf);
  544. }
  545. //-------------------------------------
  546. void CRFTXIQ::CNF_ReadFromNVRAM(void)
  547. {
  548.     if (!g_bIsRunning)
  549.     {
  550.         return;
  551.     }
  552.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  553.     switch (state)
  554.     {
  555.         case METAAPP_SUCCESS:
  556.         {
  557.             if (m_bDownloadTrigger)
  558.             {
  559.                 REQ_Write_To_NVRAM();
  560.             }
  561.             else
  562.             {
  563.                 META_RESULT MetaResult;
  564.                 m_eNvBbTxCfgVer = NVRAMMan->Get_NvBbTxCfgVer();
  565.                 if (m_eNvBbTxCfgVer <= NVRAM_BBTXCFG_VER3)
  566.                 {
  567.                     MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  568.                                                 "BBTXParameters.bbtx_common_mode_voltage",
  569.                                                 m_cTXIQBuf,
  570.                                                 m_uiTXIQBufSize,
  571.                                                 &m_sL1CalTxIq.bbtx_common_mode_voltage,
  572.                                                 sizeof(m_sL1CalTxIq.bbtx_common_mode_voltage) );
  573.                     if (MetaResult != META_SUCCESS)
  574.                     {
  575.                         Confirm(METAAPP_FAIL);
  576.                         return;
  577.                     }
  578.                     MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  579.                                                           "BBTXParameters.bbtx_gain",
  580.                                                           m_cTXIQBuf,
  581.                                                           m_uiTXIQBufSize,
  582.                                                           &m_sL1CalTxIq.bbtx_gain,
  583.                                                           sizeof(m_sL1CalTxIq.bbtx_gain) );
  584.                     if (MetaResult != META_SUCCESS)
  585.                     {
  586.                         Confirm(METAAPP_FAIL);
  587.                         return;
  588.                     }
  589.                     MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  590.                                                          "BBTXParameters.bbtx_calrcsel",
  591.                                                          m_cTXIQBuf,
  592.                                                          m_uiTXIQBufSize,
  593.                                                          &m_sL1CalTxIq.bbtx_calrcsel,
  594.                                                          sizeof(m_sL1CalTxIq.bbtx_calrcsel) );
  595.                     if (MetaResult != META_SUCCESS)
  596.                     {
  597.                         Confirm(METAAPP_FAIL);
  598.                         return;
  599.                     }
  600.                     MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  601.                                                          "BBTXParameters.apc_bat_low_voltage",
  602.                                                          m_cTXIQBuf,
  603.                                                          m_uiTXIQBufSize,
  604.                                                          &m_sL1CalTxIq.apc_bat_low_voltage,
  605.                                                          sizeof(m_sL1CalTxIq.apc_bat_low_voltage) );
  606.                     if (MetaResult != META_SUCCESS)
  607.                     {
  608.                         Confirm(METAAPP_FAIL);
  609.                         return;
  610.                     }
  611.                     MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  612.                                                              "BBTXParameters.apc_bat_high_voltage",
  613.                                                          m_cTXIQBuf,
  614.                                                          m_uiTXIQBufSize,
  615.                                                          &m_sL1CalTxIq.apc_bat_high_voltage,
  616.                                                          sizeof(m_sL1CalTxIq.apc_bat_high_voltage) );
  617.                     if (MetaResult != META_SUCCESS)
  618.                     {
  619.                         Confirm(METAAPP_FAIL);
  620.                         return;
  621.                     }
  622.                     MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  623.                                                          "BBTXParameters.apc_bat_low_temperature",
  624.                                                          m_cTXIQBuf,
  625.                                                          m_uiTXIQBufSize,
  626.                                                          &m_sL1CalTxIq.apc_bat_low_temperature,
  627.                                                          sizeof(m_sL1CalTxIq.apc_bat_low_temperature) );
  628.                     if (MetaResult != META_SUCCESS)
  629.                     {
  630.                         Confirm(METAAPP_FAIL);
  631.                         return;
  632.                     }
  633.                     MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  634.                                                          "BBTXParameters.apc_bat_high_temperature",
  635.                                                          m_cTXIQBuf,
  636.                                                          m_uiTXIQBufSize,
  637.                                                          &m_sL1CalTxIq.apc_bat_high_temperature,
  638.                                                          sizeof(m_sL1CalTxIq.apc_bat_high_temperature) );
  639.                     if (MetaResult!=META_SUCCESS)
  640.                     {
  641.                         Confirm( METAAPP_FAIL );
  642.                         return;
  643.                     }
  644.                     MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  645.                                                          "BBTXParameters.bbtx_trimI",
  646.                                                          m_cTXIQBuf,
  647.                                                          m_uiTXIQBufSize,
  648.                                                          &m_sL1CalTxIq.bbtx_trimI ,
  649.                                                          sizeof(m_sL1CalTxIq.bbtx_trimI ) );
  650.                     if (MetaResult!=META_SUCCESS)
  651.                     {
  652.                         Confirm( METAAPP_FAIL );
  653.                         return;
  654.                     }
  655.                     MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  656.                                                          "BBTXParameters.bbtx_trimQ",
  657.                                                          m_cTXIQBuf,
  658.                                                          m_uiTXIQBufSize,
  659.                                                          &m_sL1CalTxIq.bbtx_trimQ,
  660.                                                          sizeof(m_sL1CalTxIq.bbtx_trimQ) );
  661.                     if (MetaResult!=META_SUCCESS)
  662.                     {
  663.                         Confirm( METAAPP_FAIL );
  664.                         return;
  665.                     }
  666.                     MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  667.                                                          "BBTXParameters.bbtx_offsetI",
  668.                                                          m_cTXIQBuf,
  669.                                                          m_uiTXIQBufSize,
  670.                                                          &m_sL1CalTxIq.bbtx_offsetI,
  671.                                                          sizeof(m_sL1CalTxIq.bbtx_offsetI) );
  672.                     if (MetaResult!=META_SUCCESS)
  673.                     {
  674.                         Confirm( METAAPP_FAIL );
  675.                         return;
  676.                     }
  677.                     MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  678.                                                          "BBTXParameters.bbtx_offsetQ",
  679.                                                          m_cTXIQBuf,
  680.                                                          m_uiTXIQBufSize,
  681.                                                          &m_sL1CalTxIq.bbtx_offsetQ,
  682.                                                          sizeof(m_sL1CalTxIq.bbtx_offsetQ) );
  683.                     if (MetaResult!=META_SUCCESS)
  684.                     {
  685.                         Confirm( METAAPP_FAIL );
  686.                         return;
  687.                     }
  688.                     MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  689.                                                          "BBTXParameters.bbtx_isCalibrated",
  690.                                                          m_cTXIQBuf,
  691.                                                          m_uiTXIQBufSize,
  692.                                                          &m_sL1CalTxIq.bbtx_isCalibrated,
  693.                                                          sizeof(m_sL1CalTxIq.bbtx_isCalibrated) );
  694.                     if (MetaResult!=META_SUCCESS)
  695.                     {
  696.                         Confirm( METAAPP_FAIL );
  697.                         return;
  698.                     }
  699.                     if (m_eBbTxCfgVer >= BBTXCFG_VER3)
  700.                     {
  701.                         MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  702.                                                                  "BBTXParameters.bbtx_phsel",
  703.                                                                  m_cTXIQBuf,
  704.                                                                  m_uiTXIQBufSize,
  705.                                                                  &m_sL1CalTxIq.bbtx_phsel,
  706.                                                                  sizeof(m_sL1CalTxIq.bbtx_phsel));
  707.                         if (META_SUCCESS != MetaResult)
  708.                         {
  709.                             Confirm(METAAPP_FAIL);
  710.                             return;
  711.                         }
  712.                     }
  713.                     // high band parameter
  714.                     if ((RF_ID_A60111A == m_uiFinalRfId) ||
  715.                         (RF_ID_AERO2E  == m_uiFinalRfId) ||
  716.                         (RF_ID_MT6140A == m_uiFinalRfId) ||
  717.                         (RF_ID_MT6140B == m_uiFinalRfId) ||
  718.                         (RF_ID_MT6140C == m_uiFinalRfId) ||
  719.                         (RF_ID_MT6140D == m_uiFinalRfId)
  720.                        )
  721.                     {
  722.                         MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  723.                                                              "BBTXParameters.bbtx_common_mode_voltage_h",
  724.                                                              m_cTXIQBuf,
  725.                                                              m_uiTXIQBufSize,
  726.                                                              &m_sL1CalTxIq.bbtx_common_mode_voltage_h,
  727.                                                              sizeof(m_sL1CalTxIq.bbtx_common_mode_voltage_h));
  728.                         if (META_SUCCESS != MetaResult)
  729.                         {
  730.                             Confirm(METAAPP_FAIL);
  731.                             return;
  732.                         }
  733.                         MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  734.                                                              "BBTXParameters.bbtx_gain_h",
  735.                                                              m_cTXIQBuf,
  736.                                                              m_uiTXIQBufSize,
  737.                                                              &m_sL1CalTxIq.bbtx_gain_h,
  738.                                                              sizeof(m_sL1CalTxIq.bbtx_gain_h));
  739.                         if (META_SUCCESS != MetaResult)
  740.                         {
  741.                             Confirm(METAAPP_FAIL);
  742.                             return;
  743.                         }
  744.                         MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  745.                                                              "BBTXParameters.bbtx_calrcsel_h",
  746.                                                              m_cTXIQBuf,
  747.                                                              m_uiTXIQBufSize,
  748.                                                              &m_sL1CalTxIq.bbtx_calrcsel_h,
  749.                                                              sizeof(m_sL1CalTxIq.bbtx_calrcsel_h));
  750.                         if (META_SUCCESS != MetaResult)
  751.                         {
  752.                             Confirm(METAAPP_FAIL);
  753.                             return;
  754.                         }
  755.                         MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  756.                                                              "BBTXParameters.bbtx_trimI_h",
  757.                                                              m_cTXIQBuf,
  758.                                                              m_uiTXIQBufSize,
  759.                                                              &m_sL1CalTxIq.bbtx_trimI_h,
  760.                                                              sizeof(m_sL1CalTxIq.bbtx_trimI_h));
  761.                         if (META_SUCCESS != MetaResult)
  762.                         {
  763.                             Confirm(METAAPP_FAIL);
  764.                             return;
  765.                         }
  766.                         MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  767.                                                              "BBTXParameters.bbtx_trimQ_h",
  768.                                                              m_cTXIQBuf,
  769.                                                              m_uiTXIQBufSize,
  770.                                                              &m_sL1CalTxIq.bbtx_trimQ_h,
  771.                                                              sizeof(m_sL1CalTxIq.bbtx_trimQ_h));
  772.                         if (META_SUCCESS != MetaResult)
  773.                         {
  774.                             Confirm(METAAPP_FAIL);
  775.                             return;
  776.                         }
  777.                         MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  778.                                                              "BBTXParameters.bbtx_offsetI_h",
  779.                                                              m_cTXIQBuf,
  780.                                                              m_uiTXIQBufSize,
  781.                                                              &m_sL1CalTxIq.bbtx_offsetI_h,
  782.                                                              sizeof(m_sL1CalTxIq.bbtx_offsetI_h));
  783.                         if (META_SUCCESS != MetaResult)
  784.                         {
  785.                             Confirm(METAAPP_FAIL);
  786.                             return;
  787.                         }
  788.                         MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  789.                                                              "BBTXParameters.bbtx_offsetQ_h",
  790.                                                              m_cTXIQBuf,
  791.                                                              m_uiTXIQBufSize,
  792.                                                              &m_sL1CalTxIq.bbtx_offsetQ_h,
  793.                                                              sizeof(m_sL1CalTxIq.bbtx_offsetQ_h));
  794.                         if (META_SUCCESS != MetaResult)
  795.                         {
  796.                             Confirm(METAAPP_FAIL);
  797.                             return;
  798.                         }
  799.                         MetaResult = META_NVRAM_GetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  800.                                                              "BBTXParameters.bbtx_phsel_h",
  801.                                                              m_cTXIQBuf,
  802.                                                              m_uiTXIQBufSize,
  803.                                                              &m_sL1CalTxIq.bbtx_phsel_h,
  804.                                                              sizeof(m_sL1CalTxIq.bbtx_phsel_h));
  805.                         if (META_SUCCESS != MetaResult)
  806.                         {
  807.                             Confirm(METAAPP_FAIL);
  808.                             return;
  809.                         }
  810.                     }
  811.                 }
  812.                 else
  813.                 {
  814.                     MetaResult = META_NVRAM_Decompose_BBTXParameters(&m_sL1CalTxIq, m_cTXIQBuf, m_uiTXIQBufSize);
  815.                     if (META_SUCCESS != MetaResult)
  816.                     {
  817.                         Confirm(METAAPP_FAIL);
  818.                         return;
  819.                     }
  820.                 }
  821.                 DeCompose_BBTXParameters();
  822.                 Confirm(METAAPP_SUCCESS);
  823.             }
  824.         }
  825.         break;
  826.         default:
  827.         {   Confirm(state);
  828.         }
  829.         break;
  830.     }
  831. }
  832. //===========================================================================
  833. void CRFTXIQ::REQ_Write_To_NVRAM_Start(unsigned int rfmod_id, E_BBTXCFG_VER_T bbtxcfg_ver)
  834. {
  835.     g_rf_txiq_ptr = this;
  836.     g_bIsRunning = true;
  837.     m_bDownloadTrigger = true;
  838.     m_uiFinalRfId = rfmod_id;
  839.     m_eBbTxCfgVer = bbtxcfg_ver;
  840.     REQ_Read_From_NVRAM();
  841. }
  842. //----------------------------------------------------------------------------
  843. void CRFTXIQ::REQ_Write_To_NVRAM(void)
  844. {
  845.     if (!g_bIsRunning)
  846.     {
  847.         return;
  848.     }
  849.     META_RESULT MetaResult;
  850.     unsigned short lid_ver;
  851.     //MetaResult = META_NVRAM_GetLIDVersion("NVRAM_EF_L1_TXIQ_LID", &lid_ver);
  852.     //if (lid_ver > NVRAM_EF_L1_TXIQ_LID_VERNO)
  853.     //{
  854.     //    Confirm(METAAPP_NVRAM_LID_VER_NOT_SUPPORT);
  855.     //    return;
  856.     //}
  857.     if (NULL == m_cTXIQBuf)
  858.     {
  859.         MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_TXIQ_LID", (int *)&m_uiTXIQBufSize );
  860.         if (MetaResult != META_SUCCESS)
  861.         {
  862.             Confirm(METAAPP_FAIL);
  863.             return;
  864.         }
  865.         m_cTXIQBuf = new  char[m_uiTXIQBufSize];
  866.     }
  867.     // compse
  868.     m_eNvBbTxCfgVer = NVRAMMan->Get_NvBbTxCfgVer();
  869.     if (m_eNvBbTxCfgVer <= NVRAM_BBTXCFG_VER3)
  870.     {
  871.        // if (m_BbTxParaChangeFlag.b_bbtx_common_mode_voltage)
  872.         {
  873.             MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  874.                                                      "BBTXParameters.bbtx_common_mode_voltage",
  875.                                                      m_cTXIQBuf,
  876.                                                      m_uiTXIQBufSize,
  877.                                                      &m_sL1CalTxIq.bbtx_common_mode_voltage,
  878.                                                      sizeof(m_sL1CalTxIq.bbtx_common_mode_voltage));
  879.             if (MetaResult != META_SUCCESS)
  880.             {
  881.                 Confirm(METAAPP_FAIL);
  882.                 return;
  883.             }
  884.         }
  885.        // if (m_BbTxParaChangeFlag.b_bbtx_gain)
  886.         {
  887.             MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  888.                                                      "BBTXParameters.bbtx_gain",
  889.                                                      m_cTXIQBuf,
  890.                                                      m_uiTXIQBufSize,
  891.                                                      &m_sL1CalTxIq.bbtx_gain,
  892.                                                      sizeof(m_sL1CalTxIq.bbtx_gain)
  893.                                                     );
  894.             if (MetaResult != META_SUCCESS)
  895.             {
  896.                 Confirm(METAAPP_FAIL);
  897.                 return;
  898.             }
  899.         }
  900.        // if (m_BbTxParaChangeFlag.b_bbtx_calrcsel)
  901.         {
  902.             MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  903.                                                      "BBTXParameters.bbtx_calrcsel",
  904.                                                      m_cTXIQBuf,
  905.                                                      m_uiTXIQBufSize,
  906.                                                      &m_sL1CalTxIq.bbtx_calrcsel,
  907.                                                      sizeof(m_sL1CalTxIq.bbtx_calrcsel)
  908.                                                     );
  909.             if (MetaResult != META_SUCCESS)
  910.             {
  911.                 Confirm(METAAPP_FAIL);
  912.                 return;
  913.             }
  914.         }
  915.         //if (m_BbTxParaChangeFlag.b_apc_bat_low_voltage)
  916.         {
  917.             MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  918.                                                      "BBTXParameters.apc_bat_low_voltage",
  919.                                                      m_cTXIQBuf,
  920.                                                      m_uiTXIQBufSize,
  921.                                                      &m_sL1CalTxIq.apc_bat_low_voltage,
  922.                                                      sizeof(m_sL1CalTxIq.apc_bat_low_voltage)
  923.                                                     );
  924.             if (MetaResult != META_SUCCESS)
  925.             {
  926.                 Confirm(METAAPP_FAIL);
  927.                 return;
  928.             }
  929.         }
  930.         //if (m_BbTxParaChangeFlag.b_apc_bat_high_voltage)
  931.         {
  932.             MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  933.                                                      "BBTXParameters.apc_bat_high_voltage",
  934.                                                      m_cTXIQBuf,
  935.                                                      m_uiTXIQBufSize,
  936.                                                      &m_sL1CalTxIq.apc_bat_high_voltage,
  937.                                                      sizeof(m_sL1CalTxIq.apc_bat_high_voltage)
  938.                                                     );
  939.             if (MetaResult != META_SUCCESS)
  940.             {
  941.                 Confirm(METAAPP_FAIL);
  942.                 return;
  943.             }
  944.         }
  945.         //if (m_BbTxParaChangeFlag.b_apc_bat_low_temperature)
  946.         {
  947.             MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  948.                                                      "BBTXParameters.apc_bat_low_temperature",
  949.                                                      m_cTXIQBuf,
  950.                                                      m_uiTXIQBufSize,
  951.                                                      &m_sL1CalTxIq.apc_bat_low_temperature,
  952.                                                      sizeof(m_sL1CalTxIq.apc_bat_low_temperature)
  953.                                                     );
  954.             if (MetaResult != META_SUCCESS)
  955.             {
  956.                 Confirm(METAAPP_FAIL);
  957.                 return;
  958.             }
  959.         }
  960.         //if (m_BbTxParaChangeFlag.b_apc_bat_high_temperature)
  961.         {
  962.             MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  963.                                                      "BBTXParameters.apc_bat_high_temperature",
  964.                                                      m_cTXIQBuf,
  965.                                                      m_uiTXIQBufSize,
  966.                                                      &m_sL1CalTxIq.apc_bat_high_temperature,
  967.                                                      sizeof(m_sL1CalTxIq.apc_bat_high_temperature)
  968.                                                     );
  969.             if (MetaResult != META_SUCCESS)
  970.             {
  971.                 Confirm(METAAPP_FAIL);
  972.                 return;
  973.             }
  974.         }
  975.         //if (m_BbTxParaChangeFlag.b_bbtx_trimI)
  976.         {
  977.             MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  978.                                                      "BBTXParameters.bbtx_trimI",
  979.                                                      m_cTXIQBuf,
  980.                                                      m_uiTXIQBufSize,
  981.                                                      &m_sL1CalTxIq.bbtx_trimI,
  982.                                                      sizeof(m_sL1CalTxIq.bbtx_trimI)
  983.                                                     );
  984.             if (MetaResult != META_SUCCESS)
  985.             {
  986.                 Confirm(METAAPP_FAIL);
  987.                 return;
  988.             }
  989.         }
  990.         //if (m_BbTxParaChangeFlag.b_bbtx_trimQ)
  991.         {
  992.             MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  993.                                                      "BBTXParameters.bbtx_trimQ",
  994.                                                      m_cTXIQBuf,
  995.                                                      m_uiTXIQBufSize,
  996.                                                      &m_sL1CalTxIq.bbtx_trimQ,
  997.                                                      sizeof(m_sL1CalTxIq.bbtx_trimQ)
  998.                                                     );
  999.             if (MetaResult != META_SUCCESS)
  1000.             {
  1001.                 Confirm(METAAPP_FAIL);
  1002.                 return;
  1003.             }
  1004.         }
  1005.         //if (m_BbTxParaChangeFlag.b_bbtx_offsetI)
  1006.         {
  1007.             MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  1008.                                                      "BBTXParameters.bbtx_offsetI",
  1009.                                                      m_cTXIQBuf,
  1010.                                                      m_uiTXIQBufSize,
  1011.                                                      &m_sL1CalTxIq.bbtx_offsetI,
  1012.                                                      sizeof(m_sL1CalTxIq.bbtx_offsetI)
  1013.                                                     );
  1014.             if (MetaResult != META_SUCCESS)
  1015.             {
  1016.                 Confirm(METAAPP_FAIL);
  1017.                 return;
  1018.             }
  1019.         }
  1020.         //if (m_BbTxParaChangeFlag.b_bbtx_offsetQ)
  1021.         {
  1022.             MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  1023.                                                      "BBTXParameters.bbtx_offsetQ",
  1024.                                                      m_cTXIQBuf,
  1025.                                                      m_uiTXIQBufSize,
  1026.                                                      &m_sL1CalTxIq.bbtx_offsetQ,
  1027.                                                      sizeof(m_sL1CalTxIq.bbtx_offsetQ)
  1028.                                                    );
  1029.             if (MetaResult != META_SUCCESS)
  1030.             {
  1031.                 Confirm(METAAPP_FAIL);
  1032.                 return;
  1033.             }
  1034.         }
  1035.         //if (m_BbTxParaChangeFlag.b_bbtx_isCalibrated)
  1036.         {
  1037.             MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  1038.                                                      "BBTXParameters.bbtx_isCalibrated",
  1039.                                                      m_cTXIQBuf,
  1040.                                                      m_uiTXIQBufSize,
  1041.                                                      &m_sL1CalTxIq.bbtx_isCalibrated,
  1042.                                                      sizeof(m_sL1CalTxIq.bbtx_isCalibrated)
  1043.                                                     );
  1044.             if (MetaResult != META_SUCCESS)
  1045.             {
  1046.                 Confirm(METAAPP_FAIL);
  1047.                 return;
  1048.             }
  1049.         }
  1050.         if (m_eBbTxCfgVer >= BBTXCFG_VER3)
  1051.         {
  1052.             //if (m_BbTxParaChangeFlag.b_bbtx_phsel)
  1053.             {
  1054.                 MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  1055.                                                          "BBTXParameters.bbtx_phsel",
  1056.                                                          m_cTXIQBuf,
  1057.                                                          m_uiTXIQBufSize,
  1058.                                                          &m_sL1CalTxIq.bbtx_phsel,
  1059.                                                          sizeof(m_sL1CalTxIq.bbtx_phsel)
  1060.                                                         );
  1061.                 if (META_SUCCESS != MetaResult)
  1062.                 {
  1063.                     Confirm(METAAPP_FAIL);
  1064.                     return;
  1065.                 }
  1066.             }
  1067.         }
  1068.         if ((RF_ID_A60111A == m_uiFinalRfId) ||
  1069.             (RF_ID_AERO2E  == m_uiFinalRfId) ||
  1070.             (RF_ID_MT6140A == m_uiFinalRfId) ||
  1071.             (RF_ID_MT6140B == m_uiFinalRfId) ||
  1072.             (RF_ID_MT6140C == m_uiFinalRfId) ||
  1073.             (RF_ID_MT6140D == m_uiFinalRfId)
  1074.            )
  1075.         {
  1076.             //if (m_BbTxParaChangeFlag.b_bbtx_common_mode_voltage_h)
  1077.             {
  1078.                 MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  1079.                                                          "BBTXParameters.bbtx_common_mode_voltage_h",
  1080.                                                          m_cTXIQBuf,
  1081.                                                          m_uiTXIQBufSize,
  1082.                                                          &m_sL1CalTxIq.bbtx_common_mode_voltage_h,
  1083.                                                          sizeof(m_sL1CalTxIq.bbtx_common_mode_voltage_h)
  1084.                                                         );
  1085.                 if (META_SUCCESS != MetaResult)
  1086.                 {
  1087.                     Confirm(METAAPP_FAIL);
  1088.                     return;
  1089.                 }
  1090.             }
  1091.             //if (m_BbTxParaChangeFlag.b_bbtx_gain_h)
  1092.             {
  1093.                 MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  1094.                                                          "BBTXParameters.bbtx_gain_h",
  1095.                                                          m_cTXIQBuf,
  1096.                                                          m_uiTXIQBufSize,
  1097.                                                          &m_sL1CalTxIq.bbtx_gain_h,
  1098.                                                          sizeof(m_sL1CalTxIq.bbtx_gain_h)
  1099.                                                         );
  1100.                 if (META_SUCCESS != MetaResult)
  1101.                 {
  1102.                     Confirm(METAAPP_FAIL);
  1103.                     return;
  1104.                 }
  1105.             }
  1106.             //if (m_BbTxParaChangeFlag.b_bbtx_calrcsel_h)
  1107.             {
  1108.                 MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  1109.                                                          "BBTXParameters.bbtx_calrcsel_h",
  1110.                                                          m_cTXIQBuf,
  1111.                                                          m_uiTXIQBufSize,
  1112.                                                          &m_sL1CalTxIq.bbtx_calrcsel_h,
  1113.                                                          sizeof(m_sL1CalTxIq.bbtx_calrcsel_h)
  1114.                                                         );
  1115.                 if (META_SUCCESS != MetaResult)
  1116.                 {
  1117.                     Confirm(METAAPP_FAIL);
  1118.                     return;
  1119.                 }
  1120.             }
  1121.             //if (m_BbTxParaChangeFlag.b_bbtx_trimI_h)
  1122.             {
  1123.                 MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  1124.                                                          "BBTXParameters.bbtx_trimI_h",
  1125.                                                          m_cTXIQBuf,
  1126.                                                          m_uiTXIQBufSize,
  1127.                                                          &m_sL1CalTxIq.bbtx_trimI_h,
  1128.                                                          sizeof(m_sL1CalTxIq.bbtx_trimI_h)
  1129.                                                         );
  1130.                 if (META_SUCCESS != MetaResult)
  1131.                 {
  1132.                     Confirm(METAAPP_FAIL);
  1133.                     return;
  1134.                 }
  1135.             }
  1136.             //if (m_BbTxParaChangeFlag.b_bbtx_trimQ_h)
  1137.             {
  1138.                 MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  1139.                                                          "BBTXParameters.bbtx_trimQ_h",
  1140.                                                          m_cTXIQBuf,
  1141.                                                          m_uiTXIQBufSize,
  1142.                                                          &m_sL1CalTxIq.bbtx_trimQ_h,
  1143.                                                          sizeof(m_sL1CalTxIq.bbtx_trimQ_h)
  1144.                                                         );
  1145.                 if (META_SUCCESS != MetaResult)
  1146.                 {
  1147.                     Confirm(METAAPP_FAIL);
  1148.                     return;
  1149.                 }
  1150.             }
  1151.             //if (m_BbTxParaChangeFlag.b_bbtx_offsetI_h)
  1152.             {
  1153.                 MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  1154.                                                          "BBTXParameters.bbtx_offsetI_h",
  1155.                                                          m_cTXIQBuf,
  1156.                                                          m_uiTXIQBufSize,
  1157.                                                          &m_sL1CalTxIq.bbtx_offsetI_h,
  1158.                                                          sizeof(m_sL1CalTxIq.bbtx_offsetI_h)
  1159.                                                         );
  1160.                 if (META_SUCCESS != MetaResult)
  1161.                 {
  1162.                     Confirm(METAAPP_FAIL);
  1163.                     return;
  1164.                 }
  1165.             }
  1166.             //if (m_BbTxParaChangeFlag.b_bbtx_offsetQ_h)
  1167.             {
  1168.                 MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  1169.                                                          "BBTXParameters.bbtx_offsetQ_h",
  1170.                                                          m_cTXIQBuf,
  1171.                                                          m_uiTXIQBufSize,
  1172.                                                          &m_sL1CalTxIq.bbtx_offsetQ_h,
  1173.                                                          sizeof(m_sL1CalTxIq.bbtx_offsetQ_h)
  1174.                                                        );
  1175.                 if (META_SUCCESS != MetaResult)
  1176.                 {
  1177.                     Confirm(METAAPP_FAIL);
  1178.                     return;
  1179.                 }
  1180.             }
  1181.             //if (m_BbTxParaChangeFlag.b_bbtx_phsel_h)
  1182.             {
  1183.                 MetaResult = META_NVRAM_SetRecFieldValue("NVRAM_EF_L1_TXIQ_LID",
  1184.                                                          "BBTXParameters.bbtx_phsel_h",
  1185.                                                          m_cTXIQBuf,
  1186.                                                          m_uiTXIQBufSize,
  1187.                                                          &m_sL1CalTxIq.bbtx_phsel_h,
  1188.                                                          sizeof(m_sL1CalTxIq.bbtx_phsel_h)
  1189.                                                         );
  1190.                if (META_SUCCESS != MetaResult)
  1191.                {
  1192.                     Confirm(METAAPP_FAIL);
  1193.                     return;
  1194.                }
  1195.            }
  1196.         }
  1197.     }
  1198.     else
  1199.     {
  1200.         MetaResult = META_NVRAM_Compose_BBTXParameters(&m_sL1CalTxIq, m_cTXIQBuf, m_uiTXIQBufSize);
  1201.         if (META_SUCCESS != MetaResult)
  1202.         {
  1203.             Confirm(METAAPP_FAIL);
  1204.             return;
  1205.         }
  1206.     }
  1207.     NVRAMMan->ConfirmCallback = ::CNF_WriteToNVRAM;
  1208.     NVRAMMan->REQ_WriteNVRAM_Start("NVRAM_EF_L1_TXIQ_LID",
  1209.                            1,
  1210.                                    m_uiTXIQBufSize,
  1211.                                    m_cTXIQBuf);
  1212. }
  1213. //-------------------------------------
  1214. void CRFTXIQ::CNF_WriteToNVRAM(void)
  1215. {
  1216.     if (!g_bIsRunning)
  1217.     {
  1218.         return;
  1219.     }
  1220.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  1221.     Confirm(state);
  1222. }
  1223. //===========================================================================
  1224. static const AnsiString as_SECTION_NAME = "BB TX Parameters";
  1225. //---------------------------------------------------------------------------
  1226. bool  CRFTXIQ::TxIqSectionExist( char *filename )
  1227. {
  1228.     TIniFile   *ini_file;
  1229.     ini_file = new TIniFile( filename );
  1230.     if( ini_file == NULL ) return false;
  1231.     if( ini_file->SectionExists( as_SECTION_NAME ) )
  1232.     {
  1233.         return true;
  1234.     }
  1235.     return false;
  1236. }
  1237. //---------------------------------------------------------------------------
  1238. bool CRFTXIQ::REQ_Read_From_File(char *filename, unsigned int rfmod_id, E_BBTXCFG_VER_T bbtxcfg_ver)
  1239. {
  1240.     TIniFile   *ini_file;
  1241.     ini_file = new TIniFile(filename);
  1242.     if (NULL == ini_file)
  1243.     {
  1244.         return false;
  1245.     }
  1246.     m_uiFinalRfId = rfmod_id;
  1247.     m_eBbTxCfgVer = bbtxcfg_ver;
  1248.     ResetBbTxParaChangeFlag();
  1249.     AnsiString as;
  1250.    // if (ini_file->ValueExists(as_SECTION_NAME, "BB TX common mode voltage"))
  1251.     {
  1252.         m_BbTxParaChangeFlag.b_bbtx_common_mode_voltage = true;
  1253.         m_sUiL1CalTxIq.BBTXParameters.bbtx_common_mode_voltage = ini_file->ReadInteger(as_SECTION_NAME,
  1254.                                                                                        "BB TX common mode voltage",
  1255.                                                                                        0);
  1256.     }
  1257.     //if (ini_file->ValueExists(as_SECTION_NAME, "BB TX gain"))
  1258.     {
  1259.         m_BbTxParaChangeFlag.b_bbtx_gain = true;
  1260.         m_sUiL1CalTxIq.BBTXParameters.bbtx_gain = ini_file->ReadInteger(as_SECTION_NAME,
  1261.                                                                         "BB TX gain",
  1262.                                                                         0);
  1263.     }
  1264.     //if (ini_file->ValueExists(as_SECTION_NAME, "BB TX calrcsel"))
  1265.     {
  1266.         m_BbTxParaChangeFlag.b_bbtx_calrcsel = true;
  1267.         m_sUiL1CalTxIq.BBTXParameters.bbtx_calrcsel = ini_file->ReadInteger(as_SECTION_NAME,
  1268.                                                                             "BB TX calrcsel",
  1269.                                                                             0);
  1270.     }
  1271.     //if (ini_file->ValueExists(as_SECTION_NAME, "APC bat low voltage"))
  1272.     {
  1273.         m_BbTxParaChangeFlag.b_apc_bat_low_voltage = true;
  1274.         as = ini_file->ReadString(as_SECTION_NAME,
  1275.                                  "APC bat low voltage",
  1276.                                  "0");
  1277.         m_sUiL1CalTxIq.BBTXParameters.apc_bat_low_voltage = atof(as.c_str());
  1278.     }
  1279.     //if (ini_file->ValueExists(as_SECTION_NAME, "APC bat high voltage"))
  1280.     {
  1281.         m_BbTxParaChangeFlag.b_apc_bat_high_voltage = true;
  1282.         as = ini_file->ReadString(as_SECTION_NAME,
  1283.                                   "APC bat high voltage",
  1284.                                   "0");
  1285.         m_sUiL1CalTxIq.BBTXParameters.apc_bat_high_voltage = atof(as.c_str());
  1286.     }
  1287.     //if (ini_file->ValueExists(as_SECTION_NAME, "APC bat low temperature"))
  1288.     {
  1289.         m_BbTxParaChangeFlag.b_apc_bat_low_temperature = true;
  1290.         as = ini_file->ReadString(as_SECTION_NAME,
  1291.                                   "APC bat low temperature",
  1292.                                  "0");
  1293.         m_sUiL1CalTxIq.BBTXParameters.apc_bat_low_temperature = atof(as.c_str());
  1294.     }
  1295.     //if (ini_file->ValueExists(as_SECTION_NAME, "APC bat high temperature"))
  1296.     {
  1297.         m_BbTxParaChangeFlag.b_apc_bat_high_temperature = true;
  1298.         as = ini_file->ReadString(as_SECTION_NAME,
  1299.                                   "APC bat high temperature",
  1300.                                   0);
  1301.         m_sUiL1CalTxIq.BBTXParameters.apc_bat_high_temperature = atof(as.c_str());
  1302.     }
  1303.     //if (ini_file->ValueExists(as_SECTION_NAME, "Trim I"))
  1304.     {
  1305.         m_BbTxParaChangeFlag.b_bbtx_trimI = true;
  1306.         m_sUiL1CalTxIq.BBTXParameters.bbtx_trimI = ini_file->ReadInteger(as_SECTION_NAME,
  1307.                                                                          "Trim I",
  1308.                                                                          0);
  1309.     }
  1310.     //if (ini_file->ValueExists(as_SECTION_NAME, "Trim Q"))
  1311.     {
  1312.         m_BbTxParaChangeFlag.b_bbtx_trimQ = true;
  1313.         m_sUiL1CalTxIq.BBTXParameters.bbtx_trimQ = ini_file->ReadInteger(as_SECTION_NAME,
  1314.                                                                          "Trim Q",
  1315.                                                                          0);
  1316.     }
  1317.     //if (ini_file->ValueExists(as_SECTION_NAME, "Offset I"))
  1318.     {
  1319.         m_BbTxParaChangeFlag.b_bbtx_offsetI = true;
  1320.         m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI = ini_file->ReadInteger(as_SECTION_NAME,
  1321.                                                                            "Offset I",
  1322.                                                                            0);
  1323.     }
  1324.     //if (ini_file->ValueExists(as_SECTION_NAME, "Offset Q"))
  1325.     {
  1326.         m_BbTxParaChangeFlag.b_bbtx_offsetQ = true;
  1327.         m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ = ini_file->ReadInteger(as_SECTION_NAME,
  1328.                                                                            "Offset Q",
  1329.                                                                            0);
  1330.     }
  1331.     //if (ini_file->ValueExists(as_SECTION_NAME, "Calibrated flag"))
  1332.     {
  1333.         m_BbTxParaChangeFlag.b_bbtx_isCalibrated = true;
  1334.         m_sUiL1CalTxIq.BBTXParameters.bbtx_isCalibrated = ini_file->ReadInteger(as_SECTION_NAME,
  1335.                                                                                "Calibrated flag",
  1336.                                                                                 0);
  1337.     }
  1338.     if (bbtxcfg_ver >= BBTXCFG_VER3)
  1339.     {
  1340.        // if (ini_file->ValueExists(as_SECTION_NAME, "BB TX phasesel"))
  1341.         {
  1342.             m_BbTxParaChangeFlag.b_bbtx_phsel = true;
  1343.             m_sUiL1CalTxIq.BBTXParameters.bbtx_phsel = ini_file->ReadInteger(as_SECTION_NAME,
  1344.                                                                              "BB TX phasesel",
  1345.                                                                              0);
  1346.         }
  1347.         // high band paramter
  1348.         if ((RF_ID_A60111A == rfmod_id) ||
  1349.             (RF_ID_AERO2E  == rfmod_id) ||
  1350.             (RF_ID_MT6140A == rfmod_id) ||
  1351.             (RF_ID_MT6140B == rfmod_id) ||
  1352.             (RF_ID_MT6140C == rfmod_id) ||
  1353.             (RF_ID_MT6140D == rfmod_id)
  1354.            )
  1355.         {
  1356.             //if (ini_file->ValueExists(as_SECTION_NAME, "High band BB TX common mode voltage"))
  1357.             {
  1358.                 m_BbTxParaChangeFlag.b_bbtx_common_mode_voltage_h = true;
  1359.                 m_sUiL1CalTxIq.BBTXParameters.bbtx_common_mode_voltage_h = ini_file->ReadInteger(as_SECTION_NAME,
  1360.                                                                                                  "High band BB TX common mode voltage",
  1361.                                                                                                  0);
  1362.             }
  1363.             //if (ini_file->ValueExists(as_SECTION_NAME, "High band BB TX gain"))
  1364.             {
  1365.                 m_BbTxParaChangeFlag.b_bbtx_gain_h = true;
  1366.                 m_sUiL1CalTxIq.BBTXParameters.bbtx_gain_h = ini_file->ReadInteger(as_SECTION_NAME,
  1367.                                                                               "High band BB TX gain",
  1368.                                                                               0);
  1369.             }
  1370.             //if (ini_file->ValueExists(as_SECTION_NAME, "High band BB TX calrcsel"))
  1371.             {
  1372.                 m_BbTxParaChangeFlag.b_bbtx_calrcsel_h = true;
  1373.                 m_sUiL1CalTxIq.BBTXParameters.bbtx_calrcsel_h = ini_file->ReadInteger(as_SECTION_NAME,
  1374.                                                                                       "High band BB TX calrcsel",
  1375.                                                                                       0);
  1376.             }
  1377.             //if (ini_file->ValueExists(as_SECTION_NAME, "High band Trim I"))
  1378.             {
  1379.                 m_BbTxParaChangeFlag.b_bbtx_trimI_h = true;
  1380.                 m_sUiL1CalTxIq.BBTXParameters.bbtx_trimI_h = ini_file->ReadInteger(as_SECTION_NAME,
  1381.                                                                                    "High band Trim I",
  1382.                                                                                    0);
  1383.             }
  1384.            // if (ini_file->ValueExists(as_SECTION_NAME, "High band Trim Q"))
  1385.             {
  1386.                 m_BbTxParaChangeFlag.b_bbtx_trimQ_h = true;
  1387.                 m_sUiL1CalTxIq.BBTXParameters.bbtx_trimQ_h = ini_file->ReadInteger(as_SECTION_NAME,
  1388.                                                                                    "High band Trim Q",
  1389.                                                                                    0);
  1390.             }
  1391.             //if (ini_file->ValueExists(as_SECTION_NAME, "High band Offset I"))
  1392.             {
  1393.                 m_BbTxParaChangeFlag.b_bbtx_offsetI_h = true;
  1394.                 m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI_h = ini_file->ReadInteger(as_SECTION_NAME,
  1395.                                                                                      "High band Offset I",
  1396.                                                                                      0);
  1397.             }
  1398.             //if (ini_file->ValueExists(as_SECTION_NAME, "High band Offset Q"))
  1399.             {
  1400.                 m_BbTxParaChangeFlag.b_bbtx_offsetQ_h = true;
  1401.                 m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ_h = ini_file->ReadInteger(as_SECTION_NAME,
  1402.                                                                                      "High band Offset Q",
  1403.                                                                                      0);
  1404.             }
  1405.            // if (ini_file->ValueExists(as_SECTION_NAME, "High band BB TX phasesel"))
  1406.             {
  1407.                 m_BbTxParaChangeFlag.b_bbtx_phsel_h = true;
  1408.                 m_sUiL1CalTxIq.BBTXParameters.bbtx_phsel_h = ini_file->ReadInteger(as_SECTION_NAME,
  1409.                                                                                    "High band BB TX phasesel",
  1410.                                                                                    0);
  1411.             }
  1412.         } // MT6140
  1413.     } // ver3
  1414.     Compose_BBTXParameters();
  1415.     delete  ini_file;
  1416.     return true;
  1417. }
  1418. //===========================================================================
  1419. bool CRFTXIQ::REQ_Write_To_File(char *filename, unsigned int rfmod_id, E_BBTXCFG_VER_T bbtxcfg_ver)
  1420. {
  1421.     TIniFile *ini_file;
  1422.     ini_file = new TIniFile(filename);
  1423.     if (NULL == ini_file)
  1424.     {
  1425.         return  false;
  1426.     }
  1427.     m_uiFinalRfId = rfmod_id;
  1428.     m_eBbTxCfgVer = bbtxcfg_ver;
  1429.     ini_file->WriteString(as_SECTION_NAME,
  1430.                               "BB TX common mode voltage",
  1431.                               IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_common_mode_voltage));
  1432.     ini_file->WriteString(as_SECTION_NAME,
  1433.                               "BB TX gain",
  1434.                               IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_gain));
  1435.     ini_file->WriteString(as_SECTION_NAME,
  1436.                               "BB TX calrcsel",
  1437.                               IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_calrcsel));
  1438.     ini_file->WriteString(as_SECTION_NAME,
  1439.                               "APC bat low voltage",
  1440.                               Double_To_AnsiString(m_sUiL1CalTxIq.BBTXParameters.apc_bat_low_voltage) );
  1441.     ini_file->WriteString(as_SECTION_NAME,
  1442.                               "APC bat high voltage",
  1443.                               Double_To_AnsiString(m_sUiL1CalTxIq.BBTXParameters.apc_bat_high_voltage) );
  1444.     ini_file->WriteString(as_SECTION_NAME,
  1445.                               "APC bat low temperature",
  1446.                               Double_To_AnsiString(m_sUiL1CalTxIq.BBTXParameters.apc_bat_low_temperature) );
  1447.     ini_file->WriteString(as_SECTION_NAME,
  1448.                               "APC bat high temperature",
  1449.                               Double_To_AnsiString(m_sUiL1CalTxIq.BBTXParameters.apc_bat_high_temperature) );
  1450.     ini_file->WriteString(as_SECTION_NAME,
  1451.                               "Trim I",
  1452.                               IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_trimI));
  1453.     ini_file->WriteString(as_SECTION_NAME,
  1454.                               "Trim Q",
  1455.                               IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_trimQ));
  1456.     ini_file->WriteString(as_SECTION_NAME,
  1457.                               "Offset I",
  1458.                               IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI));
  1459.     ini_file->WriteString(as_SECTION_NAME,
  1460.                               "Offset Q",
  1461.                               IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ));
  1462.     ini_file->WriteString(as_SECTION_NAME,
  1463.                               "Calibrated flag",
  1464.                               IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_isCalibrated));
  1465.     if (m_eBbTxCfgVer >= BBTXCFG_VER3)
  1466.     {
  1467.         ini_file->WriteString(as_SECTION_NAME,
  1468.                               "BB TX phasesel",
  1469.                               IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_phsel));
  1470.     }
  1471.     // high band paramter
  1472.     if ((RF_ID_A60111A == rfmod_id) ||
  1473.         (RF_ID_AERO2E  == rfmod_id) ||
  1474.         (RF_ID_MT6140A == rfmod_id) ||
  1475.         (RF_ID_MT6140B == rfmod_id) ||
  1476.         (RF_ID_MT6140C == rfmod_id) ||
  1477.         (RF_ID_MT6140D == rfmod_id)
  1478.        )
  1479.     {
  1480.         ini_file->WriteString(as_SECTION_NAME,
  1481.                               "High band BB TX common mode voltage",
  1482.                               IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_common_mode_voltage_h));
  1483.         ini_file->WriteString(as_SECTION_NAME,
  1484.                            "High band BB TX gain",
  1485.                            IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_gain_h) );
  1486.         ini_file->WriteString( as_SECTION_NAME,
  1487.                            "High band BB TX calrcsel",
  1488.                            IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_calrcsel_h) );
  1489.         ini_file->WriteString( as_SECTION_NAME,
  1490.                            "High band Trim I",
  1491.                            IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_trimI_h) );
  1492.         ini_file->WriteString( as_SECTION_NAME,
  1493.                            "High band Trim Q",
  1494.                            IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_trimQ_h) );
  1495.         ini_file->WriteString( as_SECTION_NAME,
  1496.                            "High band Offset I",
  1497.                            IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetI_h) );
  1498.         ini_file->WriteString( as_SECTION_NAME,
  1499.                            "High band Offset Q",
  1500.                            IntToStr(m_sUiL1CalTxIq.BBTXParameters.bbtx_offsetQ_h) );
  1501.         ini_file->WriteString( as_SECTION_NAME,
  1502.                                    "High band BB TX phasesel",
  1503.                                    IntToStr( m_sUiL1CalTxIq.BBTXParameters.bbtx_phsel_h ) );
  1504.     }
  1505.     
  1506.     
  1507.     delete  ini_file;
  1508.     return  true;
  1509. }
  1510. //===========================================================================
  1511. ///////////////////////   Run time setting    ///////////////////////////////
  1512. //===========================================================================
  1513. //===========================================================================
  1514. ////////////////////////////  Global information  ///////////////////////////
  1515. //===========================================================================
  1516. E_METAAPP_RESULT_T CRFTXIQ::Get_ConfirmState(void)
  1517. {
  1518.     return  m_eConfirmState;
  1519. }
  1520. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1521. BBTXParameters_T* CRFTXIQ::Get_BBTXParameters(void)
  1522. {
  1523.     return &m_sL1CalTxIq;
  1524. }
  1525. //---------------------------------------------------------------------------
  1526. void CRFTXIQ::Set_BBTXParameters(BBTXParameters_T l1cal_txiq_par)
  1527. {
  1528.     m_sL1CalTxIq = l1cal_txiq_par;
  1529.     DeCompose_BBTXParameters();
  1530. }
  1531. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1532. S_UI_L1CAL_TXIQ* CRFTXIQ::Get_UiBBTXParameters(void)
  1533. {
  1534.     return &m_sUiL1CalTxIq;
  1535. }
  1536. //---------------------------------------------------------------------------
  1537. void CRFTXIQ::Set_UiBBTXParameters(E_BBTXCFG_VER_T eBbTxCfgVer, unsigned int rf_id, S_UI_L1CAL_TXIQ l1cal_txiq_par)
  1538. {
  1539.     m_eBbTxCfgVer = eBbTxCfgVer;
  1540.     m_uiFinalRfId = rf_id;
  1541.     m_sUiL1CalTxIq = l1cal_txiq_par;
  1542.     SetBbTxParaChangeFlag();
  1543.     Compose_BBTXParameters();
  1544. }
  1545. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1546. void CRFTXIQ::Set_BBTXChangeFlag(S_BBTXPARA_CHANGE_FLAG_T flag)
  1547. {
  1548.     m_BbTxParaChangeFlag = flag;
  1549. }