📄 tvp7001.c
字号:
ADC_ACTIVE_VSYNC_STATUS, TRUE, 3, 0x08, 0x14, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_VSYNC_IN_POLARITY_STATUS, TRUE, 2, 0x04, 0x14, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_SOG_ACTIVITY_STATUS, TRUE, 1, 0x02, 0x14, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_COAST_IN_POLARITY_STATUS, TRUE, 0, 0x01, 0x14, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_OUTPUT_FORMAT, TRUE, 1, 0x02, 0x15, ADC_VIDEO_OUT_444, FALSE, ADC_BOOL_LIMITS,
ADC_PIXEL_TOLERANCE, TRUE, 5, 0x0E, 0x16, 0x03, FALSE, ADC_NO_LIMITS,
ADC_TEST_OUTPUT, TRUE, 2, 0x0C, 0x16, 0x01, FALSE, ADC_NO_LIMITS,
ADC_PLL_POWER_DOWN, TRUE, 1, 0x02, 0x16, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_PLL_START_UP_ENABLE, TRUE, 0, 0x01, 0x16, 0x01, FALSE, ADC_BOOL_LIMITS,
ADC_BLUE_COARSE_GAIN, TRUE, 0, 0x0F, 0x1B, 0x05, FALSE, ADC_GAIN_LIMITS,
ADC_GREEN_COARSE_GAIN, TRUE, 4, 0xF0, 0x1B, 0x05, FALSE, ADC_GAIN_LIMITS,
ADC_RED_COARSE_GAIN, TRUE, 0, 0x0F, 0x1C, 0x05, FALSE, ADC_GAIN_LIMITS,
ADC_BLUE_FINE_OFFSET_LSB, TRUE, 0, 0x03, 0x1D, 0x00, FALSE, ADC_FINE_OFFSET_LSB_LIMITS,
ADC_GREEN_FINE_OFFSET_LSB, TRUE, 0, 0x0C, 0x1D, 0x00, FALSE, ADC_FINE_OFFSET_LSB_LIMITS,
ADC_RED_FINE_OFFSET_LSB, TRUE, 0, 0x30, 0x1D, 0x00, FALSE, ADC_FINE_OFFSET_LSB_LIMITS,
ADC_BLUE_COARSE_OFFSET, TRUE, 0, 0x3F, 0x1E, 0x1F, FALSE, ADC_COARSE_OFFSET_LIMITS,
ADC_GREEN_COARSE_OFFSET, TRUE, 0, 0x3F, 0x1F, 0x1F, FALSE, ADC_COARSE_OFFSET_LIMITS,
ADC_RED_COARSE_OFFSET, TRUE, 0, 0x3F, 0x20, 0x1F, FALSE, ADC_COARSE_OFFSET_LIMITS,
ADC_HSOUT_START, TRUE, 0, 0xFF, 0x21, 8,/*0x28,*/ FALSE, ADC_NO_LIMITS,
ADC_MACROVISION_ENABLE, TRUE, 3, 0x08, 0x22, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_VSYNC_ALIGNMENT, TRUE, 1, 0x02, 0x22, 0x01, FALSE, ADC_BOOL_LIMITS,
ADC_AUTO_LEVEL_CONTROL_ENABLE, TRUE, 7, 0x80, 0x26, 0x80, FALSE, ADC_BOOL_LIMITS,
ADC_AUTO_LEVEL_CONTROL_NSH, TRUE, 0, 0x07, 0x28, 0x03, FALSE, ADC_AUTO_LEVEL_CONTROL_NSH_LIMITS,
ADC_AUTO_LEVEL_CONTROL_NSV, TRUE, 3, 0x78, 0x28, 0x0E, FALSE, ADC_AUTO_LEVEL_CONTROL_NSV_LIMITS,
ADC_FINE_CLAMP_BLUE, TRUE, 2, 0x04, 0x2A, 0x01, FALSE, ADC_BOOL_LIMITS,
ADC_FINE_CLAMP_GREEN, TRUE, 1, 0x02, 0x2A, 0x01, FALSE, ADC_BOOL_LIMITS,
ADC_FINE_CLAMP_RED, TRUE, 0, 0x01, 0x2A, 0x01, FALSE, ADC_BOOL_LIMITS,
ADC_SETUP, TRUE, 0, 0xFF, 0x2C, 0x50, FALSE, ADC_POST_COAST_LIMITS,
ADC_COARSE_CLAMP_CONTROL_LP, TRUE, 6, 0xC0, 0x2D, 0x00, FALSE, ADC_ADC_COARSE_CLAMP_CONTROL_LP_LIMITS,
ADC_COARSE_CLAMP_CONTROL_RED, TRUE, 2, 0x04, 0x2D, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_COARSE_CLAMP_CONTROL_GREEN, TRUE, 1, 0x02, 0x2D, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_COARSE_CLAMP_CONTROL_BLUE, TRUE, 0, 0x01, 0x2D, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_ALC_PLACEMENT, TRUE, 0, 0xFF, 0x31, 0x18, FALSE, ADC_NO_LIMITS,
/* The following functions are specifically present in TVP7000 */
ADC_INPUT_SOG_SELECT, TRUE, 6, 0xC0, 0x19, ADC_INPUT_MUX_CH3, FALSE, ADC_INPUT_MUX_LIMITS,
ADC_INPUT_RED_SELECT, TRUE, 4, 0x30, 0x19, ADC_INPUT_MUX_CH3, FALSE, ADC_INPUT_MUX_LIMITS,
ADC_INPUT_GREEN_SELECT, TRUE, 2, 0x0C, 0x19, ADC_INPUT_MUX_CH3, FALSE, ADC_INPUT_MUX_LIMITS,
ADC_INPUT_BLUE_SELECT, TRUE, 0, 0x03, 0x19, ADC_INPUT_MUX_CH3, FALSE, ADC_INPUT_MUX_LIMITS,
ADC_INPUT_SELECT, TRUE, 0, 0xFF, 0x19, 0xAA, FALSE, ADC_NO_LIMITS,
ADC_INPUT_SELECT2_BIT7, TRUE, 7, 0x80, 0x1A, 0x01, FALSE, ADC_BOOL_LIMITS,
ADC_INPUT_VSYNC_SELECT, TRUE, 2, 0x04, 0x1A, ADC_VSYNC_MUX_A, FALSE, ADC_BOOL_LIMITS,
ADC_INPUT_HSYNC_SELECT, TRUE, 0, 0x01, 0x1A, ADC_HSYNC_MUX_A, FALSE, ADC_BOOL_LIMITS,
ADC_SOG_CLAMP, TRUE, 7, 0x80, 0x2E, 0x01, FALSE, ADC_BOOL_LIMITS,
/* The following are the functions which dont exist in TVP7000 */
ADC_OUTPUT_WIDTH, FALSE, 7, 0x80, 0x0E, ADC_24_BIT, FALSE, ADC_BOOL_LIMITS,
ADC_OUTPUT_MODE, FALSE, 6, 0x40, 0x0E, ADC_PARALLEL, FALSE, ADC_BOOL_LIMITS,
ADC_OUTPUT_PHASE, FALSE, 5, 0x20, 0x0E, ADC_FIRST_PIXEL_ON_A, TRUE, ADC_BOOL_LIMITS,
ADC_PIXEL_CLOCK_SOURCE, FALSE, 3, 0x08, 0x0F, ADC_INTERNAL_PCLK, FALSE, ADC_BOOL_LIMITS,
ADC_DVI_CLOCK_INVERT, FALSE, 4, 0x10, 0x14, ADC_DVI_CLOCK_NOT_INVERTED, FALSE, ADC_BOOL_LIMITS,
ADC_DVI_OUTPUT_WIDTH, FALSE, 6, 0x40, 0x10, ADC_24_BIT, FALSE, ADC_BOOL_LIMITS,
ADC_TRISTATE_OUTPUTS, FALSE, 3, 0x08, 0x14, ADC_OUTPUTS_NOT_TRISTATED, FALSE, ADC_BOOL_LIMITS,
ADC_SYNC_DETECT_PIN_POLARITY, FALSE, 2, 0x04, 0x10, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_DVI_CLOCK_ACTIVITY_STATUS, FALSE, 4, 0x10, 0x15, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_ACTIVE_IF_STATUS, FALSE, 3, 0x08, 0x15, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_ACTIVE_IF_OVERRIDE, FALSE, 2, 0x04, 0x0F, ADC_MANUAL_IF_SELECT, FALSE, ADC_BOOL_LIMITS,
ADC_ACTIVE_IF_SELECT, FALSE, 1, 0x02, 0x0F, ADC_ANALOG_INTERFACE, FALSE, ADC_BOOL_LIMITS,
ADC_SCAN_ENABLE, FALSE, 2, 0x04, 0x14, ADC_SCAN_FUNCTION_DISABLED, FALSE, ADC_BOOL_LIMITS,
ADC_LOOP_RESISTOR_CONTROL, FALSE, 0, 0x0F, 0x22, 0x02, FALSE, ADC_LOOP_RESISTOR_CONTROL_LIMITS,
ADC_INPUT_MUX_CONTROL, FALSE, 3, 0x08, 0x15, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_INPUT_BANDWIDTH, FALSE, 1, 0x05, 0x15, 0x00, TRUE, ADC_INPUT_BANDWIDTH_LIMITS,
ADC_RED_TARGET_CODE, FALSE, 0, 0xFF, 0x19, 0x04, FALSE, ADC_NO_LIMITS,
ADC_GREEN_TARGET_CODE, FALSE, 0, 0xFF, 0x1A, 0x04, FALSE, ADC_NO_LIMITS,
ADC_BLUE_TARGET_CODE, FALSE, 0, 0xFF, 0x1B, 0x04, FALSE, ADC_NO_LIMITS,
ADC_AUTO_OFFSET, FALSE, 7, 0x80, 0x1D, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_HOLD_AUTO_OFFSET, FALSE, 6, 0x40, 0x1D, 0x00, FALSE, ADC_BOOL_LIMITS,
ADC_UPDATE_MODE, FALSE, 0, 0x03, 0x1D, 0x02, FALSE, ADC_UPDATE_RATE_AUTO_OFFSET_LIMITS,
ADC_TRIM_CONTROL, FALSE, 0, 0xFF, 0x2C, 0x00, FALSE, ADC_NO_LIMITS
};
/*****************************************************************************/
/* Private variables ******************************************************/
/*****************************************************************************/
static uint08 MaxSampleFreqInMHz;
static uint16 LoopFilterCapInNF;
static uint08 NumTableEntries;
static I2CPORT I2CPort;
static I2CINIT I2CCfg;
static uint16 I2CAddress;
static BOOL IsI2CDead = FALSE;
/* Stores ADC values. Use to arrange initialization data */
/* for contiguous byte communication over I2C. Table */
/* elements also used as global tracking variables for */
/* bit mapped fields. */
static uint08 ADC_Registers[ADC_NUM_REGISTERS];
static ADC_DriverErrorStruct I2CError = {0, PASS};
static ADC_DriverErrorStruct RTAError = {0, PASS};
/*****************************************************************************/
/* Private function prototypes ******************************************/
/*****************************************************************************/
static void ADC_FindVCORangeAndChargePump(uint16 clocks_per_line,
uint32 pixel_rate,
uint32 horz_freq,
ADC_VCOAndChargePumpDataStruct *vco_charge_pump_data_ptr);
/* Byte field functions */
static int08 ADC_GetTableEntryIndex(ADC_FunctionEnum function, uint08 *table_index);
static int08 ADC_FindAndValidateADCArrayByte(ADC_FunctionEnum function, uint08 value, uint08 *table_index);
static void ADC_SetADCArrayByte(uint08 dev_subaddr, uint08 lsb_pos, uint08 mask, uint08 val);
static int08 ADC_SetADCByte(ADC_FunctionEnum function, uint08 value);
static int08 ADC_GetADCByte(ADC_FunctionEnum function, uint08 *value);
/* Limit functions */
static int08 ADC_GetLimits(ADC_FieldLimitsEnum limit_type, ADC_FieldLimitsStruct* limit_struct);
/* I2C functions */
static int08 ADC_Write(uint32 byte_count,
uint08 *data_buffer_ptr);
static int08 ADC_Read(uint08 device_subaddress,
uint32 byte_count,
uint08 *data_buffer_ptr);
/* I2C and RTA error structure functions */
static void ADC_SetI2CErrorStruct(ADC_DriverErrorStruct *i2c_error_struct);
static void ADC_SetRTAErrorStruct(ADC_DriverErrorStruct *rta_error_struct);
/*****************************************************************************/
/* Functions that may require customization for specific parts **************/
/*****************************************************************************/
/* 1. ADC_InitADC(). The function table does not handle non-functional bits or fields */
/* that are specified by the vendor for "proper operation". */
/* 2. ADC_SetPLLDivider() & ADC_GetPLLDivider(). In this implementation, contiguous */
/* multi-byte functions require specific knowledge of the start address. Shifting */
/* and masking of fields that span multiple bytes are addressed within the */
/* function and may require modification. */
/* 3. ADC_SetGainAndOffset(), ADC_SetGain(), ADC_GetGain(), ADC_SetOffset(), and */
/* ADC_GetOffset(). Contiguous multi-byte functions require specific knowledge of */
/* the start address. Specify the start address in ADC_ADCRegisterDefsEnum. */
/* 4. ADC_FindVCORangeAndChargePump(). The tests against the pixel frequency to find */
/* the VCO gain and range may require modification. */
/* 5. ADC_SetVCORangeAndChargePumpCurrent(). Some functions operate on multiple fields */
/* and my require modification. */
/* 6. There was concern that ADCs not currently supported by this driver may require */
/* multi-byte operations to configure parameters that are now configured by single */
/* byte operations. To hopefully minimize this impact, the argument list of some */
/* functions has arguments defined for sizes larger than necessary. Then, if the */
/* underlying operation becomes a multi-byte transaction, the API definition can */
/* remain static and only the code beneath must change. There are, however, */
/* unintended consequences to this methodology. */
/* */
/* ADC_SetHsyncPulseWidth() is an example of this type of function. This function */
/* currently accepts a 16 bit argument. The layered function beneath is a function */
/* used throughout the driver to set byte data. Unfortunately, this layered function */
/* will not currently operate on data sized greater than a byte. This requires some */
/* additional processing in the API to ensure range checking is performed and */
/* in the case of get functions, to ensure any data size mismatches do not cause */
/* pointers to be populated with erroneous MSBs. */
/*****************************************************************************/
/* Public functions *******************************************************/
/*****************************************************************************/
/*****************************************************************************/
/* Miscellaneous **********************************************************/
/*****************************************************************************/
uint08 ADC_IsThere48BitPort(void)
/**
* Used to determine whether or not this device has a 48 bit port option.
*
* @param void
*
* @return uint08 - 0 if device does not support 48 bit port
* 1 if device supports 48 bit port
*/
{
return (uint08)ADC_HAS_48_BIT_PORT;
}
uint08 ADC_GetMaxSampleFreqInMHz(void)
/**
* This function returns the maximum sample frequency allowed by
* the ADC. This value is set via the call ADC_CfgADC().
*
* NOTE: This function is called by the AutoLock function. It is used
* to ensure the calculated sample clock value does not exceed the
* maximum sample frequency allowed by the ADC. This function is
* expected to return a non-zero value. OEM supplied ADC drivers
* must implement this function.
*
* @param void
*
* @return uint08 - max sample frequency in MHz
*/
{
return MaxSampleFreqInMHz;
}
int08 ADC_GetI2CDriverErrno(void)
/**
* This function returns the most recent I2C driver error code.
*
* The ADC driver uses the I2C driver supplied by the API library.
* Most I2C driver errors are grouped by the ADC driver into the
* generic error code ADC_I2C_DRIVER_ERROR. The exception is
* ADC_I2C_DRIVER_TERMINAL_ERROR which is used to flag
* an unrecoverable I2C core error. This function may be used to
* get the most recent error code returned by a call to an I2C
* driver function. This value is not updated when I2C driver
* functions return PASS.
*
* @param void
*
* @return most recent I2C driver error code
*/
{
return I2CError.Error;
}
int08 ADC_GetRTAErrno(void)
/**
* This function returns the most recent RTA error code.
*
* The ADC driver uses the RTOS Adaptor supplied by the RTA library.
* RTA error codes are grouped by the ADC driver into the generic
* error code ADC_RTA_ERROR. The exception is error code
* ADC_RTA_SEM_IN_USE since this code may be used by the upper
* level to help determine whether the task owning the I2C
* semaphore requires a priority increase. This function may be
* used to get the most recent error code returned by a call to
* an RTA function. This value is not updated when RTA functions
* return PASS.
*
* @param void
*
* @return most recent RTA error code
*/
{
return RTAError.Error;
}
int08 ADC_GetI2CErrorStruct(ADC_DriverErrorStruct *i2c_error_struct)
/**
* This function gets the most recent values in the I2C driver error code structure.
*
* The ADC driver uses the I2C driver supplied with the API library.
* Most I2C driver errors are grouped by the ADC driver into the
* generic error code ADC_I2C_DRIVER_ERROR. The exception is
* ADC_I2C_DRIVER_TERMINAL_ERROR which is used to flag
* an unrecoverable I2C core error. This function may be used to
* get the most recent error code returned by a call to an I2C
* driver function. The error code structure contains the I2C driver
* error code and the owning task at the time the error code was set.
* This structure is not updated when I2C driver functions return
* PASS.
*
* @param *i2c_error_struct - I - storage for I2C error structure.
*
* @return PASS
*/
{
INT_DisableARMInterrupts();
*i2c_error_struct = I2CError;
INT_EnableARMInterrupts();
return PASS;
}
int08 ADC_GetRTAErrorStruct(ADC_DriverErrorStruct *rta_error_struct)
/**
* This function gets the most recent values in the RTA error code structure.
*
* The ADC driver uses the RTOS Adaptor supplied by the RTA library.
* RTA error codes are grouped by the ADC driver into the generic
* error code ADC_RTA_ERROR. The exception is error code
* ADC_RTA_SEM_IN_USE since this code may be used by the upper
* level to help determine whether the task owning the I2C
* semaphore requires a priority increase. This function may be
* used to get the most recent error code returned by a call to
* an RTA function. The error code structure contains the RTA function
* error code and the owning task at the time the error code was set.
* This structure is not updated when RTA functions return PASS.
*
* @param *rta_error_struct - I - storage for RTA error structure.
*
* @return PASS
*/
{
INT_DisableARMInterrupts();
*rta_error_struct = RTAError;
INT_EnableARMInterrupts();
return PASS;
}
BOOL ADC_IsI2CDead(void)
/**
* This function is called by AutoLock to determine if the I2C functions
* used by the ADC driver have returned the error code I2C_CMD_LOCK_ERROR.
* OEM supplied ADC drivers must implement this function. TI suggests the
* return codes of the I2C functions be checked and a flag set if the
* error code is ever I2C_CMD_LOCK_ERROR. Refer to the API documentation
* for explanations of the I2C function error codes.
*
* @param void
*
* @return BOOL - FALSE if an underlying I2C function has not returned the I2C_CMD_LOCK_ERROR code
* TRUE if an underlying I2C function has returned the I2C_CMD_LOCK_ERROR code
*/
{
return IsI2CDead;
}
/*****************************************************************************/
/* Initialization **********************************************************/
/*****************************************************************************/
void ADC_CfgADC(I2CPORT i2c_port, I2CINIT *i2c_cfg, uint16 i2c_address, uint08 max_sample_freq_in_mhz, uint16 cap_in_nanofarads)
/**
* Specifies the port connected to the ADC, the ADC specific
* I2CINIT structure, the ADC I2C address, the device's maximum
* sample frequency in MHz, and when applicable, the loop
* filter cap value in nanofarads. OEM supplied ADC drivers
* must implement this function.
*
* NOTE: This function is called by the AutoLock function, ALC_AutoLockADCInit().
*
* @param ic2_port - I - I2C port
* @param *i2c_cfg - I - configuration structure ADC device
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -