mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
beginnings of a factory self-test routine; expand COM functionality
This commit is contained in:
parent
19c26cbbe9
commit
858a1ed019
4 changed files with 111 additions and 3 deletions
|
|
@ -73,6 +73,12 @@ pub(crate) enum Opcode {
|
||||||
/// Query Full charge capacity of the battery
|
/// Query Full charge capacity of the battery
|
||||||
//BattFullCapacity,
|
//BattFullCapacity,
|
||||||
|
|
||||||
|
/// More charger and gas gauge status, primarily for diagnostics
|
||||||
|
MoreStats,
|
||||||
|
|
||||||
|
/// Poll the USB CC chip
|
||||||
|
PollUsbCc,
|
||||||
|
|
||||||
/// Turn Boost Mode On
|
/// Turn Boost Mode On
|
||||||
BoostOn,
|
BoostOn,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,46 @@ impl Com {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_batt_stats_blocking(&mut self) -> Result<BattStats, xous::Error> {
|
||||||
|
let response = send_message(self.conn,
|
||||||
|
Message::new_blocking_scalar(Opcode::BattStats.to_usize().unwrap(), 0, 0, 0, 0))?;
|
||||||
|
if let xous::Result::Scalar2(rs0, rs1) = response {
|
||||||
|
let bs: BattStats = [rs0, rs1].into();
|
||||||
|
Ok(bs)
|
||||||
|
} else {
|
||||||
|
Err(xous::Error::InternalError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_more_stats(&mut self) -> Result<[u16; 15], xous::Error> {
|
||||||
|
let alloc_stats: [u16; 15] = [0; 15];
|
||||||
|
let mut buf = Buffer::into_buf(alloc_stats).or(Err(xous::Error::InternalError))?;
|
||||||
|
buf.lend_mut(self.conn, Opcode::MoreStats.to_u32().unwrap())?;
|
||||||
|
|
||||||
|
let stats: [u16; 15] = buf.to_original::<[u16; 15], _>().unwrap();
|
||||||
|
Ok(stats)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn poll_usb_cc(&mut self) -> Result<(bool, [u16; 3]), xous::Error> {
|
||||||
|
let response = send_message(self.conn,
|
||||||
|
Message::new_blocking_scalar(Opcode::PollUsbCc.to_usize().unwrap(), 0, 0, 0, 0))?;
|
||||||
|
if let xous::Result::Scalar2(val1, val2) = response {
|
||||||
|
let event = if (val1 >> 16) == 0 {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
};
|
||||||
|
let regs: [u16; 3] = [
|
||||||
|
(val1 & 0xFFFF) as u16,
|
||||||
|
(val2 & 0xFFFF) as u16,
|
||||||
|
((val2 >> 16) & 0xFFFF) as u16
|
||||||
|
];
|
||||||
|
Ok((event, regs))
|
||||||
|
} else {
|
||||||
|
Err(xous::Error::InternalError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn wifi_disable(&self) -> Result<(), xous::Error> {
|
pub fn wifi_disable(&self) -> Result<(), xous::Error> {
|
||||||
send_message(self.conn, Message::new_scalar(Opcode::Wf200Disable.to_usize().unwrap(), 0, 0, 0, 0,)).map(|_| ())
|
send_message(self.conn, Message::new_scalar(Opcode::Wf200Disable.to_usize().unwrap(), 0, 0, 0, 0,)).map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -189,6 +189,33 @@ mod implementation {
|
||||||
|
|
||||||
stats
|
stats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_more_stats(&mut self) -> [u16; 15] {
|
||||||
|
self.txrx(ComState::STAT.verb);
|
||||||
|
let ack = self.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT));
|
||||||
|
if ack != 0x8888 {
|
||||||
|
log::error!("didn't receive the expected ack header to the stats readout");
|
||||||
|
}
|
||||||
|
let mut ret: [u16; 15] = [0; 15];
|
||||||
|
for r in ret.iter_mut() {
|
||||||
|
*r = self.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT));
|
||||||
|
}
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn poll_usb_cc(&mut self) -> [u32; 2] {
|
||||||
|
self.txrx(ComState::POLL_USB_CC.verb);
|
||||||
|
let event = self.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT));
|
||||||
|
let mut ret: [u16; 3] = [0; 3];
|
||||||
|
for r in ret.iter_mut() {
|
||||||
|
*r = self.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT));
|
||||||
|
}
|
||||||
|
// pack into a format that can be returned as a scalar2
|
||||||
|
[
|
||||||
|
((event as u32) << 16) | ret[0] as u32,
|
||||||
|
ret[1] as u32 | ((ret[2] as u32) << 16)
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -262,6 +289,13 @@ mod implementation {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn get_more_stats(&mut self) -> [u16; 15] {
|
||||||
|
[0; 15]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn poll_usb_cc(&mut self) -> [u32; 2] {
|
||||||
|
[0; 2]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -467,13 +501,21 @@ fn xmain() -> ! {
|
||||||
).expect("coludn't return accelerometer read data");
|
).expect("coludn't return accelerometer read data");
|
||||||
}),
|
}),
|
||||||
Some(Opcode::BattStats) => {
|
Some(Opcode::BattStats) => {
|
||||||
info!("batt stats request received");
|
|
||||||
let stats = com.get_battstats();
|
let stats = com.get_battstats();
|
||||||
let raw_stats: [usize; 2] = stats.into();
|
let raw_stats: [usize; 2] = stats.into();
|
||||||
xous::return_scalar2(msg.sender, raw_stats[1], raw_stats[0])
|
xous::return_scalar2(msg.sender, raw_stats[0], raw_stats[1])
|
||||||
.expect("couldn't return batt stats request");
|
.expect("couldn't return batt stats request");
|
||||||
info!("done returning batt stats request");
|
|
||||||
}
|
}
|
||||||
|
Some(Opcode::MoreStats) => {
|
||||||
|
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||||
|
let stats = com.get_more_stats();
|
||||||
|
buffer.replace(stats).unwrap();
|
||||||
|
}
|
||||||
|
Some(Opcode::PollUsbCc) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||||
|
let usb_cc: [u32; 2] = com.poll_usb_cc();
|
||||||
|
xous::return_scalar2(msg.sender, usb_cc[0] as usize, usb_cc[1] as usize)
|
||||||
|
.expect("couldn't return Usb CC result");
|
||||||
|
}),
|
||||||
Some(Opcode::BattStatsNb) => {
|
Some(Opcode::BattStatsNb) => {
|
||||||
for &maybe_conn in battstats_conns.iter() {
|
for &maybe_conn in battstats_conns.iter() {
|
||||||
if let Some(conn) = maybe_conn {
|
if let Some(conn) = maybe_conn {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
|
const SENTINEL: &'static str = "|TSTR";
|
||||||
|
|
||||||
self.state += 1;
|
self.state += 1;
|
||||||
let mut ret = String::<1024>::new();
|
let mut ret = String::<1024>::new();
|
||||||
write!(ret, "Test has run {} times.\n", self.state).unwrap();
|
write!(ret, "Test has run {} times.\n", self.state).unwrap();
|
||||||
|
|
@ -27,6 +29,24 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
|
|
||||||
if let Some(sub_cmd) = tokens.next() {
|
if let Some(sub_cmd) = tokens.next() {
|
||||||
match sub_cmd {
|
match sub_cmd {
|
||||||
|
"factory" => {
|
||||||
|
// set uart MUX, and turn off WFI so UART reports are "clean" (no stuck characters when CPU is in WFI)
|
||||||
|
env.llio.set_uart_mux(llio::UartType::Log).unwrap();
|
||||||
|
env.llio.wfi_override(true).unwrap();
|
||||||
|
let (x, y, z, id) = env.com.gyro_read_blocking().unwrap();
|
||||||
|
log::info!("{}|GYRO|{}|{}|{}|{}", SENTINEL, x, y, z, id);
|
||||||
|
let (wf_maj, wf_min, wf_rev) = env.com.get_wf200_fw_rev().unwrap();
|
||||||
|
log::info!("{}|WF200REV|{}|{}|{}", SENTINEL, wf_maj, wf_min, wf_rev);
|
||||||
|
let (ec_rev, ec_dirty) = env.com.get_ec_git_rev().unwrap();
|
||||||
|
log::info!("{}|ECREV|{:x}|{:?}", SENTINEL, ec_rev, ec_dirty);
|
||||||
|
let morestats = env.com.get_more_stats().unwrap();
|
||||||
|
log::info!("{}|BATTSTATS|{:?}", SENTINEL, morestats);
|
||||||
|
let (usbcc_event, usbcc_regs) = env.com.poll_usb_cc().unwrap();
|
||||||
|
log::info!("{}|USBCC|{:?}|{:?}", SENTINEL, usbcc_event, usbcc_regs);
|
||||||
|
|
||||||
|
write!(ret, "Factory test script has run, check serial terminal for output").unwrap();
|
||||||
|
env.llio.wfi_override(false).unwrap();
|
||||||
|
}
|
||||||
"devboot" => {
|
"devboot" => {
|
||||||
env.gam.set_devboot(true).unwrap();
|
env.gam.set_devboot(true).unwrap();
|
||||||
write!(ret, "devboot on").unwrap();
|
write!(ret, "devboot on").unwrap();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue