add APIs to pause the connection manager, and pause the CM while doing EC updates

It's not a good time to bug the EC to do network stuff when it's updating
itself.

...might even want to send the network into a disconnected state,
but, let's start with just turning off the connection manager
for now.
This commit is contained in:
bunnie 2022-02-02 02:38:19 +08:00
parent 002e098538
commit 562a930ce0
4 changed files with 36 additions and 1 deletions

View file

@ -66,6 +66,7 @@ pub(crate) enum Opcode {
SubscribeWifiStats,
UnsubWifiStats,
FetchSsidList,
ConnMgrStartStop,
/// [Internal] com llio interrupt callback
ComInterrupt,

View file

@ -160,6 +160,16 @@ impl NetManager {
}
Ok(ret)
}
pub fn connection_manager_stop(&self) -> Result<(), xous::Error> {
send_message(self.netconn.conn(),
Message::new_scalar(Opcode::ConnMgrStartStop.to_usize().unwrap(), 0, 0,0, 0)
).map(|_| ())
}
pub fn connection_manager_run(&self) -> Result<(), xous::Error> {
send_message(self.netconn.conn(),
Message::new_scalar(Opcode::ConnMgrStartStop.to_usize().unwrap(), 1, 0,0, 0)
).map(|_| ())
}
}
impl Drop for NetManager {
fn drop(&mut self) {

View file

@ -9,7 +9,7 @@ use com::api::{ComIntSources, Ipv4Conf, NET_MTU};
mod device;
mod connection_manager;
use xous::{Message, CID, SID, msg_scalar_unpack, msg_blocking_scalar_unpack};
use xous::{Message, CID, SID, msg_scalar_unpack, msg_blocking_scalar_unpack, send_message};
use xous_ipc::Buffer;
use std::collections::BTreeMap;
use std::collections::HashMap;
@ -1437,6 +1437,23 @@ fn xmain() -> ! {
let ret_list = buf.to_original::<SsidList, _>().expect("couldn't restore original");
buffer.replace(ret_list).expect("couldn't return config");
},
Some(Opcode::ConnMgrStartStop) => msg_scalar_unpack!(msg, code, _, _, _, {
if code == 0 { // 0 is stop, 1 is start
send_message(cm_cid,
Message::new_scalar(
connection_manager::ConnectionManagerOpcode::Stop.to_usize().unwrap(),
0, 0, 0, 0)
).expect("couldn't send stop message");
} else if code == 1 {
send_message(cm_cid,
Message::new_scalar(
connection_manager::ConnectionManagerOpcode::Run.to_usize().unwrap(),
0, 0, 0, 0)
).expect("couldn't send stop message");
} else {
log::error!("Got incorrect start/stop code: {}", code);
}
}),
Some(Opcode::Reset) => {
net_config = None;
let neighbor_cache = NeighborCache::new(BTreeMap::new());

View file

@ -443,6 +443,7 @@ impl<'a> ShellCmdApi<'a> for EcUpdate {
if let Some(sub_cmd) = tokens.next() {
match sub_cmd {
"fw" => {
env.netmgr.connection_manager_stop().unwrap();
self.in_progress = true;
let start = env.ticktimer.elapsed_ms();
self.start_time = Some(start);
@ -452,6 +453,7 @@ impl<'a> ShellCmdApi<'a> for EcUpdate {
write!(ret, "Starting EC firmware update").unwrap();
}
"gw" => {
env.netmgr.connection_manager_stop().unwrap();
self.in_progress = true;
let start = env.ticktimer.elapsed_ms();
self.start_time = Some(start);
@ -468,6 +470,7 @@ impl<'a> ShellCmdApi<'a> for EcUpdate {
write!(ret, "EC has been reset, and new firmware loaded.").unwrap();
}
"wf200" => {
env.netmgr.connection_manager_stop().unwrap();
self.in_progress = true;
let start = env.ticktimer.elapsed_ms();
self.start_time = Some(start);
@ -483,6 +486,7 @@ impl<'a> ShellCmdApi<'a> for EcUpdate {
return Ok(Some(ret));
}
env.netmgr.connection_manager_stop().unwrap();
self.in_progress = true;
let start = env.ticktimer.elapsed_ms();
self.start_time = Some(start);
@ -523,14 +527,17 @@ impl<'a> ShellCmdApi<'a> for EcUpdate {
},
Some(UpdateResult::ProgramDone) => {
write!(ret, "Programming of {} bytes done in {:.1}s. Please restart EC with `ecup reset`.", progress, elapsed / 1000.0).unwrap();
env.netmgr.connection_manager_run().unwrap();
self.in_progress = false;
},
Some(UpdateResult::AutoDone) => {
write!(ret, "Autoupdate of EC finished. Shutting down now...").unwrap();
env.netmgr.connection_manager_run().unwrap();
self.in_progress = false;
},
Some(UpdateResult::Abort) => {
write!(ret, "Programming aborted in {:.1}s. Did you stage all the firmware objects?", elapsed / 1000.0).unwrap();
env.netmgr.connection_manager_run().unwrap();
self.in_progress = false;
}
_ => write!(ret, "Got unknown update callback: {:?}", result_code).unwrap()