mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
examples: go to sleep when we panic
This prevents this process from constantly hogging the CPU. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
bdb8eac9ad
commit
834c637783
3 changed files with 27 additions and 5 deletions
|
|
@ -13,6 +13,7 @@ use log_string::LogString;
|
||||||
fn handle_panic(arg: &PanicInfo) -> ! {
|
fn handle_panic(arg: &PanicInfo) -> ! {
|
||||||
println!("PANIC!");
|
println!("PANIC!");
|
||||||
println!("Details: {:?}", arg);
|
println!("Details: {:?}", arg);
|
||||||
|
xous::syscall::wait_event();
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,7 +88,11 @@ fn main() {
|
||||||
}
|
}
|
||||||
xous::Message::Move(msg) => {
|
xous::Message::Move(msg) => {
|
||||||
let log_entry = LogString::from_message(msg);
|
let log_entry = LogString::from_message(msg);
|
||||||
println!("Log message from {}: {}", envelope.sender, log_entry);
|
println!("Moved log message from {}: {}", envelope.sender, log_entry);
|
||||||
|
}
|
||||||
|
xous::Message::ImmutableBorrow(msg) => {
|
||||||
|
let log_entry = LogString::from_message(msg);
|
||||||
|
println!("Immutably borrowed log message from {}: {}", envelope.sender, log_entry);
|
||||||
}
|
}
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ impl<'a> LogStr<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_memory_message(self, id: xous::MessageId) -> Result<xous::MemoryMessage, xous::Error> {
|
pub fn into_memory_message(self, id: xous::MessageId) -> Result<xous::MemoryMessage, xous::Error> {
|
||||||
|
// XXX This should forget the memory allocated, as it will be sent to the other process
|
||||||
Ok(xous::MemoryMessage {
|
Ok(xous::MemoryMessage {
|
||||||
id: id,
|
id: id,
|
||||||
buf: xous::MemoryRange::new(self.raw_slice.as_ptr() as usize, self.raw_slice.len()),
|
buf: xous::MemoryRange::new(self.raw_slice.as_ptr() as usize, self.raw_slice.len()),
|
||||||
|
|
@ -37,6 +38,19 @@ impl<'a> LogStr<'a> {
|
||||||
valid: xous::MemorySize::new(self.len),
|
valid: xous::MemorySize::new(self.len),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_memory_message(&self, id: xous::MessageId) -> Result<xous::MemoryMessage, xous::Error> {
|
||||||
|
Ok(xous::MemoryMessage {
|
||||||
|
id: id,
|
||||||
|
buf: xous::MemoryRange::new(self.raw_slice.as_ptr() as usize, self.raw_slice.len()),
|
||||||
|
offset: None,
|
||||||
|
valid: xous::MemorySize::new(self.len),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear(&mut self) {
|
||||||
|
self.len = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Write for LogStr<'a> {
|
impl<'a> Write for LogStr<'a> {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ use core::panic::PanicInfo;
|
||||||
fn handle_panic(arg: &PanicInfo) -> ! {
|
fn handle_panic(arg: &PanicInfo) -> ! {
|
||||||
println!("PANIC!");
|
println!("PANIC!");
|
||||||
println!("Details: {:?}", arg);
|
println!("Details: {:?}", arg);
|
||||||
|
xous::syscall::wait_event();
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,6 +124,7 @@ fn main() {
|
||||||
println!("Connected: {:?}", connection);
|
println!("Connected: {:?}", connection);
|
||||||
|
|
||||||
let mut counter = 0;
|
let mut counter = 0;
|
||||||
|
let mut ls = logstr::LogStr::new();
|
||||||
loop {
|
loop {
|
||||||
println!("Sending a scalar message with id {}...", counter + 4096);
|
println!("Sending a scalar message with id {}...", counter + 4096);
|
||||||
xous::syscall::send_message(
|
xous::syscall::send_message(
|
||||||
|
|
@ -141,13 +143,14 @@ fn main() {
|
||||||
xous::syscall::yield_slice();
|
xous::syscall::yield_slice();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ls = logstr::LogStr::new();
|
ls.clear();
|
||||||
write!(ls, "Hello, Server! Loop number: {}", counter).expect("couldn't send hello message");
|
write!(ls, "Hello, Server! This memory is borrowed from another process. Loop number: {}", counter).expect("couldn't send hello message");
|
||||||
|
|
||||||
|
println!("Sending a mutable borrow message");
|
||||||
xous::syscall::send_message(
|
xous::syscall::send_message(
|
||||||
connection,
|
connection,
|
||||||
xous::Message::Move(
|
xous::Message::ImmutableBorrow(
|
||||||
ls.into_memory_message(0)
|
ls.as_memory_message(0)
|
||||||
.expect("couldn't form memory message"),
|
.expect("couldn't form memory message"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue