mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
refactor of COM
this was much harder than I liked.
This commit is contained in:
parent
5a6ce66d7e
commit
d21c0fa3e7
7 changed files with 251 additions and 228 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -241,6 +241,8 @@ dependencies = [
|
|||
"heapless",
|
||||
"log",
|
||||
"log-server",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"rkyv 0.4.3",
|
||||
"ticktimer-server",
|
||||
"typenum",
|
||||
|
|
|
|||
|
|
@ -9,17 +9,15 @@ version = "0.1.0"
|
|||
com_rs-ref = {path = "../../imports/com_rs-ref"}
|
||||
heapless = "0.5"
|
||||
log = "0.4"
|
||||
num-derive = {version = "0.3", default-features = false}
|
||||
num-traits = {version = "0.2", default-features = false}
|
||||
log-server = {path = "../log-server"}
|
||||
ticktimer-server = {path = "../ticktimer-server"}
|
||||
typenum = "1.12"
|
||||
xous = {path = "../../xous-rs"}
|
||||
xous-ipc = {path = "../../xous-ipc"}
|
||||
xous-names = {path = "../xous-names"}
|
||||
|
||||
[dependencies.rkyv]
|
||||
default-features = false
|
||||
features = ["const_generics"]
|
||||
version = "0.4.1"
|
||||
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
|
||||
|
||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||
utralib = {path = "../../utralib"}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ use xous_ipc::String;
|
|||
use com_rs::*;
|
||||
use com_rs_ref as com_rs;
|
||||
|
||||
pub(crate) const SERVER_NAME_COM: &str = "_COM manager_";
|
||||
|
||||
#[derive(Debug, Default, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
pub struct BattStats {
|
||||
/// instantaneous voltage in mV
|
||||
|
|
@ -40,55 +42,52 @@ impl Into<[usize; 2]> for BattStats {
|
|||
}
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
pub enum Opcode {
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
pub(crate) enum Opcode {
|
||||
/// Battery stats
|
||||
BattStats,
|
||||
|
||||
/// Battery stats, non-blocking
|
||||
BattStatsNb,
|
||||
|
||||
/// Battery stats return
|
||||
BattStatsEvent(BattStats),
|
||||
|
||||
/// Query Full charge capacity of the battery
|
||||
BattFullCapacity,
|
||||
//BattFullCapacity,
|
||||
|
||||
/// Turn Boost Mode On
|
||||
BoostOn,
|
||||
//BoostOn,
|
||||
|
||||
/// Turn Boost Mode Off
|
||||
BoostOff,
|
||||
//BoostOff,
|
||||
|
||||
/// Read the current accelerations off the IMU
|
||||
ImuAccelRead,
|
||||
//ImuAccelRead,
|
||||
|
||||
/// Power off the SoC
|
||||
PowerOffSoc,
|
||||
|
||||
/// Ship mode (battery disconnect)
|
||||
ShipMode,
|
||||
//ShipMode,
|
||||
|
||||
/// Is the battery charging?
|
||||
IsCharging,
|
||||
//IsCharging,
|
||||
|
||||
/// Set the backlight brightness
|
||||
SetBackLight,
|
||||
//SetBackLight,
|
||||
|
||||
/// Request charging
|
||||
RequestCharging,
|
||||
//RequestCharging,
|
||||
|
||||
/// Erase a region of EC FLASH
|
||||
FlashErase,
|
||||
//FlashErase,
|
||||
|
||||
/// Program a page of FLASH
|
||||
//FlashProgram(&'a [u8]),
|
||||
|
||||
/// Update the SSID list
|
||||
SsidScan,
|
||||
//SsidScan,
|
||||
|
||||
/// Return the latest SSID list
|
||||
SsidFetch,
|
||||
//SsidFetch,
|
||||
|
||||
/// Fetch the git ID of the EC
|
||||
EcGitRev,
|
||||
|
|
@ -97,15 +96,20 @@ pub enum Opcode {
|
|||
Wf200Rev,
|
||||
|
||||
/// Send a line of PDS data
|
||||
Wf200PdsLine(String<512>),
|
||||
|
||||
/// Send Rx stats to fcc-agent
|
||||
RxStatsAgent,
|
||||
Wf200PdsLine, //String<512>
|
||||
|
||||
/// request for a listener to BattStats events
|
||||
RegisterBattStatsListener(String<64>),
|
||||
RegisterBattStatsListener, //String<64>
|
||||
}
|
||||
|
||||
/// These enums indicate what kind of callback type we're sending.
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
pub(crate) enum CallbackType {
|
||||
/// Battery status
|
||||
BattStats,
|
||||
}
|
||||
|
||||
/*
|
||||
impl core::convert::TryFrom<&Message> for Opcode {
|
||||
type Error = &'static str;
|
||||
fn try_from(message: &Message) -> Result<Self, Self::Error> {
|
||||
|
|
@ -144,7 +148,7 @@ impl core::convert::TryFrom<&Message> for Opcode {
|
|||
}
|
||||
}
|
||||
_ => Err("unhandled message type"),
|
||||
}
|
||||
}let registration_name = buffer.as_flat::<
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -236,3 +240,4 @@ impl Into<Message> for Opcode {
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
@ -7,85 +7,124 @@ use core::convert::TryInto;
|
|||
pub mod api;
|
||||
|
||||
use api::BattStats;
|
||||
use xous::{send_message, Error, CID};
|
||||
use xous_ipc::String;
|
||||
use api::Opcode;
|
||||
use xous::{send_message, Error, CID, Message};
|
||||
use xous_ipc::{String, Buffer};
|
||||
use num_traits::{ToPrimitive, FromPrimitive};
|
||||
|
||||
pub fn power_off_soc(cid: CID) -> Result<(), xous::Error> {
|
||||
send_message(cid, api::Opcode::PowerOffSoc.into()).map(|_| ())
|
||||
}
|
||||
/// mapping of the callback function to the library user
|
||||
/// this exists in the library user's memory space, so we can have up to one
|
||||
/// callback per library user.
|
||||
static mut BATTSTATS_CB: Option<fn(BattStats)> = None;
|
||||
|
||||
pub fn get_batt_stats(cid: CID) -> Result<BattStats, xous::Error> {
|
||||
let response = send_message(cid, api::Opcode::BattStats.into())?;
|
||||
if let xous::Result::Scalar2(upper, lower) = response {
|
||||
let raw_stats: [usize; 2] = [lower, upper];
|
||||
Ok(raw_stats.into())
|
||||
} else {
|
||||
panic!("unexpected return value: {:#?}", response);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_batt_stats_nb(cid: CID) -> Result<(), xous::Error> {
|
||||
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;
|
||||
/// handles callback messages from the COM server, in the library user's process space.
|
||||
fn battstats_server(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
||||
let sid = xous::SID::from_u32(sid0 as u32, sid1 as u32, sid2 as u32, sid3 as u32);
|
||||
loop {
|
||||
let msg = xous::receive_message(sid).unwrap();
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(api::CallbackType::BattStats) => {
|
||||
if let xous::Message::Scalar(xous::ScalarMessage {
|
||||
id: _, arg1: lo, arg2: hi, arg3: _, arg4: _
|
||||
}) = msg.body {
|
||||
let bs: BattStats = [lo, hi].into();
|
||||
unsafe {
|
||||
if let Some(cb) = BATTSTATS_CB {
|
||||
cb(bs)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
Ok((rev as u32, dirtybool))
|
||||
} else {
|
||||
panic!("unexpected return value: {:#?}", response);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_pds_line(cid: CID, s: &String<512>) -> Result<(), Error> {
|
||||
use core::fmt::Write;
|
||||
let mut clone_s: String<512> = 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::ser::serializers::BufferSerializer::new(xous::XousBuffer::new(4096));
|
||||
let pos = {
|
||||
use rkyv::ser::Serializer;
|
||||
writer.serialize_value(&request).expect("COM: couldn't archive PDS line request")
|
||||
};
|
||||
let xous_buffer = writer.into_inner();
|
||||
|
||||
xous_buffer.lend(cid, pos as u32).expect("COM: PDS line request failure");
|
||||
Ok(())
|
||||
pub struct Com {
|
||||
conn: CID,
|
||||
battstats_sid: Option<xous::SID>,
|
||||
}
|
||||
impl Com {
|
||||
pub fn new(xns: xous_names::XousNames) -> Result<Self, xous::Error> {
|
||||
let conn = xns.request_connection_blocking(api::SERVER_NAME_COM).expect("Can't connect to TRNG server");
|
||||
Ok(Com {
|
||||
conn,
|
||||
battstats_sid: None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_rx_stats_agent(cid: CID) -> Result<(), Error> {
|
||||
send_message(cid, api::Opcode::RxStatsAgent.into()).map(|_| ())
|
||||
pub fn power_off_soc(&self) -> Result<(), xous::Error> {
|
||||
send_message(self.conn,
|
||||
Message::new_scalar(Opcode::PowerOffSoc.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).map(|_| ())
|
||||
}
|
||||
|
||||
pub fn hook_batt_stats(&mut self, cb: fn(BattStats)) -> Result<(), xous::Error> {
|
||||
if unsafe{BATTSTATS_CB}.is_some() {
|
||||
return Err(xous::Error::MemoryInUse)
|
||||
}
|
||||
unsafe{BATTSTATS_CB = Some(cb)};
|
||||
if self.battstats_sid.is_none() {
|
||||
let sid = xous::create_server().unwrap();
|
||||
self.battstats_sid = Some(sid);
|
||||
let sid_tuple = sid.to_u32();
|
||||
xous::create_thread_4(battstats_server, sid_tuple.0 as usize, sid_tuple.1 as usize, sid_tuple.2 as usize, sid_tuple.3 as usize).unwrap();
|
||||
xous::send_message(self.conn,
|
||||
Message::new_scalar(Opcode::RegisterBattStatsListener.to_usize().unwrap(),
|
||||
sid_tuple.0 as usize, sid_tuple.1 as usize, sid_tuple.2 as usize, sid_tuple.3 as usize
|
||||
)).unwrap();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_batt_stats_nb(&self) -> Result<(), xous::Error> {
|
||||
send_message(self.conn, Message::new_scalar(Opcode::BattStatsNb.to_usize().unwrap(), 0, 0, 0, 0,)).map(|_| ())
|
||||
}
|
||||
|
||||
pub fn get_wf200_fw_rev(&self) -> Result<(u8, u8, u8), xous::Error> {
|
||||
let response = send_message(self.conn,
|
||||
Message::new_blocking_scalar(Opcode::Wf200Rev.to_usize().unwrap(), 0, 0, 0, 0))?;
|
||||
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(&self) -> Result<(u32, bool), Error> {
|
||||
let response = send_message(self.conn,
|
||||
Message::new_blocking_scalar(Opcode::EcGitRev.to_usize().unwrap(), 0, 0, 0, 0))?;
|
||||
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(&self, s: &String<512>) -> Result<(), Error> {
|
||||
use core::fmt::Write;
|
||||
let mut clone_s: String<512> = String::new();
|
||||
write!(clone_s, "{}", s.as_str().unwrap()).map_err(|_| xous::Error::AccessDenied)?;
|
||||
|
||||
let buf = Buffer::into_buf(clone_s).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend(
|
||||
self.conn,
|
||||
Opcode::Wf200PdsLine.to_u32().unwrap()
|
||||
).map(|_| ())
|
||||
}
|
||||
|
||||
// event relay request API
|
||||
pub fn request_battstat_events(&self, name: &str) -> Result<xous::Result, xous::Error> {
|
||||
let s = String::<64>::from_str(name);
|
||||
let buf = Buffer::into_buf(s).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend(self.conn, Opcode::RegisterBattStatsListener.to_u32().unwrap())
|
||||
}
|
||||
|
||||
// note to future self: add other event listener registrations (such as network events) here
|
||||
}
|
||||
|
||||
|
||||
// event relay request API
|
||||
pub fn request_battstat_events(name: &str, com_conn: xous::CID) -> Result<xous::Result, xous::Error> {
|
||||
let s = String::<64>::from_str(name);
|
||||
let request = api::Opcode::RegisterBattStatsListener(s);
|
||||
let mut writer = rkyv::ser::serializers::BufferSerializer::new(xous::XousBuffer::new(4096));
|
||||
let pos = {
|
||||
use rkyv::ser::Serializer;
|
||||
writer.serialize_value(&request).expect("COM: couldn't archive battstat request")
|
||||
};
|
||||
let xous_buffer = writer.into_inner();
|
||||
|
||||
xous_buffer
|
||||
.lend(com_conn, pos.try_into().unwrap())
|
||||
}
|
||||
|
||||
// note to future self: add other event listener registrations (such as network events) here
|
||||
|
|
|
|||
|
|
@ -5,13 +5,15 @@ mod api;
|
|||
use api::Opcode;
|
||||
|
||||
use core::convert::TryFrom;
|
||||
use num_traits::{ToPrimitive, FromPrimitive};
|
||||
|
||||
use log::{error, info};
|
||||
use log::{error, info, trace};
|
||||
|
||||
use com_rs_ref as com_rs;
|
||||
use com_rs::*;
|
||||
|
||||
use xous::CID;
|
||||
use xous_ipc::{Buffer, String};
|
||||
|
||||
const STD_TIMEOUT: u32 = 100;
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
|
|
@ -21,7 +23,11 @@ pub struct WorkRequest {
|
|||
}
|
||||
|
||||
fn return_battstats(cid: CID, stats: api::BattStats) -> Result<(), xous::Error> {
|
||||
xous::send_message(cid, crate::api::Opcode::BattStatsEvent(stats).into()).map(|_| ())
|
||||
let rawstats: [usize; 2] = stats.into();
|
||||
xous::send_message(cid,
|
||||
xous::Message::new_scalar(api::CallbackType::BattStats.to_usize().unwrap(),
|
||||
rawstats[0], rawstats[1], 0, 0)
|
||||
).map(|_| ())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "none")]
|
||||
|
|
@ -36,18 +42,13 @@ mod implementation {
|
|||
use xous::CID;
|
||||
|
||||
use heapless::Vec;
|
||||
use heapless::consts::*;
|
||||
use heapless::consts::U64;
|
||||
|
||||
/*
|
||||
use typenum::{UInt, UTerm};
|
||||
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>;
|
||||
*/
|
||||
const STD_TIMEOUT: u32 = 100;
|
||||
|
||||
pub struct XousCom {
|
||||
csr: utralib::CSR<u32>,
|
||||
ticktimer: CID,
|
||||
ticktimer: ticktimer_server::Ticktimer,
|
||||
pub workqueue: Vec<WorkRequest, U64>,
|
||||
busy: bool,
|
||||
}
|
||||
|
|
@ -73,7 +74,7 @@ mod implementation {
|
|||
|
||||
let mut xc = XousCom {
|
||||
csr: CSR::new(csr.as_mut_ptr() as *mut u32),
|
||||
ticktimer: ticktimer_conn,
|
||||
ticktimer,
|
||||
workqueue: Vec::new(),
|
||||
busy: false,
|
||||
//tx_queue: Vec::new(),
|
||||
|
|
@ -231,90 +232,88 @@ mod implementation {
|
|||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
use crate::implementation::XousCom;
|
||||
use heapless::Vec;
|
||||
use heapless::consts::*;
|
||||
use core::pin::Pin;
|
||||
use xous::buffer;
|
||||
use rkyv::archived_value_mut;
|
||||
|
||||
log_server::init_wait().unwrap();
|
||||
info!("COM: my PID is {}", xous::process::id());
|
||||
info!("my PID is {}", xous::process::id());
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let com_sid = xns.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") {
|
||||
xns.request_connection_blocking(xous::names::SERVER_NAME_FCCAGENT).expect("FCCAGENT: can't connect to COM")
|
||||
} else {
|
||||
0 // bogus value
|
||||
}; */
|
||||
let com_sid = xns.register_name(api::SERVER_NAME_COM).expect("can't register server");
|
||||
info!("registered with NS -- {:?}", com_sid);
|
||||
|
||||
// Create a new com object
|
||||
let mut com = XousCom::new();
|
||||
|
||||
// create a Vec to track return connections for battery stats
|
||||
let mut battstats_conns: Vec<xous::CID, U64> = Vec::new();
|
||||
// create an array to track return connections for battery stats
|
||||
let mut battstats_conns: [Option<xous::CID>; 32] = [None; 32];
|
||||
// other future notification vectors shall go here
|
||||
|
||||
info!("COM: starting main loop");
|
||||
info!("starting main loop");
|
||||
loop {
|
||||
let envelope = xous::receive_message(com_sid).unwrap();
|
||||
// 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 {
|
||||
archived_value_mut::<api::Opcode>(Pin::new(buf.as_mut()), m.id as usize)
|
||||
};
|
||||
match &*value {
|
||||
rkyv::Archived::<api::Opcode>::RegisterBattStatsListener(registration_name) => {
|
||||
let cid = xns.request_connection_blocking(registration_name.as_str()).expect("COM: can't connect to requested listener for reporting events");
|
||||
battstats_conns.push(cid).expect("COM: probably ran out of slots for battstats event reporting");
|
||||
},
|
||||
rkyv::Archived::<api::Opcode>::Wf200PdsLine(rkyv_l) => {
|
||||
let l = xous::String::<512>::from_str(rkyv_l.as_str());
|
||||
info!("COM: Wf200PdsLine got line {}", l);
|
||||
let line = l.as_bytes();
|
||||
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);
|
||||
com.txrx(length);
|
||||
//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 { // 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;
|
||||
let msg = xous::receive_message(com_sid).unwrap();
|
||||
trace!("Message: {:?}", msg);
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(Opcode::RegisterBattStatsListener) => {
|
||||
if let xous::Message::Scalar(xous::ScalarMessage {
|
||||
id: _id, arg1: sid0, arg2: sid1, arg3: sid2, arg4: sid3
|
||||
}) = msg.body {
|
||||
let sid = xous::SID::from_u32(sid0 as _, sid1 as _, sid2 as _, sid3 as _);
|
||||
let cid = Some(xous::connect(sid).unwrap());
|
||||
let mut found = false;
|
||||
for entry in battstats_conns.iter_mut() {
|
||||
if *entry == None {
|
||||
*entry = cid;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
com.txrx(word);
|
||||
//info!("COM: 0x{:04x}", word);
|
||||
}
|
||||
if !found {
|
||||
error!("RegisterBattStatsListener ran out of space registering callback");
|
||||
}
|
||||
}
|
||||
_ => panic!("Invalid memory message response -- corruption occurred"),
|
||||
};
|
||||
} else if let Ok(opcode) = Opcode::try_from(&envelope.body) {
|
||||
// info!("COM: Opcode: {:?}", opcode);
|
||||
match opcode {
|
||||
Opcode::PowerOffSoc => {
|
||||
info!("COM: power off called");
|
||||
com.txrx(ComState::POWER_OFF.verb);
|
||||
com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); // consume the obligatory return value, even if not used
|
||||
}
|
||||
Some(Opcode::Wf200PdsLine) => {
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let l = buffer.to_original::<String::<512>, _>().unwrap();
|
||||
info!("Wf200PdsLine got line {}", l);
|
||||
let line = l.as_bytes();
|
||||
let length = (l.len() + 0) as u16;
|
||||
//info!("0x{:04x}", ComState::WFX_PDS_LINE_SET.verb);
|
||||
com.txrx(ComState::WFX_PDS_LINE_SET.verb);
|
||||
//info!("0x{:04x}", length);
|
||||
com.txrx(length);
|
||||
//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 { // 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);
|
||||
//info!("0x{:04x}", word);
|
||||
}
|
||||
Opcode::BattStats => {
|
||||
info!("COM: batt stats request received");
|
||||
let stats = com.get_battstats();
|
||||
let raw_stats: [usize; 2] = stats.into();
|
||||
xous::return_scalar2(envelope.sender, raw_stats[1], raw_stats[0])
|
||||
.expect("COM: couldn't return batt stats request");
|
||||
info!("COM: done returning batt stats request");
|
||||
}
|
||||
Opcode::BattStatsNb => {
|
||||
for &conn in battstats_conns.iter() {
|
||||
}
|
||||
Some(Opcode::PowerOffSoc) => {
|
||||
info!("power off called");
|
||||
com.txrx(ComState::POWER_OFF.verb);
|
||||
com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); // consume the obligatory return value, even if not used
|
||||
}
|
||||
Some(Opcode::BattStats) => {
|
||||
info!("batt stats request received");
|
||||
let stats = com.get_battstats();
|
||||
let raw_stats: [usize; 2] = stats.into();
|
||||
xous::return_scalar2(msg.sender, raw_stats[1], raw_stats[0])
|
||||
.expect("couldn't return batt stats request");
|
||||
info!("done returning batt stats request");
|
||||
}
|
||||
Some(Opcode::BattStatsNb) => {
|
||||
for &maybe_conn in battstats_conns.iter() {
|
||||
if let Some(conn) = maybe_conn {
|
||||
com.workqueue
|
||||
.push(WorkRequest {
|
||||
work: ComState::STAT,
|
||||
|
|
@ -323,50 +322,31 @@ fn xmain() -> ! {
|
|||
.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 u16;
|
||||
let rev_lsb = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u16;
|
||||
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");
|
||||
}
|
||||
/* // 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.
|
||||
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;
|
||||
}
|
||||
// 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).expect("Can't send RxStat message to FCC agent!");
|
||||
}
|
||||
}*/
|
||||
_ => error!("unknown opcode"),
|
||||
}
|
||||
} else {
|
||||
error!("couldn't convert opcode");
|
||||
Some(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(
|
||||
msg.sender,
|
||||
((major as usize) << 16) | ((minor as usize) << 8) | (build as usize)
|
||||
)
|
||||
.expect("couldn't return WF200 firmware rev");
|
||||
}
|
||||
Some(Opcode::EcGitRev) => {
|
||||
com.txrx(ComState::EC_GIT_REV.verb);
|
||||
let rev_msb = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u16;
|
||||
let rev_lsb = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u16;
|
||||
let dirty = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)) as u8;
|
||||
xous::return_scalar2(
|
||||
msg.sender,
|
||||
((rev_msb as usize) << 16) | (rev_lsb as usize),
|
||||
dirty as usize
|
||||
)
|
||||
.expect("couldn't return WF200 firmware rev");
|
||||
}
|
||||
None => error!("unknown opcode"),
|
||||
}
|
||||
|
||||
com.process_queue();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ A list of descriptions of servers ("names") that are used as keys by the xous-na
|
|||
for the core set of kernel services.
|
||||
*/
|
||||
|
||||
pub const SERVER_NAME_COM: &str = "_COM manager_";
|
||||
pub const SERVER_NAME_LLIO: &str = "_Low Level I/O manager_";
|
||||
pub const SERVER_NAME_SHELL: &str = "_Shell_";
|
||||
pub const SERVER_NAME_GFX: &str = "_Graphics_";
|
||||
|
|
|
|||
|
|
@ -37,20 +37,20 @@ fn main() {
|
|||
|
||||
fn try_main() -> Result<(), DynError> {
|
||||
let hw_pkgs = [
|
||||
"gam",
|
||||
//"shell",
|
||||
"shellchat",
|
||||
"ime-frontend",
|
||||
"ime-plugin-shell",
|
||||
"graphics-server",
|
||||
//"gam",
|
||||
//"shellchat",
|
||||
//"ime-frontend",
|
||||
//"ime-plugin-shell",
|
||||
//"graphics-server",
|
||||
"ticktimer-server",
|
||||
"log-server",
|
||||
"com",
|
||||
"xous-names",
|
||||
"keyboard",
|
||||
//"keyboard",
|
||||
"trng",
|
||||
"llio",
|
||||
//"kernel-test",
|
||||
"rkyv-test-client",
|
||||
"rkyv-test-server",
|
||||
];
|
||||
let fcc_pkgs = [
|
||||
"shell",
|
||||
|
|
|
|||
Loading…
Reference in a new issue