XilinxProcessorIPLib/drivers/iicps/examples/xiicps_intr_multi_master_example.c
s32 IicPsMultiMasterIntrExample(u16 DeviceId)
{
	s32 Status;
	XIicPs_Config *Config;
	s32 Index;
	s32 tmp;
	s32 BufferSizes[NUMBER_OF_SIZES] = {1, 2, 19, 31, 32, 33, 62, 63, 64,
	65, 66, 94, 95, 96, 97, 98, 99, 250};

	/*
	 * Initialize the IIC driver so that it's ready to use
	 * Look up the configuration in the config table, then initialize it.
	 */
	Config = XIicPs_LookupConfig(DeviceId);
	if (NULL == Config) {
		return XST_FAILURE;
	}

	Status = XIicPs_CfgInitialize(&Iic, Config, Config->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Perform a self-test to ensure that the hardware was built correctly.
	 */
	Status = XIicPs_SelfTest(&Iic);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Connect the IIC to the interrupt subsystem such that interrupts can
	 * occur. This function is application specific.
	 */
	Status = SetupInterruptSystem(&Iic);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Setup the handlers for the IIC that will be called from the
	 * interrupt context when data has been sent and received, specify a
	 * pointer to the IIC driver instance as the callback reference so
	 * the handlers are able to access the instance data.
	 */
	XIicPs_SetStatusHandler(&Iic, (void *) &Iic, Handler);

	/*
	 * Set the IIC serial clock rate.
	 */
	XIicPs_SetSClk(&Iic, IIC_SCLK_RATE);

	/*
	 * Initialize the send buffer bytes with a pattern to send and the
	 * the receive buffer bytes to zero to allow the receive data to be
	 * verified.
	 */
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		SendBuffer[Index] = (Index % TEST_BUFFER_SIZE);
		RecvBuffer[Index] = 0;
	}

	for(Index = 0; Index < NUMBER_OF_SIZES; Index++) {

		/* Wait for bus to become idle
		 */
		while (XIicPs_BusIsBusy(&Iic)) {
			/* NOP */
		}

		SendComplete = FALSE;

		/*
		 * Send the buffer, errors are reported by TotalErrorCount.
		 */
		XIicPs_MasterSend(&Iic, SendBuffer, BufferSizes[Index],
				IIC_SLAVE_ADDR);

		/*
		 * Wait for the entire buffer to be sent, letting the interrupt
		 * processing work in the background, this function may get
		 * locked up in this loop if the interrupts are not working
		 * correctly.
		 */
		while (!SendComplete) {
				if (ArbitrationLost) {

					/* Wait for bus to become idle
					 */
					while (XIicPs_BusIsBusy(&Iic)) {
						/* NOP */
					}

					ArbitrationLost = FALSE;
					/*
					 * Re-send the buffer if there any arbitration lost and
					 * errors are reported by TotalErrorCount.
					 */
					XIicPs_MasterSend(&Iic, SendBuffer, BufferSizes[Index],
					IIC_SLAVE_ADDR);

				} else if (0 != TotalErrorCount) {
					return XST_FAILURE;
				}
			}

			/*
			 * Wait bus activities to finish.
			 */
			while (XIicPs_BusIsBusy(&Iic)) {
				/* NOP */
			}

			/*
			 * Receive data from slave, errors are reported through
			 * TotalErrorCount.
			 */
			RecvComplete = FALSE;
			XIicPs_MasterRecv(&Iic, RecvBuffer, BufferSizes[Index],
			IIC_SLAVE_ADDR);

			while (!RecvComplete) {
				if (ArbitrationLost) {

					/* Wait for bus to become idle
					 */
					while (XIicPs_BusIsBusy(&Iic)) {
						/* NOP */
					}

					ArbitrationLost = FALSE;
					/*
					 * Retry buffer read if there any arbitration lost and
					 * errors are reported by TotalErrorCount.
					 */
					XIicPs_MasterRecv(&Iic, RecvBuffer, BufferSizes[Index],
					IIC_SLAVE_ADDR);
				} else if (0 != TotalErrorCount) {
					return XST_FAILURE;
				}
			}

		/* Check for received data.
		 */
		for(tmp = 0; tmp < BufferSizes[Index]; tmp ++) {

			/*
			 * Aardvark as slave can only set up to 64 bytes for
			 * output.
			 */
			if (RecvBuffer[tmp] != tmp % 64) {
				return XST_FAILURE;
			}
		}
	}
	return XST_SUCCESS;
}
/*****************************************************************************/
/**
*
* The purpose of this function is to illustrate multi-master arbitration
* lost support in XIicPs driver.
*
* This function sends data and expects to receive the same data through the IIC
* using the Aardvark test hardware.
*
* This function uses interrupt driver mode of the IIC.
*
* This function uses interrupt transfer functions to send buffers with
* different length and receive the same from device.
* In case arbitration lost status will re-initiate the transfer
* BufferSizes array contains length information
*
* @param	DeviceId is the Device ID of the IicPs Device and is the
*		XPAR_<IICPS_instance>_DEVICE_ID value from xparameters.h
*
* @return	XST_SUCCESS if successful, otherwise XST_FAILURE.
*
* @note
*
* This function contains an infinite loop such that if interrupts are not
* working it may never return.
*
*******************************************************************************/
The purpose of this function is to illustrate multi-master arbitration
lost support in XIicPs driver.

This function sends data and expects to receive the same data through the IIC
using the Aardvark test hardware.

This function uses interrupt driver mode of the IIC.

This function uses interrupt transfer functions to send buffers with
different length and receive the same from device.
In case arbitration lost status will re-initiate the transfer
BufferSizes array contains length information
The purpose of this function is to illustrate multi - master arbitration lost support in XIicPs driver . This function sends data and expects to receive the same data through the IIC using the Aardvark test hardware . This function uses interrupt driver mode of the IIC . This function uses interrupt transfer functions to send buffers with different length and receive the same from device . In case arbitration lost status will re - initiate the transfer BufferSizes array contains length information
s32 IicPsMultiMasterIntrExample(u16 DeviceId)
{
	s32 Status;
	XIicPs_Config *Config;
	s32 Index;
	s32 tmp;
	s32 BufferSizes[NUMBER_OF_SIZES] = {1, 2, 19, 31, 32, 33, 62, 63, 64,
	65, 66, 94, 95, 96, 97, 98, 99, 250};
	Config = XIicPs_LookupConfig(DeviceId);
	if (NULL == Config) {
		return XST_FAILURE;
	}
	Status = XIicPs_CfgInitialize(&Iic, Config, Config->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = XIicPs_SelfTest(&Iic);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = SetupInterruptSystem(&Iic);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XIicPs_SetStatusHandler(&Iic, (void *) &Iic, Handler);
	XIicPs_SetSClk(&Iic, IIC_SCLK_RATE);
	for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
		SendBuffer[Index] = (Index % TEST_BUFFER_SIZE);
		RecvBuffer[Index] = 0;
	}
	for(Index = 0; Index < NUMBER_OF_SIZES; Index++) {
		while (XIicPs_BusIsBusy(&Iic)) {
		}
		SendComplete = FALSE;
		XIicPs_MasterSend(&Iic, SendBuffer, BufferSizes[Index],
				IIC_SLAVE_ADDR);
		while (!SendComplete) {
				if (ArbitrationLost) {
					while (XIicPs_BusIsBusy(&Iic)) {
					}
					ArbitrationLost = FALSE;
					XIicPs_MasterSend(&Iic, SendBuffer, BufferSizes[Index],
					IIC_SLAVE_ADDR);
				} else if (0 != TotalErrorCount) {
					return XST_FAILURE;
				}
			}
			while (XIicPs_BusIsBusy(&Iic)) {
			}
			RecvComplete = FALSE;
			XIicPs_MasterRecv(&Iic, RecvBuffer, BufferSizes[Index],
			IIC_SLAVE_ADDR);
			while (!RecvComplete) {
				if (ArbitrationLost) {
					while (XIicPs_BusIsBusy(&Iic)) {
					}
					ArbitrationLost = FALSE;
					XIicPs_MasterRecv(&Iic, RecvBuffer, BufferSizes[Index],
					IIC_SLAVE_ADDR);
				} else if (0 != TotalErrorCount) {
					return XST_FAILURE;
				}
			}
		for(tmp = 0; tmp < BufferSizes[Index]; tmp ++) {
			if (RecvBuffer[tmp] != tmp % 64) {
				return XST_FAILURE;
			}
		}
	}
	return XST_SUCCESS;
}
s32 IicPsMultiMasterIntrExample ( u16 DeviceId ) { s32 Status ; XIicPs_Config * Config ; s32 Index ; s32 tmp ; s32 BufferSizes [ NUMBER_OF_SIZES ] = { 1 , 2 , 19 , 31 , 32 , 33 , 62 , 63 , 64 , 65 , 66 , 94 , 95 , 96 , 97 , 98 , 99 , 250 } ; Config = XIicPs_LookupConfig ( DeviceId ) ; if ( NULL == Config ) { return XST_FAILURE ; } Status = XIicPs_CfgInitialize ( & Iic , Config , Config -> BaseAddress ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XIicPs_SelfTest ( & Iic ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = SetupInterruptSystem ( & Iic ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XIicPs_SetStatusHandler ( & Iic , ( void * ) & Iic , Handler ) ; XIicPs_SetSClk ( & Iic , IIC_SCLK_RATE ) ; for ( Index = 0 ; Index < TEST_BUFFER_SIZE ; Index ++ ) { SendBuffer [ Index ] = ( Index % TEST_BUFFER_SIZE ) ; RecvBuffer [ Index ] = 0 ; } for ( Index = 0 ; Index < NUMBER_OF_SIZES ; Index ++ ) { while ( XIicPs_BusIsBusy ( & Iic ) ) { } SendComplete = FALSE ; XIicPs_MasterSend ( & Iic , SendBuffer , BufferSizes [ Index ] , IIC_SLAVE_ADDR ) ; while ( ! SendComplete ) { if ( ArbitrationLost ) { while ( XIicPs_BusIsBusy ( & Iic ) ) { } ArbitrationLost = FALSE ; XIicPs_MasterSend ( & Iic , SendBuffer , BufferSizes [ Index ] , IIC_SLAVE_ADDR ) ; } else if ( 0 != TotalErrorCount ) { return XST_FAILURE ; } } while ( XIicPs_BusIsBusy ( & Iic ) ) { } RecvComplete = FALSE ; XIicPs_MasterRecv ( & Iic , RecvBuffer , BufferSizes [ Index ] , IIC_SLAVE_ADDR ) ; while ( ! RecvComplete ) { if ( ArbitrationLost ) { while ( XIicPs_BusIsBusy ( & Iic ) ) { } ArbitrationLost = FALSE ; XIicPs_MasterRecv ( & Iic , RecvBuffer , BufferSizes [ Index ] , IIC_SLAVE_ADDR ) ; } else if ( 0 != TotalErrorCount ) { return XST_FAILURE ; } } for ( tmp = 0 ; tmp < BufferSizes [ Index ] ; tmp ++ ) { if ( RecvBuffer [ tmp ] != tmp % 64 ) { return XST_FAILURE ; } } } return XST_SUCCESS ; }
The purpose of this function is to illustrate multi-master arbitration
lost support in XIicPs driver.
The purpose of this function is to illustrate multi - master arbitration lost support in XIicPs driver .
/*
	 * Initialize the IIC driver so that it's ready to use
	 * Look up the configuration in the config table, then initialize it.
	 */ /*
	 * Perform a self-test to ensure that the hardware was built correctly.
	 */ /*
	 * Connect the IIC to the interrupt subsystem such that interrupts can
	 * occur. This function is application specific.
	 */ /*
	 * Setup the handlers for the IIC that will be called from the
	 * interrupt context when data has been sent and received, specify a
	 * pointer to the IIC driver instance as the callback reference so
	 * the handlers are able to access the instance data.
	 */ /*
	 * Set the IIC serial clock rate.
	 */ /*
	 * Initialize the send buffer bytes with a pattern to send and the
	 * the receive buffer bytes to zero to allow the receive data to be
	 * verified.
	 */ /* Wait for bus to become idle
		 */ /* NOP */ /*
		 * Send the buffer, errors are reported by TotalErrorCount.
		 */ /*
		 * Wait for the entire buffer to be sent, letting the interrupt
		 * processing work in the background, this function may get
		 * locked up in this loop if the interrupts are not working
		 * correctly.
		 */ /* Wait for bus to become idle
					 */ /* NOP */ /*
					 * Re-send the buffer if there any arbitration lost and
					 * errors are reported by TotalErrorCount.
					 */ /*
			 * Wait bus activities to finish.
			 */ /* NOP */ /*
			 * Receive data from slave, errors are reported through
			 * TotalErrorCount.
			 */ /* Wait for bus to become idle
					 */ /* NOP */ /*
					 * Retry buffer read if there any arbitration lost and
					 * errors are reported by TotalErrorCount.
					 */ /* Check for received data.
		 */ /*
			 * Aardvark as slave can only set up to 64 bytes for
			 * output.
			 */