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

📄 saa7111.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
 * Copyright (c) 1995,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              : saa7111.c    1.29
 *
 *  Last update              : 11:58:50 - 99/06/23
 *
 *  Description              :
 *
 *  Initialize and control routines for saa7111 and 7111a.
 *
 *
 *  Revision                 :
 *        Built for the TCS 2.0 release
 *
 *
 */


#include <stdio.h>
#include <tm1/tmIIC.h>
#include <tm1/tmAvFormats.h>
#include <tm1/tmVImmio.h>
#include <tm1/tmVIboard.h>
#include <tmlib/dprintf.h>
#include <saa7111.h>


#define        SAA7111_NREGS     0x13    /* number of 7111 registers     */
#define        SAA7111A_NREGS    0x1F    /* number of 7111 registers     */

/******************************************************************************/
/* Default structures for video decoder configuration (supports 1 default instance) */
static boardVIAdapterEntry_t defAdapters[2] = {
  { vaaCVBS,   0, 0 },
  { vaaSvideo, 0, 5 }
};

static boardVIDec_t defaultVD [1] = 
{
    { 0x48,                /* I2C slave address of first decoder  */
      2,                   /* Number of adapters                  */
      defAdapters }        /* mapping of adapters to inputs       */
};

static UInt lastI2cError = 0;

/******************************************************************************/
/* Definitions and structures used by the video DecHAL implementation         */

typedef enum 
{
    ChipVersion=            0x00,   
    Reserved=               0x01,   
    AnalogInputControl1=    0x02,   
    AnalogInputControl2=    0x03,   
    AnalogInputControl3=    0x04,   
    AnalogInputControl4=    0x05,   
    HorzSyncStart=          0x06,   
    HorzSyncStop=           0x07,   
    SyncControl=            0x08,   
    LuminanceControl=       0x09,   
    LuminanceBrightness=    0x0A,   
    LuminanceContrast=      0x0B,   
    ChromaSaturation=       0x0C,   
    ChromaHueControl=       0x0D,   
    ChromaControl=          0x0E,   

    FormatDelayControl=     0x10,   
    OutputControl1=         0x11,   
    OutputControl2=         0x12,   
    OutputControl3=         0x13,   

    VGateStart=             0x15,   
    VGateStop=              0x16,   
    VGateMSB=               0x17,   

    TextSlicerStatus=       0x1A,
    TextSlicerByte1=        0x1B,
    TextSlicerByte2=        0x1C,

    StatusByte=             0x1F,   
} decoderRegs_t;

