⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drv_ch_i2c_com.c

📁 ST5100 driver files for ST chipset
💻 C
📖 第 1 页 / 共 3 页
字号:

/*============================================================================*/
/* FUNCTION	::	I2c_Read_Write                                                */
/* ACTION	::	Read/write data from/to the slave                             */
/* PARAMS IN :: mode	->	READ or WRITE                                     */
/*	   			 ChipAddress	->	I2C address of the chip                   */
/*					 Data	->	Buffer containing data to send                */
/*					 NbData	->	Number of data to write/read                  */
/*============================================================================*/
//int AT_I2cReadWriteDbg(unsigned char unitId, int mode, unsigned char ChipAddress, unsigned char *Data, unsigned char NbData, char *file, int line) 
int AT_I2cReadWrite(unsigned char unitId, int mode, unsigned char ChipAddress, unsigned char *Data, unsigned char NbData) 
{

	int error;
	int Result;

	Result = 0;


	I2C_Take_Sem(I2C_BACK);
	if (mode)//WRITE
	{
		if ((ChipAddress == CHANNEL_DEMOD_ADDR0)||(ChipAddress == CHANNEL_DEMOD_ADDR1))
		{
#if defined(CHIPSET_ST)
			//error = DRV_Ch_I2c_Write(unitId, (unsigned long)g_hDEMOD_Ter_I2CHandle[unitId],Data, NbData+1);//  7710_T
			error = DRV_Ch_I2c_Write(unitId, I2C_GET_HANDLE(I2C_BACK,CH_I2C_DEMOD_HANDLEID_SAT),Data, NbData+1);
#elif defined(SUPPORT_NEC_CHIP)
			error = DRV_Ch_I2c_Write(unitId, (unsigned long)unitId,Data, NbData+1);
#else
			PrintError(("[DRV_Ch_I2c_Write()] UNKNOWN CHIP\n\r"));
#endif
			if (error != DDI_CH_I2C_OK)
			{
				PrintError(("[iRegisterWrite[Ter]]DEMOD[%d]: ERRORed: Data[0][0x%02x], Data[1][0x%02x], BYTE[%d]\n", unitId, Data[0], Data[1],NbData+1));
				Result = 1;

			}
			else
			{
			}
		}
		else if ((ChipAddress == CHANNEL_TUNER_ADDR0)||(ChipAddress == CHANNEL_TUNER_ADDR1))
		{

#if defined(CHIPSET_ST)
			//  7710_T error = DRV_Ch_I2c_Write(unitId, (unsigned long)g_hTUNER_Ter_I2CHandle[unitId],Data, NbData);
			error = DRV_Ch_I2c_Write(unitId, I2C_GET_HANDLE(I2C_BACK,CH_I2C_TUNER_HANDLEID_SAT),Data, NbData);
#elif defined(SUPPORT_NEC_CHIP)
			error = DRV_Ch_Tuner_I2c_Write(unitId, (unsigned long)unitId,Data, NbData);
#else
			PrintError(("[DRV_Ch_I2c_Write()] UNKNOWN CHIP\n\r"));
#endif
			if (error != DDI_CH_I2C_OK)
			{
				PrintError(("[iRegisterWrite[Ter]]TUNER[%d]: ERRORed: Data[0][0x%02x], Data[1][0x%02x]\n",unitId, Data[0], Data[1]));
				Result = 1;
			}
			else
			{
			}
		}
		else
		{
			Result = 1;
		}
	}
	else//READ
	{
		if ((ChipAddress == CHANNEL_DEMOD_ADDR0)||(ChipAddress == CHANNEL_DEMOD_ADDR1))
		{
			/* I2C access */
#if defined(CHIPSET_ST)
			//  7710_T error = DRV_Ch_I2c_Write(unitId, (unsigned long)g_hDEMOD_Ter_I2CHandle[unitId], &Data[0], 1);
			//  7710_T error = DRV_Ch_I2c_Read(unitId, (unsigned long)g_hDEMOD_Ter_I2CHandle[unitId], &Data[1], NbData);
			error = DRV_Ch_I2c_Write(unitId, I2C_GET_HANDLE(I2C_BACK,CH_I2C_DEMOD_HANDLEID_SAT), &Data[0], 1);
			error = DRV_Ch_I2c_Read(unitId, I2C_GET_HANDLE(I2C_BACK,CH_I2C_DEMOD_HANDLEID_SAT), &Data[1], NbData);
#elif defined(SUPPORT_NEC_CHIP)
			error = DRV_Ch_I2c_Read(unitId, (unsigned long)unitId, &Data[0], (NbData+1));
#else
			PrintError(("[DRV_Ch_I2c_Write()] UNKNOWN CHIP\n\r"));
#endif
			if (error != DDI_CH_I2C_OK)
			{
				Result = 1;
				SSS_DBG(TMP1,_ERROR_,("[iRegisterRead[Ter]]DEMOD: ERRORed: Data[0][0x%02x], Data[1][0x%02x]\n", Data[0], Data[1]));
			}
			else
			{
			}
		}
		else if ((ChipAddress == CHANNEL_TUNER_ADDR0)||(ChipAddress == CHANNEL_TUNER_ADDR1))
		{
#if defined(CHIPSET_ST)
			//  7710_T error = DRV_Ch_I2c_Read(unitId, (unsigned long)g_hTUNER_Ter_I2CHandle[unitId],Data, 1);
			error = DRV_Ch_I2c_Read(unitId, I2C_GET_HANDLE(I2C_BACK,CH_I2C_TUNER_HANDLEID_SAT),Data, 1);
#elif defined(SUPPORT_NEC_CHIP)
			error = DRV_Ch_Tuner_I2c_Read(unitId, (unsigned long)unitId,Data, 1);
#else
			PrintError(("[DRV_Ch_I2c_Write()] UNKNOWN CHIP\n\r"));
#endif
			if (error != DDI_CH_I2C_OK)
			{
				Result = 1;
				PrintError(("[iRegisterRead[Ter]]TUNER: ERRORed: Data[0][0x%02x], Data[1][0x%02x]\n", Data[0], Data[1]));
			}
			else
			{
			}
		}
		else
		{
			Result = 1;
		}
	}
	I2C_Release_Sem(I2C_BACK);
	//semaphore_signal(&semI2CAccess);

	return Result;
}








#if 0
/*=============================================================================
	Function	: ofdm_write
	Description	: Just one byte write 窃荐
	Input		:
	Output		:
	Return		: FALSE if error, TRUE if success
=============================================================================*/

unsigned char ofdm_write(unsigned char ui8UnitId, unsigned char ui8RegAddress, unsigned char ui8RegData)
{
	MMAC_IIC_RESULT_CODE iicResult=MMAC_IIC_OK;
	MMAC_IIC_WRITE_IOPB iopb;

	iopb.deviceNumber = ui8NimDemodUnit[ui8UnitId];
	iopb.slaveAddr = ui8NimDemodAddress[ui8UnitId];
	iopb.subAddr = (UI32)ui8RegAddress;
	iopb.data = &ui8RegData;
	iopb.length = 0x01;
	iopb.timeout = DRV_CH_IIC_TIMEOUT;
	iopb.numSubAddressBytes = MMAC_IIC_ONE_BYTE_ADDRESSING;
	iicResult = MMAC_IIC_Write( &iopb );
	if( iicResult != MMAC_IIC_OK )
	{
		DDI_UART_Print("[ofdm_write] Error(0x%x) from MMAC_IIC_Write()\n\r", iicResult);
	}
	return (unsigned char)iicResult;
} /* end of ofdm_write */

/*=============================================================================
	Function	: ofdm_read
	Description	: Just one byte read 窃荐
	Input		:
	Output		:
	Return		: FALSE if error, TRUE if success
=============================================================================*/

