diff --git a/services/llio/src/api.rs b/services/llio/src/api.rs index 42523c6f7..b9b473e6e 100644 --- a/services/llio/src/api.rs +++ b/services/llio/src/api.rs @@ -1,10 +1,13 @@ /////////////////////// UART TYPE +#[allow(dead_code)] // we actually use this constant, but clippy insists that we don't +pub(crate) const BOOT_UART: u32 = UartType::Log as u32; + #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] pub enum UartType { - Kernel, - Log, - Application, - Invalid, + Kernel = 0, + Log = 1, + Application = 2, + Invalid = 3, } // from/to for Xous messages impl From for UartType { diff --git a/services/llio/src/lib.rs b/services/llio/src/lib.rs index 4a0d6ebbe..e19934e87 100644 --- a/services/llio/src/lib.rs +++ b/services/llio/src/lib.rs @@ -526,6 +526,12 @@ impl Llio { pub fn debug_usb_unlocked(&self) -> Result { Ok(true) // for now, always return true, because we don't have the hardware yet to lock out debug USB } + pub fn set_uart_mux(&self, setting: UartType) -> Result<(), xous::Error> { + let arg = setting.into(); + send_message(self.conn, + Message::new_scalar(Opcode::UartMux.to_usize().unwrap(), arg, 0, 0, 0) + ).map(|_| ()) + } } diff --git a/services/llio/src/main.rs b/services/llio/src/main.rs index 5e8edffd3..4b87ef533 100644 --- a/services/llio/src/main.rs +++ b/services/llio/src/main.rs @@ -17,15 +17,6 @@ use xous::{CID, msg_scalar_unpack, msg_blocking_scalar_unpack}; #[cfg(target_os = "none")] mod implementation { - // Encodes the currently valid mux values for the SoC UART hardware - #[allow(dead_code)] - enum UartMux { - Kernel = 0, - Log = 1, - App = 2, - } - const BOOT_UART: u32 = UartMux::Log as u32; - use crate::api::*; use log::{error, info}; use utralib::generated::*; @@ -118,7 +109,7 @@ mod implementation { .expect("couldn't map GPIO CSR range"); let mut gpio_csr = CSR::new(gpio_base.as_mut_ptr() as *mut u32); // setup the initial logging output - gpio_csr.wfo(utra::gpio::UARTSEL_UARTSEL, BOOT_UART); + gpio_csr.wfo(utra::gpio::UARTSEL_UARTSEL, crate::api::BOOT_UART); gpio_base.as_mut_ptr() as *mut u32 } diff --git a/services/shellchat/src/cmds.rs b/services/shellchat/src/cmds.rs index c893ff81d..d61161e35 100644 --- a/services/shellchat/src/cmds.rs +++ b/services/shellchat/src/cmds.rs @@ -94,9 +94,10 @@ mod ecup; use ecup::*; mod aes; use aes::*; mod trng_cmd; use trng_cmd::*; mod engine; use engine::*; +mod console; use console::*; -mod fcc; use fcc::*; -mod pds; // dependency of the FCC file +//mod fcc; use fcc::*; +//mod pds; // dependency of the FCC file #[derive(Debug)] pub struct CmdEnv { @@ -117,7 +118,7 @@ pub struct CmdEnv { trng_cmd: TrngCmd, engine_cmd: Engine, - fcc_cmd: Fcc, + //fcc_cmd: Fcc, } impl CmdEnv { pub fn new(xns: &xous_names::XousNames) -> CmdEnv { @@ -131,7 +132,7 @@ impl CmdEnv { trng: trng::Trng::new(&xns).unwrap(), xns: xous_names::XousNames::new().unwrap(), }; - let fcc = Fcc::new(&mut common); + //let fcc = Fcc::new(&mut common); let sha = Sha::new(&xns, &mut common); let aes = Aes::new(&xns, &mut common); let ecup = EcUpdate::new(&mut common); @@ -165,7 +166,7 @@ impl CmdEnv { trng_cmd: TrngCmd::new(), engine_cmd: engine, - fcc_cmd: fcc, + //fcc_cmd: fcc, } } @@ -176,6 +177,7 @@ impl CmdEnv { let mut ver_cmd = Ver{}; let mut backlight_cmd = Backlight{}; let mut accel_cmd = Accel{}; + let mut console_cmd = Console{}; let commands: &mut [& mut dyn ShellCmdApi] = &mut [ ///// 4. add your command to this array, so that it can be looked up and dispatched &mut echo_cmd, @@ -195,8 +197,9 @@ impl CmdEnv { &mut self.aes_cmd, &mut self.trng_cmd, &mut self.engine_cmd, + &mut console_cmd, - &mut self.fcc_cmd, + //&mut self.fcc_cmd, ]; if let Some(cmdline) = maybe_cmdline { diff --git a/services/shellchat/src/cmds/console.rs b/services/shellchat/src/cmds/console.rs new file mode 100644 index 000000000..db9554d73 --- /dev/null +++ b/services/shellchat/src/cmds/console.rs @@ -0,0 +1,42 @@ +use crate::{ShellCmdApi, CommonEnv}; +use xous_ipc::String; + +#[derive(Debug)] +pub struct Console { +} + +impl<'a> ShellCmdApi<'a> for Console { + cmd_api!(console); // inserts boilerplate for command API + + fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result>, xous::Error> { + use core::fmt::Write; + let mut ret = String::<1024>::new(); + let helpstring = "Serial console options: kernel, log, app"; + + let mut tokens = args.as_str().unwrap().split(' '); + + if let Some(sub_cmd) = tokens.next() { + match sub_cmd { + "kernel" => { + env.llio.set_uart_mux(llio::UartType::Kernel).unwrap(); + write!(ret, "kernel -> serial console").unwrap(); + } + "log" => { + env.llio.set_uart_mux(llio::UartType::Log).unwrap(); + write!(ret, "log -> serial console").unwrap(); + } + "app" => { + env.llio.set_uart_mux(llio::UartType::Application).unwrap(); + write!(ret, "app -> serial console").unwrap(); + } + _ => { + write!(ret, "{}", helpstring).unwrap(); + } + } + + } else { + write!(ret, "{}", helpstring).unwrap(); + } + Ok(Some(ret)) + } +}