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

📄 dvicontrol.c

📁 IT projecotr reference design.
💻 C
字号:
/*****************************************************************************
**             TEXAS INSTRUMENTS PROPRIETARY INFORMATION
**
**  (c) Copyright, Texas Instruments Incorporated, 2006.
**      All Rights Reserved.
**
**  Property of Texas Instruments Incorporated. Restricted Rights -
**  Use, duplication, or disclosure is subject to restrictions set
**  forth in TI's program license agreement and associated documentation.
******************************************************************************/
/****************************************************************************/
/* dvicontrol.c                                                             */
/*                                                                          */
/* dvicontrol: Implements control functions to interface AutoLock ASM and   */
/*             DVI driver to datapath state machine                         */
/****************************************************************************/

#include "common.h"
#include "ddp2230_rtos_include.h"
#include "tmr.h"
#include "src.h"
#include "ddp.h"
#include "i2c.h"
#include "al_alc.h"
#include "adc.h"
#include "gpio.h"

#include "datapath.h"
#include "dvicontrol.h"
#include "global.h"
#include "gpioFunction.h"

#define DIGITAL 1

/* DVI Addresses */
#ifdef __DVI_AD9882
    #define ADC_I2C_ADDR             0x98
    #define ADC_MAX_SAMPLE_FREQ_MHZ  140
    #define ADC_CAP_NANOFARADS       82
#endif

#ifdef __DVI_MST3762MW
    #define ADC_I2C_ADDR             0x9C
    #define ADC_MAX_SAMPLE_FREQ_MHZ  170
    #define ADC_CAP_NANOFARADS       82
#endif

void dvicontrol_powerNormal( void )
{
    ALC_AutoLockDSMCfgStruct alc_dsm_cfg;
    uint08 i;
    
                    /********************************************************/
                    /* adccontrol_powerNormal() handles DVI power up for    */
                    /* devices in reference design, so device init here     */
                    /********************************************************/

                                          /**********************************/
                                          /* One time AutoLock config       */
                                          /**********************************/
    
                                    /* Initialize and disable all callbacks */
    for( i=0; i<ALC_NUMBER_DSM_CALLBACKS; i++ )
        alc_dsm_cfg.DSMCallbacks[i] = NULL;

                                 /* Set AutoLock timeout arbitrarily large, */
                                 /* because application will handle timeout */
    alc_dsm_cfg.VsyncsUntilManual = 2400;    
    
                                             /* write the new configuration */
    ALC_SetAutoLockDSMCfg( &alc_dsm_cfg );
}

void dvicontrol_powerStandby( void )
{
                    /********************************************************/
                    /* adccontrol_powerStandby() handles DVI power down for */
                    /* devices in reference design, so no action here       */
                    /********************************************************/
}

void dvicontrol_ConfigureForSearch( DP_CONNECTOR datapathConnector )
{
    SRC_PORT_CFG port_config;
    SRC_CHANNEL_CFG src_chan_cfg;
    I2CINIT adc_i2c;
    ALC_AutoLockPortCfgStruct alc_port_cfg;
        
                                                    /************************/
                                                    /* configure port       */
                                                    /************************/
#ifdef __DVI_AD9882
    port_config.PortWidth = SRC_30_BITS;
    port_config.ABC_Mux = SRC_ABC_STRAIGHT_THRU;
    port_config.DataEnableSource = SRC_PORT1;
#endif                

#ifdef __DVI_MST3762MW
    port_config.PortWidth = SRC_30_BITS;
    port_config.ABC_Mux = SRC_ABC_ROTATE_LEFT;
    port_config.DataEnableSource = SRC_PORT1;
#endif                

#ifdef __DVI_TFP503
    port_config.PortWidth = SRC_30_BITS;
    port_config.ABC_Mux = SRC_ABC_SWAP_BC;
    port_config.DataEnableSource = SRC_PORT1;
#endif

    SRC_SetPortConfiguration( SRC_PORT1, &port_config );

                                                    /************************/
                                                    /* configure channel    */
                                                    /************************/
    src_chan_cfg.SyncPort = SRC_PORT1;
    SRC_SetChannelConfiguration( SRC_PRIMARY, &src_chan_cfg );                                            
                                                    
                                                    /************************/
                                                    /* device init          */
                                                    /************************/
    adc_i2c.MasterAddressMode = I2C_7BIT;
    adc_i2c.SlaveAddressMode = I2C_7BIT;
    adc_i2c.FilterValue = 15;
    adc_i2c.SCLClockRate = 100000;
    adc_i2c.IntEnable = TRUE;
    
#ifdef __DVI_TFP503
    GPIO_SetPinConfig(GIO_ADC_DVI_TRI, GIOCFG_OUTPUT, FALSE, GIOCFG_ACTIVE );
#else   
    ALC_AutoLockADCInit(gpConfiguration->Datapath.FrontEndDevicesI2CPort, &adc_i2c, 
                        ADC_I2C_ADDR, ADC_MAX_SAMPLE_FREQ_MHZ, ADC_CAP_NANOFARADS  );
                           
    ADC_SetDevicePower( ADC_CHIP_POWER_UP );
                                     /* Set the ADC for single pixel output */
    ADC_SetOutputPortWidth(0);    
    ADC_SetDVIOutputPortWidth(0);
#endif
    
                                                    /************************/
                                                    /* AutoLock Port init   */
                                                    /************************/
    alc_port_cfg.PortCommand = ALC_DVI_OUTPUT;
    alc_port_cfg.VsyncsUntilStable = 10;
    alc_port_cfg.VsyncsUntilUnstable = 10;    
    ALC_SetAutoLockPortCfg(ALC_PORT_1, &alc_port_cfg);    

    alc_port_cfg.PortCommand = ALC_DISABLE;
    alc_port_cfg.VsyncsUntilStable = 10;
    alc_port_cfg.VsyncsUntilUnstable = 10;    
    ALC_SetAutoLockPortCfg(ALC_PORT_2, &alc_port_cfg);    

    alc_port_cfg.PortCommand = ALC_DISABLE;
    alc_port_cfg.VsyncsUntilStable = 10;
    alc_port_cfg.VsyncsUntilUnstable = 10;    
    ALC_SetAutoLockPortCfg(ALC_PORT_3, &alc_port_cfg);
    
#ifndef __DVI_TFP503
    ADC_SetActiveInterfaceMode(ADC_MANUAL_IF_SELECT);
    ADC_SetActiveInterface(DIGITAL);
#endif
          
    ALC_AutoLockAlgorithmControl(ALC_ALG_CTL_START);
}

uint16 dvicontrol_Poll( DP_STATE datapathState )
{
          /* The AutoLock callback drives state changes -- there is no need */
                                         /* to implement a polling function */
    return DPMSG_NONE;
}

int08 dvicontrol_FillSourceConfig( DP_SOURCEDESC *srcDesc, SRC_SOURCE_CONFIG *srcConfig )
{
    ALC_StatusStruct alc_stat;
    uint16 first_pixel, first_line;
    
    ALC_GetStatus(&alc_stat);
    
    if( alc_stat.DSMStatus != ALC_ALG_STATUS_AUTOLOCKED )
    {
        srcDesc->sourceActive = FALSE;
        return FAIL;
    }
    
    SRC_GetSourceConfiguration( SRC_PORT1, srcConfig );

    srcConfig->VSyncCfg = SRC_PORT_SYNC_NOINV;
    srcConfig->HSyncCfg = SRC_PORT_SYNC_NOINV;
    srcConfig->TopField = SRC_DECODED_SYNC;   
    srcConfig->DownSampleCfg = SRC_NO_DOWNSAMPLE;
    srcConfig->IsClockPolarityPositive = TRUE;
    srcConfig->Is422 = FALSE;
    srcConfig->IsRGB = TRUE;
    srcConfig->IsExternalDE = TRUE;
    srcConfig->IsInterlaced = alc_stat.PortIsInterlaced;  
    srcConfig->IsOffsetBinary = FALSE;
    srcConfig->IsTopFieldInvertedAtScaler = TRUE;

    srcConfig->TotalArea.PixelsPerLine = alc_stat.DSMPixelsPerLine;
    srcConfig->TotalArea.LinesPerFrame = alc_stat.PortLinesPerFrame;
    
    ALC_GetFirstPixelAndFirstLine( &first_pixel, &first_line );
    
    srcConfig->ActiveArea.FirstPixel = first_pixel;
    srcConfig->ActiveArea.FirstLine = first_line;
    srcConfig->ActiveArea.PixelsPerLine = alc_stat.DSMHRes;
    srcConfig->ActiveArea.LinesPerFrame = alc_stat.DSMVRes;
    
    srcConfig->BottomFieldFirstLine = srcConfig->ActiveArea.FirstLine - 1;
    srcConfig->PixelClockFreqInkHz = alc_stat.DSMPixelFreqInkHz;

    srcConfig->ColorSpaceConvCoeffs[0] = 1024;
    srcConfig->ColorSpaceConvCoeffs[1] = 0;
    srcConfig->ColorSpaceConvCoeffs[2] = 0;
    srcConfig->ColorSpaceConvCoeffs[3] = 0;
    srcConfig->ColorSpaceConvCoeffs[4] = 1024;
    srcConfig->ColorSpaceConvCoeffs[5] = 0;
    srcConfig->ColorSpaceConvCoeffs[6] = 0;
    srcConfig->ColorSpaceConvCoeffs[7] = 0;
    srcConfig->ColorSpaceConvCoeffs[8] = 1024;
    
    srcConfig->Offset[0] = 0;
    srcConfig->Offset[1] = 0;
    srcConfig->Offset[2] = 0;
    
    if ( srcConfig->IsInterlaced &&
         (( srcConfig->ActiveArea.LinesPerFrame >= 230 && srcConfig->ActiveArea.LinesPerFrame <= 250 ) ||  /* 480i */
          ( srcConfig->ActiveArea.LinesPerFrame >= 274 && srcConfig->ActiveArea.LinesPerFrame <= 294 ) ) /* 576i */
       )
    {
        /* the DVI standard specifies that 480i and 576i come in double sampled, so we must downsample */
        srcConfig->DownSampleCfg = SRC_DOWNSAMPLE_FIRST_PXL;
        srcConfig->ActiveArea.FirstPixel /= 2;
        srcConfig->ActiveArea.PixelsPerLine /= 2;
        srcConfig->TotalArea.PixelsPerLine /= 2;
        srcConfig->PixelClockFreqInkHz /= 2;

        srcDesc->okToDeinterlace = TRUE;
        srcDesc->inputWidth = srcConfig->ActiveArea.PixelsPerLine;
        srcDesc->inputHeight = srcConfig->ActiveArea.LinesPerFrame * 2; /* 2x because we'll deinterlace this */
    }
    else
    {
        srcDesc->okToDeinterlace = FALSE;
        srcDesc->inputWidth = srcConfig->ActiveArea.PixelsPerLine;
        srcDesc->inputHeight = srcConfig->ActiveArea.LinesPerFrame;
    }
    
    srcDesc->sourceActive = TRUE;
    srcDesc->port = SRC_PORT1;

    if( srcConfig->IsInterlaced && srcDesc->okToDeinterlace == FALSE )
    {
        srcDesc->nativeWidth = srcDesc->inputWidth;
        srcDesc->nativeHeight = srcConfig->ActiveArea.LinesPerFrame * 2;
    }
    else
    {
        srcDesc->nativeWidth = srcDesc->inputWidth;
        srcDesc->nativeHeight = srcDesc->inputHeight;
    }
    
    srcDesc->isVideo = FALSE; /* assume we do not need any video algorithms for digital sources */
    srcDesc->isHighDefinitionVideo = FALSE;
    srcDesc->inputFrameRate = ((float)alc_stat.PortVertFreq)/100.0f;
    srcDesc->isYUV = FALSE;
    return PASS;
}

void dvicontrol_StopCurrentOperation( void )
{
    ALC_AutoLockAlgorithmControl(ALC_ALG_CTL_STOP);
}

⌨️ 快捷键说明

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