this commit crashes on boot

This commit is contained in:
bunnie 2021-03-16 19:07:03 +08:00
parent eda33b5de7
commit 0e8767aea2
4 changed files with 95 additions and 43 deletions

View file

@ -1328,10 +1328,10 @@ register to disable individual events.]]></description>
<register>
<name>GIT_GITREV</name>
<description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev
``d77dca2f``, so this value is 3615345199, which should be enough to check out
``2a2abe5e``, so this value is 707444318, which should be enough to check out
the exact git version used to build this firmware.]]></description>
<addressOffset>0x0014</addressOffset>
<resetValue>0xd77dca2f</resetValue>
<resetValue>0x2a2abe5e</resetValue>
<size>32</size>
<fields>
<field>
@ -1348,7 +1348,7 @@ the exact git version used to build this firmware.]]></description>
is ``1``, then the repository this was built from has one additional commit
beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description>
<addressOffset>0x0018</addressOffset>
<resetValue>0x0d</resetValue>
<resetValue>0x0e</resetValue>
<size>32</size>
<fields>
<field>
@ -1362,7 +1362,7 @@ beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description>
<register>
<name>GIT_DIRTY</name>
<addressOffset>0x001c</addressOffset>
<resetValue>0x01</resetValue>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
@ -3056,7 +3056,7 @@ again until the interrupt is serviced.]]></description>
<name>SEED1</name>
<description><![CDATA[Bits 32-63 of `SEED_SEED`. Seed used for the build]]></description>
<addressOffset>0x0000</addressOffset>
<resetValue>0x508efbe6</resetValue>
<resetValue>0x1a7a2a66</resetValue>
<size>32</size>
<fields>
<field>
@ -3071,7 +3071,7 @@ again until the interrupt is serviced.]]></description>
<name>SEED0</name>
<description><![CDATA[Bits 0-31 of `SEED_SEED`.]]></description>
<addressOffset>0x0004</addressOffset>
<resetValue>0x1f1cd099</resetValue>
<resetValue>0x4b326b1e</resetValue>
<size>32</size>
<fields>
<field>

View file

@ -1,10 +1,15 @@
use xous::String;
use xous::{String, MessageEnvelope};
use core::fmt::Write;
/////////////////////////// Common items to all commands
pub trait ShellCmdApi<'a> {
// user implemented:
// called to process the command with the remainder of the string attached
fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error>;
// called to process incoming messages that may have been origniated by the most recently issued command
fn callback(&mut self, msg: &MessageEnvelope, _env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
log::info!("SHCH: received unhandled message {:?}", msg);
Ok(None)
}
// created with cmd_api! macro
// checks if the command matches the current verb in question
@ -28,6 +33,7 @@ macro_rules! cmd_api {
};
}
/////////////////////////// Command shell integration
#[derive(Debug)]
pub struct CommonEnv {
@ -55,14 +61,17 @@ mod echo; use echo::*;
mod test; use test::*;
mod sleep; use sleep::*;
mod sensors; use sensors::*;
mod callback; use callback::*;
#[derive(Debug)]
pub struct CmdEnv {
common_env: CommonEnv,
lastverb: String::<256>,
///// 2. declare storage for your command here.
test_cmd: Test,
sleep_cmd: Sleep,
sensors_cmd: Sensors,
callback_cmd: CallBack,
}
impl CmdEnv {
pub fn new(gam: xous::CID) -> CmdEnv {
@ -74,14 +83,16 @@ impl CmdEnv {
ticktimer: xous::connect(ticktimer_server_id).unwrap(),
gam,
},
lastverb: String::<256>::new(),
///// 3. initialize your storage, by calling new()
test_cmd: Test::new(),
sleep_cmd: Sleep::new(),
sensors_cmd: Sensors::new(),
callback_cmd: CallBack::new(),
}
}
pub fn dispatch(&mut self, cmdline: &mut String::<1024>) -> Result<Option<String::<1024>>, xous::Error> {
pub fn dispatch(&mut self, maybe_cmdline: Option<&mut String::<1024>>, maybe_callback: Option<&MessageEnvelope>) -> Result<Option<String::<1024>>, xous::Error> {
let mut ret = String::<1024>::new();
let mut echo_cmd = Echo {}; // this command has no persistent storage, so we can "create" it every time we call dispatch (but it's a zero-cost absraction so this doesn't actually create any instructions)
@ -91,38 +102,59 @@ impl CmdEnv {
&mut self.test_cmd,
&mut self.sleep_cmd,
&mut self.sensors_cmd,
&mut self.callback_cmd,
];
let maybe_verb = tokenize(cmdline);
if let Some(cmdline) = maybe_cmdline {
let maybe_verb = tokenize(cmdline);
let mut cmd_ret: Result<Option<String::<1024>>, xous::Error> = Ok(None);
if let Some(verb_string) = maybe_verb {
let verb = verb_string.to_str();
let mut cmd_ret: Result<Option<String::<1024>>, xous::Error> = Ok(None);
if let Some(verb_string) = maybe_verb {
let verb = verb_string.to_str();
// search through the list of commands linearly until one matches,
// then run it.
let mut match_found = false;
for cmd in commands.iter_mut() {
if cmd.matches(verb) {
match_found = true;
cmd_ret = cmd.process(*cmdline, &mut self.common_env);
};
}
// if none match, create a list of available commands
if !match_found {
let mut first = true;
write!(ret, "Commands: ").unwrap();
for cmd in commands.iter() {
if !first {
ret.append(", ")?;
}
ret.append(cmd.verb())?;
first = false;
// search through the list of commands linearly until one matches,
// then run it.
let mut match_found = false;
for cmd in commands.iter_mut() {
if cmd.matches(verb) {
match_found = true;
cmd_ret = cmd.process(*cmdline, &mut self.common_env);
self.lastverb.clear();
write!(self.lastverb, "{}", verb).expect("SHCH: couldn't record last verb");
};
}
// if none match, create a list of available commands
if !match_found {
let mut first = true;
write!(ret, "Commands: ").unwrap();
for cmd in commands.iter() {
if !first {
ret.append(", ")?;
}
ret.append(cmd.verb())?;
first = false;
}
Ok(Some(ret))
} else {
cmd_ret
}
Ok(Some(ret))
} else {
Ok(None)
}
} else if let Some(callback) = maybe_callback {
let mut cmd_ret: Result<Option<String::<1024>>, xous::Error> = Ok(None);
if self.lastverb.len() > 0 {
let verb = self.lastverb.to_str();
for cmd in commands.iter_mut() {
if cmd.matches(verb) {
cmd_ret = cmd.callback(callback, &mut self.common_env);
break;
};
}
cmd_ret
} else {
Ok(None)
}
} else {
Ok(None)

View file

@ -1,7 +1,7 @@
#![cfg_attr(target_os = "none", no_std)]
#![cfg_attr(target_os = "none", no_main)]
use log::{error, info};
use log::info;
use core::fmt::Write;
use core::convert::TryFrom;
@ -16,6 +16,8 @@ use graphics_server::{Gid, Point, Rectangle, TextBounds, TextView, DrawStyle, Gl
use heapless::spsc::Queue;
use heapless::consts::U16;
use xous::MessageEnvelope;
mod cmds;
use cmds::*;
@ -32,7 +34,8 @@ struct Repl {
// optional structures that indicate new input to the Repl loop per iteration
// an input string
input: Option<xous::String<1024>>,
// examples of future inputs: returned values via other services
// messages from other servers
msg: Option<MessageEnvelope>,
// record our input history
history: Queue<History, U16>,
@ -57,6 +60,7 @@ impl Repl{
let screensize = gam::get_canvas_bounds(gam_conn, content).expect("SHCH: couldn't get dimensions of content canvas");
Repl {
input: None,
msg: None,
history: Queue::new(),
content,
gam: gam_conn,
@ -80,6 +84,10 @@ impl Repl{
Ok(())
}
fn msg(&mut self, message: MessageEnvelope) {
self.msg = Some(message);
}
fn circular_push(&mut self, item: History) {
if self.history.len() == self.history.capacity() {
self.history.dequeue().expect("SHCH: couldn't dequeue historye");
@ -108,7 +116,17 @@ impl Repl{
// take the input and pass it on to the various command parsers, and attach result
if let Some(mut local) = self.input {
if let Some(res) = self.env.dispatch(&mut local).expect("SHCH: command dispatch failed") {
if let Some(res) = self.env.dispatch(Some(&mut local), None).expect("SHCH: command dispatch failed") {
let mut response = xous::String::<1024>::new();
write!(response, "{}", res).expect("SHCH: can't copy result to history");
let output_history = History {
text: response,
is_input: false
};
self.circular_push(output_history);
}
} else if let Some(msg) = &self.msg {
if let Some(res) = self.env.dispatch(None, Some(msg)).expect("SCHC: callback failed") {
let mut response = xous::String::<1024>::new();
write!(response, "{}", res).expect("SHCH: can't copy result to history");
let output_history = History {
@ -121,6 +139,7 @@ impl Repl{
// clear all the inputs to the loop, so we don't process them twice
self.input = None;
self.msg = None;
// redraw UI now that we've responded
self.redraw().expect("SHCH: can't redraw");
@ -233,7 +252,8 @@ fn xmain() -> ! {
}
}
} else {
error!("SHCH: couldn't convert message");
repl.msg(envelope);
update_repl = true;
}
if update_repl {

View file

@ -1328,10 +1328,10 @@ register to disable individual events.]]></description>
<register>
<name>GIT_GITREV</name>
<description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev
``d77dca2f``, so this value is 3615345199, which should be enough to check out
``2a2abe5e``, so this value is 707444318, which should be enough to check out
the exact git version used to build this firmware.]]></description>
<addressOffset>0x0014</addressOffset>
<resetValue>0xd77dca2f</resetValue>
<resetValue>0x2a2abe5e</resetValue>
<size>32</size>
<fields>
<field>
@ -1348,7 +1348,7 @@ the exact git version used to build this firmware.]]></description>
is ``1``, then the repository this was built from has one additional commit
beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description>
<addressOffset>0x0018</addressOffset>
<resetValue>0x0d</resetValue>
<resetValue>0x0e</resetValue>
<size>32</size>
<fields>
<field>
@ -1362,7 +1362,7 @@ beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description>
<register>
<name>GIT_DIRTY</name>
<addressOffset>0x001c</addressOffset>
<resetValue>0x01</resetValue>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
@ -3056,7 +3056,7 @@ again until the interrupt is serviced.]]></description>
<name>SEED1</name>
<description><![CDATA[Bits 32-63 of `SEED_SEED`. Seed used for the build]]></description>
<addressOffset>0x0000</addressOffset>
<resetValue>0x508efbe6</resetValue>
<resetValue>0x1a7a2a66</resetValue>
<size>32</size>
<fields>
<field>
@ -3071,7 +3071,7 @@ again until the interrupt is serviced.]]></description>
<name>SEED0</name>
<description><![CDATA[Bits 0-31 of `SEED_SEED`.]]></description>
<addressOffset>0x0004</addressOffset>
<resetValue>0x1f1cd099</resetValue>
<resetValue>0x4b326b1e</resetValue>
<size>32</size>
<fields>
<field>