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

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

	Status = XIic_CfgInitialize(&IicInstance, ConfigPtr,
			ConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	/*
	 * Initialize the Dynamic IIC core.
	 */
	Status = XIic_DynamicInitialize(&IicInstance);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

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

	/*
	 * Set the Handlers for transmit and reception.
	 */
	XIic_SetSendHandler(&IicInstance, &IicInstance,
				(XIic_Handler) SendHandler);
	XIic_SetRecvHandler(&IicInstance, &IicInstance,
				(XIic_Handler) ReceiveHandler);
	XIic_SetStatusHandler(&IicInstance, &IicInstance,
				  (XIic_StatusHandler) StatusHandler);


	/*
	 * Initialize the data to write and the read buffer.
	 */
	if (sizeof(Address) == 1) {
		WriteBuffer[0] = (u8) (EEPROM_TEST_START_ADDRESS);
		EepromIicAddr |= (EEPROM_TEST_START_ADDRESS >> 8) & 0x7;
	} else {
		WriteBuffer[0] = (u8) (EEPROM_TEST_START_ADDRESS >> 8);
		WriteBuffer[1] = (u8) (EEPROM_TEST_START_ADDRESS);
		ReadBuffer[Index] = 0;
	}

	for (Index = 0; Index < PAGE_SIZE; Index++) {
		WriteBuffer[sizeof(Address) + Index] = 0xFF;
		ReadBuffer[Index] = 0;
	}

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

	/*
	 * Write to the EEPROM.
	 */
	Status = DynEepromWriteData(sizeof(Address) + PAGE_SIZE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Read from the EEPROM.
	 */
	Status = DynEepromReadData(ReadBuffer, PAGE_SIZE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Verify the data read against the data written.
	 */
	for (Index = 0; Index < PAGE_SIZE; Index++) {
		if (ReadBuffer[Index] != WriteBuffer[Index + sizeof(Address)]) {
			return XST_FAILURE;
		}

		ReadBuffer[Index] = 0;
	}

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

	for (Index = 0; Index < PAGE_SIZE; Index++) {
		WriteBuffer[sizeof(Address) + Index] = Index;
	}

	/*
	 * Write to the EEPROM.
	 */
	Status = DynEepromWriteData(sizeof(Address) + PAGE_SIZE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Read from the EEPROM.
	 */
	Status = DynEepromReadData(ReadBuffer, PAGE_SIZE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Verify the data read against the data written.
	 */
	for (Index = 0; Index < PAGE_SIZE; Index++) {
		if (ReadBuffer[Index] != WriteBuffer[Index + sizeof(Address)]) {
			return XST_FAILURE;
		}

		ReadBuffer[Index] = 0;
	}

	return XST_SUCCESS;
}
/*****************************************************************************/
/**
* This function writes, reads, and verifies the data to the IIC EEPROM in
* Dynamic controller mode. It does the write as a single page write, performs a
* buffered read.
*
*
* @return	XST_SUCCESS if successful else XST_FAILURE.
*
* @note		None.
*
******************************************************************************/
This function writes, reads, and verifies the data to the IIC EEPROM in
Dynamic controller mode. It does the write as a single page write, performs a
buffered read.
This function writes reads and verifies the data to the IIC EEPROM in Dynamic controller mode . It does the write as a single page write performs a buffered read .
int IicDynEepromExample(void)
{
	u8 Index;
	int Status;
	XIic_Config *ConfigPtr;	
	AddressType Address = EEPROM_TEST_START_ADDRESS;
	EepromIicAddr = EEPROM_ADDRESS;
	ConfigPtr = XIic_LookupConfig(IIC_DEVICE_ID);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	Status = XIic_CfgInitialize(&IicInstance, ConfigPtr,
			ConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = XIic_DynamicInitialize(&IicInstance);
	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_SetRecvHandler(&IicInstance, &IicInstance,
				(XIic_Handler) ReceiveHandler);
	XIic_SetStatusHandler(&IicInstance, &IicInstance,
				  (XIic_StatusHandler) StatusHandler);
	if (sizeof(Address) == 1) {
		WriteBuffer[0] = (u8) (EEPROM_TEST_START_ADDRESS);
		EepromIicAddr |= (EEPROM_TEST_START_ADDRESS >> 8) & 0x7;
	} else {
		WriteBuffer[0] = (u8) (EEPROM_TEST_START_ADDRESS >> 8);
		WriteBuffer[1] = (u8) (EEPROM_TEST_START_ADDRESS);
		ReadBuffer[Index] = 0;
	}
	for (Index = 0; Index < PAGE_SIZE; Index++) {
		WriteBuffer[sizeof(Address) + Index] = 0xFF;
		ReadBuffer[Index] = 0;
	}
	Status = XIic_SetAddress(&IicInstance, XII_ADDR_TO_SEND_TYPE,
				 EepromIicAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = DynEepromWriteData(sizeof(Address) + PAGE_SIZE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = DynEepromReadData(ReadBuffer, PAGE_SIZE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	for (Index = 0; Index < PAGE_SIZE; Index++) {
		if (ReadBuffer[Index] != WriteBuffer[Index + sizeof(Address)]) {
			return XST_FAILURE;
		}
		ReadBuffer[Index] = 0;
	}
	if (sizeof(Address) == 1) {
		WriteBuffer[0] = (u8) (EEPROM_TEST_START_ADDRESS);
	} else {
		WriteBuffer[0] = (u8) (EEPROM_TEST_START_ADDRESS >> 8);
		WriteBuffer[1] = (u8) (EEPROM_TEST_START_ADDRESS);
		ReadBuffer[Index] = 0;
	}
	for (Index = 0; Index < PAGE_SIZE; Index++) {
		WriteBuffer[sizeof(Address) + Index] = Index;
	}
	Status = DynEepromWriteData(sizeof(Address) + PAGE_SIZE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	Status = DynEepromReadData(ReadBuffer, PAGE_SIZE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	for (Index = 0; Index < PAGE_SIZE; Index++) {
		if (ReadBuffer[Index] != WriteBuffer[Index + sizeof(Address)]) {
			return XST_FAILURE;
		}
		ReadBuffer[Index] = 0;
	}
	return XST_SUCCESS;
}
int IicDynEepromExample ( void ) { u8 Index ; int Status ; XIic_Config * ConfigPtr ; AddressType Address = EEPROM_TEST_START_ADDRESS ; EepromIicAddr = EEPROM_ADDRESS ; ConfigPtr = XIic_LookupConfig ( IIC_DEVICE_ID ) ; if ( ConfigPtr == NULL ) { return XST_FAILURE ; } Status = XIic_CfgInitialize ( & IicInstance , ConfigPtr , ConfigPtr -> BaseAddress ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = XIic_DynamicInitialize ( & IicInstance ) ; 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_SetRecvHandler ( & IicInstance , & IicInstance , ( XIic_Handler ) ReceiveHandler ) ; XIic_SetStatusHandler ( & IicInstance , & IicInstance , ( XIic_StatusHandler ) StatusHandler ) ; if ( sizeof ( Address ) == 1 ) { WriteBuffer [ 0 ] = ( u8 ) ( EEPROM_TEST_START_ADDRESS ) ; EepromIicAddr |= ( EEPROM_TEST_START_ADDRESS >> 8 ) & 0x7 ; } else { WriteBuffer [ 0 ] = ( u8 ) ( EEPROM_TEST_START_ADDRESS >> 8 ) ; WriteBuffer [ 1 ] = ( u8 ) ( EEPROM_TEST_START_ADDRESS ) ; ReadBuffer [ Index ] = 0 ; } for ( Index = 0 ; Index < PAGE_SIZE ; Index ++ ) { WriteBuffer [ sizeof ( Address ) + Index ] = 0xFF ; ReadBuffer [ Index ] = 0 ; } Status = XIic_SetAddress ( & IicInstance , XII_ADDR_TO_SEND_TYPE , EepromIicAddr ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = DynEepromWriteData ( sizeof ( Address ) + PAGE_SIZE ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = DynEepromReadData ( ReadBuffer , PAGE_SIZE ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } for ( Index = 0 ; Index < PAGE_SIZE ; Index ++ ) { if ( ReadBuffer [ Index ] != WriteBuffer [ Index + sizeof ( Address ) ] ) { return XST_FAILURE ; } ReadBuffer [ Index ] = 0 ; } if ( sizeof ( Address ) == 1 ) { WriteBuffer [ 0 ] = ( u8 ) ( EEPROM_TEST_START_ADDRESS ) ; } else { WriteBuffer [ 0 ] = ( u8 ) ( EEPROM_TEST_START_ADDRESS >> 8 ) ; WriteBuffer [ 1 ] = ( u8 ) ( EEPROM_TEST_START_ADDRESS ) ; ReadBuffer [ Index ] = 0 ; } for ( Index = 0 ; Index < PAGE_SIZE ; Index ++ ) { WriteBuffer [ sizeof ( Address ) + Index ] = Index ; } Status = DynEepromWriteData ( sizeof ( Address ) + PAGE_SIZE ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } Status = DynEepromReadData ( ReadBuffer , PAGE_SIZE ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } for ( Index = 0 ; Index < PAGE_SIZE ; Index ++ ) { if ( ReadBuffer [ Index ] != WriteBuffer [ Index + sizeof ( Address ) ] ) { return XST_FAILURE ; } ReadBuffer [ Index ] = 0 ; } return XST_SUCCESS ; }
This function writes, reads, and verifies the data to the IIC EEPROM in
Dynamic controller mode.
This function writes reads and verifies the data to the IIC EEPROM in Dynamic controller mode .
/* Pointer to configuration data */ /*
	 * Initialize the IIC driver so that it is ready to use.
	 */ /*
	 * Initialize the Dynamic IIC core.
	 */ /*
	 * Setup the Interrupt System.
	 */ /*
	 * Set the Handlers for transmit and reception.
	 */ /*
	 * Initialize the data to write and the read buffer.
	 */ /*
	 * Set the Slave address.
	 */ /*
	 * Write to the EEPROM.
	 */ /*
	 * Read from the EEPROM.
	 */ /*
	 * Verify the data read against the data written.
	 */ /*
	 * Initialize the data to write and the read buffer.
	 */ /*
	 * Write to the EEPROM.
	 */ /*
	 * Read from the EEPROM.
	 */ /*
	 * Verify the data read against the data written.
	 */