Hi Folks,

Could I suggest we modify the i2c eeprom_write function in i2c.c to the code 
given below?

The current function writes one byte at a time on the eeprom. This is less than 
optimum as each write triggers a refresh on the eeprom which refreshes a whole 
page (64 bytes). 
That is sub-optimal on two accounts: 1- the eeprom endurance is specified in 
number of page refresh (OK at 1 million it might not be an issue) but 2- it 
takes about 64 times longer than needed to write a program into the eeprom.
Modifying the function to write 64 bytes at a time (which fit nicely in one EP0 
transfer) cuts down the program writing time from 73s down to 2s.

Cheers,

Sébastien

BOOL eeprom_write(BYTE prom_addr, WORD addr, WORD length, BYTE* buf)
{
  BYTE addr_len=0;
  BYTE addr_buffer[2];
  BYTE bs;
  BYTE *data_buffer_ptr = buf;
  BYTE *last_data_ptr = buf + length;

  if (EEPROM_TWO_BYTE) {
    addr_len = 2;
    addr_buffer[0] = MSB(addr);
    addr_buffer[1] = LSB(addr);
  }
  else {
    addr_len = 1;
    addr_buffer[0] = LSB(addr);
  }

  while ( data_buffer_ptr < last_data_ptr ) {
    if ( (last_data_ptr - data_buffer_ptr) > MAX_EEP_WRITE) { // Should not be 
the case if data is from an EP0 transfer
      bs = MAX_EEP_WRITE;
    }
    else bs = last_data_ptr - data_buffer_ptr;
    if ( ! i2c_write ( prom_addr, addr_len, addr_buffer, bs, data_buffer_ptr ) 
) return FALSE;
    addr += bs; // Potentially more data to come so remember to increase the 
address and buffer pointer 
    data_buffer_ptr += bs;
  }
  return TRUE;
}


                                          
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Fx2lib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fx2lib-devel

Reply via email to