diff --git a/services/test-swapper/Cargo.toml b/services/test-swapper/Cargo.toml index 7f310798c..599e4876c 100644 --- a/services/test-swapper/Cargo.toml +++ b/services/test-swapper/Cargo.toml @@ -23,7 +23,7 @@ rkyv = { version = "0.8.8", default-features = false, features = [ "std", "alloc", ] } - +xous-swapper = { path = "../xous-swapper" } utralib = { version = "0.1.25", optional = true, default-features = false } diff --git a/services/test-swapper/src/main.rs b/services/test-swapper/src/main.rs index ec57a34f8..9df616d95 100644 --- a/services/test-swapper/src/main.rs +++ b/services/test-swapper/src/main.rs @@ -29,9 +29,10 @@ fn main() -> ! { } log::info!("start spi flash map test"); - let spimap = xous::map_memory( + let mut spimap = xous::map_memory( None, xous::MemoryAddress::new(xous::arch::MMAP_VIRT_BASE), + // should normally be cramium_hal::board::SPINOR_LEN 16 * 1024 * 1024, xous::MemoryFlags::R | xous::MemoryFlags::W | xous::MemoryFlags::VIRT, ) @@ -39,15 +40,30 @@ fn main() -> ! { log::info!("spimap: {:x?}", spimap); // cache_flush(); // we have the mapping, now try to dereference it and read something to test it - let spislice: &[u32] = unsafe { spimap.as_slice() }; + let spislice: &mut [u32] = unsafe { spimap.as_slice_mut() }; log::info!("spislice ptr: {:x}", spislice.as_ptr() as usize); // this should trigger the page fault and thus the handler log::info!("spislice @ 0: {:x?}", &spislice[..32]); log::info!("spislice @ 16384: {:x?}", &spislice[16384..16384 + 32]); log::info!("spislice @ 8190: {:x?}", &spislice[8190..8190 + 32]); + + // poke some data into the slice for flushing + log::info!("writing data"); + for (i, d) in spislice[4096 / size_of::()..(4096 / size_of::()) + 4].iter_mut().enumerate() { + *d = i as u32 | 0x1111_0000; + } + log::info!("wrote: {:x?}", &spislice[4096 / size_of::()..(4096 / size_of::()) + 4]); + // marks modified pages as dirty. + xous_swapper::mark_dirty(&spislice[4096 / size_of::()..(4096 / size_of::()) + 4]); + log::info!("pages marked as dirty; now doing sync"); + + // Calls sync to explicitly flush the dirty pages now + xous_swapper::sync(Some(&spislice[4096 / size_of::()..(4096 / size_of::()) + 4])); + // xous_swapper::sync::(None); + log::info!("sync call done"); + log::info!("end spi flash map test"); - loop {} const DELAY_MS: u64 = 1000; for i in 0.. {