From 57bbc4b2e55b31817e82f433035f713486fc8ef3 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 3 May 2024 18:47:21 +0800 Subject: [PATCH] move debug into a separate file also create a cramium debug target --- services/xous-swapper/src/debug.rs | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 services/xous-swapper/src/debug.rs diff --git a/services/xous-swapper/src/debug.rs b/services/xous-swapper/src/debug.rs new file mode 100644 index 000000000..24ea6d336 --- /dev/null +++ b/services/xous-swapper/src/debug.rs @@ -0,0 +1,45 @@ +use core::fmt::{Error, Write}; + +use utralib::*; + +pub struct DebugUart {} +impl DebugUart { + #[cfg(all(feature = "debug-print", any(feature = "precursor", feature = "renode")))] + pub fn putc(&mut self, c: u8) { + let mut csr = CSR::new(loader::swap::SWAP_APP_UART_VADDR as *mut u32); + + // Wait until TXFULL is `0` + while csr.r(utra::app_uart::TXFULL) != 0 {} + csr.wfo(utra::app_uart::RXTX_RXTX, c as u32); + } + + #[cfg(all(feature = "debug-print", any(feature = "cramium-soc")))] + pub fn putc(&mut self, c: u8) { + use cramium_hal::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( + loader::swap::SWAP_APP_UART_VADDR as usize, + loader::swap::APP_UART_IFRAM_ADDR as usize, + loader::swap::SWAP_APP_UART_IFRAM_VADDR as usize, + ) + }; + // enqueue our character to send via DMA + uart.write(&[c]); + } + + #[cfg(not(feature = "debug-print"))] + pub fn putc(&self, _c: u8) {} +} + +impl Write for DebugUart { + fn write_str(&mut self, s: &str) -> Result<(), Error> { + for c in s.bytes() { + self.putc(c); + } + Ok(()) + } +}