📄 adccontrol.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.
******************************************************************************/
/****************************************************************************/
/* adccontrol.c */
/* */
/* adccontrol: Implements control functions to interface AutoLock ASM and */
/* ADC 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 "gpio.h"
#include "dbmessage.h"
#include "gpio.h"
#include "disp.h"
#ifdef __ADC_TVP7001
#include "tvp7001.h"
#endif
#ifdef __ADC_TVP7002
#include "tvp7002.h"
#endif
#ifdef __ADC_MST3762MW
#include "adc.h"
#include "te8200pf.h"
#endif
#if !defined(__ADC_TVP7001) && !defined(__ADC_TVP7002) && !defined(__ADC_MST3762MW)
#include "adc.h"
#endif
#include "datapath.h"
#include "adccontrol.h"
#include "global.h"
#include "gpioFunction.h"
#include "eeprom.h"
#include "app_cfg.h"
#define ANALOG 0
/* ADC Addresses */
#ifdef __ADC_AD9882
#define ADC_I2C_ADDR 0x98
#define ADC_MAX_SAMPLE_FREQ_MHZ 140
#define ADC_CAP_NANOFARADS 82
#endif
#ifdef __ADC_MST3762MW
#define ADC_I2C_ADDR 0x9C
#define ADC_MAX_SAMPLE_FREQ_MHZ 170
#define ADC_CAP_NANOFARADS 82
#define SS_I2C_ADDR 0xEC
ALC_SyncTypeEnum adccontrol_SyncSepCallback(void);
#endif
#if defined(__ADC_TVP7001) || defined(__ADC_TVP7002)
#define ADC_I2C_ADDR 0xBA
#define ADC_MAX_SAMPLE_FREQ_MHZ 165
#define ADC_CAP_NANOFARADS 100
#endif
static ALC_SavedModeStruct userSavedModeTable[3];
static int08 tracking;
static int08 verticalPosition;
static int08 horizontalPosition;
void adccontrol_powerNormal( void )
{
I2CINIT adc_i2c;
ALC_AutoLockASMCfgStruct alc_asm_cfg;
ALC_SavedModeStruct* savedMode2address;
uint08 savedMode2num = 0;
ADC_LimitStruct limits;
uint16 nominalOffset, nominalGain;
uint08 i;
/* enable the ADC */
#if defined(__ADC_TVP7001) || defined(__ADC_TVP7002)
GPIO_SetPinConfig(GIO_ADC_DVI_TRI, GIOCFG_OUTPUT, TRUE, GIOCFG_ACTIVE );
#endif
adc_i2c.MasterAddressMode = I2C_7BIT;
adc_i2c.SlaveAddressMode = I2C_7BIT;
adc_i2c.FilterValue = 15;
adc_i2c.SCLClockRate = 100000;
adc_i2c.IntEnable = TRUE;
/* ensure i2c is initialized for ADC and power up */
ALC_AutoLockADCInit(gpConfiguration->Datapath.FrontEndDevicesI2CPort, &adc_i2c,
ADC_I2C_ADDR, ADC_MAX_SAMPLE_FREQ_MHZ, ADC_CAP_NANOFARADS );
ADC_SetDevicePower( ADC_CHIP_POWER_UP );
/**********************************/
/* One time AutoLock config */
/**********************************/
/* Initialize and disable all callbacks */
for( i=0; i<ALC_NUMBER_ASM_CALLBACKS; i++ )
alc_asm_cfg.ASMCallbacks[i] = NULL;
/* Enable the phase callback for intermediate image display */
if( gpConfiguration->Datapath.EnablePhaseCallback )
{
alc_asm_cfg.ASMCallbacks[ALC_PHASE_START] = datapath_AlockStateMachineCallback;
alc_asm_cfg.ASMCallbacks[ALC_PHASE_END] = datapath_AlockStateMachineCallback;
}
/* Retrieve ADC Calibrated gains */
#ifdef __ADC_MST3762MW
/* use nominal values for the MST3762MW */
nominalOffset = 0x7f;
nominalGain = 0x7f;
alc_asm_cfg.RedCalibratedOffset = nominalOffset;
alc_asm_cfg.GreenCalibratedOffset = nominalOffset;
alc_asm_cfg.BlueCalibratedOffset = nominalOffset;
alc_asm_cfg.RedCalibratedGain = nominalGain;
alc_asm_cfg.GreenCalibratedGain = nominalGain;
alc_asm_cfg.BlueCalibratedGain = nominalGain;
alc_asm_cfg.RedChMidLevelCalibratedOffset = nominalOffset;
alc_asm_cfg.BlueChMidLevelCalibratedOffset = nominalOffset;
#else
nominalOffset = 0x3f;
if( ADC_GetOffsetLimits( &limits ) == PASS )
{
nominalOffset = (limits.LowerLimit + limits.UpperLimit)/2;
}
nominalGain = 0x7f;
if( ADC_GetGainLimits( &limits ) == PASS )
{
nominalGain = (limits.LowerLimit + limits.UpperLimit)/2;
}
/* use stored calibrated values in eeprom */
EE_GETVAR( UserMachine.Cal_Data.RedOffset, alc_asm_cfg.RedCalibratedOffset );
EE_GETVAR( UserMachine.Cal_Data.GreenOffset, alc_asm_cfg.GreenCalibratedOffset );
EE_GETVAR( UserMachine.Cal_Data.BlueOffset, alc_asm_cfg.BlueCalibratedOffset );
EE_GETVAR( UserMachine.Cal_Data.RedGain, alc_asm_cfg.RedCalibratedGain );
EE_GETVAR( UserMachine.Cal_Data.GreenGain, alc_asm_cfg.GreenCalibratedGain );
EE_GETVAR( UserMachine.Cal_Data.BlueGain, alc_asm_cfg.BlueCalibratedGain );
EE_GETVAR( UserMachine.Cal_Data.RedMidLevelOffset, alc_asm_cfg.RedChMidLevelCalibratedOffset );
EE_GETVAR( UserMachine.Cal_Data.BlueMidLevelOffset, alc_asm_cfg.BlueChMidLevelCalibratedOffset );
/* ensure values from eeprom are within limits */
alc_asm_cfg.RedCalibratedOffset = LMT( (nominalOffset * 6/10), alc_asm_cfg.RedCalibratedOffset, (nominalOffset * 14/10) );
alc_asm_cfg.GreenCalibratedOffset = LMT( (nominalOffset * 6/10), alc_asm_cfg.GreenCalibratedOffset, (nominalOffset * 14/10) );
alc_asm_cfg.BlueCalibratedOffset = LMT( (nominalOffset * 6/10), alc_asm_cfg.BlueCalibratedOffset, (nominalOffset * 14/10) );
alc_asm_cfg.RedCalibratedGain = LMT( (nominalGain * 6/10), alc_asm_cfg.RedCalibratedGain, (nominalGain * 14/10) );
alc_asm_cfg.GreenCalibratedGain = LMT( (nominalGain * 6/10), alc_asm_cfg.GreenCalibratedGain, (nominalGain * 14/10) );
alc_asm_cfg.BlueCalibratedGain = LMT( (nominalGain * 6/10), alc_asm_cfg.BlueCalibratedGain, (nominalGain * 14/10) );
alc_asm_cfg.RedChMidLevelCalibratedOffset = LMT( (nominalOffset * 6/10), alc_asm_cfg.RedChMidLevelCalibratedOffset, (nominalOffset * 14/10) );
alc_asm_cfg.BlueChMidLevelCalibratedOffset = LMT( (nominalOffset * 6/10), alc_asm_cfg.BlueChMidLevelCalibratedOffset, (nominalOffset * 14/10) );
#endif
/* Configure user save mode table */
EE_GETVAR( UserMachine.UserSettings[0], userSavedModeTable[0] );
EE_GETVAR( UserMachine.UserSettings[1], userSavedModeTable[1] );
EE_GETVAR( UserMachine.UserSettings[2], userSavedModeTable[2] );
alc_asm_cfg.Group1SavedModePtr = userSavedModeTable;
alc_asm_cfg.Group1NumSavedModes = 3;
/* get the saved mode table from flash */
ALC_GetAutoLockModesNumModes(&savedMode2num);
if (savedMode2num > 0)
{
ALC_GetAutoLockModesTableAddress(&savedMode2address);
alc_asm_cfg.Group2SavedModePtr = savedMode2address;
alc_asm_cfg.Group2NumSavedModes = savedMode2num;
}
/* specify algorithm behavoir */
alc_asm_cfg.SMTCfg = ALC_SMT1_SMT2_ALF;
alc_asm_cfg.OperatingMode = ALC_AUTO_CALIBRATED_GAIN;
/* Set AutoLock timeout arbitrarily large, */
/* because application will handle timeout */
alc_asm_cfg.VsyncsUntilManual = 2400;
/* get the device phase range */
if (ADC_GetPhaseLimits( &limits ) == PASS)
{
/* try to get the best phase setting */
/* note: this may be reduced to improve lock time */
alc_asm_cfg.NumPhases = (uint08)(limits.UpperLimit - limits.LowerLimit + 1);
}
else
alc_asm_cfg.NumPhases = (uint08)32;
/* set the clock detection mode according to the app data variable */
alc_asm_cfg.ClockDetectionMode = gpConfiguration->Datapath.AlcClockDetectionMode;
/* set the WideMode flag */
alc_asm_cfg.WideMode = FALSE;
#ifdef __ADC_MST3762MW
/* Enable oclkb for sync separator, set to 100MHz/4 = 25MHz */
DDP_EnableGeneralPurposeClock( DDP_CLK_OUTPUT_B, TRUE, (uint08)4 );
GPIO_EnableAlternativeFunction( GPIO_GPCLK1_OUT, TRUE );
/* initialize sync separator and install autolock callback */
if ( SYNC_Init( SS_I2C_ADDR, I2C_PORT0 ) == PASS )
{
alc_asm_cfg.SyncProcessorCallback = adccontrol_SyncSepCallback;
}
else
{
alc_asm_cfg.SyncProcessorCallback = NULL;
}
#else
/* no sync separator installed, so no need for a callback function */
alc_asm_cfg.SyncProcessorCallback = NULL;
#endif
/* ensure all AutoLock processing is enabled */
alc_asm_cfg.StateMachineDisable = 0;
/* write the new configuration */
ALC_SetAutoLockASMCfg( &alc_asm_cfg );
}
void adccontrol_powerStandby( void )
{
I2CINIT adc_i2c;
#if defined(__ADC_TVP7001) || defined(__ADC_TVP7002)
GPIO_SetPinConfig(GIO_ADC_DVI_TRI, GIOCFG_OUTPUT, TRUE, GIOCFG_ACTIVE );
#endif
adc_i2c.MasterAddressMode = I2C_7BIT;
adc_i2c.SlaveAddressMode = I2C_7BIT;
adc_i2c.FilterValue = 15;
adc_i2c.SCLClockRate = 100000;
adc_i2c.IntEnable = TRUE;
/* ensure i2c is initialized for ADC and power down */
ALC_AutoLockADCInit(gpConfiguration->Datapath.FrontEndDevicesI2CPort, &adc_i2c,
ADC_I2C_ADDR, ADC_MAX_SAMPLE_FREQ_MHZ, ADC_CAP_NANOFARADS );
ADC_SetDevicePower( ADC_CHIP_POWER_DOWN );
}
void adccontrol_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 __ADC_AD9882
port_config.PortWidth = SRC_30_BITS;
port_config.ABC_Mux = SRC_ABC_STRAIGHT_THRU;
port_config.DataEnableSource = SRC_PORT1;
#endif
#ifdef __ADC_MST3762MW
port_config.PortWidth = SRC_30_BITS;
port_config.ABC_Mux = SRC_ABC_ROTATE_LEFT;
port_config.DataEnableSource = SRC_PORT1;
#endif
#if defined(__ADC_TVP7001) || defined(__ADC_TVP7002)
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;
#if defined(__ADC_TVP7001) || defined(__ADC_TVP7002)
GPIO_SetPinConfig(GIO_ADC_DVI_TRI, GIOCFG_OUTPUT, TRUE, GIOCFG_ACTIVE );
#endif
ALC_AutoLockADCInit(gpConfiguration->Datapath.FrontEndDevicesI2CPort, &adc_i2c,
ADC_I2C_ADDR, ADC_MAX_SAMPLE_FREQ_MHZ, ADC_CAP_NANOFARADS );
ADC_SetDevicePower( ADC_CHIP_POWER_UP );
/************************/
/* AutoLock Port init */
/************************/
alc_port_cfg.PortCommand = ALC_ADC_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);
ADC_SetOutputPortWidth(0);
ADC_SetActiveInterfaceMode(ADC_MANUAL_IF_SELECT);
ADC_SetActiveInterface(ANALOG);
#ifdef __ADC_MST3762MW
SYNC_ConfigureForSeparateHV();
#endif
/********************************/
/* start the AutoLock Algorithm */
/********************************/
ALC_AutoLockAlgorithmControl(ALC_ALG_CTL_START);
}
uint16 adccontrol_Poll( DP_STATE datapathState )
{
#ifdef __ADC_MST3762MW
/* switch the active port on the sync separator every 500ms */
if( datapathState == LOOK_FOR_SYNCS )
{
if( SYNC_GetConfiguredPort() == 0 )
{
if( (datapath_TimeElapsedInState() % 1000) >= 500 )
{
SYNC_ConfigureForSOG();
}
}
else
{
if( (datapath_TimeElapsedInState() % 1000) < 500 )
{
SYNC_ConfigureForSeparateHV();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -