Expand description

A queue (fifo) implementation for storing arbitrary data in flash memory.

Use push to add data to the fifo and use peek and pop to get the data back.


// Initialize the flash. This can be internal or external
let mut flash = init_flash();
// These are the flash addresses in which the crate will operate.
// The crate will not read, write or erase outside of this range.
let flash_range = 0x1000..0x3000;
// We need to give the crate a buffer to work with.
// It must be big enough to serialize the biggest value of your storage type in.
let mut data_buffer = [0; 128];

let my_data = [10, 47, 29];

// We can push some data to the queue
push(&mut flash, flash_range.clone(), NoCache::new(), &my_data, false).await.unwrap();

// We can peek at the oldest data

assert_eq!(
    &peek(&mut flash, flash_range.clone(), NoCache::new(), &mut data_buffer).await.unwrap().unwrap()[..],
    &my_data[..]
);

// With popping we get back the oldest data, but that data is now also removed

assert_eq!(
    &pop(&mut flash, flash_range.clone(), NoCache::new(), &mut data_buffer).await.unwrap().unwrap()[..],
    &my_data[..]
);

// If we pop again, we find there's no data anymore

assert_eq!(
    pop(&mut flash, flash_range.clone(), NoCache::new(), &mut data_buffer).await,
    Ok(None)
);

Structs§

Functions§

  • Find the largest size of data that can be stored.
  • Peek at the oldest data.
  • Peek at the data from oldest to newest.
  • Pop the oldest data from the queue.
  • Pop the data from oldest to newest.
  • Push data into the queue in the given flash memory with the given range. The data can only be taken out with the pop function.
  • Try to repair the state of the flash to hopefull get back everything in working order. Care is taken that no data is lost, but this depends on correctly repairing the state and so is only best effort.