try to layer in the fcc agent

This commit is contained in:
bunnie 2020-12-31 19:31:12 +08:00
parent 886f48ba61
commit b9a31f7d99
16 changed files with 261 additions and 82 deletions

17
Cargo.lock generated
View file

@ -156,7 +156,7 @@ dependencies = [
[[package]] [[package]]
name = "com_rs" name = "com_rs"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/betrusted-io/com_rs.git?rev=9a91a81f482ea8eba2f2de5d6c20b9bd399f39a9#9a91a81f482ea8eba2f2de5d6c20b9bd399f39a9" source = "git+https://github.com/betrusted-io/com_rs.git?rev=a9e05f414accef08348b77be6fc0f668b319e6ff#a9e05f414accef08348b77be6fc0f668b319e6ff"
[[package]] [[package]]
name = "crc" name = "crc"
@ -217,6 +217,20 @@ dependencies = [
"termcolor", "termcolor",
] ]
[[package]]
name = "fcc-agent"
version = "0.1.0"
dependencies = [
"com",
"heapless",
"log",
"log-server",
"ticktimer-server",
"typenum",
"utralib",
"xous",
]
[[package]] [[package]]
name = "fuchsia-cprng" name = "fuchsia-cprng"
version = "0.1.1" version = "0.1.1"
@ -801,7 +815,6 @@ dependencies = [
"bitflags", "bitflags",
"blitstr", "blitstr",
"com", "com",
"com_rs",
"graphics-server", "graphics-server",
"log", "log",
"log-server", "log-server",

View file

@ -9,6 +9,7 @@ members = [
"services/ticktimer-server", "services/ticktimer-server",
"services/com", "services/com",
"services/trng-tester", "services/trng-tester",
"services/fcc-agent",
# "services/xous-names", # "services/xous-names",
"svd2utra", "svd2utra",
"xtask", "xtask",
@ -19,6 +20,7 @@ default-members = [
"services/graphics-server", "services/graphics-server",
"services/ticktimer-server", "services/ticktimer-server",
"services/trng-tester", "services/trng-tester",
"services/fcc-agent",
# "services/xous-names", # "services/xous-names",
"services/com", "services/com",
] ]

View file

@ -81,6 +81,11 @@ then
sudo wishbone-tool --csr-csv $CSR_CSV --load-name $KERNEL_IMAGE --load-address 0x500000 --load-flash sudo wishbone-tool --csr-csv $CSR_CSV --load-name $KERNEL_IMAGE --load-address 0x500000 --load-flash
fi fi
else else
md5sum $FPGA_IMAGE
md5sum $KERNEL_IMAGE
md5sum $CSR_CSV
if [ $USE_IDENTITY -eq 1 ] if [ $USE_IDENTITY -eq 1 ]
then then
# there is a private key # there is a private key

View file

@ -11,7 +11,7 @@ heapless = "0.5"
log-server = { path = "../log-server" } log-server = { path = "../log-server" }
ticktimer-server = { path = "../ticktimer-server" } ticktimer-server = { path = "../ticktimer-server" }
log = "0.4" log = "0.4"
com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "9a91a81f482ea8eba2f2de5d6c20b9bd399f39a9" } com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "a9e05f414accef08348b77be6fc0f668b319e6ff" }
typenum = "1.12" typenum = "1.12"
[target.'cfg(not(any(windows,unix)))'.dependencies] [target.'cfg(not(any(windows,unix)))'.dependencies]
@ -21,5 +21,6 @@ utralib = { path = "../../utralib"}
[features] [features]
debugprint = [] debugprint = []
fccagent = []
#default = [] # "debugprint" #default = [] # "debugprint"
default = ["debugprint"] default = ["debugprint", "fccagent"]

View file

