HardFOC Vortex V1 HAL
Unified HAL API for the HardFOC Vortex motor-control platform (ESP32-C6, TMC9660)
Loading...
Searching...
No Matches
NvsManager.h
Go to the documentation of this file.
1
14#ifndef VORTEX_NVS_MANAGER_H_
15#define VORTEX_NVS_MANAGER_H_
16
17#include <atomic>
18#include <cstdint>
19
20#include "core/hf-core-drivers/internal/hf-internal-interface-wrap/inc/base/BaseNvs.h"
21
33public:
34 static NvsManager& GetInstance() noexcept;
35
36 NvsManager(const NvsManager&) = delete;
37 NvsManager& operator=(const NvsManager&) = delete;
40
42 [[nodiscard]] bool EnsureInitialized() noexcept;
43
44 [[nodiscard]] bool IsInitialized() const noexcept {
45 return initialized_.load(std::memory_order_acquire);
46 }
47
49 [[nodiscard]] bool Deinitialize() noexcept;
50
52 [[nodiscard]] hf_nvs_err_t GetLastError() const noexcept { return last_error_; }
53
55 [[nodiscard]] BaseNvs& App() noexcept { return app_; }
56
58 [[nodiscard]] BaseNvs& Calibration() noexcept { return calibration_; }
59
61 [[nodiscard]] BaseNvs& Config() noexcept { return config_; }
62
63 void DumpStatistics() const noexcept;
64
65private:
66 NvsManager() noexcept;
67 ~NvsManager() = default;
68
69 void SetLastError(hf_nvs_err_t e) noexcept { last_error_ = e; }
70
71 // Owned by the board binding (bsp_bind/VortexBoardBind.h); constructing them touches no hardware.
72 BaseNvs& app_;
73 BaseNvs& calibration_;
74 BaseNvs& config_;
75
76 std::atomic<bool> initialized_{false};
77 hf_nvs_err_t last_error_{hf_nvs_err_t::NVS_SUCCESS};
78};
79
80#endif // VORTEX_NVS_MANAGER_H_
Singleton giving access to the Vortex board persistent-storage namespaces.
Definition NvsManager.h:32
NvsManager(NvsManager &&)=delete
BaseNvs & config_
Definition NvsManager.h:74
NvsManager & operator=(NvsManager &&)=delete
hf_nvs_err_t GetLastError() const noexcept
Last NVS error from the most recent failing operation (any region).
Definition NvsManager.h:52
bool IsInitialized() const noexcept
Definition NvsManager.h:44
void SetLastError(hf_nvs_err_t e) noexcept
Definition NvsManager.h:69
BaseNvs & App() noexcept
General application storage (vortex namespace).
Definition NvsManager.h:55
BaseNvs & Calibration() noexcept
Calibration and tuning blobs (vortex_cal namespace).
Definition NvsManager.h:58
bool Deinitialize() noexcept
Close namespaces (call after other subsystems if they may persist on shutdown).
Definition NvsManager.cpp:67
static NvsManager & GetInstance() noexcept
Definition NvsManager.cpp:18
BaseNvs & Config() noexcept
Device configuration (vortex_cfg namespace).
Definition NvsManager.h:61
bool EnsureInitialized() noexcept
Initialize NVS flash (once) and open all Vortex namespaces.
Definition NvsManager.cpp:32
NvsManager(const NvsManager &)=delete
BaseNvs & app_
Definition NvsManager.h:72
BaseNvs & calibration_
Definition NvsManager.h:73
void DumpStatistics() const noexcept
Definition NvsManager.cpp:82
std::atomic< bool > initialized_
Definition NvsManager.h:76
NvsManager & operator=(const NvsManager &)=delete
hf_nvs_err_t last_error_
Definition NvsManager.h:77