diff --git a/services/status/locales/i18n.json b/services/status/locales/i18n.json index 0304a1fd4..3c5ba7f81 100644 --- a/services/status/locales/i18n.json +++ b/services/status/locales/i18n.json @@ -64,6 +64,11 @@ "zh": "设置时间", "en-audio": "Set time" }, + "mainmenu.reboot": { + "en": "Reboot", + "zh": "重启", + "en-audio": "Reboot" + }, "mainmenu.closemenu": { "en": "Close menu", "zh": "关闭功能表", diff --git a/services/status/src/main.rs b/services/status/src/main.rs index f5fecf935..98729081b 100644 --- a/services/status/src/main.rs +++ b/services/status/src/main.rs @@ -41,6 +41,8 @@ enum StatusOpcode { Pump, /// Pulls up the time setting UI UxSetTime, + /// Initiates a reboot + Reboot, Quit, } @@ -141,6 +143,7 @@ fn xmain() -> ! { let gam = gam::Gam::new(&xns).expect("|status: can't connect to GAM"); let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer"); let mut com = com::Com::new(&xns).expect("|status: can't connect to COM"); + let susres = susres::Susres::new_without_hook(&xns).unwrap(); log::trace!("|status: getting screen size"); let screensize = gam @@ -597,6 +600,25 @@ fn xmain() -> ! { rtc.set_rtc(dt).expect("couldn't set the current time"); pump_run.store(true, Ordering::Relaxed); // stop status updates while we do this }), + Some(StatusOpcode::Reboot) => { + if ((llio.adc_vbus().unwrap() as f64) * 0.005033) > 1.5 { + // power plugged in, do a reboot using a warm boot method + susres.reboot(true).expect("couldn't issue reboot command"); + } else { + // ensure the self-boosting facility is turned off, this interferes with a cold boot + com.set_boost(false).ok(); + llio.boost_on(false).ok(); + // do a full cold-boot if the power is cut. This will force a re-load of the SoC contents. + gam.shipmode_blank_request().ok(); + ticktimer.sleep_ms(500).ok(); // screen redraw time after the blank request + rtc.set_wakeup_alarm(4).expect("couldn't set wakeup alarm"); + llio.allow_ec_snoop(true).ok(); + llio.allow_power_off(true).ok(); + com.power_off_soc().ok(); + ticktimer.sleep_ms(4000).ok(); + panic!("system did not reboot"); + } + } Some(StatusOpcode::Quit) => { break; } diff --git a/services/status/src/mainmenu.rs b/services/status/src/mainmenu.rs index 8855af941..7931fb504 100644 --- a/services/status/src/mainmenu.rs +++ b/services/status/src/mainmenu.rs @@ -84,6 +84,15 @@ pub fn main_menu_thread(keys: Arc>, status_sid: xous::SID) { }; menu.add_item(setrtc_item); + let reboot_item = MenuItem { + name: String::<64>::from_str(t!("mainmenu.reboot", xous::LANG)), + action_conn: status_conn, + action_opcode: StatusOpcode::Reboot.to_u32().unwrap(), + action_payload: MenuPayload::Scalar([0, 0, 0, 0]), + close_on_select: true, + }; + menu.add_item(reboot_item); + let close_item = MenuItem { name: String::<64>::from_str(t!("mainmenu.closemenu", xous::LANG)), action_conn: menu.gam.conn(), diff --git a/services/susres/src/lib.rs b/services/susres/src/lib.rs index b0e613739..a1c6169e0 100644 --- a/services/susres/src/lib.rs +++ b/services/susres/src/lib.rs @@ -115,6 +115,23 @@ impl Susres { } } + /// Passing `true` causes the whole SOC including peripherals to receive a reset signal + /// `false` causes only the CPU to reboot, while the peripherals retain state. Generally you want `true`. + pub fn reboot(&self, whole_soc: bool) -> Result<(), xous::Error> { + send_message(self.conn, + Message::new_scalar(Opcode::RebootRequest.to_usize().unwrap(), 0, 0, 0, 0) + ).map(|_|())?; + + if whole_soc { + send_message(self.conn, + Message::new_scalar(Opcode::RebootSocConfirm.to_usize().unwrap(), 0, 0, 0, 0) + ).map(|_|()) + } else { + send_message(self.conn, + Message::new_scalar(Opcode::RebootCpuConfirm.to_usize().unwrap(), 0, 0, 0, 0) + ).map(|_|()) + } + } } fn drop_conn(sid: xous::SID) { let cid = xous::connect(sid).unwrap();