tmbsl7113.c

来自「PNX1500上视频采集芯片7113的设置源代码」· C语言 代码 · 共 2,254 行 · 第 1/5 页

C
2,254
字号
//// Copyright (C) 2003 Koninklijke Philips Electronics N.V., // All Rights Reserved. //// This source code and any compilation or derivative thereof is the // proprietary information of Koninklijke Philips Electronics N.V. // and is confidential in nature. // Under no circumstances is this software to be exposed to or placed // under an Open Source License of any type without the expressed // written permission of Koninklijke Philips Electronics N.V. // //###########################################################//! //      \file           tmbsl7113.c // //      \brief          - // // //-----------------------------------------------------------// //      %version:       eh04#32 % //      instance:       DS_4 //      %date_created:  2004-12-02 16:38:14 % ////###########################################################//-----------------------------------------------------------------------------// FILE NAME:    tmbsl7113.c//// DESCRIPTION:  These are some functions to handle/simulate the external//               analog video input decoder.//// DOCUMENT REF: DVP Software Coding Guidelines//               DVP/MoReUse Naming Conventions specification//               DVP Software Versioning Specification//               DVP Board Support Library Architecture Specification//// NOTES:        None//-----------------------------------------------------------------------------////-----------------------------------------------------------------------------// Standard include files://-----------------------------------------------------------------------------//#include <tmNxTypes.h>                    // DVP standard data types/structures#include <tmAvFormats.h>                // Rectangles, video formats, etc.#include <tmStdLib.h>                   // DVP standard 'C' library header file//-----------------------------------------------------------------------------// Project include files://-----------------------------------------------------------------------------//#include <tmdlIic.h>                    // IIC device library API#include "tmbsl7113local.h"             // Video In board support library hdr//-----------------------------------------------------------------------------// Types and defines://-----------------------------------------------------------------------------////-----------------------------------------------------------------------------// Global data://-----------------------------------------------------------------------------////-----------------------------------------------------------------------------// Function Prototypes://-----------------------------------------------------------------------------//static tmErrorCode_t  mapAdapterInput (    decoderStruct_t*           pVD,     tmVideoAnalogAdapter_t  adapterType,     UInt32                  adapterIndex,    UInt8                   *mode    );static tmErrorCode_t  getAdapterInput (    decoderStruct_t*           pVD,     tmVideoAnalogAdapter_t  *adapterType,     UInt32                  *adapterIndex,    UInt8                   mode    );static UInt32 microsleep(UInt32 usec);static Bool                         // Successful or not SetReg(                             // Set a register value     decoderStruct_t* pVD,           // Pointer to I2C access structure     UInt8 bReg,                     // Subaddress of the register     UInt8 bData);                   // Value to be written static Bool                         // Successful or not GetReg(                             // Get a register value     decoderStruct_t* pVD,           // Pointer to I2C access structure     UInt8 bReg,                     // Subaddress of the register     UInt8 * pbData);                // Pointer to variable to recieve value static tmErrorCode_t setRegArray (    decoderStruct_t* pVD,           // Pointer to I2C access structure     UInt8           *pData,    UInt32          dataSize);//-----------------------------------------------------------------------------// Exported functions://-----------------------------------------------------------------------------////-----------------------------------------------------------------------------//// FUNCTION:    tmbsl7113Init://// DESCRIPTION: //// RETURN:      tmErrorCode_t for success or error//// NOTES:       NONE////-----------------------------------------------------------------------------tmErrorCode_t   tmbsl7113Init (    tmUnitSelect_t   aviUnit,           //  I: AVI Unit number    ptmbslAvi_t      pDec,              //  I: ptr to video decoder    ptmbslAviParam_t params             //  I: Video modes, etc    ){    UInt32              i           = 0;    tmErrorCode_t       rval        = TM_OK;    UInt32              inputMode   = 0;       tmInstance_t        tmIicInstance;    decoderStruct_t*    pVD         = Null;                if( aviUnit >= SAA7113_MAX_UNITS )    {        return TMBSL_ERR_AVI_BAD_UNIT_NUMBER;    }    pVD   = &(gDecInstance[aviUnit]);    // return if already initialized    if( pVD->init == True )    {        //We do want to re-initialize some capabilities and configuration        //return TM_OK;    }        // If this is the first init call for this unit perform initial steps        // save capabilities and configuration for this unit    pVD->config.gpioFirstPin   = pDec->gpioFirstPin;     pVD->config.gpioLastPin    = pDec->gpioLastPin;     pVD->config.i2cUnit        = pDec->i2cUnit;     pVD->config.slaveAddr      = pDec->slaveAddr;     pVD->config.capFlags       = pDec->capFlags;     pVD->config.outputFormats  = pDec->outputFormats;     pVD->config.standards      = pDec->standards;     pVD->config.adapters       = pDec->adapters;     pVD->config.numAdapters    = pDec->numAdapters;     pVD->config.adapterTable   = pDec->adapterTable;    // Copy parameters    pVD->curVideoStandard = params->videoStandard;    pVD->curAdapterType   = params->adapterType;    pVD->curAdapterIndex  = params->adapterIndex;    if (! ( (params->videoStandard == vasNone)         || (params->videoStandard & (vasNTSC | vasPAL | vasSECAM))) )    {        return TMBSL_ERR_AVI_NOT_SUPPORTED;    }    // We only want to open this once    if( pVD->init != True )    {        // Open I2C device for initial setup         if( (rval = tmdlIicOpenM( &tmIicInstance,                                 pVD->config.i2cUnit )) == TM_OK )        {            pVD->iicInstance = tmIicInstance;        }        else        {            return rval;        }    }    // Setup default setting in SAA7113     setRegArray(pVD, saa7113_defRegs, sizeof(saa7113_defRegs));    if (lastI2cError != TM_OK)    {        return lastI2cError;    }    if (! ( (params->adapterType == vaaNone)         || (params->adapterType & (vaaCVBS | vaaSvideo))) )    {        tmdlIicClose( pVD->iicInstance );        return TMBSL_ERR_AVI_NOT_SUPPORTED;    }    pVD->init = True;    // Set video standard accordingly     if ((rval = tmbsl7113SetStandard (aviUnit, pVD->curVideoStandard)) != TM_OK)    {        tmdlIicClose (pVD->iicInstance);        return rval;    }    // Set input of video accordingly     rval = tmbsl7113SetAnalogInput (                    aviUnit,                     pVD->curAdapterType,                     pVD->curAdapterIndex );    return  rval;}//-----------------------------------------------------------------------------//// FUNCTION:    tmbsl7113Deinit://// DESCRIPTION: //// RETURN:      tmErrorCode_t for success or error//// NOTES:       NONE////-----------------------------------------------------------------------------tmErrorCode_t   tmbsl7113Deinit (    tmUnitSelect_t   aviUnit            //  I: AVI Unit number    ){    tmErrorCode_t       tmRetVal = TM_OK;    decoderStruct_t*    pVD         = Null;                if ( aviUnit >= SAA7113_MAX_UNITS )    {        return TMBSL_ERR_AVI_BAD_UNIT_NUMBER;    }    if ( gDecInstance[aviUnit].init != True )    {        return TMBSL_ERR_AVI_NOT_INITIALIZED;    }    pVD   = &(gDecInstance[aviUnit]);    tmRetVal = tmdlIicClose( pVD->iicInstance );    gDecInstance[aviUnit].init = False;    return tmRetVal;}//-----------------------------------------------------------------------------//// FUNCTION:    tmbsl7113GetSWVersion://// DESCRIPTION: //// RETURN:      tmErrorCode_t for success or error//// NOTES:       NONE////-----------------------------------------------------------------------------tmErrorCode_t   tmbsl7113GetSWVersion (    ptmSWVersion_t     pSWVersion        //  I: Receives SW Version     ){    pSWVersion->compatibilityNr = SAA7113_BSL_COMP_NUM;    pSWVersion->majorVersionNr  = SAA7113_BSL_MAJOR_VER;    pSWVersion->minorVersionNr  = SAA7113_BSL_MINOR_VER;    return TM_OK;}//-----------------------------------------------------------------------------//// FUNCTION:    tmbsl7113GetPowerState://// DESCRIPTION: Get the power state of this device.//// RETURN:      tmErrorCode_t for success or error//// NOTES:////-----------------------------------------------------------------------------tmErrorCode_ttmbsl7113GetPowerState (    tmUnitSelect_t      aviUnit,        //  I: AVI Unit number    ptmPowerState_t     pPowerState     //  O: Power state of this device){    tmErrorCode_t       tmRetVal = TM_OK;    // TODO: Implementation    if( aviUnit >= SAA7113_MAX_UNITS )    {        return TMBSL_ERR_AVI_BAD_UNIT_NUMBER;    }    if( gDecInstance[aviUnit].init != True )    {        return TMBSL_ERR_AVI_NOT_INITIALIZED;    }    *pPowerState = gDecInstance[aviUnit].curPowerState;    return tmRetVal;}//-----------------------------------------------------------------------------//// FUNCTION:    tmbsl7113SetPowerState://// DESCRIPTION: Set the power state of this device.//// RETURN:      tmErrorCode_t for success or error//// NOTES:////-----------------------------------------------------------------------------tmErrorCode_ttmbsl7113SetPowerState (    tmUnitSelect_t      aviUnit,        //  I: AVI Unit number    tmPowerState_t      powerState      //  I: Power state of this device){    tmErrorCode_t       tmRetVal = TM_OK;    // TODO: Implementation    if( aviUnit >= SAA7113_MAX_UNITS )    {        return TMBSL_ERR_AVI_BAD_UNIT_NUMBER;    }    if( gDecInstance[aviUnit].init != True )    {        return TMBSL_ERR_AVI_NOT_INITIALIZED;    }        gDecInstance[aviUnit].curPowerState = powerState;    return tmRetVal;}//-----------------------------------------------------------------------------//// FUNCTION:    tmbsl7113DisableDecoder://// DESCRIPTION: disables decoder if applicable //// RETURN:      tmErrorCode_t for success or error//// NOTES:       NONE////-----------------------------------------------------------------------------tmErrorCode_t   tmbsl7113DisableDecoder (    tmUnitSelect_t     aviUnit,          //  I: AVI Unit number    Bool               disable           //  I: set True to disable decoder    ){    /* Counterpart to Video DecHAL VideoDecEnableDecoder */    UInt8 ucValue;    decoderStruct_t*    pVD         = Null;                if ( aviUnit >= SAA7113_MAX_UNITS )    {        return TMBSL_ERR_AVI_BAD_UNIT_NUMBER;    }    if ( gDecInstance[aviUnit].init != True )    {        return TMBSL_ERR_AVI_NOT_INITIALIZED;    }    pVD   = &(gDecInstance[aviUnit]);    if (!GetReg(pVD, OutputControl1, &ucValue))        /* Check only first access */        return lastI2cError;    SetReg(pVD, OutputControl1, (UInt8)((ucValue & ~0x0c) | (disable ? 0x00 : 0x0c)));    return TM_OK;}//-----------------------------------------------------------------------------//// FUNCTION:    tmbsl7113SetStandard://// DESCRIPTION: Set the video analog standard //// RETURN:      tmErrorCode_t for success or error//// NOTES:       NONE////-----------------------------------------------------------------------------tmErrorCode_t   tmbsl7113SetStandard (    tmUnitSelect_t          aviUnit,    //  I: AVI Unit number    tmVideoAnalogStandard_t standard    //  I: new video standard    ){     UInt8 ucVal;    decoderStruct_t*    pVD         = Null;                if ( aviUnit >= SAA7113_MAX_UNITS )    {        return TMBSL_ERR_AVI_BAD_UNIT_NUMBER;    }    if ( gDecInstance[aviUnit].init != True )    {        return TMBSL_ERR_AVI_NOT_INITIALIZED;    }    pVD   = &(gDecInstance[aviUnit]);                                                  // Only check first access     if (GetReg(pVD, ChromaControl, &ucVal))      // Read old value     {        ucVal &= ~0x73;                          // Delete video standard bits; 

⌨️ 快捷键说明

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