From 77f43566206351be31cf63f5ab3a34786841fa32 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 15 Jan 2022 15:43:03 +0800 Subject: [PATCH] Sync the EC to the SOC on boot Always reset the EC on boot. If we have a cold-boot situation, it's hard to know what state the EC is in versus our stack; a hard reset on the EC guarantees we at least always start from the same point. Note that on suspend/resume, there is no reset - the EC continues trundling onwards, but the system was designed for this. --- services/net/src/main.rs | 13 ++++++++++--- services/status/src/main.rs | 4 ++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/services/net/src/main.rs b/services/net/src/main.rs index 20a8e4c26..d3b5a5ee0 100644 --- a/services/net/src/main.rs +++ b/services/net/src/main.rs @@ -90,13 +90,21 @@ fn xmain() -> ! { let net_conn = xous::connect(net_sid).unwrap(); log::trace!("registered with NS -- {:?}", net_sid); - // hook the COM interrupt listener + // bring the EC into a sane state for the network -- that is, reset the EC let mut llio = llio::Llio::new(&xns); + let com = com::Com::new(&xns).unwrap(); + let timer = ticktimer_server::Ticktimer::new().unwrap(); + + llio.ec_reset().unwrap(); + timer.sleep_ms(3500).unwrap(); + com.link_reset().unwrap(); + com.reseed_ec_trng().unwrap(); + + // hook the COM interrupt listener let net_cid = xous::connect(net_sid).unwrap(); llio.hook_com_event_callback(Opcode::ComInterrupt.to_u32().unwrap(), net_cid).unwrap(); llio.com_event_enable(true).unwrap(); // setup the interrupt masks - let com = com::Com::new(&xns).unwrap(); let mut com_int_list: Vec:: = vec![]; com.ints_get_active(&mut com_int_list); log::debug!("COM initial pending interrupts: {:?}", com_int_list); @@ -150,7 +158,6 @@ fn xmain() -> ! { let mut udp_clones = HashMap::>::new(); // additional clones for UDP responders // other link storage - let timer = ticktimer_server::Ticktimer::new().unwrap(); let neighbor_cache = NeighborCache::new(BTreeMap::new()); let ip_addrs = [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 0)]; let routes = Routes::new(BTreeMap::new()); diff --git a/services/status/src/main.rs b/services/status/src/main.rs index 98729081b..48d111eb9 100644 --- a/services/status/src/main.rs +++ b/services/status/src/main.rs @@ -202,6 +202,10 @@ fn xmain() -> ! { ) .expect("|status: Can't draw border line"); + // 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