mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
refactor debug-print in bao1x-hal
on dabao targets the duart is unavailable, so, it's convenient to have a uart-based debug option in the HAL. this patch creates a flag that can allow either target.
This commit is contained in:
parent
fe4ef1bc39
commit
8f208cac4c
3 changed files with 30 additions and 11 deletions
|
|
@ -96,7 +96,9 @@ verilator-only = ["utralib/bao1x"]
|
|||
mpw = ["utralib/bao1x"]
|
||||
hdl-test = ["utralib/bao1x"]
|
||||
verbose-debug = []
|
||||
debug-print-usb = []
|
||||
debug-print = []
|
||||
debug-print-duart = ["debug-print"]
|
||||
debug-print-uart = ["debug-print"]
|
||||
|
||||
udma-stress-test = [
|
||||
] # For RTL simulation testing - aggravates a key corner case
|
||||
|
|
|
|||
|
|
@ -8,15 +8,32 @@ pub static mut SWAP_APP_UART_VADDR: usize = 0;
|
|||
pub static mut SWAP_APP_UART_IFRAM_VADDR: usize = 0;
|
||||
|
||||
impl Uart {
|
||||
#[cfg(all(feature = "debug-print-usb", not(target_os = "xous")))]
|
||||
#[cfg(all(feature = "debug-print", not(target_os = "xous")))]
|
||||
pub fn putc(&self, c: u8) {
|
||||
let base = utra::duart::HW_DUART_BASE 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(feature = "debug-print-uart")]
|
||||
{
|
||||
let buf: [u8; 1] = [c];
|
||||
let uart_buf_addr = crate::board::UART_DMA_TX_BUF_PHYS;
|
||||
let mut udma_uart = unsafe {
|
||||
// safety: this is safe to call, because we set up clock and events prior to calling new.
|
||||
crate::udma::Uart::get_handle(
|
||||
utra::udma_uart_2::HW_UDMA_UART_2_BASE,
|
||||
uart_buf_addr,
|
||||
uart_buf_addr,
|
||||
)
|
||||
};
|
||||
udma_uart.write(&buf);
|
||||
}
|
||||
#[cfg(feature = "debug-print-duart")]
|
||||
{
|
||||
let base = utra::duart::HW_DUART_BASE 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-usb", target_os = "xous"))]
|
||||
#[cfg(all(feature = "debug-print", target_os = "xous"))]
|
||||
pub fn putc(&mut self, c: u8) {
|
||||
if unsafe { SWAP_APP_UART_VADDR } == 0 {
|
||||
match xous::syscall::map_memory(
|
||||
|
|
@ -60,18 +77,18 @@ impl Uart {
|
|||
uart.write(&[c]);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "debug-print-usb"))]
|
||||
#[cfg(not(feature = "debug-print"))]
|
||||
pub fn putc(&mut self, _c: u8) {}
|
||||
}
|
||||
|
||||
use core::fmt::{Error, Write};
|
||||
impl Write for Uart {
|
||||
fn write_str(&mut self, _s: &str) -> Result<(), Error> {
|
||||
#[cfg(not(all(feature = "std", not(feature = "debug-print-usb"))))]
|
||||
#[cfg(not(all(feature = "std", not(feature = "debug-print"))))]
|
||||
for c in _s.bytes() {
|
||||
self.putc(c);
|
||||
}
|
||||
// #[cfg(all(feature = "std", not(feature = "debug-print-usb")))]
|
||||
// #[cfg(all(feature = "std", not(feature = "debug-print")))]
|
||||
// log::info!("{}", _s);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ hosted = ["utralib/hosted", "utralib/std"]
|
|||
renode = ["utralib/renode", "utralib/std"]
|
||||
mass-storage = []
|
||||
debug-print-usb = [
|
||||
"bao1x-hal/debug-print-usb",
|
||||
"bao1x-hal/debug-print-duart",
|
||||
] # mutually exclusive feature with other crates that use the app UART
|
||||
verbose-debug = ["bao1x-hal/verbose-debug"]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue