rf_agc.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:18k
- /*****************************************************************************
- * 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:
- * ---------
- * rf_agc.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * RF AGC 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 <IniFiles.hpp>
- #pragma hdrstop
- #ifndef _FORM_MAIN_H_
- #include "form_Main.h"
- #endif
- #ifndef _RF_AGC_H_
- #include "rf_agc.h"
- #endif
- #ifndef _MAN_FDM_H_
- #include "man_fdm.h"
- #endif
- #ifndef _MAN_ACTIVE_H_
- #include "man_active.h"
- #endif
- // misc
- #ifndef _MISC_H_
- #include "misc.h"
- #endif
- #ifndef _FT_UTILS_H_
- #include "ft_utils.h"
- #endif
- // NVRAM
- #ifndef _NVRAM_VER_H_
- #include "nvram_ver.h"
- #endif
- //===========================================================================
- static CRFAGC* g_rf_agc_ptr;
- static bool g_bIsRunning = false;
- extern TfrmMainSel *frmMainSel;
- //===========================================================================
- static void CNF_ReadFromNVRAM( void )
- {
- g_rf_agc_ptr->CNF_ReadFromNVRAM( );
- }
- //-------------------------------------------------------------------------
- static void CNF_WriteToNVRAM( void )
- {
- g_rf_agc_ptr->CNF_WriteToNVRAM( );
- }
- //-------------------------------------------------------------------------
- static void CNF_ResetNVRAMData( void )
- {
- g_rf_agc_ptr->CNF_ResetNVRAMData( );
- }
- //-------------------------------------------------------------------------
- static void REQ_TimeOut( void )
- { g_rf_agc_ptr->REQ_TimeOut();
- }
- //-------------------------------------------------------------------------
- static void REQ_Finish( void )
- { g_rf_agc_ptr->REQ_Finish();
- }
- //===========================================================================
- CRFAGC::CRFAGC( void )
- {
- g_bIsRunning = false;
- ConfirmCallback = NULL;
- m_uiAgcBufSize = NULL;
- m_cAgcBuf = NULL;
- }
- //---------------------------------------------------------------------------
- CRFAGC::~CRFAGC()
- {
- g_bIsRunning = false;
- ConfirmCallback = 0;
- if(m_cAgcBuf)
- {
- delete [] m_cAgcBuf;
- m_cAgcBuf = NULL;
- }
- }
- //---------------------------------------------------------------------------
- void CRFAGC::REQ_Finish( void )
- {
- if(!g_bIsRunning) return;
- Confirm( METAAPP_SUCCESS );
- g_bIsRunning = false;
- }
- //---------------------------------------------------------------------------
- void CRFAGC::REQ_Stop( void )
- {
- if(!g_bIsRunning) return;
- NVRAMMan->REQ_Stop();
- Confirm( METAAPP_STOP );
- g_bIsRunning = false;
- }
- //---------------------------------------------------------------------------
- void CRFAGC::REQ_TimeOut( void )
- {
- if(!g_bIsRunning) return;
- NVRAMMan->REQ_Stop();
- Confirm( METAAPP_TIMEOUT );
- g_bIsRunning = false;
- }
- //---------------------------------------------------------------------------
- void CRFAGC::Confirm(E_METAAPP_RESULT_T confirm_state)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- if (NULL == ConfirmCallback)
- {
- return;
- }
- m_eConfirmState = confirm_state;
- ActiveMan->SetActiveFunction(ConfirmCallback);
- }
- //===========================================================================
- void CRFAGC::REQ_Read_From_NVRAM_Start(void)
- {
- g_rf_agc_ptr = this;
- g_bIsRunning = true;
- m_bDownloadTrigger = false;
- REQ_Read_From_NVRAM();
- }
- //---------------------------------------------------------------------------
- void CRFAGC::REQ_Read_From_NVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- if (NULL == m_cAgcBuf)
- {
- META_RESULT MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_AGCPATHLOSS_LID", (int *) &m_uiAgcBufSize);
- if (MetaResult != META_SUCCESS)
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- m_cAgcBuf = new char[m_uiAgcBufSize];
- }
- NVRAMMan->ConfirmCallback = ::CNF_ReadFromNVRAM;
- NVRAMMan->REQ_ReadNVRAM_Start( "NVRAM_EF_L1_AGCPATHLOSS_LID",
- 1,
- m_uiAgcBufSize,
- m_cAgcBuf
- );
- }
- //-------------------------------------
- void CRFAGC::CNF_ReadFromNVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
- switch (state)
- {
- case METAAPP_SUCCESS:
- {
- if (m_bDownloadTrigger)
- {
- REQ_Write_To_NVRAM();
- }
- else
- {
- META_RESULT MetaResult = META_NVRAM_Decompose_agcPathLoss(&m_sAgcPathLoss,
- m_cAgcBuf,
- m_uiAgcBufSize);
- if (MetaResult != META_SUCCESS)
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- ActiveMan->SetActiveFunction(::REQ_Finish);
- }
- }
- break;
- default:
- {
- Confirm(state);
- }
- break;
- }
- }
- //===========================================================================
- void CRFAGC::REQ_Write_To_NVRAM_Start(void)
- {
- g_rf_agc_ptr = this;
- g_bIsRunning = true;
- m_bDownloadTrigger = true;
- REQ_Write_To_NVRAM();
- }
- //---------------------------------------------------------------------------
- void CRFAGC::REQ_Write_To_NVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- META_RESULT MetaResult;
- unsigned short lid_ver;
- MetaResult = META_NVRAM_GetLIDVersion("NVRAM_EF_L1_AGCPATHLOSS_LID", &lid_ver);
- if (lid_ver > NVRAM_EF_L1_AGCPATHLOSS_LID_VERNO)
- {
- Confirm(METAAPP_NVRAM_LID_VER_NOT_SUPPORT);
- return;
- }
- if (NULL == m_cAgcBuf)
- {
- MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_AGCPATHLOSS_LID", (int *) &m_uiAgcBufSize);
- if (MetaResult != META_SUCCESS)
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- m_cAgcBuf = new char[m_uiAgcBufSize];
- }
- MetaResult = META_NVRAM_Compose_agcPathLoss( &m_sAgcPathLoss,
- m_cAgcBuf,
- m_uiAgcBufSize );
- if (MetaResult != META_SUCCESS)
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- NVRAMMan->ConfirmCallback = ::CNF_WriteToNVRAM;
- NVRAMMan->REQ_WriteNVRAM_Start("NVRAM_EF_L1_AGCPATHLOSS_LID",
- 1, // only 1 record
- m_uiAgcBufSize,
- m_cAgcBuf);
- }
- //-------------------------------------
- void CRFAGC::CNF_WriteToNVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
- Confirm(state);
- }
- //===========================================================================
- void CRFAGC::REQ_Reset_NVRAM_Data( void )
- {
- g_rf_agc_ptr = this;
- g_bIsRunning = true;
- NVRAMMan->ConfirmCallback = ::CNF_ResetNVRAMData;
- NVRAMMan->REQ_ResetNVRAMData_Start("NVRAM_EF_L1_AGCPATHLOSS_LID");
- }
- //-------------------------------------
- void CRFAGC::CNF_ResetNVRAMData( void )
- {
- if(!g_bIsRunning) return;
- E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
- Confirm(state);
- }
- //==============================================================================
- static const char SUBBAND_NAME[][32] =
- {
- "GSM400 Sub band, RX loss",
- "GSM850 Sub band, RX loss",
- "GSM900 Sub band, RX loss",
- "DCS1800 Sub band, RX loss",
- "PCS1900 Sub band, RX loss",
- };
- //--------------------------------------------------------------------------
- static const char BAND_NAME[5][12] =
- { "GSM400",
- "GSM850",
- "GSM900",
- "DCS1800",
- "PCS1900"
- };
- //--------------------------------------------------------------------------
- bool CRFAGC::RxLossSectionExist(char *filename, FrequencyBand freqband)
- {
- TIniFile *ini_file;
- ini_file = new TIniFile(filename);
- if (NULL == ini_file)
- {
- return false;
- }
- if (!ini_file->SectionExists((AnsiString) SUBBAND_NAME[freqband]))
- {
- delete ini_file;
- return false;
- }
- delete ini_file;
- return true;
- }
- //--------------------------------------------------------------------------
- bool CRFAGC::AnyRxLossSectionExist(char *filename)
- {
- int FrequencyBandStart;
- TIniFile *ini_file;
- ini_file = new TIniFile(filename);
- if (NULL == ini_file)
- {
- return false;
- }
- if (frmMainSel->cbGSM850->Checked)
- {
- FrequencyBandStart = FrequencyBand850;
- }
- else
- { FrequencyBandStart = FrequencyBand900;
- }
- for(int band = FrequencyBandStart; band<=FrequencyBand1900; band++)
- {
- if( ini_file->SectionExists((AnsiString) SUBBAND_NAME[band]))
- {
- delete ini_file;
- return true;
- }
- }
- delete ini_file;
- return false;
- }
- //==============================================================================
- bool CRFAGC::REQ_Read_From_File(char *filename)
- {
- FrequencyBand FrequencyBandStart;
- if (frmMainSel->cbGSM850->Checked)
- {
- FrequencyBandStart = FrequencyBand850;
- }
- else
- { FrequencyBandStart = FrequencyBand900;
- }
- for (FrequencyBand freqband = FrequencyBandStart; freqband<=FrequencyBand1900; freqband++)
- {
- if (!REQ_Read_From_File_Single_Band(filename, freqband))
- {
- return false;
- }
- }
- return true;
- }
- //----------------------------------------------------------------------------
- bool CRFAGC::REQ_Read_From_File_Single_Band(char *filename, FrequencyBand freqband)
- {
- TIniFile *ini_file;
- AnsiString data;
- char str[2048];
- int idata[PLTABLE_SIZE];
- float fdata[PLTABLE_SIZE];
- ini_file = new TIniFile(filename);
- if (NULL == ini_file)
- {
- return false;
- }
- data = ini_file->ReadString(SUBBAND_NAME[freqband],
- "Max ARFCN",
- "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1");
- strcpy(str, data.c_str());
- String_To_Array_int(str, idata, PLTABLE_SIZE);
- idata[ PLTABLE_SIZE-1 ] = -1;
- for (int i=0; i<PLTABLE_SIZE; i++)
- {
- m_sAgcPathLoss.agcPathLoss[freqband][i].max_arfcn = idata[i];
- }
- data = ini_file->ReadString(SUBBAND_NAME[freqband],
- "RX loss",
- "0,0,0,0,0,0,0,0,0,0,0,0");
- strcpy( str, data.c_str()
- );
- String_To_Array_float(str, fdata, PLTABLE_SIZE);
- fdata[PLTABLE_SIZE-1] = 0;
- for (int i=0; i<PLTABLE_SIZE; i++)
- {
- m_sAgcPathLoss.agcPathLoss[freqband][i].gain_offset = (int)(fdata[i]*GAIN_SCALE);
- }
- delete ini_file;
- return true;
- }
- //===========================================================================
- bool CRFAGC::REQ_Write_To_File(char *filename)
- {
- FrequencyBand FrequencyBandStart;
- if(frmMainSel->cbGSM850->Checked)
- {
- FrequencyBandStart = FrequencyBand850;
- }
- else
- {
- FrequencyBandStart = FrequencyBand900;
- }
- for (FrequencyBand freqband = FrequencyBandStart; freqband<=FrequencyBand1900; freqband++)
- {
- if (!REQ_Write_To_File_Single_Band(filename, freqband))
- {
- return false;
- }
- }
- return true;
- }
- //---------------------------------------------------------------------------
- bool CRFAGC::REQ_Write_To_File_Single_Band(char *filename, FrequencyBand freqband)
- {
- TIniFile *ini_file;
- char str[2048];
- int idata[PLTABLE_SIZE];
- float fdata[PLTABLE_SIZE];
- int i;
- ini_file = new TIniFile( filename );
- if( ini_file == NULL ) return false;
- if( ini_file != NULL )
- {
- for(i=0; i<PLTABLE_SIZE; i++)
- { idata[i] = m_sAgcPathLoss.agcPathLoss[freqband][i].max_arfcn;
- }
- Array_To_String_int( str, idata, PLTABLE_SIZE-1, ',' );
- ini_file->WriteString( SUBBAND_NAME[freqband],
- "Max ARFCN",
- str );
- for(i=0; i<PLTABLE_SIZE; i++)
- { fdata[i] = m_sAgcPathLoss.agcPathLoss[freqband][i].gain_offset*1.0/GAIN_SCALE;
- }
- Array_To_String_float( str, fdata, PLTABLE_SIZE-1, ',' );
- ini_file->WriteString( SUBBAND_NAME[freqband],
- "RX loss",
- str);
- delete ini_file;
- }
- return true;
- }
- //-------------------------------------------------------------------------
- bool CRFAGC::REQ_Write_To_M12193( char *filename )
- {
- FILE *fs;
- int arfcn, loss;
- int band, i;
- fs = fopen( filename, "a+t" );
- if(fs==0) return(false);
- fprintf( fs, "/*----------------------------------------*/n");
- fprintf( fs, "/* Calibration data for path loss of gain */n");
- fprintf( fs, "/*----------------------------------------*/n");
- fprintf( fs, "n");
- for(band=2; band<5; band++)
- {
- fprintf( fs, "/* %s....................................................................*/n", BAND_NAME[band] );
- fprintf( fs, "n");
- fprintf( fs, "sAGCGAINOFFSET AGC_PATHLOSS_%s[ PLTABLE_SIZE ] =n", BAND_NAME[band] );
- fprintf( fs, "{n");
- for( i=0; i<PLTABLE_SIZE-1; i++ )
- { arfcn = m_sAgcPathLoss.agcPathLoss[band][i].max_arfcn;
- loss = m_sAgcPathLoss.agcPathLoss[band][i].gain_offset;
- if( (arfcn<0)||(arfcn>1023) ) break;
- fprintf( fs, " { %4d, GAINLOSS( %.3f ) },n", arfcn , (float)loss*1.0/GAIN_SCALE );
- }
- fprintf( fs, " /*-------------------------*/n");
- fprintf( fs, " { TABLE_END }n");
- fprintf( fs, "};n");
- fprintf( fs, "n");
- }
- fprintf( fs, "/*...........................................................................*/n");
- fprintf( fs, "n");
- fprintf( fs, "sAGCGAINOFFSET* AGC_PATHLOSS_TABLE[] =n");
- fprintf( fs, "{ 0, /*#FrequencyBand400 */n");
- fprintf( fs, " 0, /*#FrequencyBand850 */n");
- fprintf( fs, " AGC_PATHLOSS_GSM900, /* FrequencyBand900 */n");
- fprintf( fs, " AGC_PATHLOSS_DCS1800, /* FrequencyBand1800 */n");
- fprintf( fs, " AGC_PATHLOSS_PCS1900, /* FrequencyBand1900 */n");
- fprintf( fs, "};n");
- fprintf( fs, "n");
- fclose(fs);
- return(true);
- }
- //===========================================================================
- ///////////////////////// Global information //////////////////////////////
- //===========================================================================
- E_METAAPP_RESULT_T CRFAGC::Get_ConfirmState(void)
- {
- return m_eConfirmState;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- l1cal_agcPathLoss_T* CRFAGC::Get_PathLoss(void)
- {
- return &m_sAgcPathLoss;
- }
- //---------------------------------------------------------------------------
- void CRFAGC::Set_PathLoss(l1cal_agcPathLoss_T path_loss)
- {
- m_sAgcPathLoss = path_loss;
- }