fm_radio.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:21k
- /*****************************************************************************
- * 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:
- * ---------
- * fm_radio.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * FM radio 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 _FM_RADIO_H_
- #include "fm_radio.h"
- #endif
- #ifndef _MAN_ACTIVE_H_
- #include "man_active.h"
- #endif
- #ifndef _MAN_FDM_H_
- #include "man_fdm.h"
- #endif
- #ifndef _MAN_HANDLE_H_
- #include "man_handle.h"
- #endif
- //===========================================================================
- static CFMRADIO* g_fm_radio_ptr;
- static bool g_bIsRunning = false;
- //===========================================================================
- //------------------------------------------------------------------------------
- //static void REQ_TimeOut(void)
- //{
- // g_fm_radio_ptr->REQ_TimeOut();
- //}
- //------------------------------------------------------------------------------
- //static void REQ_Finish(void)
- //{
- // g_fm_radio_ptr->REQ_Finish();
- //}
- //---------------------------------------------------------------------------
- static void REQ_FM_Power_On(void)
- {
- g_fm_radio_ptr->REQ_FM_Power_On();
- }
- //---------------------------------------------------------------------------
- static void REQ_FM_Power_Off(void)
- {
- g_fm_radio_ptr->REQ_FM_Power_Off();
- }
- //---------------------------------------------------------------------------
- static void REQ_Set_Freq(void)
- {
- g_fm_radio_ptr->REQ_Set_Freq();
- }
- //---------------------------------------------------------------------------
- static void REQ_Get_FM_Status(void)
- {
- g_fm_radio_ptr->REQ_Get_FM_Status();
- }
- //---------------------------------------------------------------------------
- static void REQ_SearchFreq(void)
- {
- g_fm_radio_ptr->REQ_SearchFreq();
- }
- //---------------------------------------------------------------------------
- static void REQ_SetAudio(void)
- {
- g_fm_radio_ptr->REQ_SetAudio();
- }
- //----------------------------------------------------------------------------
- static void __stdcall CNF_AudioSetVolume(const AUDIO_RESULT status, const short token, void *usrData)
- {
- g_fm_radio_ptr->CNF_AudioSetVolume(status, token, usrData);
- }
- //---------------------------------------------------------------------------
- static void REQ_ReadData(void)
- {
- g_fm_radio_ptr->REQ_ReadData();
- }
- //---------------------------------------------------------------------------
- static void REQ_WriteData(void)
- {
- g_fm_radio_ptr->REQ_WriteData();
- }
- //===========================================================================
- CFMRADIO::CFMRADIO(void)
- {
- g_bIsRunning = false;
- ConfirmCallback = NULL;
- }
- //---------------------------------------------------------------------------
- CFMRADIO::~CFMRADIO()
- {
- g_bIsRunning = false;
- ConfirmCallback = NULL;
- }
- //---------------------------------------------------------------------------
- //void CFMRADIO::REQ_Finish(void)
- //{
- // if (!g_bIsRunning)
- // {
- // return;
- // }
- //
- // Confirm(METAAPP_SUCCESS);
- //}
- //---------------------------------------------------------------------------
- //void CFMRADIO::REQ_TimeOut(void)
- //{
- // if (!g_bIsRunning)
- // {
- // return;
- // }
- //
- // META_CancelAllBlockingCall_r(m_META_HANDLE_Obj.Get_MainHandle());
- // Confirm(METAAPP_TIMEOUT);
- //}
- //---------------------------------------------------------------------------
- void CFMRADIO::Confirm(E_METAAPP_RESULT_T confirm_state)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- if (confirm_state != METAAPP_SECTION_OK)
- {
- g_bIsRunning = false;
- }
- if (confirm_state != METAAPP_SUCCESS)
- {
- META_Cancel_r(m_META_HANDLE_Obj.Get_MainHandle(), m_sSETVOLUME);
- META_CancelAllBlockingCall_r(m_META_HANDLE_Obj.Get_MainHandle());
- }
- if (NULL == ConfirmCallback)
- {
- return;
- }
- m_eConfirmState = confirm_state;
- ActiveMan->SetActiveFunction(ConfirmCallback);
- }
- //===========================================================================
- void CFMRADIO::REQ_FM_Power_On_Start(void)
- {
- g_fm_radio_ptr = this;
- g_bIsRunning = true;
- ActiveMan->SetActiveFunction(::REQ_FM_Power_On);
- }
- //---------------------------------------------------------------------------
- void CFMRADIO::REQ_FM_Power_On(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- META_RESULT MetaResult = META_FM_PowerOn_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000);
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- Confirm(METAAPP_SUCCESS);
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void CFMRADIO::REQ_FM_Power_Off_Start(void)
- {
- g_fm_radio_ptr = this;
- g_bIsRunning = true;
- ActiveMan->SetActiveFunction(::REQ_FM_Power_Off);
- }
- //---------------------------------------------------------------------------
- void CFMRADIO::REQ_FM_Power_Off(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- META_RESULT MetaResult = META_FM_PowerOff_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000);
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- Confirm(METAAPP_SUCCESS);
- }
- //===========================================================================
- void CFMRADIO::REQ_Set_Freq_Start(FM_FREQ_REQ_T freq)
- {
- g_fm_radio_ptr = this;
- g_bIsRunning = true;
- m_sFMFreq = freq;
- ActiveMan->SetActiveFunction(::REQ_Set_Freq);
- }
- //---------------------------------------------------------------------------
- void CFMRADIO::REQ_Set_Freq(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- META_RESULT MetaResult = META_FM_SetFreq_r(m_META_HANDLE_Obj.Get_MainHandle(),5000, &m_sFMFreq);
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- Confirm(METAAPP_SUCCESS);
- }
- //===========================================================================
- void CFMRADIO::REQ_SearchFreq_Start(S_FM_SEARCH_STATION_T search_station)
- {
- g_fm_radio_ptr = this;
- g_bIsRunning = true;
- m_sSearchStation = search_station;
- ActiveMan->SetActiveFunction(::REQ_SearchFreq);
- }
- //---------------------------------------------------------------------------
- void CFMRADIO::REQ_SearchFreq(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- META_RESULT MetaResult;
- // set RSSI threshold
- MetaResult = META_FM_SetRssiThreold_r(m_META_HANDLE_Obj.Get_MainHandle(),5000, &m_sSearchStation.s_rssi_thrsh);
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- // set IF counter delta
- MetaResult = META_FM_SetIfCntDelta_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &m_sSearchStation.s_if_cnt_delta);
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- // search station
- if (m_sSearchStation.s_freq_range.m_i2StartFreq < m_sSearchStation.s_freq_range.m_i2StopFreq)
- {
- MetaResult = META_FM_SearchNextFreq_r(m_META_HANDLE_Obj.Get_MainHandle(),5000, &m_sSearchStation.s_freq_range, &m_sValidFreq);
- }
- else
- {
- MetaResult = META_FM_SearchPrevFreq_r(m_META_HANDLE_Obj.Get_MainHandle(),5000, &m_sSearchStation.s_freq_range, &m_sValidFreq);
- }
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- if ((!m_sValidFreq.m_ucExit) || (m_sValidFreq.m_i2ValidFreq <= 0))
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- FM_FREQ_REQ_T freq_req;
- freq_req.m_i2CurFreq = m_sValidFreq.m_i2ValidFreq;
- MetaResult = META_FM_SetFreq_r(m_META_HANDLE_Obj.Get_MainHandle(),5000, &freq_req);
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- Confirm(METAAPP_SUCCESS);
- }
- //===========================================================================
- void CFMRADIO::REQ_Get_FM_Status_Start(void)
- {
- g_fm_radio_ptr = this;
- g_bIsRunning = true;
- ActiveMan->SetActiveFunction(::REQ_Get_FM_Status);
- }
- //---------------------------------------------------------------------------
- void CFMRADIO::REQ_Get_FM_Status(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- // RSSI
- META_RESULT MetaResult = META_FM_GetRSSI_r(m_META_HANDLE_Obj.Get_MainHandle(),5000, &m_sFMFreq, &(m_sStatus.s_rssi));
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- // IF counter
- MetaResult = META_FM_GetIfCnt_r(m_META_HANDLE_Obj.Get_MainHandle(),5000, &m_sFMFreq, &(m_sStatus.s_if_cnt));
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- // H/L state
- MetaResult = META_FM_GetHighOrLowSide_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &m_sFMFreq, &(m_sStatus.s_hl_side));
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- // stereo/mono
- MetaResult = META_FM_GetStereoOrMono_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &(m_sStatus.s_stero_mono));
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- Confirm(METAAPP_SUCCESS);
- }
- //===========================================================================
- void CFMRADIO::REQ_SetAudio_Start(S_FM_AUDIO_T audio)
- {
- g_fm_radio_ptr = this;
- g_bIsRunning = true;
- m_sAudio = audio;
- ActiveMan->SetActiveFunction(::REQ_SetAudio);
- }
- //---------------------------------------------------------------------------
- void CFMRADIO::REQ_SetAudio(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- // set volume
- // META_RESULT MetaResult = META_Audio_Set_Volume_r(m_META_HANDLE_Obj.Get_MainHandle(), &m_sAudio.s_vol, ::CNF_AudioSetVolume, &m_sSETVOLUME, NULL);
- // if (MetaResult != META_SUCCESS)
- // {
- // if (META_TIMEOUT == MetaResult)
- // {
- // Confirm(METAAPP_TIMEOUT);
- // }
- // else
- // {
- // Confirm(METAAPP_FAIL);
- // }
- // return;
- // }
- // DWORD wait_result;
- // m_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- // ResetEvent(m_hEvent);
- // wait_result = WaitForSingleObject(m_hEvent, 5000);
- // if (WAIT_TIMEOUT == wait_result)
- // {
- // Confirm(METAAPP_TIMEOUT);
- // return;
- // }
- // set mono or stereo blend
- m_sAudio.s_mono_stereo_blend.m_u4ItemValue = FM_ENABLE;
- META_RESULT MetaResult = META_FM_SetMonoOrStereo_Blend_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &m_sAudio.s_mono_stereo_blend);
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- // set soft mute
- MetaResult = META_FM_SetSoftMute_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &m_sAudio.s_soft_mute_onoff);
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- // set soft mute stage
- //MetaResult = META_FM_SelectSoftMuteStage_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &m_sAudio.s_soft_mute_level);
- //if (MetaResult != META_SUCCESS)
- //{
- // if (META_TIMEOUT == MetaResult)
- // {
- // Confirm(METAAPP_TIMEOUT);
- // }
- // else
- // {
- // Confirm(METAAPP_FAIL);
- // }
- // return;
- //}
- // set blend stage
- MetaResult = META_FM_SelectSBlendStage_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &m_sAudio.s_stereo_blend_level);
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- Confirm(METAAPP_SUCCESS);
- }
- //--------------------------------------------------------------------------
- void __stdcall CFMRADIO::CNF_AudioSetVolume(const AUDIO_RESULT status, const short token, void *usrData)
- {
- if (status != AUD_RES_OK)
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- SetEvent(m_hEvent);
- }
- //===========================================================================
- void CFMRADIO::REQ_ReadData_Start(unsigned char addr)
- {
- g_fm_radio_ptr = this;
- g_bIsRunning = true;
- m_ucAddr = addr;
- ActiveMan->SetActiveFunction(::REQ_ReadData);
- }
- //---------------------------------------------------------------------------
- void CFMRADIO::REQ_ReadData(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- FM_READ_BYTE_ADDR_REQ_T req;
- FM_READ_BYTE_CNF_T cnf;
- req.m_ucAddr = m_ucAddr;
- META_RESULT MetaResult = META_FM_ReadByte_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &req, &cnf);
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- m_usData = cnf.m_u2ReadByte;
- Confirm(METAAPP_SUCCESS);
- }
- //===========================================================================
- void CFMRADIO::REQ_WriteData_Start(unsigned char addr, unsigned short data)
- {
- g_fm_radio_ptr = this;
- g_bIsRunning = true;
- m_ucAddr = addr;
- m_usData = data;
- ActiveMan->SetActiveFunction(::REQ_WriteData);
- }
- //---------------------------------------------------------------------------
- void CFMRADIO::REQ_WriteData(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- FM_WRITE_BYTE_REQ_T req;
- req.m_ucAddr = m_ucAddr;
- req.m_u2WriteByte = m_usData;
- META_RESULT MetaResult = META_FM_WriteByte_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &req);
- if (MetaResult != META_SUCCESS)
- {
- if (META_TIMEOUT == MetaResult)
- {
- Confirm(METAAPP_TIMEOUT);
- }
- else
- {
- Confirm(METAAPP_FAIL);
- }
- return;
- }
- Confirm(METAAPP_SUCCESS);
- }
- //===========================================================================
- ///////////////////////////// Query /////////////////////////
- //===========================================================================
- bool CFMRADIO::Query_FMSupport_Start(void)
- {
- META_RESULT MetaResult = META_QueryIfFunctionSupportedByTarget_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, "META_FM_GetChipId_r");
- if (MetaResult != META_SUCCESS)
- {
- m_bFMSupport = false;
- }
- m_bFMSupport = true;
- return m_bFMSupport;
- }
- //---------------------------------------------------------------------------
- bool CFMRADIO::REQ_Query_FMChipID_Start(FM_CHIP_ID_CNF_T& fm_chip_id)
- {
- META_RESULT MetaResult = META_FM_GetChipId_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &m_sFMChipId);
- if (MetaResult != META_SUCCESS)
- {
- return false;
- }
- fm_chip_id = m_sFMChipId;
- return true;
- }
- //===========================================================================
- ///////////////////////////// Global information /////////////////////////
- //===========================================================================
- E_METAAPP_RESULT_T CFMRADIO::Get_ConfirmState(void)
- {
- return m_eConfirmState;
- }
- //---------------------------------------------------------------------------
- bool CFMRADIO::Get_FMSupport(void)
- {
- return m_bFMSupport;
- }
- //---------------------------------------------------------------------------
- FM_CHIP_ID_CNF_T* CFMRADIO::Get_FMChipID(void)
- {
- return &m_sFMChipId;
- }
- //---------------------------------------------------------------------------
- S_FM_STATUS_T* CFMRADIO::Get_FMStatus(void)
- {
- return &m_sStatus;
- }
- //---------------------------------------------------------------------------
- FM_VAILD_FREQ_CNF_T* CFMRADIO::Get_ValidFreq(void)
- {
- return &m_sValidFreq;
- }
- //---------------------------------------------------------------------------
- unsigned short CFMRADIO::Get_Data(void)
- {
- return m_usData;
- }