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

📄 deccontrol.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.
******************************************************************************/
/****************************************************************************/
/* deccontrol.c                                                             */
/*                                                                          */
/* deccontrol: Implements control functions to interface video decoder      */
/*             driver to datapath state machine                             */
/****************************************************************************/

#include "common.h"
#include "ddp2230_rtos_include.h"
#include "tmr.h"
#include "src.h"

#include "datapath.h"
#include "deccontrol.h"
#include "tvp5146.h"
#include "global.h"

/****************************************************************************/
/* Local constants and declarations.                                        */
/****************************************************************************/

#ifdef __DEC_TVP5146
    #define DEC_I2C_ADDR             0xB8
#endif

                        /****************************************************/
                        /* Local variables.                                 */
                        /****************************************************/
static VideoStdTypeEnum detectedStandard = 0xFF;
static uint08 deccount=0;

void deccontrol_powerNormal( void )
{
    // kludge i2c init
    DEC_Init( DEC_I2C_ADDR, gpConfiguration->Datapath.FrontEndDevicesI2CPort );
    DEC_SetPowerLevel( ACTIVE );
    DEC_DisableOutput();
}

void deccontrol_powerStandby( void )
{
    // kludge i2c init
    DEC_Init( DEC_I2C_ADDR, gpConfiguration->Datapath.FrontEndDevicesI2CPort );
    DEC_SetPowerLevel( CLOCK_EIGHTH );
}

/****************************************************************************/
/* Video decoder initialization.                                            */
/****************************************************************************/

void deccontrol_ConfigureForSearch( DP_CONNECTOR datapathConnector )
{
    SRC_PORT_CFG port_config;
    SRC_CHANNEL_CFG src_chan_cfg;
    
                                                    /************************/
                                                    /* configure port       */
                                                    /************************/
    port_config.PortWidth = SRC_08_BITS;
    port_config.ABC_Mux = SRC_ABC_STRAIGHT_THRU;
    port_config.DataEnableSource = SRC_PORT1;   /* Data Bit 10 pin location */

    SRC_SetPortConfiguration( SRC_PORT3, &port_config );

                                                    /************************/
                                                    /* configure channel    */
                                                    /************************/
    src_chan_cfg.SyncPort = SRC_PORT3;
    SRC_SetChannelConfiguration( SRC_PRIMARY, &src_chan_cfg );                                          

                                                    /************************/
                                                    /* device init          */
                                                    /************************/
    DEC_Init( DEC_I2C_ADDR, gpConfiguration->Datapath.FrontEndDevicesI2CPort );
    DEC_InitCommon( );
    
    DEC_EnableOutput();
    /* Wait for 1 frame after change */
	RTA_TaskDelay(TMR_ConvertMSToTicks(20));
			
	/* turn off Auto standard prior to selecting the new connector */
	DEC_EnableAutoStandard(AS_NONE);
	
	switch( datapathConnector )
	{
		case SVIDEO:
			DEC_SelectSVideo( );
			break;
		case COMPOSITE:
			DEC_SelectComposite( );
			break;
        case COMPONENT:
			DEC_SelectComponent( );
			break;
		default:
		    return;
	}
	
	DEC_SetStandard(AUTO);
	
	deccount = 0;
	detectedStandard = 0xFF;
}

uint16 deccontrol_Poll( DP_STATE datapathState )
{
    BOOL syncsDetected;
    VideoStdTypeEnum newStandard;
    
    switch( datapathState )
    {  
    case LOOK_FOR_SYNCS:
                  /* wait 300 ms after initialization before reading status */
        if( datapath_TimeElapsedInState() < 300 )
            break;
    
        if( DEC_IsSignalPresent( &syncsDetected ) != PASS )
            break;
    
        if( syncsDetected )
        {
            deccount++;
        }
        else
        {
            deccount = 0;
        }

        if( deccount > 2 )
        {
            deccount = 0;
            return DPMSG_STATE_SYNCSDETECTED;
        }        
        break;
    
    case ATTEMPT_LOCK:
        if( DEC_GetStandard( &newStandard ) != PASS )
            break;

        if( detectedStandard == newStandard )
        {
            deccount++;
        }
        else
        {
            deccount = 0;
            detectedStandard = newStandard;
        }
        
        if( deccount > 1 )
        {
            deccount = 0;
            return DPMSG_STATE_LOCKED;
        }
        break;
        
    case MONITOR_SOURCE:
        if( DEC_IsSignalPresent( &syncsDetected ) != PASS )
            break; 

        if( DEC_GetStandard( &newStandard ) != PASS )
            break;
        
        if( !syncsDetected || detectedStandard != newStandard )
        {
            deccount++;
        }
        else
        {
            deccount = 0;
        }
        
        if( deccount > 3 )
        {
            if( !syncsDetected )
                return DPMSG_STATE_LOSTLOCK;
            else
                return DPMSG_STATE_REACQUIRE;
        }
        break;
    
    case SPLASH_AT_STARTUP:
    case SUSPENDED:
    case BEGIN_SCAN:
    default:
        /* do nothing */
        break;
    }
    
    return DPMSG_NONE;
}

