📄 tidtv_tvp5160.c
字号:
}
}
else if ((CC1x_capture == 0) & (CC2x_capture==1)) { // 1x slicing done
CC_cnt++;
if (CC1x_error_rate > CC_Threshold) { // 3 for Cable, 5 for Air
TiDTV_Tvp5160SetVBUSAddr(0x800600);
TiDTV_Tvp5160I2cWrite(sizeof(TVP5160_InitCC1xNTSC), (UCHAR *) &(TVP5160_InitCC2xNTSC[0]), 3 * OS_TICKS_PER_SEC);
//CC1x_capture =1;
CC_cnt=0;
}
}
else if ((CC1x_capture == 0) & (CC2x_capture==0)) {// 1x and 2x slicing done
CC_cnt++;
if(CC1x_error_rate < CC2x_error_rate) {
TiDTV_Tvp5160SetVBUSAddr(0x800600);
TiDTV_Tvp5160I2cWrite(sizeof(TVP5160_InitCC1xNTSC), (UCHAR *) &(TVP5160_InitCC1xNTSC[0]), 3 * OS_TICKS_PER_SEC);
//CC1x_capture = CC2x_capture =1;
CC_cnt=0;
}
}
// }
// Release the Mutex Semaphore
OSSemPost(TiDTV_VideoDecCtrl.pMutexSem);
}
/*******************************************************************************
* @RoutineName:: TiDTV_VideoDecCheckVideoFmt
*
* @Description:: Check VideoDec Innput Video Format
*
* @Input :: none
*
* @Output :: none
*
* @Return ::
* int : Input Video Format Changed (1) or not (0)
*******************************************************************************/
int TiDTV_VideoDecCheckVideoFmt(void)
{
INT8U uCosRetStatus;
UCHAR AddrData[2], VideoFmt = 0xff;
int RetStatus = 0;
// check if it is locked
if (TiDTV_VideoDecCtrl.LockStatus == 0)
return 0; // Input Signal is not locked
// Take the Mutex Semaphore
OSSemPend(TiDTV_VideoDecCtrl.pMutexSem, 0, &uCosRetStatus);
if (TiDTV_Tvp5160I2cRead(TVP5160_REG_STATUS_5, 1, &VideoFmt, OS_TICKS_PER_SEC / 2) != TI_DTV_E_NG)
{
VideoFmt &= 0x0f;
switch (VideoFmt) {
case TVP5160_VIDEO_NTSC:
case TVP5160_VIDEO_MPAL:
TiDTV_VideoDecCtrl.NvVideoFmt = TI_DTV_NV_NTSC;
break;
case TVP5160_VIDEO_PAL:
case TVP5160_VIDEO_NPAL:
TiDTV_VideoDecCtrl.NvVideoFmt = TI_DTV_NV_PAL;
break;
case TVP5160_VIDEO_480P:
TiDTV_VideoDecCtrl.NvVideoFmt = TI_DTV_NV_480P;
break;
case TVP5160_VIDEO_576P:
TiDTV_VideoDecCtrl.NvVideoFmt = TI_DTV_NV_576P;
break;
default:
VideoFmt = TiDTV_VideoDecCtrl.NvVideoFmt = 0xff; // unkown format
break;
}
}
if (TiDTV_VideoDecCtrl.VideoFmt != VideoFmt) {
TiDTV_VideoDecCtrl.VideoFmt = VideoFmt;
if (VideoFmt != 0xff) {
// Video Standard changed
AddrData[0] = TVP5160_REG_OUTPUT_FMT_1;
if (VideoFmt == TVP5160_VIDEO_480P || VideoFmt == TVP5160_VIDEO_576P) {
// 20-bit 656 output format: I2C_0x33 = 0x44
AddrData[1] = 0x44;
} else {
// 10-bit 656 output format: I2C_0x33 = 0x40
AddrData[1] = 0x40;
}
TiDTV_Tvp5160I2cWrite(2, AddrData, OS_TICKS_PER_SEC / 5);
RetStatus = 1;
}
}
// Release the Mutex Semaphore
OSSemPost(TiDTV_VideoDecCtrl.pMutexSem);
return RetStatus;
}
/*******************************************************************************
* @RoutineName:: TiDTV_VideoDecOutputCtrl
*
* @Description:: Enable or Disable VideoDec Outputs
*
* @Input ::
* int Flag : 1 = Enable Outputs, 0 = Disable Outputs (high impedance)
*
* @Output :: none
*
* @Return :: none
*******************************************************************************/
void TiDTV_VideoDecOutputCtrl(int Flag)
{
INT8U uCosRetStatus;
UCHAR AddrData[2];
// Take the Mutex Semaphore
OSSemPend(TiDTV_VideoDecCtrl.pMutexSem, 0, &uCosRetStatus);
AddrData[0] = TVP5160_REG_OUTPUT_FMT_2;
if (Flag) {
// Enable Outputs
AddrData[1] = 0x11;
} else {
// Disable Outputs
AddrData[1] = 0x00;
}
TiDTV_Tvp5160I2cWrite(2, AddrData, OS_TICKS_PER_SEC / 5);
// Release the Mutex Semaphore
OSSemPost(TiDTV_VideoDecCtrl.pMutexSem);
}
/*******************************************************************************
* @RoutineName:: TiDTV_Tvp5160VdpFifoCtrl
*
* @Description:: Control the TVP5160 VDP FIFO data to Video Data Port or I2C
*
* @Input ::
* UCHAR Flag : 1 = Host (through I2C), 0 = Video Data Port Y[9:2]
*
* @Output :: none
*
* @Return :: none
*******************************************************************************/
static void TiDTV_Tvp5160VdpFifoCtrl(UCHAR Flag)
{
UCHAR AddrData[2];
// VDP FIFO Reset
AddrData[0] = TVP5160_REG_FIFO_RESET;
AddrData[1] = 0x01;
TiDTV_Tvp5160I2cWrite(2, AddrData, OS_TICKS_PER_SEC / 5);
// Flag = 1: Allow host port access to the VBI FIFO data
// Flag = 0: VBI FIFO Data to the video output Y[9:2]
AddrData[0] = TVP5160_REG_VDP_FIFO_OUT_CTRL;
AddrData[1] = Flag;
TiDTV_Tvp5160I2cWrite(2, AddrData, OS_TICKS_PER_SEC / 5);
}
/*******************************************************************************
* @RoutineName:: TiDTV_Tvp5160InitVDP
*
* @Description:: TVP5160 VDP (VBI Data Processor) Initializations
*
* @Input :: none
*
* @Output :: none
*
* @Return :: none
*******************************************************************************/
void TiDTV_Tvp5160InitVDP(void)
{
TiDTV_Tvp5160SetVBUSAddr(0x902040); // loading CRAM
TiDTV_Tvp5160I2cWrite(sizeof(TVP5160_VdpCRamNtsc601Gemstar),
(UCHAR *) &(TVP5160_VdpCRamNtsc601Gemstar[0]), 2 * OS_TICKS_PER_SEC);
TiDTV_Tvp5160SetVBUSAddr(0x800600);
TiDTV_Tvp5160I2cWrite(sizeof(TVP5160_InitCC2xNTSC), (UCHAR *) &(TVP5160_InitCC1xNTSC[0]), 3 * OS_TICKS_PER_SEC);
CC2x_error_rate = CC2x_errorcnt = 0;
CC1x_error_rate = CC1x_errorcnt = 0;
CC1x_capture = CC2x_capture =1;
}
/*******************************************************************************
* @RoutineName:: TiDTV_Tvp5160InitVDP
*
* @Description:: TVP5160 VDP (VBI Data Processor) Initializations
*
* @Input :: CC mode 1x or 2x (default to 1x)
*
* @Output :: none
*
* @Return :: none
*******************************************************************************/
void TiDTV_Tvp5160InitVDP_2x(void)
{
TiDTV_Tvp5160SetVBUSAddr(0x800600); // Reset VDP
TiDTV_Tvp5160I2cWrite(sizeof(TVP5160_InitCC2xNTSC), (UCHAR *) &(TVP5160_InitCC1x_resetNTSC[0]), 3 * OS_TICKS_PER_SEC);
memset(TiDTV_NvAncDataBuf,0,sizeof(TiDTV_NvAncDataBuf)); // Clear Ancillary data buffer
TiDTV_Tvp5160SetVBUSAddr(0x800600); // Set to 1x slicing mode
TiDTV_Tvp5160I2cWrite(sizeof(TVP5160_InitCC2xNTSC), (UCHAR *) &(TVP5160_InitCC1xNTSC[0]), 3 * OS_TICKS_PER_SEC);
CC2x_error_rate = CC2x_errorcnt = 0;
CC1x_error_rate = CC1x_errorcnt = 0;
CC1x_capture = CC2x_capture =1;
CC_cnt=0;
if (TiDTV_SysCtrl.CurAirCableATV == 0) CC_Threshold = 5;
else CC_Threshold = 3;
}
/*******************************************************************************
* @RoutineName:: TiDTV_VideoDecCheckTotalVLines
*
* @Description:: TVP5160 Check current signal total lines
*
* @Input :: none
*
* @Output :: none
*
* @Return ::
* USHORT : Video vertical total line numbers
*******************************************************************************/
int TiDTV_VideoDecCheckTotalVLines(void)
{
INT8U uCosRetStatus;
int VTotalLineNumber = 0;
UCHAR temp8;
// Take the Mutex Semaphore
OSSemPend(TiDTV_VideoDecCtrl.pMutexSem, 0, &uCosRetStatus);
// get upper 3 bit
TiDTV_Tvp5160I2cRead(0x43, 1, &temp8, OS_TICKS_PER_SEC / 2);
VTotalLineNumber = temp8 & 0x07;
VTotalLineNumber <<= 8;
// get lower 8 bit
TiDTV_Tvp5160I2cRead(0x42, 1, &temp8, OS_TICKS_PER_SEC / 2);
VTotalLineNumber |= temp8;
// Release the Mutex Semaphore
OSSemPost(TiDTV_VideoDecCtrl.pMutexSem);
return VTotalLineNumber;
}
/*******************************************************************************
* @RoutineName:: TiDTV_VideoDecAdjBrightness
*
* @Description:: TVP5160 adjust brightness
*
* @Input :: UCHAR Persentage. the Persentage is that:
* Percentage = (float) (Current_Value - Min) / (float)(Max - Min) * 100;
* Current_Value is data stored, min value is current OSD min, max value is current OSD max
*
* @Output :: none
*
* @Return :: none
*******************************************************************************/
void TiDTV_VideoDecAdjBrightness(int Persentage)
{
INT8U uCosRetStatus;
UCHAR RealValue;
UCHAR VideoDecBrightnessMin, VideoDecBrightnessMax;
if (Persentage > 100)
return;
// Take the Mutex Semaphore
OSSemPend(TiDTV_VideoDecCtrl.pMutexSem, 0, &uCosRetStatus);
VideoDecBrightnessMin = 16; // depends on different decoder
VideoDecBrightnessMax = 240; // depends on different decoder
RealValue = (VideoDecBrightnessMax - VideoDecBrightnessMin) * (Persentage / 100);
// write register value
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0x09, RealValue, OS_TICKS_PER_SEC / 2);
// Release the Mutex Semaphore
OSSemPost(TiDTV_VideoDecCtrl.pMutexSem);
}
/*******************************************************************************
* @RoutineName:: TiDTV_VideoDecAdjSharpness
*
* @Description:: TVP5160 adjust Sharpness
*
* @Input :: UCHAR Persentage. the Persentage is that:
* Percentage = (float) (Current_Value - Min) / (float)(Max - Min) * 100;
* Current_Value is data stored, min value is current OSD min, max value is current OSD max
*
* @Output :: none
*
* @Return :: none
*******************************************************************************/
void TiDTV_VideoDecAdjSharpness(int Persentage)
{
INT8U uCosRetStatus;
UCHAR temp8;
if (Persentage > 100)
return;
// Take the Mutex Semaphore
OSSemPend(TiDTV_VideoDecCtrl.pMutexSem, 0, &uCosRetStatus);
// read peaking register value
TiDTV_I2cRead(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0xdf,1, &temp8, OS_TICKS_PER_SEC / 2);
// set peaking gains
if (Persentage < 25)
temp8 = (temp8 & 0x00);
else if((Persentage >= 25) && (Persentage < 50))
temp8 = ((temp8 & 0xfc) | 0x01);
else if((Persentage >= 50) && (Persentage < 75))
temp8 = ((temp8 & 0xfc) | 0x02);
else if(Persentage >= 75)
temp8 = ((temp8 & 0xfc) | 0x03);
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 1, TVP5160_I2C_DEVICE_ADDR, 1, 0xdf, temp8, OS_TICKS_PER_SEC / 5);
// Release the Mutex Semaphore
OSSemPost(TiDTV_VideoDecCtrl.pMutexSem);
}
/*******************************************************************************
* @RoutineName:: TiDTV_VideoDecAdjNoiseReduction
*
* @Description:: TVP5160 adjust Noise Reduction
*
* @Input ::
* UCHAR Persentage : the Persentage is that:
* Percentage = (float) (Current_Value - Min) / (float)(Max - Min) * 100;
* Current_Value is data stored, min value is current OSD min,
* max value is current OSD max
*
* @Output :: none
*
* @Return :: none
*******************************************************************************/
void TiDTV_VideoDecAdjNoiseReduction(int Persentage)
{
INT8U uCosRetStatus;
UCHAR NREnable = 0;
UCHAR WorkChar[5];
if (Persentage > 100)
return;
// Take the Mutex Semaphore
OSSemPend(TiDTV_VideoDecCtrl.pMutexSem, 0, &uCosRetStatus);
// read noise register Status value
TiDTV_I2cRead(TVP5160_I2C_CHANNEL, 0, TVP5160_I2C_DEVICE_ADDR, 1, 0x0D,1, &NREnable, OS_TICKS_PER_SEC / 2);
if(Persentage == 0)
{
// disable NR
NREnable = NREnable & ~BIT2;
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 0, TVP5160_I2C_DEVICE_ADDR, 1, 0x0D, NREnable, OS_TICKS_PER_SEC / 2);
}
else
{
if((NREnable & BIT2) != BIT2)
{
NREnable = NREnable | BIT2;
TiDTV_I2cWriteByte(TVP5160_I2C_CHANNEL, 0, TVP5160_I2C_DEVICE_ADDR, 1, 0x0D,NREnable, OS_TICKS_PER_SEC / 2);
}
WorkChar[0] = 0x5a;
WorkChar[1] = TVP5160_NRSensitivityTable[Persentage/30][0];
WorkChar[2] = TVP5160_NRSensitivityTable[Persentage/30][1];
WorkChar[3] = TVP5160_NRSensitivityTable[Persentage/30][2];
WorkChar[4] = TVP5160_NRSensitivityTable[Persentage/30][3];
TiDTV_I2cWrite(TVP5160_I2C_CHANNEL, 0, TVP5160_I2C_DEVICE_ADDR, 5,WorkChar, OS_TICKS_PER_SEC);
}
// Release the Mutex Semaphore
OSSemPost(TiDTV_VideoDecCtrl.pMutexSem);
}
#ifdef TVP5160_uCODE
static int TiDTV_Tvp5160VBUSWriteByte(int Addr,UCHAR Val)
{
int RetStatus = TiDTV_Tvp5160SetVBUSAddr(Addr);
UCHAR WorkChar[4];
if (RetStatus == TI_DTV_E_OK) {
WorkChar[0] = 0xE0;
WorkChar[1] = Val;
RetStatus = TiDTV_Tvp5160I2cWrite(2, WorkChar, OS_TICKS_PER_SEC / 4);
}
return RetStatus;
}
#endif
int TiDTV_Tvp5160VBUSReadByte(int Addr,UCHAR *pVal)
{
int RetStatus = TiDTV_Tvp5160SetVBUSAddr(Addr);
return TiDTV_Tvp5160I2cRead(0xE0,1,pVal,OS_TICKS_PER_SEC / 8);
}
static int TiDTV_Tvp5160SetVBUSAddr(UINT32 Addr)
{
UCHAR WorkChar[4];
WorkChar[0] = 0xE8;
WorkChar[1] = (UCHAR)(Addr & 0xff);
WorkChar[2] = (UCHAR)((Addr & 0xff00) >> 8);
WorkChar[3] = (UCHAR)((Addr & 0xff0000) >> 16);
return TiDTV_Tvp5160I2cWrite(4, WorkChar, OS_TICKS_PER_SEC / 2);
}
#ifdef TVP5160_uCODE
static void TiDTV_Tvp5160DownloaduCode(void)
{
TiDTV_Tvp5160VBUSWriteByte(0xB00060,0x03);
TiDTV_Tvp5160VBUSWriteByte(0xB00063,0x01);
TiDTV_Tvp5160SetVBUSAddr(0x400000);
TiDTV_Tvp5160I2cWrite(sizeof(TiDTV_TVP5160_uCode), (UCHAR *)&TiDTV_TVP5160_uCode[0], 10 * OS_TICKS_PER_SEC);
TiDTV_Tvp5160VBUSWriteByte(0xB00060, 0x02);
TiDTV_UserTimeDly(TI_DTV_SOFT_TIMER0, 100);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -