11 #ifndef __EEPROM_HEADER
12 #define __EEPROM_HEADER
17 #include "../ustd/unordered_map.hpp"
18 #include "../util/reset.hpp"
19 #include "../util/checksum.hpp"
24 template<
typename EEPROM_concept,
unsigned int EEPROM_size>
25 class EEPROMV2_class {
26 typedef uint16_t adress_type;
28 enum{not_corrupt = 0, corrupt = 0xFF, not_set = 2};
30 EEPROMV2_class(EEPROM_concept &
eeprom): oes_(eeprom), ies_(eeprom), current_free_(1), corrupted_(not_set) {
38 if(corrupted_ != corrupt and corrupted_ != not_corrupt) {
39 corrupted_ = ies_.
read();
40 oes_.
write(not_corrupt);
42 if(corrupted_ == corrupt) {
51 DEBUG_MSG(
"eeprom is corrupted! reset and fresh init incomming")
62 oes_.
pos() = map_.
at(adress_type(&t));
70 ies_.
pos() = map_.
at(adress_type(&t));
77 if(!map_.
contains(adress_type(&t))) {
78 map_[adress_type(&t)] = current_free_;
79 current_free_ +=
sizeof(t) + 1;
80 ASSERT(current_free_ < EEPROM_size);
81 pos = map_[adress_type(&t)];
84 pos = map_[adress_type(&t)];
87 void clear(uint8_t
const & arg = 0xFF) {
89 for(adress_type
i = 0;
i < EEPROM_size; ++
i) {
98 adress_type current_free_;
102 EEPROMV2_class<EEPROMClass, 1024>
eeprom(EEPROM);
104 #endif //__EEPROM_HEADER
size_type & pos()
Definition: serializer.hpp:203
void clear(uint8_t const &arg=0xFF)
Definition: eeprom.hpp:87
EEPROMV2_class< EEPROMClass, 1024 > eeprom(EEPROM)
size_type & pos()
Definition: serializer.hpp:149
EEPROMV2_class & operator&(T &t)
Definition: eeprom.hpp:37
EEPROMV2_class & operator<<(T &t)
Definition: eeprom.hpp:61
Definition: adv_eeprom.hpp:44
#define DEBUG_MSG(x)
Definition: ard_assert.hpp:32
uint16_t size_type
Definition: serializer.hpp:113
EEPROMV2_class & operator>>(T &t)
Definition: eeprom.hpp:69
void reset()
Definition: reset.hpp:15
bool contains(K const &key) const
Definition: unordered_map.hpp:64
void reset()
Definition: eeprom.hpp:33
V & at(K const &key)
Definition: unordered_map.hpp:53
void write(uint8_t const &in)
Definition: serializer.hpp:144
void adjust_pos(T &t, size_type &pos)
Definition: adv_eeprom.hpp:121
uint8_t checksum(T const &t)
Definition: checksum.hpp:17
#define ASSERT(exp)
Definition: ard_assert.hpp:33
EEPROMV2_class(EEPROM_concept &eeprom)
Definition: eeprom.hpp:30
uint8_t read()
Definition: serializer.hpp:199