int i2c_send_slave_address()

in shakti/bsp/drivers/i2c/i2c_driver.c [314:377]


int i2c_send_slave_address(i2c_struct * instance, unsigned char slaveAddress, unsigned char rdWrCntrl, unsigned long delay)
{
	int timeout;
	unsigned char temp = 0;
	int status = 0;

	delay = delay;

	if(rdWrCntrl == 0)
		slaveAddress |= I2C_WRITE;
	else
		slaveAddress |= I2C_READ;

	//Writing the slave address that needs to be written into data register.
	instance->data = slaveAddress;
	log_debug("\tSlave Address 0x%x written into data register\n", slaveAddress);

	//Reads back the data register to confirm
	temp = instance->data; //Reads the slave address from I2C controller

	if(slaveAddress != (int)temp)
	{
		log_error("\tSlave address is not matching; Written Add. Value: 0x%x; Read Add. Value: 0x%x\n", slaveAddress, temp);
		log_error("\n There is some issue in AXI interface. Please check.");
		return EAXI_ERROR;
	}

	//Waits till the bus becomes free.
	while(wait_till_I2c_bus_free(instance))
	{
		log_error("\tError in Waiting for BB\n");
		return EI2C_BUS_ERROR;
	}


	//Send the start condition and slave address to slave
#ifndef USE_SA_WRITE_I2C_INTERRUPT
	instance->control = I2C_START; //Sending the slave address to the I2C slave
	waitfor(90000);
	//Wait for PIN to become low.
	timeout = wait_till_txrx_operation_Completes(instance, &status);
	if (timeout) {//Asking the controller to send a start signal to initiate the transaction
		printf("\tTimeout happened - Write did not go through the BFM -- Diagnose\n");
		instance->control = I2C_STOP; //~
		return EI2C_PIN_ERROR;
	}

	if (status & I2C_LRB) {
		instance->control = I2C_STOP; //~
		printf("\tSome status check failing\n");
		return EI2C_LRB_ERROR;
	}

#else
	i2c_complete_flag = 0;

	instance->control = I2C_START_ENI; //Sending the slave address to the I2C slave
	while(!i2c_complete_flag);
	log_info("\n Slave Address Write Operation is complete.");
	i2c_complete_flag = 0;
#endif

	return I2C_SUCCESS;
}