dhiltonp / hexbright

The easiest way to start programming your hexbright.
BSD 2-Clause "Simplified" License
124 stars 114 forks source link

up_n_down:Improve EEPROM usage pattern #30

Closed ptesarik closed 11 years ago

ptesarik commented 11 years ago

The original program writes to fixed EEPROM locations, stressing the first two cells only. The modified algorithm distributes the stress across all of the EEPROM memory. It is implemented as follows:

  1. All configuration is kept in a single data structure.
  2. The EEPROM memory space is divided into slots.
  3. Each slot has a sequence number.
  4. A new slot is always used to write the configuration, and it gets the next highest available sequence number.
  5. Number of slots is not a multiple of the highest sequence number.
  6. Both sequence numbers and slot numbers can overflow eventually, but thanks to point 5, there will always be a "gap" after the last sequence number.

The configuration is read once at startup, and written once before switching off, and only if any values actually changed.

wbattestilli commented 11 years ago

This is quite clever and definitely can be useful in many cases where EEPROM writes are frequent. Up_n_down, at present, only writes to EEPROM infrequently and probably does not benefit from this.

The cost of this is 374 bytes. This is acceptable for some uses but it should definitely be optional and integrated into the hexbright library.

I recommend that you look into integrating it into the library before we merge. If not, I can probably look into it when I have some spare cycles (in a couple of weeks unfortunately).

ptesarik commented 11 years ago

OK, I'm leaving it out for now. I will push it again when I rewrite it as a library class.