From 5b80b3fb42df1948a231d78e7c2f5db9cdcee450 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 23 Feb 2021 04:01:01 +0800 Subject: [PATCH] get fcc-agent working again --- Cargo.lock | 3 +- buildpush.sh | 2 +- emulation/renode.svd | 129 +++++++++++--------------------- imports/blitstr-ref/Cargo.toml | 4 +- imports/com_rs-ref/Cargo.toml | 2 +- services/com/src/lib.rs | 2 +- services/com/src/main.rs | 10 ++- services/fcc-agent/src/main.rs | 109 ++++++++++++++++++++++----- services/log-server/src/main.rs | 2 +- svd2utra/examples/soc.svd | 129 +++++++++++--------------------- 10 files changed, 193 insertions(+), 199 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 235236ddc..c9553ec9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,6 +121,7 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "blitstr" version = "0.3.0" +source = "git+https://github.com/betrusted-io/blitstr.git?rev=cde0deb6784c3f5c7b9da838ea9aa14ed373bcb3#cde0deb6784c3f5c7b9da838ea9aa14ed373bcb3" dependencies = [ "rkyv", ] @@ -250,7 +251,7 @@ dependencies = [ [[package]] name = "com_rs" version = "0.1.0" -source = "git+https://github.com/betrusted-io/com_rs.git?rev=a9e05f414accef08348b77be6fc0f668b319e6ff#a9e05f414accef08348b77be6fc0f668b319e6ff" +source = "git+https://github.com/betrusted-io/com_rs.git?rev=885330c0a58fc5c3c9388628435dab24a0b61ab5#885330c0a58fc5c3c9388628435dab24a0b61ab5" [[package]] name = "com_rs-ref" diff --git a/buildpush.sh b/buildpush.sh index aa71eb5a1..451256210 100755 --- a/buildpush.sh +++ b/buildpush.sh @@ -67,7 +67,7 @@ DESTDIR=code/precursors # full rebuild, and not just an incremental rebuild. :-/ #touch services/log-server/src/main.rs # bump the build time in the log server -cargo $USE_NIGHTLY xtask hw-image ../betrusted-soc/build/software/soc.svd +cargo $USE_NIGHTLY xtask fcc-agent ../betrusted-soc/build/software/soc.svd # only copy if changed, othrewise it seems to trigger extra build effort... rsync -a --no-times --checksum ../betrusted-soc/build/software/soc.svd svd2utra/examples/soc.svd diff --git a/emulation/renode.svd b/emulation/renode.svd index bb4c9e69d..cee67ae7c 100644 --- a/emulation/renode.svd +++ b/emulation/renode.svd @@ -19,7 +19,7 @@ IDENTIFIER_MEM - + 0x0000 0x00 32 @@ -1320,10 +1320,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x14057e44 + 0xbc2a74fa 32 @@ -1340,7 +1340,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 - 0x06 + 0x08 32 @@ -1354,7 +1354,7 @@ beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> GIT_DIRTY 0x001c - 0x01 + 0x00 32 @@ -3030,7 +3030,7 @@ again until the interrupt is serviced.]]> SEED1 0x0000 - 0x4066250a + 0x3f420745 32 @@ -3045,7 +3045,7 @@ again until the interrupt is serviced.]]> SEED0 0x0004 - 0x7e58e3d5 + 0xbd3a2e0 32 @@ -4124,10 +4124,40 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> - XADC_DRP_ENABLE + XADC_GPIO5 + 0x002c 0x00 32 + + + xadc_gpio5 + 11 + [11:0] + 0 + + + + + XADC_GPIO2 + + 0x0030 + 0x00 + 32 + + + xadc_gpio2 + 11 + [11:0] + 0 + + + + + XADC_DRP_ENABLE + 0x0034 + 0x00 + 32 xadc_drp_enable @@ -4139,7 +4169,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> XADC_DRP_READ - 0x0030 + 0x0038 0x00 32 @@ -4153,7 +4183,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> XADC_DRP_WRITE - 0x0034 + 0x003c 0x00 32 @@ -4167,7 +4197,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> XADC_DRP_DRDY - 0x0038 + 0x0040 0x00 32 @@ -4181,7 +4211,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> XADC_DRP_ADR - 0x003c + 0x0044 0x00 32 @@ -4195,7 +4225,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> XADC_DRP_DAT_W - 0x0040 + 0x0048 0x00 32 @@ -4209,7 +4239,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> XADC_DRP_DAT_R - 0x0044 + 0x004c 0x00 32 @@ -4221,79 +4251,10 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> - - RO_HEALTH_MONOBIT - 0x0048 - 0x00 - 32 - - - stat_error - 0 - [0:0] - 0 - - - - missed_sample - 1 - [1:1] - 1 - - - - - - RO_HEALTH_ONES - 0x004c - 0x00 - 32 - - - ones - 31 - [31:0] - 0 - - - - - - RO_HEALTH_SAMPLECOUNT - 0x0050 - 0x40000 - 32 - - - samplecount - 31 - [31:0] - 0 - - - - - - RO_HEALTH_SIGMA - 0x0054 - 0x200 - 32 - - - sigma - 31 - [31:0] - 0 - - - - 0 - 0x58 + 0x50 registers diff --git a/imports/blitstr-ref/Cargo.toml b/imports/blitstr-ref/Cargo.toml index 7ff5aa3f8..f6e47b767 100644 --- a/imports/blitstr-ref/Cargo.toml +++ b/imports/blitstr-ref/Cargo.toml @@ -6,8 +6,8 @@ edition = "2018" description = "blitstr import package" [dependencies] -# blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "6c56865b89f782df7b3383d3480a83873dbc0189" } -blitstr = { path = "../../../blitstr" } +blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "cde0deb6784c3f5c7b9da838ea9aa14ed373bcb3" } +# blitstr = { path = "../../../blitstr" } # targeting hardware diff --git a/imports/com_rs-ref/Cargo.toml b/imports/com_rs-ref/Cargo.toml index 25d6318ed..c14333a63 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 = "a9e05f414accef08348b77be6fc0f668b319e6ff" } +com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "885330c0a58fc5c3c9388628435dab24a0b61ab5" } #com_rs = { path = "../../../betrusted-ec/sw/com_rs" } diff --git a/services/com/src/lib.rs b/services/com/src/lib.rs index 83f503884..968f1961e 100644 --- a/services/com/src/lib.rs +++ b/services/com/src/lib.rs @@ -57,7 +57,7 @@ pub fn send_pds_line(cid: CID, s: &xous::String<512>) -> Result<(), Error> { let mut clone_s: xous::String<512> = xous::String::new(); write!(clone_s, "{}", s.as_str().unwrap()).map_err(|_| xous::Error::AccessDenied)?; let request = api::Opcode::Wf200PdsLine(clone_s); - let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(512)); + let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096)); let pos = writer.archive(&request).expect("COM: couldn't archive PDS line request"); let xous_buffer = writer.into_inner(); diff --git a/services/com/src/main.rs b/services/com/src/main.rs index 6c46eb0d2..e596fc06c 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -249,11 +249,12 @@ fn xmain() -> ! { let com_sid = xous_names::register_name(xous::names::SERVER_NAME_COM).expect("COM: can't register server"); info!("COM: registered with NS -- {:?}", com_sid); + /* // get rid of this feature for now, it doesn't work, we don't use it, and it potentially causes troubles let agent_conn= if cfg!(feature = "fccagent") { xous_names::request_connection_blocking(xous::names::SERVER_NAME_FCCAGENT).expect("FCCAGENT: can't connect to COM") } else { 0 // bogus value - }; + }; */ // Create a new com object let mut com = XousCom::new(); @@ -265,7 +266,7 @@ fn xmain() -> ! { info!("COM: starting main loop"); loop { let envelope = xous::receive_message(com_sid).unwrap(); - // info!("COM: Message: {:?}", envelope); + info!("COM: Message: {:?}", envelope); if let xous::Message::Borrow(m) = &envelope.body { let mut buf = unsafe { buffer::XousBuffer::from_memory_message(m) }; let value = unsafe { @@ -281,7 +282,7 @@ fn xmain() -> ! { let l: xous::String<512> = rkyv_l.unarchive(); info!("COM: Wf200PdsLine got line {}", l); let line = l.as_bytes(); - let length = line.len() as u16; + let length = (l.len() + 0) as u16; //info!("COM: 0x{:04x}", ComState::WFX_PDS_LINE_SET.verb); com.txrx(ComState::WFX_PDS_LINE_SET.verb); //info!("COM: 0x{:04x}", length); @@ -351,6 +352,7 @@ fn xmain() -> ! { ) .expect("COM: couldn't return WF200 firmware rev"); } + /* // excised because it doesn't work Opcode::RxStatsAgent => { if cfg!(feature = "fccagent") { // note -- this code never worked, but wasn't needed. just hanging out as bread crumbs for future work in case this is needed. @@ -366,7 +368,7 @@ fn xmain() -> ! { let m = xous::Message::Borrow(data.into_message(2)); xous::send_message(agent_conn, m).expect("Can't send RxStat message to FCC agent!"); } - } + }*/ _ => error!("unknown opcode"), } } else { diff --git a/services/fcc-agent/src/main.rs b/services/fcc-agent/src/main.rs index b2c2af606..4729cbaaf 100644 --- a/services/fcc-agent/src/main.rs +++ b/services/fcc-agent/src/main.rs @@ -105,18 +105,19 @@ UART received <{i:{a:6,b:1,f:F4240,c:{a:0,b:0,c:0,d:44},d:{a:FFB,b:0,c:0,d:0,e:6 use xous::{Message, ScalarMessage}; #[derive(Debug)] -pub enum Opcode<'a> { +pub enum Opcode { Char(u8), - RxStats(&'a [u8]), + // RxStats(&'a [u8]), } -impl<'a> core::convert::TryFrom<&'a Message> for Opcode<'a> { +impl core::convert::TryFrom<& Message> for Opcode { type Error = &'static str; - fn try_from(message: &'a Message) -> Result { + fn try_from(message: & Message) -> Result { match message { Message::Scalar(m) => match m.id { 1 => Ok(Opcode::Char(m.arg1 as u8)), _ => Err("unrecognized opcode"), }, + /* Message::Borrow(m) => match m.id { 2 => { let stats = unsafe { @@ -128,25 +129,25 @@ impl<'a> core::convert::TryFrom<&'a Message> for Opcode<'a> { Ok(Opcode::RxStats(stats)) } _ => {print!("unhandled opcode"); Err("unrecognized opcode")}, - } + }*/ _ => {print!("unhandled message type"); Err("unhandled message type")}, } } } -impl<'a> Into for Opcode<'a> { +impl Into for Opcode { fn into(self) -> Message { match self { Opcode::Char(c) => Message::Scalar(ScalarMessage { id: 1, arg1: c as usize, arg2: 0, arg3: 0, arg4: 0}), - Opcode::RxStats(stats) => { + /* Opcode::RxStats(stats) => { let data = xous::carton::Carton::from_bytes(stats); Message::Borrow(data.into_message(2)) - } + } */ } } } -use log::error; +use log::{error, info}; use core::fmt::{Error, Write}; use utralib::generated::*; @@ -375,11 +376,23 @@ fn do_agent(cmd: &mut String, com_cid: xous::CID, pds_list: &mut Vec::new(); write!(&mut sendable_string, "{}", pds); println!("{}", sendable_string); send_pds_line(com_cid, &sendable_string); + loop { + if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) { + if elapsed_time - last_time > 250 { + last_time = elapsed_time; + break; + } + } + } } pds_list.clear(); } else if tokens[1].trim() == "ec_version" { @@ -447,15 +460,29 @@ pub union sl_wfx_indication_data_u { #[xous::xous_main] fn xmain() -> ! { - log_server::init_wait().unwrap(); - print!("FCCAGENT: my PID is {}", xous::process::id()); + /* + // use this to select which UART to monitor in the main loop + use utralib::generated::*; + let gpio_base = xous::syscall::map_memory( + xous::MemoryAddress::new(utra::gpio::HW_GPIO_BASE), + None, + 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ) + .expect("couldn't map GPIO CSR range"); + let mut gpio = CSR::new(gpio_base.as_mut_ptr() as *mut u32); + gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 2); // 0 = kernel, 1 = log, 2 = app_uart + */ - let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap(); - let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap(); + log_server::init_wait().unwrap(); + info!("FCCAGENT: my PID is {}", xous::process::id()); let agent_server_sid = xous_names::register_name(xous::names::SERVER_NAME_FCCAGENT).expect("FCCAGENT: can't register server"); let agent_server_client = xous_names::request_connection_blocking(xous::names::SERVER_NAME_FCCAGENT).expect("FCCAGENT: can't connect to COM"); + let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap(); + let ticktimer_conn = xous::connect(ticktimer_server_id).unwrap(); + let mut uart = Uart::new(agent_server_client); let com_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_COM).expect("FCCAGENT: can't connect to COM"); @@ -477,6 +504,7 @@ fn xmain() -> ! { let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap(); let mut pds_list: Vec, U16> = Vec::new(); let mut repeat = false; + let mut phase = 0; loop { let envelope = xous::try_receive_message(agent_server_sid).unwrap(); match envelope { @@ -489,12 +517,13 @@ fn xmain() -> ! { cmd_string.push(c as char).unwrap(); } else { println!(""); - do_agent(&mut cmd_string, com_conn, &mut pds_list, &info_csr).unwrap(); + do_agent(&mut cmd_string, com_conn, &mut pds_list, &info_csr,/* &mut gpio */).unwrap(); repeat = was_continuous(&mut cmd_string); // print!("agent@precursor:~$ "); cmd_string.clear(); } }, + /* Opcode::RxStats(stats) => { println!("got rxstats message"); let mut stats_u: sl_wfx_indication_data_u = sl_wfx_indication_data_u {raw_data: [0; 376]}; @@ -506,7 +535,7 @@ fn xmain() -> ! { println!("PER on total number of frames: {}", unsafe{stats_u.rx_stats.per_total}); println!("Throughput on correct frames received: {}", unsafe{stats_u.rx_stats.throughput}); // TODO: fill in more stats output - }, + },*/ _ => println!("Unknown opcode received.") } } @@ -520,17 +549,57 @@ fn xmain() -> ! { if repeat { for pds in pds_list.iter() { - let mut sendable_string = xous::String::new(4096); + let mut sendable_string = xous::String::<512>::new(); write!(&mut sendable_string, "{}", pds); println!("{}", sendable_string); send_pds_line(com_conn, &sendable_string); } } - /* - let mut string_buffer = xous::String::new(4096); + + /* // for testing the PDS API + let mut string_buffer = xous::String::<512>::new(); write!(&mut string_buffer, "\"{{i:{{a:7,b:1,f:3E8,c:{{a:0,b:0,c:0,d:44}},d:{{a:BB8,b:0,c:0,d:15,e:64,f:4}},e:{{}}}}}}\"").expect("Can't write"); + //write!(&mut string_buffer, "{{i:{{a:7,b:1,f:3E8,c:{{a:0,b:0,c:0,d:44}},d:{{a:BB8,b:0,c:0,d:15,e:64,f:4}},e:{{}}}}}}").expect("Can't write"); println!("sending line: {}", string_buffer); - send_pds_line(com_conn, &string_buffer);*/ + send_pds_line(com_conn, &string_buffer); */ + + //// full simulation of commands + /* + if phase == 0 { + info!("FCCAGENT: sending PDS start commands"); + let mut pds1: String = String::from(""); + write!(&mut pds1, "{{j:{{a:0}}}}"); + pds_list.push(pds1); + let mut pds2: String = String::from(""); + write!(&mut pds2, "{{h:{{e:0,a:50,b:0,c:[{{a:[1,E],b:[0,0,0,0,0,0]}}],d:0}},i:{{a:1,b:1,f:F4240,c:{{a:0,b:0,c:0,d:44}},d:{{a:5DC,b:0,c:0,d:0,e:0,f:1}},e:{{}}}}}}"); + pds_list.push(pds2); + let mut pds3: String = String::from(""); + write!(&mut pds3, "{{i:{{a:1,b:1,f:F4240,c:{{a:0,b:0,c:0,d:44}},d:{{a:5DC,b:0,c:0,d:0,e:0,f:1}},e:{{}}}}}}"); + pds_list.push(pds3); + + let mut cmd: String = String::from(""); + write!(&mut cmd, "wfx_test_agent commit_pds"); + do_agent(&mut cmd, com_conn, &mut pds_list, &info_csr).unwrap(); + phase = 1; + } else if phase == 1 { + info!("FCCAGENT: waiting..."); + phase = 2; + } else if phase == 2 { + info!("FCCAGENT: sending PDS stop commands"); + let mut pds_stop: String = String::from(""); + write!(&mut pds_stop, "{{i:{{a:1,b:1,f:F4240,c:{{a:0,b:0,c:0,d:44}},d:{{a:5DC,b:0,c:0,d:0,e:64,f:1}},e:{{}}}}}}"); + pds_list.push(pds_stop); + + let mut cmd: String = String::from(""); + write!(&mut cmd, "wfx_test_agent commit_pds"); + do_agent(&mut cmd, com_conn, &mut pds_list, &info_csr).unwrap(); + phase = 3; + } else { + info!("FCCAGENT: waiting again..."); + phase = 0; + } + */ + } } else { error!("error requesting ticktimer!") diff --git a/services/log-server/src/main.rs b/services/log-server/src/main.rs index d14466df0..9b3eb4da7 100644 --- a/services/log-server/src/main.rs +++ b/services/log-server/src/main.rs @@ -324,7 +324,7 @@ fn some_main() -> ! { ) .expect("couldn't map GPIO CSR range"); let mut gpio = CSR::new(gpio_base.as_mut_ptr() as *mut u32); - gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 1); // 0 = kernel, 1 = log, 2 = app_uart + gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 2); // 0 = kernel, 1 = log, 2 = app_uart } let mut output = implementation::init(); diff --git a/svd2utra/examples/soc.svd b/svd2utra/examples/soc.svd index bb4c9e69d..cee67ae7c 100644 --- a/svd2utra/examples/soc.svd +++ b/svd2utra/examples/soc.svd @@ -19,7 +19,7 @@ IDENTIFIER_MEM - + 0x0000 0x00 32 @@ -1320,10 +1320,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x14057e44 + 0xbc2a74fa 32 @@ -1340,7 +1340,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 - 0x06 + 0x08 32 @@ -1354,7 +1354,7 @@ beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> GIT_DIRTY 0x001c - 0x01 + 0x00 32 @@ -3030,7 +3030,7 @@ again until the interrupt is serviced.]]> SEED1 0x0000 - 0x4066250a + 0x3f420745 32 @@ -3045,7 +3045,7 @@ again until the interrupt is serviced.]]> SEED0 0x0004 - 0x7e58e3d5 + 0xbd3a2e0 32 @@ -4124,10 +4124,40 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> - XADC_DRP_ENABLE + XADC_GPIO5 + 0x002c 0x00 32 + + + xadc_gpio5 + 11 + [11:0] + 0 + + + + + XADC_GPIO2 + + 0x0030 + 0x00 + 32 + + + xadc_gpio2 + 11 + [11:0] + 0 + + + + + XADC_DRP_ENABLE + 0x0034 + 0x00 + 32 xadc_drp_enable @@ -4139,7 +4169,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> XADC_DRP_READ - 0x0030 + 0x0038 0x00 32 @@ -4153,7 +4183,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> XADC_DRP_WRITE - 0x0034 + 0x003c 0x00 32 @@ -4167,7 +4197,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> XADC_DRP_DRDY - 0x0038 + 0x0040 0x00 32 @@ -4181,7 +4211,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> XADC_DRP_ADR - 0x003c + 0x0044 0x00 32 @@ -4195,7 +4225,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> XADC_DRP_DAT_W - 0x0040 + 0x0048 0x00 32 @@ -4209,7 +4239,7 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> XADC_DRP_DAT_R - 0x0044 + 0x004c 0x00 32 @@ -4221,79 +4251,10 @@ VCCBRAM (V) = ``Value`` x 3 / 4096.]]> - - RO_HEALTH_MONOBIT - 0x0048 - 0x00 - 32 - - - stat_error - 0 - [0:0] - 0 - - - - missed_sample - 1 - [1:1] - 1 - - - - - - RO_HEALTH_ONES - 0x004c - 0x00 - 32 - - - ones - 31 - [31:0] - 0 - - - - - - RO_HEALTH_SAMPLECOUNT - 0x0050 - 0x40000 - 32 - - - samplecount - 31 - [31:0] - 0 - - - - - - RO_HEALTH_SIGMA - 0x0054 - 0x200 - 32 - - - sigma - 31 - [31:0] - 0 - - - - 0 - 0x58 + 0x50 registers