man_metadll.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:16k
- /*****************************************************************************
- * 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:
- * ---------
- * man_metadll.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * BROM negotiate 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 <vcl.h>
- #include <SyncObjs.hpp>
- #pragma hdrstop
- #include "form_main.h"
- #include "man_active_boot.h"
- #include "man_metadll.h"
- #include "misc.h"
- #ifndef _USB_COM_COMMON_H_
- #include "usb_com_common.h"
- #endif
- //---------------------------------------------------------------------------
- //-- for Meta Factory ----//
- HANDLE hCOM;
- //------------------------//
- //---------------------------------------------------------------------------
- CMetaDllMan *MetaDllMan = 0;
- extern TfrmMainSel *frmMainSel;
- //---------------------------------------------------------------------------
- static CMetaDllMan* metadllman_ptr;
- //---------------------------------------------------------------------------
- //char META_DLL_Version[10];
- //bool Bootok = false;
- bool ConnectTargetok = false;
- bool isBootTarget = false;
- bool isConnectTarget = false;
- bool isMETAInit = false;
- bool isMETACOMMSTART = false;
- bool isEndExcuted = 0x00;
- bool IsRunning = false;
- //bool isUartOpen = false;
- HANDLE p_METADLL_Connect_Event;
- bool isFirstOpenComErr = true;
- static CMETAHANDLE g_META_HANDLE_Obj;
- // connect in META mode
- extern META_ConnectInMETA_Req g_ConnectInMETA_Req;
- extern META_ConnectInMETA_Report g_ConnectInMETA_Report;
- //===========================================================================
- void Boot_Target_Thread()
- {
- #if 0
- Bootok = false;
- // Bootok = Boot_Target( MetaDllMan->hCom, &(frmMainSel->BootStop) );
- Boot_Target( MetaDllMan->hCom, &(frmMainSel->BootStop) );
- if(Bootok == false)
- {
- //Bootok;
- }
- #endif
- }
- //---------------------------------------------------------------------------
- void METADLL_Connect(META_Connect_Req* META_connect_req, int* BootStop, META_Connect_Report* META_connect_report)
- {
- META_RESULT META_Result;
- char str[512];
- if (USB_COM == META_connect_req->com_port)
- {
- unsigned short us_com_port;
- META_ConnectByUSB_Report report;
- META_Result = META_GetDynamicUSBComPort_r(g_META_HANDLE_Obj.Get_MainHandle(), META_connect_req->ms_connect_timeout, &us_com_port, BootStop);
- if ((META_Result != META_SUCCESS) && (META_Result != META_STOP_ENUM_USB_PROCEDURE))
- {
- frmMainSel->DisableGlbTimer();
- AnsiString as_msg;
- as_msg = "Get dynamic USB COM fail, please press [Reconnect] button to connect with target";
- Application->MessageBox(as_msg.c_str(), "Fail", MB_OK);
- }
- if (META_SUCCESS == META_Result)
- {
- META_ConnectByUSB_Req req;
- req.com_port = us_com_port;
- req.ms_connect_timeout = META_connect_req->ms_connect_timeout;
- req.boot_meta_arg = META_connect_req->boot_meta_arg;
- req.boot_meta_arg.m_usb_enable = _TRUE;
- META_Result = META_ConnectWithTargetByUSB_r(g_META_HANDLE_Obj.Get_MainHandle(), &req, BootStop, &report);
- if ((report.boot_meta_ret != S_DONE) &&
- (report.boot_meta_ret != S_STOP) &&
- (report.boot_meta_ret != S_BROM_FAIL_TO_GET_BBCHIP_HW_VER)
- )
- {
- frmMainSel->DisableGlbTimer();
- sprintf(str, "%s(%d)", StatusToString(report.boot_meta_ret), report.boot_meta_ret);
- AnsiString as_msg(str);
- as_msg += ", please press [Reconnect] button to connect with target";
- Application->MessageBox(as_msg.c_str(), "Fail", MB_OK);
- }
- else if ((META_Result != META_SUCCESS) &&
- (META_Result != META_STOP_ENUM_USB_PROCEDURE) &&
- (META_Result != META_MAUI_DB_INCONSISTENT)
- )
- {
- frmMainSel->DisableGlbTimer();
- const char* pc_err = META_GetErrorString(META_Result);
- AnsiString as_msg(pc_err);
- as_msg += ", please press [Reconnect] button to connect with target";
- Application->MessageBox(as_msg.c_str(), "Fail", MB_OK);
- }
- else
- {
- META_connect_report->boot_result = report.boot_result;
- }
- }
- }
- else // UART COM
- {
- META_connect_req->boot_meta_arg.m_usb_enable = _FALSE;
- META_Result = META_ConnectWithTarget_r(g_META_HANDLE_Obj.Get_MainHandle(), META_connect_req, BootStop, META_connect_report);
- if ((META_connect_report->boot_meta_ret != S_DONE) &&
- (META_connect_report->boot_meta_ret != S_STOP) &&
- (META_connect_report->boot_meta_ret != S_BROM_FAIL_TO_GET_BBCHIP_HW_VER)
- )
- {
- frmMainSel->DisableGlbTimer();
- sprintf(str, "%s(%d)", StatusToString(META_connect_report->boot_meta_ret), META_connect_report->boot_meta_ret );
- AnsiString as_msg(str);
- as_msg += ", please press [Reconnect] button to connect with target";
- Application->MessageBox(as_msg.c_str(), "Fail", MB_OK);
- }
- else if ((META_Result != META_SUCCESS) &&
- (META_Result != META_STOP_BOOTUP_PROCEDURE) &&
- (META_Result != META_MAUI_DB_INCONSISTENT)
- )
- {
- frmMainSel->DisableGlbTimer();
- const char* pc_err = META_GetErrorString(META_Result);
- AnsiString as_msg(pc_err);
- as_msg += ", please press [Reconnect] button to connect with target";
- Application->MessageBox(as_msg.c_str(), "Fail", MB_OK);
- }
- }
- if ((META_SUCCESS == META_Result) || (META_MAUI_DB_INCONSISTENT == META_Result))
- {
- ConnectTargetok = true;
- }
- isConnectTarget = false;
- }
- //---------------------------------------------------------------------------
- void METADLL_Connect_Thread()
- {
- METADLL_Connect(&(frmMainSel->META_connect_req), &(frmMainSel->BootStop), &(frmMainSel->META_connect_report));
- SetEvent(p_METADLL_Connect_Event);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void METADLL_ConnectInMetaMode(META_ConnectInMETA_Req* p_req, int* p_BootStop, META_ConnectInMETA_Report *p_report)
- {
- META_RESULT META_Result;
- //char str[512];
- META_Result = META_ConnectInMetaMode_r(g_META_HANDLE_Obj.Get_MainHandle(), p_req, p_BootStop, p_report);
- if ((META_Result != META_SUCCESS) &&
- (META_Result != META_STOP_BOOTUP_PROCEDURE) &&
- (META_Result != META_MAUI_DB_INCONSISTENT)
- )
- {
- frmMainSel->DisableGlbTimer();
- const char* pc_err = META_GetErrorString(META_Result);
- AnsiString as_msg(pc_err);
- as_msg += ", please press [Reconnect] button to connect with target";
- Application->MessageBox(as_msg.c_str(), "Fail", MB_OK);
- }
- if ((META_SUCCESS == META_Result) ||
- (META_MAUI_DB_INCONSISTENT == META_Result))
- {
- ConnectTargetok = true;
- }
- isConnectTarget = false;
- }
- //---------------------------------------------------------------------------
- void METADLL_ConnectInMetaMode_Thread()
- {
- METADLL_ConnectInMetaMode(&g_ConnectInMETA_Req, &(frmMainSel->BootStop), &g_ConnectInMETA_Report);
- SetEvent(p_METADLL_Connect_Event);
- }
- //----------------------------------------------------------------------------
- void CMetaDllMan::METADLL_DisconnectWithTarget( void )
- {
- if( ConnectTargetok )
- {
- META_DisconnectWithTarget_r( m_META_HANDLE_Obj.Get_MainHandle() );
- ConnectTargetok = false;
- }
- }
- //==============================================================================
- void UartDisconnect( void )
- {
- frmMainSel->UartDisconnect();
- }
- //----------------------------------------------------------------------------
- static void __stdcall ErrorHandler(const META_CNF_ERR_CODE err)
- {
- metadllman_ptr->ErrorHandler(err);
- }
- //----------------------------------------------------------------------------
- void __stdcall SystemHandler(const char *sys_trace)
- {
- metadllman_ptr->SystemHandler(sys_trace);
- }
- //==============================================================================
- bool CMetaDllMan::StartConnectTarget(bool b_connect_in_meta_mode)
- {
- if (!ConnectTargetok)
- {
- if (!isConnectTarget)
- {
- p_METADLL_Connect_Event = CreateEvent(NULL, TRUE, FALSE, NULL);
- ResetEvent(p_METADLL_Connect_Event);
- isConnectTarget = true;
- if (b_connect_in_meta_mode)
- {
- ActiveMan_Boot->SetActiveFunction_Boot(METADLL_ConnectInMetaMode_Thread);
- }
- else
- {
- ActiveMan_Boot->SetActiveFunction_Boot(METADLL_Connect_Thread);
- }
- }
- return false;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- void __stdcall CMetaDllMan::ErrorHandler(const META_CNF_ERR_CODE err)
- {
- }
- //----------------------------------------------------------------------------
- void __stdcall CMetaDllMan::SystemHandler(const char *sys_trace)
- {
- Application->MessageBox( sys_trace, "System trace", MB_OK );
- }
- //===========================================================================
- CMetaDllMan::CMetaDllMan( void )
- {
- IsRunning = false;
- hCom = NULL;
- //ComPort = 1;
- // ComPort = META_COM1;
- ComPort = 1;
- metadllman_ptr = this;
- // const char **version;
- // const char **release_type;
- // const char **build_date;
- /// const char **load_ptah;
- // META_GetDLLInfo( version, release_type, build_date, load_ptah);
- unsigned int major_ver;
- unsigned int minor_ver;
- unsigned int build_num;
- unsigned int patch_num;
- META_GetDLLVer( &major_ver, &minor_ver, &build_num, &patch_num);
- // META_GetVersion( &Version );
- // unsigned int x, y, z, z2;
- // x = ( (Version) & 0xFF000000 ) >> 24;
- // y = ( (Version) & 0x00FF0000 ) >> 16;
- // z = ( (Version) & 0x0000FFFF );
- // sprintf(::META_DLL_Version, "%d.%d.%d", x, y, z);
- m_asMETADLLVer = IntToStr(major_ver) + "." +
- IntToStr(minor_ver) + "." +
- IntToStr(build_num) + "." +
- IntToStr(patch_num);
- // m_asMETADLLBuildDate = (AnsiString) *build_date;
- }
- //---------------------------------------------------------------------------
- CMetaDllMan::~CMetaDllMan( )
- {
- if(IsRunning)
- {
- End();
- IsRunning = false;
- }
- }
- //---------------------------------------------------------------------------
- bool CMetaDllMan::MetaInit( void )
- {
- m_META_HANDLE_Obj.REQ_AllocateMainHandle_Start();
- //MetaResult = META_Init_r( m_META_HANDLE_Obj.Get_MainHandle(), ::ErrorHandler );
- //if( MetaResult != META_SUCCESS ) return false;
- //isMETAInit = true;
- //return true;
- return true;
- }
- //---------------------------------------------------------------------------
- bool CMetaDllMan::End(void)
- {
- META_RESULT meta_result;
- if (isMETACOMMSTART)
- {
- meta_result = META_COMM_Stop_r(m_META_HANDLE_Obj.Get_MainHandle());
- if (meta_result != META_SUCCESS)
- {
- // Application->MessageBox( "META COMM stop error", "Error", MB_OK );
- return(false);
- }
- isMETACOMMSTART = false;
- }
- META_CancelAllBlockingCall_r(m_META_HANDLE_Obj.Get_MainHandle());
- if (ConnectTargetok)
- {
- META_DisconnectWithTarget_r(m_META_HANDLE_Obj.Get_MainHandle());
- ConnectTargetok = false;
- }
- if (isMETAInit)
- {
- //int meta_handle = m_META_HANDLE_Obj.Get_MainHandle();
- //META_Deinit_r(&meta_handle);
- m_META_HANDLE_Obj.REQ_ReleaseMainHandle_Start();
- m_META_HANDLE_Obj.REQ_ReleaseSecondHandle_Start();
- isMETAInit = false;
- }
- #if 0
- if (isUartOpen)
- {
- ::UART_Close(hCom);
- }
- #endif
- IsRunning = false;
- return(true);
- }
- //==============================================================================
- bool CMetaDllMan::isMetaVerRequiredByTargetOk( unsigned int meta_ver_required_by_target )
- {
- //META_GetVersion( &Version );
- //if( Version < meta_ver_required_by_target )
- //{
- // return false;
- //}
- return true;
- }
- //---------------------------------------------------------------------------
- void CMetaDllMan::getMetaVerRequiredByTarget( unsigned int meta_ver_required_by_target, char* p_cmeta_ver_required_by_target )
- {
- unsigned int x, y,z;
- x = ( (meta_ver_required_by_target) & 0xFF000000 ) >> 24;
- y = ( (meta_ver_required_by_target) & 0x00FF0000 ) >> 16;
- z = ( (meta_ver_required_by_target) & 0x0000FFFF );
- sprintf(p_cmeta_ver_required_by_target, "%d.%d.%d", x, y, z);
- }
- //===========================================================================
- //////////////////////////////// information //////////////////////////////
- //===========================================================================
- AnsiString CMetaDllMan::Get_METADLLVersion( void )
- {
- return m_asMETADLLVer;
- }
- //---------------------------------------------------------------------------
- AnsiString CMetaDllMan::Get_METADLLBuildDate( void )
- { return m_asMETADLLBuildDate;
- }