Skip to content

doc: Clarify constraints #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
/// Currently contains [`OverlapIterator`]
pub mod iter;
/// Technology specific traits for NOR Flashes
///
/// These traits are suitable for NOR flash backed memory, but given the wide range of flash
/// technologies, not all NOR flashes may implement all those traits, nor <!-- no pun intended -->
/// will every instance necessarily be backed by NOR flash. The documentation of the individual
/// traits and their members define the precise criteria for the applicability of the trait.
pub mod nor_flash;

/// A region denotes a contiguous piece of memory between two addresses.
Expand Down
21 changes: 16 additions & 5 deletions src/nor_flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ pub trait ReadNorFlash: ErrorType {
///
/// # Errors
///
/// Returns an error if the arguments are not aligned or out of bounds. The implementation
/// can use the [`check_read`] helper function.
/// Returns an error if the arguments are not aligned, or if the range exceeds the bounds. The
/// implementation can use the [`check_read`] helper function.
fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error>;

/// The capacity of the peripheral in bytes.
///
/// This must be a multiple of READ_SIZE.
fn capacity(&self) -> usize;
}

Expand All @@ -83,10 +85,12 @@ pub fn check_read<T: ReadNorFlash>(

/// NOR flash trait.
pub trait NorFlash: ReadNorFlash {
/// The minumum number of bytes the storage peripheral can write
/// The number of bytes to which writes must be aligned, and of of which written lengths must
/// be a multiple of.
const WRITE_SIZE: usize;

/// The minumum number of bytes the storage peripheral can erase
/// The number of bytes to which erases must be aligned, and of of which erased lengths must be
/// a multiple of.
const ERASE_SIZE: usize;

/// Erase the given storage range, clearing all data within `[from..to]`.
Expand All @@ -103,7 +107,8 @@ pub trait NorFlash: ReadNorFlash {

/// If power is lost during write, the contents of the written words are undefined,
/// but the rest of the page is guaranteed to be unchanged.
/// It is not allowed to write to the same word twice.
/// It is not allowed to write to the same word twice unless another trait
/// ([MultiwriteNorFlash]) allows it.
///
/// # Errors
///
Expand Down Expand Up @@ -216,7 +221,11 @@ impl Region for Page {
}
}

/// An implementation of byte-addressed [Storage] based on [NorFlash]
///
/// The provided storage is as large as the underlying flash memory, and thus no journaling is
/// performed. If a write is interrupted, up to a page of data (a size that is not visible to
/// consumers of the [Storage] trait) may be lost.
pub struct RmwNorFlashStorage<'a, S> {
storage: S,
merge_buffer: &'a mut [u8],
Expand Down Expand Up @@ -291,7 +300,9 @@ where
}
}

/// An implementation of byte-addressed [Storage] based on [MultiwriteNorFlash]
///
/// Compared to [RmwNorFlashStorage], this may save erases.
pub struct RmwMultiwriteNorFlashStorage<'a, S> {
storage: S,
merge_buffer: &'a mut [u8],
Expand Down