T_BT_CAP_ID.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:29k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * T_BT_CAP_ID.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * BT CAP ID calibration source
- *
- * Author:
- * -------
- * Andy Ueng (mtk00490)
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * $Revision$
- * $Modtime$
- * $Log$
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- #include <assert.h>
- #include <math.h>
- #pragma hdrstop
- #ifndef _T_META_FACTORY_CALIBRATION_H_
- #include "T_META_factory_calibration.H"
- #endif
- #ifndef _CAL_COMMON_H_
- #include "cal_common.h"
- #endif
- #ifndef _META_FACTORY_H_
- #include "meta_factory.h"
- #endif
- // BT
- #ifndef _BT_POWER_H_
- #include "bt_power.h"
- #endif
- #ifndef _BT_RF_H_
- #include "bt_rf.h"
- #endif
- #ifndef _BT_CON_H_
- #include "bt_con.h"
- #endif
- #ifndef _BT_INFO_MT6601_H_
- #include "bt_info_mt6601.h"
- #endif
- // misc
- #ifndef _TIME_UTILS_H_
- #include "time_utils.h"
- #endif
- #ifndef _MATH_UTILS_H_
- #include "math_utils.h"
- #endif
- #ifndef _FT_UTILS_H_
- #include "ft_utils.h"
- #endif
- // callback
- #ifndef _MF_BT_CB_H_
- #include "mf_bt_cb.h"
- #endif
- #define TARGET_POLL_COUNT 400000
- extern bool is_suspend_cal;
- //******************************************************************************
- ///////////////////////////// BT CAP ID calibration //////////////////////////
- //******************************************************************************
- bool __fastcall T_META_factory_calibration::BTCrystalCapIDCal_MT6601(void)
- {
- char tempbuf[256];
- S_BT_CT sBTCT;
- S_BTT_INQUIRY s_inquiry;
- E_BTT_STATE_T btt_state;
- S_BT_SCAN scan;
- PostMessage(
- ctrl.hPostMsgDestHandle,
- WM_MF_BT_CRYSTAL_CAPID_BEGIN,
- 0,
- 0
- );
- log->Add("n" +DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================= BT Crystal CAP ID calibration begin ================ "
- );
- // read BT info from NVRAM
- //m_cBT_INFO_Obj.ConfirmCallback = ::CNF_MF_BT;
- //m_cBT_INFO_Obj.REQ_Read_From_NVRAM_Start();
- //RestartTimerCal(WM_MF_NVRAM_BT_INFO_READ_FAIL);
- //SUSPEND_CAL_THREAD
- //E_METAAPP_RESULT_T state = m_cBT_INFO_Obj.Get_ConfirmState();
- //if (state != METAAPP_SUCCESS)
- //{
- // CalErrorHandler( WM_MF_NVRAM_BT_INFO_READ_FAIL);
- // log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- // " FAIL : Target > read BT info. from NVRAM fail "
- // );
- // return false;
- //}
- RestartTimerCal(WM_MF_BTT_CONFIG_BD_ADDRESS_FAIL);
- if (!m_btt_ctrl.BTT_Config_BD_Address(m_pBtt, m_asBD_Address))
- {
- CalErrorHandler(WM_MF_BTT_CONFIG_BD_ADDRESS_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester < Config BD address fail "
- );
- return false;
- }
- //m_cBT_POWER_Obj.REQ_Power_On_Start();
- RestartTimerCal(WM_MF_BTT_CONFIG_SLAVE_PARAMETER_FAIL);
- if (!m_btt_ctrl.BTT_Config_Slave_Parameter(m_pBtt, m_usBT_CRYSTAL_CHANNEL))
- {
- CalErrorHandler(WM_MF_BTT_CONFIG_SLAVE_PARAMETER_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester < Config slave parameter fail "
- );
- return false;
- }
- // inquiry enable
- if (m_asInquiry_Enable.AnsiCompareIC("yes") == 0)
- {
- sBTCT.hPostMsgDestHandle = NULL;
- sBTCT.log = NULL;
- // set inquiry scan interval
- //if (!m_cBT_POWER_Obj.REQ_Query_Power_On_Start())
- //{
- // m_cBT_POWER_Obj.REQ_Power_On_Start();
- //}
- //Sleep(1000);
-
- m_cBT_CT_Obj.ConfirmCallback = ::CNF_MF_BT;
- m_cBT_CT_Obj.REQ_Set_Inquiry_Scan_Interval_Start(sBTCT);
- RestartTimerCal(WM_MF_BT_INQUIRY_ENABLE_FAIL);
- SUSPEND_CAL_THREAD
- E_METAAPP_RESULT_T state = m_cBT_CT_Obj.Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- CalErrorHandler(WM_MF_BT_INQUIRY_ENABLE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target < set BT inquiry interval fail "
- );
- return false;
- }
- // set scan type
- scan.e_scan_type = SCAN_ENABLE_INQUIRY_ONLY;
- scan.b_interlaced_inquiry_scan = true;
- scan.b_interlaced_page_scan = false;
- m_cBT_CT_Obj.Set_ScanParameter(scan);
- m_cBT_CT_Obj.ConfirmCallback = ::CNF_MF_BT;
- m_cBT_CT_Obj.REQ_Scan_Start(sBTCT);
- RestartTimerCal(WM_MF_BTT_CONFIG_SCAN_FAIL);
- SUSPEND_CAL_THREAD
- state = m_cBT_CT_Obj.Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- CalErrorHandler(WM_MF_BTT_CONFIG_SCAN_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target < BT config inquiry scan parameter fail "
- );
- return false;
- }
- // trigger BT tester to inquiry
- RestartTimerCal(WM_MF_BTT_CONFIG_INQUIRY_FAIL);
- s_inquiry.i_timeout = 10;
- s_inquiry.i_response_num = 1;
- if (!m_btt_ctrl.BTT_Config_Inquiry(m_pBtt, s_inquiry))
- {
- CalErrorHandler(WM_MF_BTT_CONFIG_INQUIRY_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester < Config inquiry fail "
- );
- return false;
- }
- RestartTimerCal(WM_MF_BTT_INQUIRY_FAIL);
- if (!m_btt_ctrl.BTT_Inquiry(m_pBtt))
- {
- CalErrorHandler(WM_MF_BTT_INQUIRY_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester < Inquiry fail "
- );
- return false;
- }
- RestartTimerCal(WM_MF_BTT_QUERY_STATE_FAIL);
- do
- {
- CHECK_TERMINATE_BY_USER
- Sleep(100);
- if (!m_btt_ctrl.BTT_Query_State(m_pBtt, btt_state))
- {
- CalErrorHandler(WM_MF_BTT_QUERY_STATE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester < query state fail "
- );
- return false;
- }
- }
- while (BTT_STATUS_INQUIRY == btt_state);
- }
- unsigned char ucCAP_ID[2];
- double d_freq_err[2];
- ucCAP_ID[0] = m_ucBT_CRYSTAL_CAP_ID1;
- ucCAP_ID[1] = m_ucBT_CRYSTAL_CAP_ID2;
- for (int i=0; i<2; i++)
- {
- // set CAP_ID
- m_pCal->s_cal_obj.pc_BT_INFO6601_Obj->Set_BT_CAP_ID(ucCAP_ID[i]);
- // write BT info to NVRAM
- m_pCal->s_cal_obj.pc_BT_INFO6601_Obj->ConfirmCallback = ::CNF_MF_BT;
- m_pCal->s_cal_obj.pc_BT_INFO6601_Obj->REQ_Write_To_NVRAM_Start();
- RestartTimerCal(WM_MF_NVRAM_BT_INFO_WRITE_FAIL);
- SUSPEND_CAL_THREAD
- E_METAAPP_RESULT_T state = m_pCal->s_cal_obj.pc_BT_INFO6601_Obj->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_BTRADIO_MT6601_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_BTRADIO_MT6601_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_BT_INFO_WRITE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < Write BT info. to flash "
- );
- }
- return false;
- }
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < Write BT CAP_ID = " + IntToStr(ucCAP_ID[i]) + " to flash "
- );
- // m_cBT_POWER_Obj.REQ_Power_On_Start();
- // enter test mode
- //Sleep(1000);
- S_BT_RF sBtRf;
- sBtRf.hPostMsgDestHandle = NULL;
- sBtRf.log = NULL;
- m_cBT_RF_Obj.ConfirmCallback = ::CNF_MF_BT;
- m_cBT_RF_Obj.REQ_Enter_Test_Mode_Start(sBtRf);
- RestartTimerCal(WM_MF_BT_ENTER_TEST_MODE_FAIL);
- SUSPEND_CAL_THREAD
- state = m_cBT_RF_Obj.Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- CalErrorHandler(WM_MF_BT_ENTER_TEST_MODE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target < Enter BT test mode fail "
- );
- return false;
- }
- // set page scan interval
- m_cBT_CT_Obj.ConfirmCallback = ::CNF_MF_BT;
- m_cBT_CT_Obj.REQ_Set_Page_Scan_Interval_Start(sBTCT);
- RestartTimerCal(WM_MF_BT_INQUIRY_ENABLE_FAIL);
- SUSPEND_CAL_THREAD
- state = m_cBT_CT_Obj.Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- CalErrorHandler(WM_MF_BT_INQUIRY_ENABLE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target < set BT page interval fail "
- );
- return false;
- }
- // set scan type
- scan.e_scan_type = SCAN_ENABLE_PAGE_ONLY;
- scan.b_interlaced_inquiry_scan = false;
- scan.b_interlaced_page_scan = true;
- m_cBT_CT_Obj.Set_ScanParameter(scan);
- m_cBT_CT_Obj.ConfirmCallback = ::CNF_MF_BT;
- m_cBT_CT_Obj.REQ_Scan_Start(sBTCT);
- RestartTimerCal(WM_MF_BTT_CONFIG_SCAN_FAIL);
- SUSPEND_CAL_THREAD
- state = m_cBT_CT_Obj.Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- CalErrorHandler(WM_MF_BTT_CONFIG_SCAN_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target < BT config page scan parameter fail "
- );
- return false;
- }
- // trigger BT tester to make connection
- RestartTimerCal(WM_MF_BTT_CONNECT_TEST_FAIL);
- if (!m_btt_ctrl.BTT_Connect_Test(m_pBtt))
- {
- CalErrorHandler(WM_MF_BTT_CONNECT_TEST_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester < Connect testmode fail "
- );
- return false;
- }
- RestartTimerCal(WM_MF_BTT_QUERY_STATE_FAIL);
- do
- {
- CHECK_TERMINATE_BY_USER
- Sleep(100);
- if (!m_btt_ctrl.BTT_Query_State(m_pBtt, btt_state))
- {
- CalErrorHandler(WM_MF_BTT_QUERY_STATE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester < query state fail "
- );
- return false;
- }
- }
- while (BTT_STATUS_TEST != btt_state);
- // config TX modulation
- S_BTT_MOD bt_mod;
- bt_mod.i_burst_num = 100;
- bt_mod.i_channel = m_usBT_CRYSTAL_CHANNEL;
- RestartTimerCal(WM_MF_BTT_CONNECT_TEST_FAIL);
- if (!m_btt_ctrl.BTT_Config_MOD(m_pBtt, bt_mod))
- {
- CalErrorHandler(WM_MF_BTT_CONNECT_TEST_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester < Connect testmode fail "
- );
- return false;
- }
- // read TX frequency accuracy
- RestartTimerCal(WM_MF_BTT_READ_FREQ_ACCURACY);
- if (!m_btt_ctrl.BTT_Read_Average_Freq_Error(m_pBtt, d_freq_err[i]))
- {
- CalErrorHandler(WM_MF_BTT_READ_FREQ_ACCURACY);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester > read frequency accuracy fail "
- );
- return false;
- }
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " BT tester > read frequency accuracy = " + Double_To_AnsiString(d_freq_err[i])
- );
- // release connection
- RestartTimerCal(WM_MF_BTT_RELEASE_FAIL);
- if (!m_btt_ctrl.BTT_Release(m_pBtt))
- {
- CalErrorHandler(WM_MF_BTT_RELEASE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester < release connection fail "
- );
- return false;
- }
- RestartTimerCal(WM_MF_BTT_QUERY_STATE_FAIL);
- do
- {
- CHECK_TERMINATE_BY_USER
- Sleep(100);
- if (!m_btt_ctrl.BTT_Query_State(m_pBtt, btt_state))
- {
- CalErrorHandler(WM_MF_BTT_QUERY_STATE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester < query state fail "
- );
- return false;
- }
- }
- while (BTT_STATUS_STANDBY != btt_state);
- }
- // Evaluate
- double ddata;
- unsigned char ucCAP_ID_min = BT_CAP_ID_MAX;
- if ((d_freq_err[0] - d_freq_err[1]) != 0)
- {
- ddata = ucCAP_ID[0] - 1.0*d_freq_err[0]*(ucCAP_ID[0] - ucCAP_ID[1])/(d_freq_err[0] - d_freq_err[1]);
- ddata += (ddata>=0) ? 0.5 : -0.5 ;
- ucCAP_ID_min = (int)ddata;
- }
- if (ucCAP_ID_min > BT_CAP_ID_MAX)
- {
- ucCAP_ID_min = BT_CAP_ID_MAX;
- }
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Evaluate : CAP_ID = " + IntToStr(ucCAP_ID_min)
- );
- // set CAP_ID
- m_pCal->s_cal_obj.pc_BT_INFO6611_Obj->Set_BT_CAP_ID(ucCAP_ID_min);
- // write BT info to NVRAM
- m_pCal->s_cal_obj.pc_BT_INFO6601_Obj->ConfirmCallback = ::CNF_MF_BT;
- m_pCal->s_cal_obj.pc_BT_INFO6601_Obj->REQ_Write_To_NVRAM_Start();
- RestartTimerCal(WM_MF_NVRAM_BT_INFO_WRITE_FAIL);
- SUSPEND_CAL_THREAD
- E_METAAPP_RESULT_T state = m_pCal->s_cal_obj.pc_BT_INFO6601_Obj->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_BTRADIO_MT6601_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_WNDRV_DAC_DC_OFFSET_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_BT_INFO_WRITE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < Write BT info. to flash "
- );
- }
- return false;
- }
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < Write BT CAP_ID = " + IntToStr(ucCAP_ID_min) + " to flash "
- );
- if (!WriteBtCapIDCalResultToFile(as_ID+".cal", Application->ExeName, m_pCal->b_CalResultPath, m_pCal->s_bt_bb_id))
- {
- CalErrorHandler(WM_MF_BT_CRYSTAL_CAPID_WRITE_CAL_RESULT_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : write AFC parameter to cal file "
- );
- return false;
- }
-
- log->Add("n" +DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================= BT Crystal CAP ID calibration end ================ "
- );
- frmFatcory->DisableAllCalTimer();
- return true;
- }
- //----------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::BTCrystalCapIDCheck_MT6601(void)
- {
- char tempbuf[256];
- log->Add( "n" +DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================= BT Crystal CAP ID check begin ================ "
- );
- // enter test mode
- //Sleep(1000);
- S_BT_RF sBtRf;
- sBtRf.hPostMsgDestHandle = NULL;
- sBtRf.log = NULL;
- m_cBT_RF_Obj.ConfirmCallback = ::CNF_MF_BT;
- m_cBT_RF_Obj.REQ_Enter_Test_Mode_Start(sBtRf);
- RestartTimerCal(WM_MF_BT_ENTER_TEST_MODE_FAIL);
- SUSPEND_CAL_THREAD
- E_METAAPP_RESULT_T state = m_cBT_RF_Obj.Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- CalErrorHandler(WM_MF_BT_ENTER_TEST_MODE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target < Enter BT test mode fail "
- );
- return false;
- }
- // set page scan interval
- S_BT_CT sBTCT;
- sBTCT.hPostMsgDestHandle = NULL;
- sBTCT.log = NULL;
- m_cBT_CT_Obj.ConfirmCallback = ::CNF_MF_BT;
- m_cBT_CT_Obj.REQ_Set_Page_Scan_Interval_Start(sBTCT);
- RestartTimerCal(WM_MF_BT_INQUIRY_ENABLE_FAIL);
- SUSPEND_CAL_THREAD
- state = m_cBT_CT_Obj.Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- CalErrorHandler(WM_MF_BT_INQUIRY_ENABLE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target < set BT page interval fail "
- );
- return false;
- }
- // set scan type
- S_BT_SCAN scan;
- scan.e_scan_type = SCAN_ENABLE_PAGE_ONLY;
- scan.b_interlaced_inquiry_scan = false;
- scan.b_interlaced_page_scan = true;
- m_cBT_CT_Obj.Set_ScanParameter(scan);
- m_cBT_CT_Obj.ConfirmCallback = ::CNF_MF_BT;
- m_cBT_CT_Obj.REQ_Scan_Start(sBTCT);
- RestartTimerCal(WM_MF_BTT_CONFIG_SCAN_FAIL);
- SUSPEND_CAL_THREAD
- state = m_cBT_CT_Obj.Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- CalErrorHandler(WM_MF_BTT_CONFIG_SCAN_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : Target < BT config page scan parameter fail "
- );
- return false;
- }
- // trigger BT tester to make connection
- RestartTimerCal(WM_MF_BTT_CONNECT_TEST_FAIL);
- if (!m_btt_ctrl.BTT_Connect_Test(m_pBtt))
- {
- CalErrorHandler(WM_MF_BTT_CONNECT_TEST_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester < Connect testmode fail "
- );
- return false;
- }
- RestartTimerCal(WM_MF_BTT_QUERY_STATE_FAIL);
- E_BTT_STATE_T btt_state;
- do
- {
- CHECK_TERMINATE_BY_USER
- Sleep(100);
- if (!m_btt_ctrl.BTT_Query_State(m_pBtt, btt_state))
- {
- CalErrorHandler(WM_MF_BTT_QUERY_STATE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester < query state fail "
- );
- return false;
- }
- }
- while (BTT_STATUS_TEST != btt_state);
- // read TX frequency accuracy
- double d_freq_err;
- RestartTimerCal(WM_MF_BTT_READ_FREQ_ACCURACY);
- if (!m_btt_ctrl.BTT_Read_Average_Freq_Error(m_pBtt, d_freq_err))
- {
- CalErrorHandler(WM_MF_BTT_READ_FREQ_ACCURACY);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester > read frequency accuracy fail "
- );
- return false;
- }
- // release connection
- RestartTimerCal(WM_MF_BTT_RELEASE_FAIL);
- if (!m_btt_ctrl.BTT_Release(m_pBtt))
- {
- CalErrorHandler(WM_MF_BTT_RELEASE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester < release connection fail "
- );
- return false;
- }
- RestartTimerCal(WM_MF_BTT_QUERY_STATE_FAIL);
- do
- {
- CHECK_TERMINATE_BY_USER
- Sleep(100);
- if (!m_btt_ctrl.BTT_Query_State(m_pBtt, btt_state))
- {
- CalErrorHandler(WM_MF_BTT_QUERY_STATE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : BT tester < query state fail "
- );
- return false;
- }
- }
- while (BTT_STATUS_STANDBY != btt_state);
- if (Abs_double(d_freq_err) > m_dBT_CRYSTAL_MAX_FREQ_ACCURACY)
- {
- CalErrorHandler(WM_MF_BT_CRYSTAL_CAPID_CHECK_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Fail: BT CAP ID check ." + " frequency accuracy = " + Double_To_AnsiString(d_freq_err) +
- ", MAX frequency accuracy = " + Double_To_AnsiString(m_dBT_CRYSTAL_MAX_FREQ_ACCURACY)
- );
- return false;
- }
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Pass: BT CAP ID check ." + " frequency accuracy = " + Double_To_AnsiString(d_freq_err) +
- ", MAX frequency accuracy = " + Double_To_AnsiString(m_dBT_CRYSTAL_MAX_FREQ_ACCURACY)
- );
- PostMessage(ctrl.hPostMsgDestHandle,
- WM_MF_BT_CRYSTAL_CAPID_CALIBRATION_DONE,
- 0,
- 0
- );
- log->Add( "n" +DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================= BT Crystal CAP ID check end ================ "
- );
- frmFatcory->DisableAllCalTimer();
- return true;
- }
- //===========================================================================
- bool __fastcall T_META_factory_calibration::BTCrystalCapIDCal_MT6611(void)
- {
- PostMessage(ctrl.hPostMsgDestHandle,
- WM_MF_BT_CRYSTAL_CAPID_BEGIN,
- 0,
- 0
- );
- log->Add("n" +DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================= BT Crystal CAP ID calibration begin ================ "
- );
- if (!m_pCal->s_cal_obj.pc_BT_INFO6611_Obj->REQ_Enable_PCM_Clock_Sync_Signal())
- {
- CalErrorHandler(WM_MF_BT_ENABLE_PCM_CLOCK_SYNC_SIGNAL_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Fail: enable PCM clock sync. signal "
- );
- return false;
- }
- unsigned char uc_pre_cap_id = BT_CAP_ID_MAX + 1;
- unsigned int ui_min_poll_count;
- unsigned int ui_poll_count_diff;
- unsigned int ui_min_poll_count_diff = 2 * TARGET_POLL_COUNT;
- unsigned char uc_min_cap_id;
- unsigned char uc_cal_cap_id = m_pCal->s_cal_obj.pc_BT_INFO6611_Obj->Get_BT_CAP_ID();
- unsigned char ucCAP_ID[2];
- unsigned int ui_poll_count;
- unsigned char uc_first_cap_id = BT_CAP_ID_MIN;
- unsigned char uc_last_cap_id = BT_CAP_ID_MAX;
- while ((ui_min_poll_count_diff != 0) &&
- (uc_first_cap_id < uc_last_cap_id) &&
- (uc_cal_cap_id <= BT_CAP_ID_MAX)
- )
- {
- if (!m_pCal->s_cal_obj.pc_BT_INFO6611_Obj->REQ_Set_CapId(uc_cal_cap_id))
- {
- CalErrorHandler(WM_MF_BT_SET_CRYSTAL_CAPID_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Fail: set BT crystal CAP ID "
- );
- return false;
- }
- if (!m_pCal->s_cal_obj.pc_BT_INFO6611_Obj->REQ_Start_Calibrate_Crystal_Clock())
- {
- CalErrorHandler(WM_MF_BT_START_CALIBRATE_CRYSTAL_CLOCK_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Fail: BT start to calibrate crystal clock "
- );
- return false;
- }
-
- Sleep(100);
- if (!m_pCal->s_cal_obj.pc_BT_INFO6611_Obj->REQ_Get_Result())
- {
- CalErrorHandler(WM_MF_BT_READ_CRYSTAL_CLOCK_RESULT_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Fail: get BT crystal clock "
- );
- return false;
- }
- ui_poll_count = m_pCal->s_cal_obj.pc_BT_INFO6611_Obj->Get_LpoPllCount();
- ui_poll_count_diff = (unsigned int) abs(ui_poll_count - TARGET_POLL_COUNT);
- if (ui_poll_count_diff < ui_min_poll_count_diff)
- {
- ui_min_poll_count_diff = ui_poll_count_diff;
- ui_min_poll_count = ui_poll_count;
- uc_min_cap_id = uc_cal_cap_id;
- }
- if (ui_poll_count < TARGET_POLL_COUNT)
- {
- uc_last_cap_id = uc_cal_cap_id - 1;
- }
- else if (ui_poll_count > TARGET_POLL_COUNT)
- {
- uc_first_cap_id = uc_cal_cap_id + 1;
- }
- if ((uc_first_cap_id >= uc_last_cap_id) ||
- (uc_pre_cap_id == uc_cal_cap_id) ||
- (TARGET_POLL_COUNT == ui_poll_count)
- )
- {
- break;
- }
- uc_pre_cap_id = uc_cal_cap_id;
- uc_cal_cap_id = (uc_first_cap_id + uc_last_cap_id) / 2;
- }
- m_pCal->s_cal_obj.pc_BT_INFO6611_Obj->Set_BT_CAP_ID(uc_min_cap_id);
- m_pCal->s_cal_obj.pc_BT_INFO6611_Obj->ConfirmCallback = ::CNF_MF_BT;
- m_pCal->s_cal_obj.pc_BT_INFO6611_Obj->REQ_Write_To_NVRAM_Start();
- RestartTimerCal(WM_MF_NVRAM_BT_INFO_WRITE_FAIL);
- SUSPEND_CAL_THREAD
- CHECK_TERMINATE_BY_USER
- E_METAAPP_RESULT_T state = m_pCal->s_cal_obj.pc_BT_INFO6611_Obj->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- CalErrorHandler(WM_MF_NVRAM_BT_INFO_WRITE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target < write BT CAP ID to NVRAM fail."
- );
- return false;
- }
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target < write BT CAP ID = " + IntToStr(uc_min_cap_id) + " to NVRAM."
- );
- if (!WriteBtCapIDCalResultToFile(as_ID+".cal", Application->ExeName, m_pCal->b_CalResultPath, m_pCal->s_bt_bb_id))
- {
- CalErrorHandler(WM_MF_BT_CRYSTAL_CAPID_WRITE_CAL_RESULT_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : write AFC parameter to cal file "
- );
- return false;
- }
- if ((ui_min_poll_count > m_uiMAX_POLL_COUNT) || (ui_min_poll_count < m_uiMIN_POLL_COUNT))
- {
- CalErrorHandler(WM_MF_BT_CRYSTAL_CAPID_CHECK_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Fail: BT CAP ID check ." + " poll count = " + IntToStr(ui_min_poll_count) +
- ", min poll count = " + IntToStr(m_uiMIN_POLL_COUNT) +
- ", max poll count = " + IntToStr(m_uiMAX_POLL_COUNT)
- );
- return false;
- }
- PostMessage(ctrl.hPostMsgDestHandle,
- WM_MF_BT_CRYSTAL_CAPID_CALIBRATION_DONE,
- 0,
- 0
- );
- return true;
- }