📄 tunermt2060.c
字号:
/**
* \file $Id: tunermt2060.c,v 1.10 2005/10/19 07:44:35 paulja Exp $
*
* \brief DRXBSP tuner implementation for MT2060.
*
* \author Paul Janssen
*/
/*
* $(c) 2005 Micronas GmbH. All rights reserved.
*
* This software and related documentation (the 'Software') are intellectual
* property owned by Micronas and are copyright of Micronas, unless specifically
* noted otherwise.
*
* Any use of the Software is permitted only pursuant to the terms of the
* license agreement, if any, which accompanies, is included with or applicable
* to the Software ('License Agreement') or upon express written consent of
* Micronas. Any copying, reproduction or redistribution of the Software in
* whole or in part by any means not in accordance with the License Agreement
* or as agreed in writing by Micronas is expressly prohibited.
*
* THE SOFTWARE IS WARRANTED, IF AT ALL, ONLY ACCORDING TO THE TERMS OF THE
* LICENSE AGREEMENT. EXCEPT AS WARRANTED IN THE LICENSE AGREEMENT THE SOFTWARE
* IS DELIVERED 'AS IS' AND MICRONAS HEREBY DISCLAIMS ALL WARRANTIES AND
* CONDITIONS WITH REGARD TO THE SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIT
* ENJOYMENT, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL
* PROPERTY OR OTHER RIGHTS WHICH MAY RESULT FROM THE USE OR THE INABILITY
* TO USE THE SOFTWARE.
*
* IN NO EVENT SHALL MICRONAS BE LIABLE FOR INDIRECT, INCIDENTAL, CONSEQUENTIAL,
* PUNITIVE, SPECIAL OR OTHER DAMAGES WHATSOEVER INCLUDING WITHOUT LIMITATION,
* DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
* INFORMATION, AND THE LIKE, ARISING OUT OF OR RELATING TO THE USE OF OR THE
* INABILITY TO USE THE SOFTWARE, EVEN IF MICRONAS HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES, EXCEPT PERSONAL INJURY OR DEATH RESULTING FROM
* MICRONAS' NEGLIGENCE. $
*
*/
/*------------------------------------------------------------------------------
INCLUDE FILES
------------------------------------------------------------------------------*/
#include "tunermt2060.h"
/*------------------------------------------------------------------------------
DEFINES
------------------------------------------------------------------------------*/
#define TUNER_MT2060_IF_OUTPUT_FREQ (36000000) /* in Hz */
#define TUNER_MT2060_FREQ_STEP_SIZE (62500) /* in Hz */
/*------------------------------------------------------------------------------
STATIC VARIABLES
------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
GLOBAL VARIABLES
------------------------------------------------------------------------------*/
TUNERFunc_t TUNERMT2060Functions_g = {
TUNER_MT2060_Open,
TUNER_MT2060_Close,
TUNER_MT2060_SetFrequency,
TUNER_MT2060_GetFrequency,
TUNER_MT2060_LockStatus,
DRXBSP_TUNER_DefaultI2CWriteRead
};
/*------------------------------------------------------------------------------
STRUCTURES
------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
FUNCTIONS
------------------------------------------------------------------------------*/
/**
* \fn DRXStatus_t TUNER_MT2060_Open( pTUNERInstance_t tuner )
* \brief Open a tuner.
* \return DRXStatus_t Return status.
* \retval DRX_STS_OK Opened tuner with success.
* \retval DRX_STS_ERROR Something went wrong.
*/
DRXStatus_t
TUNER_MT2060_Open( pTUNERInstance_t tuner )
{
UData_t mtStatus = MT_ERROR;
const UData_t freqStepSize = TUNER_MT2060_FREQ_STEP_SIZE;
pTUNERMT2060Data_t extAttr = (pTUNERMT2060Data_t) tuner->myExtAttr;
/* initialize the tuner */
mtStatus = MT2060_Open( tuner->myI2CDevAddr.i2cAddr,
&(extAttr->handleTuner),
(Handle_t) tuner );
if ( MT_IS_ERROR(mtStatus) )
{
return DRX_STS_ERROR;
}
/* program gain range */
mtStatus = MT2060_SetGainRange( extAttr->handleTuner,
MT2060_VGAG_0DB);
if (MT_IS_ERROR(mtStatus))
{
return DRX_STS_ERROR;
}
/* program frequency stepsize */
mtStatus = MT2060_SetParam( extAttr->handleTuner,
MT2060_STEPSIZE,
freqStepSize );
if ( MT_IS_ERROR(mtStatus) )
{
return DRX_STS_ERROR;
}
return DRX_STS_OK;
}
/*============================================================================*/
/**
* \fn DRXStatus_t DRXBSP_TUNER_Close( pTUNERInstance_t tuner )
* \brief Close a tuner.
* \return DRXStatus_t Return status.
* \retval DRX_STS_OK Closed tuner with success.
* \retval DRX_STS_ERROR Something went wrong.
*/
DRXStatus_t
TUNER_MT2060_Close( pTUNERInstance_t tuner )
{
UData_t mtStatus = MT_ERROR;
pTUNERMT2060Data_t extAttr = (pTUNERMT2060Data_t) tuner->myExtAttr;
mtStatus = MT2060_Close( extAttr->handleTuner );
if ( MT_IS_ERROR(mtStatus) )
{
return DRX_STS_ERROR;
}
return( DRX_STS_OK );
}
/*============================================================================*/
/**
* \fn DRXStatus_t DRXBSP_TUNER_SetFrequency( pTUNERInstance_t tuner,
TUNERMode_t mode,
DRXFrequency_t centerFrequency )
* \brief Program tuner at given center frequency for given mode.
* \return DRXStatus_t Return status.
* \retval DRX_STS_OK Programmed tuner successfully.
* \retval DRX_STS_ERROR Something went wrong.
*/
DRXStatus_t
TUNER_MT2060_SetFrequency( pTUNERInstance_t tuner,
TUNERMode_t mode,
DRXFrequency_t centerFrequency )
{
UData_t newBandwidth = 0;
UData_t correctedCenterFreq = 0;
UData_t newCenterFreq = 0;
s32_t offsetFreq = 0;
UData_t mtStatus = MT_ERROR;
pTUNERMT2060Data_t extAttr = (pTUNERMT2060Data_t) tuner->myExtAttr;
if ( ( centerFrequency < ( tuner->myCommonAttr->minFreqRF) ) ||
( centerFrequency > ( tuner->myCommonAttr->maxFreqRF) ) )
{
/* frequency out of range for this tuner */
return DRX_STS_ERROR;
}
/* determine bandwidth */
switch ( mode & (TUNER_MODE_6MHZ | TUNER_MODE_7MHZ | TUNER_MODE_8MHZ) )
{
case TUNER_MODE_6MHZ:
newBandwidth = 6750000L;
break;
case TUNER_MODE_7MHZ:
newBandwidth = 7750000L;
break;
case TUNER_MODE_8MHZ:
newBandwidth = 8750000L;
break;
default:
return (DRX_STS_ERROR);
}
/* determine offset to program (crystal deviation) */
offsetFreq = ((s32_t)centerFrequency * (extAttr->freqOffsetRF));
offsetFreq /= ((s32_t)1000000L);
correctedCenterFreq = (UData_t)( ((s32_t)1000)*((s32_t)centerFrequency + offsetFreq) );
/* program desired RF frequency */
mtStatus = MT2060_ChangeFreq( extAttr->handleTuner,
correctedCenterFreq,
(extAttr->firstIF),
TUNER_MT2060_IF_OUTPUT_FREQ,
newBandwidth);
if (MT_IS_ERROR(mtStatus))
{
return (DRX_STS_ERROR);
}
#if 0
/* Compute actual RF frequency to which tuner is tuned */
mtStatus = MT2060_GetParam( extAttr->handleTuner,
MT2060_INPUT_FREQ,
&newCenterFreq);
if (MT_IS_ERROR(mtStatus))
{
return (DRX_STS_ERROR);
}
newCenterFreq -= ((UData_t) offsetFreq);
#else
newCenterFreq = centerFrequency;
#endif
tuner->myCommonAttr->RFfrequency = (DRXFrequency_t) newCenterFreq;
tuner->myCommonAttr->IFfrequency =
(DRXFrequency_t) (TUNER_MT2060_IF_OUTPUT_FREQ/1000 );
return( DRX_STS_OK );
}
/*============================================================================*/
/**
* \fn DRXStatus_t DRXBSP_TUNER_GetFrequency( pTUNERInstance_t tuner,
pDRXFrequency_t RFfrequency,
pDRXFrequency_t IFfrequency )
* \brief Get tuned center frequency.
* \return DRXStatus_t Return status.
* \retval DRX_STS_OK Returned frequency successfully.
* \retval DRX_STS_ERROR Something went wrong.
*/
DRXStatus_t
TUNER_MT2060_GetFrequency( pTUNERInstance_t tuner,
pDRXFrequency_t RFfrequency,
pDRXFrequency_t IFfrequency )
{
if ( RFfrequency != NULL )
{
*RFfrequency = tuner->myCommonAttr->RFfrequency;
}
if ( IFfrequency != NULL )
{
*IFfrequency = tuner->myCommonAttr->IFfrequency;
}
return( DRX_STS_OK );
}
/*============================================================================*/
/**
* \fn DRXStatus_t DRXBSP_TUNER_LockStatus( pTUNERInstance_t tuner,
pTUNERLockStatus_t lockStat )
* \brief Get tuner locking status.
* \return DRXStatus_t Return status.
* \retval DRX_STS_OK Acquired locking status successfully.
* \retval DRX_STS_ERROR Something went wrong.
*/
DRXStatus_t
TUNER_MT2060_LockStatus( pTUNERInstance_t tuner,
pTUNERLockStatus_t lockStat )
{
UData_t mtStatus = MT_ERROR;
pTUNERMT2060Data_t extAttr = (pTUNERMT2060Data_t) tuner->myExtAttr;
/* report lock */
if ( lockStat != NULL )
{
*lockStat = TUNER_NOT_LOCKED;
/* read tuner lock status */
mtStatus = MT2060_GetLocked( extAttr->handleTuner );
if (mtStatus == MT_OK)
{
/* tuner is locked */
*lockStat = TUNER_LOCKED;
}
else if ( MT_IS_ERROR(mtStatus) )
{
return DRX_STS_ERROR;
}
}
return DRX_STS_OK;
}
/*============================================================================*/
/* End of file */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -