mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
make the COM reset no longer open loop; unblock as soon as EC responds
This commit is contained in:
parent
2a2e305c7b
commit
a7c9027d05
5 changed files with 59 additions and 17 deletions
|
|
@ -144,6 +144,9 @@ pub struct WlanDebug {
|
||||||
|
|
||||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||||
pub(crate) enum Opcode {
|
pub(crate) enum Opcode {
|
||||||
|
/// A ping back, used to determine when the COM has finished initializing
|
||||||
|
Ping,
|
||||||
|
|
||||||
/// Reset the COM link - useful after an EC reset
|
/// Reset the COM link - useful after an EC reset
|
||||||
LinkReset,
|
LinkReset,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,15 @@ impl Com {
|
||||||
Message::new_blocking_scalar(Opcode::LinkReset.to_usize().unwrap(), 0, 0, 0, 0)
|
Message::new_blocking_scalar(Opcode::LinkReset.to_usize().unwrap(), 0, 0, 0, 0)
|
||||||
).map(|_| ())
|
).map(|_| ())
|
||||||
}
|
}
|
||||||
|
pub fn ping(&self, value: usize) -> Result<usize, xous::Error> {
|
||||||
|
if let xous::Result::Scalar1(pong) = send_message(self.conn,
|
||||||
|
Message::new_blocking_scalar(Opcode::Ping.to_usize().unwrap(), value, 0, 0, 0)
|
||||||
|
)? {
|
||||||
|
Ok(pong)
|
||||||
|
} else {
|
||||||
|
Err(xous::Error::InternalError)
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn reseed_ec_trng(&self) -> Result<(), xous::Error> {
|
pub fn reseed_ec_trng(&self) -> Result<(), xous::Error> {
|
||||||
send_message(self.conn,
|
send_message(self.conn,
|
||||||
Message::new_scalar(Opcode::ReseedTrng.to_usize().unwrap(), 0, 0, 0, 0)
|
Message::new_scalar(Opcode::ReseedTrng.to_usize().unwrap(), 0, 0, 0, 0)
|
||||||
|
|
|
||||||
|
|
@ -352,7 +352,31 @@ fn xmain() -> ! {
|
||||||
// reset the EC so we're in sync at boot on state
|
// reset the EC so we're in sync at boot on state
|
||||||
let llio = llio::Llio::new(&xns);
|
let llio = llio::Llio::new(&xns);
|
||||||
llio.ec_reset().unwrap();
|
llio.ec_reset().unwrap();
|
||||||
ticktimer.sleep_ms(EC_BOOT_WAIT_MS).unwrap();
|
ticktimer.sleep_ms(250).unwrap();
|
||||||
|
#[cfg(not(any(windows, unix)))] // avoid errors in hosted mode
|
||||||
|
{
|
||||||
|
let mut attempts = 0;
|
||||||
|
let ping_value = 0xaeedu16; // for various reasons, this is a string that is "unlikely" to happen randomly
|
||||||
|
loop {
|
||||||
|
com.txrx(ComState::LINK_PING.verb);
|
||||||
|
com.txrx(ping_value);
|
||||||
|
let pong = com.wait_txrx(ComState::LINK_READ.verb, Some(5000)); // this should "stall" until the EC comes out of reset
|
||||||
|
let phase = com.wait_txrx(ComState::LINK_READ.verb, Some(500));
|
||||||
|
if pong == !ping_value &&
|
||||||
|
phase == 0x600d { // 0x600d is a hard-coded constant. It's included to confirm that we aren't "wedged" just sending one value back at us
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
log::warn!("Wf200 reset: establishing link sync, attempt {} [{:04x}/{:04x}]", attempts, pong, phase);
|
||||||
|
com.txrx(ComState::LINK_SYNC.verb);
|
||||||
|
ticktimer.sleep_ms(200).unwrap();
|
||||||
|
attempts += 1;
|
||||||
|
}
|
||||||
|
if attempts > 50 {
|
||||||
|
log::error!("EC didn't sync out of reset...continuing and praying for the best.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// register a suspend/resume listener
|
// register a suspend/resume listener
|
||||||
let sr_cid = xous::connect(com_sid).expect("couldn't create suspend callback connection");
|
let sr_cid = xous::connect(com_sid).expect("couldn't create suspend callback connection");
|
||||||
|
|
@ -420,6 +444,9 @@ fn xmain() -> ! {
|
||||||
com.txrx(ComState::BL_START.verb | (bl_main as u16) & 0x1f | (((bl_sec as u16) & 0x1f) << 5));
|
com.txrx(ComState::BL_START.verb | (bl_main as u16) & 0x1f | (((bl_sec as u16) & 0x1f) << 5));
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
Some(Opcode::Ping) => xous::msg_blocking_scalar_unpack!(msg, ping, _, _, _, {
|
||||||
|
xous::return_scalar(msg.sender, !ping).unwrap();
|
||||||
|
}),
|
||||||
Some(Opcode::LinkReset) => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
Some(Opcode::LinkReset) => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||||
com.txrx(ComState::LINK_SYNC.verb);
|
com.txrx(ComState::LINK_SYNC.verb);
|
||||||
ticktimer.sleep_ms(200).unwrap(); // give some time for the link to reset - the EC does not have a guaranteed latency to respond to a link reset
|
ticktimer.sleep_ms(200).unwrap(); // give some time for the link to reset - the EC does not have a guaranteed latency to respond to a link reset
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,7 @@ impl XousDisplay {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn redraw(&mut self) {
|
pub fn redraw(&mut self) {
|
||||||
|
log::info!("**update**");
|
||||||
let mut busy_count = 0;
|
let mut busy_count = 0;
|
||||||
let mut dirty_count = 0;
|
let mut dirty_count = 0;
|
||||||
while self.busy() {
|
while self.busy() {
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ pub fn pump_thread(conn: usize, pump_run: Arc<AtomicBool>) {
|
||||||
#[xous::xous_main]
|
#[xous::xous_main]
|
||||||
fn xmain() -> ! {
|
fn xmain() -> ! {
|
||||||
log_server::init_wait().unwrap();
|
log_server::init_wait().unwrap();
|
||||||
log::set_max_level(log::LevelFilter::Info);
|
log::set_max_level(log::LevelFilter::Debug);
|
||||||
log::info!("my PID is {}", xous::process::id());
|
log::info!("my PID is {}", xous::process::id());
|
||||||
|
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
|
|
@ -146,7 +146,7 @@ fn xmain() -> ! {
|
||||||
let status_gid: Gid = Gid::new(canvas_gid);
|
let status_gid: Gid = Gid::new(canvas_gid);
|
||||||
log::trace!("|status: my canvas {:?}", status_gid);
|
log::trace!("|status: my canvas {:?}", status_gid);
|
||||||
|
|
||||||
log::trace!("|status: registering GAM|status thread");
|
log::debug!("|status: registering GAM|status thread");
|
||||||
// we have one connection, from the status main loop; but we make it with a local call, not using xns. so there's 0 in xns.
|
// we have one connection, from the status main loop; but we make it with a local call, not using xns. so there's 0 in xns.
|
||||||
let status_sid = xns
|
let status_sid = xns
|
||||||
.register_name(SERVER_NAME_STATUS, Some(0))
|
.register_name(SERVER_NAME_STATUS, Some(0))
|
||||||
|
|
@ -165,7 +165,6 @@ fn xmain() -> ! {
|
||||||
|
|
||||||
let gam = gam::Gam::new(&xns).expect("|status: can't connect to GAM");
|
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 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();
|
let susres = susres::Susres::new_without_hook(&xns).unwrap();
|
||||||
let mut netmgr = net::NetManager::new();
|
let mut netmgr = net::NetManager::new();
|
||||||
|
|
||||||
|
|
@ -193,7 +192,7 @@ fn xmain() -> ! {
|
||||||
DrawStyle::new(PixelColor::Light, PixelColor::Light, 0),
|
DrawStyle::new(PixelColor::Light, PixelColor::Light, 0),
|
||||||
);
|
);
|
||||||
|
|
||||||
log::trace!("|status: building textview objects");
|
log::debug!("|status: building textview objects");
|
||||||
// build uptime text view: left half of status bar
|
// build uptime text view: left half of status bar
|
||||||
let mut uptime_tv = TextView::new(
|
let mut uptime_tv = TextView::new(
|
||||||
status_gid,
|
status_gid,
|
||||||
|
|
@ -206,8 +205,8 @@ fn xmain() -> ! {
|
||||||
write!(uptime_tv, "{}", t!("secnote.startup", xous::LANG)).expect("|status: couldn't init uptime text");
|
write!(uptime_tv, "{}", t!("secnote.startup", xous::LANG)).expect("|status: couldn't init uptime text");
|
||||||
gam.post_textview(&mut uptime_tv)
|
gam.post_textview(&mut uptime_tv)
|
||||||
.expect("|status: can't draw battery stats");
|
.expect("|status: can't draw battery stats");
|
||||||
log::trace!("|status: screensize as reported: {:?}", screensize);
|
log::debug!("|status: screensize as reported: {:?}", screensize);
|
||||||
log::trace!("|status: uptime initialized to '{:?}'", uptime_tv);
|
log::debug!("|status: uptime initialized to '{:?}'", uptime_tv);
|
||||||
|
|
||||||
// build battstats text view: right half of status bar
|
// build battstats text view: right half of status bar
|
||||||
let mut battstats_tv = TextView::new(
|
let mut battstats_tv = TextView::new(
|
||||||
|
|
@ -228,16 +227,6 @@ fn xmain() -> ! {
|
||||||
remaining_capacity: 650,
|
remaining_capacity: 650,
|
||||||
};
|
};
|
||||||
|
|
||||||
// the EC gets reset by the Net crate on boot to ensure that the state machines are synced up
|
|
||||||
// this takes a few seconds, so we have a dead-wait here. This is a good spot for it because
|
|
||||||
// the status bar reads "booting up..." during this period.
|
|
||||||
ticktimer.sleep_ms(4000).unwrap();
|
|
||||||
com.hook_batt_stats(battstats_cb)
|
|
||||||
.expect("|status: couldn't hook callback for events from COM");
|
|
||||||
// prime the loop
|
|
||||||
com.req_batt_stats()
|
|
||||||
.expect("Can't get battery stats from COM");
|
|
||||||
|
|
||||||
log::debug!("initializing RTC...");
|
log::debug!("initializing RTC...");
|
||||||
let mut rtc = llio::Rtc::new(&xns);
|
let mut rtc = llio::Rtc::new(&xns);
|
||||||
|
|
||||||
|
|
@ -337,6 +326,18 @@ fn xmain() -> ! {
|
||||||
let mut battstats_phase = true;
|
let mut battstats_phase = true;
|
||||||
let mut secnotes_force_redraw = false;
|
let mut secnotes_force_redraw = false;
|
||||||
|
|
||||||
|
// the EC gets reset by the Net crate on boot to ensure that the state machines are synced up
|
||||||
|
// this takes a few seconds, so we have a dead-wait here. This is a good spot for it because
|
||||||
|
// the status bar reads "booting up..." during this period.
|
||||||
|
log::debug!("syncing with COM");
|
||||||
|
let mut com = com::Com::new(&xns).expect("|status: can't connect to COM");
|
||||||
|
com.ping(0).unwrap(); // this will block until the COM is ready to take events
|
||||||
|
com.hook_batt_stats(battstats_cb)
|
||||||
|
.expect("|status: couldn't hook callback for events from COM");
|
||||||
|
// prime the loop
|
||||||
|
com.req_batt_stats()
|
||||||
|
.expect("Can't get battery stats from COM");
|
||||||
|
|
||||||
log::debug!("starting main menu thread");
|
log::debug!("starting main menu thread");
|
||||||
create_main_menu(keys.clone(), xous::connect(status_sid).unwrap(), &com);
|
create_main_menu(keys.clone(), xous::connect(status_sid).unwrap(), &com);
|
||||||
create_app_menu(xous::connect(status_sid).unwrap());
|
create_app_menu(xous::connect(status_sid).unwrap());
|
||||||
|
|
@ -355,6 +356,7 @@ fn xmain() -> ! {
|
||||||
t!("rtc.saturday", xous::LANG),
|
t!("rtc.saturday", xous::LANG),
|
||||||
t!("rtc.sunday", xous::LANG),
|
t!("rtc.sunday", xous::LANG),
|
||||||
];
|
];
|
||||||
|
log::debug!("subscribe to wifi updates");
|
||||||
netmgr.wifi_state_subscribe(cb_cid, StatusOpcode::WifiStats.to_u32().unwrap()).unwrap();
|
netmgr.wifi_state_subscribe(cb_cid, StatusOpcode::WifiStats.to_u32().unwrap()).unwrap();
|
||||||
let mut wifi_status: WlanStatus = WlanStatus::from_ipc(WlanStatusIpc::default());
|
let mut wifi_status: WlanStatus = WlanStatus::from_ipc(WlanStatusIpc::default());
|
||||||
log::info!("|status: starting main loop"); // don't change this -- factory test looks for this exact string
|
log::info!("|status: starting main loop"); // don't change this -- factory test looks for this exact string
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue