From 1fd2fcd086be2b988dc1dce9358d808ea10995cd Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Fri, 26 Aug 2022 20:14:10 -0700 Subject: Serial macros --- src/lib.rs | 1 + src/serial.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/serial.rs (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 550b78f..476ef60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,5 +3,6 @@ //! Processor independent code for operating systems! //! Provides common structures for synchronization, memory, etc. #![no_std] +pub mod serial; pub mod sync; pub mod util; diff --git a/src/serial.rs b/src/serial.rs new file mode 100644 index 0000000..91bc8eb --- /dev/null +++ b/src/serial.rs @@ -0,0 +1,46 @@ +//! Serial Printing + +/// # Print without newline +/// +/// Print formatted arguments without a newline +#[macro_export] +macro_rules! serial_print { + ($($arg:tt)*) => (crate::_serial_print(format_args!($($arg)*))); +} + +/// # Print with newline +/// +/// Print formatted arguments with a newline +#[macro_export] +macro_rules! serial_println { + () => ($crate::serial_print!("\n")); + ($($arg:tt)*) => ({ + crate::_serial_print(format_args_nl!($($arg)*)); + }) +} + +/// # Debug print without newline +/// +/// Print formatted arguments without a newline but only with `verbose` feature +#[macro_export] +macro_rules! serial_vprint { + ($($arg:tt)*) => ({ + #[cfg(feature="verbose")] + crate::_serial_print(format_args!($($arg)*)) + }); +} + +/// # Debug print with newline +/// +/// Print formatted arguments with a newline but only with `verbose` feature +#[macro_export] +macro_rules! serial_vprintln { + () => ({ + #[cfg(feature="verbose")] + $crate::serial_print!("\n") + }); + ($($arg:tt)*) => ({ + #[cfg(feature="verbose")] + crate::_serial_print(format_args_nl!($($arg)*)); + }) +} -- cgit v1.2.1