mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
add debugging support to HAL lib
tries to do the right thing in both Xous and bare metal environments, although, xous formatting might be a little funky.
This commit is contained in:
parent
1b4e6b310a
commit
7c0aa1bcbe
2 changed files with 51 additions and 0 deletions
49
libs/cramium-hal/src/debug.rs
Normal file
49
libs/cramium-hal/src/debug.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
use utralib::generated::*;
|
||||
pub struct Uart {}
|
||||
|
||||
impl Uart {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
use core::fmt::{Error, Write};
|
||||
impl Write for Uart {
|
||||
fn write_str(&mut self, s: &str) -> Result<(), Error> {
|
||||
#[cfg(not(feature = "std"))]
|
||||
for c in s.bytes() {
|
||||
self.putc(c);
|
||||
}
|
||||
#[cfg(feature = "std")]
|
||||
log::info!("{}", s);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub mod debug_print_hardware {
|
||||
#[macro_export]
|
||||
macro_rules! print
|
||||
{
|
||||
($($args:tt)+) => ({
|
||||
use core::fmt::Write;
|
||||
let _ = write!(crate::debug::Uart {}, $($args)+);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! println
|
||||
{
|
||||
() => ({
|
||||
$crate::print!("\r\n")
|
||||
});
|
||||
($fmt:expr) => ({
|
||||
$crate::print!(concat!($fmt, "\r\n"))
|
||||
});
|
||||
($fmt:expr, $($args:tt)+) => ({
|
||||
$crate::print!(concat!($fmt, "\r\n"), $($args)+)
|
||||
});
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
#[macro_use]
|
||||
pub mod debug;
|
||||
pub mod ifram;
|
||||
pub mod iox;
|
||||
pub mod sce;
|
||||
|
|
|
|||
Loading…
Reference in a new issue