Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions embedded-mcu-hal/src/nvram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}