AP_Var: added EEPROM wear levelling

This adds a variable length dummy variable at the front of the EEPROM
when we erase it, which has the effect of moving the location of any
hot variables within the EEPROM. This should improve EEPROM
life. Thanks to Mike for the implementation.

Pair-Programmed-With: Mike Smith

git-svn-id: https://arducopter.googlecode.com/svn/trunk@3234 f9c3cf11-9bcb-44bc-f272-b75c42450872
This commit is contained in:
tridge60@gmail.com 2011-09-04 06:39:57 +00:00
parent 06c4f60490
commit dab8c0cca8
2 changed files with 16 additions and 1 deletions

View File

@ -593,6 +593,8 @@ bool AP_Var::_EEPROM_locate(bool allocate)
// sentinel.
//
if (0 == _tail_sentinel) {
uint8_t pad_size;
debug("writing header");
EEPROM_header ee_header;
@ -601,8 +603,17 @@ bool AP_Var::_EEPROM_locate(bool allocate)
ee_header.spare = 0;
eeprom_write_block(&ee_header, (void *)0, sizeof(ee_header));
_tail_sentinel = sizeof(ee_header);
// Write a variable-sized pad header with a reserved key value
// to help wear-level the EEPROM a bit.
pad_size = (((uint8_t)micros()) % k_size_max) + 1; // should be fairly random
var_header.key = k_key_pad;
var_header.size = pad_size - 1;
eeprom_write_block(&var_header, (void *)_tail_sentinel, sizeof(var_header));
_tail_sentinel += sizeof(var_header) + pad_size;
}
// Save the location we are going to insert at, and compute the new

View File

@ -112,6 +112,10 @@ public:
///
static const Key k_key_sentinel = 0xff;
/// Key assigned to the wear-balancing pad entry in EEPROM.
///
static const Key k_key_pad = 0xfe;
/// A bitmask that removes any control bits from a key giving just the
/// value.
///