mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
move debug into a separate file
also create a cramium debug target
This commit is contained in:
parent
e3c244f48b
commit
57bbc4b2e5
1 changed files with 45 additions and 0 deletions
45
services/xous-swapper/src/debug.rs
Normal file
45
services/xous-swapper/src/debug.rs
Normal file
|
|
@ -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(())
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue