mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
examples: log: get building cross-platform
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
17ae34a1c1
commit
8cc43d64b5
2 changed files with 90 additions and 56 deletions
17
examples/log/build.rs
Normal file
17
examples/log/build.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
// NOTE: Adapted from cortex-m/build.rs
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let target = env::var("TARGET").unwrap();
|
||||||
|
|
||||||
|
let target_os = target.split('-').nth(2).unwrap_or("none");
|
||||||
|
|
||||||
|
// If we're not running on a desktop-class operating system, emit the "baremetal"
|
||||||
|
// config setting. This will enable software to do tasks such as
|
||||||
|
// managing memory.
|
||||||
|
if target_os == "none" {
|
||||||
|
println!("cargo:rustc-cfg=baremetal");
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("cargo:rerun-if-changed=build.rs");
|
||||||
|
}
|
||||||
|
|
@ -1,50 +1,67 @@
|
||||||
#![no_std]
|
#![cfg_attr(baremetal, no_std)]
|
||||||
#![no_main]
|
#![cfg_attr(baremetal, no_main)]
|
||||||
|
|
||||||
|
#[cfg(baremetal)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod debug;
|
mod debug;
|
||||||
|
|
||||||
mod log_string;
|
mod log_string;
|
||||||
mod start;
|
mod start;
|
||||||
|
|
||||||
use core::panic::PanicInfo;
|
|
||||||
use core::fmt::Write;
|
|
||||||
use log_string::LogString;
|
use log_string::LogString;
|
||||||
|
use core::fmt::Write;
|
||||||
|
|
||||||
#[panic_handler]
|
#[cfg(not(baremetal))]
|
||||||
fn handle_panic(arg: &PanicInfo) -> ! {
|
mod native_nostd {
|
||||||
println!("PANIC!");
|
pub fn init() {}
|
||||||
println!("Details: {:?}", arg);
|
|
||||||
xous::syscall::wait_event();
|
|
||||||
loop {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_irq(irq_no: usize, arg: *mut usize) {
|
#[cfg(baremetal)]
|
||||||
print!("Handling IRQ {} (arg: {:08x}): ", irq_no, arg as usize);
|
mod native_nostd {
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
while let Some(c) = debug::DEFAULT.getc() {
|
#[panic_handler]
|
||||||
print!("0x{:02x}", c);
|
fn handle_panic(arg: &PanicInfo) -> ! {
|
||||||
|
println!("PANIC!");
|
||||||
|
println!("Details: {:?}", arg);
|
||||||
|
xous::syscall::wait_event();
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_irq(irq_no: usize, arg: *mut usize) {
|
||||||
|
print!("Handling IRQ {} (arg: {:08x}): ", irq_no, arg as usize);
|
||||||
|
|
||||||
|
while let Some(c) = crate::debug::DEFAULT.getc() {
|
||||||
|
print!("0x{:02x}", c);
|
||||||
|
}
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init() {
|
||||||
|
let uart = xous::syscall::map_memory(
|
||||||
|
xous::MemoryAddress::new(0xf000_4000),
|
||||||
|
None,
|
||||||
|
4096,
|
||||||
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
)
|
||||||
|
.expect("couldn't map serial port");
|
||||||
|
unsafe { crate::debug::DEFAULT_UART_ADDR = uart.as_mut_ptr() };
|
||||||
|
println!("Mapped UART @ {:08x}", uart.addr.get());
|
||||||
|
|
||||||
|
println!("Process: map success!");
|
||||||
|
crate::debug::DEFAULT.enable_rx();
|
||||||
|
|
||||||
|
println!("Allocating IRQ...");
|
||||||
|
xous::syscall::claim_interrupt(4, handle_irq, core::ptr::null_mut::<usize>())
|
||||||
|
.expect("couldn't claim interrupt");
|
||||||
}
|
}
|
||||||
println!();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[cfg_attr(baremetal, no_mangle)]
|
||||||
fn main() {
|
fn main() {
|
||||||
let uart = xous::syscall::map_memory(
|
if cfg!(not(any(windows,unix))) {
|
||||||
xous::MemoryAddress::new(0xf000_4000),
|
native_nostd::init();
|
||||||
None,
|
}
|
||||||
4096,
|
|
||||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
|
||||||
)
|
|
||||||
.expect("couldn't map serial port");
|
|
||||||
unsafe { debug::DEFAULT_UART_ADDR = uart.as_mut_ptr() };
|
|
||||||
println!("Mapped UART @ {:08x}", uart.addr.get());
|
|
||||||
|
|
||||||
println!("Process: map success!");
|
|
||||||
debug::DEFAULT.enable_rx();
|
|
||||||
|
|
||||||
println!("Allocating IRQ...");
|
|
||||||
xous::syscall::claim_interrupt(4, handle_irq, 0 as *mut usize)
|
|
||||||
.expect("couldn't claim interrupt");
|
|
||||||
|
|
||||||
// println!("Allocating a ton of space on the stack...");
|
// println!("Allocating a ton of space on the stack...");
|
||||||
// {
|
// {
|
||||||
|
|
@ -79,33 +96,33 @@ fn main() {
|
||||||
xous::syscall::create_server(xous::make_name!("📜")).expect("couldn't create server");
|
xous::syscall::create_server(xous::make_name!("📜")).expect("couldn't create server");
|
||||||
println!("Server listening on address {:?}", server_addr);
|
println!("Server listening on address {:?}", server_addr);
|
||||||
|
|
||||||
let mut counter = 0;
|
let mut counter: usize = 0;
|
||||||
loop {
|
loop {
|
||||||
if counter & 0xfff == 0 {
|
if counter.trailing_zeros() >= 12 {
|
||||||
println!("Counter tick: {}", counter);
|
println!("Counter tick: {}", counter);
|
||||||
}
|
}
|
||||||
counter += 1;
|
counter += 1;
|
||||||
// // println!("Waiting for an event...");
|
println!("Waiting for an event...");
|
||||||
// let mut envelope = xous::syscall::receive_message(server_addr).expect("couldn't get address");
|
let mut envelope =
|
||||||
// // println!("Got message envelope: {:?}", envelope);
|
xous::syscall::receive_message(server_addr).expect("couldn't get address");
|
||||||
// match &mut envelope.message {
|
println!("Got message envelope: {:?}", envelope);
|
||||||
// xous::Message::Scalar(msg) => {
|
match &mut envelope.message {
|
||||||
// println!("Scalar message from {}: {:?}", envelope.sender, msg)
|
xous::Message::Scalar(msg) => {
|
||||||
// }
|
println!("Scalar message from {}: {:?}", envelope.sender, msg)
|
||||||
// xous::Message::Move(msg) => {
|
}
|
||||||
// let log_entry = LogString::from_message(msg);
|
xous::Message::Move(msg) => {
|
||||||
// println!("Moved log message from {}: {}", envelope.sender, log_entry);
|
let log_entry = LogString::from_message(msg);
|
||||||
// }
|
println!("Moved log message from {}: {}", envelope.sender, log_entry);
|
||||||
// xous::Message::ImmutableBorrow(msg) => {
|
}
|
||||||
// let log_entry = LogString::from_message(msg);
|
xous::Message::ImmutableBorrow(msg) => {
|
||||||
// println!("Immutably borrowed log message from {}: {}", envelope.sender, log_entry);
|
let log_entry = LogString::from_message(msg);
|
||||||
// }
|
println!("Immutably borrowed log message from {}: {}", envelope.sender, log_entry);
|
||||||
// xous::Message::MutableBorrow(msg) => {
|
}
|
||||||
// let mut log_entry = LogString::from_message(msg);
|
xous::Message::MutableBorrow(msg) => {
|
||||||
// println!("Immutably borrowed log message from {}: {}", envelope.sender, log_entry);
|
let mut log_entry = LogString::from_message(msg);
|
||||||
// writeln!(log_entry, " << HELLO FROM THE SERVER").unwrap();
|
println!("Immutably borrowed log message from {}: {}", envelope.sender, log_entry);
|
||||||
// }
|
writeln!(log_entry, " << HELLO FROM THE SERVER").unwrap();
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue