⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 td1536.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 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              : %M%    %I%
 *
 *  Last update              : %U% - %E%
 *
 *  Description              :
 *
 */

#include "td1536.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;
}td1536TunerStatus_t, *ptd1536TunerStatus_t;

static td1536TunerStatus_t statusArray[4];

static tmLibdevErr_t tuneToFreq(UInt32 unitID, UInt32 frequency, Int offset);

/******************************************************************************/
/* dummy function to be dll compatible with 2.0 final */
tmLibdevErr_t td1536GetStatus(UInt32 unitID, UInt8 * chanParams)
{
    return TMLIBDEV_OK;
}

static tmLibdevErr_t tuneToFreq(UInt32 unitID, UInt32 frequency, Int offset)
{
    ptd1536TunerStatus_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 < TD1536_MIN_FREQUENCY) || (tunFreq > TD1536_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 td1536Init(UInt32 unitID, ptd1536Param_t params)
{
    ptd1536TunerStatus_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   = 0xa0;
    tunerStatus->frequency  = 0;
    tunerStatus->offset     = 0;
    tunerStatus->iFreq      = params->iFreq;

    if (params->useInternalAGC)
        tunerStatus->control2 |= 0x04;

    switch (params->input)
    {
    case ttiCableNTSC:
        tunerStatus->control2 |= 0x01;
        break;
    case ttiCableATSC:
        tunerStatus->control2 |= 0x01 | 0x40;
        break;
    case ttiAntennaNTSC:
        break;
    case ttiAntennaATSC:
        tunerStatus->control2 |= 0x40;
        break;
    default:
        return TVTUNER_ERR_UNSUPPORTED_INPUT;
    }
 
    return tuneToFreq(unitID, 50000000, 0);
}

/******************************************************************************/
extern tmLibdevErr_t td1536SetFrequency(UInt32 unitID, ptsaTvTunerChannelParams_t chanParams)
{
    tmAssert(chanParams, TMLIBDEV_ERR_NULL_PARAMETER);

    return tuneToFreq(unitID, chanParams->frequency, chanParams->offset);
}

/******************************************************************************/
extern tmLibdevErr_t td1536SetInput(UInt32 unitID, tsaTvTunerInput_t input)
{
    ptd1536TunerStatus_t tunerStatus = &statusArray[unitID];
    UInt8                iicArray[2];
    iicRequest_t         req;
    tmLibdevErr_t        err;
    Int                  iicInstance;

    tunerStatus->control2 = tunerStatus->control2 & 0xbe;

    switch (input)
    {
    case ttiCableNTSC:
        tunerStatus->control2 |= 0x01;
        break;
    case ttiCableATSC:
        tunerStatus->control2 |= 0x01 | 0x40;
        break;
    case ttiAntennaNTSC:
        break;
    case ttiAntennaATSC:
        tunerStatus->control2 |= 0x40;
        break;
    default:
        return TVTUNER_ERR_UNSUPPORTED_INPUT;
    }

    iicArray[0] = tunerStatus->control1;
    iicArray[1] = tunerStatus->control2;

    req.address              = tunerStatus->iicAddress;
    req.byteCount            = 2;
    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->control2 = iicArray[1];

    return TMLIBDEV_OK;
}

/******************************************************************************/
extern tmLibdevErr_t td1536Tweak(UInt32 unitID, td1536TweakMode_t mode)
{
    ptd1536TunerStatus_t tunerStatus = &statusArray[unitID];
    Int                  offset;

    offset = tunerStatus->offset;

    switch (mode)
    {
    case td1536TweakUp:
        offset += TUNER_STEPSIZE;
        break;
    case td1536TweakDown:
        offset -= TUNER_STEPSIZE;
        break;
    case td1536TweakReset:
        offset = 0;
        break;
    default:
        return TVTUNER_ERR_UNSUPPORTED_TWEAK_MODE;
    }

    return tuneToFreq(unitID, tunerStatus->frequency, offset);
}

/******************************************************************************/
extern tmLibdevErr_t td1536GetChanParams(UInt32 unitID, ptsaTvTunerChannelParams_t chanParams)
{
    ptd1536TunerStatus_t tunerStatus = &statusArray[unitID];

    tmAssert(chanParams, TMLIBDEV_ERR_NULL_PARAMETER);

    chanParams->frequency = tunerStatus->frequency;
    chanParams->offset    = tunerStatus->offset;

    return TMLIBDEV_OK;
}

/******************************************************************************/
extern tmLibdevErr_t td1536GetLock(UInt32 unitID, Bool * locked)
{
    ptd1536TunerStatus_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 + -