XilinxProcessorIPLib/drivers/iic/examples/xiic_multi_master_example.c
int IicMultiMasterExample(void)
{
	u8 Index;
	int Status;
	XIic_Config *ConfigPtr;	/* Pointer to configuration data */
	AddressType Address = EEPROM_TEST_START_ADDRESS;

	/*
	 * Initialize the data to write and the read buffer.
	 */
	if (sizeof(Address) == 1) {
		WriteBuffer[0] = (u8) (Address);
	}
	else {
		WriteBuffer[0] = (u8) (Address >> 8);
		WriteBuffer[1] = (u8) (Address);
	}
	for (Index = 0; Index < PAGE_SIZE; Index++) {
		WriteBuffer[sizeof(Address) + Index] = 0xFF;
	}

	/*
	 * Include the multi master functionality.
	 */
	XIic_MultiMasterInclude();

	/*
	 * Initialize the IIC driver so that it is ready to use.
	 */
	ConfigPtr = XIic_LookupConfig(XPAR_IIC_0_DEVICE_ID);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}

	Status = XIic_CfgInitialize(&IicInstance, ConfigPtr,
					ConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}


	/*
	 * Setup the Interrupt System.
	 */
	Status = SetupInterruptSystem(&IicInstance);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Set the Transmit and status handlers.
	 */
	XIic_SetSendHandler(&IicInstance, &IicInstance,
				(XIic_Handler) SendHandler);
	XIic_SetStatusHandler(&IicInstance, &IicInstance,
				  (XIic_StatusHandler) StatusHandler);

	/*
	 * Set the address of the slave.
	 */
	Status = XIic_SetAddress(&IicInstance, XII_ADDR_TO_SEND_TYPE,
				 EEPROM_ADDRESS);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	IicInstance.Stats.TxErrors = 0;
	/*
	 * Set the defaults.
	 */
	TransmitComplete = 1;

	/*
	 * Start the IIC device.
	 */
	Status = XIic_Start(&IicInstance);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Write to the EEPROM.
	 */
	XIic_MasterSend(&IicInstance, WriteBuffer, PAGE_SIZE);

	while (1) {
		/*
		 * If arbitration is lost and some time later Bus if bus
		 * becomes free transmit the data.
		 */
		if (BusNotBusy) {
			/*
			 * Start the IIC device.
			 */
			Status = XIic_Start(&IicInstance);
			if (Status != XST_SUCCESS) {
				return XST_FAILURE;
			}

			/*
			 * Send the data.
			 */
			XIic_MasterSend(&IicInstance, WriteBuffer, PAGE_SIZE);

			/*
			 * Clear the Flag.
			 */
			BusNotBusy = 0;
		}

		/*
		 * This condition is required to be checked in the case where we
		 * are writing two consecutive buffers of data to the EEPROM.
		 * The EEPROM takes about 2 milliseconds time to update the data
		 * internally after a STOP has been sent on the bus.
		 * A NACK will be generated in the case of a second write before
		 * the EEPROM updates the data internally resulting in a
		 * Transmission Error.
		 */
		if (IicInstance.Stats.TxErrors != 0) {
			/*
			 * If the Slave didn't acknowledge then we should keep
			 * making attempts to transmit the data.
			 */
			IicInstance.Stats.TxErrors = 0;
			/*
			 * Start the IIC device.
			 */
			Status = XIic_Start(&IicInstance);
			if (Status != XST_SUCCESS) {
				return XST_FAILURE;
			}

			/*
			 * Send the data.
			 */
			XIic_MasterSend(&IicInstance, WriteBuffer, PAGE_SIZE);
		}

		if ((!TransmitComplete) &&
			(XIic_IsIicBusy(&IicInstance) == FALSE))
			break;
	}

	/*
	 * Stop the IIC device.
	 */
	Status = XIic_Stop(&IicInstance);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
* This function writes the data to the IIC EEPROM.
*
*
* @return	XST_SUCCESS if successful else XST_FAILURE.
*
* @note		None.
*
****************************************************************************/
This function writes the data to the IIC EEPROM.
This function writes the data to the IIC EEPROM .
int IicMultiMasterExample(void)
{
	u8 Index;
	int Status;
	XIic_Config *ConfigPtr;	
	AddressType Address = EEPROM_TEST_START_ADDRESS;
	if (sizeof(Address) == 1) {
		WriteBuffer[0] = (u8) (Address);
	}
	else {
		WriteBuffer[0] = (u8) (Address >> 8);
		WriteBuffer[1] = (u8) (Address);
	}
	for (Index = 0; Index < PAGE_SIZE; Index++) {
		WriteBuffer[sizeof(Address) + Index] = 0xFF;
	}
	XIic_MultiMasterInclude();
	ConfigPtr = XIic_LookupConfig(XPAR_IIC_0_DEVICE_ID);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	Status = XIic_CfgInitialize(&IicInstance, ConfigPtr,
					ConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = SetupInterruptSystem(&IicInstance);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XIic_SetSendHandler(&IicInstance, &IicInstance,
				(XIic_Handler) SendHandler);
	XIic_SetStatusHandler(&IicInstance, &IicInstance,
				  (XIic_StatusHandler) StatusHandler);
	Status = XIic_SetAddress(&IicInstance, XII_ADDR_TO_SEND_TYPE,
				 EEPROM_ADDRESS);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	IicInstance.Stats.TxErrors = 0;
	TransmitComplete = 1;
	Status = XIic_Start(&IicInstance);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XIic_MasterSend(&IicInstance, WriteBuffer, PAGE_SIZE);
	while (1) {
		if (BusNotBusy) {
			Status = XIic_Start(&IicInstance);
			if (Status != XST_SUCCESS) {
				return XST_FAILURE;
			}
			XIic_MasterSend(&IicInstance, WriteBuffer, PAGE_SIZE);
			BusNotBusy = 0;
		}
		if (IicInstance.Stats.TxErrors != 0) {
			IicInstance.Stats.TxErrors = 0;
			Status = XIic_Start(&IicInstance);
			if (Status != XST_SUCCESS) {
				return XST_FAILURE;
			}
			XIic_MasterSend(&IicInstance, WriteBuffer, PAGE_SIZE);
		}
		if ((!TransmitComplete) &&
			(XIic_IsIicBusy(&IicInstance) == FALSE))
			break;
	}
	Status = XIic_Stop(&IicInstance);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	return XST_SUCCESS;
}
int IicMultiMasterExample ( void ) { u8 Index ; int Status ; XIic_Config * ConfigPtr ; AddressType Address = EEPROM_TEST_START_ADDRESS ; if ( sizeof ( Address ) == 1 ) { WriteBuffer [ 0 ] = ( u8 ) ( Address ) ; } else { WriteBuffer [ 0 ] = ( u8 ) ( Address >> 8 ) ; WriteBuffer [ 1 ] = ( u8 ) ( Address ) ; } for ( Index = 0 ; Index < PAGE_SIZE ; Index ++ ) { WriteBuffer [ sizeof ( Address ) + Index ] = 0xFF ; } XIic_MultiMasterInclude ( ) ; ConfigPtr = XIic_LookupConfig ( XPAR_IIC_0_DEVICE_ID ) ; if ( ConfigPtr == NULL ) { return XST_FAILURE ; } Status = XIic_CfgInitialize ( & IicInstance , ConfigPtr , ConfigPtr -> BaseAddress ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = SetupInterruptSystem ( & IicInstance ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XIic_SetSendHandler ( & IicInstance , & IicInstance , ( XIic_Handler ) SendHandler ) ; XIic_SetStatusHandler ( & IicInstance , & IicInstance , ( XIic_StatusHandler ) StatusHandler ) ; Status = XIic_SetAddress ( & IicInstance , XII_ADDR_TO_SEND_TYPE , EEPROM_ADDRESS ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } IicInstance . Stats . TxErrors = 0 ; TransmitComplete = 1 ; Status = XIic_Start ( & IicInstance ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XIic_MasterSend ( & IicInstance , WriteBuffer , PAGE_SIZE ) ; while ( 1 ) { if ( BusNotBusy ) { Status = XIic_Start ( & IicInstance ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XIic_MasterSend ( & IicInstance , WriteBuffer , PAGE_SIZE ) ; BusNotBusy = 0 ; } if ( IicInstance . Stats . TxErrors != 0 ) { IicInstance . Stats . TxErrors = 0 ; Status = XIic_Start ( & IicInstance ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XIic_MasterSend ( & IicInstance , WriteBuffer , PAGE_SIZE ) ; } if ( ( ! TransmitComplete ) && ( XIic_IsIicBusy ( & IicInstance ) == FALSE ) ) break ; } Status = XIic_Stop ( & IicInstance ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } return XST_SUCCESS ; }
This function writes the data to the IIC EEPROM.
This function writes the data to the IIC EEPROM .
/* Pointer to configuration data */ /*
	 * Initialize the data to write and the read buffer.
	 */ /*
	 * Include the multi master functionality.
	 */ /*
	 * Initialize the IIC driver so that it is ready to use.
	 */ /*
	 * Setup the Interrupt System.
	 */ /*
	 * Set the Transmit and status handlers.
	 */ /*
	 * Set the address of the slave.
	 */ /*
	 * Set the defaults.
	 */ /*
	 * Start the IIC device.
	 */ /*
	 * Write to the EEPROM.
	 */ /*
		 * If arbitration is lost and some time later Bus if bus
		 * becomes free transmit the data.
		 */ /*
			 * Start the IIC device.
			 */ /*
			 * Send the data.
			 */ /*
			 * Clear the Flag.
			 */ /*
		 * This condition is required to be checked in the case where we
		 * are writing two consecutive buffers of data to the EEPROM.
		 * The EEPROM takes about 2 milliseconds time to update the data
		 * internally after a STOP has been sent on the bus.
		 * A NACK will be generated in the case of a second write before
		 * the EEPROM updates the data internally resulting in a
		 * Transmission Error.
		 */ /*
			 * If the Slave didn't acknowledge then we should keep
			 * making attempts to transmit the data.
			 */ /*
			 * Start the IIC device.
			 */ /*
			 * Send the data.
			 */ /*
	 * Stop the IIC device.
	 */