XilinxProcessorIPLib/drivers/v_hdmitxss/examples/hdcp_key_utility/hdcp_key_utility.c
unsigned EepromWriteByte(u16 Address, u8 *BufferPtr, u16 ByteCount)
{
	volatile unsigned SentByteCount;
	volatile unsigned AckByteCount;
	u8 WriteBuffer[sizeof(Address) + PAGE_SIZE];
	int Index;


	/*
	 * A temporary write buffer must be used which contains both the address
	 * and the data to be written, put the address in first based upon the
	 * size of the address for the EEPROM.
	 */
	WriteBuffer[0] = (u8)(Address >> 8);
	WriteBuffer[1] = (u8)(Address);

	/*
	 * Put the data in the write buffer following the address.
	 */
	for (Index = 0; Index < ByteCount; Index++) {
		WriteBuffer[sizeof(Address) + Index] = BufferPtr[Index];
	}

	/*
	 * Set the address register to the specified address by writing
	 * the address to the device, this must be tried until it succeeds
	 * because a previous write to the device could be pending and it
	 * will not ack until that write is complete.
	 */
	do {
		SentByteCount = XIic_Send(XHDCP_IIC_BASEADDR,
					EEPROM_ADDRESS,
					(u8 *)&Address, sizeof(Address),
					XIIC_STOP);
		if (SentByteCount != sizeof(Address)) {

			/* Send is aborted so reset Tx FIFO */
			XIic_WriteReg(XHDCP_IIC_BASEADDR,  XIIC_CR_REG_OFFSET,
					XIIC_CR_TX_FIFO_RESET_MASK);
			XIic_WriteReg(XHDCP_IIC_BASEADDR, XIIC_CR_REG_OFFSET,
					XIIC_CR_ENABLE_DEVICE_MASK);
		}

	} while (SentByteCount != sizeof(Address));

	/*
	 * Write a page of data at the specified address to the EEPROM.
	 */
	SentByteCount = XIic_Send(XHDCP_IIC_BASEADDR, EEPROM_ADDRESS,
				  WriteBuffer, sizeof(Address) + ByteCount,
				  XIIC_STOP);

	/*
	 * Wait for the write to be complete by trying to do a write and
	 * the device will not ack if the write is still active.
	 */
	do {
		AckByteCount = XIic_Send(XHDCP_IIC_BASEADDR, EEPROM_ADDRESS,
					(u8 *)&Address, sizeof(Address),
					XIIC_STOP);
		if (AckByteCount != sizeof(Address)) {

			/* Send is aborted so reset Tx FIFO */
			XIic_WriteReg(XHDCP_IIC_BASEADDR,  XIIC_CR_REG_OFFSET,
					XIIC_CR_TX_FIFO_RESET_MASK);
			XIic_WriteReg(XHDCP_IIC_BASEADDR, XIIC_CR_REG_OFFSET,
					XIIC_CR_ENABLE_DEVICE_MASK);
		}

	} while (AckByteCount != sizeof(Address));


	/*
	 * Return the number of bytes written to the EEPROM
	 */
	return SentByteCount - sizeof(Address);
}
/*****************************************************************************/
/**
* This function writes a buffer of bytes to the IIC serial EEPROM.
*
* @param	Address contains the address in the EEPROM to write to.
* @param	BufferPtr contains the address of the data to write.
* @param	ByteCount contains the number of bytes in the buffer to be written.
*		Note that this should not exceed the page size of the EEPROM as
*		noted by the constant PAGE_SIZE.
*
* @return	The number of bytes written, a value less than that which was
*		specified as an input indicates an error.
*
* @note		None.
*
****************************************************************************/
This function writes a buffer of bytes to the IIC serial EEPROM.
This function writes a buffer of bytes to the IIC serial EEPROM .
unsigned EepromWriteByte(u16 Address, u8 *BufferPtr, u16 ByteCount)
{
	volatile unsigned SentByteCount;
	volatile unsigned AckByteCount;
	u8 WriteBuffer[sizeof(Address) + PAGE_SIZE];
	int Index;
	WriteBuffer[0] = (u8)(Address >> 8);
	WriteBuffer[1] = (u8)(Address);
	for (Index = 0; Index < ByteCount; Index++) {
		WriteBuffer[sizeof(Address) + Index] = BufferPtr[Index];
	}
	do {
		SentByteCount = XIic_Send(XHDCP_IIC_BASEADDR,
					EEPROM_ADDRESS,
					(u8 *)&Address, sizeof(Address),
					XIIC_STOP);
		if (SentByteCount != sizeof(Address)) {
			XIic_WriteReg(XHDCP_IIC_BASEADDR,  XIIC_CR_REG_OFFSET,
					XIIC_CR_TX_FIFO_RESET_MASK);
			XIic_WriteReg(XHDCP_IIC_BASEADDR, XIIC_CR_REG_OFFSET,
					XIIC_CR_ENABLE_DEVICE_MASK);
		}
	} while (SentByteCount != sizeof(Address));
	SentByteCount = XIic_Send(XHDCP_IIC_BASEADDR, EEPROM_ADDRESS,
				  WriteBuffer, sizeof(Address) + ByteCount,
				  XIIC_STOP);
	do {
		AckByteCount = XIic_Send(XHDCP_IIC_BASEADDR, EEPROM_ADDRESS,
					(u8 *)&Address, sizeof(Address),
					XIIC_STOP);
		if (AckByteCount != sizeof(Address)) {
			XIic_WriteReg(XHDCP_IIC_BASEADDR,  XIIC_CR_REG_OFFSET,
					XIIC_CR_TX_FIFO_RESET_MASK);
			XIic_WriteReg(XHDCP_IIC_BASEADDR, XIIC_CR_REG_OFFSET,
					XIIC_CR_ENABLE_DEVICE_MASK);
		}
	} while (AckByteCount != sizeof(Address));
	return SentByteCount - sizeof(Address);
}
unsigned EepromWriteByte ( u16 Address , u8 * BufferPtr , u16 ByteCount ) { volatile unsigned SentByteCount ; volatile unsigned AckByteCount ; u8 WriteBuffer [ sizeof ( Address ) + PAGE_SIZE ] ; int Index ; WriteBuffer [ 0 ] = ( u8 ) ( Address >> 8 ) ; WriteBuffer [ 1 ] = ( u8 ) ( Address ) ; for ( Index = 0 ; Index < ByteCount ; Index ++ ) { WriteBuffer [ sizeof ( Address ) + Index ] = BufferPtr [ Index ] ; } do { SentByteCount = XIic_Send ( XHDCP_IIC_BASEADDR , EEPROM_ADDRESS , ( u8 * ) & Address , sizeof ( Address ) , XIIC_STOP ) ; if ( SentByteCount != sizeof ( Address ) ) { XIic_WriteReg ( XHDCP_IIC_BASEADDR , XIIC_CR_REG_OFFSET , XIIC_CR_TX_FIFO_RESET_MASK ) ; XIic_WriteReg ( XHDCP_IIC_BASEADDR , XIIC_CR_REG_OFFSET , XIIC_CR_ENABLE_DEVICE_MASK ) ; } } while ( SentByteCount != sizeof ( Address ) ) ; SentByteCount = XIic_Send ( XHDCP_IIC_BASEADDR , EEPROM_ADDRESS , WriteBuffer , sizeof ( Address ) + ByteCount , XIIC_STOP ) ; do { AckByteCount = XIic_Send ( XHDCP_IIC_BASEADDR , EEPROM_ADDRESS , ( u8 * ) & Address , sizeof ( Address ) , XIIC_STOP ) ; if ( AckByteCount != sizeof ( Address ) ) { XIic_WriteReg ( XHDCP_IIC_BASEADDR , XIIC_CR_REG_OFFSET , XIIC_CR_TX_FIFO_RESET_MASK ) ; XIic_WriteReg ( XHDCP_IIC_BASEADDR , XIIC_CR_REG_OFFSET , XIIC_CR_ENABLE_DEVICE_MASK ) ; } } while ( AckByteCount != sizeof ( Address ) ) ; return SentByteCount - sizeof ( Address ) ; }
This function writes a buffer of bytes to the IIC serial EEPROM.
This function writes a buffer of bytes to the IIC serial EEPROM .
/*
	 * A temporary write buffer must be used which contains both the address
	 * and the data to be written, put the address in first based upon the
	 * size of the address for the EEPROM.
	 */ /*
	 * Put the data in the write buffer following the address.
	 */ /*
	 * Set the address register to the specified address by writing
	 * the address to the device, this must be tried until it succeeds
	 * because a previous write to the device could be pending and it
	 * will not ack until that write is complete.
	 */ /* Send is aborted so reset Tx FIFO */ /*
	 * Write a page of data at the specified address to the EEPROM.
	 */ /*
	 * Wait for the write to be complete by trying to do a write and
	 * the device will not ack if the write is still active.
	 */ /* Send is aborted so reset Tx FIFO */ /*
	 * Return the number of bytes written to the EEPROM
	 */