@ -35,7 +35,7 @@ impl Into<[usize; 2]> for BattStats {
} }
#[derive(Debug)] #[derive(Debug)]
pub enum Opcode { pub enum Opcode<'a> {
/// Battery stats /// Battery stats
BattStats, BattStats,
@ -76,16 +76,28 @@ pub enum Opcode {
FlashErase, FlashErase,
/// Program a page of FLASH /// Program a page of FLASH
FlashProgram, FlashProgram(&'a [u8]),
/// Update the SSID list /// Update the SSID list
SsidScan, SsidScan,
/// Return the latest SSID list /// Return the latest SSID list
SsidFetch, SsidFetch,
/// Fetch the git ID of the EC
EcGitRev,
/// Fetch the firmware rev of the WF200
Wf200Rev,
/// Send a line of PDS data
Wf200PdsLine(&'a [u8]),
/// Send Rx stats to fcc-agent
RxStatsAgent,
} }
impl<'a> core::convert::TryFrom<&'a Message> for Opcode { impl<'a> core::convert::TryFrom<&'a Message> for Opcode<'a> {
type Error = &'static str; type Error = &'static str;
fn try_from(message: &'a Message) -> Result<Self, Self::Error> { fn try_from(message: &'a Message) -> Result<Self, Self::Error> {
match message { match message {
@ -103,6 +115,8 @@ impl<'a> core::convert::TryFrom<&'a Message> for Opcode {
} else if m.id as u16 == ComState::STAT_RETURN.verb { } else if m.id as u16 == ComState::STAT_RETURN.verb {
let raw_stats: [usize; 2] = [m.arg1, m.arg2]; let raw_stats: [usize; 2] = [m.arg1, m.arg2];
Ok(Opcode::BattStatsReturn(raw_stats.into())) Ok(Opcode::BattStatsReturn(raw_stats.into()))
} else if m.id as u16 == ComState::WFX_RXSTAT_GET.verb {
Ok(Opcode::RxStatsAgent)
} else { } else {
Err("unrecognized command") Err("unrecognized command")
} }
@ -112,6 +126,23 @@ impl<'a> core::convert::TryFrom<&'a Message> for Opcode {
Ok(Opcode::BattStats) Ok(Opcode::BattStats)
} else if m.id as u16 == ComState::GYRO_READ.verb { } else if m.id as u16 == ComState::GYRO_READ.verb {
Ok(Opcode::ImuAccelRead) Ok(Opcode::ImuAccelRead)
} else if m.id as u16 == ComState::WFX_FW_REV_GET.verb {
Ok(Opcode::Wf200Rev)
} else if m.id as u16 == ComState::EC_GIT_REV.verb {
Ok(Opcode::EcGitRev)
} else {
Err("unrecognized opcode")
}
},
Message::Borrow(m) => {
if m.id as u16 == ComState::WFX_PDS_LINE_SET.verb {
let line = 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))
} else { } else {
Err("unrecognized opcode") Err("unrecognized opcode")
} }
@ -121,7 +152,7 @@ impl<'a> core::convert::TryFrom<&'a Message> for Opcode {
} }
} }
impl Into<Message> for Opcode { impl<'a> Into<Message> for Opcode<'a> {
fn into(self) -> Message { fn into(self) -> Message {
match self { match self {
Opcode::BoostOn => Message::Scalar(ScalarMessage { Opcode::BoostOn => Message::Scalar(ScalarMessage {
@ -147,7 +178,17 @@ impl Into<Message> for Opcode {
arg3: 0, arg3: 0,
arg4: 0, arg4: 0,
}) })
} },
Opcode::Wf200Rev => Message::BlockingScalar(ScalarMessage {
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) => {
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") _ => todo!("message type not yet implemented")
} }
} }

View file

@ -25,3 +25,35 @@ pub fn get_batt_stats(cid: CID) -> Result<BattStats, xous::Error> {
pub fn get_batt_stats_nb(cid: CID) -> Result<(), xous::Error> { pub fn get_batt_stats_nb(cid: CID) -> Result<(), xous::Error> {
send_message(cid, api::Opcode::BattStatsNb.into()).map(|_|()) send_message(cid, api::Opcode::BattStatsNb.into()).map(|_|())
} }
pub fn get_wf200_fw_rev(cid: CID) -> Result<(u8, u8, u8), xous::Error> {
let response = send_message(cid, api::Opcode::Wf200Rev.into())?;
if let xous::Result::Scalar1(rev) = response {
Ok(((rev >> 16) as u8, (rev >> 8) as u8, rev as u8))
} else {
panic!("unexpected return value: {:#?}", response);
}
}
pub fn get_ec_git_rev(cid: CID) -> Result<(u32, bool), Error> {
let response = send_message(cid, api::Opcode::EcGitRev.into())?;
if let xous::Result::Scalar2(rev, dirty) = response {
let dirtybool: bool;
if dirty == 0 {
dirtybool = false;
} else {
dirtybool = true;
}
Ok((rev as u32, dirtybool))
} else {
panic!("unexpected return value: {:#?}", response);
}
}
pub fn send_pds_line(cid: CID, line: &[u8]) -> Result<(), Error> {
send_message(cid, api::Opcode::Wf200PdsLine(line).into()).map(|_| ())
}
pub fn get_rx_stats_agent(cid: CID) -> Result<(), Error> {
send_message(cid, api::Opcode::RxStatsAgent.into()).map(|_| ())
}

View file

@ -11,6 +11,8 @@ use log::{error, info};
use com_rs::*; use com_rs::*;
use xous::CID; use xous::CID;
const STD_TIMEOUT: u32 = 100;
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct WorkRequest { pub struct WorkRequest {
work: ComSpec, work: ComSpec,
@ -31,6 +33,7 @@ mod implementation {
use xous::CID; use xous::CID;
use log::{error, info}; use log::{error, info};
use crate::return_battstats; use crate::return_battstats;
use crate::STD_TIMEOUT;
#[macro_use] #[macro_use]
use heapless::Vec; use heapless::Vec;
@ -41,8 +44,6 @@ mod implementation {
use typenum::bit::{B0, B1}; use typenum::bit::{B0, B1};
type U1280 = UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>; type U1280 = UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>;
*/ */
const STD_TIMEOUT: u32 = 100;
pub struct XousCom { pub struct XousCom {
csr: utralib::CSR<u32>, csr: utralib::CSR<u32>,
ticktimer: CID, ticktimer: CID,
@ -222,6 +223,14 @@ fn xmain() -> ! {
let shell_id = xous::SID::from_bytes(b"shell ").unwrap(); let shell_id = xous::SID::from_bytes(b"shell ").unwrap();
let shell_conn = xous::connect(shell_id).unwrap(); let shell_conn = xous::connect(shell_id).unwrap();
let agent_conn: usize;
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
}
// Create a new com object // Create a new com object
let mut com = XousCom::new(); let mut com = XousCom::new();
@ -250,6 +259,60 @@ fn xmain() -> ! {
Opcode::BattStatsNb => { Opcode::BattStatsNb => {
com.workqueue.push(WorkRequest { work: ComState::STAT, sender: shell_conn }).unwrap(); com.workqueue.push(WorkRequest { work: ComState::STAT, sender: shell_conn }).unwrap();
} }
Opcode::Wf200Rev => {
com.txrx(ComState::WFX_FW_REV_GET.verb);
let major = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u8;
let minor = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u8;
let build = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u8;
xous::return_scalar(
envelope.sender,
((major as usize) << 16) | ((minor as usize) << 8) | (build as usize)
)
.expect("COM: couldn't return WF200 firmware rev");
}
Opcode::EcGitRev => {
com.txrx(ComState::EC_GIT_REV.verb);
let rev_msb = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u8;
let rev_lsb = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u8;
let dirty = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u8;
xous::return_scalar2(
envelope.sender,
((rev_msb as usize) << 16) | (rev_lsb as usize),
dirty as usize
)
.expect("COM: couldn't return WF200 firmware rev");
}
Opcode::Wf200PdsLine(line) => {
let length = line.len() as u16;
com.txrx(ComState::WFX_PDS_LINE_SET.verb);
com.txrx(length);
for i in 0..(ComState::WFX_PDS_LINE_SET.w_words as usize - 1) {
let word: u16;
if (i * 2 + 1) == (length as usize - 1) { // 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);
} else {
word = 0;
}
com.txrx(word);
}
}
Opcode::RxStatsAgent => {
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") {
// 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);
}
}
_ => error!("unknown opcode"), _ => error!("unknown opcode"),
} }
} else { } else {

View file

@ -13,8 +13,8 @@ log = "0.4"
utralib = { path = "../../utralib"} utralib = { path = "../../utralib"}
[features] [features]
debugprint = [] debugprint = [] # adding this allocates the UART for debugging the logger
logging = [] logging = [] # adding this allocates the UART for logging of Xous
default = [] default = []
#default = ["logging"] #default = ["logging"]
#default = ["debugprint"] #default = ["debugprint"]

View file

@ -43,6 +43,7 @@ pub const DEFAULT: Uart = Uart {};
impl Uart { impl Uart {
fn map_uart(&self) { fn map_uart(&self) {
if cfg!(feature = "debugprint") {
/* /*
Note: the memory address and interrupt specified here needs to map to a unique hardware Note: the memory address and interrupt specified here needs to map to a unique hardware
UART resource. Modify in this function as necessary. UART resource. Modify in this function as necessary.
@ -62,8 +63,10 @@ impl Uart {
xous::claim_interrupt(utra::console::CONSOLE_IRQ, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ"); xous::claim_interrupt(utra::console::CONSOLE_IRQ, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
self.enable_rx(); self.enable_rx();
} }
}
pub fn putc(&self, c: u8) { pub fn putc(&self, c: u8) {
if cfg!(feature = "debugprint") {
if unsafe{DEFAULT_UART_ADDR} as usize == 0 { if unsafe{DEFAULT_UART_ADDR} as usize == 0 {
self.map_uart(); self.map_uart();
} }
@ -73,13 +76,17 @@ impl Uart {
while uart_csr.r(utra::uart::TXFULL) != 0 {} while uart_csr.r(utra::uart::TXFULL) != 0 {}
uart_csr.wo(utra::uart::RXTX, c as u32); uart_csr.wo(utra::uart::RXTX, c as u32);
} }
}
pub fn enable_rx(&self) { pub fn enable_rx(&self) {
if cfg!(feature = "debugprint") {
let mut uart_csr = CSR::new(unsafe{DEFAULT_UART_ADDR as *mut u32}); let mut uart_csr = CSR::new(unsafe{DEFAULT_UART_ADDR as *mut u32});
uart_csr.rmwf(utra::uart::EV_ENABLE_RX, 1 ); uart_csr.rmwf(utra::uart::EV_ENABLE_RX, 1 );
} }
}
pub fn getc(&self) -> Option<u8> { pub fn getc(&self) -> Option<u8> {
if cfg!(feature = "debugprint") {
if unsafe{DEFAULT_UART_ADDR} as usize == 0 { if unsafe{DEFAULT_UART_ADDR} as usize == 0 {
self.map_uart(); self.map_uart();
} }
@ -92,6 +99,9 @@ impl Uart {
c c
} }
} }
} else {
None
}
} }
} }

View file

@ -102,6 +102,7 @@ mod implementation {
pub struct Output {} pub struct Output {}
pub fn init() -> Output { pub fn init() -> Output {
if cfg!(feature = "logging") {
let uart = xous::syscall::map_memory( let uart = xous::syscall::map_memory(
xous::MemoryAddress::new(utra::console::HW_CONSOLE_BASE), xous::MemoryAddress::new(utra::console::HW_CONSOLE_BASE),
None, None,
@ -123,6 +124,7 @@ mod implementation {
) )
.expect("couldn't claim interrupt"); .expect("couldn't claim interrupt");
println!("Claimed IRQ {}", utra::console::CONSOLE_IRQ); println!("Claimed IRQ {}", utra::console::CONSOLE_IRQ);
}
Output {} Output {}
} }
@ -139,6 +141,7 @@ mod implementation {
} }
fn handle_irq(irq_no: usize, arg: *mut usize) { fn handle_irq(irq_no: usize, arg: *mut usize) {
if cfg!(feature = "logging") {
print!("Handling IRQ {} (arg: {:08x}): ", irq_no, arg as usize); print!("Handling IRQ {} (arg: {:08x}): ", irq_no, arg as usize);
while let Some(c) = crate::debug::DEFAULT.getc() { while let Some(c) = crate::debug::DEFAULT.getc() {
@ -146,11 +149,13 @@ mod implementation {
} }
println!(); println!();
} }
}
pub struct OutputWriter {} pub struct OutputWriter {}
impl OutputWriter { impl OutputWriter {
pub fn putc(&self, c: u8) { pub fn putc(&self, c: u8) {
if cfg!(feature = "logging") {
let mut uart_csr = CSR::new(unsafe { crate::debug::DEFAULT_UART_ADDR as *mut u32 }); let mut uart_csr = CSR::new(unsafe { crate::debug::DEFAULT_UART_ADDR as *mut u32 });
// Wait until TXFULL is `0` // Wait until TXFULL is `0`
@ -158,6 +163,7 @@ mod implementation {
uart_csr.wo(utra::uart::RXTX, c as u32); uart_csr.wo(utra::uart::RXTX, c as u32);
} }
} }
}
impl Write for OutputWriter { impl Write for OutputWriter {
fn write_str(&mut self, s: &str) -> Result<(), Error> { fn write_str(&mut self, s: &str) -> Result<(), Error> {

View file

@ -14,7 +14,6 @@ log-server = { path = "../log-server" }
log = "0.4" log = "0.4"
com = { path = "../com"} com = { path = "../com"}
com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "9a91a81f482ea8eba2f2de5d6c20b9bd399f39a9" }
# blitstr = { path = "../../../blitstr" } # blitstr = { path = "../../../blitstr" }
blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "69f7c04b9f44a20571c4792c8fc9166f5d6b548d" } blitstr = { git = "https://github.com/betrusted-io/blitstr.git", rev = "69f7c04b9f44a20571c4792c8fc9166f5d6b548d" }

View file

@ -265,7 +265,7 @@ fn shell_main() -> ! {
} }
// rate limit graphics // rate limit graphics
ticktimer_server::sleep_ms(ticktimer_conn, 1000).expect("couldn't sleep"); // ticktimer_server::sleep_ms(ticktimer_conn, 1000).expect("couldn't sleep");
// draw the ball // draw the ball
graphics_server::draw_rectangle( graphics_server::draw_rectangle(

View file

@ -18,4 +18,6 @@ utralib = { path = "../../utralib"}
[features] [features]
debugprint = [] debugprint = []
default = [] # "debugprint" disablewatchdog = []
# generally you want to disable watchdog if you're doing development.
default = ["disablewatchdog"] # "debugprint"

View file

@ -94,7 +94,11 @@ mod implementation {
connection, connection,
}; };
if cfg!(feature = "disablewatchdog") {
// do nothing
} else {
xtt.wdt.wfo(utra::wdt::WATCHDOG_ENABLE, 1); xtt.wdt.wfo(utra::wdt::WATCHDOG_ENABLE, 1);
}
xous::claim_interrupt( xous::claim_interrupt(
utra::ticktimer::TICKTIMER_IRQ, utra::ticktimer::TICKTIMER_IRQ,

View file

@ -8,3 +8,4 @@ then
fi fi
riscv64-unknown-elf-gdb -ex 'set riscv use-compressed-breakpoints off' -ex 'file kernel/target/riscv32imac-unknown-none-elf/release/kernel' -ex "tar rem $1:3333" riscv64-unknown-elf-gdb -ex 'set riscv use-compressed-breakpoints off' -ex 'file kernel/target/riscv32imac-unknown-none-elf/release/kernel' -ex "tar rem $1:3333"
#riscv64-unknown-elf-gdb -ex 'set riscv use-compressed-breakpoints off' -ex 'file target/riscv32imac-unknown-none-elf/release/fcc-agent' -ex "tar rem $1:3333"

View file

@ -76,7 +76,7 @@ fn build_hw_image(debug: bool, svd: Option<String>) -> Result<(), DynError> {
let kernel = build_kernel(debug)?; let kernel = build_kernel(debug)?;
let mut init = vec![]; let mut init = vec![];
for pkg in &["shell", "graphics-server", "ticktimer-server", "log-server", "com", "trng-tester"] { // "xous-names" for pkg in &["shell", "graphics-server", "ticktimer-server", "log-server", "com", "fcc-agent"] { // "xous-names", "trng-tester"
init.push(build(pkg, debug, Some(TARGET), None)?); init.push(build(pkg, debug, Some(TARGET), None)?);
} }
let loader = build("loader", debug, Some(TARGET), Some("loader".into()))?; let loader = build("loader", debug, Some(TARGET), Some("loader".into()))?;