mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
examples: fix shell running on hardware
Previously, the `baremetal.rs` library was removed. This resulted in this program no longer running on hardware. Add this library back in. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
965696df8b
commit
179623e083
3 changed files with 43 additions and 86 deletions
|
|
@ -1,69 +0,0 @@
|
||||||
use core::panic::PanicInfo;
|
|
||||||
|
|
||||||
#[panic_handler]
|
|
||||||
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!();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Rust entry point (_start_rust)
|
|
||||||
///
|
|
||||||
/// Zeros bss section, initializes data section and calls main. This function
|
|
||||||
/// never returns.
|
|
||||||
#[link_section = ".init.rust"]
|
|
||||||
#[export_name = "_start"]
|
|
||||||
pub unsafe extern "C" fn start_rust() -> ! {
|
|
||||||
extern "Rust" {
|
|
||||||
// This symbol will be provided by the kernel
|
|
||||||
fn main();
|
|
||||||
}
|
|
||||||
|
|
||||||
let uart = xous::syscall::map_memory(
|
|
||||||
xous::MemoryAddress::new(0xf000_1000),
|
|
||||||
None,
|
|
||||||
4096,
|
|
||||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
|
||||||
)
|
|
||||||
.expect("couldn't map uart");
|
|
||||||
crate::debug::DEFAULT_UART_ADDR = uart.as_mut_ptr() as _;
|
|
||||||
println!("Mapped UART @ {:08x}", uart.addr.get());
|
|
||||||
|
|
||||||
xous::syscall::map_memory(
|
|
||||||
xous::MemoryAddress::new(0xf000_2000),
|
|
||||||
None,
|
|
||||||
4096,
|
|
||||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
|
||||||
)
|
|
||||||
.map(|_| println!("!!!WARNING: managed to steal kernel's memory"))
|
|
||||||
.ok();
|
|
||||||
println!("Process: map success!");
|
|
||||||
|
|
||||||
crate::debug::DEFAULT.enable_rx();
|
|
||||||
println!("Allocating IRQ...");
|
|
||||||
xous::claim_interrupt(2, handle_irq, core::ptr::null_mut::<usize>())
|
|
||||||
// xous::rsyscall(xous::SysCall::ClaimInterrupt(
|
|
||||||
// 2,
|
|
||||||
// handle_irq as *mut usize,
|
|
||||||
// core::ptr::null_mut::<usize>(),
|
|
||||||
// ))
|
|
||||||
.expect("couldn't claim interrupt");
|
|
||||||
|
|
||||||
main();
|
|
||||||
panic!("exited main");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[export_name = "abort"]
|
|
||||||
pub extern "C" fn abort() -> ! {
|
|
||||||
panic!("aborted");
|
|
||||||
}
|
|
||||||
|
|
@ -22,6 +22,16 @@ macro_rules! println
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 struct Uart {}
|
pub struct Uart {}
|
||||||
|
|
||||||
pub static mut DEFAULT_UART_ADDR: *mut usize = 0x0000_0000 as *mut usize;
|
pub static mut DEFAULT_UART_ADDR: *mut usize = 0x0000_0000 as *mut usize;
|
||||||
|
|
@ -31,14 +41,31 @@ pub const DEFAULT: Uart = Uart {};
|
||||||
impl Uart {
|
impl Uart {
|
||||||
pub fn putc(&self, c: u8) {
|
pub fn putc(&self, c: u8) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
if DEFAULT_UART_ADDR as usize == 0 {
|
||||||
|
let uart = xous::syscall::map_memory(
|
||||||
|
xous::MemoryAddress::new(0xf000_1000),
|
||||||
|
None,
|
||||||
|
4096,
|
||||||
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
)
|
||||||
|
.expect("couldn't map uart");
|
||||||
|
DEFAULT_UART_ADDR = uart.as_mut_ptr() as _;
|
||||||
|
println!("Mapped UART @ {:08x}", uart.addr.get());
|
||||||
|
// core::mem::forget(uart);
|
||||||
|
|
||||||
|
println!("Allocating IRQ...");
|
||||||
|
xous::claim_interrupt(2, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
|
||||||
|
self.enable_rx();
|
||||||
|
}
|
||||||
let base = DEFAULT_UART_ADDR;
|
let base = DEFAULT_UART_ADDR;
|
||||||
|
|
||||||
// Wait until TXFULL is `0`
|
// Wait until TXFULL is `0`
|
||||||
while base.add(1).read_volatile() != 0 {}
|
while base.add(1).read_volatile() != 0 {}
|
||||||
base.add(0).write_volatile(c as usize)
|
base.add(0).write_volatile(c as usize)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable_rx(self) {
|
pub fn enable_rx(&self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let base = DEFAULT_UART_ADDR;
|
let base = DEFAULT_UART_ADDR;
|
||||||
base.add(5).write_volatile(base.add(5).read_volatile() | 2)
|
base.add(5).write_volatile(base.add(5).read_volatile() | 2)
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,6 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod debug;
|
mod debug;
|
||||||
|
|
||||||
#[cfg(baremetal)]
|
|
||||||
mod baremetal;
|
|
||||||
|
|
||||||
mod timer;
|
mod timer;
|
||||||
// mod logstr;
|
// mod logstr;
|
||||||
|
|
||||||
|
|
@ -19,11 +16,8 @@ mod timer;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
#[cfg_attr(baremetal, no_mangle)]
|
#[xous::xous_main]
|
||||||
fn main() {
|
fn shell_main() -> ! {
|
||||||
println!("Starting to initialize the timer");
|
|
||||||
#[cfg(not(baremetal))]
|
|
||||||
xous::arch::ensure_connection().unwrap();
|
|
||||||
timer::init();
|
timer::init();
|
||||||
|
|
||||||
let mut connection = None;
|
let mut connection = None;
|
||||||
|
|
@ -45,7 +39,7 @@ fn main() {
|
||||||
// let ls = logstr::LogStr::new();
|
// let 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(
|
match xous::syscall::send_message(
|
||||||
connection,
|
connection,
|
||||||
xous::Message::Scalar(xous::ScalarMessage {
|
xous::Message::Scalar(xous::ScalarMessage {
|
||||||
id: counter + 4096,
|
id: counter + 4096,
|
||||||
|
|
@ -54,15 +48,20 @@ fn main() {
|
||||||
arg3: !counter,
|
arg3: !counter,
|
||||||
arg4: counter + 1,
|
arg4: counter + 1,
|
||||||
}),
|
}),
|
||||||
)
|
) {
|
||||||
.expect("couldn't send scalar message");
|
Err(xous::Error::ServerQueueFull) => {
|
||||||
if counter.trailing_zeros() >= 12 {
|
println!("Server queue is full... retrying");
|
||||||
println!("Loop {}", counter);
|
continue;
|
||||||
|
},
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Loop {}", counter);
|
||||||
|
counter += 1;
|
||||||
|
},
|
||||||
|
Err(e) => panic!("Unable to send message: {:?}", e),
|
||||||
}
|
}
|
||||||
counter += 1;
|
|
||||||
|
|
||||||
#[cfg(not(baremetal))]
|
// #[cfg(not(target_os = "none"))]
|
||||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
// std::thread::sleep(std::time::Duration::from_millis(500));
|
||||||
// if counter & 2 == 0 {
|
// if counter & 2 == 0 {
|
||||||
// xous::syscall::yield_slice();
|
// xous::syscall::yield_slice();
|
||||||
// }
|
// }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue