41#define HF_NVS_ERR_LIST(X) \
43 X(NVS_SUCCESS, 0, "Success") \
45 X(NVS_ERR_FAILURE, 1, "General failure") \
46 X(NVS_ERR_NOT_INITIALIZED, 2, "Not initialized") \
47 X(NVS_ERR_ALREADY_INITIALIZED, 3, "Already initialized") \
48 X(NVS_ERR_INVALID_PARAMETER, 4, "Invalid parameter") \
49 X(NVS_ERR_NULL_POINTER, 5, "Null pointer") \
50 X(NVS_ERR_OUT_OF_MEMORY, 6, "Out of memory") \
52 X(NVS_ERR_KEY_NOT_FOUND, 7, "Key not found") \
53 X(NVS_ERR_KEY_TOO_LONG, 8, "Key too long") \
54 X(NVS_ERR_VALUE_TOO_LARGE, 9, "Value too large") \
55 X(NVS_ERR_NAMESPACE_NOT_FOUND, 10, "Namespace not found") \
56 X(NVS_ERR_STORAGE_FULL, 11, "Storage full") \
57 X(NVS_ERR_INVALID_DATA, 12, "Invalid data") \
58 X(NVS_ERR_READ_ONLY, 13, "Read only mode") \
59 X(NVS_ERR_CORRUPTED, 14, "Data corrupted") \
61 X(NVS_ERR_ENCRYPTION_FAILED, 15, "Encryption operation failed") \
62 X(NVS_ERR_DECRYPTION_FAILED, 16, "Decryption operation failed") \
63 X(NVS_ERR_ENCRYPTION_NOT_CONFIGURED, 17, "Encryption not configured") \
64 X(NVS_ERR_ENCRYPTION_NOT_SUPPORTED, 18, "Encryption not supported") \
65 X(NVS_ERR_KEY_PARTITION_CORRUPTED, 19, "Key partition corrupted") \
66 X(NVS_ERR_WRONG_ENCRYPTION_SCHEME, 20, "Wrong encryption scheme") \
67 X(NVS_ERR_VERSION_MISMATCH, 21, "NVS version mismatch") \
68 X(NVS_ERR_NO_FREE_PAGES, 22, "No free pages available") \
69 X(NVS_ERR_PARTITION_NOT_FOUND, 23, "NVS partition not found") \
70 X(NVS_ERR_ITERATOR_INVALID, 24, "Iterator invalid or expired") \
71 X(NVS_ERR_SECURITY_VIOLATION, 25, "Security policy violation") \
72 X(NVS_ERR_UNSUPPORTED_OPERATION, 26, "Unsupported operation") \
73 X(NVS_ERR_UNKNOWN, 27, "Unknown error")
77#define X(name, value, desc) name = value,
89#define X(NAME, VALUE, DESC) \
90 case hf_nvs_err_t::NAME: \
242 size_t* actual_size =
nullptr) noexcept = 0;
262 size_t* actual_size =
nullptr) noexcept = 0;
371 explicit BaseNvs(
const char* namespace_name) noexcept
hf_nvs_err_t
Definition BaseNvs.h:76
@ NVS_ERR_UNSUPPORTED_OPERATION
constexpr std::string_view HfNvsErrToString(hf_nvs_err_t err) noexcept
Convert NVS error code to string view.
Definition BaseNvs.h:87
#define X(name, value, desc)
Definition BaseNvs.h:77
Platform-agnostic hardware type definitions for the HardFOC system.
uint32_t hf_u32_t
Platform-agnostic 32-bit unsigned integer type.
Definition HardwareTypes.h:52
int32_t hf_i32_t
Platform-agnostic 32-bit signed integer type.
Definition HardwareTypes.h:76
Abstract base class for non-volatile storage operations.
Definition BaseNvs.h:147
virtual hf_nvs_err_t ResetDiagnostics() noexcept
Reset NVS diagnostic information.
Definition BaseNvs.h:341
virtual size_t GetMaxValueSize() const noexcept=0
Get maximum value size supported.
virtual hf_nvs_err_t Commit() noexcept=0
Commit any pending writes to non-volatile storage.
hf_nvs_statistics_t statistics_
NVS operation statistics.
Definition BaseNvs.h:384
void SetInitialized(bool initialized) noexcept
Set the initialized state.
Definition BaseNvs.h:378
virtual hf_nvs_err_t SetBlob(const char *key, const void *data, size_t data_size) noexcept=0
Store binary data (blob).
virtual hf_nvs_err_t GetStatistics(hf_nvs_statistics_t &statistics) const noexcept
Get NVS operation statistics.
Definition BaseNvs.h:351
virtual ~BaseNvs() noexcept=default
Virtual destructor to ensure proper cleanup.
virtual hf_nvs_err_t Initialize() noexcept=0
Initialize the storage system and open the namespace.
bool EnsureDeinitialized()
Ensures that the NVS storage is deinitialized.
Definition BaseNvs.h:178
bool EnsureInitialized()
Ensures that the NVS storage is initialized (lazy initialization).
Definition BaseNvs.h:167
virtual hf_nvs_err_t GetDiagnostics(hf_nvs_diagnostics_t &diagnostics) const noexcept
Get NVS diagnostic information.
Definition BaseNvs.h:361
virtual size_t GetMaxKeyLength() const noexcept=0
Get maximum key length supported.
virtual hf_nvs_err_t Deinitialize() noexcept=0
Deinitialize the storage system and close the namespace.
virtual const char * GetDescription() const noexcept=0
Get description of this storage implementation.
const char * namespace_name_
Namespace name.
Definition BaseNvs.h:382
const char * GetNamespace() const noexcept
Get the namespace name.
Definition BaseNvs.h:300
hf_nvs_diagnostics_t diagnostics_
NVS diagnostic information.
Definition BaseNvs.h:385
virtual hf_nvs_err_t ResetStatistics() noexcept
Reset NVS operation statistics.
Definition BaseNvs.h:331
virtual hf_nvs_err_t GetSize(const char *key, size_t &size) noexcept=0
Get the size of a stored value.
bool initialized_
Initialization status.
Definition BaseNvs.h:383
virtual hf_nvs_err_t GetString(const char *key, char *buffer, size_t buffer_size, size_t *actual_size=nullptr) noexcept=0
Retrieve a string value.
virtual hf_nvs_err_t SetU32(const char *key, hf_u32_t value) noexcept=0
Store a 32-bit unsigned integer value.
virtual bool KeyExists(const char *key) noexcept=0
Check if a key exists in storage.
virtual hf_nvs_err_t GetU32(const char *key, hf_u32_t &value) noexcept=0
Retrieve a 32-bit unsigned integer value.
virtual hf_nvs_err_t GetBlob(const char *key, void *buffer, size_t buffer_size, size_t *actual_size=nullptr) noexcept=0
Retrieve binary data (blob).
BaseNvs(const char *namespace_name) noexcept
Protected constructor with namespace specification.
Definition BaseNvs.h:371
virtual hf_nvs_err_t EraseKey(const char *key) noexcept=0
Remove a key from storage.
bool IsInitialized() const noexcept
Check if storage is initialized.
Definition BaseNvs.h:189
virtual hf_nvs_err_t SetString(const char *key, const char *value) noexcept=0
Store a string value.
#define HF_NVS_ERR_LIST(X)
HardFOC NVS error codes.
Definition BaseNvs.h:41
NVS diagnostic information.
Definition BaseNvs.h:120
hf_u32_t consecutive_errors
Definition BaseNvs.h:122
hf_u32_t system_uptime_ms
Definition BaseNvs.h:124
hf_nvs_err_t last_error
Definition BaseNvs.h:121
bool storage_healthy
Definition BaseNvs.h:123
NVS operation statistics.
Definition BaseNvs.h:102
hf_u32_t failed_ops
Definition BaseNvs.h:112
hf_u32_t total_erases
Definition BaseNvs.h:108
hf_u32_t total_commits
Definition BaseNvs.h:107
hf_u32_t bytes_written
Definition BaseNvs.h:113
hf_nvs_err_t last_error
Definition BaseNvs.h:109
hf_u32_t last_operation_time_us
Definition BaseNvs.h:110
hf_u32_t bytes_read
Definition BaseNvs.h:114
hf_u32_t total_reads
Definition BaseNvs.h:105
hf_u32_t total_operations
Definition BaseNvs.h:103
hf_u32_t total_errors
Definition BaseNvs.h:104
hf_u32_t total_writes
Definition BaseNvs.h:106
hf_u32_t successful_ops
Definition BaseNvs.h:111