unsigned char ofdm_read(unsigned char ui8UnitId, unsigned char ui8RegAddress, unsigned char *lpRegData)
{
	MMAC_IIC_RESULT_CODE iicResult=MMAC_IIC_OK;
	MMAC_IIC_READ_IOPB iopb;

	iopb.deviceNumber = ui8NimDemodUnit[ui8UnitId];
	iopb.slaveAddr = ui8NimDemodAddress[ui8UnitId];
	iopb.subAddr = (UI32)ui8RegAddress;
	iopb.data = lpRegData;
	iopb.length = 0x01;
	iopb.timeout = DRV_CH_IIC_TIMEOUT;
	iopb.numSubAddressBytes = MMAC_IIC_ONE_BYTE_ADDRESSING;
	iicResult = MMAC_IIC_Read( &iopb ); 
	if( iicResult != MMAC_IIC_OK )
	{
		DDI_UART_Print("[ofdm_read] Error(0x%x) from MMAC_IIC_Read()\n\r", iicResult);
	}
	return (unsigned char)iicResult;
} /* end of ofdm_read */

/*=============================================================================
	Function	: analogif_write
	Description	: Just one byte write 窃荐
	Input		:
	Output		:
	Return		: FALSE if error, TRUE if success
=============================================================================*/

unsigned char analogif_write(unsigned char ui8UnitId, unsigned char ui8RegAddress, unsigned char ui8RegData)
{
	MMAC_IIC_RESULT_CODE iicResult=MMAC_IIC_OK;
	MMAC_IIC_WRITE_IOPB iopb;

	iopb.deviceNumber = ui8NimAnalogIFUnit[ui8UnitId];
	iopb.slaveAddr = ui8NimAnalogIFAddress[ui8UnitId];
	iopb.subAddr = (UI32)ui8RegAddress;
	iopb.data = &ui8RegData;
	iopb.length = 0x01;
	iopb.timeout = DRV_CH_IIC_TIMEOUT;
	iopb.numSubAddressBytes = MMAC_IIC_ONE_BYTE_ADDRESSING;
	iicResult = MMAC_IIC_Write( &iopb );
	if( iicResult != MMAC_IIC_OK )
	{
		DDI_UART_Print("[analogIF_write] Error(0x%x) from MMAC_IIC_Write()\n\r", iicResult);
	}
	return (unsigned char)iicResult;
} /* end of analogif_write */

/*=============================================================================
	Function	: analogif_read
	Description	: Just one byte read 窃荐
	Input		:
	Output		:
	Return		: FALSE if error, TRUE if success
=============================================================================*/

unsigned char analogif_read(unsigned char ui8UnitId, unsigned char *lpRegData)
{
	MMAC_IIC_RESULT_CODE iicResult=MMAC_IIC_OK;
	MMAC_IIC_READ_IOPB iopb;

	iopb.deviceNumber = ui8NimAnalogIFUnit[ui8UnitId];
	iopb.slaveAddr = ui8NimAnalogIFAddress[ui8UnitId];
	iopb.subAddr = 0;
	iopb.data = lpRegData;
	iopb.length = 0x01;
	iopb.timeout = DRV_CH_IIC_TIMEOUT;
	iopb.numSubAddressBytes = MMAC_IIC_ZERO_BYTE_ADDRESSING;
	iicResult = MMAC_IIC_Read( &iopb ); 
	if( iicResult != MMAC_IIC_OK )
	{
		DDI_UART_Print("[analogif_read] Error(0x%x) from MMAC_IIC_Read()\n\r", iicResult);
	}
	return (unsigned char)iicResult;
} /* end of analogif_read */


/*=============================================================================
	Function	: TunerIicTx
	Description	: Just 7 byte tuner write窃荐
	Input		:
	Output		:
	Return		: FALSE if error, TRUE if success
=============================================================================*/
unsigned char	TunerIicTx(unsigned char ui8UnitId, unsigned char ui8Length, unsigned char *ptunerWriteData)
{
	MMAC_IIC_RESULT_CODE iicResult=MMAC_IIC_OK;
	MMAC_IIC_WRITE_IOPB iopb;

	iopb.deviceNumber = ui8NimTunerUnit[ui8UnitId];
	iopb.slaveAddr = ui8NimTunerAddress[ui8UnitId];
	iopb.subAddr = 0;
	iopb.data = ptunerWriteData;
	iopb.length = ui8Length;
	iopb.timeout = DRV_CH_IIC_TIMEOUT;
	iopb.numSubAddressBytes = MMAC_IIC_ZERO_BYTE_ADDRESSING;
	iicResult = MMAC_IIC_Write( &iopb );
	if( iicResult != MMAC_IIC_OK )
	{
		DDI_UART_Print("[TunerIicTx] Error(0x%x) from MMAC_IIC_Write()\n\r", iicResult);
	}
	/* Maybe too long??*/
	MMAC_RTOS_Sleep(MMAC_RTOS_MSEC_TO_TICKS(10));

	return (unsigned char)iicResult;
}

/*=============================================================================
	Function	: TunerIicRx
	Description	: 
	Input		:
	Output		:
	Return		: FALSE if error, TRUE if success
=============================================================================*/
unsigned char	TunerIicRx(unsigned char ui8UnitId, unsigned char *ptunerReadData)
{
	MMAC_IIC_RESULT_CODE iicResult=MMAC_IIC_OK;
	MMAC_IIC_READ_IOPB iopb;

	iopb.deviceNumber = ui8NimTunerUnit[ui8UnitId];
	iopb.slaveAddr = ui8NimTunerAddress[ui8UnitId];
	iopb.subAddr = 0;
	iopb.data = ptunerReadData;
	iopb.length = 0x1;
	iopb.timeout = DRV_CH_IIC_TIMEOUT;
	iopb.numSubAddressBytes = MMAC_IIC_ZERO_BYTE_ADDRESSING;
	iicResult = MMAC_IIC_Read( &iopb );
	if( iicResult != MMAC_IIC_OK )
	{
		DDI_UART_Print("[TunerIicRx] Error(0x%x) from MMAC_IIC_Read()\n\r", iicResult);
	}
	/* Maybe too long??*/
	MMAC_RTOS_Sleep(MMAC_RTOS_MSEC_TO_TICKS(10));

	return (unsigned char)iicResult;
}
/*=============================================================================
	Function	: drv_i2c_Write
	Description	: DSP Code download侩
	Input		:
	Output		:
	Return		: FALSE if error, TRUE if success
=============================================================================*/

