@ -45,20 +45,20 @@
# endif
# if defined(CONFIG_FIREFLY_DEMO_BOARD)
# include "fmio_hw.h"
# include "fmio.h"
# define I2C_USE_MIO
static FMioConfig master_mio_config ;
static FMioCtrl master_mio_ctrl ;
static FMioConfig slave_mio_config ;
static FMioCtrl slave_mio_ctrl ;
# define MASTER_MIO FMIO1_ID
# define SLAVE_MIO FMIO2_ID
# include "fmio_hw.h"
# include "fmio.h"
# define I2C_USE_MIO
static FMioConfig master_mio_config ;
static FMioCtrl master_mio_ctrl ;
static FMioConfig slave_mio_config ;
static FMioCtrl slave_mio_ctrl ;
# define MASTER_MIO FMIO1_ID
# define SLAVE_MIO FMIO2_ID
# elif defined(CONFIG_PD2308_DEMO_BOARD)
# define I2C_USE_CONTROLLER
# define MASTER_I2C_ID FI2C0_ID
# define SLAVE_I2C_ID FI2C1_ID
# define I2C_USE_CONTROLLER
# define MASTER_I2C_ID FI2C0_ID
# define SLAVE_I2C_ID FI2C1_ID
# endif
@ -121,6 +121,8 @@ void FI2cSlaveCb(void *instance_p, void *para, u32 evt)
case FI2C_EVT_SLAVE_WRITE_REQUESTED :
slave_p - > first_write = TRUE ;
break ;
case FI2C_EVT_SLAVE_ABORT :
break ;
default :
break ;
}
@ -153,6 +155,11 @@ void FI2cSlaveWriteRequest(void *instance_p, void *para)
FI2cSlaveCb ( instance_p , para , FI2C_EVT_SLAVE_WRITE_REQUESTED ) ;
}
void FI2cSlaveAbort ( void * instance_p , void * para )
{
FI2cSlaveCb ( instance_p , para , FI2C_EVT_SLAVE_ABORT ) ;
}
# if defined(I2C_USE_MIO)
FError FI2cMioSlaveInit ( u32 address , u32 speed_rate )
{
@ -206,7 +213,7 @@ FError FI2cMioSlaveInit(u32 address, u32 speed_rate)
FI2cSlaveRegisterIntrHandler ( instance_p , FI2C_EVT_SLAVE_READ_REQUESTED , FI2cSlaveReadRequest ) ;
FI2cSlaveRegisterIntrHandler ( instance_p , FI2C_EVT_SLAVE_STOP , FI2cSlaveStop ) ;
FI2cSlaveRegisterIntrHandler ( instance_p , FI2C_EVT_SLAVE_WRITE_REQUESTED , FI2cSlaveWriteRequest ) ;
FI2cSlaveRegisterIntrHandler ( instance_p , FI2C_EVT_SLAVE_ABORT , FI2cSlaveAbort ) ;
u32 cpu_id ;
GetCpuId ( & cpu_id ) ;
InterruptSetTargetCpus ( input_cfg . irq_num , cpu_id ) ;
@ -325,7 +332,7 @@ FError FI2cSlaveInit(u32 address, u32 speed_rate)
FI2cSlaveRegisterIntrHandler ( instance_p , FI2C_EVT_SLAVE_READ_REQUESTED , FI2cSlaveReadRequest ) ;
FI2cSlaveRegisterIntrHandler ( instance_p , FI2C_EVT_SLAVE_STOP , FI2cSlaveStop ) ;
FI2cSlaveRegisterIntrHandler ( instance_p , FI2C_EVT_SLAVE_WRITE_REQUESTED , FI2cSlaveWriteRequest ) ;
FI2cSlaveRegisterIntrHandler ( instance_p , FI2C_EVT_SLAVE_ABORT , FI2cSlaveAbort ) ;
u32 cpu_id ;
GetCpuId ( & cpu_id ) ;
InterruptSetTargetCpus ( input_cfg . irq_num , cpu_id ) ;
@ -453,6 +460,8 @@ FError FI2cSlaveDeinit(void)
# endif
FI2c * instance_p = & slave . device ;
FI2cClearAbort ( instance_p - > config . base_addr ) ; /* 清除错误状态 */
InterruptMask ( instance_p - > config . irq_num ) ;
FI2cDeInitialize ( instance_p ) ;
@ -472,7 +481,8 @@ FError FI2cMasterDeinit(void)
return ret ;
}
# endif
/* disable all i2c irq */
FI2cClearAbort ( master_i2c_instance . config . base_addr ) ; /* 清除错误状态 */
FI2c * instance_p = & master_i2c_instance ;
FI2cDeInitialize ( instance_p ) ;
@ -499,14 +509,14 @@ FError FI2cMasterSlaveExample(void)
ret = FI2cMioSlaveInit ( address , speed_rate ) ;
if ( ret ! = FT_SUCCESS )
{
FI2CMS_ERROR ( " FI2cMioSlaveInit mio_id :%d is error! \n " , SLAVE_MIO ) ;
FI2CMS_ERROR ( " FI2cMioSlaveInit mio_id :%d is error! \n " , SLAVE_MIO ) ;
goto err ;
}
ret = FI2cMioMasterInit ( address , speed_rate ) ;
if ( FT_SUCCESS ! = ret )
{
FI2CMS_ERROR ( " FI2cMioMasterInit mio_id :%d is error! \n " , MASTER_MIO ) ;
FI2CMS_ERROR ( " FI2cMioMasterInit mio_id :%d is error! \n " , MASTER_MIO ) ;
goto err ;
}
# endif
@ -515,14 +525,14 @@ FError FI2cMasterSlaveExample(void)
ret = FI2cSlaveInit ( address , speed_rate ) ;
if ( ret ! = FT_SUCCESS )
{
FI2CMS_ERROR ( " FI2cSlaveInit I2c_id :%d is error! \n " , SLAVE_I2C_ID ) ;
FI2CMS_ERROR ( " FI2cSlaveInit I2c_id :%d is error! \n " , SLAVE_I2C_ID ) ;
goto err ;
}
ret = FI2cMasterInit ( address , speed_rate ) ;
if ( FT_SUCCESS ! = ret )
{
FI2CMS_ERROR ( " FI2cMasterInit I2c_id :%d is error! \n " , MASTER_I2C_ID ) ;
FI2CMS_ERROR ( " FI2cMasterInit I2c_id :%d is error! \n " , MASTER_I2C_ID ) ;
goto err ;
}
# endif
@ -544,19 +554,24 @@ FError FI2cMasterSlaveExample(void)
ret = FI2cMasterRead ( read_buf , input_len , offset ) ;
if ( FI2C_SUCCESS = = ret )
{
printf ( " \r \n Read 0x%x len %d:%s. \r \n " , offset , input_len , read_buf ) ;
printf ( " \r \n Read 0x%x len %d:%s. \r \n " , offset , input_len , read_buf ) ;
FtDumpHexByte ( read_buf , input_len ) ;
}
/* print message on example run result */
err :
ret = FI2cMasterDeinit ( ) ;
if ( FI2C_SUCCESS ! = ret )
if ( ret ! = FT_SUCCESS )
{
FI2CMS_ERROR ( " FI2cMasterDeinit error! \n " ) ;
goto err ;
FI2CMS_ERROR ( " FI2cDdmaMasterDeinit error! \n " ) ;
}
/* print message on example run result */
err :
ret = FI2cSlaveDeinit ( ) ;
if ( ret ! = FT_SUCCESS )
{
FI2CMS_ERROR ( " FI2cSlaveDeinit error! \n " ) ;
}
FIOMuxDeInit ( ) ;
if ( 0 = = ret )
{
printf ( " %s@%d: I2C master-slave example [success] \r \n " , __func__ , __LINE__ ) ;