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

MTK

开发平台:

C++ Builder

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2001
  8. *
  9. *****************************************************************************/
  10. /*****************************************************************************
  11.  *
  12.  * Filename:
  13.  * ---------
  14.  *   wifi_bb.cpp
  15.  *
  16.  * Project:
  17.  * --------
  18.  *   Maui META APP
  19.  *
  20.  * Description:
  21.  * ------------
  22.  *   WiFi baseband source
  23.  *
  24.  * Author:
  25.  * -------
  26.  *  Andy Ueng (mtk00490)
  27.  *
  28.  *============================================================================
  29.  *             HISTORY
  30.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  31.  *------------------------------------------------------------------------------
  32.  * $Revision$
  33.  * $Modtime$
  34.  * $Log$
  35.  *
  36.  *------------------------------------------------------------------------------
  37.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  38.  *============================================================================
  39.  ****************************************************************************/
  40. //===========================================================================
  41. #include <IniFiles.hpp>
  42. #pragma hdrstop
  43. #ifndef  _WIFI_BB_H_
  44. #include "wifi_bb.h"
  45. #endif
  46. // man
  47. #ifndef  _MAN_ACTIVE_H_
  48. #include "man_active.h"
  49. #endif
  50. // misc
  51. #ifndef  _FT_UTILS_H_
  52. #include "ft_utils.h"
  53. #endif
  54. static CWIFIBB*  gs_wifi_bb_ptr;
  55. //===========================================================================
  56. //static  void  Read_From_Reg( void )
  57. //{   gs_wifi_bb_ptr->Read_From_Reg();
  58. //}
  59. //------------------------------------------------------------------------------
  60. //static  void  REQ_Read_From_AllReg( void )
  61. //{   gs_wifi_bb_ptr->REQ_Read_From_AllReg();
  62. //}
  63. //------------------------------------------------------------------------------
  64. //static  void  Write_To_Reg( void )
  65. //{   gs_wifi_bb_ptr->Write_To_Reg();
  66. //}
  67. //---------------------------------------------------------------------------
  68. static  void  REQ_Read_BBCR_Setting_From_Reg( void )
  69. {   gs_wifi_bb_ptr->REQ_Read_BBCR_Setting_From_Reg();
  70. }
  71. //---------------------------------------------------------------------------
  72. static  void  REQ_Write_BBCR_Setting_To_Reg( void )
  73. {    gs_wifi_bb_ptr->REQ_Write_BBCR_Setting_To_Reg();
  74. }
  75. //------------------------------------------------------------------------------
  76. static void  REQ_TimeOut( void )
  77. {   gs_wifi_bb_ptr->REQ_TimeOut();
  78. }
  79. //------------------------------------------------------------------------------
  80. static void  REQ_Finish( void )
  81. {   gs_wifi_bb_ptr->REQ_Finish();
  82. }
  83. //===========================================================================
  84. CWIFIBB::CWIFIBB( void )
  85. {
  86.    m_bIsRunning = false;
  87.    ConfirmCallback = 0;
  88. }
  89. //---------------------------------------------------------------------------
  90. CWIFIBB::~CWIFIBB( )
  91. {
  92.    m_bIsRunning = false;
  93.    ConfirmCallback = 0;
  94. }
  95. //---------------------------------------------------------------------------
  96. void  CWIFIBB::REQ_Finish( void )
  97. {
  98.    if( ! m_bIsRunning )  return;
  99.    Confirm( STATE_BB_OK );
  100.    m_bIsRunning = false;
  101. }
  102. //---------------------------------------------------------------------------
  103. void  CWIFIBB::REQ_Stop( void )
  104. {
  105.     if( ! m_bIsRunning )  return;
  106.     Confirm( STATE_BB_STOP );
  107.     m_bIsRunning = false;
  108. }
  109. //---------------------------------------------------------------------------
  110. void  CWIFIBB::REQ_TimeOut( void )
  111. {
  112.     if( ! m_bIsRunning )  return;
  113.     Confirm( STATE_BB_TIMEOUT );
  114.     m_bIsRunning = false;
  115. }
  116. //---------------------------------------------------------------------------
  117. void  CWIFIBB::Confirm( int confirm_state )
  118. {
  119.    if( ! m_bIsRunning )  return;
  120.    if(ConfirmCallback==0)  return;
  121.    m_iConfirmState = confirm_state;
  122.    ActiveMan->SetActiveFunction( ConfirmCallback );
  123. }
  124. //===========================================================================
  125. void  CWIFIBB::REQ_Read_BBCR_Setting_From_Reg_Start( S_WiFi_BBCR &bbcr )
  126. {
  127.     gs_wifi_bb_ptr = this;
  128.     m_bIsRunning   = true;
  129.     m_sBBCR        = bbcr;
  130.     ActiveMan->SetActiveFunction( ::REQ_Read_BBCR_Setting_From_Reg );
  131. }
  132. //------------------------------------------------------------
  133. void  CWIFIBB::REQ_Read_BBCR_Setting_From_Reg( void )
  134. {
  135.     if( ! m_bIsRunning )
  136.     {   Confirm( STATE_BB_FAIL );  return;  }
  137.     META_RESULT  MetaResult;
  138.    // for( int i=0; i<WIFI_BBCR_TYPE_NUM; i++ )
  139.     {
  140.        // for(int j=0; j<WIFI_BBCR_MAX_NUM; j++ )
  141.         {
  142.            // if( m_sBBCR_Setting[i][j].checked )
  143.             {  // MetaResult = META_WiFi_BBRegRead_r( 500, m_sBBCR_Setting[i][j].addr, &m_sBBCR_Setting[i][j].value );
  144.                 MetaResult = META_WiFi_BBRegRead_r( m_META_HANDLE_Obj.Get_MainHandle(), 100*m_sBBCR.count, m_sBBCR.bb_reg8, m_sBBCR.count );
  145.             }
  146.         }
  147.     }
  148.     if(MetaResult!=META_SUCCESS)
  149.     {
  150.         if( MetaResult!=META_TIMEOUT )
  151.         {   Confirm( STATE_BB_FAIL );  return;  }
  152.         else
  153.         {   Confirm( STATE_BB_TIMEOUT );  return;   }
  154.     }
  155.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  156. }
  157. //===========================================================================
  158. void  CWIFIBB::REQ_Write_BBCR_Setting_To_Reg_Start( S_WiFi_BBCR &bbcr )
  159. {
  160.     gs_wifi_bb_ptr = this;
  161.     m_bIsRunning   = true;
  162.     m_sBBCR        = bbcr;
  163.     ActiveMan->SetActiveFunction( ::REQ_Write_BBCR_Setting_To_Reg );
  164. }
  165. //------------------------------------------------------------
  166. void  CWIFIBB::REQ_Write_BBCR_Setting_To_Reg( void )
  167. {
  168.     if( ! m_bIsRunning )
  169.     {   Confirm( STATE_BB_FAIL );  return;  }
  170.     META_RESULT  MetaResult;
  171.    //for( int i=0; i<WIFI_BBCR_TYPE_NUM; i++ )
  172.     {
  173.         //for(int j=0; j<WIFI_BBCR_MAX_NUM; j++ )
  174.         {
  175.            // if( m_sBBCR_Setting[i][j].checked && (false == m_sBBCR_Setting[i][j].RO) )
  176.             {  //MetaResult = META_WiFi_BBRegWrite_r( 500, m_sBBCR_Setting[i][j].addr, m_sBBCR_Setting[i][j].value );
  177.                 MetaResult = META_WiFi_BBRegWrite_r( m_META_HANDLE_Obj.Get_MainHandle(), 100*m_sBBCR.count, m_sBBCR.bb_reg8, m_sBBCR.count );
  178.             }
  179.         }
  180.     }
  181.     if(MetaResult!=META_SUCCESS)
  182.     {
  183.         if( MetaResult!=META_TIMEOUT )
  184.         {   Confirm( STATE_BB_FAIL );  return;  }
  185.         else
  186.         {   Confirm( STATE_BB_TIMEOUT );  return;   }
  187.     }
  188.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  189. }
  190. //============================================================================
  191. /////////////////////////////  File read/write   /////////////////////////////
  192. //============================================================================
  193. static const AnsiString SECTION_NAME = "WiFi MT5911 baseband register";
  194. static const AnsiString KEY_NAME[] =
  195. {
  196.     "initialization and PHY-configuration register",
  197.     "TX-related register",
  198.     "RX-related register",
  199.     "BBP configuration register",
  200. };
  201. //----------------------------------------------------------------------------
  202. bool  CWIFIBB::REQ_Read_From_File( char *filename )
  203. {
  204.     TIniFile   *ini_file;
  205.     AnsiString  as_data;
  206.     char        str[2048];
  207.     unsigned char      ucdata[WIFI_BBCR_MAX_NUM];
  208.     int         i;
  209.     ini_file = new TIniFile( filename );
  210.     if( ini_file == NULL )  return false;
  211.     // Initialization and PHY-Configuration
  212.     as_data = ini_file->ReadString( SECTION_NAME,
  213.                                      KEY_NAME[WIFI_BBCR_IPC],
  214.                                      "0,0,0,0,0,");
  215.     strcpy( str, as_data.c_str() );
  216.     String_To_Array_UnsignedChar( str, ucdata, WIFI_IPC_NUM );
  217.     for( i=0; i<WIFI_IPC_NUM; i++ )
  218.     {  m_sBBCR_Setting[WIFI_BBCR_IPC][i].value = ucdata[i];  }
  219.     // TX-related
  220.     as_data = ini_file->ReadString( SECTION_NAME,
  221.                                      KEY_NAME[WIFI_BBCR_TX],
  222.                                      "0,0,0,0,0,0,0,0,0,0,");
  223.     strcpy( str, as_data.c_str() );
  224.     String_To_Array_UnsignedChar( str, ucdata, WIFI_TX_NUM );
  225.     for( i=0; i<WIFI_TX_NUM; i++ )
  226.     {  m_sBBCR_Setting[WIFI_BBCR_TX][i].value = ucdata[i];  }
  227.     // RX-related
  228.     as_data = ini_file->ReadString( SECTION_NAME,
  229.                                      KEY_NAME[WIFI_BBCR_RX],
  230.                                      "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,");
  231.     strcpy( str, as_data.c_str() );
  232.     String_To_Array_UnsignedChar( str, ucdata, WIFI_RX_NUM );
  233.     for( i=0; i<WIFI_RX_NUM; i++ )
  234.     {  m_sBBCR_Setting[WIFI_BBCR_RX][i].value = ucdata[i];  }
  235.     // BBP Configuration
  236.     as_data = ini_file->ReadString( SECTION_NAME,
  237.                                      KEY_NAME[WIFI_BBCR_RX],
  238.                                      "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,");
  239.     strcpy( str, as_data.c_str() );
  240.     String_To_Array_UnsignedChar( str, ucdata, WIFI_BBPC_NUM );
  241.     for( i=0; i<WIFI_BBPC_NUM; i++ )
  242.     {  m_sBBCR_Setting[WIFI_BBCR_BBPC][i].value = ucdata[i];  }
  243.     delete  ini_file;
  244.     return true;
  245. }
  246. //-----------------------------------------------------------------------------
  247. bool  CWIFIBB::REQ_Write_To_File( char *filename )
  248. {
  249.     TIniFile   *ini_file;
  250.     char        str[2048];
  251.     unsigned char         ucdata[WIFI_BBCR_MAX_NUM];
  252.     int         i;
  253.     ini_file = new TIniFile( filename );
  254.     if( ini_file == NULL )  return  false;
  255.     // Initialization and PHY-Configuration
  256.     for( i=0; i<WIFI_IPC_NUM; i++ )
  257.     {   ucdata[i] = m_sBBCR_Setting[WIFI_BBCR_IPC][i].value;  }
  258.     Array_To_String_UnsignedChar( str, ucdata, WIFI_IPC_NUM, ',' );
  259.     ini_file->WriteString( SECTION_NAME,
  260.                            KEY_NAME[WIFI_BBCR_IPC],
  261.                            str );
  262.     // TX-related
  263.     for( i=0; i<WIFI_TX_NUM; i++ )
  264.     {   ucdata[i] = m_sBBCR_Setting[WIFI_BBCR_TX][i].value;  }
  265.     Array_To_String_UnsignedChar( str, ucdata, WIFI_TX_NUM, ',' );
  266.     ini_file->WriteString( SECTION_NAME,
  267.                            KEY_NAME[WIFI_BBCR_TX],
  268.                            str );
  269.     // RX-related
  270.     for( i=0; i<WIFI_RX_NUM; i++ )
  271.     {   ucdata[i] = m_sBBCR_Setting[WIFI_BBCR_RX][i].value;  }
  272.     Array_To_String_UnsignedChar( str, ucdata, WIFI_RX_NUM, ',' );
  273.     ini_file->WriteString( SECTION_NAME,
  274.                            KEY_NAME[WIFI_BBCR_RX],
  275.                            str );
  276.     // BBP Configuration
  277.     for( i=0; i<WIFI_BBPC_NUM; i++ )
  278.     {   ucdata[i] = m_sBBCR_Setting[WIFI_BBCR_BBPC][i].value;  }
  279.     Array_To_String_UnsignedChar( str, ucdata, WIFI_BBPC_NUM, ',' );
  280.     ini_file->WriteString( SECTION_NAME,
  281.                            KEY_NAME[WIFI_BBCR_BBPC],
  282.                            str );
  283.     
  284.     delete  ini_file;
  285.     return  true;
  286. }
  287. //===========================================================================
  288. ////////////////////////////   Global  information   ////////////////////////
  289. //===========================================================================
  290. int   CWIFIBB::Get_ConfirmState( void )
  291. {
  292.     return  m_iConfirmState;
  293. }
  294. //---------------------------------------------------------------------------
  295. S_WiFi_BBCR   CWIFIBB::Get_BBCR( void )
  296. {
  297.     return  m_sBBCR;
  298. }
  299. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  300. unsigned int  CWIFIBB::Get_BBCR_Setting_Value( int type, int idx )
  301. {
  302.     return  m_sBBCR_Setting[type][idx].value;
  303. }
  304. //----------------------------------------------------------------------------
  305. void CWIFIBB::Set_BBCR_Setting_Value( int type, int idx, unsigned int value )
  306. {   m_sBBCR_Setting[type][idx].value = value;
  307. }
  308. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  309. void CWIFIBB::Set_BBCR_Setting( int type, int idx, S_WIFI_BBCR_SETTING bbcr )
  310. {   m_sBBCR_Setting[type][idx] = bbcr;
  311. }