From 9f4dc8a7b1d7b9d4015b328ec50e22505945f662 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 14 Apr 2021 22:43:23 +0800 Subject: [PATCH] add wifi reset opcodes --- Cargo.lock | 2 +- emulation/renode.svd | 12 ++++++------ imports/com_rs-ref/Cargo.toml | 2 +- services/com/src/api.rs | 6 ++++++ services/com/src/lib.rs | 13 +++++++++++++ services/com/src/main.rs | 8 ++++++++ services/shellchat/src/cmds.rs | 4 ++++ svd2utra/examples/soc.svd | 12 ++++++------ 8 files changed, 45 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 557f24006..5d2f3ac04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -314,7 +314,7 @@ dependencies = [ [[package]] name = "com_rs" version = "0.1.0" -source = "git+https://github.com/betrusted-io/com_rs.git?rev=885330c0a58fc5c3c9388628435dab24a0b61ab5#885330c0a58fc5c3c9388628435dab24a0b61ab5" +source = "git+https://github.com/betrusted-io/com_rs.git?rev=8dfa9ad067b41d0970da1578bb70b0869bc9a74f#8dfa9ad067b41d0970da1578bb70b0869bc9a74f" [[package]] name = "com_rs-ref" diff --git a/emulation/renode.svd b/emulation/renode.svd index 9d5fc26c1..e3e5e844e 100644 --- a/emulation/renode.svd +++ b/emulation/renode.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1070,10 +1070,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x1a095da1 + 0xd1096e6d 32 @@ -1090,7 +1090,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x13 + 0x14 32 @@ -2803,7 +2803,7 @@ again until the interrupt is serviced.]]> SEED1 0x0000 - 0x9878c8f + 0x6d9ae7d0 32 @@ -2818,7 +2818,7 @@ again until the interrupt is serviced.]]> SEED0 0x0004 - 0x8f844c5 + 0x48864b41 32 diff --git a/imports/com_rs-ref/Cargo.toml b/imports/com_rs-ref/Cargo.toml index c14333a63..83c64e559 100644 --- a/imports/com_rs-ref/Cargo.toml +++ b/imports/com_rs-ref/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" description = "com_rs import package" [dependencies] -com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "885330c0a58fc5c3c9388628435dab24a0b61ab5" } +com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "8dfa9ad067b41d0970da1578bb70b0869bc9a74f" } #com_rs = { path = "../../../betrusted-ec/sw/com_rs" } diff --git a/services/com/src/api.rs b/services/com/src/api.rs index a4659036d..998a8c10c 100644 --- a/services/com/src/api.rs +++ b/services/com/src/api.rs @@ -93,6 +93,12 @@ pub(crate) enum Opcode { /// request for a listener to BattStats events RegisterBattStatsListener, //String<64> + + /// Reset the wifi chip + Wf200Reset, + + /// Disable the wifi chip + Wf200Disable, } /// These enums indicate what kind of callback type we're sending. diff --git a/services/com/src/lib.rs b/services/com/src/lib.rs index ad3beb44e..0c3bde010 100644 --- a/services/com/src/lib.rs +++ b/services/com/src/lib.rs @@ -41,6 +41,7 @@ fn battstats_server(sid0: usize, sid1: usize, sid2: usize, sid3: usize) { pub struct Com { conn: CID, battstats_sid: Option, + ticktimer: ticktimer_server::Ticktimer, } impl Com { pub fn new(xns: &xous_names::XousNames) -> Result { @@ -48,6 +49,7 @@ impl Com { Ok(Com { conn, battstats_sid: None, + ticktimer: ticktimer_server::Ticktimer::new().expect("Can't connect to ticktimer"), }) } @@ -118,6 +120,17 @@ impl Com { } Ok(()) } + + pub fn wifi_disable(&self) -> Result<(), xous::Error> { + send_message(self.conn, Message::new_scalar(Opcode::Wf200Disable.to_usize().unwrap(), 0, 0, 0, 0,)).map(|_| ()) + } + // as wifi_reset() re-initializes the wifi chip, call this after wifi_disable() to re-enable wifi + pub fn wifi_reset(&self) -> Result<(), xous::Error> { + send_message(self.conn, Message::new_scalar(Opcode::Wf200Reset.to_usize().unwrap(), 0, 0, 0, 0,)).expect("couldn't send reset opcode"); + self.ticktimer.sleep_ms(2000).expect("failed in waiting for wifi chip to reset"); + Ok(()) + } + // note to future self: add other event listener registrations (such as network events) here } diff --git a/services/com/src/main.rs b/services/com/src/main.rs index 6b8b6e3a5..aa5b5ce2f 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -359,6 +359,14 @@ fn xmain() -> ! { ) .expect("couldn't return WF200 firmware rev"); } + Some(Opcode::Wf200Reset) => { + com.txrx(ComState::WF200_RESET.verb); + com.txrx(0); + } + Some(Opcode::Wf200Disable) => { + com.txrx(ComState::WF200_RESET.verb); + com.txrx(1); + } None => {error!("unknown opcode"); break}, } diff --git a/services/shellchat/src/cmds.rs b/services/shellchat/src/cmds.rs index 9bd42255e..2c96b9f5c 100644 --- a/services/shellchat/src/cmds.rs +++ b/services/shellchat/src/cmds.rs @@ -64,6 +64,7 @@ mod sleep; use sleep::*; mod sensors; use sensors::*; mod callback; use callback::*; mod rtc_cmd; use rtc_cmd::*; +//mod fcc; use fcc::*; #[derive(Debug)] pub struct CmdEnv { @@ -75,6 +76,7 @@ pub struct CmdEnv { sensors_cmd: Sensors, callback_cmd: CallBack, rtc_cmd: RtcCmd, + //fcc_cmd: Fcc, } impl CmdEnv { pub fn new(xns: &xous_names::XousNames) -> CmdEnv { @@ -93,6 +95,7 @@ impl CmdEnv { sensors_cmd: Sensors::new(), callback_cmd: CallBack::new(), rtc_cmd: RtcCmd::new(&xns), + //fcc_cmd: Fcc::new(), } } @@ -108,6 +111,7 @@ impl CmdEnv { &mut self.sensors_cmd, &mut self.callback_cmd, &mut self.rtc_cmd, + //&mut self.fcc_cmd, ]; if let Some(cmdline) = maybe_cmdline { diff --git a/svd2utra/examples/soc.svd b/svd2utra/examples/soc.svd index 9d5fc26c1..e3e5e844e 100644 --- a/svd2utra/examples/soc.svd +++ b/svd2utra/examples/soc.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1070,10 +1070,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x1a095da1 + 0xd1096e6d 32 @@ -1090,7 +1090,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x13 + 0x14 32 @@ -2803,7 +2803,7 @@ again until the interrupt is serviced.]]> SEED1 0x0000 - 0x9878c8f + 0x6d9ae7d0 32 @@ -2818,7 +2818,7 @@ again until the interrupt is serviced.]]> SEED0 0x0004 - 0x8f844c5 + 0x48864b41 32