Pages: [1]   Go Down
Author Topic: [proposal] write+verify function for EEPROMAnything.h  (Read 1063 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
God Member
*****
Karma: 2
Posts: 596
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Writes the data to eeprom, reads it back and compares it to the original data. It returns true if the argument and the read-back data are the same, false otherwise.
In other words, true meanse "write successful", false means "write failed. eeprom probably corrupt".

template <class T> boolean EEPROM_writeVerifyAnything(int ee, const T& value)
{
    T aux;
    EEPROM_writeAnything(ee, value);
    EEPROM_readAnything(ee, aux);
    return memcmp((const byte*)&value, (const byte*)&aux, sizeof(T)) == 0;
}

Comments are welcome. :-)
Logged

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What if there's byte in eeprom that is corrupted, should it be marked for the future? Write something that would indicate the failure?
That would make it too complicated? Some area for the information about bad bytes?

Too much for me, just thinking...

Cheers,
Kari
Logged


The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

0
Offline Offline
God Member
*****
Karma: 2
Posts: 596
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The idea behind this function it to make easy to detect eeprom write errors.
What to do in case of error is left as an exercise to the reader :-)

Seriously, though, I guess that type of functionality belongs to a higher software level. Probably another library...

Thanks for your suggestions.
Logged

Pages: [1]   Go Up
Jump to: