diff --git a/services/com/src/api.rs b/services/com/src/api.rs index 62fa9d8ce..6a45413e9 100644 --- a/services/com/src/api.rs +++ b/services/com/src/api.rs @@ -144,6 +144,9 @@ pub struct WlanDebug { #[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] 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 LinkReset, diff --git a/services/com/src/lib.rs b/services/com/src/lib.rs index 543809c93..0b810d2bd 100644 --- a/services/com/src/lib.rs +++ b/services/com/src/lib.rs @@ -84,6 +84,15 @@ impl Com { Message::new_blocking_scalar(Opcode::LinkReset.to_usize().unwrap(), 0, 0, 0, 0) ).map(|_| ()) } + pub fn ping(&self, value: usize) -> Result { + 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> { send_message(self.conn, Message::new_scalar(Opcode::ReseedTrng.to_usize().unwrap(), 0, 0, 0, 0) diff --git a/services/com/src/main.rs b/services/com/src/main.rs index eaae9d63d..916e47cb7 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -352,7 +352,31 @@ fn xmain() -> ! { // reset the EC so we're in sync at boot on state let llio = llio::Llio::new(&xns); 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 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)); } }), + 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, _, _, _, _, { 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 diff --git a/services/graphics-server/src/backend/betrusted.rs b/services/graphics-server/src/backend/betrusted.rs index dc3aa2943..8502d08b1 100644 --- a/services/graphics-server/src/backend/betrusted.rs +++ b/services/graphics-server/src/backend/betrusted.rs @@ -134,6 +134,7 @@ impl XousDisplay { } pub fn redraw(&mut self) { + log::info!("**update**"); let mut busy_count = 0; let mut dirty_count = 0; while self.busy() { diff --git a/services/status/src/main.rs b/services/status/src/main.rs index d349ea8ad..4c420c0e8 100644 --- a/services/status/src/main.rs +++ b/services/status/src/main.rs @@ -116,7 +116,7 @@ pub fn pump_thread(conn: usize, pump_run: Arc) { #[xous::xous_main] fn xmain() -> ! { 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()); let xns = xous_names::XousNames::new().unwrap(); @@ -146,7 +146,7 @@ fn xmain() -> ! { let status_gid: Gid = Gid::new(canvas_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. let status_sid = xns .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 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 mut netmgr = net::NetManager::new(); @@ -193,7 +192,7 @@ fn xmain() -> ! { 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 let mut uptime_tv = TextView::new( status_gid, @@ -206,8 +205,8 @@ fn xmain() -> ! { write!(uptime_tv, "{}", t!("secnote.startup", xous::LANG)).expect("|status: couldn't init uptime text"); gam.post_textview(&mut uptime_tv) .expect("|status: can't draw battery stats"); - log::trace!("|status: screensize as reported: {:?}", screensize); - log::trace!("|status: uptime initialized to '{:?}'", uptime_tv); + log::debug!("|status: screensize as reported: {:?}", screensize); + log::debug!("|status: uptime initialized to '{:?}'", uptime_tv); // build battstats text view: right half of status bar let mut battstats_tv = TextView::new( @@ -228,16 +227,6 @@ fn xmain() -> ! { 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..."); let mut rtc = llio::Rtc::new(&xns); @@ -337,6 +326,18 @@ fn xmain() -> ! { let mut battstats_phase = true; 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"); create_main_menu(keys.clone(), xous::connect(status_sid).unwrap(), &com); create_app_menu(xous::connect(status_sid).unwrap()); @@ -355,6 +356,7 @@ fn xmain() -> ! { t!("rtc.saturday", 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(); 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