lh172a.c

来自「DVB软件,基于CT216软件的开发源程序.」· C语言 代码 · 共 236 行

C
236
字号
#include <string.h>
#include <stdio.h>
#include "ct_os.h"
#include "ct_sys.h"
#include "ct_iic.h"
#include "ct_nim.h"
#include "LH172A.h"

#define TUNER_ADD  	 	0xC2
#define TUNER_IFKHZ   	36125
#if 0
#ifdef IIC_UART
/*******************************************************************************************/
bool8 Tuner_Write(u8 *pu8Buffer , u8 u8Length)
{
    if ((pu8Buffer == NULL)||
        (u8Length > MAX_IIC_BURST_LENGTH)||
        (u8Length==0))
    {        
        return FALSE;
    }

    if ( IIC2UART_Write(TUNER_ADD, *pu8Buffer, (pu8Buffer+1), (u8Length-1)) == FALSE )
	{		    
	    return FALSE;
	}
    return TRUE;
}
/*******************************************************************************************/
bool8 Tuner_Read(u8 *pu8Buffer, u8 u8Length)
{
    if ((pu8Buffer == NULL)||(u8Length > MAX_IIC_BURST_LENGTH))
    {
        return FALSE;
    }    
    
	if ( IIC2UART_Read(TUNER_ADD, 0, pu8Buffer, u8Length, FALSE) == FALSE )
	{
	    return FALSE;
	}

    return TRUE;
}
#else
/*******************************************************************************************/
bool8 Tuner_Write(u8 *pu8Buffer , u8 u8Length)
{
    u32 u32Handle;	
    
	if (CT_NIM_GetBus() == EN_CT_NIM_BUS_0)
	{
		if( CT_IIC_Open(EN_CT_IIC_BUS_0, TUNER_ADD, &u32Handle)!= DRV_OK)
		{		
			printf("\nCT_IIC_Open 0 Error");
	        return FALSE;
	    }
	}
	else
	{
		if( CT_IIC_Open(EN_CT_IIC_BUS_1, TUNER_ADD, &u32Handle)!= DRV_OK)
		{		
			printf("\nCT_IIC_Open 1 Error");
	        return FALSE;
	    }		
	}
#ifdef NIM_SW_IIC
	if(CT_SW_IIC_WriteData(u32Handle, pu8Buffer, u8Length) != DRV_OK )
#else
	if(CT_IIC_WriteData(u32Handle, pu8Buffer, u8Length) != DRV_OK )
#endif
	{		
		printf("\nCT_IIC_WriteData Error");
		CT_IIC_Close(u32Handle);
		return(FALSE);
	}
	
	CT_IIC_Close(u32Handle);
	return (TRUE);     
}
/*******************************************************************************************/
bool8 Tuner_Read(u8 *pu8Buffer, u8 u8Length)
{    
    u32 u32Handle;
		
	if (CT_NIM_GetBus() == EN_CT_NIM_BUS_0)
	{
		if( CT_IIC_Open(EN_CT_IIC_BUS_0, TUNER_ADD, &u32Handle)!= DRV_OK)
		{
			printf("\nR CT_IIC_Open 0 Error");
        	return FALSE;
        }
	}
	else
	{
		if( CT_IIC_Open(EN_CT_IIC_BUS_1, TUNER_ADD, &u32Handle)!= DRV_OK)
		{
			printf("\nR CT_IIC_Open 1 Error");
        	return FALSE;		
        }
	}

#ifdef NIM_SW_IIC
	if(CT_SW_IIC_ReadData(u32Handle, pu8Buffer, u8Length) != DRV_OK )
#else
	if(CT_IIC_ReadData(u32Handle, pu8Buffer, u8Length) != DRV_OK )
#endif
	{
		printf("\nR CT_IIC_ReadData Error");
		CT_IIC_Close(u32Handle);		
		return FALSE;
	}
	
	CT_IIC_Close(u32Handle);
	return (TRUE) ;
}
#endif
#endif
/*******************************************************************************
 * Program SAMGSUNG DTOS403LH172A tuner
 *******************************************************************************/
// Note:
// 1. Some parameter need to be determined: BW, TOP....

bool8 CT221_ProgramTuner_LH172A(u32 dwFreqkHz, u8 dwBWandFreqkHz)
{
	u8  ucIndex;/* index into tuner control table*/
	u8  szBuffer[7];
	u8  status;
	u8  WriteBytes[6];
	u8 i;

	unsigned long dwTunerFreq;

	u16 sTunerFreqTableMHZ[] = {0,    
                                47,    54,  111,  118,  139,  146, // VHF low
                                174,  188,  258,  342,  366,  438, //VHF high
                                470,  566,  638,  718,  862     }; //UHF

	/*u8  sTunerControlTable[] = {0,
								0x01, 0x21, 0x41, 0x61, 0x81, 0xa1, 
								0xc1, 0x22, 0x42, 0x62, 0x82, 0xa2,
								0xc2, 0x68, 0x88, 0xa8, 0xc8, 0xe8    };*/

	/* control register, CP part*/
/*		u8  sTunerControlTable[] = {0,
								0x02, 0x04, 0x06, 0x08, 0x10, 0x12, //  6
								0x02, 0x04, 0x06, 0x08, 0x10, 0x12, // 12
								0x06, 0x08, 0x0a, 0x0c, 0x0e    };  // 17
*/
#define TABLE_COUNT 17 // latest count of FrequencyTable

	// VHF low
	// VHF high
	// UHF

	unsigned int FcompkHzx100 = 6250;


	/*scan table for control bytes s*/
	dwTunerFreq = dwFreqkHz / 1000; /* RF (MHz)*/
	for (ucIndex = TABLE_COUNT; ucIndex >= 1; ucIndex--)
	{
		if ((dwTunerFreq) >= sTunerFreqTableMHZ[ucIndex]) break;
	}

	/* Get control byte for RF frequency*/
    szBuffer[2] = 0xc0;   //1 1 0 0 0 0 0 0 
    szBuffer[3] = 0xa0;


#if 1
	if (ucIndex <= 6) // VHF low ( <174 )
	{
		szBuffer[3] |= 0x01; 
	}
	else if (ucIndex <= 12) // VHF high ( <470 )
	{
		szBuffer[3] |= 0x02; 
	}
	else // UHF
	{		
		szBuffer[3] = 0x04<<5; 
		szBuffer[3] |= 0x08; 
	}
#else
	szBuffer[3] |= 0x08; 		
#endif


	/* add in bandwidth switching */ 
	/* This is a conjectured value, needed to be checked*/
	//if (dwBWandFreqkHz == 8)
		szBuffer[3] |= 0x10;

	/* calculate LO frequency*/
	dwTunerFreq = dwFreqkHz; /* kHz*/
	/* IF offset*/
	/*	dwTunerFreq -= TUNER_IFKHZ; */
	dwTunerFreq += TUNER_IFKHZ;
	/* convert frequency to divider ratio*/
	dwTunerFreq = (dwTunerFreq * 1000) / FcompkHzx100;
	dwTunerFreq += 5;
	dwTunerFreq /= 10;     /*round off the result*/

	szBuffer[0] = (u8) ((dwTunerFreq >> 8) & 0xff);
	szBuffer[1] = (u8) (dwTunerFreq & 0xff);


	/* Program AGC setting 
       ie. ATC, TOP*/
	szBuffer[4] = 0x83; 

	for (i=0;i<5;i++)
	{
		WriteBytes[i] = szBuffer[i];
		//printf("\n WriteBytes = 0x%02x",WriteBytes[i]);
	}
	
	status = Tuner_Write(&WriteBytes[0], 5);
	//status = RegWrite(TUNER_ADD, WriteBytes[0], &WriteBytes[1], 5);
	CT_OS_MS_Delay(5);
/*
	WriteByts[0] = szBuffer[2];
	WriteByts[1] = szBuffer[4];

	status = RegWrite(TUNER_ADD, WriteByts[0], &WriteByts[1], 2);
	Sleep(50);
*/


	return (TRUE);    

}


⌨️ 快捷键说明

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