sharp0302a.c

来自「QPSK Tuner details, for conexant chipset」· C语言 代码 · 共 191 行

C
191
字号
#include "CSQpskCFG.h"
#include "cs_typedef.h"
#include "CSHDI_typedef.h"
#include "cs_i2c.h"
#include "cs_os.h"
#include "cs_frnpublic.h"
#include "cs_qpsk.h"

#define SHARP0302A_TUNER_IF		0
#define SHARP0302A_TUNE_STEP		125
#define SHARP0302A_TUNELIMIT_LOW	900000		// KHz
#define SHARP0302A_TUNELIMIT_HIGH	2200000		// KHz
#define SHARP0302A_BANDFREQREF		1450000		// KHz
#define SHARP0302AADDR		0xc0
#define SHARP0302A_PLLLOCK_MASK	0x40
#define SHARP0302A_PLLLOCK_FLAG	0x40

static HCSHANDLE hSharp0302I2C[MAX_TUNER_NUM];


CSQPSK_Error_t Sharp0302aInit(CSHDITunerIndex enmTunerIndex)
{
	int ErrorCode;

	CX2414XEnableRepeatMode(enmTunerIndex, 1);
	hSharp0302I2C[enmTunerIndex] = 0;
	ErrorCode = CSI2COpen(enmTunerIndex,SHARP0302AADDR,&hSharp0302I2C[enmTunerIndex]);
	if (ErrorCode != CSI2C_SUCCESS)
	{
		return CSQPSK_I2C_ERROR;
	}
	
	return CSQPSK_SUCCESS;
}


CSQPSK_Error_t Sharp0302aTerm(CSHDITunerIndex enmTunerIndex)
{
	int ErrorCode;

	CX2414XEnableRepeatMode(enmTunerIndex, 0);
	ErrorCode = CSI2CClose(hSharp0302I2C[enmTunerIndex]);
	if (ErrorCode != CSI2C_SUCCESS)
	{
		return CSQPSK_I2C_ERROR;
	}
	return CSQPSK_SUCCESS;
}


CSQPSK_Error_t Sharp0302aWrtReg( CSHDITunerIndex enmTunerIndex,BYTE *pubData ,DWORD dwDataLen)
{
	int ErrorCode;

	CX2414XSetRepeatMode(enmTunerIndex);
	if ( CSI2CRequestBus_inner(enmTunerIndex, CSHDI_TIMEOUT_INFINITY) == CSI2C_SUCCESS )
	{
		ErrorCode= CSI2CWriteWithStop (hSharp0302I2C[enmTunerIndex], pubData, dwDataLen ) ;
		if (ErrorCode != CSI2C_SUCCESS)
		{
			CSI2CReleaseBus_inner(enmTunerIndex);
			return CSQPSK_I2C_ERROR;
		}
		CSI2CReleaseBus_inner(enmTunerIndex);
	}
	else
	{
		CSI2CReleaseBus_inner(enmTunerIndex);
	}
	
	return CSQPSK_SUCCESS;
}


CSQPSK_Error_t Sharp0302aGetPLLStatus ( CSHDITunerIndex enmTunerIndex, int *pnPllLock )
{
	BYTE bValue;
	int ret;

	//CSTRACE( INFO_LEVEL, "Sharp0302aGetPLLStatus\r\n");
	CX2414XSetRepeatMode(enmTunerIndex);
	if ( CSI2CRequestBus_inner(enmTunerIndex, CSHDI_TIMEOUT_INFINITY) == CSI2C_SUCCESS )
	{
		bValue = 0;
		ret = CSI2CReadWithStop ( hSharp0302I2C[enmTunerIndex], &bValue, 1 ) ;
		//STV0299DisableTunerI2C(enmTunerIndex);
		CSI2CReleaseBus_inner(enmTunerIndex);
		if (ret == CSI2C_SUCCESS)
		{
			if (( bValue & SHARP0302A_PLLLOCK_MASK ) == SHARP0302A_PLLLOCK_FLAG )
				*pnPllLock = 1;
			else
				*pnPllLock = 0;
			//CSTRACE( INFO_LEVEL, "Sharp0302aGetPLLStatus bValue = 0x%x\r\n", bValue);
			return CSQPSK_SUCCESS;
		}
		else
		{
			return CSQPSK_FAILURE;
		}
	}
	//CSTRACE( INFO_LEVEL, "Sharp0302aGetPLLStatus bValue 2 = 0x%x\r\n", bValue);
	return CSQPSK_I2C_ERROR;
}

void Sharp0302aReset( CSHDITunerIndex enmTunerIndex)
{
	BYTE aucData[4];

	aucData[0] = 0x00;
	aucData[1] = 0x00;
	aucData[2] = 0x80;
	aucData[3] = 0x00;
	
	Sharp0302aWrtReg( enmTunerIndex, aucData, 4);
}

BOOL Sharp0302aCheckTuner(CSHDITunerIndex enmTunerIndex)
{
	BYTE bValue;
	int ret;
	HCSHANDLE hTmpHandle;
	BYTE aucData[4];

	aucData[0] = 0x00;
	aucData[1] = 0x00;
	aucData[2] = 0x80;
	aucData[3] = 0x00;
	
	

	CSI2COpen(enmTunerIndex, 0xc6, &hTmpHandle);

	CX2414XSetRepeatMode(enmTunerIndex);
	if ( CSI2CRequestBus_inner(enmTunerIndex, CSHDI_TIMEOUT_INFINITY) == CSI2C_SUCCESS )
	{
		ret = CSI2CWriteWithStop( hTmpHandle, aucData, 4);
		CSI2CReleaseBus_inner(enmTunerIndex);
		CSI2CClose(hTmpHandle);
		if (ret == CSI2C_SUCCESS)
		{
			return FALSE;			
		}
		else
		{
			return TRUE;;
		}
	}
	CSI2CReleaseBus_inner(enmTunerIndex);
	return FALSE;
	
	
#if 0
	Sharp0302aReset(enmTunerIndex);
	Shart0302aSetFrequency( enmTunerIndex,1400000, 27500) ;
	CX2414XSetRepeatMode(enmTunerIndex);
	if ( CSI2CRequestBus(enmTunerIndex, CSHDI_TIMEOUT_INFINITY) == CSI2C_SUCCESS )
	{
		bValue = 0;
		ret = CSI2CReadWithStop ( hSharp0302I2C[enmTunerIndex], &bValue, 1 ) ;
		CSI2CReleaseBus(enmTunerIndex);
		if (ret == CSI2C_SUCCESS)
		{
			CSTRACE( INFO_LEVEL, "Sharp0302aGetPLLStatus bValue = 0x%x\r\n", bValue);
			if (bValue == 0x48)
			{
				return TRUE;
			}
			else
			{
				return FALSE;
			}
			
		}
		else
		{
			return CSQPSK_FAILURE;
		}
	}
	CSI2CReleaseBus(enmTunerIndex);
	return FALSE;
#endif

}






⌨️ 快捷键说明

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