FreeBSD/sys/boot/arm/at91/bootspi/ee.c
/*
 * .KB_C_FN_DEFINITION_START
 * void WriteEEPROM(unsigned ee_off, char *data_addr, unsigned size)
 *  This global function writes data to the eeprom at ee_off using data
 * from data_addr for size bytes.  Assume the TWI has been initialized.
 * This function does not utilize the page write mode as the write time is
 * much greater than the time required to access the device for byte-write
 * functionality.  This allows the function to be much simpler.
 * .KB_C_FN_DEFINITION_END
 */
.KB_C_FN_DEFINITION_START
void WriteEEPROM(unsigned ee_off, char *data_addr, unsigned size)
This global function writes data to the eeprom at ee_off using data
from data_addr for size bytes.  Assume the TWI has been initialized.
This function does not utilize the page write mode as the write time is
much greater than the time required to access the device for byte-write
functionality.  This allows the function to be much simpler.
. KB_C_FN_DEFINITION_START void WriteEEPROM ( unsigned ee_off char * data_addr unsigned size ) This global function writes data to the eeprom at ee_off using data from data_addr for size bytes . Assume the TWI has been initialized . This function does not utilize the page write mode as the write time is much greater than the time required to access the device for byte - write functionality . This allows the function to be much simpler .
void
EEWrite(unsigned ee_off, const char *data_addr, unsigned size)
{
	const AT91PS_TWI 	twiPtr = AT91C_BASE_TWI;
	unsigned		status;
	char			test_data;
	while (size--) {
		twiPtr->TWI_MMR = (iicaddr(ee_off) << 16) |
		    AT91C_TWI_IADRSZ_1_BYTE;
		twiPtr->TWI_IADR = ee_off++;
		status = twiPtr->TWI_SR;
		twiPtr->TWI_THR = *(data_addr++);
		twiPtr->TWI_CR = AT91C_TWI_START;
		while (!(twiPtr->TWI_SR & AT91C_TWI_TXRDY))
			continue;
		twiPtr->TWI_CR = AT91C_TWI_STOP;
		status = twiPtr->TWI_SR;
		while (!(twiPtr->TWI_SR & AT91C_TWI_TXCOMP))
			continue;
		EERead(ee_off, &test_data, 1);
	}
}
void EEWrite ( unsigned ee_off , const char * data_addr , unsigned size ) { const AT91PS_TWI twiPtr = AT91C_BASE_TWI ; unsigned status ; char test_data ; while ( size -- ) { twiPtr -> TWI_MMR = ( iicaddr ( ee_off ) << 16 ) | AT91C_TWI_IADRSZ_1_BYTE ; twiPtr -> TWI_IADR = ee_off ++ ; status = twiPtr -> TWI_SR ; twiPtr -> TWI_THR = * ( data_addr ++ ) ; twiPtr -> TWI_CR = AT91C_TWI_START ; while ( ! ( twiPtr -> TWI_SR & AT91C_TWI_TXRDY ) ) continue ; twiPtr -> TWI_CR = AT91C_TWI_STOP ; status = twiPtr -> TWI_SR ; while ( ! ( twiPtr -> TWI_SR & AT91C_TWI_TXCOMP ) ) continue ; EERead ( ee_off , & test_data , 1 ) ; } }
.KB_C_FN_DEFINITION_START
 void WriteEEPROM(unsigned ee_off, char *data_addr, unsigned size)
  This global function writes data to the eeprom at ee_off using data
 from data_addr for size bytes.
. KB_C_FN_DEFINITION_START void WriteEEPROM ( unsigned ee_off char * data_addr unsigned size ) This global function writes data to the eeprom at ee_off using data from data_addr for size bytes .
// Set the TWI Master Mode Register // Load one data byte // wait for write operation to complete, it is done once // we can read it back...