unsigned char drv_i2c_Write(unsigned char ui8UnitId, unsigned char Buffer[], unsigned char SubAddr, unsigned short NumberToWrite)
{
	MMAC_IIC_RESULT_CODE iicResult=MMAC_IIC_OK;
	MMAC_IIC_WRITE_IOPB iopb;

	DDI_UART_Print("[drv_i2c_Write] (unitId %d)(buffer 0x%x)(subAddr 0x%x)(numToWrite 0x%x)\n\r", ui8UnitId, Buffer, SubAddr, NumberToWrite);
	iopb.deviceNumber = ui8NimDemodUnit[ui8UnitId];
	iopb.slaveAddr = ui8NimDemodAddress[ui8UnitId];
	iopb.subAddr = SubAddr;
	iopb.data = Buffer;
	iopb.length = NumberToWrite;
	iopb.timeout = DRV_CH_IIC_TIMEOUT*10;
	iopb.numSubAddressBytes = MMAC_IIC_ONE_BYTE_ADDRESSING;
	iicResult = MMAC_IIC_Write( &iopb );
	if( iicResult != MMAC_IIC_OK )
	{
		DDI_UART_Print("[drv_i2c_Write] Error(0x%x) from MMAC_IIC_Write()\n\r", iicResult);
	}

	return (unsigned char)iicResult;
} /* end of drv_i2c_Write */
#else
/*=============================================================================
	Function	: ofdm_write
	Description	: Just one byte write 窃荐
	Input		:
	Output		:
	Return		: FALSE if error, TRUE if success
=============================================================================*/
unsigned char ofdm_write(unsigned char ui8UnitId, unsigned char ui8RegAddress, unsigned char ui8RegData)
{
	unsigned char Data[2];
	unsigned char Result;
	unsigned char ChipAddress;
	Data[0] = ui8RegAddress;
	Data[1] = ui8RegData;

	if (ui8UnitId == 0)
		ChipAddress = CHANNEL_DEMOD_ADDR0;
	if (ui8UnitId == 1)
		ChipAddress = CHANNEL_DEMOD_ADDR1;

	//Result = (unsigned char)AT_I2cReadWrite(ui8UnitId, 1, ChipAddress, Data, 2);
	return Result;
} /* end of ofdm_write */

/*=============================================================================
	Function	: ofdm_read
	Description	: Just one byte read 窃荐
	Input		:
	Output		:
	Return		: FALSE if error, TRUE if success
=============================================================================*/
unsigned char ofdm_read(unsigned char ui8UnitId, unsigned char ui8RegAddress, unsigned char *lpRegData)
{
	unsigned char Data[2];
	unsigned char Result;
	unsigned char ChipAddress;
	Data[0] = ui8RegAddress;
	Data[1] = 0;

	if (ui8UnitId == 0)
		ChipAddress = CHANNEL_DEMOD_ADDR0;
	if (ui8UnitId == 1)
		ChipAddress = CHANNEL_DEMOD_ADDR1;


	//Result = (unsigned char)AT_I2cReadWrite(ui8UnitId, 0, ChipAddress, Data, 2);
	*lpRegData = Data[1];
	return Result;
} /* end of ofdm_read */

#endif


int	DRV_CH_Set_Type(unsigned char unitId, unsigned long type, unsigned char addrIndex)
{
	unsigned long	demodAddr;
	unsigned long	tunerAddr;
	unsigned char	deviceId;
	PrintInfo((">>> [DRV_CH_Set_Type] Type:[%x] orderIndex:[%x]\n", type, addrIndex));
	switch(type)
	{
		case DDI_CHANNEL_TYPE_TER:
			switch(addrIndex)
			{
				case 1:
					demodAddr = CHANNEL_DEMOD_ADDR1;
					tunerAddr = CHANNEL_TUNER_ADDR1;
					break;
				case 0:
				default:
					demodAddr = CHANNEL_DEMOD_ADDR0;
					tunerAddr = CHANNEL_TUNER_ADDR0;
					break;
			}
			deviceId = DDI_CH_I2C_DEVICEID;
			break;
		case DDI_CHANNEL_TYPE_SAT:
			switch(addrIndex)
			{
				case 1:
					demodAddr = CHANNEL_DEMOD_ADDR;
					tunerAddr = CHANNEL_TUNER_ADDR;
					break;
				case 0:
				default:
					demodAddr = CHANNEL_DEMOD_ADDR;
					tunerAddr = CHANNEL_TUNER_ADDR;
					break;
			}
			deviceId = DDI_CH_I2C_DEVICEID;
			break;
		default:
            PrintError(("[DRV_CH_Set_Type] Fails Unknown Type:[%x] orderIndex:[%x]\n", type, addrIndex));
			break;
	}

	g_hI2c_DeviceId[unitId] = deviceId;
	g_hDemod_I2c_Addr[unitId] = demodAddr;
	g_hTuner_I2c_Addr[unitId] = tunerAddr;

	return 0;
}

⌨️ 快捷键说明

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