static unsigned char saa7111_regs[SAA7111A_NREGS] = {
    0x00, 0x00, 0xD8, 0x23, 0x00, 0x00, 0x00, 0x00,
    0x88, 0x10, 0x80, 0x47, 0x40, 0x00, 0x01, 0x00,
    0xC8, 0x8C, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
/*  Set one extra bit in order to make tm1100 debug board
    direct vi to TM1 iso. to vo directly.
    Hopefully, it doesn't affect other boards.
    The line used to be:
    0xC8, 0x0C, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, */
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

/******************************************************************************/
static tmLibdevErr_t  
mapAdapterInput (pboardVIDec_t pVD, pboardVIParam_t param, UInt *mode)
{
    UInt i; 

    /* If the adapter is vaaNone then use the default adapter */
    if (param->adapterType == vaaNone)
    {
        *mode = pVD->adapterTable[0].decInput;
        return TMLIBDEV_OK;
    }

    for (i = 0; i < pVD->numAdapters; i++)
    {
        /* Find the right instance of the adapter */
        if ((pVD->adapterTable[i].instNum == param->adapterInstance) &&
            (pVD->adapterTable[i].adapterType == param->adapterType))
        {
            *mode = pVD->adapterTable[i].decInput;
            return TMLIBDEV_OK;
        }
    }

    /* No adapter instance found. If it's unqual to zero */
    /*  -> try with instance zero... */
    if (param->adapterInstance != 0)
    {
        param->adapterInstance = 0;
        return mapAdapterInput (pVD, param, mode);
    }

    /* Right adapter was not found -> return error */
    return BOARD_ERR_UNSUPPORTED_ADAPTER;
}

/******************************************************************************/
tmLibdevErr_t 
saa7111InitM(pboardVIDec_t pVD, pboardVIParam_t param)
{
    UInt        i, rval = 0;
    UInt inputMode;   

    viSetSELFCLOCKM(param->mmioBase, 0);

    /* Copy video standard to internal variable */
    pVD->curVideoStandard = param->videoStandard;

    if (param->videoStandard == vasNone)
        return TMLIBDEV_OK;
    if ( !(param->videoStandard & (vasNTSC | vasPAL)) )
        return BOARD_ERR_UNSUPPORTED_STANDARD;

    /* from here on : supported videoStandard is specified */ 
    for (i = 0; i < SAA7111_NREGS; i++) {
        rval |= iicWriteReg(pVD->slaveAddr, i, saa7111_regs[i]);
    }
    if (! ( (param->adapterType == vaaNone)
         || (param->adapterType & (vaaCVBS|vaaSvideo))) )
        return BOARD_ERR_UNSUPPORTED_ADAPTER;

    /* Make sure the adapter's instance is valid on this board and we get a valid mode */
    if (mapAdapterInput (pVD, param, &inputMode) != TMLIBDEV_OK)
        return BOARD_ERR_INVALID_ADAPTER_INSTANCE;

    /* Set input of video accordingly */
    rval |= saa7111SetAnalogInput (pVD, inputMode);

    return (tmLibdevErr_t) rval;
}

tmLibdevErr_t 
saa7111Init(pboardVIParam_t param)
{
    return saa7111InitM(&defaultVD[0], param);
}

/******************************************************************************/

#define A_STATUS_CTL        0x1F
#define A_HLCK_MASK         0x40
#define A_FIDT_MASK         0x20
#define A_CSTD_DETECTED_MASK    0x01

#define A_CHROMA_CTL        0x0E

tmLibdevErr_t
saa7111AGetStandardM(pboardVIDec_t pVD, tmVideoAnalogStandard_t * std)
{
    unsigned int        stat, chroma;
    int                 notDetected = True;
    int                 err = 0;
    int                 i, j;
    unsigned char       colorStandard[5] = {0x01, 0x11, 0x21, 0x31, 0x51};

    microsleep(400000);     /* This stupid routine need to sleep a lot. */
    for (j = 0; ( (j<2) && notDetected ); j++) { 
        for ( *std = vasNone, i = 0; ( (i<5) && notDetected ); i++) {
            err |= iicWriteReg(pVD->slaveAddr, A_CHROMA_CTL, colorStandard[i]);
            microsleep(100000);
            err |= iicReadReg(pVD->slaveAddr, A_CHROMA_CTL, &chroma);
            err |= iicReadReg(pVD->slaveAddr, A_STATUS_CTL, &stat);
 
            if (err) {
                /* iic read write err */
                return ( (tmLibdevErr_t) err); 
            }
            if (stat & A_HLCK_MASK) {
                microsleep(500000); /* not in sync err, give it a long nap */
            }
            if (stat & A_CSTD_DETECTED_MASK) { /* color videoStandard detected */
                if (stat & A_FIDT_MASK) {  /* 60 Hz */
                    switch (i) {
                        case 0: /* NTSC M */
                            *std = vasNTSC;
                            break;
                        case 1: /* PAL 4.43 */
                            *std = vasPAL;
                            break;
                        case 2: /* NTSC 4.43 */
                            *std = vasNTSC;
                            break;
                        case 3: /* NTSC N */
                            *std = vasNTSC;
                            break;
                        case 4: /* PAL 4.43 */
                            *std = vasPAL;
                            break;
                        default:
                            *std = vasNone; /* should not come here */
                            break;
                    } /* end of switch */
                } else { /* 50Hz */
                    switch (i) {
                        case 0: /* PAL BGHI */
                            *std = vasPAL;
                            break;
                        case 1: /* NTSC 4.43 */
                            *std = vasNTSC;
                            break;
                        case 2: /* PAL N */
                            *std = vasPAL;
                            break;
                        case 3: /* PAL M */
                            *std = vasPAL;
                            break;
                        case 4: /* SECAM */
                            *std = vasSECAM;
                            break;
                        default:
                            *std = vasNone; /* should not come here */
                            break;
                    } /* end of switch */
                }
                notDetected = False;
            }
        } /* end of i for loop */
    } /* end of j for loop */

    if (stat & A_HLCK_MASK) {
        /* not in sync err, message may be obscure */
        return BOARD_ERR_VAL_OUT_OF_RANGE;
    }
    if (notDetected) {
        return BOARD_ERR_COLOR_STANDARD_NOT_DETECTED;
    }

    /* Store detected standard in internal variable */
    pVD->curVideoStandard = *std;

    return TMLIBDEV_OK;
}

tmLibdevErr_t
saa7111AGetStandard(tmVideoAnalogStandard_t * std)
{
    return saa7111AGetStandardM (&defaultVD[0], std);
}

tmLibdevErr_t 
saa7111GetAdapterVideoStandard(pboardVIDec_t pVD, tmVideoAnalogAdapter_t adapter, UInt adapterNum, tmVideoAnalogStandard_t *std)
{
    UInt inputMode;   

    /* Build up fake param structure to use available map function */
    boardVIParam_t param;

    param.adapterInstance = adapterNum;
    param.adapterType     = adapter;

    /* Map the adapter's instance to a valid mode */
    if (mapAdapterInput (pVD, &param, &inputMode) != TMLIBDEV_OK)
        return BOARD_ERR_INVALID_ADAPTER_INSTANCE;

    /* Set input of video accordingly */
    saa7111SetAnalogInput (pVD, inputMode);

    return saa7111AGetStandardM (pVD, std);
}

/******************************************************************************/

tmLibdevErr_t 
saa7111AInitM(pboardVIDec_t pVD, pboardVIParam_t param)
{
    UInt        i, rval = 0;

    viSetSELFCLOCKM(param->mmioBase, 0);

    /* Copy video standard to internal variable */
    pVD->curVideoStandard = param->videoStandard;

    if (param->videoStandard == vasNone)
        return TMLIBDEV_OK;
    if ( !(param->videoStandard & (vasNTSC | vasPAL)) )
        return BOARD_ERR_UNSUPPORTED_STANDARD;

    /* from here on : supported standard is specified */ 
    for (i = 0; i < SAA7111A_NREGS; i++) {
        rval |= iicWriteReg(pVD->slaveAddr, i, saa7111_regs[i]);
    }
    if (! ((param->adapterType==vaaNone)
         ||(param->adapterType&(vaaCVBS|vaaSvideo))) )
        return BOARD_ERR_UNSUPPORTED_ADAPTER;

    if (param->adapterType == vaaSvideo) {
        rval |= iicWriteReg(pVD->slaveAddr, 0x2, 0xDD);
        rval |= iicWriteReg(pVD->slaveAddr, 0x9, 0x80);
    }

    return (tmLibdevErr_t) rval;
}

tmLibdevErr_t 
saa7111AInit(pboardVIParam_t param)
{
    return saa7111AInitM(&defaultVD[0], param);
}

/**********************************************************************/

tmLibdevErr_t 
saa7111ConfigureM(pboardVIDec_t pVD, UInt32 subaddr, UInt32 value)
{
    tmLibdevErr_t rval = TMLIBDEV_OK;

    rval |= iicWriteReg(pVD->slaveAddr, subaddr, value);
    return (tmLibdevErr_t) rval;
}

tmLibdevErr_t 
saa7111Configure(UInt32 subaddr, UInt32 value)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -