Skip to main content

FileFlash

Struct FileFlash 

Source
pub struct FileFlash { /* private fields */ }

Implementations§

Source§

impl FileFlash

Source

pub fn new( file: File, capacity: u32, page_size: usize, block_size: usize, durability: Durability, ) -> Result<Self, Error>

Examples found in repository?
examples/slate_flash_calib.rs (line 58)
49fn time_flash_programs(dir: &std::path::Path, label: &str, dur: Durability) {
50    let path = dir.join(format!("calib_{label}.bin"));
51    let file = OpenOptions::new()
52        .read(true)
53        .write(true)
54        .create(true)
55        .truncate(false)
56        .open(&path)
57        .unwrap();
58    let mut flash = FileFlash::new(file, CAPACITY, PAGE, BLOCK, dur).unwrap();
59    let buf = [0xA5u8; PAGE];
60    let mut ns = Vec::with_capacity(N);
61    // Each page may be programmed once, so every iteration targets a fresh
62    // page rather than re-erasing (an erase is a different cost).
63    for i in 0..N {
64        let addr = (i * PAGE) as u32;
65        let t0 = Instant::now();
66        flash.program(addr, &buf).unwrap();
67        ns.push(t0.elapsed().as_nanos() as u64);
68    }
69    summarize(&format!("FileFlash::program,{label}"), ns);
70    drop(flash);
71    let _ = std::fs::remove_file(&path);
72}
Source

pub fn counters(&self) -> FlashCounters

Device I/O tallies accumulated since this handle was created.

Trait Implementations§

Source§

impl Flash for FileFlash

Source§

type Error = FileFlashError

Flash error type.
Source§

fn page_size(&self) -> usize

Program granularity.
Source§

fn block_size(&self) -> usize

Erase granularity, multiple of page_size.
Source§

fn capacity(&self) -> u32

Capacity in bytes, C_flash.
Source§

fn read(&mut self, addr: u32, buf: &mut [u8]) -> Result<(), Self::Error>

Reads from flash.
Source§

fn program(&mut self, addr: u32, buf: &[u8]) -> Result<(), Self::Error>

May only program pages that are in erased state. addr and buf.len() must be page-aligned/page-sized multiples. Completion = durable.
Source§

fn erase(&mut self, block_addr: u32) -> Result<(), Self::Error>

Erases a block resetting it to all 1s.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.