mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
cleanup local echo during BIO loading - makes it a bit more reliable
This commit is contained in:
parent
dc7ac598dc
commit
6e28127cae
7 changed files with 64 additions and 28 deletions
|
|
@ -48,6 +48,7 @@ board-dabao = [
|
||||||
bio-math-test = ["bio-lib/c-math-test"]
|
bio-math-test = ["bio-lib/c-math-test"]
|
||||||
bio-wheel-test = ["bio-lib/c-colorwheel"]
|
bio-wheel-test = ["bio-lib/c-colorwheel"]
|
||||||
ctap-bringup = []
|
ctap-bringup = []
|
||||||
usb = []
|
extra-cmds = []
|
||||||
aestests = ["aes"]
|
aestests = ["aes"]
|
||||||
default = ["usb", "bio-math-test", "bio-wheel-test"]
|
|
||||||
|
default = []
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
use std::collections::HashMap;
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
sync::{Arc, atomic::AtomicBool},
|
||||||
|
};
|
||||||
|
|
||||||
use String;
|
use String;
|
||||||
use bao1x_hal_service::trng;
|
use bao1x_hal_service::trng;
|
||||||
|
|
@ -41,6 +44,7 @@ pub struct CommonEnv {
|
||||||
trng: trng::Trng,
|
trng: trng::Trng,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
xns: xous_names::XousNames,
|
xns: xous_names::XousNames,
|
||||||
|
echo: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
impl CommonEnv {
|
impl CommonEnv {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
@ -78,11 +82,13 @@ mod ver;
|
||||||
use ver::*;
|
use ver::*;
|
||||||
mod test;
|
mod test;
|
||||||
use test::*;
|
use test::*;
|
||||||
|
#[cfg(feature = "extra-cmds")]
|
||||||
mod trng_cmd;
|
mod trng_cmd;
|
||||||
|
#[cfg(feature = "extra-cmds")]
|
||||||
use trng_cmd::*;
|
use trng_cmd::*;
|
||||||
#[cfg(feature = "usb")]
|
#[cfg(feature = "extra-cmds")]
|
||||||
mod usb;
|
mod usb;
|
||||||
#[cfg(feature = "usb")]
|
#[cfg(feature = "extra-cmds")]
|
||||||
use usb::*;
|
use usb::*;
|
||||||
#[cfg(feature = "aestests")]
|
#[cfg(feature = "aestests")]
|
||||||
mod aes_cmd;
|
mod aes_cmd;
|
||||||
|
|
@ -101,8 +107,9 @@ pub struct CmdEnv {
|
||||||
common_env: CommonEnv,
|
common_env: CommonEnv,
|
||||||
lastverb: String,
|
lastverb: String,
|
||||||
///// 2. declare storage for your command here.
|
///// 2. declare storage for your command here.
|
||||||
|
#[cfg(feature = "extra-cmds")]
|
||||||
trng_cmd: TrngCmd,
|
trng_cmd: TrngCmd,
|
||||||
#[cfg(feature = "usb")]
|
#[cfg(feature = "extra-cmds")]
|
||||||
usb: Usb,
|
usb: Usb,
|
||||||
#[cfg(feature = "aestests")]
|
#[cfg(feature = "aestests")]
|
||||||
aes_cmd: Aes,
|
aes_cmd: Aes,
|
||||||
|
|
@ -111,7 +118,7 @@ pub struct CmdEnv {
|
||||||
bio: BioLoader,
|
bio: BioLoader,
|
||||||
}
|
}
|
||||||
impl CmdEnv {
|
impl CmdEnv {
|
||||||
pub fn new(xns: &xous_names::XousNames) -> CmdEnv {
|
pub fn new(xns: &xous_names::XousNames, echo: Arc<AtomicBool>) -> CmdEnv {
|
||||||
let ticktimer = ticktimer::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
let ticktimer = ticktimer::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||||
// _ prefix allows us to leave the `mut` here without creating a warning.
|
// _ prefix allows us to leave the `mut` here without creating a warning.
|
||||||
// the `mut` option is needed for some features.
|
// the `mut` option is needed for some features.
|
||||||
|
|
@ -120,6 +127,7 @@ impl CmdEnv {
|
||||||
cb_registrations: HashMap::new(),
|
cb_registrations: HashMap::new(),
|
||||||
trng: trng::Trng::new(&xns).unwrap(),
|
trng: trng::Trng::new(&xns).unwrap(),
|
||||||
xns: xous_names::XousNames::new().unwrap(),
|
xns: xous_names::XousNames::new().unwrap(),
|
||||||
|
echo,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "aestests")]
|
#[cfg(feature = "aestests")]
|
||||||
let aes_cmd = Aes::new(&xns, &mut _common);
|
let aes_cmd = Aes::new(&xns, &mut _common);
|
||||||
|
|
@ -127,11 +135,12 @@ impl CmdEnv {
|
||||||
common_env: _common,
|
common_env: _common,
|
||||||
lastverb: String::new(),
|
lastverb: String::new(),
|
||||||
///// 3. initialize your storage, by calling new()
|
///// 3. initialize your storage, by calling new()
|
||||||
|
#[cfg(feature = "extra-cmds")]
|
||||||
trng_cmd: {
|
trng_cmd: {
|
||||||
log::debug!("trng");
|
log::debug!("trng");
|
||||||
TrngCmd::new()
|
TrngCmd::new()
|
||||||
},
|
},
|
||||||
#[cfg(feature = "usb")]
|
#[cfg(feature = "extra-cmds")]
|
||||||
usb: Usb::new(),
|
usb: Usb::new(),
|
||||||
#[cfg(feature = "aestests")]
|
#[cfg(feature = "aestests")]
|
||||||
aes_cmd,
|
aes_cmd,
|
||||||
|
|
@ -157,10 +166,11 @@ impl CmdEnv {
|
||||||
///// 4. add your command to this array, so that it can be looked up and dispatched
|
///// 4. add your command to this array, so that it can be looked up and dispatched
|
||||||
&mut echo_cmd,
|
&mut echo_cmd,
|
||||||
&mut ver_cmd,
|
&mut ver_cmd,
|
||||||
|
#[cfg(feature = "extra-cmds")]
|
||||||
&mut self.trng_cmd,
|
&mut self.trng_cmd,
|
||||||
&mut i2cdetect_cmd,
|
&mut i2cdetect_cmd,
|
||||||
&mut console_cmd,
|
&mut console_cmd,
|
||||||
#[cfg(feature = "usb")]
|
#[cfg(feature = "extra-cmds")]
|
||||||
&mut self.usb,
|
&mut self.usb,
|
||||||
#[cfg(feature = "aestests")]
|
#[cfg(feature = "aestests")]
|
||||||
&mut self.aes_cmd,
|
&mut self.aes_cmd,
|
||||||
|
|
|
||||||
|
|
@ -322,15 +322,29 @@ impl Drop for BioLoader {
|
||||||
impl<'a> ShellCmdApi<'a> for BioLoader {
|
impl<'a> ShellCmdApi<'a> for BioLoader {
|
||||||
cmd_api!(bio);
|
cmd_api!(bio);
|
||||||
|
|
||||||
fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
|
fn process(&mut self, args: String, env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
|
|
||||||
if args == "ready" {
|
if args == "ready" {
|
||||||
|
env.echo.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||||
|
write!(ret, "OK").unwrap();
|
||||||
|
return Ok(Some(ret));
|
||||||
|
}
|
||||||
|
|
||||||
|
if args == "echo_on" {
|
||||||
|
env.echo.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||||
|
write!(ret, "OK").unwrap();
|
||||||
|
return Ok(Some(ret));
|
||||||
|
}
|
||||||
|
|
||||||
|
if args == "echo_off" {
|
||||||
|
env.echo.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||||
write!(ret, "OK").unwrap();
|
write!(ret, "OK").unwrap();
|
||||||
return Ok(Some(ret));
|
return Ok(Some(ret));
|
||||||
}
|
}
|
||||||
|
|
||||||
if args == "clear" {
|
if args == "clear" {
|
||||||
|
env.echo.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||||
self.clear();
|
self.clear();
|
||||||
self.store.write_app_key(APP_BIO_PINS_INDEX, &[0u8; 32]).ok();
|
self.store.write_app_key(APP_BIO_PINS_INDEX, &[0u8; 32]).ok();
|
||||||
self.store.write_app_key(APP_BIO_CLK_INDEX, &[0u8; 32]).ok();
|
self.store.write_app_key(APP_BIO_CLK_INDEX, &[0u8; 32]).ok();
|
||||||
|
|
@ -400,6 +414,7 @@ impl<'a> ShellCmdApi<'a> for BioLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.starts_with("reload") {
|
if args.starts_with("reload") {
|
||||||
|
env.echo.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||||
match self.reload() {
|
match self.reload() {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
write!(ret, "BIO load successful").unwrap();
|
write!(ret, "BIO load successful").unwrap();
|
||||||
|
|
@ -413,6 +428,7 @@ impl<'a> ShellCmdApi<'a> for BioLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.starts_with("rx") {
|
if args.starts_with("rx") {
|
||||||
|
env.echo.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||||
self.bio_ss.debug(self.resource_grant.cores[0]);
|
self.bio_ss.debug(self.resource_grant.cores[0]);
|
||||||
let arg_list: Vec<&str> = args.split_whitespace().collect();
|
let arg_list: Vec<&str> = args.split_whitespace().collect();
|
||||||
let iters =
|
let iters =
|
||||||
|
|
@ -439,6 +455,7 @@ impl<'a> ShellCmdApi<'a> for BioLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.starts_with("tx") {
|
if args.starts_with("tx") {
|
||||||
|
env.echo.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||||
let arg_list: Vec<&str> = args.split_whitespace().collect();
|
let arg_list: Vec<&str> = args.split_whitespace().collect();
|
||||||
if arg_list.len() >= 2 {
|
if arg_list.len() >= 2 {
|
||||||
let s = arg_list[1].trim();
|
let s = arg_list[1].trim();
|
||||||
|
|
@ -479,6 +496,7 @@ impl<'a> ShellCmdApi<'a> for BioLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
if args == "pad" {
|
if args == "pad" {
|
||||||
|
env.echo.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||||
// Zero-fill every slot not yet received, then commit.
|
// Zero-fill every slot not yet received, then commit.
|
||||||
// This allows the host to send only the chunks that carry real data
|
// This allows the host to send only the chunks that carry real data
|
||||||
// and let the device pad the remainder of the 0xf00-byte buffer.
|
// and let the device pad the remainder of the 0xf00-byte buffer.
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
let helpstring = "test [proc] [freemem] [interrupts] [panic] [timer] [env]";
|
let helpstring = "test [proc] [freemem] [interrupts] [panic] [env]";
|
||||||
|
|
||||||
let mut tokens = args.split(' ');
|
let mut tokens = args.split(' ');
|
||||||
|
|
||||||
|
|
@ -23,7 +23,7 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
match sub_cmd {
|
match sub_cmd {
|
||||||
"timer" => {
|
"timer" => {
|
||||||
let start = _env.ticktimer.elapsed_ms();
|
let start = _env.ticktimer.elapsed_ms();
|
||||||
log::info!("Starting test");
|
log::info!("Timer test - runs forever");
|
||||||
let mut seconds = 0;
|
let mut seconds = 0;
|
||||||
loop {
|
loop {
|
||||||
let elapsed = _env.ticktimer.elapsed_ms() - start;
|
let elapsed = _env.ticktimer.elapsed_ms() - start;
|
||||||
|
|
@ -33,6 +33,9 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"echo" => {
|
||||||
|
_env.echo.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||||
|
}
|
||||||
"panic" => {
|
"panic" => {
|
||||||
log::info!("System will panic now");
|
log::info!("System will panic now");
|
||||||
panic!("test panic");
|
panic!("test panic");
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ mod ctap;
|
||||||
mod repl;
|
mod repl;
|
||||||
mod shell;
|
mod shell;
|
||||||
use cmds::*;
|
use cmds::*;
|
||||||
#[cfg(feature = "usb")]
|
|
||||||
use usb_bao1x::UsbHid;
|
use usb_bao1x::UsbHid;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
@ -20,12 +19,9 @@ fn main() {
|
||||||
// spawn the shell thread
|
// spawn the shell thread
|
||||||
shell::start_shell();
|
shell::start_shell();
|
||||||
|
|
||||||
#[cfg(feature = "usb")]
|
tt.sleep_ms(500).ok(); // pause for the system to startup
|
||||||
{
|
let usb = UsbHid::new();
|
||||||
tt.sleep_ms(500).ok(); // pause for the system to startup
|
usb.serial_console_input_injection();
|
||||||
let usb = UsbHid::new();
|
|
||||||
usb.serial_console_input_injection();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "ctap-bringup")]
|
#[cfg(feature = "ctap-bringup")]
|
||||||
{
|
{
|
||||||
|
|
@ -33,8 +29,12 @@ fn main() {
|
||||||
crate::ctap::ctap_test();
|
crate::ctap::ctap_test();
|
||||||
}
|
}
|
||||||
|
|
||||||
// idle the main thread, all children are spawned
|
// This idiom creates a dummy server that blocks. This effectively parks the parent
|
||||||
|
// process, allowing its child threads to run without taking any CPU resources.
|
||||||
|
let dummy_sid = xous::create_server().unwrap();
|
||||||
loop {
|
loop {
|
||||||
tt.sleep_ms(2_000).ok();
|
// This call blocks forever since nobody has `dummy_sid` and thus it will never
|
||||||
|
// receive a message.
|
||||||
|
let _ = xous::receive_message(dummy_sid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::sync::{Arc, atomic::AtomicBool};
|
||||||
|
|
||||||
use xous::MessageEnvelope;
|
use xous::MessageEnvelope;
|
||||||
|
|
||||||
use crate::CmdEnv;
|
use crate::CmdEnv;
|
||||||
|
|
@ -27,13 +29,13 @@ pub(crate) struct Repl {
|
||||||
env: CmdEnv,
|
env: CmdEnv,
|
||||||
}
|
}
|
||||||
impl Repl {
|
impl Repl {
|
||||||
pub(crate) fn new(xns: &xous_names::XousNames) -> Self {
|
pub(crate) fn new(xns: &xous_names::XousNames, echo: Arc<AtomicBool>) -> Self {
|
||||||
Repl {
|
Repl {
|
||||||
input: None,
|
input: None,
|
||||||
msg: None,
|
msg: None,
|
||||||
history: Vec::new(),
|
history: Vec::new(),
|
||||||
history_len: HISTORY_DEPTH,
|
history_len: HISTORY_DEPTH,
|
||||||
env: CmdEnv::new(xns),
|
env: CmdEnv::new(xns, echo),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
|
use std::sync::{Arc, atomic::AtomicBool};
|
||||||
|
|
||||||
use bao1x_api::*;
|
use bao1x_api::*;
|
||||||
#[cfg(feature = "usb")]
|
|
||||||
use usb_bao1x::UsbHid;
|
use usb_bao1x::UsbHid;
|
||||||
use xous::msg_scalar_unpack;
|
use xous::msg_scalar_unpack;
|
||||||
|
|
||||||
|
|
@ -32,12 +33,12 @@ fn shell() {
|
||||||
let kbd = keyboard::Keyboard::new(&xns).unwrap();
|
let kbd = keyboard::Keyboard::new(&xns).unwrap();
|
||||||
kbd.register_listener(SERVER_NAME_SHELLCHAT, ConsoleOp::Keypress.to_u32().unwrap() as usize);
|
kbd.register_listener(SERVER_NAME_SHELLCHAT, ConsoleOp::Keypress.to_u32().unwrap() as usize);
|
||||||
|
|
||||||
let mut repl = crate::repl::Repl::new(&xns);
|
let echo = Arc::new(AtomicBool::new(true));
|
||||||
|
let mut repl = crate::repl::Repl::new(&xns, echo.clone());
|
||||||
let mut update_repl = false;
|
let mut update_repl = false;
|
||||||
let mut was_callback = false;
|
let mut was_callback = false;
|
||||||
let mut history_index: isize = 0;
|
let mut history_index: isize = 0;
|
||||||
|
|
||||||
#[cfg(feature = "usb")]
|
|
||||||
let usb = UsbHid::new();
|
let usb = UsbHid::new();
|
||||||
|
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
|
|
@ -48,8 +49,9 @@ fn shell() {
|
||||||
match console_op {
|
match console_op {
|
||||||
Some(ConsoleOp::Keypress) => msg_scalar_unpack!(msg, k1, _k2, _k3, _k4, {
|
Some(ConsoleOp::Keypress) => msg_scalar_unpack!(msg, k1, _k2, _k3, _k4, {
|
||||||
let k = char::from_u32(k1 as u32).unwrap_or('\u{0000}');
|
let k = char::from_u32(k1 as u32).unwrap_or('\u{0000}');
|
||||||
#[cfg(feature = "usb")]
|
if echo.load(std::sync::atomic::Ordering::SeqCst) {
|
||||||
usb.serial_send(&[k1 as u8]).ok();
|
usb.serial_send(&[k1 as u8]).ok();
|
||||||
|
}
|
||||||
if k1 == 0x08 {
|
if k1 == 0x08 {
|
||||||
// backspace character
|
// backspace character
|
||||||
input.pop(); // returns None if empty
|
input.pop(); // returns None if empty
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue