70class StateWearLevelingSector :
public StateStorageInterface {
72 enum class State : uint8_t {
80 explicit StateWearLevelingSector(Storage *storage,
83 uint32_t availableSize);
84 ~StateWearLevelingSector();
86 bool loadPreambles(uint32_t storageStartingOffset, uint16_t size)
override;
87 void initSectionPreamble(SectionPreamble *preamble)
override;
88 bool writeSectionPreamble()
override;
89 bool initFromStorage()
override;
90 void deleteAll()
override;
91 bool prepareSaveState()
override;
92 bool prepareSizeCheck()
override;
93 bool prepareLoadState()
override;
94 bool readState(
unsigned char *,
int)
override;
95 bool writeState(
const unsigned char *,
int)
override;
96 bool finalizeSaveState()
override;
97 bool finalizeSizeCheck()
override;
98 bool finalizeLoadState()
override;
99 void notifyUpdate()
override;
102 virtual uint16_t getSectorSize()
const;
105 uint16_t getSizeValue(uint16_t availableSize)
override;
106 bool tryLoadPreamblesFrom(uint32_t offset);
107 bool isDataDifferent(uint32_t address,
const uint8_t *data, uint32_t size);
108 bool isSlotValid(uint32_t address, uint8_t *buffer);
109 uint32_t getPhysicalSlotCount()
const;
110 uint32_t getMaxBitmapSlotCount()
const;
111 int getSlotSize()
const;
112 uint32_t getFirstSlotAddress()
const;
113 uint32_t getNextSlotAddress(uint32_t slotAddress)
const;
114 uint32_t getPreviousSlotAddress(uint32_t slotAddress)
const;
115 uint16_t slotSize()
const;
116 uint32_t updateStateEntryAddress();
117 uint32_t sectionOffset = 0;
118 uint32_t availableSize;
119 uint16_t elementStateSize = 0xFFFF;
120 uint16_t stateSlotNewSize = 0;
121 uint32_t currentStateBufferOffset = 0;
123 bool elementStateCrcCValid =
false;
124 bool storageStateOk =
false;
125 bool initDone =
false;
126 bool currentSlotPreparedForFirstWrite =
false;
127 int repeatBeforeSwitchToAnotherSlot = 0;
129 uint32_t currentSlotAddress = 0;
130 uint32_t lastStoredSlotAddress = 0;
131 uint32_t lastValidAddress = 0;
132 uint8_t *dataBuffer =
nullptr;
134 State state = State::NONE;