add duart debug support for std environment

This commit is contained in:
bunnie 2025-10-26 22:17:37 +08:00
parent e91eb176e7
commit fc3da61307
2 changed files with 30 additions and 1 deletions

View file

@ -33,7 +33,28 @@ impl Uart {
}
}
#[cfg(all(feature = "debug-print", target_os = "xous"))]
#[cfg(all(feature = "debug-print-duart", target_os = "xous"))]
pub fn putc(&self, c: u8) {
if unsafe { SWAP_APP_UART_VADDR } == 0 {
match xous::syscall::map_memory(
xous::MemoryAddress::new(utralib::utra::duart::HW_DUART_BASE),
None,
4096,
xous::MemoryFlags::R | xous::MemoryFlags::W,
) {
Ok(uart) => {
unsafe { SWAP_APP_UART_VADDR = uart.as_mut_ptr() as usize };
}
_ => return,
}
}
let base = unsafe { SWAP_APP_UART_VADDR as *mut u32 };
let mut uart = CSR::new(base);
while uart.r(utra::duart::SFR_SR) != 0 {}
uart.wo(utra::duart::SFR_TXD, c as u32);
}
#[cfg(all(feature = "debug-print-uart", target_os = "xous"))]
pub fn putc(&mut self, c: u8) {
if unsafe { SWAP_APP_UART_VADDR } == 0 {
match xous::syscall::map_memory(

View file

@ -97,3 +97,11 @@ pub unsafe fn read_sp() -> usize {
core::arch::asm!("mv {0}, sp", out(reg) sp);
sp
}
/// DUART is first-come, first-served in Xous environment. This stub
/// can be called early in a server's initialization process so that it can get
/// exclusive access to the DUART (assuming the kernel is configured to relinquish it)
#[cfg(feature = "std")]
pub fn claim_duart() {
crate::println!("PID {} got duart", xous::process::id());
}