edt3022.c

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

C
265
字号
#include <stdio.h>
#include "ct_os.h"
#include "ct_sys.h"
#include "ct_iic.h"
#include "ct_nim.h"
#include "EDT3022.h"

//#define IIC_UART
#define TUNER_ADD   	0xC0
//static u8 szBuffer[8];

#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 EDT3022(Earda) tuner
 *******************************************************************************/
bool8 CT221_ProgramTuner_EDT3022(u32 RfFreq, u8 dwBWandFreqkHz)
{
	unsigned int N;
	u8           WriteBytes[5];
	float        TunerFreq;
	u8           status;
//	u8           TUNER_ID  = 0xc0;
	u8           ByteMask  = 0xff;
	unsigned int NMask     = 0x7fff;
	unsigned int ByteShift = 8;
	
//	u8           freqIF = 36167;
		

	TunerFreq = RfFreq / 1000.0;

	// Calculate divider N with step size = 166.67 kHz.
	N = (unsigned int)(TunerFreq * 6 + 217 + 0.5);
	
	// Calculate divider N with step size = 62.5 kHz.
	//N = (unsigned int)(TunerFreq * 16 + 579 + 0.5);
	
	N &= NMask;

	// Set divider byte 1 and 2.
	//   - Note: Divider byte 1 is WriteBytes[0].
	//           Divider byte 2 is WriteBytes[1].
	WriteBytes[0] = N >> ByteShift & ByteMask;
	WriteBytes[1] = N & ByteMask;


	// Set control byte and band switch byte.
	//   - Note: Control byte is WriteBytes[2].
	//           Band switch byte is WriteBytes[3].
	if (TunerFreq > 833) 
	{
		WriteBytes[2] = (0xF8 | 0x04);//0xf8:CP=650, Ratio = 24
		WriteBytes[3] = (0x08 | 0x04); //0x08:8M , 0x04: UHF
	}
	else if(TunerFreq > 545) 
	{
		WriteBytes[2] = (0xF0 |0x04);//0xf0:CP=250
		WriteBytes[3] = (0x08 | 0x04); //0x08:8M , 0x04: UHF
	}
	else if(TunerFreq > 473) //>=474  +-0.2 
	{
		WriteBytes[2] = (0xB8 |0x04);  //0xb8:CP=125
		WriteBytes[3] = (0x08 | 0x04); //0x08:8M , 0x04: UHF
	}	
	else if(TunerFreq > 457)  
	{
		WriteBytes[2] = (0xF8 |0x04);//0xf8:CP=650
		WriteBytes[3] = (0x00 | 0x02); //0x00:7M , 0x02: VHF high
	}	
	else if(TunerFreq > 377) 
	{
		WriteBytes[2] = (0xF0 |0x04);//0xf0:CP=250
		WriteBytes[3] = (0x00 | 0x02); //0x00:7M , 0x02: VHF high
	}	
	else if(TunerFreq > 177) 
	{
		WriteBytes[2] = (0xB8 |0x04);  //0xb8:CP=125
		WriteBytes[3] = (0x00 | 0x02); //0x00:7M , 0x02: VHF high
	}	
	else if(TunerFreq > 138) 
	{
		WriteBytes[2] = (0xF0 |0x04);//0xf0:CP=250
		WriteBytes[3] = (0x00 | 0x01); //0x00:7M , 0x01: VHF low
	}	
	else //51~
	{
		WriteBytes[2] = (0xB8 |0x04);  //0xb8:CP=125
		WriteBytes[3] = (0x00 | 0x01); //0x00:7M , 0x01: VHF low
	}	
	#if 0//20080228 762 C/N Fail
	if (TunerFreq > 749) //750
	{
		WriteBytes[2] = 0xfc; // cp=650
		WriteBytes[3] = 0x0c;
	}
	else if(TunerFreq > 609) //610 
	{
		WriteBytes[2] = 0xf4; // cp=250
		WriteBytes[3] = 0x0c;
	}
	else if(TunerFreq > 473) //>=474  +-0.2 
	{
		WriteBytes[2] = 0xbc; // cp=125
		WriteBytes[3] = 0x0c;
	}	
	else if(TunerFreq > 429) // 430 
	{
		WriteBytes[2] = 0xbc; // cp=125
		WriteBytes[3] = 0x02;
	}	
	else if(TunerFreq > 177) //>= 178 +-0.2 
	{
		WriteBytes[2] = 0xac; // cp=50
		WriteBytes[3] = 0x02;
	}	
	else
	{
		WriteBytes[2] = 0xac;
		WriteBytes[3] = 0x01;
	}	
	#endif
	
	//WriteBytes[2] |= 0x02; // 62.5
	
	//if (dwBWandFreqkHz == 0x08)
	  WriteBytes[3] |= 0x08;
	//else 
		//WriteBytes[3] &= ~0x08; 

	// Set auxiliary byte.	//   - Note: Auxiliary byte is WriteBytes[4].
	WriteBytes[4] = 0x40; //if need LOOP Though, set 0X21

	status = Tuner_Write(&WriteBytes[0], 4);

	CT_OS_MS_Delay(5);

	WriteBytes[2]|=0x18;	
	WriteBytes[2]&=~0x20;
	WriteBytes[3] = WriteBytes[4];
	status = Tuner_Write(&WriteBytes[0], 4);
	CT_OS_MS_Delay(5);
	
	return TRUE; 	       
}


#if 0//if need, open it
bool8 Check_tuner_lock(void)
{   
    u8 buffer[1];
   
	Tuner_Read(buffer, 1);
	if((buffer[0] !=255)&&(buffer[0] &0x40))
		return	TRUE;
	else
		return	FALSE;
}
#endif

⌨️ 快捷键说明

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