Move choice between prod and test storage to embedded_flash module

This way all users of storage can share the logic to choose between flash or RAM
storage depending on the "std" feature. This is needed because the store_latency
example assumes flash storage but is built when running `cargo test
--features=std`.
This commit is contained in:
Julien Cretin
2020-12-10 18:04:25 +01:00
parent ece546a03b
commit 371b8af224
3 changed files with 41 additions and 35 deletions

View File

@@ -19,10 +19,10 @@ extern crate lang_items;
use alloc::vec;
use core::fmt::Write;
use ctap2::embedded_flash::SyscallStorage;
use ctap2::embedded_flash::{new_storage, Storage};
use libtock_drivers::console::Console;
use libtock_drivers::timer::{self, Duration, Timer, Timestamp};
use persistent_store::{Storage, Store};
use persistent_store::Store;
fn timestamp(timer: &Timer) -> Timestamp<f64> {
Timestamp::<f64>::from_clock_value(timer.get_current_clock().ok().unwrap())
@@ -36,10 +36,11 @@ fn measure<T>(timer: &Timer, operation: impl FnOnce() -> T) -> (T, Duration<f64>
}
// Only use one store at a time.
unsafe fn boot_store(num_pages: usize, erase: bool) -> Store<SyscallStorage> {
let mut storage = SyscallStorage::new(num_pages).unwrap();
unsafe fn boot_store(num_pages: usize, erase: bool) -> Store<Storage> {
let mut storage = new_storage(num_pages);
if erase {
for page in 0..storage.num_pages() {
for page in 0..num_pages {
use persistent_store::Storage;
storage.erase_page(page).unwrap();
}
}