📄 fi1236mk2.c
字号:
/*
* Copyright (c) 1999 by TriMedia Technologies.
*
* +-------------------------------------------------------------------+
* | This software is furnished under a license and may only be used |
* | and copied in accordance with the terms and conditions of such a |
* | license and with the inclusion of this copyright notice. This |
* | software or any other copies of this software may not be provided |
* | or otherwise made available to any other person. The ownership |
* | and title of this software is not transferred. |
* | |
* | The information in this software is subject to change without |
* | any prior notice and should not be construed as a commitment by |
* | TriMedia Technologies. |
* | |
* | This code and information is provided "as is" without any |
* | warranty of any kind, either expressed or implied, including but |
* | not limited to the implied warranties of merchantability and/or |
* | fitness for any particular purpose. |
* +-------------------------------------------------------------------+
*
*
* Module name : fi1236mk2.c 1.2
*
* Last update : 18:43:40 - 00/11/09
*
* Description :
*
*/
#include "fi1236mk2.h"
#include <tmlib/dprintf.h>
#include <tm1/tmAssert.h>
#include <tm1/tmIIC.h>
#include <tmlib/tmtypes.h>
/* Frequency Spec (Hz) */
#define LOW_BAND_MIN 50000000
#define LOW_BAND_MAX 157000000
#define MID_BAND_MIN 160000000
#define MID_BAND_MAX 450000000
#define HIGH_BAND_MIN 455000000
#define HIGH_BAND_MAX 860000000
#define TUNER_STEPSIZE 62500
/* Setting different bands (P7, P5, P4 of Control byte 2) */
#define LOW_BAND 0xa0
#define MID_BAND 0x90
#define HIGH_BAND 0x30
typedef struct
{
UInt32 iicAddress;
UInt32 frequency;
Int offset;
UInt32 iFreq;
UInt8 divider1;
UInt8 divider2;
UInt8 control1;
UInt8 control2;
}fi1236mk2TunerStatus_t, *pfi1236mk2TunerStatus_t;
static fi1236mk2TunerStatus_t statusArray[4];
static tmLibdevErr_t tuneToFreq(UInt32 unitID, UInt32 frequency, Int offset);
/******************************************************************************/
static tmLibdevErr_t tuneToFreq(UInt32 unitID, UInt32 frequency, Int offset)
{
pfi1236mk2TunerStatus_t tunerStatus = &statusArray[unitID];
UInt32 tunFreq;
UInt8 band;
UInt32 temp;
UInt8 iicArray[4];
iicRequest_t req;
tmLibdevErr_t err;
Int iicInstance;
if ((frequency == tunerStatus->frequency) && (offset == tunerStatus->offset))
return TMLIBDEV_OK;
tunFreq = frequency + offset;
/* check if frequency is in range */
if ((tunFreq < FI1236MK2_MIN_FREQUENCY) || (tunFreq > FI1236MK2_MAX_FREQUENCY))
return TVTUNER_ERR_UNSUPPORTED_FREQUENCY;
if (tunFreq < LOW_BAND_MAX)
{
band = LOW_BAND;
}
else if (tunFreq < MID_BAND_MAX)
{
band = MID_BAND;
}
else
{
band = HIGH_BAND;
}
tunerStatus->control2 = (tunerStatus->control2 & 0x4f) | band;
tunFreq += tunerStatus->iFreq;
temp = tunFreq / TUNER_STEPSIZE;
iicArray[0] = tunerStatus->control1;
iicArray[1] = tunerStatus->control2;
iicArray[2] = (UInt8) ((temp >> 8) & 0x7f);
iicArray[3] = (UInt8) (temp & 0xff);
req.address = tunerStatus->iicAddress;
req.byteCount = 4;
req.direction = IIC_WRITE;
req.type = IIC_SIMPLE;
req.data = iicArray;
req.numRetries = 1;
req.waitBeforeRetry = 200;
req.mode = IIC_Synchronous_By_Polling;
req.completion_function = Null;
err = iicOpen(&iicInstance);
if (err != TMLIBDEV_OK)
return err;
err = iicDispatch(iicInstance, &req);
if (err != TMLIBDEV_OK)
return err;
err = iicClose(iicInstance);
if (err != TMLIBDEV_OK)
return err;
tunerStatus->divider1 = iicArray[2];
tunerStatus->divider2 = iicArray[3];
tunerStatus->frequency = frequency;
tunerStatus->offset = offset;
return TMLIBDEV_OK;
}
/******************************************************************************/
extern tmLibdevErr_t fi1236mk2Init(UInt32 unitID, pfi1236mk2Param_t params)
{
pfi1236mk2TunerStatus_t tunerStatus = &statusArray[unitID];
tmAssert(params, TMLIBDEV_ERR_NULL_PARAMETER);
tunerStatus->iicAddress = params->iicAddress;
tunerStatus->divider1 = 0x01;
tunerStatus->divider2 = 0x00;
tunerStatus->control1 = 0x8e;
tunerStatus->control2 = 0x60;
tunerStatus->frequency = 0;
tunerStatus->offset = 0;
tunerStatus->iFreq = params->iFreq;
if (params->useInternalAGC)
tunerStatus->control2 |= 0x04;
return tuneToFreq(unitID, 50000000, 0);
}
/******************************************************************************/
extern tmLibdevErr_t fi1236mk2SetFrequency(UInt32 unitID, ptsaTvTunerChannelParams_t chanParams)
{
tmAssert(chanParams, TMLIBDEV_ERR_NULL_PARAMETER);
return tuneToFreq(unitID, chanParams->frequency, chanParams->offset);
}
/******************************************************************************/
extern tmLibdevErr_t fi1236mk2Tweak(UInt32 unitID, fi1236mk2TweakMode_t mode)
{
pfi1236mk2TunerStatus_t tunerStatus = &statusArray[unitID];
Int offset;
offset = tunerStatus->offset;
switch (mode)
{
case fi1236mk2TweakUp:
offset += TUNER_STEPSIZE;
break;
case fi1236mk2TweakDown:
offset -= TUNER_STEPSIZE;
break;
case fi1236mk2TweakReset:
offset = 0;
break;
default:
return TVTUNER_ERR_UNSUPPORTED_TWEAK_MODE;
}
return tuneToFreq(unitID, tunerStatus->frequency, offset);
}
/******************************************************************************/
extern tmLibdevErr_t fi1236mk2GetChanParams(UInt32 unitID, ptsaTvTunerChannelParams_t chanParams)
{
pfi1236mk2TunerStatus_t tunerStatus = &statusArray[unitID];
tmAssert(chanParams, TMLIBDEV_ERR_NULL_PARAMETER);
chanParams->frequency = tunerStatus->frequency;
chanParams->offset = tunerStatus->offset;
return TMLIBDEV_OK;
}
/******************************************************************************/
extern tmLibdevErr_t fi1236mk2GetLock(UInt32 unitID, Bool * locked)
{
pfi1236mk2TunerStatus_t tunerStatus = &statusArray[unitID];
tmLibdevErr_t err;
UInt iicVal;
err = iicReadReg(tunerStatus->iicAddress, -1, &iicVal);
if (err != TMLIBDEV_OK)
return err;
if (iicVal & 0x40)
*locked = True;
else
*locked = False;
return TMLIBDEV_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -