mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
Allow logging from spawn
This allows the spawn (i.e. new process) to use log. Firstly, xous-api-log was changed to allow no_std when the target os is xous (this is done using a feature). Then, in spawn itself, an AtomicU32 is moved into memory as a replacement for XOUS_LOGGER_CONNECTION, which is not in .text and is thus not in the stub file.
This commit is contained in:
parent
dc9411669c
commit
6f86f3b115
6 changed files with 26 additions and 26 deletions
|
|
@ -179,7 +179,7 @@ rev="4296c2e7904898766cf7d8d589759a129794783b" # use the commitref because we're
|
|||
# path = "./api/xous-api-names"
|
||||
# [patch.crates-io.xous-api-susres]
|
||||
# path = "./api/xous-api-susres"
|
||||
# [patch.crates-io.xous-api-log]
|
||||
# path = "./api/xous-api-log"
|
||||
[patch.crates-io.xous-api-log]
|
||||
path = "./api/xous-api-log"
|
||||
# [patch.crates-io.xous-api-ticktimer]
|
||||
# path = "./api/xous-api-ticktimer"
|
||||
|
|
|
|||
|
|
@ -19,4 +19,5 @@ num-traits = {version = "0.2.14", default-features = false}
|
|||
[features]
|
||||
debugprint = [] # adding this allocates the UART for debugging the logger
|
||||
logging = [] # adding this allocates the hardware UART for console interactions
|
||||
nostd = [] # adding this causes the program to be built without std
|
||||
default = ["logging"]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
#![cfg_attr(any(target_os = "none", feature = "nostd"), no_std)]
|
||||
use core::fmt::Write;
|
||||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
use num_traits::ToPrimitive;
|
||||
|
|
@ -96,8 +96,10 @@ pub fn init() -> Result<(), LogError> {
|
|||
}
|
||||
|
||||
pub fn init_wait() -> Result<(), ()> {
|
||||
let sid = xous::SID::from_bytes(b"xous-log-server ").unwrap();
|
||||
let cid = xous::connect(sid).or(Err(()))?;
|
||||
XOUS_LOGGER_CONNECTION.store(
|
||||
xous::connect(xous::SID::from_bytes(b"xous-log-server ").unwrap()).or(Err(()))?,
|
||||
cid,
|
||||
Ordering::Relaxed,
|
||||
);
|
||||
log::set_logger(&XOUS_LOGGER).or(Err(()))?;
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
// this should be changed at some point to support other platforms
|
||||
let target = "riscv32imac-unknown-xous-elf";
|
||||
|
||||
// compile the spawn package
|
||||
let status = Command::new("cargo").args(&["build", "--package", "spawn", "--target", target])
|
||||
.status().unwrap();
|
||||
if !status.success() {
|
||||
panic!();
|
||||
}
|
||||
// turn it into a stub
|
||||
let status = Command::new("cargo").args(&["run", "--package", "tools", "--bin", "copy-object", "--"])
|
||||
.arg(&format!("../../target/{}/debug/spawn", target))
|
||||
.status().unwrap();
|
||||
if !status.success() {
|
||||
panic!();
|
||||
}
|
||||
|
||||
println!("cargo:rerun-if-changed=spawn");
|
||||
}
|
||||
|
|
@ -7,3 +7,5 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
xous = "0.9.42"
|
||||
log-server = { package = "xous-api-log", version = "0.1.35", features = ["nostd"] }
|
||||
log = "0.4.17"
|
||||
|
|
|
|||
|
|
@ -31,6 +31,23 @@ fn handle_panic(_arg: &core::panic::PanicInfo) -> ! {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn init(server1: u32, server2: u32, server3: u32, server4: u32) -> ! {
|
||||
let server = xous::SID::from_u32(server1, server2, server3, server4);
|
||||
|
||||
// recreate the extra sections that were cut out of the stub
|
||||
let mut memory = xous::map_memory(
|
||||
None,
|
||||
core::num::NonZeroUsize::new(0x40000000),
|
||||
0x1000,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W
|
||||
).unwrap();
|
||||
let connection = core::sync::atomic::AtomicU32::new(0);
|
||||
let slice = unsafe { core::slice::from_raw_parts(&connection as *const _ as *const u8, core::mem::size_of::<core::sync::atomic::AtomicU32>()) };
|
||||
for (dest, src) in memory.as_slice_mut::<u8>().iter_mut().skip(8).zip(slice) {
|
||||
*dest = *src;
|
||||
}
|
||||
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
log::info!("my PID is {}", xous::process::id());
|
||||
loop {
|
||||
if let Ok(xous::Result::MessageEnvelope(envelope)) =
|
||||
xous::rsyscall(xous::SysCall::ReceiveMessage(server))
|
||||
|
|
|
|||
Loading…
Reference in a new issue