diff --git a/api/xous-api-susres/src/api.rs b/api/xous-api-susres/src/api.rs index 514d2857d..b53d1686d 100644 --- a/api/xous-api-susres/src/api.rs +++ b/api/xous-api-susres/src/api.rs @@ -63,6 +63,9 @@ pub enum Opcode { /// used by processes to indicate they are suspending now; this blocks until resume using the "execution gate" SuspendingNow, + /// used to power off the system without suspend + PowerOff, + /// exit the server Quit, } diff --git a/api/xous-api-susres/src/lib.rs b/api/xous-api-susres/src/lib.rs index 59e7ca51d..9aea42821 100644 --- a/api/xous-api-susres/src/lib.rs +++ b/api/xous-api-susres/src/lib.rs @@ -180,6 +180,13 @@ impl Susres { ).map(|_|()) } } + + /// Pulls power from the SoC without attempting to save state + pub fn immediate_poweroff(&self) -> Result<(), xous::Error> { + send_message(self.conn, + Message::new_scalar(Opcode::PowerOff.to_usize().unwrap(), 0, 0, 0, 0) + ).map(|_|()) + } } fn drop_conn(sid: xous::SID) { let cid = xous::connect(sid).unwrap(); diff --git a/services/xous-susres/src/main.rs b/services/xous-susres/src/main.rs index 32899d084..cafc828dd 100644 --- a/services/xous-susres/src/main.rs +++ b/services/xous-susres/src/main.rs @@ -212,6 +212,12 @@ mod implementation { pub fn set_reboot_vector(&mut self, vector: u32) { self.reboot_csr.wfo(utra::reboot::ADDR_ADDR, vector); } + pub fn force_power_off(&mut self) { + loop { + self.csr.wfo(utra::susres::POWERDOWN_POWERDOWN, 1); + xous::yield_slice(); + } // block forever here + } pub fn setup_timeout_csr(&mut self, cid: xous::CID) -> Result<(), xous::Error> { xous::send_message(cid, @@ -444,6 +450,7 @@ mod implementation { } pub fn reboot(&self, _reboot_soc: bool) {} pub fn set_reboot_vector(&self, _vector: u32) {} + pub fn force_power_off(&mut self) {} pub fn do_suspend(&mut self, _forced: bool) { } pub fn do_resume(&mut self) -> bool { @@ -808,6 +815,9 @@ fn main() -> ! { Some(Opcode::SuspendDeny) => { allow_suspend = false; }, + Some(Opcode::PowerOff) => { + susres_hw.force_power_off(); + } Some(Opcode::Quit) => { break }