add serial console mux setting

This commit is contained in:
bunnie 2021-06-24 13:52:44 +08:00
parent 3b0a4f2bf4
commit afa55055ea
5 changed files with 65 additions and 20 deletions

View file

@ -1,10 +1,13 @@
/////////////////////// UART TYPE /////////////////////// 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)] #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
pub enum UartType { pub enum UartType {
Kernel, Kernel = 0,
Log, Log = 1,
Application, Application = 2,
Invalid, Invalid = 3,
} }
// from/to for Xous messages // from/to for Xous messages
impl From<usize> for UartType { impl From<usize> for UartType {

View file

@ -526,6 +526,12 @@ impl Llio {
pub fn debug_usb_unlocked(&self) -> Result<bool, xous::Error> { pub fn debug_usb_unlocked(&self) -> Result<bool, xous::Error> {
Ok(true) // for now, always return true, because we don't have the hardware yet to lock out debug USB 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(|_| ())
}
} }

View file

@ -17,15 +17,6 @@ use xous::{CID, msg_scalar_unpack, msg_blocking_scalar_unpack};
#[cfg(target_os = "none")] #[cfg(target_os = "none")]
mod implementation { 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 crate::api::*;
use log::{error, info}; use log::{error, info};
use utralib::generated::*; use utralib::generated::*;
@ -118,7 +109,7 @@ mod implementation {
.expect("couldn't map GPIO CSR range"); .expect("couldn't map GPIO CSR range");
let mut gpio_csr = CSR::new(gpio_base.as_mut_ptr() as *mut u32); let mut gpio_csr = CSR::new(gpio_base.as_mut_ptr() as *mut u32);
// setup the initial logging output // 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 gpio_base.as_mut_ptr() as *mut u32
} }

View file

@ -94,9 +94,10 @@ mod ecup; use ecup::*;
mod aes; use aes::*; mod aes; use aes::*;
mod trng_cmd; use trng_cmd::*; mod trng_cmd; use trng_cmd::*;
mod engine; use engine::*; mod engine; use engine::*;
mod console; use console::*;
mod fcc; use fcc::*; //mod fcc; use fcc::*;
mod pds; // dependency of the FCC file //mod pds; // dependency of the FCC file
#[derive(Debug)] #[derive(Debug)]
pub struct CmdEnv { pub struct CmdEnv {
@ -117,7 +118,7 @@ pub struct CmdEnv {
trng_cmd: TrngCmd, trng_cmd: TrngCmd,
engine_cmd: Engine, engine_cmd: Engine,
fcc_cmd: Fcc, //fcc_cmd: Fcc,
} }
impl CmdEnv { impl CmdEnv {
pub fn new(xns: &xous_names::XousNames) -> CmdEnv { pub fn new(xns: &xous_names::XousNames) -> CmdEnv {
@ -131,7 +132,7 @@ impl CmdEnv {
trng: trng::Trng::new(&xns).unwrap(), trng: trng::Trng::new(&xns).unwrap(),
xns: xous_names::XousNames::new().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 sha = Sha::new(&xns, &mut common);
let aes = Aes::new(&xns, &mut common); let aes = Aes::new(&xns, &mut common);
let ecup = EcUpdate::new(&mut common); let ecup = EcUpdate::new(&mut common);
@ -165,7 +166,7 @@ impl CmdEnv {
trng_cmd: TrngCmd::new(), trng_cmd: TrngCmd::new(),
engine_cmd: engine, engine_cmd: engine,
fcc_cmd: fcc, //fcc_cmd: fcc,
} }
} }
@ -176,6 +177,7 @@ impl CmdEnv {
let mut ver_cmd = Ver{}; let mut ver_cmd = Ver{};
let mut backlight_cmd = Backlight{}; let mut backlight_cmd = Backlight{};
let mut accel_cmd = Accel{}; let mut accel_cmd = Accel{};
let mut console_cmd = Console{};
let commands: &mut [& mut dyn ShellCmdApi] = &mut [ let commands: &mut [& mut dyn ShellCmdApi] = &mut [
///// 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,
@ -195,8 +197,9 @@ impl CmdEnv {
&mut self.aes_cmd, &mut self.aes_cmd,
&mut self.trng_cmd, &mut self.trng_cmd,
&mut self.engine_cmd, &mut self.engine_cmd,
&mut console_cmd,
&mut self.fcc_cmd, //&mut self.fcc_cmd,
]; ];
if let Some(cmdline) = maybe_cmdline { if let Some(cmdline) = maybe_cmdline {

View file

@ -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<Option<String::<1024>>, 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))
}
}