diff --git a/services/susres/src/api.rs b/services/susres/src/api.rs index aaf6d705a..a8f483ef4 100644 --- a/services/susres/src/api.rs +++ b/services/susres/src/api.rs @@ -70,7 +70,7 @@ impl SuspendResume for RegManager { if let Some(sp) = self.sus_prologue { sp(self); } - for entry in self.registers.iter_mut() { + for entry in self.registers.iter_mut().rev() { if let Some(reg) = entry { // masking is done on the write side match reg.item { @@ -87,7 +87,7 @@ impl SuspendResume for RegManager { if let Some(rp) = self.res_prologue { rp(self); } - for entry in self.registers.iter().rev() { // this is in reverse order to the suspend + for entry in self.registers.iter() { // this is in reverse order to the suspend if let Some(reg) = entry { if let Some(mut value) = reg.value { if let Some(mask) = reg.mask { @@ -105,12 +105,14 @@ impl SuspendResume for RegManager { } } } -/* + +// because the volatile memory regions can be potentially large (128kiB), but fewer (maybe 5-6 total in the system), +// we allocate these as stand-alone structures and manage them explicitly. pub struct ManagedMem { pub mem: xous::MemoryRange, pub backing: [u32; N], } -pub trait SusResMem { +impl SuspendResume for ManagedMem { fn suspend(&mut self) { let src = self.mem.as_ptr() as *const u32; for words in 0..self.mem.len() { @@ -124,7 +126,6 @@ pub trait SusResMem { } } } -*/ diff --git a/services/susres/src/main.rs b/services/susres/src/main.rs index b2620f20b..796a8547a 100644 --- a/services/susres/src/main.rs +++ b/services/susres/src/main.rs @@ -2,21 +2,77 @@ #![cfg_attr(target_os = "none", no_main)] mod api; +use api::*; use num_traits::FromPrimitive; -use log::info; +#[cfg(target_os = "none")] +mod implementation { + use utralib::generated::*; + use crate::api::*; + + fn handle_irq(_irq_no: usize, arg: *mut usize) { + let sr = unsafe{ &mut *(arg as *mut SusResHw) }; + // dummy routine for now + sr.csr.wfo(utra::susres::EV_PENDING_SOFT_INT, 1); + } + + pub struct SusResHw { + /// our CSR + csr: utralib::CSR, + /// backing store for the ticktimer value + time_backing: Option<[u32; 2]>, + } + impl SusResHw { + pub fn new() -> Self { + let csr = xous::syscall::map_memory( + xous::MemoryAddress::new(utra::susres::HW_SUSRES_BASE), + None, + 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ) + .expect("couldn't map SusRes CSR range"); + + let mut sr = SusResHw { + csr: CSR::new(csr.as_mut_ptr() as *mut u32), + time_backing: None, + }; + + xous::claim_interrupt( + utra::susres::SUSRES_IRQ, + handle_irq, + (&mut sr) as *mut SusResHw as *mut usize, + ).expect("couldn't claim IRQ"); + + sr + } + } + +} + +#[cfg(not(target_os = "none"))] +mod implementation { + pub struct SusResHw { + } + impl SusResHw { + pub fn new() -> Self { + SusResHw {} + } + } +} #[xous::xous_main] fn xmain() -> ! { log_server::init_wait().unwrap(); log::set_max_level(log::LevelFilter::Trace); - info!("my PID is {}", xous::process::id()); + log::info!("my PID is {}", xous::process::id()); let xns = xous_names::XousNames::new().unwrap(); let susres_sid = xns.register_name(api::SERVER_NAME_SUSRES).expect("can't register server"); log::trace!("registered with NS -- {:?}", susres_sid); + let susres_hw = implementation::SusResHw::new(); + loop { let msg = xous::receive_message(susres_sid).unwrap(); /* diff --git a/services/ticktimer-server/src/main.rs b/services/ticktimer-server/src/main.rs index 2075f24ab..fe7eb3bb3 100644 --- a/services/ticktimer-server/src/main.rs +++ b/services/ticktimer-server/src/main.rs @@ -137,7 +137,7 @@ mod implementation { ) .expect("couldn't map Watchdog timer CSR range"); - let susres = RegManager::::new(csr.as_mut_ptr() as *mut u32); + let susres = RegManager::new(csr.as_mut_ptr() as *mut u32); let mut xtt = XousTickTimer { csr: CSR::new(csr.as_mut_ptr() as *mut u32), diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 98d7e9f72..46da750fe 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -143,6 +143,7 @@ cbtest builds an image for callback testing trng-test [soc.svd] builds an image for TRNG testing (both avalanche and ring oscillator on) ro-test [soc.svd] builds an image for ring oscillator only TRNG testing av-test [soc.svd] builds an image for avalanche generater only TRNG testing +sr-test [soc.svd] builds the suspend/resume testing image " ) }