mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +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)+) => ({
|
||||
use core::fmt::Write;
|
||||
let _ = write!(crate::debug::DEFAULT_UART, $($args)+);
|
||||
let _ = write!(crate::debug::DEFAULT, $($args)+);
|
||||
});
|
||||
}
|
||||
#[macro_export]
|
||||
|
|
@ -22,42 +22,41 @@ macro_rules! println
|
|||
});
|
||||
}
|
||||
|
||||
pub struct Uart {
|
||||
pub base: *mut usize,
|
||||
}
|
||||
pub struct Uart {}
|
||||
|
||||
pub const DEFAULT_UART: Uart = Uart {
|
||||
base: 0xE000_1000 as *mut usize,
|
||||
};
|
||||
pub static mut DEFAULT_UART_ADDR: *mut usize = 0x0000_0000 as *mut usize;
|
||||
|
||||
pub const DEFAULT: Uart = Uart {};
|
||||
|
||||
impl Uart {
|
||||
pub fn putc(&self, c: u8) {
|
||||
unsafe {
|
||||
let base = DEFAULT_UART_ADDR;
|
||||
// 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) {
|
||||
unsafe {
|
||||
self.base
|
||||
.add(5)
|
||||
.write_volatile(self.base.add(5).read_volatile() | 2)
|
||||
let base = DEFAULT_UART_ADDR;
|
||||
base.add(5).write_volatile(base.add(5).read_volatile() | 2)
|
||||
};
|
||||
}
|
||||
|
||||
pub fn getc(&self) -> Option<u8> {
|
||||
unsafe {
|
||||
let base = DEFAULT_UART_ADDR;
|
||||
// If EV_PENDING_RX is 1, return the pending character.
|
||||
// Otherwise, return None.
|
||||
match self.base.add(4).read_volatile() & 2 {
|
||||
match base.add(4).read_volatile() & 2 {
|
||||
0 => None,
|
||||
ack => {
|
||||
let c = Some(self.base.add(0).read_volatile() as u8);
|
||||
self.base.add(4).write_volatile(ack);
|
||||
let c = Some(base.add(0).read_volatile() as u8);
|
||||
base.add(4).write_volatile(ack);
|
||||
c
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ fn handle_panic(arg: &PanicInfo) -> ! {
|
|||
fn handle_irq(irq_no: usize, arg: *mut 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);
|
||||
}
|
||||
println!("");
|
||||
|
|
@ -27,13 +27,19 @@ fn handle_irq(irq_no: usize, arg: *mut usize) {
|
|||
|
||||
#[no_mangle]
|
||||
fn main() {
|
||||
xous::rsyscall(xous::SysCall::MapPhysical(
|
||||
let uart = xous::rsyscall(xous::SysCall::MapPhysical(
|
||||
0xF0001000 as *mut usize,
|
||||
debug::DEFAULT_UART.base as *mut usize,
|
||||
0 as *mut usize,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
))
|
||||
.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(
|
||||
0xF0002000 as *mut usize,
|
||||
0xF0002000 as *mut usize,
|
||||
|
|
@ -43,7 +49,7 @@ fn main() {
|
|||
.map(|_| println!("!!!WARNING: managed to steal kernel's memory"))
|
||||
.ok();
|
||||
println!("Process: map success!");
|
||||
debug::DEFAULT_UART.enable_rx();
|
||||
debug::DEFAULT.enable_rx();
|
||||
println!("Allocating IRQ...");
|
||||
xous::rsyscall(xous::SysCall::ClaimInterrupt(
|
||||
2,
|
||||
|
|
|
|||
Loading…
Reference in a new issue