mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
shell: don't specify an address
Since we can now omit virtual addresses, use this feature when allocating the UART. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
08e416c776
commit
1ba52da9a3
2 changed files with 24 additions and 19 deletions
|
|
@ -5,7 +5,7 @@ macro_rules! print
|
||||||
{
|
{
|
||||||
($($args:tt)+) => ({
|
($($args:tt)+) => ({
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
let _ = write!(crate::debug::DEFAULT_UART, $($args)+);
|
let _ = write!(crate::debug::DEFAULT, $($args)+);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|
@ -22,42 +22,41 @@ macro_rules! println
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Uart {
|
pub struct Uart {}
|
||||||
pub base: *mut usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const DEFAULT_UART: Uart = Uart {
|
pub static mut DEFAULT_UART_ADDR: *mut usize = 0x0000_0000 as *mut usize;
|
||||||
base: 0xE000_1000 as *mut usize,
|
|
||||||
};
|
pub const DEFAULT: Uart = Uart {};
|
||||||
|
|
||||||
impl Uart {
|
impl Uart {
|
||||||
pub fn putc(&self, c: u8) {
|
pub fn putc(&self, c: u8) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
let base = DEFAULT_UART_ADDR;
|
||||||
// Wait until TXFULL is `0`
|
// Wait until TXFULL is `0`
|
||||||
while self.base.add(1).read_volatile() != 0 {
|
while base.add(1).read_volatile() != 0 {
|
||||||
()
|
()
|
||||||
}
|
}
|
||||||
self.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 {
|
||||||
self.base
|
let base = DEFAULT_UART_ADDR;
|
||||||
.add(5)
|
base.add(5).write_volatile(base.add(5).read_volatile() | 2)
|
||||||
.write_volatile(self.base.add(5).read_volatile() | 2)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getc(&self) -> Option<u8> {
|
pub fn getc(&self) -> Option<u8> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
let base = DEFAULT_UART_ADDR;
|
||||||
// If EV_PENDING_RX is 1, return the pending character.
|
// If EV_PENDING_RX is 1, return the pending character.
|
||||||
// Otherwise, return None.
|
// Otherwise, return None.
|
||||||
match self.base.add(4).read_volatile() & 2 {
|
match base.add(4).read_volatile() & 2 {
|
||||||
0 => None,
|
0 => None,
|
||||||
ack => {
|
ack => {
|
||||||
let c = Some(self.base.add(0).read_volatile() as u8);
|
let c = Some(base.add(0).read_volatile() as u8);
|
||||||
self.base.add(4).write_volatile(ack);
|
base.add(4).write_volatile(ack);
|
||||||
c
|
c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ fn handle_panic(arg: &PanicInfo) -> ! {
|
||||||
fn handle_irq(irq_no: usize, arg: *mut usize) {
|
fn handle_irq(irq_no: usize, arg: *mut usize) {
|
||||||
print!("Handling IRQ {} (arg: {:08x}): ", irq_no, arg as usize);
|
print!("Handling IRQ {} (arg: {:08x}): ", irq_no, arg as usize);
|
||||||
|
|
||||||
while let Some(c) = debug::DEFAULT_UART.getc() {
|
while let Some(c) = debug::DEFAULT.getc() {
|
||||||
print!("0x{:02x}", c);
|
print!("0x{:02x}", c);
|
||||||
}
|
}
|
||||||
println!("");
|
println!("");
|
||||||
|
|
@ -27,13 +27,19 @@ fn handle_irq(irq_no: usize, arg: *mut usize) {
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
fn main() {
|
fn main() {
|
||||||
xous::rsyscall(xous::SysCall::MapPhysical(
|
let uart = xous::rsyscall(xous::SysCall::MapPhysical(
|
||||||
0xF0001000 as *mut usize,
|
0xF0001000 as *mut usize,
|
||||||
debug::DEFAULT_UART.base as *mut usize,
|
0 as *mut usize,
|
||||||
4096,
|
4096,
|
||||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
))
|
))
|
||||||
.expect("couldn't map address");
|
.expect("couldn't map address");
|
||||||
|
let uart = match uart {
|
||||||
|
xous::Result::MemoryRange(base, _size) => base as *mut usize,
|
||||||
|
x => panic!("Unexpected result: {:?}", x),
|
||||||
|
};
|
||||||
|
unsafe { debug::DEFAULT_UART_ADDR = uart };
|
||||||
|
println!("Mapped UART @ {:08x}", uart as usize);
|
||||||
xous::rsyscall(xous::SysCall::MapPhysical(
|
xous::rsyscall(xous::SysCall::MapPhysical(
|
||||||
0xF0002000 as *mut usize,
|
0xF0002000 as *mut usize,
|
||||||
0xF0002000 as *mut usize,
|
0xF0002000 as *mut usize,
|
||||||
|
|
@ -43,7 +49,7 @@ fn main() {
|
||||||
.map(|_| println!("!!!WARNING: managed to steal kernel's memory"))
|
.map(|_| println!("!!!WARNING: managed to steal kernel's memory"))
|
||||||
.ok();
|
.ok();
|
||||||
println!("Process: map success!");
|
println!("Process: map success!");
|
||||||
debug::DEFAULT_UART.enable_rx();
|
debug::DEFAULT.enable_rx();
|
||||||
println!("Allocating IRQ...");
|
println!("Allocating IRQ...");
|
||||||
xous::rsyscall(xous::SysCall::ClaimInterrupt(
|
xous::rsyscall(xous::SysCall::ClaimInterrupt(
|
||||||
2,
|
2,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue