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

📄 adccontrol.c

📁 IT projecotr reference design.
💻 C
📖 第 1 页 / 共 3 页
字号:
            }
        }
    }
#endif

          /* The AutoLock callback drives state changes -- there is no need */
                                         /* to implement a polling function */
    return DPMSG_NONE;
}

int08 adccontrol_FillSourceConfig( DP_SOURCEDESC *srcDesc, SRC_SOURCE_CONFIG *srcConfig )
{
    ALC_StatusStruct alc_stat;
    
    ALC_GetStatus(&alc_stat);
    
    if( alc_stat.ASMStatus != ALC_ALG_STATUS_AUTOLOCKED && alc_stat.ASMStatus != ALC_ALG_STATUS_PROCESSING )
    {
              /* allow ALC_ALG_STATUS_PROCESSING for phase callback support */
        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 = !alc_stat.ASMIsYUV;
    srcConfig->IsExternalDE = FALSE;
    srcConfig->IsInterlaced = alc_stat.PortIsInterlaced;
    srcConfig->IsOffsetBinary = TRUE;
    srcConfig->IsTopFieldInvertedAtScaler = alc_stat.ASMIsTopfieldInverted;

    srcConfig->TotalArea.PixelsPerLine = alc_stat.ASMSampleClock;
    srcConfig->TotalArea.LinesPerFrame = alc_stat.PortLinesPerFrame;
    
    srcConfig->ActiveArea.FirstPixel = alc_stat.ASMActiveLeftPixel;
    srcConfig->ActiveArea.FirstLine = alc_stat.ASMActiveTopLine;
    srcConfig->ActiveArea.PixelsPerLine = alc_stat.ASMActiveRightPixel - alc_stat.ASMActiveLeftPixel + 1;
    srcConfig->ActiveArea.LinesPerFrame = alc_stat.ASMActiveBottomLine - alc_stat.ASMActiveTopLine + 1;
    
    srcConfig->BottomFieldFirstLine = srcConfig->ActiveArea.FirstLine;
    srcConfig->PixelClockFreqInkHz = alc_stat.ASMSampleClockFreqInkHz;
          
    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 (!alc_stat.ASMIsPortSyncs)
    {
        srcConfig->VSyncCfg = SRC_ALF_SYNC;
        srcConfig->HSyncCfg = SRC_ALF_SYNC;
        srcConfig->TopField = SRC_ALF_SYNC;
        srcConfig->IsInterlaced = alc_stat.RawIsInterlaced;    
        srcConfig->TotalArea.LinesPerFrame = alc_stat.RawLinesPerFrame;        
    }
    
    if ( srcConfig->IsInterlaced &&
         (( srcConfig->ActiveArea.LinesPerFrame >= 230 && srcConfig->ActiveArea.LinesPerFrame <= 250 ) ||  /* 480i */
          ( srcConfig->ActiveArea.LinesPerFrame >= 274 && srcConfig->ActiveArea.LinesPerFrame <= 294 ) ) /* 576i */
       )
    {
        /* AutoLock double-samples interlaced sources to get 2x pixel clock for DEI */
        srcConfig->DownSampleCfg = SRC_DOWNSAMPLE_FIRST_PXL;
        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( alc_stat.ASMIsSubSampled )
        srcDesc->nativeWidth = alc_stat.ASMHRes;
    else
        srcDesc->nativeWidth = srcConfig->ActiveArea.PixelsPerLine;
        
    if( srcConfig->IsInterlaced )
        srcDesc->nativeHeight = srcConfig->ActiveArea.LinesPerFrame * 2;
    else
        srcDesc->nativeHeight = srcConfig->ActiveArea.LinesPerFrame;
    
    srcDesc->isVideo = alc_stat.ASMIsComponentVideo | alc_stat.ASMIsHDTV;
    srcDesc->isHighDefinitionVideo = alc_stat.ASMIsHDTV;
    srcDesc->inputFrameRate = ((float)alc_stat.PortVertFreq)/100.0f;
    
    if (!alc_stat.ASMIsPortSyncs)
    {
        srcDesc->inputFrameRate = ((float)alc_stat.RawVertFreq)/100.0f;
    }
    
    ALC_GetGain( &srcDesc->alcGain ); 
    ALC_GetOffset( &srcDesc->alcOffset );
    tracking = 0;
    srcDesc->alcSampleClock = srcConfig->TotalArea.PixelsPerLine;
    horizontalPosition = 0;
    srcDesc->alcLeftPixel = srcConfig->ActiveArea.FirstPixel;
    verticalPosition = 0;
    srcDesc->alcTopLine = srcConfig->ActiveArea.FirstLine;    
    
    srcDesc->isYUV = alc_stat.ASMIsYUV;

    return PASS;
}

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


/****************************************************************************/
/* Phase user controls                                                      */
/****************************************************************************/

int08 adccontrol_GetPhaseLimits( int08 *min, int08 *max )
{
    ALC_LimitStruct limits;

    if( ALC_GetPhaseLimits( &limits ) != PASS )
        return FAIL;

    *min = limits.LowerLimit;
    *max = limits.UpperLimit;

    return PASS;
}

int08 adccontrol_GetPhase( int08 *phase )
{
    if( ALC_GetPhase( (uint08*) phase ) != PASS )
        return FAIL;
    return PASS;
}

int08 adccontrol_SetPhase( int08 phase )
{
    if( ALC_SetPhase( (uint08) phase ) != PASS )
        return FAIL;
    return PASS;
}

/****************************************************************************/
/* Tracking user controls                                                   */
/****************************************************************************/

int08 adccontrol_GetTrackingLimits( int08 *min, int08 *max )
{
    *min = -5;
    *max = 5;
    return PASS;
}

int08 adccontrol_GetTracking( int08 *track )
{
    *track = tracking;
    return PASS;
}

int08 adccontrol_SetTracking( int08 track )
{
    ALC_StatusStruct alc_stat;
    SRC_SOURCE_CONFIG src_cfg;
    DP_SOURCEDESC *srcDesc;
    uint16 sampleClock;
    DISP_DISPLAY_CONFIG disp_cfg;
    
    datapath_GetSourceDesc( &srcDesc );
    if( srcDesc->sourceActive == TRUE && srcDesc->connector == VGA )
    {   
        sampleClock = srcDesc->alcSampleClock + track;
        if( srcDesc->okToDeinterlace == TRUE )
        {
            sampleClock *= 2;                /* account for double sampling */
        }
        
        if( ALC_SetSampleClock( sampleClock ) != PASS )
        {
            return FAIL;
        }
        
                             /* Read AutoLock status to get new pixel clock */
        ALC_GetStatus(&alc_stat);
        SRC_GetSourceConfiguration( SRC_PORT1, &src_cfg );
        
        src_cfg.PixelClockFreqInkHz = alc_stat.ASMSampleClockFreqInkHz;
        src_cfg.TotalArea.PixelsPerLine = srcDesc->alcSampleClock + track;

        if( SRC_SetSourceConfiguration( SRC_PORT1, &src_cfg ) < PASS )
        {
            sampleClock = srcDesc->alcSampleClock + tracking;
            if( srcDesc->okToDeinterlace == TRUE )
            {
                sampleClock *= 2;            /* account for double sampling */
            }
            ALC_SetSampleClock( sampleClock );
            return FAIL;
        }
        
        tracking = track;
        DISP_GetDisplay( SRC_PRIMARY, &disp_cfg ); 
        DISP_SetDisplay( SRC_PRIMARY, disp_cfg ); 
        return PASS;
    }
    return FAIL;
}

/****************************************************************************/
/* Horizontal Position (framing) user controls                              */
/****************************************************************************/

int08 adccontrol_GetHorizontalPositionLimits( int08 *min, int08 *max )
{
    SRC_SOURCE_CONFIG src_cfg;
    DP_SOURCEDESC *srcDesc;
    
    datapath_GetSourceDesc( &srcDesc );
    SRC_GetSourceConfiguration( SRC_PORT1, &src_cfg );

    *min = MAX( -5, -1*srcDesc->alcLeftPixel + 10 );
    *max = MIN( src_cfg.TotalArea.PixelsPerLine - src_cfg.ActiveArea.PixelsPerLine - srcDesc->alcLeftPixel - 1, 5 );

    return PASS;
}

int08 adccontrol_GetHorizontalPosition( int08 *hpos )
{
    *hpos = horizontalPosition;
    return PASS;
}

int08 adccontrol_SetHorizontalPosition( int08 hpos )
{
    SRC_SOURCE_CONFIG src_cfg;
    DP_SOURCEDESC *srcDesc;
    DISP_DISPLAY_CONFIG disp_cfg;
    
    datapath_GetSourceDesc( &srcDesc );
    if( srcDesc->sourceActive == TRUE && srcDesc->connector == VGA )
    {  
        SRC_GetSourceConfiguration( SRC_PORT1, &src_cfg );
        src_cfg.ActiveArea.FirstPixel = srcDesc->alcLeftPixel + hpos;
        if( SRC_SetSourceConfiguration( SRC_PORT1, &src_cfg ) < PASS )
        {
            return FAIL;
        }
        horizontalPosition = hpos;
        DISP_GetDisplay( SRC_PRIMARY, &disp_cfg ); 
        DISP_SetDisplay( SRC_PRIMARY, disp_cfg ); 
        return PASS;
    }
    return FAIL;
}

/****************************************************************************/
/* Vertical Position (framing) user controls                                */
/****************************************************************************/

int08 adccontrol_GetVerticalPositionLimits( int08 *min, int08 *max )
{
    SRC_SOURCE_CONFIG src_cfg;
    DP_SOURCEDESC *srcDesc;

    datapath_GetSourceDesc( &srcDesc );
    SRC_GetSourceConfiguration( SRC_PORT1, &src_cfg );

    *min = MAX( -5, -1*srcDesc->alcTopLine + 1 );
    *max = MIN( src_cfg.TotalArea.LinesPerFrame - src_cfg.ActiveArea.LinesPerFrame - srcDesc->alcTopLine - 1, 5 );

    return PASS;
}

int08 adccontrol_GetVerticalPosition( int08 *vpos )
{
    *vpos = verticalPosition;
    return PASS;
}

int08 adccontrol_SetVerticalPosition( int08 vpos )
{
    SRC_SOURCE_CONFIG src_cfg;
    DP_SOURCEDESC *srcDesc;
    DISP_DISPLAY_CONFIG disp_cfg;
    
    datapath_GetSourceDesc( &srcDesc );
    if( srcDesc->sourceActive == TRUE && srcDesc->connector == VGA )
    {
        SRC_GetSourceConfiguration( SRC_PORT1, &src_cfg );
        src_cfg.ActiveArea.FirstLine = srcDesc->alcTopLine + vpos;
        src_cfg.BottomFieldFirstLine = src_cfg.ActiveArea.FirstLine;
        if( SRC_SetSourceConfiguration( SRC_PORT1, &src_cfg ) < PASS )
        {
            return FAIL;
        }
        verticalPosition = vpos;
        DISP_GetDisplay( SRC_PRIMARY, &disp_cfg ); 
        DISP_SetDisplay( SRC_PRIMARY, disp_cfg ); 
        return PASS;
    }
    return FAIL;
}

/****************************************************************************/
/* Saved mode table user control                                            */
/****************************************************************************/

void adccontrol_SaveSettingsToSMT( uint08 index )
{
    ALC_StatusStruct alc_stat;
    DP_SOURCEDESC *srcDesc;
    
    ALC_GetStatus(&alc_stat);       /* read AutoLock status */
    datapath_GetSourceDesc( &srcDesc ); /* read source desc */
    
    if( srcDesc->sourceActive != TRUE || srcDesc->connector != VGA || alc_stat.ASMStatus != ALC_ALG_STATUS_AUTOLOCKED )
    {
        return;
    }
    
    userSavedModeTable[index].Flags                 = 0; /* bit1 = rerun framing; bit2 = use stored phase */
    
    userSavedModeTable[index].VsyncPolarity_C       = alc_stat.RawVsyncPolarity;
    userSavedModeTable[index].HsyncPolarity_C       = alc_stat.RawHsyncPolarity;
    userSavedModeTable[index].SyncType_C            = alc_stat.RawSyncType;
    userSavedModeTable[index].Flags_C               = (alc_stat.RawIsInterlaced);  /* bit1 = isInterlaced */
    userSavedModeTable[index].LinesPerFrame_C       = alc_stat.RawLinesPerFrame;
    userSavedModeTable[index].LineTimeInNS_C        = 100000000/alc_stat.RawHorzFreq; /* 10e9 ns * 1/(freq*10 Hz) */
    userSavedModeTable[index].LineTimeInNSMargin_C  = 10;
    userSavedModeTable[index].LinesPerFrameMargin_C = 4;
        
    userSavedModeTable[index].ActiveLeftPixel_R     = alc_stat.ASMActiveLeftPixel;
    userSavedModeTable[index].ActiveRightPixel_R    = alc_stat.ASMActiveRightPixel;
    userSavedModeTable[index].ActiveTopLine_R       = alc_stat.ASMActiveTopLine;
    userSavedModeTable[index].ActiveBottomLine_R    = alc_stat.ASMActiveBottomLine;
    userSavedModeTable[index].NativeHRes_R          = srcDesc->nativeWidth;
    userSavedModeTable[index].ADCSampleClock_R      = alc_stat.ASMSampleClock;
    userSavedModeTable[index].Flags_R               = (alc_stat.ASMIsYUV) | (alc_stat.ASMIsHDTV << 1) | (alc_stat.ASMIsComponentVideo << 2);

⌨️ 快捷键说明

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