get fcc test working

This commit is contained in:
bunnie 2021-01-02 03:04:28 +08:00
parent 3ceb41208c
commit 63234411e2
7 changed files with 57 additions and 34 deletions

View file

@ -21,8 +21,8 @@ riscv = "0.5.6"
debug-print = []
print-panics = []
report-memory = ["stats_alloc"]
default = ["print-panics", "debug-print"]
# default = []
# default = ["print-panics", "debug-print"]
default = []
[target.'cfg(any(windows, unix))'.dependencies]
lazy_static = "1.4"

View file

@ -12,6 +12,7 @@ log-server = { path = "../log-server" }
ticktimer-server = { path = "../ticktimer-server" }
log = "0.4"
com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "a9e05f414accef08348b77be6fc0f668b319e6ff" }
#com_rs = { path = "../../../betrusted-ec/sw/com_rs" }
typenum = "1.12"
[target.'cfg(not(any(windows,unix)))'.dependencies]

View file

@ -91,7 +91,7 @@ pub enum Opcode<'a> {
Wf200Rev,
/// Send a line of PDS data
Wf200PdsLine(&'a [u8]),
Wf200PdsLine(&'a str),
/// Send Rx stats to fcc-agent
RxStatsAgent,
@ -136,13 +136,13 @@ impl<'a> core::convert::TryFrom<&'a Message> for Opcode<'a> {
},
Message::Borrow(m) => {
if m.id as u16 == ComState::WFX_PDS_LINE_SET.verb {
let line = unsafe {
let s = unsafe {
core::slice::from_raw_parts(
m.buf.as_ptr(),
m.valid.map(|x| x.get()).unwrap_or_else(|| m.buf.len()),
)
};
Ok(Opcode::Wf200PdsLine(line))
Ok(Opcode::Wf200PdsLine(core::str::from_utf8(s).unwrap()))
} else {
Err("unrecognized opcode")
}
@ -183,10 +183,10 @@ impl<'a> Into<Message> for Opcode<'a> {
id: ComState::WFX_FW_REV_GET.verb as _, arg1: 0, arg2: 0, arg3: 0, arg4: 0 }),
Opcode::EcGitRev => Message::BlockingScalar(ScalarMessage {
id: ComState::EC_GIT_REV.verb as _, arg1: 0, arg2: 0, arg3: 0, arg4: 0 }),
Opcode::Wf200PdsLine(pdsline) => {
/*Opcode::Wf200PdsLine(pdsline) => {
let data = xous::carton::Carton::from_bytes(pdsline);
Message::Borrow(data.into_message(ComState::WFX_PDS_LINE_SET.verb as _))
},
},*/
Opcode::RxStatsAgent => Message::Scalar(ScalarMessage {
id: ComState::WFX_RXSTAT_GET.verb as _, arg1: 0, arg2: 0, arg3: 0, arg4: 0 }),
_ => todo!("message type not yet implemented")

View file

@ -7,6 +7,7 @@ pub mod api;
use api::BattStats;
use xous::{send_message, Error, CID};
use com_rs::*;
pub fn power_off_soc(cid: CID) -> Result<(), xous::Error> {
send_message(cid, api::Opcode::PowerOffSoc.into()).map(|_| ())
@ -50,8 +51,9 @@ pub fn get_ec_git_rev(cid: CID) -> Result<(u32, bool), Error> {
}
}
pub fn send_pds_line(cid: CID, line: &[u8]) -> Result<(), Error> {
send_message(cid, api::Opcode::Wf200PdsLine(line).into()).map(|_| ())
pub fn send_pds_line(cid: CID, s: &xous::String) -> Result<(), Error> {
s.lend(cid, ComState::WFX_PDS_LINE_SET.verb as _).map( |_| ())
// send_message(cid, api::Opcode::Wf200PdsLine(line).into()).map(|_| ())
}
pub fn get_rx_stats_agent(cid: CID) -> Result<(), Error> {

View file

@ -92,9 +92,10 @@ mod implementation {
pub fn txrx(&mut self, tx: u16) -> u16 {
self.csr.wfo(utra::com::TX_TX, tx as u32); // transaction is automatically initiated on write
// wait while transaction is in progress. A transaction takes about 80-100 CPU cycles;
// not quite enough to be worth the overhead of an interrupt, so we just yield our time slice
// not quite enough to be worth the overhead of an interrupt, so we just busy wait
// yielding a time slice is a bad idea: we don't get it back until like 1ms later, which causes other problems
while self.csr.rf(utra::com::STATUS_TIP) == 1 {
xous::yield_slice();
// xous::yield_slice();
}
// grab the RX value and return it
@ -282,15 +283,18 @@ fn xmain() -> ! {
)
.expect("COM: couldn't return WF200 firmware rev");
}
Opcode::Wf200PdsLine(line) => {
info!("COM: Wf200PdsLine got line {}", unsafe{core::str::from_utf8_unchecked(line)});
/*
Opcode::Wf200PdsLine(l) => {
info!("COM: Wf200PdsLine got line {}", l);
let line = l.as_bytes();
let length = line.len() 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);
com.txrx(length);
for i in 0..(ComState::WFX_PDS_LINE_SET.w_words as usize - 1) {
//for i in 0..(ComState::WFX_PDS_LINE_SET.w_words as usize - 1) {
for i in 0..128 {
let word: u16;
if (i * 2 + 1) == (length as usize - 1) { // odd last element
if (i * 2 + 1) == length as usize { // odd last element
word = line[i * 2] as u16;
} else if i * 2 < length as usize {
word = (line[i*2] as u16) | ((line[i*2+1] as u16) << 8);
@ -298,7 +302,8 @@ fn xmain() -> ! {
word = 0;
}
com.txrx(word);
}*/
//info!("COM: 0x{:04x}", word);
}
}
Opcode::RxStatsAgent => {
xous::send_message(agent_conn, xous::Message::Scalar(

View file

@ -159,7 +159,7 @@ impl Write for Uart {
}
}
fn do_agent(cmd: &mut String<U2048>, com_cid: xous::CID) -> Result<(), xous::Error> {
fn do_agent(cmd: &mut String<U2048>, com_cid: xous::CID, pds_list: &mut Vec<String<U512>, U16>) -> Result<(), xous::Error> {
if false {
let tokens: Vec<&str, U16> = cmd.as_mut_str().split(' ').collect();
for token in tokens.iter() {
@ -224,11 +224,24 @@ fn do_agent(cmd: &mut String<U2048>, com_cid: xous::CID) -> Result<(), xous::Err
println!("0.0.0\n\r");
} else if tokens[1].trim() == "write_test_data" {
let pdsline = tokens[2].trim();
println!("sending line: {}", pdsline);
send_pds_line(com_cid, pdsline.as_bytes())?;
let mut stripped: String<U512> = String::from("");
for c in pdsline.chars() {
if c != '"' {
stripped.push(c);
}
}
pds_list.push(stripped);
} else if tokens[1].trim() == "read_rx_stats" {
println!("sending rx stats request");
get_rx_stats_agent(com_cid).unwrap();
println!("rx stats request disabled!!");
//get_rx_stats_agent(com_cid).unwrap();
} else if tokens[1].trim() == "commit_pds" {
for pds in pds_list.iter() {
let mut sendable_string = xous::String::new(4096);
write!(&mut sendable_string, "{}", pds);
println!("{}", sendable_string);
send_pds_line(com_cid, &sendable_string);
}
pds_list.clear();
} else {
println!("{}: wfx_test_agent sub-command not recognized.", tokens[1].trim());
}
@ -299,6 +312,7 @@ fn xmain() -> ! {
print!("\n\r\n\r*** FCC agent ***\n\r\n\r");
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
let mut pds_list: Vec<String<U512>, U16> = Vec::new();
loop {
let envelope = xous::try_receive_message(agent_server_sid).unwrap();
match envelope {
@ -311,7 +325,7 @@ fn xmain() -> ! {
cmd_string.push(c as char).unwrap();
} else {
println!("");
do_agent(&mut cmd_string, com_conn).unwrap();
do_agent(&mut cmd_string, com_conn, &mut pds_list).unwrap();
// print!("agent@precursor:~$ ");
cmd_string.clear();
}
@ -332,20 +346,20 @@ fn xmain() -> ! {
}
}
}
_ => (),
_ => () //xous::yield_slice(), // no message received, idle
}
// Periodic tasks
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
if elapsed_time - last_time > 10_000 {
last_time = elapsed_time;
let pdsline = "testingline";
println!("sending line: {}", pdsline);
send_pds_line(com_conn, pdsline.as_bytes());
/*
let mut string_buffer = xous::String::new(4096);
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);*/
}
} else {
error!("error requesting ticktimer!")
}
xous::yield_slice();
}
}

View file

@ -185,7 +185,7 @@ fn shell_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, 0); // 0 = kernel, 1 = log, 2 = app_uart
gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 2); // 0 = kernel, 1 = log, 2 = app_uart
}
let style_dark = DrawStyle::new(PixelColor::Dark, PixelColor::Dark, 1);
@ -202,7 +202,7 @@ fn shell_main() -> ! {
graphics_server::set_glyph_style(graphics_conn, GlyphStyle::Regular).expect("unable to set glyph");
let (_, font_h) = graphics_server::query_glyph(graphics_conn).expect("unable to query glyph");
let mut work_clipregion = Rectangle::new_coords_with_style(4, font_h as i16 + 2, screensize.x, font_h as i16 * 8 + 18, style_light);
let mut work_cursor;
let mut work_cursor: Cursor;
graphics_server::draw_rectangle(graphics_conn, work_clipregion)
.expect("unable to clear region");
@ -241,6 +241,7 @@ fn shell_main() -> ! {
Point::new(screensize.x as _, font_h as i16),
style_dark)).expect("can't draw line");
/*
// work area
string_buffer.clear();
write!(&mut string_buffer,
@ -263,9 +264,9 @@ fn shell_main() -> ! {
graphics_server::draw_string(graphics_conn, &string_buffer).expect("unable to draw string");
firsttime = false;
}
*/
// rate limit graphics
// ticktimer_server::sleep_ms(ticktimer_conn, 1000).expect("couldn't sleep");
//ticktimer_server::sleep_ms(ticktimer_conn, 500).expect("couldn't sleep");
// draw the ball
graphics_server::draw_rectangle(
@ -294,7 +295,7 @@ fn shell_main() -> ! {
// Periodic tasks
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
if elapsed_time - last_time > 500 {
if elapsed_time - last_time > 1000 {
last_time = elapsed_time;
info!("Requesting batt stats from COM");
get_batt_stats_nb(com_conn).expect("Can't get battery stats from COM");