mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
unify debug.rs and move to UTRA format
This commit is contained in:
parent
62b625ec60
commit
1d23d2c1f7
7 changed files with 215 additions and 163 deletions
|
|
@ -6,12 +6,9 @@ pub struct Uart {
|
||||||
impl Uart {
|
impl Uart {
|
||||||
pub fn putc(&self, c: u8) {
|
pub fn putc(&self, c: u8) {
|
||||||
let mut uart = CSR::new(self.base);
|
let mut uart = CSR::new(self.base);
|
||||||
unsafe {
|
// Wait until TXFULL is `0`
|
||||||
// Wait until TXFULL is `0`
|
while uart.r(utra::uart::TXFULL) != 0 {}
|
||||||
while uart.r(utra::uart::TXFULL) != 0 {
|
uart.wo(utra::uart::RXTX, c as u32)
|
||||||
}
|
|
||||||
uart.wo(utra::uart::RXTX, c as u32)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,72 +29,77 @@ 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) = crate::debug::DEFAULT.getc() {
|
while let Some(c) = crate::debug::DEFAULT.getc() {
|
||||||
print!("0x{:02x}", c);
|
print!("{}", c as char);
|
||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Uart {}
|
pub struct Uart {}
|
||||||
|
|
||||||
|
// this is a hack to bypass an explicit initialization/allocation step for the debug structure
|
||||||
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;
|
||||||
|
|
||||||
pub const DEFAULT: Uart = Uart {};
|
pub const DEFAULT: Uart = Uart {};
|
||||||
|
|
||||||
impl Uart {
|
impl Uart {
|
||||||
|
fn map_uart(&self) {
|
||||||
|
/*
|
||||||
|
Note: the memory address and interrupt specified here needs to map to a unique hardware
|
||||||
|
UART resource. Modify in this function as necessary.
|
||||||
|
*/
|
||||||
|
let uart = xous::syscall::map_memory(
|
||||||
|
xous::MemoryAddress::new(utra::console::HW_CONSOLE_BASE),
|
||||||
|
None,
|
||||||
|
4096,
|
||||||
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
)
|
||||||
|
.expect("couldn't map debug uart");
|
||||||
|
unsafe{ 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(utra::console::CONSOLE_IRQ, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
|
||||||
|
self.enable_rx();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn putc(&self, c: u8) {
|
pub fn putc(&self, c: u8) {
|
||||||
if cfg!(feature = "debugprint") {
|
if cfg!(feature = "debugprint") {
|
||||||
unsafe {
|
if unsafe{DEFAULT_UART_ADDR} as usize == 0 {
|
||||||
if DEFAULT_UART_ADDR as usize == 0 {
|
self.map_uart();
|
||||||
let uart = xous::syscall::map_memory(
|
}
|
||||||
xous::MemoryAddress::new(utra::console::HW_CONSOLE_BASE),
|
let mut uart_csr = CSR::new(unsafe{ DEFAULT_UART_ADDR as *mut u32});
|
||||||
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...");
|
// Wait until TXFULL is `0`
|
||||||
xous::claim_interrupt(utra::console::CONSOLE_IRQ, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
|
while uart_csr.r(utra::uart::TXFULL) != 0 {}
|
||||||
self.enable_rx();
|
uart_csr.wo(utra::uart::RXTX, c as u32);
|
||||||
}
|
|
||||||
let base = DEFAULT_UART_ADDR;
|
|
||||||
let mut uart_csr = CSR::new(DEFAULT_UART_ADDR as *mut u32);
|
|
||||||
|
|
||||||
// Wait until TXFULL is `0`
|
|
||||||
while uart_csr.r(utra::console::TXFULL) != 0 {}
|
|
||||||
uart_csr.wo(utra::console::RXTX, c as u32);
|
|
||||||
/*
|
|
||||||
while base.add(1).read_volatile() != 0 {}
|
|
||||||
base.add(0).write_volatile(c as usize)*/
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable_rx(&self) {
|
pub fn enable_rx(&self) {
|
||||||
unsafe {
|
if cfg!(feature = "debugprint") {
|
||||||
// let base = DEFAULT_UART_ADDR;
|
let mut uart_csr = CSR::new(unsafe{DEFAULT_UART_ADDR as *mut u32});
|
||||||
// base.add(5).write_volatile(base.add(5).read_volatile() | 2)
|
uart_csr.wfo(utra::uart::EV_ENABLE_ENABLE, uart_csr.rf(utra::uart::EV_ENABLE_ENABLE) | 2 );
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getc(&self) -> Option<u8> {
|
pub fn getc(&self) -> Option<u8> {
|
||||||
// unsafe {
|
if cfg!(feature = "debugprint") {
|
||||||
// let base = DEFAULT_UART_ADDR;
|
if unsafe{DEFAULT_UART_ADDR} as usize == 0 {
|
||||||
// // If EV_PENDING_RX is 1, return the pending character.
|
self.map_uart();
|
||||||
// // Otherwise, return None.
|
}
|
||||||
// match base.add(4).read_volatile() & 2 {
|
let mut uart_csr = CSR::new(unsafe{DEFAULT_UART_ADDR as *mut u32});
|
||||||
// 0 => None,
|
match uart_csr.rf(utra::uart::EV_PENDING_PENDING) & 2 {
|
||||||
// ack => {
|
0 => None,
|
||||||
// let c = Some(base.add(0).read_volatile() as u8);
|
ack => {
|
||||||
// base.add(4).write_volatile(ack);
|
let c = Some(uart_csr.rf(utra::uart::RXTX_RXTX) as u8);
|
||||||
// c
|
uart_csr.wo(utra::uart::EV_PENDING, ack);
|
||||||
// }
|
c
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
None
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
use core::fmt::{Error, Write};
|
use core::fmt::{Error, Write};
|
||||||
|
|
||||||
|
use utralib::generated::*;
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! print
|
macro_rules! print
|
||||||
{
|
{
|
||||||
|
|
@ -22,43 +24,81 @@ 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!("{}", c as char);
|
||||||
|
}
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Uart {}
|
pub struct Uart {}
|
||||||
|
|
||||||
|
// this is a hack to bypass an explicit initialization/allocation step for the debug structure
|
||||||
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;
|
||||||
|
|
||||||
pub const DEFAULT: Uart = Uart {};
|
pub const DEFAULT: Uart = Uart {};
|
||||||
|
|
||||||
impl Uart {
|
impl Uart {
|
||||||
pub fn putc(&self, c: u8) {
|
fn map_uart(&self) {
|
||||||
unsafe {
|
/*
|
||||||
let base = DEFAULT_UART_ADDR;
|
Note: the memory address and interrupt specified here needs to map to a unique hardware
|
||||||
// Wait until TXFULL is `0`
|
UART resource. Modify in this function as necessary.
|
||||||
while base.add(1).read_volatile() != 0 {
|
*/
|
||||||
}
|
let uart = xous::syscall::map_memory(
|
||||||
base.add(0).write_volatile(c as usize)
|
xous::MemoryAddress::new(utra::console::HW_CONSOLE_BASE),
|
||||||
};
|
None,
|
||||||
|
4096,
|
||||||
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
)
|
||||||
|
.expect("couldn't map debug uart");
|
||||||
|
unsafe{ 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(utra::console::CONSOLE_IRQ, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
|
||||||
|
self.enable_rx();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable_rx(self) {
|
pub fn putc(&self, c: u8) {
|
||||||
unsafe {
|
if cfg!(feature = "debugprint") {
|
||||||
let base = DEFAULT_UART_ADDR;
|
if unsafe{DEFAULT_UART_ADDR} as usize == 0 {
|
||||||
base.add(5).write_volatile(base.add(5).read_volatile() | 2)
|
self.map_uart();
|
||||||
};
|
}
|
||||||
|
let mut uart_csr = CSR::new(unsafe{ DEFAULT_UART_ADDR as *mut u32});
|
||||||
|
|
||||||
|
// Wait until TXFULL is `0`
|
||||||
|
while uart_csr.r(utra::uart::TXFULL) != 0 {}
|
||||||
|
uart_csr.wo(utra::uart::RXTX, c as u32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn enable_rx(&self) {
|
||||||
|
if cfg!(feature = "debugprint") {
|
||||||
|
let mut uart_csr = CSR::new(unsafe{DEFAULT_UART_ADDR as *mut u32});
|
||||||
|
uart_csr.wfo(utra::uart::EV_ENABLE_ENABLE, uart_csr.rf(utra::uart::EV_ENABLE_ENABLE) | 2 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getc(&self) -> Option<u8> {
|
pub fn getc(&self) -> Option<u8> {
|
||||||
unsafe {
|
if cfg!(feature = "debugprint") {
|
||||||
let base = DEFAULT_UART_ADDR;
|
if unsafe{DEFAULT_UART_ADDR} as usize == 0 {
|
||||||
// If EV_PENDING_RX is 1, return the pending character.
|
self.map_uart();
|
||||||
// Otherwise, return None.
|
}
|
||||||
match base.add(4).read_volatile() & 2 {
|
let mut uart_csr = CSR::new(unsafe{DEFAULT_UART_ADDR as *mut u32});
|
||||||
|
match uart_csr.rf(utra::uart::EV_PENDING_PENDING) & 2 {
|
||||||
0 => None,
|
0 => None,
|
||||||
ack => {
|
ack => {
|
||||||
let c = Some(base.add(0).read_volatile() as u8);
|
let c = Some(uart_csr.rf(utra::uart::RXTX_RXTX) as u8);
|
||||||
base.add(4).write_volatile(ack);
|
uart_csr.wo(utra::uart::EV_PENDING, ack);
|
||||||
c
|
c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,72 +29,77 @@ 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) = crate::debug::DEFAULT.getc() {
|
while let Some(c) = crate::debug::DEFAULT.getc() {
|
||||||
print!("0x{:02x}", c);
|
print!("{}", c as char);
|
||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Uart {}
|
pub struct Uart {}
|
||||||
|
|
||||||
|
// this is a hack to bypass an explicit initialization/allocation step for the debug structure
|
||||||
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;
|
||||||
|
|
||||||
pub const DEFAULT: Uart = Uart {};
|
pub const DEFAULT: Uart = Uart {};
|
||||||
|
|
||||||
impl Uart {
|
impl Uart {
|
||||||
|
fn map_uart(&self) {
|
||||||
|
/*
|
||||||
|
Note: the memory address and interrupt specified here needs to map to a unique hardware
|
||||||
|
UART resource. Modify in this function as necessary.
|
||||||
|
*/
|
||||||
|
let uart = xous::syscall::map_memory(
|
||||||
|
xous::MemoryAddress::new(utra::console::HW_CONSOLE_BASE),
|
||||||
|
None,
|
||||||
|
4096,
|
||||||
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
)
|
||||||
|
.expect("couldn't map debug uart");
|
||||||
|
unsafe{ 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(utra::console::CONSOLE_IRQ, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
|
||||||
|
self.enable_rx();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn putc(&self, c: u8) {
|
pub fn putc(&self, c: u8) {
|
||||||
if cfg!(feature = "debugprint") {
|
if cfg!(feature = "debugprint") {
|
||||||
unsafe {
|
if unsafe{DEFAULT_UART_ADDR} as usize == 0 {
|
||||||
if DEFAULT_UART_ADDR as usize == 0 {
|
self.map_uart();
|
||||||
let uart = xous::syscall::map_memory(
|
}
|
||||||
xous::MemoryAddress::new(utra::console::HW_CONSOLE_BASE),
|
let mut uart_csr = CSR::new(unsafe{ DEFAULT_UART_ADDR as *mut u32});
|
||||||
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...");
|
// Wait until TXFULL is `0`
|
||||||
xous::claim_interrupt(utra::console::CONSOLE_IRQ, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
|
while uart_csr.r(utra::uart::TXFULL) != 0 {}
|
||||||
self.enable_rx();
|
uart_csr.wo(utra::uart::RXTX, c as u32);
|
||||||
}
|
|
||||||
let base = DEFAULT_UART_ADDR;
|
|
||||||
let mut uart_csr = CSR::new(DEFAULT_UART_ADDR as *mut u32);
|
|
||||||
|
|
||||||
// Wait until TXFULL is `0`
|
|
||||||
while uart_csr.r(utra::console::TXFULL) != 0 {}
|
|
||||||
uart_csr.wo(utra::console::RXTX, c as u32);
|
|
||||||
/*
|
|
||||||
while base.add(1).read_volatile() != 0 {}
|
|
||||||
base.add(0).write_volatile(c as usize)*/
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable_rx(&self) {
|
pub fn enable_rx(&self) {
|
||||||
unsafe {
|
if cfg!(feature = "debugprint") {
|
||||||
// let base = DEFAULT_UART_ADDR;
|
let mut uart_csr = CSR::new(unsafe{DEFAULT_UART_ADDR as *mut u32});
|
||||||
// base.add(5).write_volatile(base.add(5).read_volatile() | 2)
|
uart_csr.wfo(utra::uart::EV_ENABLE_ENABLE, uart_csr.rf(utra::uart::EV_ENABLE_ENABLE) | 2 );
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getc(&self) -> Option<u8> {
|
pub fn getc(&self) -> Option<u8> {
|
||||||
// unsafe {
|
if cfg!(feature = "debugprint") {
|
||||||
// let base = DEFAULT_UART_ADDR;
|
if unsafe{DEFAULT_UART_ADDR} as usize == 0 {
|
||||||
// // If EV_PENDING_RX is 1, return the pending character.
|
self.map_uart();
|
||||||
// // Otherwise, return None.
|
}
|
||||||
// match base.add(4).read_volatile() & 2 {
|
let mut uart_csr = CSR::new(unsafe{DEFAULT_UART_ADDR as *mut u32});
|
||||||
// 0 => None,
|
match uart_csr.rf(utra::uart::EV_PENDING_PENDING) & 2 {
|
||||||
// ack => {
|
0 => None,
|
||||||
// let c = Some(base.add(0).read_volatile() as u8);
|
ack => {
|
||||||
// base.add(4).write_volatile(ack);
|
let c = Some(uart_csr.rf(utra::uart::RXTX_RXTX) as u8);
|
||||||
// c
|
uart_csr.wo(utra::uart::EV_PENDING, ack);
|
||||||
// }
|
c
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
None
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ fn shell_main() -> ! {
|
||||||
"SHELL: graphics and ticktimer connections are the same!"
|
"SHELL: graphics and ticktimer connections are the same!"
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut counter: usize = 0;
|
// let mut counter: usize = 0;
|
||||||
// let ls = logstr::LogStr::new();
|
// let ls = logstr::LogStr::new();
|
||||||
let mut lfsr = 0xace1u32;
|
let mut lfsr = 0xace1u32;
|
||||||
let dark = graphics_server::Color::from(0);
|
let dark = graphics_server::Color::from(0);
|
||||||
|
|
|
||||||
|
|
@ -29,72 +29,77 @@ 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) = crate::debug::DEFAULT.getc() {
|
while let Some(c) = crate::debug::DEFAULT.getc() {
|
||||||
print!("0x{:02x}", c);
|
print!("{}", c as char);
|
||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Uart {}
|
pub struct Uart {}
|
||||||
|
|
||||||
|
// this is a hack to bypass an explicit initialization/allocation step for the debug structure
|
||||||
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;
|
||||||
|
|
||||||
pub const DEFAULT: Uart = Uart {};
|
pub const DEFAULT: Uart = Uart {};
|
||||||
|
|
||||||
impl Uart {
|
impl Uart {
|
||||||
|
fn map_uart(&self) {
|
||||||
|
/*
|
||||||
|
Note: the memory address and interrupt specified here needs to map to a unique hardware
|
||||||
|
UART resource. Modify in this function as necessary.
|
||||||
|
*/
|
||||||
|
let uart = xous::syscall::map_memory(
|
||||||
|
xous::MemoryAddress::new(utra::console::HW_CONSOLE_BASE),
|
||||||
|
None,
|
||||||
|
4096,
|
||||||
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
)
|
||||||
|
.expect("couldn't map debug uart");
|
||||||
|
unsafe{ 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(utra::console::CONSOLE_IRQ, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
|
||||||
|
self.enable_rx();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn putc(&self, c: u8) {
|
pub fn putc(&self, c: u8) {
|
||||||
if cfg!(feature = "debugprint") {
|
if cfg!(feature = "debugprint") {
|
||||||
unsafe {
|
if unsafe{DEFAULT_UART_ADDR} as usize == 0 {
|
||||||
if DEFAULT_UART_ADDR as usize == 0 {
|
self.map_uart();
|
||||||
let uart = xous::syscall::map_memory(
|
}
|
||||||
xous::MemoryAddress::new(utra::console::HW_CONSOLE_BASE),
|
let mut uart_csr = CSR::new(unsafe{ DEFAULT_UART_ADDR as *mut u32});
|
||||||
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...");
|
// Wait until TXFULL is `0`
|
||||||
xous::claim_interrupt(utra::console::CONSOLE_IRQ, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
|
while uart_csr.r(utra::uart::TXFULL) != 0 {}
|
||||||
self.enable_rx();
|
uart_csr.wo(utra::uart::RXTX, c as u32);
|
||||||
}
|
|
||||||
let base = DEFAULT_UART_ADDR;
|
|
||||||
let mut uart_csr = CSR::new(DEFAULT_UART_ADDR as *mut u32);
|
|
||||||
|
|
||||||
// Wait until TXFULL is `0`
|
|
||||||
while uart_csr.r(utra::console::TXFULL) != 0 {}
|
|
||||||
uart_csr.wo(utra::console::RXTX, c as u32);
|
|
||||||
/*
|
|
||||||
while base.add(1).read_volatile() != 0 {}
|
|
||||||
base.add(0).write_volatile(c as usize)*/
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable_rx(&self) {
|
pub fn enable_rx(&self) {
|
||||||
unsafe {
|
if cfg!(feature = "debugprint") {
|
||||||
// let base = DEFAULT_UART_ADDR;
|
let mut uart_csr = CSR::new(unsafe{DEFAULT_UART_ADDR as *mut u32});
|
||||||
// base.add(5).write_volatile(base.add(5).read_volatile() | 2)
|
uart_csr.wfo(utra::uart::EV_ENABLE_ENABLE, uart_csr.rf(utra::uart::EV_ENABLE_ENABLE) | 2 );
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getc(&self) -> Option<u8> {
|
pub fn getc(&self) -> Option<u8> {
|
||||||
// unsafe {
|
if cfg!(feature = "debugprint") {
|
||||||
// let base = DEFAULT_UART_ADDR;
|
if unsafe{DEFAULT_UART_ADDR} as usize == 0 {
|
||||||
// // If EV_PENDING_RX is 1, return the pending character.
|
self.map_uart();
|
||||||
// // Otherwise, return None.
|
}
|
||||||
// match base.add(4).read_volatile() & 2 {
|
let mut uart_csr = CSR::new(unsafe{DEFAULT_UART_ADDR as *mut u32});
|
||||||
// 0 => None,
|
match uart_csr.rf(utra::uart::EV_PENDING_PENDING) & 2 {
|
||||||
// ack => {
|
0 => None,
|
||||||
// let c = Some(base.add(0).read_volatile() as u8);
|
ack => {
|
||||||
// base.add(4).write_volatile(ack);
|
let c = Some(uart_csr.rf(utra::uart::RXTX_RXTX) as u8);
|
||||||
// c
|
uart_csr.wo(utra::uart::EV_PENDING, ack);
|
||||||
// }
|
c
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
None
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ impl XousTickTimer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn raw_ticktime(&self) -> u64 {
|
pub fn raw_ticktime(&self) -> u64 {
|
||||||
let mut tt = CSR::new(self.csr.as_mut_ptr() as *mut u32);
|
let tt = CSR::new(self.csr.as_mut_ptr() as *mut u32);
|
||||||
let mut time: u64 = tt.r(utra::ticktimer::TIME0) as u64;
|
let mut time: u64 = tt.r(utra::ticktimer::TIME0) as u64;
|
||||||
time |= (tt.r(utra::ticktimer::TIME1) as u64) << 32;
|
time |= (tt.r(utra::ticktimer::TIME1) as u64) << 32;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue