mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
checkpoint: problems with pds send line (borrowed memory)
This commit is contained in:
parent
17156e483c
commit
3ceb41208c
5 changed files with 77 additions and 70 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -224,12 +224,12 @@ fn xmain() -> ! {
|
|||
let shell_conn = xous::connect(shell_id).unwrap();
|
||||
|
||||
let agent_conn: usize;
|
||||
//if cfg!(feature = "fccagent") {
|
||||
if cfg!(feature = "fccagent") {
|
||||
let agent_id = xous::SID::from_bytes(b"fcc-agent-server").unwrap();
|
||||
agent_conn = xous::connect(agent_id).expect("Couldn't connect to fcc-agent! Are you building with the right features enabled?");
|
||||
//} else {
|
||||
// agent_conn = 0; // bogus value
|
||||
//}
|
||||
} else {
|
||||
agent_conn = 0; // bogus value
|
||||
}
|
||||
|
||||
// Create a new com object
|
||||
let mut com = XousCom::new();
|
||||
|
|
@ -283,6 +283,8 @@ 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)});
|
||||
/*
|
||||
let length = line.len() as u16;
|
||||
com.txrx(ComState::WFX_PDS_LINE_SET.verb);
|
||||
com.txrx(length);
|
||||
|
|
@ -296,22 +298,29 @@ fn xmain() -> ! {
|
|||
word = 0;
|
||||
}
|
||||
com.txrx(word);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
Opcode::RxStatsAgent => {
|
||||
xous::send_message(agent_conn, xous::Message::Scalar(
|
||||
xous::ScalarMessage { id: 1, arg1: '!' as usize, arg2: 0, arg3: 0, arg4: 0}
|
||||
));
|
||||
let mut stats: [u8; (ComState::WFX_RXSTAT_GET.r_words*2) as usize] = [0; (ComState::WFX_RXSTAT_GET.r_words*2) as usize];
|
||||
/*
|
||||
com.txrx(ComState::WFX_RXSTAT_GET.verb);
|
||||
for i in 0..ComState::WFX_RXSTAT_GET.r_words as usize {
|
||||
let data = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT));
|
||||
stats[i*2] = data as u8;
|
||||
stats[i*2+1] = (data >> 8) as u8;
|
||||
}
|
||||
//if cfg!(feature = "fccagent") {
|
||||
}*/
|
||||
if cfg!(feature = "fccagent") {
|
||||
// hard-coded from fccagent to break circular dependency of fcc agent on com on agent on com on...
|
||||
let data = xous::carton::Carton::from_bytes(&stats);
|
||||
let m = xous::Message::Borrow(data.into_message(2));
|
||||
xous::send_message(agent_conn, m);
|
||||
//}
|
||||
}
|
||||
xous::send_message(agent_conn, xous::Message::Scalar(
|
||||
xous::ScalarMessage { id: 1, arg1: '@' as usize, arg2: 0, arg3: 0, arg4: 0}
|
||||
));
|
||||
}
|
||||
_ => error!("unknown opcode"),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
use xous::{Message, ScalarMessage};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Opcode<'a> {
|
||||
Char(u8),
|
||||
RxStats(&'a [u8]),
|
||||
}
|
||||
impl<'a> core::convert::TryFrom<&'a Message> for Opcode<'a> {
|
||||
type Error = &'static str;
|
||||
fn try_from(message: &'a Message) -> Result<Self, Self::Error> {
|
||||
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 {
|
||||
core::slice::from_raw_parts(
|
||||
m.buf.as_ptr(),
|
||||
m.valid.map(|x| x.get()).unwrap_or_else(|| m.buf.len()),
|
||||
)
|
||||
};
|
||||
Ok(Opcode::RxStats(stats))
|
||||
}
|
||||
_ => Err("unrecognized opcode"),
|
||||
}
|
||||
_ => Err("unhandled message type"),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a> Into<Message> for Opcode<'a> {
|
||||
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) => {
|
||||
let data = xous::carton::Carton::from_bytes(stats);
|
||||
Message::Borrow(data.into_message(2))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,49 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
#![cfg_attr(target_os = "none", no_main)]
|
||||
|
||||
mod api;
|
||||
use api::Opcode;
|
||||
use xous::{Message, ScalarMessage};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Opcode<'a> {
|
||||
Char(u8),
|
||||
RxStats(&'a [u8]),
|
||||
}
|
||||
impl<'a> core::convert::TryFrom<&'a Message> for Opcode<'a> {
|
||||
type Error = &'static str;
|
||||
fn try_from(message: &'a Message) -> Result<Self, Self::Error> {
|
||||
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 {
|
||||
core::slice::from_raw_parts(
|
||||
m.buf.as_ptr(),
|
||||
m.valid.map(|x| x.get()).unwrap_or_else(|| m.buf.len()),
|
||||
)
|
||||
};
|
||||
Ok(Opcode::RxStats(stats))
|
||||
}
|
||||
_ => {print!("unhandled opcode"); Err("unrecognized opcode")},
|
||||
}
|
||||
_ => {print!("unhandled message type"); Err("unhandled message type")},
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a> Into<Message> for Opcode<'a> {
|
||||
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) => {
|
||||
let data = xous::carton::Carton::from_bytes(stats);
|
||||
Message::Borrow(data.into_message(2))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use log::error;
|
||||
use core::fmt::{Error, Write};
|
||||
|
|
@ -13,7 +54,6 @@ use heapless::String;
|
|||
use heapless::Vec;
|
||||
use heapless::consts::*;
|
||||
|
||||
use xous::{Message, ScalarMessage};
|
||||
use core::convert::TryFrom;
|
||||
|
||||
use com::*;
|
||||
|
|
@ -67,7 +107,7 @@ impl Uart {
|
|||
Note: this function takes over the console UART. Not compatible with console logging.
|
||||
*/
|
||||
let uart = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utra::console::HW_CONSOLE_BASE),
|
||||
xous::MemoryAddress::new(utra::app_uart::HW_APP_UART_BASE),
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
|
|
@ -83,7 +123,7 @@ impl Uart {
|
|||
UART_STRUCT.rx_conn = connection;
|
||||
}
|
||||
|
||||
xous::claim_interrupt(utra::console::CONSOLE_IRQ, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
|
||||
xous::claim_interrupt(utra::app_uart::APP_UART_IRQ, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
|
||||
|
||||
uart_struct
|
||||
}
|
||||
|
|
@ -120,7 +160,7 @@ impl Write for Uart {
|
|||
}
|
||||
|
||||
fn do_agent(cmd: &mut String<U2048>, com_cid: xous::CID) -> Result<(), xous::Error> {
|
||||
if true {
|
||||
if false {
|
||||
let tokens: Vec<&str, U16> = cmd.as_mut_str().split(' ').collect();
|
||||
for token in tokens.iter() {
|
||||
println!("token: {}", token);
|
||||
|
|
@ -181,19 +221,17 @@ fn do_agent(cmd: &mut String<U2048>, com_cid: xous::CID) -> Result<(), xous::Err
|
|||
let (major, minor, build) = get_wf200_fw_rev(com_cid).unwrap();
|
||||
println!("{}.{}.{}\n\r", major, minor, build);
|
||||
} else if tokens[1].trim() == "read_driver_version" {
|
||||
println!("n/a\n\r");
|
||||
println!("0.0.0\n\r");
|
||||
} else if tokens[1].trim() == "write_test_data" {
|
||||
if tokens.len() != 3 {
|
||||
// wrong command length, ignore
|
||||
return Ok(());
|
||||
}
|
||||
let pdsline = tokens[2].trim();
|
||||
println!("sending line: {}", pdsline);
|
||||
send_pds_line(com_cid, pdsline.as_bytes())?;
|
||||
} else if tokens[1].trim() == "read_rx_stats" {
|
||||
println!("sending rx stats request");
|
||||
get_rx_stats_agent(com_cid).unwrap();
|
||||
} else {
|
||||
println!("{}: wfx_test_agent sub-command not recognized.", tokens[1].trim());
|
||||
}
|
||||
|
||||
} else {
|
||||
println!("{}: command not recognized.", command.trim());
|
||||
}
|
||||
|
|
@ -260,7 +298,7 @@ fn xmain() -> ! {
|
|||
uart.enable_rx();
|
||||
|
||||
print!("\n\r\n\r*** FCC agent ***\n\r\n\r");
|
||||
let mut last_time: u64 = 0;
|
||||
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
||||
loop {
|
||||
let envelope = xous::try_receive_message(agent_server_sid).unwrap();
|
||||
match envelope {
|
||||
|
|
@ -290,7 +328,7 @@ fn xmain() -> ! {
|
|||
println!("Throughput on correct frames received: {}", unsafe{stats_u.rx_stats.throughput});
|
||||
// TODO: fill in more stats output
|
||||
},
|
||||
_ => ()
|
||||
_ => println!("Unknown opcode received.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -298,9 +336,12 @@ fn xmain() -> ! {
|
|||
}
|
||||
// Periodic tasks
|
||||
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
|
||||
if elapsed_time - last_time > 500 {
|
||||
if elapsed_time - last_time > 10_000 {
|
||||
last_time = elapsed_time;
|
||||
// println!("Agent loop");
|
||||
|
||||
let pdsline = "testingline";
|
||||
println!("sending line: {}", pdsline);
|
||||
send_pds_line(com_conn, pdsline.as_bytes());
|
||||
}
|
||||
} else {
|
||||
error!("error requesting ticktimer!")
|
||||
|
|
|
|||
|
|
@ -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, 1); // 0 = kernel, 1 = log
|
||||
gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 0); // 0 = kernel, 1 = log, 2 = app_uart
|
||||
}
|
||||
|
||||
let style_dark = DrawStyle::new(PixelColor::Dark, PixelColor::Dark, 1);
|
||||
|
|
|
|||
Loading…
Reference in a new issue