int08 deccontrol_FillSourceConfig( DP_SOURCEDESC *srcDesc, SRC_SOURCE_CONFIG *srcConfig )
{
    if ((detectedStandard == NTSC) || (detectedStandard == NTSC443) || (detectedStandard == PALM) || (detectedStandard == PAL60))
    {
        srcConfig->VSyncCfg = SRC_PORT_SYNC_NOINV;
        srcConfig->HSyncCfg = SRC_PORT_SYNC_NOINV;
        srcConfig->TopField = SRC_PORT_SYNC_INV;
        srcConfig->DownSampleCfg = SRC_NO_DOWNSAMPLE;
        srcConfig->IsClockPolarityPositive = TRUE;
        srcConfig->Is422 = TRUE;
        srcConfig->IsRGB = FALSE;
        srcConfig->IsExternalDE = TRUE;
        srcConfig->IsInterlaced = TRUE;
        srcConfig->IsOffsetBinary = TRUE;
        srcConfig->IsTopFieldInvertedAtScaler = FALSE;

        srcConfig->TotalArea.PixelsPerLine = 858;
        srcConfig->TotalArea.LinesPerFrame = 263;  //lines per field (rounded up)
        
        srcConfig->ActiveArea.FirstPixel = 5;
        srcConfig->ActiveArea.FirstLine = 21;
        srcConfig->ActiveArea.PixelsPerLine = 720;
        srcConfig->ActiveArea.LinesPerFrame = 240;
         
        srcConfig->BottomFieldFirstLine = 21;
        srcConfig->PixelClockFreqInkHz = 27000;

        srcConfig->ColorSpaceConvCoeffs[0] = 1024;
        srcConfig->ColorSpaceConvCoeffs[1] = 7461;
        srcConfig->ColorSpaceConvCoeffs[2] = 7839;
        srcConfig->ColorSpaceConvCoeffs[3] = 1024;
        srcConfig->ColorSpaceConvCoeffs[4] = 1436;
        srcConfig->ColorSpaceConvCoeffs[5] = 0;
        srcConfig->ColorSpaceConvCoeffs[6] = 1024;
        srcConfig->ColorSpaceConvCoeffs[7] = 0;
        srcConfig->ColorSpaceConvCoeffs[8] = 1814;

        srcConfig->Offset[0] = 0;
        srcConfig->Offset[1] = 0;
        srcConfig->Offset[2] = 0;
        
        srcDesc->sourceActive = TRUE;
        srcDesc->port = SRC_PORT3;
        srcDesc->okToDeinterlace = TRUE;
        srcDesc->inputWidth = srcConfig->ActiveArea.PixelsPerLine;
        srcDesc->inputHeight = srcConfig->ActiveArea.LinesPerFrame * 2; /* 2x because we'll deinterlace this */
        srcDesc->nativeWidth = 640;
        srcDesc->nativeHeight = 480;
        srcDesc->isVideo = TRUE;
        srcDesc->isHighDefinitionVideo = FALSE;
        srcDesc->inputFrameRate = 60.0f;
        srcDesc->isYUV = TRUE;
    }
    else if((detectedStandard == PAL) || (detectedStandard == PALN) || (detectedStandard == SECAM)) 
    {  
        srcConfig->VSyncCfg = SRC_PORT_SYNC_NOINV;
        srcConfig->HSyncCfg = SRC_PORT_SYNC_NOINV;
        srcConfig->TopField = SRC_PORT_SYNC_INV;
        srcConfig->DownSampleCfg = SRC_NO_DOWNSAMPLE;
        srcConfig->IsClockPolarityPositive = TRUE;
        srcConfig->Is422 = TRUE;
        srcConfig->IsRGB = FALSE;
        srcConfig->IsExternalDE = TRUE;
        srcConfig->IsInterlaced = TRUE;
        srcConfig->IsOffsetBinary = TRUE;
        srcConfig->IsTopFieldInvertedAtScaler = FALSE;

        srcConfig->TotalArea.PixelsPerLine = 864;
        srcConfig->TotalArea.LinesPerFrame = 313;  //lines per field (rounded up)
        
        srcConfig->ActiveArea.FirstPixel = 5;
        srcConfig->ActiveArea.FirstLine = 25;
        srcConfig->ActiveArea.PixelsPerLine = 720;
        srcConfig->ActiveArea.LinesPerFrame = 287;
      
        srcConfig->BottomFieldFirstLine = 24;
        srcConfig->PixelClockFreqInkHz = 27000;

        srcConfig->ColorSpaceConvCoeffs[0] = 1024;
        srcConfig->ColorSpaceConvCoeffs[1] = 7461;
        srcConfig->ColorSpaceConvCoeffs[2] = 7839;
        srcConfig->ColorSpaceConvCoeffs[3] = 1024;
        srcConfig->ColorSpaceConvCoeffs[4] = 1436;
        srcConfig->ColorSpaceConvCoeffs[5] = 0;
        srcConfig->ColorSpaceConvCoeffs[6] = 1024;
        srcConfig->ColorSpaceConvCoeffs[7] = 0;
        srcConfig->ColorSpaceConvCoeffs[8] = 1814;

        srcConfig->Offset[0] = 0;
        srcConfig->Offset[1] = 0;
        srcConfig->Offset[2] = 0;
        
        srcDesc->sourceActive = TRUE;
        srcDesc->port = SRC_PORT3;
        srcDesc->okToDeinterlace = TRUE;
        srcDesc->inputWidth = srcConfig->ActiveArea.PixelsPerLine;
        srcDesc->inputHeight = srcConfig->ActiveArea.LinesPerFrame * 2; /* 2x because we'll deinterlace this */
        srcDesc->nativeWidth = 768;
        srcDesc->nativeHeight = 576;
        srcDesc->isVideo = TRUE;
        srcDesc->isHighDefinitionVideo = FALSE;
        srcDesc->inputFrameRate = 50.0f;
        srcDesc->isYUV = TRUE;
    }
    else
    {
        srcDesc->sourceActive = FALSE;
    }
    
    return PASS;
}

void deccontrol_StopCurrentOperation( void )
{
    DEC_DisableOutput();
}

/* set video standard based on index of supported standards in OSD design */
/* 0 = auto, 1 = NTSC, 2 = PAL, 3 = SECAM */
int08 deccontrol_SetVideoStandard( uint08 index )
{ 
    switch (index)
    {
        case 0:
            if ( DEC_SetStandard( AUTO ) != PASS )
            {
                return FAIL;
            }
            break;
            
        case 1:
            if ( DEC_SetStandard( NTSC ) != PASS )
            {
                return FAIL;
            }
            break;
            
        case 2:
            if ( DEC_SetStandard( PAL ) != PASS )
            {
                return FAIL;
            }
            break;
            
        case 3:
            if ( DEC_SetStandard( SECAM ) != PASS )
            {
                return FAIL;
            }
            break;
        default:
            return FAIL;
    }
    return PASS;
}
            
            
/* get video standard based on index of supported standards in OSD design */
/* 0 = auto, 1 = NTSC, 2 = PAL, 3 = SECAM */
int08 deccontrol_GetVideoStandard( uint08 *index )
{ 
    VideoStdTypeEnum standard;
    
    if ( DEC_GetStandard( &standard ) == PASS )
    {
	    switch (standard)
	    {
	        case AUTO:
	            *index = 0;
	            break;

	        case NTSC:
	            *index = 1;
	            break;
	            
	        case PAL:
	            *index = 2;
	            break;
	            
	        case SECAM:
	            *index = 3;
	            break;
	            
	        default:
	            return FAIL;
	    }
	}
	else
	    return FAIL;
	    
    return PASS;
}
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            

⌨️ 快捷键说明

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