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

📄 i2c_api.c

📁 三星ic 9980的源代码. 718版.
💻 C
📖 第 1 页 / 共 2 页
字号:
	}

	IO_WData32_EX((unsigned char *)& rI2CDS_H,0,data);
	/* Pending clear : Restart operation */
	temp2=IO_RData32_EX((unsigned char *)&rI2CCON_H);	
	temp2 |=I2C_PENDING;
	IO_WData32_EX((unsigned char *)& rI2CCON_H,0,temp2);
}	

/******************************************************************************
 * Function name  : I2C_ReadByte                                              *
 * Revision       : 0.0                                                       *
 * Arguments      : void                                                      *
 * Return         : void                                                      *
 * By             :                                                           *
 * Description    :                                                           *
 *****************************************************************************/
UCHAR I2C_ReadByte(void)
{
	ULONG temp2;

	I2C_CheckComplete();
	/* Pending clear : Restart operation */
	temp2=IO_RData32_EX((unsigned char *)&rI2CCON_H);	
	temp2 |=I2C_PENDING;
	IO_WData32_EX((unsigned char *)& rI2CCON_H,0,temp2);

	I2C_CheckComplete();
	
	return((unsigned char)rI2CDS_L);
}	

/******************************************************************************
 * Function name  : I2C_ReadMode                                              *
 * Revision       : 0.0                                                       *
 * Arguments      : void                                                      *
 * Return         : void                                                      *
 * By             :                                                           *
 * Description    :                                                           *
 *****************************************************************************/
void I2C_ReadMode(UCHAR word_address)
{
	ULONG temp1,temp2;

	I2C_CheckComplete();

	IO_WData32_EX((unsigned char *)& rI2CDS_H,0,word_address);
	temp1 = (I2C_MasterRx <<6) | (I2C_CmdSTART <<5) | I2C_Enable; 
					/* Master Rx mode, ReStart condition, Rx/Tx Enable */
	IO_WData32_EX((unsigned char *)& rI2CSTAT_H,0,temp1);
	
	temp2=IO_RData32_EX((unsigned char *)&rI2CCON_H);	
	temp2 |=I2C_PENDING;
	IO_WData32_EX((unsigned char *)& rI2CCON_H,0,temp2);
}	

/******************************************************************************
 * Function name  : I2C_RandomByteWrite
 * Arguments      : void
 * Return         : void
 * By             :
 * Description    :
 *****************************************************************************/
void I2C_RandomByteWrite( UCHAR slave_add, 
									 UCHAR word_add, 
									 UCHAR data)
{	
	I2C_Initilize();
	I2C_SlaveAddress(slave_add, word_add);
	I2C_WriteByte(data);
	I2C_Stop();
 	I2C_WriteBusyChk(slave_add);
}

#if 0
/******************************************************************************
 * Function name  : I2C_PageWrite
 * Arguments      : void
 * Return         : void
 * By             :
 * Description    :
 *****************************************************************************/
void I2C_PageWrite( UCHAR slave_add, 
						   UCHAR word_add, 
						   UCHAR write_num, 
						   UCHAR *data_ptr)
{	
	UCHAR i;
	
	I2C_Initilize();
	
	I2C_SlaveAddress(slave_add, word_add);

	for(i=0; i<write_num; i++){
	I2C_WriteByte(*(data_ptr+i));
	}

	I2C_Stop();
}
#endif
/******************************************************************************
 * Function name  : I2C_RandomByteRead
 * Arguments      : void
 * Return         : void
 * By             :
 * Description    :
 *****************************************************************************/
UCHAR I2C_RandomByteRead(UCHAR slave_add, UCHAR word_add)
{	
	UCHAR	data;
	I2C_Initilize();
	I2C_SlaveAddress(slave_add, word_add);
	I2C_ReadMode(slave_add);
	data=I2C_ReadByte();
	I2C_Stop();
	return(data);
}

/******************************************************************************
 * Function name  : I2C_CurrentRead
 * Arguments      : void
 * Return         : void
 * By             :
 * Description    :
 *****************************************************************************/
#if 0
UCHAR I2C_CurrentRead(UCHAR slave_add)
{	
	UCHAR	data;
	I2C_Initilize();
	rI2CDS = slave_add;
	rI2CSTAT = (I2C_MasterRx <<6) | (I2C_CmdSTART <<5) | I2C_Enable; 
					/* Master Rx mode, ReStart condition, Rx/Tx Enable */
	data=I2C_ReadByte();
	I2C_Stop();
	return(data);
}
#endif
/******************************************************************************
 * Function name  : I2C_SequentialRead
 * Arguments      : void
 * Return         : void
 * By             :
 * Description    :
 *****************************************************************************/
#if 0
void 	I2C_SequentialRead( UCHAR slave_add, 
									 UCHAR read_num, 
									 UCHAR *data_ptr)
{	
	UCHAR	num;
	UCHAR	data;
	I2C_Initilize();
	rI2CDS = slave_add;
	rI2CSTAT = (I2C_MasterRx <<6) | (I2C_CmdSTART <<5) | I2C_Enable; 
					/* Master Rx mode, ReStart condition, Rx/Tx Enable */

	rI2CCON  =  (1 << I2C_ACK) | (1 << I2C_512CK) | I2C_PRESCALE ;		/* ACK Enable */
	for(num=0; num<read_num-1; num++){
	data=I2C_ReadByte();
	*data_ptr++=data;
		SysPrintf("\n I2C Read Data =  : 0x%x ", data); 
	}

	rI2CCON  =  (0 << I2C_ACK) | (1 << I2C_512CK) | I2C_PRESCALE ;		/* ACK Disable */
	data=I2C_ReadByte();
	*data_ptr++=data;

	I2C_Stop();
}

/******************************************************************************
 * Function name  : I2C_PageRead
 * Arguments      : void
 * Return         : void
 * By             :
 * Description    :
 *****************************************************************************/
void 	I2C_PageRead( UCHAR slave_add, 
							  UCHAR word_add, 
							  UCHAR read_num, 
							  UCHAR *data_ptr)
{	
	UCHAR	num;
	UCHAR	data;
	
	I2C_Initilize();
	I2C_SlaveAddress(slave_add, word_add); /* Master Rx mode, ReStart condition, Rx/Tx Enable */
	I2C_ReadMode(slave_add);
					
	rI2CCON  =  (1 << I2C_ACK) | (1 << I2C_512CK) | I2C_PRESCALE ;		/* ACK Enable */
	for(num=0; num<read_num-1; num++){
	data=I2C_ReadByte();
	*data_ptr++=data;
	}

	rI2CCON  =  (0 << I2C_ACK) | (1 << I2C_512CK) | I2C_PRESCALE ;		/* ACK Disable */
	data=I2C_ReadByte();
	*data_ptr++=data;

	I2C_Stop();
}
#endif
/*------------------------------------------------------------------------------*/
/******************************************************************************
 * Function name  : I2C_CheckComplete
 * Arguments      : void
 * Return         : void
 * By             :
 * Description    :
 *****************************************************************************/
 void I2C_CheckComplete(void)
{
	UINT	timeout = I2C_TIMEOUT_PENDING_CHECK;
	
	while(1){
		if(rI2CCON_L & I2C_PENDING)
		{
			if(rI2CSTAT_L & 0x8)
			{	
				// Arbitration Fail
				IO_WData32_EX((unsigned char *)& rI2CCON_H,0,I2C_PENDING);
				// SysPrintf("\n[I2C] I2C Bus arbitration fail ");
			}
			else if(rI2CSTAT_L & 0x4)
			{
				// Address-as-slave status
				IO_WData32_EX((unsigned char *)& rI2CCON_H,0,I2C_PENDING);
				// SysPrintf("\n[I2C] I2C Fatal Error ");
			}
			else
			{
				// transmit or receive operation is completed.
				break;
			}
		}
		else
		{
			/* Previous transfer finish check */
			// Previous transfer finish check :Cycle time = 80us
			timeout--;
			if( timeout == 0 )
			{
				//SysPrintf("\n[I2C] I2C_Operation fail:Check ");
				break;
			}

			I2C_DelayForWait();
		}
	}
}

//maymeng 051011 added
UCHAR SL_readEepromByte ( UCHAR	addr )
{
	UCHAR data;

//	SysGetSema( &gSema_eeprom, SYS_WAIT );

	data = I2C_RandomByteRead( EEPROM_ADDRESS, addr);

//	SysReleaseSema( &gSema_eeprom );
	return ( data );
}

void SL_writeEepromByte( UCHAR	addr, UCHAR data )
{

//	SysGetSema( &gSema_eeprom, SYS_WAIT );

	I2C_RandomByteWrite(EEPROM_ADDRESS, addr, data);

//	SysReleaseSema( &gSema_eeprom );
}

#if 0
void eeprom_recored_msf(void)
{
	if(MP3_DISC== GetDiscType())
		{
			SL_writeEepromByte( EEPROM_MP3FILE_CNT, (UCHAR)cn );
			SL_writeEepromByte( EEPROM_MP3DIR_CNT, (UCHAR)cn );
			SL_writeEepromByte( EEPROM_MP3DIR_NOW, (UCHAR)cn );
			SL_writeEepromByte( EEPROM_MP3TRK_NOW, (UCHAR)cn );
		}
	else if((VCD_DISC == GetDiscType())|| (CD_DA== GetDiscType()))
		{
			SL_writeEepromByte( EEPROM_PLAY_TRK, (UCHAR)cn );
			SL_writeEepromByte( EEPROM_PLAY_MIN, (UCHAR)cn );
			SL_writeEepromByte( EEPROM_PLAY_SEC, (UCHAR)cn );
			SL_writeEepromByte( EEPROM_PLAY_FRM, (UCHAR)cn );
		}
	else
		return;
}
#endif


⌨️ 快捷键说明

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