mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
add support for paged mode debugging
we have to allocate the virtual page in our process space before we can use the debug UART.
This commit is contained in:
parent
6625e45dd2
commit
e8fd388ae9
1 changed files with 50 additions and 2 deletions
|
|
@ -1,23 +1,71 @@
|
||||||
|
#[allow(unused_imports)]
|
||||||
use utralib::generated::*;
|
use utralib::generated::*;
|
||||||
pub struct Uart {}
|
pub struct Uart {}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub static mut SWAP_APP_UART_VADDR: usize = 0;
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub static mut SWAP_APP_UART_IFRAM_VADDR: usize = 0;
|
||||||
|
|
||||||
impl Uart {
|
impl Uart {
|
||||||
|
#[cfg(all(feature = "debug-print-usb", not(target_os = "xous")))]
|
||||||
pub fn putc(&self, c: u8) {
|
pub fn putc(&self, c: u8) {
|
||||||
let base = utra::duart::HW_DUART_BASE as *mut u32;
|
let base = utra::duart::HW_DUART_BASE as *mut u32;
|
||||||
let mut uart = CSR::new(base);
|
let mut uart = CSR::new(base);
|
||||||
while uart.r(utra::duart::SFR_SR) != 0 {}
|
while uart.r(utra::duart::SFR_SR) != 0 {}
|
||||||
uart.wo(utra::duart::SFR_TXD, c as u32);
|
uart.wo(utra::duart::SFR_TXD, c as u32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "debug-print-usb", target_os = "xous"))]
|
||||||
|
pub fn putc(&mut self, c: u8) {
|
||||||
|
if unsafe { SWAP_APP_UART_VADDR } == 0 {
|
||||||
|
let uart = xous::syscall::map_memory(
|
||||||
|
xous::MemoryAddress::new(utralib::utra::udma_uart_0::HW_UDMA_UART_0_BASE),
|
||||||
|
None,
|
||||||
|
4096,
|
||||||
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
)
|
||||||
|
.expect("couldn't map debug serial port");
|
||||||
|
unsafe { SWAP_APP_UART_VADDR = uart.as_mut_ptr() as usize };
|
||||||
|
}
|
||||||
|
if unsafe { SWAP_APP_UART_IFRAM_VADDR } == 0 {
|
||||||
|
let mem = xous::syscall::map_memory(
|
||||||
|
xous::MemoryAddress::new(crate::board::APP_UART_IFRAM_ADDR),
|
||||||
|
None,
|
||||||
|
4096,
|
||||||
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
)
|
||||||
|
.expect("couldn't map debug serial port dma ram");
|
||||||
|
unsafe { SWAP_APP_UART_IFRAM_VADDR = mem.as_mut_ptr() as usize };
|
||||||
|
}
|
||||||
|
use crate::udma;
|
||||||
|
// safety: safe to call as long as the raw parts are initialized and we exclusively
|
||||||
|
// own it; and the UART has been initialized. For this peripheral, initialization
|
||||||
|
// is handled by the loader and tossed to us, and exclusivity of access is something
|
||||||
|
// we just have to not bungle.
|
||||||
|
let mut uart = unsafe {
|
||||||
|
udma::Uart::get_handle(
|
||||||
|
SWAP_APP_UART_VADDR as usize,
|
||||||
|
crate::board::APP_UART_IFRAM_ADDR as usize,
|
||||||
|
SWAP_APP_UART_IFRAM_VADDR as usize,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
// enqueue our character to send via DMA
|
||||||
|
uart.write(&[c]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "debug-print-usb"))]
|
||||||
|
pub fn putc(&mut self, _c: u8) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
use core::fmt::{Error, Write};
|
use core::fmt::{Error, Write};
|
||||||
impl Write for Uart {
|
impl Write for Uart {
|
||||||
fn write_str(&mut self, s: &str) -> Result<(), Error> {
|
fn write_str(&mut self, s: &str) -> Result<(), Error> {
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(all(feature = "std", not(feature = "debug-print-usb"))))]
|
||||||
for c in s.bytes() {
|
for c in s.bytes() {
|
||||||
self.putc(c);
|
self.putc(c);
|
||||||
}
|
}
|
||||||
#[cfg(feature = "std")]
|
#[cfg(all(feature = "std", not(feature = "debug-print-usb")))]
|
||||||
log::info!("{}", s);
|
log::info!("{}", s);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue