57 explicit StmNvs(
const char* namespace_name =
"default",
72 size_t* actual_size =
nullptr)
noexcept override;
74 hf_nvs_err_t SetBlob(
const char* key,
const void* data,
size_t data_size)
noexcept override;
76 size_t* actual_size =
nullptr)
noexcept override;
80 bool KeyExists(
const char* key)
noexcept override;
130 const void* data,
size_t data_size)
noexcept;
133 bool IsValidKey(
const char* key)
const noexcept;
Abstract base class for Non-Volatile Storage implementations in the HardFOC system.
hf_nvs_err_t
Definition BaseNvs.h:76
uint32_t hf_u32_t
Platform-agnostic 32-bit unsigned integer type.
Definition HardwareTypes.h:52
uint8_t hf_u8_t
Platform-agnostic 8-bit unsigned integer type.
Definition HardwareTypes.h:40
uint16_t hf_u16_t
Platform-agnostic 16-bit unsigned integer type.
Definition HardwareTypes.h:46
STM32 platform-specific type definitions for hardware abstraction.
Abstract base class for non-volatile storage operations.
Definition BaseNvs.h:147
STM32 NVS — flash-backed key-value store with wear leveling.
Definition StmNvs.h:50
hf_nvs_err_t SetString(const char *key, const char *value) noexcept override
Store a string value.
Definition StmNvs.cpp:144
EntryType
NVS entry types.
Definition StmNvs.h:100
size_t entry_count_
Current entry count.
Definition StmNvs.h:147
hf_nvs_err_t GetU32(const char *key, hf_u32_t &value) noexcept override
Retrieve a 32-bit unsigned integer value.
Definition StmNvs.cpp:130
hf_stm32_nvs_config_t flash_config_
Flash region config.
Definition StmNvs.h:144
size_t GetEntryCount() const noexcept
Get number of stored entries.
Definition StmNvs.h:93
int FindCacheEntry(const char *key) const noexcept
Find entry in RAM cache by key.
Definition StmNvs.cpp:263
hf_nvs_err_t Commit() noexcept override
Commit any pending writes to non-volatile storage.
Definition StmNvs.cpp:221
hf_nvs_err_t SetBlob(const char *key, const void *data, size_t data_size) noexcept override
Store binary data (blob).
Definition StmNvs.cpp:178
struct __attribute__((packed)) EntryHeader
Entry header stored in flash (packed)
Definition StmNvs.h:108
size_t GetMaxKeyLength() const noexcept override
Get maximum key length supported.
Definition StmNvs.cpp:247
hf_nvs_err_t EraseKey(const char *key) noexcept override
Remove a key from storage.
Definition StmNvs.cpp:209
hf_nvs_err_t GetBlob(const char *key, void *buffer, size_t buffer_size, size_t *actual_size=nullptr) noexcept override
Retrieve binary data (blob).
Definition StmNvs.cpp:190
bool KeyExists(const char *key) noexcept override
Check if a key exists in storage.
Definition StmNvs.cpp:226
const char * GetDescription() const noexcept override
Get description of this storage implementation.
Definition StmNvs.cpp:243
size_t GetMaxValueSize() const noexcept override
Get maximum value size supported.
Definition StmNvs.cpp:251
hf_nvs_err_t SetU32(const char *key, hf_u32_t value) noexcept override
Store a 32-bit unsigned integer value.
Definition StmNvs.cpp:119
hf_nvs_err_t Deinitialize() noexcept override
Deinitialize the storage system and close the namespace.
Definition StmNvs.cpp:105
const hf_stm32_nvs_config_t & GetFlashConfig() const noexcept
Get the flash configuration.
Definition StmNvs.h:90
hf_nvs_err_t Initialize() noexcept override
Initialize the storage system and open the namespace.
Definition StmNvs.cpp:82
size_t GetFreeSpace() const noexcept
Get available free space in current sector (bytes)
Definition StmNvs.cpp:255
hf_nvs_err_t GetSize(const char *key, size_t &size) noexcept override
Get the size of a stored value.
Definition StmNvs.cpp:232
static hf_u32_t ComputeCrc32(const void *data, size_t length) noexcept
Simple CRC32 for entry validation.
Definition StmNvs.cpp:517
hf_nvs_err_t GetString(const char *key, char *buffer, size_t buffer_size, size_t *actual_size=nullptr) noexcept override
Retrieve a string value.
Definition StmNvs.cpp:158
static constexpr size_t kMaxEntries
Max cached entries (cal-sized)
Definition StmNvs.h:145
bool IsValidKey(const char *key) const noexcept
Validate a key string.
Definition StmNvs.cpp:293
hf_nvs_err_t LoadFromFlash() noexcept
Read entries from flash into RAM cache.
Definition StmNvs.cpp:446
hf_u32_t write_offset_
Current write position in flash.
Definition StmNvs.h:148
~StmNvs() noexcept override
Definition StmNvs.cpp:74
hf_nvs_err_t FlushToFlash() noexcept
Write all dirty entries to flash.
Definition StmNvs.cpp:299
int AddOrUpdateCache(const char *key, EntryType type, const void *data, size_t data_size) noexcept
Add or update entry in RAM cache.
Definition StmNvs.cpp:272
CacheEntry cache_[kMaxEntries]
RAM cache.
Definition StmNvs.h:146
RAM cache entry.
Definition StmNvs.h:116
bool dirty
Needs flash write.
Definition StmNvs.h:121
hf_u8_t data[576]
Value data (blob capacity for large cal records)
Definition StmNvs.h:119
hf_u16_t data_length
Actual data length.
Definition StmNvs.h:120
char key[64]
Key string.
Definition StmNvs.h:117
EntryType type
Value type.
Definition StmNvs.h:118
bool erased
Marked for deletion.
Definition StmNvs.h:122
Flash-based NVS configuration for STM32.
Definition StmTypes.h:537