diff --git a/embedded-mcu-hal/src/nvram.rs b/embedded-mcu-hal/src/nvram.rs index f7d134d..60408b8 100644 --- a/embedded-mcu-hal/src/nvram.rs +++ b/embedded-mcu-hal/src/nvram.rs @@ -14,7 +14,23 @@ pub trait NvramStorage<'a, T>: Send { pub trait Nvram<'a, StorageType, StoredType, const CELL_COUNT: usize>: Send where StorageType: NvramStorage<'a, StoredType>, + StoredType: Copy, { /// Returns an array of mutable storage cells. + /// + /// This method borrows the NVRAM for its entire lifetime to prevent double-borrowing + /// of the underlying hardware. It can effectively only be called once per instance. fn storage(&'a mut self) -> &'a mut [StorageType; CELL_COUNT]; + + /// Dumps the contents of all storage cells into an array. + /// This is for integrity validation purposes and not an alternative to `storage`. + fn dump_storage(&self) -> [StoredType; CELL_COUNT]; + + /// Clears all storage cells to an implementation-defined cleared state. + /// + /// StoredType implementations should document their clearing behavior. For numeric + /// types like u32, this is commonly zero. + /// Best practice is to use this API, if needed, during device initialization to ensure + /// a known state prior to calling `storage()` and utilizing the NVRAM cells. + fn clear_storage(&mut self); }