add a reboot command to the main menu

This commit is contained in:
bunnie 2022-01-12 14:00:31 +08:00
parent f53f86077d
commit 69eefb3e64
4 changed files with 53 additions and 0 deletions

View file

@ -64,6 +64,11 @@
"zh": "设置时间",
"en-audio": "Set time"
},
"mainmenu.reboot": {
"en": "Reboot",
"zh": "重启",
"en-audio": "Reboot"
},
"mainmenu.closemenu": {
"en": "Close menu",
"zh": "关闭功能表",

View file

@ -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;
}

View file

@ -84,6 +84,15 @@ pub fn main_menu_thread(keys: Arc<Mutex<RootKeys>>, 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(),

View file

@ -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();