diff --git a/services/pddb/src/tests.rs b/services/pddb/src/tests.rs index e19b86efd..96560759b 100644 --- a/services/pddb/src/tests.rs +++ b/services/pddb/src/tests.rs @@ -555,16 +555,6 @@ pub(crate) fn ci_tests(pddb_os: &mut PddbOs) -> Result<()> { log::info!("CI done"); - /* - // abortive attempt to get CI to exit cleanly - #[cfg(not(any(target_os = "none", target_os = "xous")))] - { - let xns = xous_names::XousNames::new().unwrap(); - let susres = susres::Susres::new_without_hook(&xns).unwrap(); - susres.initiate_suspend().expect("couldn't initiate suspend op"); - //xous::rsyscall(xous::SysCall::Shutdown).expect("unable to quit"); - }*/ - Ok(()) } } diff --git a/services/shellchat/src/cmds/sleep.rs b/services/shellchat/src/cmds/sleep.rs index f2c126aab..698e33bc5 100644 --- a/services/shellchat/src/cmds/sleep.rs +++ b/services/shellchat/src/cmds/sleep.rs @@ -64,7 +64,15 @@ impl<'a> ShellCmdApi<'a> for Sleep { write!(ret, "crypto power is now off").unwrap(); } "sus" => { - self.susres.initiate_suspend().unwrap(); + match self.susres.initiate_suspend() { + Err(xous::Error::Timeout) => { + write!(ret, "Couldn't suspend, a server was blocking suspend.\n").ok(); + } + Ok(_) => {}, + Err(e) => { + write!(ret, "Unknown error on suspend: {:?}", e).ok(); + } + } // the message below is sent after we wake up write!(ret, "Resumed from sleep!").unwrap(); } @@ -82,7 +90,15 @@ impl<'a> ShellCmdApi<'a> for Sleep { loop { log::info!("suspend/resume cycle: {}", iters); llio.set_wakeup_alarm(4).unwrap(); - susres.initiate_suspend().unwrap(); + match susres.initiate_suspend() { + Err(xous::Error::Timeout) => { + log::warn!("Couldn't suspend, a server was blocking suspend.\n"); + } + Ok(_) => {}, + Err(e) => { + log::error!("Unknown error on suspend: {:?}", e); + } + } ticktimer.sleep_ms(8000).unwrap(); iters += 1; } diff --git a/services/status/locales/i18n.json b/services/status/locales/i18n.json index 30c4b7c89..6e00411b2 100644 --- a/services/status/locales/i18n.json +++ b/services/status/locales/i18n.json @@ -1,4 +1,10 @@ { + "suspend.fail": { + "ja": "中断不可能な操作が保留中です。 数秒後にスリープ リクエストを再試行してください。", + "en": "Uninterruptible operation pending. Please retry the sleep request in a couple seconds.", + "zh": "不间断操作挂起。 请在几秒钟后重试睡眠请求。", + "en-tts": "Uninterruptible operation pending. Please retry the sleep request in a couple seconds." + }, "socup.candidate": { "ja": "ゲートウェアの更新候補が見つかりました。\n\n適用する必要がありますか?", "en": "An update candidate for the SoC was found.\n\nShould we apply it?\n\nNOTE: if you just installed an update, try rebooting using a paperclip in the hole in the lower right hand corner. This forces the latest image to load.", diff --git a/services/status/src/main.rs b/services/status/src/main.rs index a0de16afe..2d72a8d08 100644 --- a/services/status/src/main.rs +++ b/services/status/src/main.rs @@ -1001,7 +1001,15 @@ fn wrapped_main() -> ! { modals.show_notification(t!("mainmenu.cant_sleep", xous::LANG), None).expect("couldn't notify that power is plugged in"); } else { // log::set_max_level(log::LevelFilter::Debug); - susres.initiate_suspend().expect("couldn't initiate suspend op"); + match susres.initiate_suspend() { + Ok(_) => {}, + Err(xous::Error::Timeout) => { + modals.show_notification(t!("suspend.fail", xous::LANG), None).unwrap(); + } + Err(_e) => { + panic!("Unhandled error on suspend request"); + } + } } }, Some(StatusOpcode::BatteryDisconnect) => { diff --git a/services/susres/src/lib.rs b/services/susres/src/lib.rs index 7bd46b960..9bcefe314 100644 --- a/services/susres/src/lib.rs +++ b/services/susres/src/lib.rs @@ -53,7 +53,6 @@ impl Susres { }) } pub fn conn(&self) -> CID { self.conn } - pub fn getop_suspend(&self) -> u32 { Opcode::SuspendRequest.to_u32().unwrap() } pub fn new_without_hook(xns: &xous_names::XousNames) -> Result { REFCOUNT.fetch_add(1, Ordering::Relaxed); @@ -66,9 +65,19 @@ impl Susres { pub fn initiate_suspend(&self) -> Result<(), xous::Error> { log::trace!("suspend initiated"); - send_message(self.conn, - Message::new_scalar(Opcode::SuspendRequest.to_usize().unwrap(), 0, 0, 0, 0) - ).map(|_|()) + match send_message(self.conn, + Message::new_blocking_scalar(Opcode::SuspendRequest.to_usize().unwrap(), 0, 0, 0, 0) + ) { + Ok(xous::Result::Scalar1(result)) => { + if result == 1 { + Ok(()) + } else { + // indicate that we couldn't initiate the suspend + Err(xous::Error::Timeout) + } + }, + _ => Err(xous::Error::InternalError) + } } pub fn suspend_until_resume(&mut self, token: usize) -> Result { diff --git a/services/susres/src/main.rs b/services/susres/src/main.rs index 22ac544d6..b6d097710 100644 --- a/services/susres/src/main.rs +++ b/services/susres/src/main.rs @@ -699,6 +699,9 @@ fn main() -> ! { // if the 2-second timeout is still pending from a previous suspend, deny the suspend request. // ...just don't suspend that quickly after resuming??? if allow_suspend && !timeout_pending { + // ack the request early + xous::return_scalar(msg.sender, 1).ok(); + susres_hw.ignore_wfi(); suspend_requested = true; // clear the resume gate @@ -726,7 +729,8 @@ fn main() -> ! { // let the events fire xous::yield_slice(); } else { - log::warn!("suspend requested, but the system was not allowed to suspend. Ignoring request.") + log::warn!("suspend requested, but the system was not allowed to suspend. Ignoring request."); + xous::return_scalar(msg.sender, 0).ok(); } }, Some(Opcode::SuspendTimeout) => {