From 93400df67cb819d3cc7744fe06fb4ab6d7bbd565 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 15 Apr 2021 04:10:47 +0800 Subject: [PATCH] an initial cut at fcc test commands --- 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 | 7 + services/com/src/main.rs | 6 + services/llio/src/lib.rs | 7 + services/llio/src/main.rs | 2 +- services/shellchat/src/cmds.rs | 9 +- services/shellchat/src/cmds/fcc.rs | 197 ++++++++++++++++++++++++++ services/shellchat/src/cmds/pds.rs | 48 +++++++ services/ticktimer-server/src/main.rs | 1 + svd2utra/examples/soc.svd | 12 +- 13 files changed, 292 insertions(+), 19 deletions(-) create mode 100644 services/shellchat/src/cmds/fcc.rs create mode 100644 services/shellchat/src/cmds/pds.rs diff --git a/Cargo.lock b/Cargo.lock index 5d2f3ac04..f7f89d3f8 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=8dfa9ad067b41d0970da1578bb70b0869bc9a74f#8dfa9ad067b41d0970da1578bb70b0869bc9a74f" +source = "git+https://github.com/betrusted-io/com_rs.git?rev=4b45a42ad2d932550566d6c32ec1e1dd60e93c67#4b45a42ad2d932550566d6c32ec1e1dd60e93c67" [[package]] name = "com_rs-ref" diff --git a/emulation/renode.svd b/emulation/renode.svd index e3e5e844e..4b5ce16c4 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 - 0xd1096e6d + 0x9e613ee0 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 - 0x14 + 0x15 32 @@ -2803,7 +2803,7 @@ again until the interrupt is serviced.]]> SEED1 0x0000 - 0x6d9ae7d0 + 0x6bb645a1 32 @@ -2818,7 +2818,7 @@ again until the interrupt is serviced.]]> SEED0 0x0004 - 0x48864b41 + 0x73801cba 32 diff --git a/imports/com_rs-ref/Cargo.toml b/imports/com_rs-ref/Cargo.toml index 83c64e559..e8bf80019 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 = "8dfa9ad067b41d0970da1578bb70b0869bc9a74f" } +com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "4b45a42ad2d932550566d6c32ec1e1dd60e93c67" } #com_rs = { path = "../../../betrusted-ec/sw/com_rs" } diff --git a/services/com/src/api.rs b/services/com/src/api.rs index 998a8c10c..5ac584739 100644 --- a/services/com/src/api.rs +++ b/services/com/src/api.rs @@ -99,6 +99,12 @@ pub(crate) enum Opcode { /// Disable the wifi chip Wf200Disable, + + /// start passive SSID scanning + ScanOn, + + /// stop passive SSID scanning + ScanOff, } /// 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 0c3bde010..eb5abd67f 100644 --- a/services/com/src/lib.rs +++ b/services/com/src/lib.rs @@ -130,6 +130,13 @@ impl Com { self.ticktimer.sleep_ms(2000).expect("failed in waiting for wifi chip to reset"); Ok(()) } + pub fn set_ssid_scanning(&self, enable: bool) -> Result<(), xous::Error> { + if enable { + send_message(self.conn, Message::new_scalar(Opcode::ScanOn.to_usize().unwrap(), 0, 0, 0, 0,)).map(|_| ()) + } else { + send_message(self.conn, Message::new_scalar(Opcode::ScanOff.to_usize().unwrap(), 0, 0, 0, 0,)).map(|_| ()) + } + } // 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 aa5b5ce2f..af9b87876 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -367,6 +367,12 @@ fn xmain() -> ! { com.txrx(ComState::WF200_RESET.verb); com.txrx(1); } + Some(Opcode::ScanOn) => { + com.txrx(ComState::SSID_SCAN_ON.verb); + } + Some(Opcode::ScanOff) => { + com.txrx(ComState::SSID_SCAN_OFF.verb); + } None => {error!("unknown opcode"); break}, } diff --git a/services/llio/src/lib.rs b/services/llio/src/lib.rs index 7cc75ed64..96ab9b756 100644 --- a/services/llio/src/lib.rs +++ b/services/llio/src/lib.rs @@ -274,7 +274,14 @@ impl Llio { Err(xous::Error::MemoryInUse) // can't hook it twice } } + pub fn ec_reset(&self) -> Result<(), xous::Error> { + send_message(self.conn, + Message::new_scalar(Opcode::EcReset.to_usize().unwrap(), 0, 0, 0, 0) + ).map(|_| ()) + } } + + fn drop_conn(sid: xous::SID) { let cid = xous::connect(sid).unwrap(); xous::send_message(cid, diff --git a/services/llio/src/main.rs b/services/llio/src/main.rs index 7d73af205..28e2e53e3 100644 --- a/services/llio/src/main.rs +++ b/services/llio/src/main.rs @@ -336,7 +336,7 @@ mod implementation { } pub fn ec_reset(&mut self) { self.power_csr.rmwf(utra::power::POWER_RESET_EC, 1); - self.ticktimer.sleep_ms(100).unwrap(); + self.ticktimer.sleep_ms(20).unwrap(); self.power_csr.rmwf(utra::power::POWER_RESET_EC, 0); } pub fn ec_power_on(&mut self) { diff --git a/services/shellchat/src/cmds.rs b/services/shellchat/src/cmds.rs index 2c96b9f5c..eb2a42356 100644 --- a/services/shellchat/src/cmds.rs +++ b/services/shellchat/src/cmds.rs @@ -64,7 +64,8 @@ mod sleep; use sleep::*; mod sensors; use sensors::*; mod callback; use callback::*; mod rtc_cmd; use rtc_cmd::*; -//mod fcc; use fcc::*; +mod fcc; use fcc::*; +mod pds; // dependency of the FCC file #[derive(Debug)] pub struct CmdEnv { @@ -76,7 +77,7 @@ pub struct CmdEnv { sensors_cmd: Sensors, callback_cmd: CallBack, rtc_cmd: RtcCmd, - //fcc_cmd: Fcc, + fcc_cmd: Fcc, } impl CmdEnv { pub fn new(xns: &xous_names::XousNames) -> CmdEnv { @@ -95,7 +96,7 @@ impl CmdEnv { sensors_cmd: Sensors::new(), callback_cmd: CallBack::new(), rtc_cmd: RtcCmd::new(&xns), - //fcc_cmd: Fcc::new(), + fcc_cmd: Fcc::new(), } } @@ -111,7 +112,7 @@ impl CmdEnv { &mut self.sensors_cmd, &mut self.callback_cmd, &mut self.rtc_cmd, - //&mut self.fcc_cmd, + &mut self.fcc_cmd, ]; if let Some(cmdline) = maybe_cmdline { diff --git a/services/shellchat/src/cmds/fcc.rs b/services/shellchat/src/cmds/fcc.rs new file mode 100644 index 000000000..fd69336bb --- /dev/null +++ b/services/shellchat/src/cmds/fcc.rs @@ -0,0 +1,197 @@ +use crate::{ShellCmdApi, CommonEnv}; +use xous_ipc::String; +use com::Com; +use ticktimer_server::Ticktimer; + +use crate::cmds::pds::PDS_DATA; +use crate::cmds::pds::PDS_STOP_DATA; +use crate::cmds::pds::Rate; + +use core::fmt::Write; + +use xous::{Message, ScalarMessage, MessageEnvelope}; +use core::sync::atomic::{AtomicBool, Ordering}; +static CB_RUN: AtomicBool = AtomicBool::new(false); +pub fn callback_thread() { + let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer"); + let xns = xous_names::XousNames::new().unwrap(); + let callback_conn = xns.request_connection_blocking(crate::SERVER_NAME_SHELLCHAT).unwrap(); + + log::info!("callback initiator test thread started"); + loop { + if CB_RUN.load(Ordering::Relaxed) { + CB_RUN.store(false, Ordering::Relaxed); + ticktimer.sleep_ms(20_000).unwrap(); + // just send a bogus message + xous::send_message(callback_conn, Message::Scalar(ScalarMessage{ + id: 0xdeadbeef, arg1: 0, arg2: 0, arg3: 0, arg4: 0, + })).unwrap(); + } else { + ticktimer.sleep_ms(250).unwrap(); // a little more polite than simply busy-waiting + } + } +} + +#[derive(Debug)] +pub struct Fcc { + channel: Option, + rate: Option, + pds_list: [Option>; 8], + go: bool, + tx_start_time: u64, +} +impl Fcc { + pub fn new() -> Fcc { + xous::create_thread_0(callback_thread).expect("couldn't create callback generator thread"); + Fcc { + channel: Some(2), // default to simplify testing, replace with None + rate: Some(Rate::B1Mbps), // default to simplify testing, replace with None + pds_list: [None; 8], + go: false, + tx_start_time: 0, + } + } + fn send_pds(&self, com: &Com, ticktimer: &Ticktimer) { + for &maybe_pds in self.pds_list.iter() { + if let Some(pds) = maybe_pds { + if pds.len() > 0 { + com.send_pds_line(&pds).unwrap(); + ticktimer.sleep_ms(50).expect("couldn't sleep during send_pds"); + } + } + } + } + fn clear_pds(&mut self) { + for pds in self.pds_list.iter_mut() { + *pds = None; + } + } + fn stop_tx(&mut self, com: &com::Com, ticktimer: &Ticktimer) { + CB_RUN.store(false, Ordering::Relaxed); // make sure the callback function is disabled + self.go = false; + self.clear_pds(); + self.pds_list[0] = Some(String::<512>::from_str(PDS_STOP_DATA)); + self.send_pds(&com, &ticktimer); + self.clear_pds(); + } +} +impl<'a> ShellCmdApi<'a> for Fcc { + cmd_api!(fcc); // inserts boilerplate for command API + + fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result>, xous::Error> { + let mut ret = String::<1024>::new(); + let helpstring = "fcc [ch 1-14] [rate ] [go] [stop] [rev] [res]\nrate code: b[1,2,5.5,11], g[6,9,12,18,24,36,48,54], mcs[0-7]"; + + // no matter what, we want SSID scanning to be off + env.com.set_ssid_scanning(false).expect("couldn't turn of SSID scanning"); + + let mut tokens = args.as_str().unwrap().split(' '); + + if let Some(sub_cmd) = tokens.next() { + match sub_cmd { + "res" => { + env.llio.ec_reset().unwrap(); + //env.com.wifi_reset().unwrap(); // doesn't work right now :-/ + write!(ret, "EC has been reset").unwrap(); + } + "rev" => { + let (maj, min, rev) = env.com.get_wf200_fw_rev().unwrap(); + write!(ret, "Wf200 fw rev {}.{}.{}", maj, min, rev).unwrap(); + } + "stop" => { + self.stop_tx(&env.com, &env.ticktimer); + write!(ret, "{}", "Transmission stopped").unwrap(); + }, + "go" => { + if let Some(channel) = self.channel { + if channel < 1 || channel > 14 { + write!(ret, "Channel {} out of bounds", channel).unwrap(); + } else { + if let Some(rate) = self.rate { + let mut found = false; + self.clear_pds(); + for record in PDS_DATA.iter() { + if record.rate == rate { + let mut index: usize = 0; + for &line in record.pds_data[(channel-1) as usize].iter() { + self.pds_list[index] = Some(String::<512>::from_str(line)); + index += 1; + } + found = true; + break; + } + } + if found { + self.send_pds(&env.com, &env.ticktimer); + write!(ret, "TX live: ch {} rate {:?}", channel, rate).unwrap(); + self.go = true; + self.tx_start_time = env.ticktimer.elapsed_ms(); + CB_RUN.store(true, Ordering::Relaxed); // initiate the callback for the next wakeup + } else { + write!(ret, "Rate/channel combo not found: ch {} rate {:?}", channel, rate).unwrap(); + } + } else { + write!(ret, "{}", "No rate selected").unwrap(); + } + } + } else { + write!(ret, "{}", "No channel selected").unwrap(); + } + }, + "ch" => { + if let Some(ch_str) = tokens.next() { + if let Ok(ch) = ch_str.parse::() { + if ch >= 1 && ch <= 14 { + self.channel = Some(ch); + write!(ret, "Channel set to {}", ch).unwrap(); + } else { + write!(ret, "Channel {} is out of range (1-14)", ch).unwrap(); + } + } else { + write!(ret, "Couldn't parse channel: {}", ch_str).unwrap(); + } + } else { + write!(ret, "Specify channel number of 1-14").unwrap(); + } + } + "rate" => { + if let Some(rate_str) = tokens.next() { + match rate_str { + "b1" => self.rate = Some(Rate::B1Mbps), + "b2" => self.rate = Some(Rate::B2Mbps), + "b5.5" => self.rate = Some(Rate::B5_5Mbps), + "b11" => self.rate = Some(Rate::B11Mbps), + // fill in remainder later + _ => write!(ret, "Rate code {} invalid, pick one of b[1,2,5.5,11], g[6,9,12,18,24,36,48,54], mcs[0-7]", rate_str).unwrap(), + } + } else { + write!(ret, "Specify rate code of b[1,2,5.5,11], g[6,9,12,18,24,36,48,54], mcs[0-7]").unwrap(); + } + } + _ => { + write!(ret, "{}", helpstring).unwrap(); + } + } + } else { + write!(ret, "{}", helpstring).unwrap(); + } + Ok(Some(ret)) + } + + fn callback(&mut self, _msg: &MessageEnvelope, env: &mut CommonEnv) -> Result>, xous::Error> { + let mut ret = String::<1024>::new(); + if self.go { + if (env.ticktimer.elapsed_ms() - self.tx_start_time) > (1000 * 60 * 5) { + self.stop_tx(&env.com, &env.ticktimer); + write!(ret, "5 minute timeout on TX, stopping for TX overheat safety!").unwrap(); + } else { + self.send_pds(&env.com, &env.ticktimer); + write!(ret, "TX renewed: ch {} rate {:?}", self.channel.unwrap(), self.rate.unwrap()).unwrap(); + CB_RUN.store(true, Ordering::Relaxed); // re-initiate the callback + } + } else { + write!(ret, "Info: passing on TX renewal").unwrap(); + } + Ok(Some(ret)) + } +} diff --git a/services/shellchat/src/cmds/pds.rs b/services/shellchat/src/cmds/pds.rs new file mode 100644 index 000000000..6dc5198f4 --- /dev/null +++ b/services/shellchat/src/cmds/pds.rs @@ -0,0 +1,48 @@ +#[derive(Debug, Eq, PartialEq, Copy, Clone)] +pub enum Rate { + B1Mbps, + B2Mbps, + B5_5Mbps, + B11Mbps, + G6Mbps, + G9Mbps, + G12Mbps, + G18Mbps, + G24Mbps, + G36Mbps, + G48Mbps, + G54Mbps, + NMCS0, + NMCS1, + NMCS2, + NMCS3, + NMCS4, + NMCS5, + NMCS6, + NMCS7, +} + +pub struct PdsRecord { + pub rate: Rate, + pub pds_data: &'static [[&'static str; 4]; 2], +} + +pub const PDS_DATA: [PdsRecord; 2] = [ + PdsRecord { + rate: Rate::B1Mbps, + pds_data: &[ + ["{j:{a:0}}", "{i:{a:1,b:1,f:2255100,c:{a:0,b:0,c:0,d:44},d:{a:FFB,b:0,c:1,d:E,e:0,f:4},e:{}}}", "", ""], // channel 6 + ["{j:{a:0}}", "{i:{a:1,b:1,f:2255100,c:{a:0,b:0,c:0,d:44},d:{a:FFB,b:0,c:1,d:E,e:0,f:4},e:{}}}", "", ""], // channel 6 + ], + }, + PdsRecord { + rate: Rate::B2Mbps, + pds_data: &[ + ["{j:{a:0}}", "{i:{a:1,b:1,f:2255100,c:{a:0,b:0,c:0,d:44},d:{a:FFB,b:0,c:1,d:E,e:0,f:4},e:{}}}", "", ""], // channel 6 + ["{j:{a:0}}", "{i:{a:1,b:1,f:2255100,c:{a:0,b:0,c:0,d:44},d:{a:FFB,b:0,c:1,d:E,e:0,f:4},e:{}}}", "", ""], // channel 6 + ], + }, +]; + +pub const PDS_STOP_DATA: &str = "{i:{a:1,b:1,f:2255100,c:{a:0,b:0,c:0,d:44},d:{a:FFB,b:0,c:1,d:E,e:64,f:4},e:{}}}"; + diff --git a/services/ticktimer-server/src/main.rs b/services/ticktimer-server/src/main.rs index 119f5a3f3..c73bc3240 100644 --- a/services/ticktimer-server/src/main.rs +++ b/services/ticktimer-server/src/main.rs @@ -79,6 +79,7 @@ mod implementation { #[cfg(feature = "watchdog")] if xtt.wdt.rf(utra::wdt::STATE_ENABLED) == 1 { if xtt.wdt.rf(utra::wdt::STATE_DISARMED) != 1 { + xtt.wdt.wfo(utra::wdt::WATCHDOG_RESET_CODE, 0x600d); while xtt.wdt.rf(utra::wdt::STATE_ARMED1) == 1 { xtt.wdt.wfo(utra::wdt::WATCHDOG_RESET_CODE, 0x600d); } diff --git a/svd2utra/examples/soc.svd b/svd2utra/examples/soc.svd index e3e5e844e..4b5ce16c4 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 - 0xd1096e6d + 0x9e613ee0 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 - 0x14 + 0x15 32 @@ -2803,7 +2803,7 @@ again until the interrupt is serviced.]]> SEED1 0x0000 - 0x6d9ae7d0 + 0x6bb645a1 32 @@ -2818,7 +2818,7 @@ again until the interrupt is serviced.]]> SEED0 0x0004 - 0x48864b41 + 0x73801cba 32