|
HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
|
STM32 NVS — flash-backed key-value store with wear leveling. More...
#include <StmNvs.h>
Classes | |
| struct | CacheEntry |
| RAM cache entry. More... | |
Public Member Functions | |
| StmNvs (const char *namespace_name="default", const hf_stm32_nvs_config_t &flash_config=hf_stm32_nvs_config_t()) noexcept | |
| Construct with namespace and flash configuration. | |
| ~StmNvs () noexcept override | |
| hf_nvs_err_t | Initialize () noexcept override |
| Initialize the storage system and open the namespace. | |
| hf_nvs_err_t | Deinitialize () noexcept override |
| Deinitialize the storage system and close the namespace. | |
| hf_nvs_err_t | SetU32 (const char *key, hf_u32_t value) noexcept override |
| Store a 32-bit unsigned integer value. | |
| hf_nvs_err_t | GetU32 (const char *key, hf_u32_t &value) noexcept override |
| Retrieve a 32-bit unsigned integer value. | |
| hf_nvs_err_t | SetString (const char *key, const char *value) noexcept override |
| Store a string value. | |
| 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. | |
| hf_nvs_err_t | SetBlob (const char *key, const void *data, size_t data_size) noexcept override |
| Store binary data (blob). | |
| 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). | |
| hf_nvs_err_t | EraseKey (const char *key) noexcept override |
| Remove a key from storage. | |
| hf_nvs_err_t | Commit () noexcept override |
| Commit any pending writes to non-volatile storage. | |
| bool | KeyExists (const char *key) noexcept override |
| Check if a key exists in storage. | |
| hf_nvs_err_t | GetSize (const char *key, size_t &size) noexcept override |
| Get the size of a stored value. | |
| const char * | GetDescription () const noexcept override |
| Get description of this storage implementation. | |
| size_t | GetMaxKeyLength () const noexcept override |
| Get maximum key length supported. | |
| size_t | GetMaxValueSize () const noexcept override |
| Get maximum value size supported. | |
| const hf_stm32_nvs_config_t & | GetFlashConfig () const noexcept |
| Get the flash configuration. | |
| size_t | GetEntryCount () const noexcept |
| Get number of stored entries. | |
| size_t | GetFreeSpace () const noexcept |
| Get available free space in current sector (bytes) | |
Public Member Functions inherited from BaseNvs | |
| virtual | ~BaseNvs () noexcept=default |
| Virtual destructor to ensure proper cleanup. | |
| BaseNvs (const BaseNvs &)=delete | |
| BaseNvs & | operator= (const BaseNvs &)=delete |
| bool | EnsureInitialized () |
| Ensures that the NVS storage is initialized (lazy initialization). | |
| bool | EnsureDeinitialized () |
| Ensures that the NVS storage is deinitialized. | |
| bool | IsInitialized () const noexcept |
| Check if storage is initialized. | |
| const char * | GetNamespace () const noexcept |
| Get the namespace name. | |
| virtual hf_nvs_err_t | ResetStatistics () noexcept |
| Reset NVS operation statistics. | |
| virtual hf_nvs_err_t | ResetDiagnostics () noexcept |
| Reset NVS diagnostic information. | |
| virtual hf_nvs_err_t | GetStatistics (hf_nvs_statistics_t &statistics) const noexcept |
| Get NVS operation statistics. | |
| virtual hf_nvs_err_t | GetDiagnostics (hf_nvs_diagnostics_t &diagnostics) const noexcept |
| Get NVS diagnostic information. | |
Private Types | |
| enum class | EntryType : hf_u8_t { U32 = 0x01 , STRING = 0x02 , BLOB = 0x03 , ERASED = 0xFF } |
| NVS entry types. More... | |
Private Member Functions | |
| struct | __attribute__ ((packed)) EntryHeader |
| Entry header stored in flash (packed) | |
| int | FindCacheEntry (const char *key) const noexcept |
| Find entry in RAM cache by key. | |
| int | AddOrUpdateCache (const char *key, EntryType type, const void *data, size_t data_size) noexcept |
| Add or update entry in RAM cache. | |
| bool | IsValidKey (const char *key) const noexcept |
| Validate a key string. | |
| hf_nvs_err_t | FlushToFlash () noexcept |
| Write all dirty entries to flash. | |
| hf_nvs_err_t | LoadFromFlash () noexcept |
| Read entries from flash into RAM cache. | |
Static Private Member Functions | |
| static hf_u32_t | ComputeCrc32 (const void *data, size_t length) noexcept |
| Simple CRC32 for entry validation. | |
Private Attributes | |
| hf_stm32_nvs_config_t | flash_config_ |
| Flash region config. | |
| CacheEntry | cache_ [kMaxEntries] |
| RAM cache. | |
| size_t | entry_count_ |
| Current entry count. | |
| hf_u32_t | write_offset_ |
| Current write position in flash. | |
Static Private Attributes | |
| static constexpr size_t | kMaxEntries = 64 |
| Max cached entries. | |
Additional Inherited Members | |
Protected Member Functions inherited from BaseNvs | |
| BaseNvs (const char *namespace_name) noexcept | |
| Protected constructor with namespace specification. | |
| void | SetInitialized (bool initialized) noexcept |
| Set the initialized state. | |
Protected Attributes inherited from BaseNvs | |
| const char * | namespace_name_ |
| Namespace name. | |
| bool | initialized_ |
| Initialization status. | |
| hf_nvs_statistics_t | statistics_ |
| NVS operation statistics. | |
| hf_nvs_diagnostics_t | diagnostics_ |
| NVS diagnostic information. | |
STM32 NVS — flash-backed key-value store with wear leveling.
Design:
|
strongprivate |
|
explicitnoexcept |
Construct with namespace and flash configuration.
| namespace_name | Logical namespace (for multi-partition support) |
| flash_config | Flash region configuration |
|
overridenoexcept |
|
inlineprivate |
Entry header stored in flash (packed)
< Key string length (not including null)
< Value type
< Data length in bytes
< CRC32 of key + data
|
privatenoexcept |
Add or update entry in RAM cache.
|
overridevirtualnoexcept |
Commit any pending writes to non-volatile storage.
Implements BaseNvs.
|
staticprivatenoexcept |
Simple CRC32 for entry validation.
|
overridevirtualnoexcept |
Deinitialize the storage system and close the namespace.
Implements BaseNvs.
|
overridevirtualnoexcept |
Remove a key from storage.
| key | Storage key to remove |
Implements BaseNvs.
|
privatenoexcept |
Find entry in RAM cache by key.
|
privatenoexcept |
Write all dirty entries to flash.
|
overridevirtualnoexcept |
Retrieve binary data (blob).
| key | Storage key (null-terminated string) |
| buffer | Buffer to store the retrieved data |
| buffer_size | Size of the buffer in bytes |
| actual_size | Actual size of the data (optional) |
Implements BaseNvs.
|
overridevirtualnoexcept |
|
inlinenoexcept |
Get number of stored entries.
|
inlinenoexcept |
Get the flash configuration.
|
noexcept |
Get available free space in current sector (bytes)
|
overridevirtualnoexcept |
|
overridevirtualnoexcept |
|
overridevirtualnoexcept |
Get the size of a stored value.
| key | Storage key |
| size | Reference to store the size |
Implements BaseNvs.
|
overridevirtualnoexcept |
Retrieve a string value.
| key | Storage key (null-terminated string) |
| buffer | Buffer to store the retrieved string |
| buffer_size | Size of the buffer in bytes |
| actual_size | Actual size of the string (optional) |
Implements BaseNvs.
|
overridevirtualnoexcept |
Retrieve a 32-bit unsigned integer value.
| key | Storage key (null-terminated string) |
| value | Reference to store the retrieved value |
Implements BaseNvs.
|
overridevirtualnoexcept |
Initialize the storage system and open the namespace.
Implements BaseNvs.
|
privatenoexcept |
Validate a key string.
|
overridevirtualnoexcept |
Check if a key exists in storage.
| key | Storage key to check |
Implements BaseNvs.
|
privatenoexcept |
Read entries from flash into RAM cache.
|
overridevirtualnoexcept |
Store binary data (blob).
| key | Storage key (null-terminated string) |
| data | Pointer to data to store |
| data_size | Size of data in bytes |
Implements BaseNvs.
|
overridevirtualnoexcept |
Store a string value.
| key | Storage key (null-terminated string) |
| value | String value to store |
Implements BaseNvs.
|
overridevirtualnoexcept |
Store a 32-bit unsigned integer value.
| key | Storage key (null-terminated string) |
| value | Value to store |
Implements BaseNvs.
|
private |
RAM cache.
|
private |
Current entry count.
|
private |
Flash region config.
|
staticconstexprprivate |
Max cached entries.
|
private |
Current write position in flash.